Permalink
Browse files

UI: Cleanup common message handling.

Most of it can just be handled by the common parent classes.
  • Loading branch information...
unknownbrackets committed Dec 2, 2017
1 parent e945ad6 commit f1bd54148b8e739b1cd3fcbf59605419e7276d46
@@ -252,16 +252,6 @@ void ControlMappingScreen::CreateViews() {
}
}
void ControlMappingScreen::sendMessage(const char *message, const char *value) {
// Always call the base class method first to handle the most common messages.
UIDialogScreenWithBackground::sendMessage(message, value);
if (!strcmp(message, "settings") && screenManager()->topScreen() == this) {
UpdateUIState(UISTATE_MENU);
screenManager()->push(new GameSettingsScreen(""));
}
}
UI::EventReturn ControlMappingScreen::OnClearMapping(UI::EventParams &params) {
KeyMap::g_controllerMap.clear();
RecreateViews();
@@ -35,7 +35,6 @@ class ControlMappingScreen : public UIDialogScreenWithBackground {
void KeyMapped(int pspkey); // Notification to let us refocus the same one after recreating views.
protected:
virtual void CreateViews() override;
virtual void sendMessage(const char *message, const char *value) override;
private:
UI::EventReturn OnDefaultMapping(UI::EventParams &params);
UI::EventReturn OnClearMapping(UI::EventParams &params);
View
@@ -1032,20 +1032,6 @@ void GameSettingsScreen::update() {
}
}
void GameSettingsScreen::sendMessage(const char *message, const char *value) {
// Always call the base class method first to handle the most common messages.
UIDialogScreenWithBackground::sendMessage(message, value);
if (!strcmp(message, "control mapping") && screenManager()->topScreen() == this) {
UpdateUIState(UISTATE_MENU);
screenManager()->push(new ControlMappingScreen());
}
if (!strcmp(message, "display layout editor") && screenManager()->topScreen() == this) {
UpdateUIState(UISTATE_MENU);
screenManager()->push(new DisplayLayoutScreen());
}
}
void GameSettingsScreen::onFinish(DialogResult result) {
if (g_Config.bEnableSound) {
if (PSP_IsInited() && !IsAudioInitialised())
View
@@ -35,7 +35,6 @@ class GameSettingsScreen : public UIDialogScreenWithGameBackground {
protected:
virtual void CreateViews();
virtual void sendMessage(const char *message, const char *value);
void CallbackRestoreDefaults(bool yes);
void CallbackRenderingBackend(bool yes);
bool UseVerticalLayout() const;
View
@@ -938,10 +938,6 @@ void MainScreen::sendMessage(const char *message, const char *value) {
if (!strcmp(message, "boot") && screenManager()->topScreen() == this) {
screenManager()->switchScreen(new EmuScreen(value));
}
if (!strcmp(message, "settings") && screenManager()->topScreen() == this) {
UpdateUIState(UISTATE_MENU);
screenManager()->push(new GameSettingsScreen(""));
}
if (!strcmp(message, "permission_granted") && !strcmp(value, "storage")) {
RecreateViews();
}
View
@@ -156,19 +156,35 @@ void DrawGameBackground(UIContext &dc, const std::string &gamePath) {
}
void HandleCommonMessages(const char *message, const char *value, ScreenManager *manager, Screen *activeScreen) {
bool isActiveScreen = manager->topScreen() == activeScreen;
if (!strcmp(message, "clear jit")) {
if (MIPSComp::jit && PSP_IsInited()) {
MIPSComp::jit->ClearCache();
}
if (PSP_IsInited()) {
currentMIPS->UpdateCore((CPUCore)g_Config.iCpuCore);
}
} else if (!strcmp(message, "control mapping") && manager->topScreen() == activeScreen) {
} else if (!strcmp(message, "control mapping") && isActiveScreen) {
UpdateUIState(UISTATE_MENU);
manager->push(new ControlMappingScreen());
} else if (!strcmp(message, "display layout editor") && manager->topScreen() == activeScreen) {
} else if (!strcmp(message, "display layout editor") && isActiveScreen) {
UpdateUIState(UISTATE_MENU);
manager->push(new DisplayLayoutScreen());
} else if (!strcmp(message, "settings") && isActiveScreen) {
UpdateUIState(UISTATE_MENU);
manager->push(new GameSettingsScreen(""));
} else if (!strcmp(message, "language screen") && isActiveScreen) {
I18NCategory *dev = GetI18NCategory("Developer");
auto langScreen = new NewLanguageScreen(dev->T("Language"));
langScreen->OnChoice.Add([](UI::EventParams &) {
NativeMessageReceived("recreateviews", "");
if (host) {
host->UpdateUI();
}
return UI::EVENT_DONE;
});
manager->push(langScreen);
} else if (!strcmp(message, "window minimized")) {
if (!strcmp(value, "true")) {
gstate_c.skipDrawReason |= SKIPDRAW_WINDOW_MINIMIZED;
@@ -214,32 +230,6 @@ void UIDialogScreenWithGameBackground::sendMessage(const char *message, const ch
void UIScreenWithBackground::sendMessage(const char *message, const char *value) {
HandleCommonMessages(message, value, screenManager(), this);
I18NCategory *dev = GetI18NCategory("Developer");
if (!strcmp(message, "language screen") && screenManager()->topScreen() == this) {
auto langScreen = new NewLanguageScreen(dev->T("Language"));
langScreen->OnChoice.Handle(this, &UIScreenWithBackground::OnLanguageChange);
screenManager()->push(langScreen);
} else if (!strcmp(message, "settings") && screenManager()->topScreen() == this) {
screenManager()->push(new GameSettingsScreen("", ""));
}
}
UI::EventReturn UIScreenWithBackground::OnLanguageChange(UI::EventParams &e) {
screenManager()->RecreateAllViews();
if (host) {
host->UpdateUI();
}
return UI::EVENT_DONE;
}
UI::EventReturn UIDialogScreenWithBackground::OnLanguageChange(UI::EventParams &e) {
screenManager()->RecreateAllViews();
if (host) {
host->UpdateUI();
}
return UI::EVENT_DONE;
}
void UIDialogScreenWithBackground::DrawBackground(UIContext &dc) {
@@ -255,14 +245,6 @@ void UIDialogScreenWithBackground::AddStandardBack(UI::ViewGroup *parent) {
void UIDialogScreenWithBackground::sendMessage(const char *message, const char *value) {
HandleCommonMessages(message, value, screenManager(), this);
I18NCategory *dev = GetI18NCategory("Developer");
if (!strcmp(message, "language screen") && screenManager()->topScreen() == this) {
auto langScreen = new NewLanguageScreen(dev->T("Language"));
langScreen->OnChoice.Handle(this, &UIDialogScreenWithBackground::OnLanguageChange);
screenManager()->push(langScreen);
} else if (!strcmp(message, "settings") && screenManager()->topScreen() == this) {
screenManager()->push(new GameSettingsScreen("", ""));
}
}
PromptScreen::PromptScreen(std::string message, std::string yesButtonText, std::string noButtonText, std::function<void(bool)> callback)
View
@@ -39,7 +39,6 @@ class UIScreenWithBackground : public UIScreen {
protected:
void DrawBackground(UIContext &dc) override;
void sendMessage(const char *message, const char *value) override;
UI::EventReturn OnLanguageChange(UI::EventParams &e);
};
class UIScreenWithGameBackground : public UIScreenWithBackground {
@@ -58,7 +57,6 @@ class UIDialogScreenWithBackground : public UIDialogScreen {
protected:
void DrawBackground(UIContext &dc) override;
void sendMessage(const char *message, const char *value) override;
UI::EventReturn OnLanguageChange(UI::EventParams &e);
void AddStandardBack(UI::ViewGroup *parent);
};
View
@@ -433,6 +433,7 @@ UI::EventReturn GamePauseScreen::OnCreateConfig(UI::EventParams &e)
screenManager()->topScreen()->RecreateViews();
return UI::EVENT_DONE;
}
UI::EventReturn GamePauseScreen::OnDeleteConfig(UI::EventParams &e)
{
I18NCategory *di = GetI18NCategory("Dialog");
@@ -443,13 +444,3 @@ UI::EventReturn GamePauseScreen::OnDeleteConfig(UI::EventParams &e)
return UI::EVENT_DONE;
}
void GamePauseScreen::sendMessage(const char *message, const char *value) {
UIDialogScreenWithGameBackground::sendMessage(message, 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();
}
}
View
@@ -35,7 +35,6 @@ class GamePauseScreen : public UIDialogScreenWithGameBackground {
protected:
virtual void CreateViews() override;
virtual void update() override;
virtual void sendMessage(const char *message, const char *value) override;
void CallbackDeleteConfig(bool yes);
private:

0 comments on commit f1bd541

Please sign in to comment.