From 1e6b6bde884382c49e8c1fe4a234cf262995e81e Mon Sep 17 00:00:00 2001 From: dP Date: Wed, 1 Sep 2021 22:28:14 +0300 Subject: [PATCH] Add new company/spectate option back to the company toolbar dropdown --- src/lang/english.txt | 3 +++ src/toolbar_gui.cpp | 29 +++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index 10dc2a50e9..1e7837a9a6 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -5660,3 +5660,6 @@ STR_CM_LOGIN_WINDOW_CHANGE_PASSWORD_HELPTEXT :{BLACK}Change password STR_CM_LOGIN_WINDOW_SIGN_IN_HELPTEXT :{BLACK}Sign in (you must be on the correct community server) STR_CM_LOGIN_WINDOW_USERNAME_DISPLAY :{WHITE}{RAW_STRING} STR_CM_LOGIN_WINDOW_PASSWORD_DISPLAY :{WHITE}{STRING} + +STR_CM_NETWORK_COMPANY_LIST_NEW_COMPANY :New company +STR_CM_NETWORK_COMPANY_LIST_SPECTATE :Spectate diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index db10c34767..3d84c5a54e 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -214,7 +214,9 @@ static void PopupMainToolbMenu(Window *w, int widget, StringID string, int count /** Enum for the Company Toolbar's network related buttons */ static const int CTMN_CLIENT_LIST = -1; ///< Show the client list -static const int CTMN_SPECTATOR = -2; ///< Show a company window as spectator +static const int CTMN_SPECTATE = -2; ///< Become spectator +static const int CTMN_NEW_COMPANY = -3; ///< Create a new company +static const int CTMN_SPECTATOR = -4; ///< Show a company window as spectator /** * Pop up a generic company list menu. @@ -232,8 +234,13 @@ static void PopupMainCompanyToolbMenu(Window *w, int widget, int grey = 0) /* Add the client list button for the companies menu */ list.emplace_back(new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_CLIENT_LIST, CTMN_CLIENT_LIST, false)); - break; + if (_local_company == COMPANY_SPECTATOR) { + list.emplace_back(new DropDownListStringItem(STR_CM_NETWORK_COMPANY_LIST_NEW_COMPANY, CTMN_NEW_COMPANY, NetworkMaxCompaniesReached())); + } else { + list.emplace_back(new DropDownListStringItem(STR_CM_NETWORK_COMPANY_LIST_SPECTATE, CTMN_SPECTATE, false)); + } + break; case WID_TN_STORY: list.emplace_back(new DropDownListStringItem(STR_STORY_BOOK_SPECTATOR, CTMN_SPECTATOR, false)); break; @@ -659,6 +666,24 @@ static CallBackFunction MenuClickCompany(int index) case CTMN_CLIENT_LIST: ShowClientList(); return CBF_NONE; + + case CTMN_NEW_COMPANY: + if (_network_server) { + DoCommandP(0, CCA_NEW, _network_own_client_id, CMD_COMPANY_CTRL); + } else { + NetworkSendCommand(0, CCA_NEW, 0, CMD_COMPANY_CTRL, nullptr, {}, _local_company); + } + return CBF_NONE; + + + case CTMN_SPECTATE: + if (_network_server) { + NetworkServerDoMove(CLIENT_ID_SERVER, COMPANY_SPECTATOR); + MarkWholeScreenDirty(); + } else { + NetworkClientRequestMove(COMPANY_SPECTATOR); + } + return CBF_NONE; } } ShowCompany((CompanyID)index);