Permalink
Browse files

Merge pull request #10234 from unknownbrackets/ui-message

UI: Handle messages even when dialog is top
  • Loading branch information...
hrydgard committed Dec 2, 2017
2 parents 1f9fabe + 8e27600 commit b79525846971427111febd7212049265cf760acd
@@ -132,6 +132,7 @@ class DenseHashMap {
void Clear() {
memset(state.data(), (int)BucketState::FREE, state.size());
count_ = 0;
removedCount_ = 0;
}
void Rebuild() {
@@ -277,6 +278,7 @@ class PrehashMap {
void Clear() {
memset(state.data(), (int)BucketState::FREE, state.size());
count_ = 0;
removedCount_ = 0;
}
// Gets rid of REMOVED tombstones, making lookups somewhat more efficient.
@@ -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")) {
UpdateUIState(UISTATE_MENU);
screenManager()->push(new GameSettingsScreen(""));
}
}
UI::EventReturn ControlMappingScreen::OnClearMapping(UI::EventParams &params) {
KeyMap::g_controllerMap.clear();
RecreateViews();
@@ -33,9 +33,10 @@ class ControlMappingScreen : public UIDialogScreenWithBackground {
public:
ControlMappingScreen() {}
void KeyMapped(int pspkey); // Notification to let us refocus the same one after recreating views.
std::string tag() const override { return "control mapping"; }
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);
@@ -31,6 +31,7 @@ class DisplayLayoutScreen : public UIDialogScreenWithBackground {
virtual bool touch(const TouchInput &touch) override;
virtual void dialogFinished(const Screen *dialog, DialogResult result) override;
virtual void onFinish(DialogResult reason) override;
std::string tag() const override { return "display layout screen"; }
protected:
virtual UI::EventReturn OnCenter(UI::EventParams &e);
@@ -311,7 +311,7 @@ static void AfterStateBoot(bool success, const std::string &message, void *ignor
void EmuScreen::sendMessage(const char *message, const char *value) {
// External commands, like from the Windows UI.
if (!strcmp(message, "pause")) {
if (!strcmp(message, "pause") && screenManager()->topScreen() == this) {
releaseButtons();
screenManager()->push(new GamePauseScreen(gamePath_));
} else if (!strcmp(message, "lost_focus")) {
@@ -346,15 +346,15 @@ void EmuScreen::sendMessage(const char *message, const char *value) {
bootPending_ = true;
bootGame(value);
}
} else if (!strcmp(message, "control mapping")) {
} else if (!strcmp(message, "control mapping") && screenManager()->topScreen() == this) {
UpdateUIState(UISTATE_MENU);
releaseButtons();
screenManager()->push(new ControlMappingScreen());
} else if (!strcmp(message, "display layout editor")) {
} else if (!strcmp(message, "display layout editor") && screenManager()->topScreen() == this) {
UpdateUIState(UISTATE_MENU);
releaseButtons();
screenManager()->push(new DisplayLayoutScreen());
} else if (!strcmp(message, "settings")) {
} else if (!strcmp(message, "settings") && screenManager()->topScreen() == this) {
UpdateUIState(UISTATE_MENU);
releaseButtons();
screenManager()->push(new GameSettingsScreen(gamePath_));
@@ -35,7 +35,7 @@ class GameScreen : public UIDialogScreenWithGameBackground {
virtual void update();
virtual std::string tag() const { return "game"; }
std::string tag() const override { return "game"; }
protected:
virtual void CreateViews();
@@ -236,7 +236,6 @@ void GameSettingsScreen::CreateViews() {
softwareGPU->OnClick.Add([=](EventParams &e) {
if (g_Config.bSoftwareRendering)
settingInfo_->Show(gr->T("SoftGPU Tip", "Currently VERY slow"), e.v);
bloomHackEnable_ = !g_Config.bSoftwareRendering && (g_Config.iInternalResolution != 1);
return UI::EVENT_CONTINUE;
});
softwareGPU->OnClick.Handle(this, &GameSettingsScreen::OnSoftwareRendering);
@@ -356,12 +355,10 @@ void GameSettingsScreen::CreateViews() {
}
return UI::EVENT_CONTINUE;
});
bezierChoiceDisable_ = g_Config.bHardwareTessellation;
beziersChoice->SetDisabledPtr(&bezierChoiceDisable_);
beziersChoice->SetDisabledPtr(&g_Config.bHardwareTessellation);
CheckBox *tessellationHW = graphicsSettings->Add(new CheckBox(&g_Config.bHardwareTessellation, gr->T("Hardware Tessellation", "Hardware tessellation (experimental)")));
tessellationHW->OnClick.Add([=](EventParams &e) {
bezierChoiceDisable_ = g_Config.bHardwareTessellation;
settingInfo_->Show(gr->T("HardwareTessellation Tip", "Uses hardware to make curves, always uses a fixed quality"), e.v);
return UI::EVENT_CONTINUE;
});
@@ -809,7 +806,7 @@ UI::EventReturn GameSettingsScreen::OnSoftwareRendering(UI::EventParams &e) {
vtxCacheEnable_ = !g_Config.bSoftwareRendering && g_Config.bHardwareTransform;
postProcEnable_ = !g_Config.bSoftwareRendering && (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE);
resolutionEnable_ = !g_Config.bSoftwareRendering && (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE);
bezierChoiceDisable_ = g_Config.bHardwareTessellation;
bloomHackEnable_ = !g_Config.bSoftwareRendering && (g_Config.iInternalResolution != 1);
tessHWEnable_ = IsBackendSupportHWTess() && !g_Config.bSoftwareRendering && g_Config.bHardwareTransform;
return UI::EVENT_DONE;
}
@@ -975,12 +972,6 @@ UI::EventReturn GameSettingsScreen::OnChangeBackground(UI::EventParams &e) {
return UI::EVENT_DONE;
}
UI::EventReturn GameSettingsScreen::OnReloadCheats(UI::EventParams &e) {
// Hmm, strange mechanism.
g_Config.bReloadCheats = true;
return UI::EVENT_DONE;
}
UI::EventReturn GameSettingsScreen::OnFullscreenChange(UI::EventParams &e) {
System_SendMessage("toggle_fullscreen", g_Config.bFullScreen ? "1" : "0");
return UI::EVENT_DONE;
@@ -995,7 +986,7 @@ UI::EventReturn GameSettingsScreen::OnResolutionChange(UI::EventParams &e) {
if (g_Config.iAndroidHwScale == 1) {
RecreateActivity();
}
bloomHackEnable_ = g_Config.iInternalResolution != 1;
bloomHackEnable_ = !g_Config.bSoftwareRendering && g_Config.iInternalResolution != 1;
Reporting::UpdateConfig();
return UI::EVENT_DONE;
}
@@ -1005,13 +996,6 @@ UI::EventReturn GameSettingsScreen::OnHwScaleChange(UI::EventParams &e) {
return UI::EVENT_DONE;
}
UI::EventReturn GameSettingsScreen::OnShaderChange(UI::EventParams &e) {
if (gpu) {
gpu->ClearShaderCache();
}
return UI::EVENT_DONE;
}
UI::EventReturn GameSettingsScreen::OnDumpNextFrameToLog(UI::EventParams &e) {
if (gpu) {
gpu->DumpNextFrame();
@@ -1032,20 +1016,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")) {
UpdateUIState(UISTATE_MENU);
screenManager()->push(new ControlMappingScreen());
}
if (!strcmp(message, "display layout editor")) {
UpdateUIState(UISTATE_MENU);
screenManager()->push(new DisplayLayoutScreen());
}
}
void GameSettingsScreen::onFinish(DialogResult result) {
if (g_Config.bEnableSound) {
if (PSP_IsInited() && !IsAudioInitialised())
@@ -1068,14 +1038,6 @@ void GameSettingsScreen::onFinish(DialogResult result) {
NativeMessageReceived("gpu_clearCache", "");
}
/*
void GlobalSettingsScreen::CreateViews() {
using namespace UI;
root_ = new ScrollView(ORIENT_VERTICAL);
enableReports_ = Reporting::IsEnabled();
}*/
void GameSettingsScreen::CallbackRenderingBackend(bool yes) {
// If the user ends up deciding not to restart, set the config back to the current backend
// so it doesn't get switched by accident.
@@ -30,12 +30,12 @@ class GameSettingsScreen : public UIDialogScreenWithGameBackground {
virtual void update();
virtual void onFinish(DialogResult result);
std::string tag() const override { return "settings"; }
UI::Event OnRecentChanged;
protected:
virtual void CreateViews();
virtual void sendMessage(const char *message, const char *value);
void CallbackRestoreDefaults(bool yes);
void CallbackRenderingBackend(bool yes);
bool UseVerticalLayout() const;
@@ -63,7 +63,6 @@ class GameSettingsScreen : public UIDialogScreenWithGameBackground {
UI::EventReturn OnControlMapping(UI::EventParams &e);
UI::EventReturn OnTouchControlLayout(UI::EventParams &e);
UI::EventReturn OnDumpNextFrameToLog(UI::EventParams &e);
UI::EventReturn OnReloadCheats(UI::EventParams &e);
UI::EventReturn OnTiltTypeChange(UI::EventParams &e);
UI::EventReturn OnTiltCustomize(UI::EventParams &e);
UI::EventReturn OnComboKey(UI::EventParams &e);
@@ -85,7 +84,6 @@ class GameSettingsScreen : public UIDialogScreenWithGameBackground {
UI::EventReturn OnDisplayLayoutEditor(UI::EventParams &e);
UI::EventReturn OnResolutionChange(UI::EventParams &e);
UI::EventReturn OnHwScaleChange(UI::EventParams &e);
UI::EventReturn OnShaderChange(UI::EventParams &e);
UI::EventReturn OnRestoreDefaultSettings(UI::EventParams &e);
UI::EventReturn OnRenderingMode(UI::EventParams &e);
UI::EventReturn OnRenderingBackend(UI::EventParams &e);
@@ -119,7 +117,6 @@ class GameSettingsScreen : public UIDialogScreenWithGameBackground {
bool postProcEnable_;
bool resolutionEnable_;
bool bloomHackEnable_;
bool bezierChoiceDisable_;
bool tessHWEnable_;
};
@@ -935,21 +935,9 @@ 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")) {
if (!strcmp(message, "boot") && screenManager()->topScreen() == this) {
screenManager()->switchScreen(new EmuScreen(value));
}
if (!strcmp(message, "control mapping")) {
UpdateUIState(UISTATE_MENU);
screenManager()->push(new ControlMappingScreen());
}
if (!strcmp(message, "display layout editor")) {
UpdateUIState(UISTATE_MENU);
screenManager()->push(new DisplayLayoutScreen());
}
if (!strcmp(message, "settings")) {
UpdateUIState(UISTATE_MENU);
screenManager()->push(new GameSettingsScreen(""));
}
if (!strcmp(message, "permission_granted") && !strcmp(value, "storage")) {
RecreateViews();
}
@@ -155,18 +155,36 @@ void DrawGameBackground(UIContext &dc, const std::string &gamePath) {
}
}
void HandleCommonMessages(const char *message, const char *value, ScreenManager *manager) {
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")) {
} else if (!strcmp(message, "control mapping") && isActiveScreen && activeScreen->tag() != "control mapping") {
UpdateUIState(UISTATE_MENU);
manager->push(new ControlMappingScreen());
} else if (!strcmp(message, "display layout editor")) {
} else if (!strcmp(message, "display layout editor") && isActiveScreen && activeScreen->tag() != "display layout screen") {
UpdateUIState(UISTATE_MENU);
manager->push(new DisplayLayoutScreen());
} else if (!strcmp(message, "settings") && isActiveScreen && activeScreen->tag() != "settings") {
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;
@@ -191,7 +209,7 @@ void UIScreenWithGameBackground::DrawBackground(UIContext &dc) {
}
void UIScreenWithGameBackground::sendMessage(const char *message, const char *value) {
if (!strcmp(message, "settings")) {
if (!strcmp(message, "settings") && screenManager()->topScreen() == this) {
screenManager()->push(new GameSettingsScreen(gamePath_));
} else {
UIScreenWithBackground::sendMessage(message, value);
@@ -203,41 +221,15 @@ void UIDialogScreenWithGameBackground::DrawBackground(UIContext &dc) {
}
void UIDialogScreenWithGameBackground::sendMessage(const char *message, const char *value) {
if (!strcmp(message, "settings")) {
if (!strcmp(message, "settings") && screenManager()->topScreen() == this) {
screenManager()->push(new GameSettingsScreen(gamePath_));
} else {
UIDialogScreenWithBackground::sendMessage(message, value);
}
}
void UIScreenWithBackground::sendMessage(const char *message, const char *value) {
HandleCommonMessages(message, value, screenManager());
I18NCategory *dev = GetI18NCategory("Developer");
if (!strcmp(message, "language screen")) {
auto langScreen = new NewLanguageScreen(dev->T("Language"));
langScreen->OnChoice.Handle(this, &UIScreenWithBackground::OnLanguageChange);
screenManager()->push(langScreen);
} else if (!strcmp(message, "settings")) {
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;
HandleCommonMessages(message, value, screenManager(), this);
}
void UIDialogScreenWithBackground::DrawBackground(UIContext &dc) {
@@ -252,15 +244,7 @@ void UIDialogScreenWithBackground::AddStandardBack(UI::ViewGroup *parent) {
}
void UIDialogScreenWithBackground::sendMessage(const char *message, const char *value) {
HandleCommonMessages(message, value, screenManager());
I18NCategory *dev = GetI18NCategory("Developer");
if (!strcmp(message, "language screen")) {
auto langScreen = new NewLanguageScreen(dev->T("Language"));
langScreen->OnChoice.Handle(this, &UIDialogScreenWithBackground::OnLanguageChange);
screenManager()->push(langScreen);
} else if (!strcmp(message, "settings")) {
screenManager()->push(new GameSettingsScreen("", ""));
}
HandleCommonMessages(message, value, screenManager(), this);
}
PromptScreen::PromptScreen(std::string message, std::string yesButtonText, std::string noButtonText, std::function<void(bool)> callback)
@@ -447,7 +431,7 @@ void LogoScreen::update() {
}
void LogoScreen::sendMessage(const char *message, const char *value) {
if (!strcmp(message, "boot")) {
if (!strcmp(message, "boot") && screenManager()->topScreen() == this) {
screenManager()->switchScreen(new EmuScreen(value));
}
}
@@ -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);
};
Oops, something went wrong.

0 comments on commit b795258

Please sign in to comment.