src/misc_gui.cpp
changeset 9897 4d9a6ff6703e
parent 9790 5d5c70e0334e
child 9916 40b0040c754b
equal deleted inserted replaced
9896:19aa91881726 9897:4d9a6ff6703e
  1054 };
  1054 };
  1055 
  1055 
  1056 
  1056 
  1057 struct QueryStringWindow : public QueryStringBaseWindow
  1057 struct QueryStringWindow : public QueryStringBaseWindow
  1058 {
  1058 {
  1059 	QueryStringWindow(const WindowDesc *desc, Window *parent) : QueryStringBaseWindow(desc)
  1059 	QueryStringWindow(size_t size, const WindowDesc *desc, Window *parent) : QueryStringBaseWindow(size, desc)
  1060 	{
  1060 	{
  1061 		this->parent = parent;
  1061 		this->parent = parent;
  1062 		SetBit(_no_scroll, SCROLL_EDIT);
  1062 		SetBit(_no_scroll, SCROLL_EDIT);
  1063 
  1063 
  1064 		this->FindWindowPlacementAndResize(desc);
  1064 		this->FindWindowPlacementAndResize(desc);
  1165 	uint realmaxlen = maxlen & ~0x1000;
  1165 	uint realmaxlen = maxlen & ~0x1000;
  1166 
  1166 
  1167 	DeleteWindowById(WC_QUERY_STRING, 0);
  1167 	DeleteWindowById(WC_QUERY_STRING, 0);
  1168 	DeleteWindowById(WC_SAVELOAD, 0);
  1168 	DeleteWindowById(WC_SAVELOAD, 0);
  1169 
  1169 
  1170 	QueryStringWindow *w = new QueryStringWindow(&_query_string_desc, parent);
  1170 	QueryStringWindow *w = new QueryStringWindow(realmaxlen + 1, &_query_string_desc, parent);
  1171 
  1171 
  1172 	assert(realmaxlen < lengthof(w->edit_str_buf));
  1172 	GetString(w->edit_str_buf, str, &w->edit_str_buf[realmaxlen]);
  1173 
  1173 	w->edit_str_buf[realmaxlen] = '\0';
  1174 	GetString(w->edit_str_buf, str, lastof(w->edit_str_buf));
  1174 
  1175 	w->edit_str_buf[realmaxlen - 1] = '\0';
  1175 	if (!(maxlen & 0x1000)) w->orig = strdup(w->edit_str_buf);
  1176 
       
  1177 	if (maxlen & 0x1000) {
       
  1178 		w->orig = NULL;
       
  1179 	} else {
       
  1180 		strecpy(w->orig_str_buf, w->edit_str_buf, lastof(w->orig_str_buf));
       
  1181 		w->orig = w->orig_str_buf;
       
  1182 	}
       
  1183 
  1176 
  1184 	w->LowerWidget(QUERY_STR_WIDGET_TEXT);
  1177 	w->LowerWidget(QUERY_STR_WIDGET_TEXT);
  1185 	w->caption = caption;
  1178 	w->caption = caption;
  1186 	w->afilter = afilter;
  1179 	w->afilter = afilter;
  1187 	InitializeTextBuffer(&w->text, w->edit_str_buf, realmaxlen, maxwidth);
  1180 	InitializeTextBuffer(&w->text, w->edit_str_buf, realmaxlen, maxwidth);
  1412 		 * Let's use the name of player #0 for now. */
  1405 		 * Let's use the name of player #0 for now. */
  1413 		const Player *p = GetPlayer(IsValidPlayerID(_local_player) ? _local_player : PLAYER_FIRST);
  1406 		const Player *p = GetPlayer(IsValidPlayerID(_local_player) ? _local_player : PLAYER_FIRST);
  1414 
  1407 
  1415 		SetDParam(0, p->index);
  1408 		SetDParam(0, p->index);
  1416 		SetDParam(1, _date);
  1409 		SetDParam(1, _date);
  1417 		GetString(this->edit_str_buf, STR_4004, lastof(this->edit_str_buf));
  1410 		GetString(this->edit_str_buf, STR_4004, &this->edit_str_buf[this->edit_str_size - 1]);
  1418 		SanitizeFilename(this->edit_str_buf);
  1411 		SanitizeFilename(this->edit_str_buf);
  1419 	}
  1412 	}
  1420 
  1413 
  1421 	SaveLoadWindow(const WindowDesc *desc, SaveLoadDialogMode mode) : QueryStringBaseWindow(desc)
  1414 	SaveLoadWindow(const WindowDesc *desc, SaveLoadDialogMode mode) : QueryStringBaseWindow(64, desc)
  1422 	{
  1415 	{
  1423 		static const StringID saveload_captions[] = {
  1416 		static const StringID saveload_captions[] = {
  1424 			STR_4001_LOAD_GAME,
  1417 			STR_4001_LOAD_GAME,
  1425 			STR_0298_LOAD_SCENARIO,
  1418 			STR_0298_LOAD_SCENARIO,
  1426 			STR_4000_SAVE_GAME,
  1419 			STR_4000_SAVE_GAME,
  1443 
  1436 
  1444 		this->widget[1].data = saveload_captions[mode];
  1437 		this->widget[1].data = saveload_captions[mode];
  1445 		this->LowerWidget(7);
  1438 		this->LowerWidget(7);
  1446 
  1439 
  1447 		this->afilter = CS_ALPHANUMERAL;
  1440 		this->afilter = CS_ALPHANUMERAL;
  1448 		InitializeTextBuffer(&this->text, this->edit_str_buf, lengthof(this->edit_str_buf), 240);
  1441 		InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 240);
  1449 
  1442 
  1450 		/* pause is only used in single-player, non-editor mode, non-menu mode. It
  1443 		/* pause is only used in single-player, non-editor mode, non-menu mode. It
  1451 		 * will be unpaused in the WE_DESTROY event handler. */
  1444 		 * will be unpaused in the WE_DESTROY event handler. */
  1452 		if (_game_mode != GM_MENU && !_networking && _game_mode != GM_EDITOR) {
  1445 		if (_game_mode != GM_MENU && !_networking && _game_mode != GM_EDITOR) {
  1453 			if (_pause_game >= 0) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
  1446 			if (_pause_game >= 0) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);