From db370c1fd3d7fe99868881ab51c1fc6a0de9dc9d Mon Sep 17 00:00:00 2001 From: The Dax Date: Mon, 21 Oct 2013 16:52:44 -0400 Subject: [PATCH] Call the base class sendMessage when handling messages from native, so every screen can refresh from a language update at any time. --- UI/ControlMappingScreen.cpp | 6 +++--- UI/CwCheatScreen.cpp | 6 ------ UI/CwCheatScreen.h | 1 - UI/GameSettingsScreen.cpp | 12 +++--------- UI/GameSettingsScreen.h | 1 - UI/MainScreen.cpp | 8 +++++--- UI/MiscScreens.cpp | 14 ++++++++++++++ UI/MiscScreens.h | 2 ++ 8 files changed, 27 insertions(+), 23 deletions(-) diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index fd3429a6b6..14896fda2e 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -214,9 +214,9 @@ void ControlMappingScreen::CreateViews() { } void ControlMappingScreen::sendMessage(const char *message, const char *value) { - if (!strcmp(message, "language")) { - screenManager()->RecreateAllViews(); - } + // Always call the base class method first to handle the most common messages. + UIDialogScreenWithBackground::sendMessage(message, value); + if (!strcmp(message, "settings")) { UpdateUIState(UISTATE_MENU); screenManager()->push(new GameSettingsScreen("")); diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index 00137d7c20..42908315e6 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -92,12 +92,6 @@ void CwCheatScreen::CreateViews() { } } -void CwCheatScreen::sendMessage(const char *message, const char *value) { - if (!strcmp(message, "language")) { - screenManager()->RecreateAllViews(); - } -} - UI::EventReturn CwCheatScreen::OnBack(UI::EventParams ¶ms) { screenManager()->finishDialog(this, DR_OK); diff --git a/UI/CwCheatScreen.h b/UI/CwCheatScreen.h index 59f6cd5d08..8d6575fb93 100644 --- a/UI/CwCheatScreen.h +++ b/UI/CwCheatScreen.h @@ -42,7 +42,6 @@ public: UI::EventReturn OnEnableAll(UI::EventParams ¶ms); protected: virtual void CreateViews(); - virtual void sendMessage(const char *message, const char *value); private: UI::EventReturn OnCheckBox(UI::EventParams ¶ms); diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index d88febc42d..0f34c013ef 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -353,9 +353,9 @@ void GameSettingsScreen::update(InputState &input) { } void GameSettingsScreen::sendMessage(const char *message, const char *value) { - if (!strcmp(message, "language")) { - screenManager()->RecreateAllViews(); - } + // Always call the base class method first to handle the most common messages. + UIDialogScreenWithBackground::sendMessage(message, value); + if (!strcmp(message, "control mapping")) { UpdateUIState(UISTATE_MENU); screenManager()->push(new ControlMappingScreen()); @@ -502,12 +502,6 @@ void DeveloperToolsScreen::CreateViews() { list->Add(new Choice(d->T("Back")))->OnClick.Handle(this, &DeveloperToolsScreen::OnBack); } -void DeveloperToolsScreen::sendMessage(const char *message, const char *value){ - if (!strcmp(message, "language")) { - screenManager()->RecreateAllViews(); - } -} - UI::EventReturn DeveloperToolsScreen::OnBack(UI::EventParams &e) { screenManager()->finishDialog(this, DR_OK); diff --git a/UI/GameSettingsScreen.h b/UI/GameSettingsScreen.h index 575cdb12e5..14cdb03278 100644 --- a/UI/GameSettingsScreen.h +++ b/UI/GameSettingsScreen.h @@ -93,7 +93,6 @@ public: protected: virtual void CreateViews(); - virtual void sendMessage(const char *message, const char *value); private: UI::EventReturn OnBack(UI::EventParams &e); diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 34e6e5bb62..014e23d634 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -586,12 +586,12 @@ void MainScreen::CreateViews() { } void MainScreen::sendMessage(const char *message, const char *value) { + // Always call the base class method first to handle the most common messages. + UIScreenWithBackground::sendMessage(message, value); + if (!strcmp(message, "boot")) { screenManager()->switchScreen(new EmuScreen(value)); } - if (!strcmp(message, "language")) { - screenManager()->RecreateAllViews(); - } if (!strcmp(message, "control mapping")) { UpdateUIState(UISTATE_MENU); screenManager()->push(new ControlMappingScreen()); @@ -845,6 +845,8 @@ UI::EventReturn GamePauseScreen::OnCwCheat(UI::EventParams &e) { } void GamePauseScreen::sendMessage(const char *message, const char *value) { + // Since the language message isn't allowed to be in native, we have to have add this + // to every screen which directly inherits from UIScreen(which are few right now, luckily). if (!strcmp(message, "language")) { screenManager()->RecreateAllViews(); } diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index 7043071557..2b6da5797b 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -94,16 +94,30 @@ void DrawBackground(float alpha) { } } +void HandleCommonMessages(const char *message, const char *value, ScreenManager *manager) { + if (!strcmp(message, "language")) { + manager->RecreateAllViews(); + } +} + void UIScreenWithBackground::DrawBackground(UIContext &dc) { ::DrawBackground(1.0f); dc.Flush(); } +void UIScreenWithBackground::sendMessage(const char *message, const char *value) { + HandleCommonMessages(message, value, screenManager()); +} + void UIDialogScreenWithBackground::DrawBackground(UIContext &dc) { ::DrawBackground(1.0f); dc.Flush(); } +void UIDialogScreenWithBackground::sendMessage(const char *message, const char *value) { + HandleCommonMessages(message, value, screenManager()); +} + PromptScreen::PromptScreen(std::string message, std::string yesButtonText, std::string noButtonText, std::function callback) : message_(message), callback_(callback) { I18NCategory *d = GetI18NCategory("Dialog"); diff --git a/UI/MiscScreens.h b/UI/MiscScreens.h index 0fc2414a05..581b4a65fd 100644 --- a/UI/MiscScreens.h +++ b/UI/MiscScreens.h @@ -33,6 +33,7 @@ public: UIScreenWithBackground() : UIScreen() {} protected: virtual void DrawBackground(UIContext &dc); + virtual void sendMessage(const char *message, const char *value); }; class UIDialogScreenWithBackground : public UIDialogScreen { @@ -40,6 +41,7 @@ public: UIDialogScreenWithBackground() : UIDialogScreen() {} protected: virtual void DrawBackground(UIContext &dc); + virtual void sendMessage(const char *message, const char *value); }; class PromptScreen : public UIDialogScreenWithBackground {