diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index 47f622ab7b..c42d7d092c 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -149,7 +149,7 @@ struct AIListWindow : public Window { for (int i = 0; i < this->selected; i++) it++; AIConfig::GetConfig(slot)->Change((*it).second->GetName(), (*it).second->GetVersion()); } - SetWindowDirty(WC_GAME_OPTIONS, 0); + SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_AI); } virtual void OnClick(Point pt, int widget, int click_count) @@ -583,7 +583,7 @@ struct AIConfigWindow : public Window { AIConfigWindow() : Window() { - this->InitNested(&_ai_config_desc); // Initializes 'this->line_height' as a side effect. + this->InitNested(&_ai_config_desc, WN_GAME_OPTIONS_AI); // Initializes 'this->line_height' as a side effect. this->vscroll = this->GetScrollbar(WID_AIC_SCROLLBAR); this->selected_slot = INVALID_COMPANY; NWidgetCore *nwi = this->GetWidget(WID_AIC_LIST); @@ -752,7 +752,7 @@ struct AIConfigWindow : public Window { /** Open the AI config window. */ void ShowAIConfigWindow() { - DeleteWindowById(WC_GAME_OPTIONS, 0); + DeleteWindowByClass(WC_GAME_OPTIONS); new AIConfigWindow(); } diff --git a/src/bootstrap_gui.cpp b/src/bootstrap_gui.cpp index 64fa2479ac..91b87829b5 100644 --- a/src/bootstrap_gui.cpp +++ b/src/bootstrap_gui.cpp @@ -132,7 +132,7 @@ public: /** Start listening to the content client events. */ BootstrapAskForDownloadWindow() : Window() { - this->InitNested(&_bootstrap_query_desc); + this->InitNested(&_bootstrap_query_desc, WN_CONFIRM_POPUP_QUERY_BOOTSTRAP); _network_content_client.AddCallback(this); } diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 0ecd436717..5cd9650389 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -812,7 +812,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 if (ci == NULL) return CommandCost(); /* Delete multiplayer progress bar */ - DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); + DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); Company *c = DoStartupNewCompany(false); diff --git a/src/genworld.cpp b/src/genworld.cpp index beb9059b2b..e450aa2b9b 100644 --- a/src/genworld.cpp +++ b/src/genworld.cpp @@ -83,7 +83,7 @@ static void CleanupGeneration() _gw.abortp = NULL; _gw.threaded = false; - DeleteWindowById(WC_MODAL_PROGRESS, 0); + DeleteWindowByClass(WC_MODAL_PROGRESS); ShowFirstError(); MarkWholeScreenDirty(); } diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 354d6227b1..1bd488a462 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -443,7 +443,7 @@ struct AboutWindow : public Window { AboutWindow() : Window() { - this->InitNested(&_about_desc); + this->InitNested(&_about_desc, WN_GAME_OPTIONS_ABOUT); this->counter = 5; this->text_position = this->GetWidget(WID_A_SCROLLING_TEXT)->pos_y + this->GetWidget(WID_A_SCROLLING_TEXT)->current_y; @@ -501,7 +501,7 @@ struct AboutWindow : public Window { void ShowAboutWindow() { - DeleteWindowById(WC_GAME_OPTIONS, 0); + DeleteWindowByClass(WC_GAME_OPTIONS); new AboutWindow(); } @@ -1114,7 +1114,7 @@ struct QueryStringWindow : public QueryStringBaseWindow this->flags = flags; InitializeTextBuffer(&this->text, this->edit_str_buf, max_bytes, max_chars); - this->InitNested(desc); + this->InitNested(desc, WN_QUERY_STRING); this->parent = parent; @@ -1245,7 +1245,7 @@ static const WindowDesc _query_string_desc( */ void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags) { - DeleteWindowById(WC_QUERY_STRING, 0); + DeleteWindowByClass(WC_QUERY_STRING); new QueryStringWindow(str, caption, ((flags & QSF_LEN_IN_CHARS) ? MAX_CHAR_LENGTH : 1) * maxsize, maxsize, &_query_string_desc, parent, afilter, flags); } @@ -1267,7 +1267,7 @@ struct QueryWindow : public Window { this->message = message; this->proc = callback; - this->InitNested(desc); + this->InitNested(desc, WN_CONFIRM_POPUP_QUERY); this->parent = parent; this->left = parent->left + (parent->width / 2) - (this->width / 2); diff --git a/src/network/network.cpp b/src/network/network.cpp index dd47be1729..52c6cb4647 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -791,7 +791,7 @@ void NetworkDisconnect(bool blocking, bool close_admins) if (_settings_client.network.server_advertise) NetworkUDPRemoveAdvertise(blocking); - DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); + DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); NetworkClose(close_admins); diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index fd133dc548..0c7ef4536d 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -181,7 +181,7 @@ void ClientNetworkGameSocketHandler::ClientError(NetworkRecvStatus res) this->CloseConnection(res); _networking = false; - DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); + DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); return; } @@ -314,7 +314,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendCompanyInformationQuery() { my_client->status = STATUS_COMPANY_INFO; _network_join_status = NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO; - SetWindowDirty(WC_NETWORK_STATUS_WINDOW, 0); + SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); Packet *p = new Packet(PACKET_CLIENT_COMPANY_INFO); my_client->SendPacket(p); @@ -326,7 +326,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendJoin() { my_client->status = STATUS_JOIN; _network_join_status = NETWORK_JOIN_STATUS_AUTHORIZING; - SetWindowDirty(WC_NETWORK_STATUS_WINDOW, 0); + SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); Packet *p = new Packet(PACKET_CLIENT_JOIN); p->Send_string(_openttd_revision); @@ -531,7 +531,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FULL(Packet *p) { /* We try to join a server which is full */ ShowErrorMessage(STR_NETWORK_ERROR_SERVER_FULL, INVALID_STRING_ID, WL_CRITICAL); - DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); + DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); return NETWORK_RECV_STATUS_SERVER_FULL; } @@ -540,7 +540,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_BANNED(Packet * { /* We try to join a server where we are banned */ ShowErrorMessage(STR_NETWORK_ERROR_SERVER_BANNED, INVALID_STRING_ID, WL_CRITICAL); - DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); + DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); return NETWORK_RECV_STATUS_SERVER_BANNED; } @@ -578,7 +578,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMPANY_INFO(Pa p->Recv_string(company_info->clients, sizeof(company_info->clients)); - SetWindowDirty(WC_NETWORK_WINDOW, 0); + SetWindowDirty(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_GAME); return NETWORK_RECV_STATUS_OKAY; } @@ -675,7 +675,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p ShowErrorMessage(STR_NETWORK_ERROR_LOSTCONNECTION, INVALID_STRING_ID, WL_CRITICAL); } - DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); + DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); return NETWORK_RECV_STATUS_SERVER_ERROR; } @@ -770,7 +770,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_WAIT(Packet *p) /* But... only now we set the join status to waiting, instead of requesting. */ _network_join_status = NETWORK_JOIN_STATUS_WAITING; _network_join_waiting = p->Recv_uint8(); - SetWindowDirty(WC_NETWORK_STATUS_WINDOW, 0); + SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); return NETWORK_RECV_STATUS_OKAY; } @@ -790,7 +790,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN(Packe _network_join_bytes_total = 0; _network_join_status = NETWORK_JOIN_STATUS_DOWNLOADING; - SetWindowDirty(WC_NETWORK_STATUS_WINDOW, 0); + SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); return NETWORK_RECV_STATUS_OKAY; } @@ -801,7 +801,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_SIZE(Packet if (this->savegame == NULL) return NETWORK_RECV_STATUS_MALFORMED_PACKET; _network_join_bytes_total = p->Recv_uint32(); - SetWindowDirty(WC_NETWORK_STATUS_WINDOW, 0); + SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); return NETWORK_RECV_STATUS_OKAY; } @@ -815,7 +815,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DATA(Packet this->savegame->AddPacket(p); _network_join_bytes = (uint32)this->savegame->written_bytes; - SetWindowDirty(WC_NETWORK_STATUS_WINDOW, 0); + SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); return NETWORK_RECV_STATUS_OKAY; } @@ -826,7 +826,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet if (this->savegame == NULL) return NETWORK_RECV_STATUS_MALFORMED_PACKET; _network_join_status = NETWORK_JOIN_STATUS_PROCESSING; - SetWindowDirty(WC_NETWORK_STATUS_WINDOW, 0); + SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); /* * Make sure everything is set for reading. @@ -847,7 +847,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet this->last_packet = _realtime_tick; if (!load_success) { - DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); + DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); ShowErrorMessage(STR_NETWORK_ERROR_SAVEGAMEERROR, INVALID_STRING_ID, WL_CRITICAL); return NETWORK_RECV_STATUS_SAVEGAME; } diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp index 6499e52746..0e08cb705e 100644 --- a/src/network/network_content.cpp +++ b/src/network/network_content.cpp @@ -475,7 +475,7 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_CONTENT(Packet *p) /* We have a file opened, thus are downloading internal content */ size_t toRead = (size_t)(p->size - p->pos); if (fwrite(p->buffer + p->pos, 1, toRead, this->curFile) != toRead) { - DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); + DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD); ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD, STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD_FILE_NOT_WRITABLE, WL_ERROR); this->Close(); fclose(this->curFile); @@ -509,7 +509,7 @@ bool ClientNetworkContentSocketHandler::BeforeDownload() const char *filename = GetFullFilename(this->curInfo, true); if (filename == NULL || (this->curFile = fopen(filename, "wb")) == NULL) { /* Unless that fails ofcourse... */ - DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); + DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD); ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD, STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD_FILE_NOT_WRITABLE, WL_ERROR); return false; } diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index a4981124a6..4eef3e502e 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -55,7 +55,7 @@ BaseNetworkContentDownloadStatusWindow::BaseNetworkContentDownloadStatusWindow(c _network_content_client.AddCallback(this); _network_content_client.DownloadSelectedContent(this->total_files, this->total_bytes); - this->InitNested(desc, 0); + this->InitNested(desc, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD); } BaseNetworkContentDownloadStatusWindow::~BaseNetworkContentDownloadStatusWindow() @@ -117,7 +117,7 @@ public: */ NetworkContentDownloadStatusWindow() : BaseNetworkContentDownloadStatusWindow(&_network_content_download_status_window_desc) { - this->parent = FindWindowById(WC_NETWORK_WINDOW, 1); + this->parent = FindWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_CONTENT_LIST); } /** Free whatever we've allocated */ @@ -163,17 +163,17 @@ public: case CONTENT_TYPE_BASE_GRAPHICS: BaseGraphics::FindSets(); - SetWindowDirty(WC_GAME_OPTIONS, 0); + SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS); break; case CONTENT_TYPE_BASE_SOUNDS: BaseSounds::FindSets(); - SetWindowDirty(WC_GAME_OPTIONS, 0); + SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS); break; case CONTENT_TYPE_BASE_MUSIC: BaseMusic::FindSets(); - SetWindowDirty(WC_GAME_OPTIONS, 0); + SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS); break; case CONTENT_TYPE_NEWGRF: @@ -193,7 +193,7 @@ public: } /* Always invalidate the download window; tell it we are going to be gone */ - InvalidateWindowData(WC_NETWORK_WINDOW, 1, 2); + InvalidateWindowData(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_CONTENT_LIST, 2); } virtual void OnClick(Point pt, int widget, int click_count) @@ -205,7 +205,7 @@ public: } else { /* If downloading succeeded, close the online content window. This will close * the current window as well. */ - DeleteWindowById(WC_NETWORK_WINDOW, 1); + DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_CONTENT_LIST); } } } @@ -357,7 +357,7 @@ public: { this->CreateNestedTree(desc); this->vscroll = this->GetScrollbar(WID_NCL_SCROLLBAR); - this->FinishInitNested(desc, 1); + this->FinishInitNested(desc, WN_NETWORK_WINDOW_CONTENT_LIST); this->GetWidget(WID_NCL_SEL_ALL_UPDATE)->SetDisplayedPlane(select_all); @@ -658,7 +658,7 @@ public: break; case WID_NCL_DOWNLOAD: - if (BringWindowToFrontById(WC_NETWORK_STATUS_WINDOW, 0) == NULL) new NetworkContentDownloadStatusWindow(); + if (BringWindowToFrontById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD) == NULL) new NetworkContentDownloadStatusWindow(); break; } } @@ -801,7 +801,7 @@ public: } /* If data == 2 then the status window caused this OnInvalidate */ - this->SetWidgetDisabledState(WID_NCL_DOWNLOAD, this->filesize_sum == 0 || (FindWindowById(WC_NETWORK_STATUS_WINDOW, 0) != NULL && data != 2)); + this->SetWidgetDisabledState(WID_NCL_DOWNLOAD, this->filesize_sum == 0 || (FindWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD) != NULL && data != 2)); this->SetWidgetDisabledState(WID_NCL_UNSELECT, this->filesize_sum == 0); this->SetWidgetDisabledState(WID_NCL_SELECT_ALL, !show_select_all); this->SetWidgetDisabledState(WID_NCL_SELECT_UPDATE, !show_select_upgrade); @@ -915,7 +915,7 @@ void ShowNetworkContentListWindow(ContentVector *cv, ContentType type) _network_content_client.RequestContentList(cv, true); } - DeleteWindowById(WC_NETWORK_WINDOW, 1); + DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_CONTENT_LIST); new NetworkContentListWindow(&_network_content_list_desc, cv != NULL); #else ShowErrorMessage(STR_CONTENT_NO_ZLIB, STR_CONTENT_NO_ZLIB_SUB, WL_ERROR); diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 3d84bd3736..82d74bb2fd 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -74,7 +74,7 @@ void SortNetworkLanguages() */ void UpdateNetworkGameWindow(bool unselect) { - InvalidateWindowData(WC_NETWORK_WINDOW, 0, unselect ? 1 : 0); + InvalidateWindowData(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_GAME, unselect ? 1 : 0); } typedef GUIList GUIGameServerList; @@ -425,7 +425,7 @@ public: { this->CreateNestedTree(desc); this->vscroll = this->GetScrollbar(WID_NG_SCROLLBAR); - this->FinishInitNested(desc, 0); + this->FinishInitNested(desc, WN_NETWORK_WINDOW_GAME); ttd_strlcpy(this->edit_str_buf, _settings_client.network.client_name, this->edit_str_size); this->afilter = CS_ALPHANUMERAL; @@ -651,7 +651,7 @@ public: this->field = widget; switch (widget) { case WID_NG_CANCEL: // Cancel button - DeleteWindowById(WC_NETWORK_WINDOW, 0); + DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_GAME); break; case WID_NG_CONN_BTN: // 'Connection' droplist @@ -980,7 +980,8 @@ static const WindowDesc _network_game_window_desc( void ShowNetworkGameWindow() { static bool first = true; - DeleteWindowById(WC_NETWORK_WINDOW, 0); + DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_LOBBY); + DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_START); /* Only show once */ if (first) { @@ -1000,7 +1001,7 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow { NetworkStartServerWindow(const WindowDesc *desc) : QueryStringBaseWindow(NETWORK_NAME_LENGTH) { - this->InitNested(desc, 0); + this->InitNested(desc, WN_NETWORK_WINDOW_START); ttd_strlcpy(this->edit_str_buf, _settings_client.network.server_name, this->edit_str_size); @@ -1316,7 +1317,8 @@ static const WindowDesc _network_start_server_window_desc( static void ShowNetworkStartServerWindow() { - DeleteWindowById(WC_NETWORK_WINDOW, 0); + DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_GAME); + DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_LOBBY); new NetworkStartServerWindow(&_network_start_server_window_desc); } @@ -1332,7 +1334,7 @@ struct NetworkLobbyWindow : public Window { { this->CreateNestedTree(desc); this->vscroll = this->GetScrollbar(WID_NL_SCROLLBAR); - this->FinishInitNested(desc, 0); + this->FinishInitNested(desc, WN_NETWORK_WINDOW_LOBBY); this->OnResize(); } @@ -1608,7 +1610,8 @@ static const WindowDesc _network_lobby_window_desc( */ static void ShowNetworkLobbyWindow(NetworkGameList *ngl) { - DeleteWindowById(WC_NETWORK_WINDOW, 0); + DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_START); + DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_GAME); NetworkTCPQueryServer(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port)); // company info NetworkUDPQueryServer(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port)); // general data @@ -1623,7 +1626,7 @@ static void ShowNetworkLobbyWindow(NetworkGameList *ngl) */ NetworkCompanyInfo *GetLobbyCompanyInfo(CompanyID company) { - NetworkLobbyWindow *lobby = dynamic_cast(FindWindowById(WC_NETWORK_WINDOW, 0)); + NetworkLobbyWindow *lobby = dynamic_cast(FindWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_LOBBY)); return (lobby != NULL && company < MAX_COMPANIES) ? &lobby->company_info[company] : NULL; } @@ -1990,8 +1993,8 @@ struct NetworkJoinStatusWindow : Window { NetworkJoinStatusWindow(const WindowDesc *desc) : Window() { - this->parent = FindWindowById(WC_NETWORK_WINDOW, 0); - this->InitNested(desc, 0); + this->parent = FindWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_GAME); + this->InitNested(desc, WN_NETWORK_STATUS_WINDOW_JOIN); } virtual void DrawWidget(const Rect &r, int widget) const @@ -2100,13 +2103,13 @@ static const WindowDesc _network_join_status_window_desc( void ShowJoinStatusWindow() { - DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); + DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); new NetworkJoinStatusWindow(&_network_join_status_window_desc); } void ShowNetworkNeedPassword(NetworkPasswordType npt) { - NetworkJoinStatusWindow *w = (NetworkJoinStatusWindow *)FindWindowById(WC_NETWORK_STATUS_WINDOW, 0); + NetworkJoinStatusWindow *w = (NetworkJoinStatusWindow *)FindWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); if (w == NULL) return; w->password_type = npt; diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index 6333a24d0d..9ce75b679d 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -277,7 +277,7 @@ void GRFParameterInfo::SetValue(struct GRFConfig *config, uint32 value) SB(config->param[this->param_nr], this->first_bit, this->num_bit, value); } config->num_params = max(config->num_params, this->param_nr + 1); - SetWindowClassesDirty(WC_GAME_OPTIONS); // Is always the newgrf window + SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE); } /** @@ -688,7 +688,7 @@ void DoScanNewGRFFiles(void *callback) /* Yes... these are the NewGRF windows */ InvalidateWindowClassesData(WC_SAVELOAD, 0, true); - InvalidateWindowData(WC_GAME_OPTIONS, 0, GOID_NEWGRF_RESCANNED, true); + InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE, GOID_NEWGRF_RESCANNED, true); if (callback != NULL) ((NewGRFScanCallback*)callback)->OnNewGRFsScanned(); DeleteWindowByClass(WC_MODAL_PROGRESS); diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 24f5f1d60d..b60bd080f3 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -284,7 +284,7 @@ struct NewGRFParametersWindow : public Window { if (!this->action14present && this->grf_config->num_params > 0) { this->grf_config->num_params--; this->InvalidateData(); - SetWindowClassesDirty(WC_GAME_OPTIONS); // Is always the newgrf window + SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE); } break; @@ -293,7 +293,7 @@ struct NewGRFParametersWindow : public Window { if (!this->action14present && c->num_params < c->num_valid_params) { c->param[c->num_params++] = 0; this->InvalidateData(); - SetWindowClassesDirty(WC_GAME_OPTIONS); // Is always the newgrf window + SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE); } break; } @@ -349,7 +349,7 @@ struct NewGRFParametersWindow : public Window { case WID_NP_RESET: this->grf_config->SetParameterDefaults(); this->InvalidateData(); - SetWindowClassesDirty(WC_GAME_OPTIONS); // Is always the newgrf window + SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE); break; case WID_NP_ACCEPT: @@ -727,7 +727,7 @@ struct NewGRFWindow : public QueryStringBaseWindow, NewGRFScanCallback { this->GetWidget(WID_NS_SHOW_REMOVE)->SetDisplayedPlane(this->editable ? 0 : 1); this->GetWidget(WID_NS_SHOW_APPLY)->SetDisplayedPlane(this->editable ? 0 : SZSP_HORIZONTAL); - this->FinishInitNested(desc); + this->FinishInitNested(desc, WN_GAME_OPTIONS_NEWGRF_STATE); InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size); this->SetFocusedWidget(WID_NS_FILTER); @@ -1940,7 +1940,7 @@ struct ScanProgressWindow : public Window { /** Create the window. */ ScanProgressWindow() : Window(), last_name(NULL), scanned(0) { - this->InitNested(&_scan_progress_desc); + this->InitNested(&_scan_progress_desc, 1); } /** Free the last name buffer. */ diff --git a/src/news_gui.cpp b/src/news_gui.cpp index f5fa83ab2d..a20be0f9f6 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -1089,7 +1089,7 @@ struct MessageOptionsWindow : Window { MessageOptionsWindow(const WindowDesc *desc) : Window() { - this->InitNested(desc); + this->InitNested(desc, WN_GAME_OPTIONS_MESSAGE_OPTION); /* Set up the initial disabled buttons in the case of 'off' or 'full' */ NewsDisplay all_val = _news_type_data[0].display; for (int i = 0; i < NT_END; i++) { @@ -1345,6 +1345,6 @@ static const WindowDesc _message_options_desc( */ void ShowMessageOptions() { - DeleteWindowById(WC_GAME_OPTIONS, 0); + DeleteWindowByClass(WC_GAME_OPTIONS); new MessageOptionsWindow(&_message_options_desc); } diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index a7d7c36a4d..ea0152bf0c 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -414,9 +414,9 @@ struct BuildRailToolbarWindow : Window { RailType railtype; ///< Rail type to build. int last_user_action; ///< Last started user action. - BuildRailToolbarWindow(const WindowDesc *desc, WindowNumber window_number, RailType railtype) : Window() + BuildRailToolbarWindow(const WindowDesc *desc, RailType railtype) : Window() { - this->InitNested(desc); + this->InitNested(desc, TRANSPORT_RAIL); this->SetupRailToolbar(railtype); this->DisableWidget(WID_RAT_REMOVE); this->last_user_action = WIDGET_LIST_END; @@ -735,6 +735,7 @@ struct BuildRailToolbarWindow : Window { DeleteWindowById(WC_BUILD_SIGNAL, TRANSPORT_RAIL); DeleteWindowById(WC_BUILD_STATION, TRANSPORT_RAIL); DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_RAIL); + DeleteWindowById(WC_BUILD_WAYPOINT, TRANSPORT_RAIL); DeleteWindowById(WC_SELECT_STATION, 0); DeleteWindowByClass(WC_BUILD_BRIDGE); } @@ -841,7 +842,7 @@ Window *ShowBuildRailToolbar(RailType railtype) DeleteWindowByClass(WC_BUILD_TOOLBAR); _cur_railtype = railtype; _remove_button_clicked = false; - return new BuildRailToolbarWindow(&_build_rail_desc, TRANSPORT_RAIL, railtype); + return new BuildRailToolbarWindow(&_build_rail_desc, railtype); } EventState RailToolbarGlobalHotkeys(uint16 key, uint16 keycode) @@ -1533,14 +1534,14 @@ public: case WID_BS_DRAG_SIGNALS_DENSITY_DECREASE: if (_settings_client.gui.drag_signals_density > 1) { _settings_client.gui.drag_signals_density--; - SetWindowDirty(WC_GAME_OPTIONS, 0); + SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_SETTINGS); } break; case WID_BS_DRAG_SIGNALS_DENSITY_INCREASE: if (_settings_client.gui.drag_signals_density < 20) { _settings_client.gui.drag_signals_density++; - SetWindowDirty(WC_GAME_OPTIONS, 0); + SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_SETTINGS); } break; @@ -1777,7 +1778,7 @@ static const NWidgetPart _nested_build_waypoint_widgets[] = { static const WindowDesc _build_waypoint_desc( WDP_AUTO, 0, 0, - WC_BUILD_DEPOT, WC_BUILD_TOOLBAR, + WC_BUILD_WAYPOINT, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, _nested_build_waypoint_widgets, lengthof(_nested_build_waypoint_widgets) ); diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 8ac0306d49..3b23e9c01d 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -826,7 +826,7 @@ static const WindowDesc _build_road_scen_desc( Window *ShowBuildRoadScenToolbar() { _cur_roadtype = ROADTYPE_ROAD; - return AllocateWindowDescFront(&_build_road_scen_desc, 0); + return AllocateWindowDescFront(&_build_road_scen_desc, TRANSPORT_ROAD); } EventState RoadToolbarEditorGlobalHotkeys(uint16 key, uint16 keycode) diff --git a/src/settings.cpp b/src/settings.cpp index a4ee25997e..6052df34f1 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1717,7 +1717,7 @@ CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uin GamelogStopAction(); } - SetWindowDirty(WC_GAME_OPTIONS, 0); + SetWindowClassesDirty(WC_GAME_OPTIONS); } return CommandCost(); @@ -1754,7 +1754,7 @@ CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32 return CommandCost(); } - SetWindowDirty(WC_GAME_OPTIONS, 0); + SetWindowClassesDirty(WC_GAME_OPTIONS); } return CommandCost(); @@ -1783,7 +1783,9 @@ bool SetSettingValue(uint index, int32 value, bool force_newgame) Write_ValidateSetting(var2, sd, value); } if (sd->desc.proc != NULL) sd->desc.proc((int32)ReadValue(var, sd->save.conv)); - SetWindowDirty(WC_GAME_OPTIONS, 0); + + SetWindowClassesDirty(WC_GAME_OPTIONS); + return true; } diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 5afcd541f7..681b0ca583 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -130,7 +130,7 @@ struct GameOptionsWindow : Window { this->opt = &GetGameSettings(); this->reload = false; - this->InitNested(desc); + this->InitNested(desc, WN_GAME_OPTIONS_GAME_OPTIONS); this->OnInvalidateData(0); } @@ -464,7 +464,7 @@ struct GameOptionsWindow : Window { case WID_GO_TOWNNAME_DROPDOWN: // Town names if (_game_mode == GM_MENU || Town::GetNumItems() == 0) { this->opt->game_creation.town_name = index; - SetWindowDirty(WC_GAME_OPTIONS, 0); + SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS); } break; @@ -603,7 +603,7 @@ static const WindowDesc _game_options_desc( /** Open the game options window. */ void ShowGameOptions() { - DeleteWindowById(WC_GAME_OPTIONS, 0); + DeleteWindowByClass(WC_GAME_OPTIONS); new GameOptionsWindow(&_game_options_desc); } @@ -624,7 +624,7 @@ public: GameDifficultyWindow(const WindowDesc *desc) : Window() { - this->InitNested(desc); + this->InitNested(desc, WN_GAME_OPTIONS_GAME_DIFFICULTY); /* Setup disabled buttons when creating window * disable all other difficulty buttons during gameplay except for 'custom' */ @@ -879,7 +879,7 @@ static const WindowDesc _game_difficulty_desc( /** Open the game-difficulty window. */ void ShowGameDifficulty() { - DeleteWindowById(WC_GAME_OPTIONS, 0); + DeleteWindowByClass(WC_GAME_OPTIONS); new GameDifficultyWindow(&_game_difficulty_desc); } @@ -1594,7 +1594,7 @@ struct GameSettingsWindow : Window { this->CreateNestedTree(desc); this->vscroll = this->GetScrollbar(WID_GS_SCROLLBAR); - this->FinishInitNested(desc, 0); + this->FinishInitNested(desc, WN_GAME_OPTIONS_GAME_SETTINGS); this->vscroll->SetCount(_settings_main_page.Length()); } @@ -1793,7 +1793,7 @@ static const WindowDesc _settings_selection_desc( /** Open advanced settings window. */ void ShowGameSettings() { - DeleteWindowById(WC_GAME_OPTIONS, 0); + DeleteWindowByClass(WC_GAME_OPTIONS); new GameSettingsWindow(&_settings_selection_desc); } diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp index cd71227b26..589af1cae5 100644 --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -479,7 +479,7 @@ struct SignWindow : QueryStringBaseWindow, SignList { this->caption = STR_EDIT_SIGN_CAPTION; this->afilter = CS_ALPHANUMERAL; - this->InitNested(desc); + this->InitNested(desc, WN_QUERY_STRING_SIGN); this->LowerWidget(WID_QES_TEXT); UpdateSignEditWindow(si); @@ -656,7 +656,7 @@ void HandleClickOnSign(const Sign *si) void ShowRenameSignWindow(const Sign *si) { /* Delete all other edit windows */ - DeleteWindowById(WC_QUERY_STRING, 0); + DeleteWindowByClass(WC_QUERY_STRING); new SignWindow(&_query_sign_edit_desc, si); } @@ -667,7 +667,7 @@ void ShowRenameSignWindow(const Sign *si) */ void DeleteRenameSignWindow(SignID sign) { - SignWindow *w = dynamic_cast(FindWindowById(WC_QUERY_STRING, 0)); + SignWindow *w = dynamic_cast(FindWindowById(WC_QUERY_STRING, WN_QUERY_STRING_SIGN)); if (w != NULL && w->cur_sign == sign) delete w; } diff --git a/src/window_type.h b/src/window_type.h index 38e956dff3..975103667c 100644 --- a/src/window_type.h +++ b/src/window_type.h @@ -12,6 +12,33 @@ #ifndef WINDOW_TYPE_H #define WINDOW_TYPE_H +/** + * Window numbers. + */ +enum WindowNumberEnum { + WN_GAME_OPTIONS_AI = 0, ///< AI settings. + WN_GAME_OPTIONS_ABOUT, ///< About window. + WN_GAME_OPTIONS_NEWGRF_STATE, ///< NewGRF settings. + WN_GAME_OPTIONS_MESSAGE_OPTION, ///< News settings. + WN_GAME_OPTIONS_GAME_OPTIONS, ///< Game options. + WN_GAME_OPTIONS_GAME_DIFFICULTY, ///< Game difficulty. + WN_GAME_OPTIONS_GAME_SETTINGS, ///< Game settings. + + WN_QUERY_STRING = 0, ///< Query string. + WN_QUERY_STRING_SIGN, ///< Query string for signs. + + WN_CONFIRM_POPUP_QUERY = 0, ///< Query popup confirm. + WN_CONFIRM_POPUP_QUERY_BOOTSTRAP, ///< Query popup confirm for bootstrap. + + WN_NETWORK_WINDOW_GAME = 0, ///< Network game window. + WN_NETWORK_WINDOW_LOBBY, ///< Network lobby window. + WN_NETWORK_WINDOW_CONTENT_LIST, ///< Network content list. + WN_NETWORK_WINDOW_START, ///< Network start server. + + WN_NETWORK_STATUS_WINDOW_JOIN = 0, ///< Network join status. + WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD, ///< Network content download status. +}; + /** * Window classes. */ @@ -39,7 +66,7 @@ enum WindowClass { /** * Build toolbar; Window numbers: - * - 0 = #RailToolbarWidgets + * - #TRANSPORT_RAIL = #RailToolbarWidgets * - #TRANSPORT_AIR = #AirportToolbarWidgets * - #TRANSPORT_WATER = #DockToolbarWidgets * - #TRANSPORT_ROAD = #RoadToolbarWidgets @@ -48,8 +75,8 @@ enum WindowClass { /** * Scenario build toolbar; Window numbers: - * - 0 = #RoadToolbarWidgets * - #TRANSPORT_WATER = #DockToolbarWidgets + * - #TRANSPORT_ROAD = #RoadToolbarWidgets */ WC_SCEN_BUILD_TOOLBAR, @@ -90,16 +117,16 @@ enum WindowClass { WC_TOOLTIPS, /** - * Query string window; Window numbers: (TODO - CONFLICT) - * - 0 = #QueryStringWidgets - * - 0 = #QueryEditSignWidgets + * Query string window; Window numbers: + * - #WN_QUERY_STRING = #QueryStringWidgets + * - #WN_QUERY_STRING_SIGN = #QueryEditSignWidgets */ WC_QUERY_STRING, /** - * Popup with confirm question; Window numbers: (TODO - CONFLICT) - * - 0 = #BootstrapAskForDownloadWidgets - * - 0 = #QueryWidgets + * Popup with confirm question; Window numbers: + * - #WN_CONFIRM_POPUP_QUERY = #QueryWidgets + * - #WN_CONFIRM_POPUP_QUERY_BOOTSTRAP = #BootstrapAskForDownloadWidgets */ WC_CONFIRM_POPUP_QUERY, @@ -365,14 +392,19 @@ enum WindowClass { WC_TRUCK_STATION, /** - * Build depot; Window numbers: (TODO - CONFLICT) + * Build depot; Window numbers: * - #TRANSPORT_WATER = #BuildDockDepotWidgets * - #TRANSPORT_RAIL = #BuildRailDepotWidgets - * - #TRANSPORT_RAIL = #BuildRailWaypointWidgets * - #TRANSPORT_ROAD = #BuildRoadDepotWidgets */ WC_BUILD_DEPOT, + /** + * Build waypoint; Window numbers: + * - #TRANSPORT_RAIL = #BuildRailWaypointWidgets + */ + WC_BUILD_WAYPOINT, + /** * Found a town; Window numbers: * - 0 = #TownFoundingWidgets @@ -407,19 +439,19 @@ enum WindowClass { WC_GENERATE_LANDSCAPE, /** - * Progress report of landscape generation; Window numbers: (TODO - CONFLICT) + * Progress report of landscape generation; Window numbers: * - 0 = #GenerationProgressWidgets - * - 0 = #ScanProgressWidgets + * - 1 = #ScanProgressWidgets */ WC_MODAL_PROGRESS, /** - * Network window; Window numbers: (TODO - CONFLICT) - * - 0 = #NetworkGameWidgets - * - 0 = #NetworkLobbyWidgets - * - 1 = #NetworkContentListWidgets - * - 1 = #NetworkStartServerWidgets + * Network window; Window numbers: + * - #WN_NETWORK_WINDOW_GAME = #NetworkGameWidgets + * - #WN_NETWORK_WINDOW_LOBBY = #NetworkLobbyWidgets + * - #WN_NETWORK_WINDOW_CONTENT_LIST = #NetworkContentListWidgets + * - #WN_NETWORK_WINDOW_START = #NetworkStartServerWidgets */ WC_NETWORK_WINDOW, @@ -436,9 +468,9 @@ enum WindowClass { WC_CLIENT_LIST_POPUP, /** - * Network status window; Window numbers: (TODO - CONFLICT) - * - 0 = #NetworkJoinStatusWidgets - * - 0 = #NetworkContentDownloadStatusWidgets + * Network status window; Window numbers: + * - #WN_NETWORK_STATUS_WINDOW_JOIN = #NetworkJoinStatusWidgets + * - #WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD = #NetworkContentDownloadStatusWidgets */ WC_NETWORK_STATUS_WINDOW, @@ -554,14 +586,14 @@ enum WindowClass { WC_MUSIC_TRACK_SELECTION, /** - * Game options window; Window numbers: (TODO - CONFLICT) - * - 0 = #AIConfigWidgets - * - 0 = #AboutWidgets - * - 0 = #NewGRFStateWidgets - * - 0 = #MessageOptionWidgets - * - 0 = #GameOptionsWidgets - * - 0 = #GameDifficultyWidgets - * - 0 = #GameSettingsWidgets + * Game options window; Window numbers: + * - #WN_GAME_OPTIONS_AI = #AIConfigWidgets + * - #WN_GAME_OPTIONS_ABOUT = #AboutWidgets + * - #WN_GAME_OPTIONS_NEWGRF_STATE = #NewGRFStateWidgets + * - #WN_GAME_OPTIONS_MESSAGE_OPTION = #MessageOptionWidgets + * - #WN_GAME_OPTIONS_GAME_OPTIONS = #GameOptionsWidgets + * - #WN_GAME_OPTIONS_GAME_DIFFICULTY = #GameDifficultyWidgets + * - #WN_GAME_OPTIONS_GAME_SETTINGS = #GameSettingsWidgets */ WC_GAME_OPTIONS,