Skip to content

Commit

Permalink
Merge pull request #18272 from hrydgard/ui-event-enum
Browse files Browse the repository at this point in the history
Change global UI messages to use an enum instead of strings.
  • Loading branch information
hrydgard committed Sep 30, 2023
2 parents 2a4d21e + c0e5da0 commit aedd51f
Show file tree
Hide file tree
Showing 38 changed files with 220 additions and 198 deletions.
36 changes: 35 additions & 1 deletion Common/System/System.h
Expand Up @@ -207,6 +207,40 @@ enum class SystemNotification {
ACTIVITY,
};

// I guess it's not super great architecturally to centralize this, since it's not general - but same with a lot of
// the other stuff, and this is only used by PPSSPP, so... better this than ugly strings.
enum class UIMessage {
PERMISSION_GRANTED,
POWER_SAVING,
RECREATE_VIEWS,
CONFIG_LOADED,
REQUEST_GAME_BOOT,
REQUEST_GAME_RUN, // or continue?
REQUEST_GAME_PAUSE,
REQUEST_GAME_RESET,
REQUEST_GAME_STOP,
SHOW_CONTROL_MAPPING,
SHOW_CHAT_SCREEN,
SHOW_DISPLAY_LAYOUT_EDITOR,
SHOW_SETTINGS,
SHOW_LANGUAGE_SCREEN,
REQUEST_GPU_DUMP_NEXT_FRAME,
REQUEST_CLEAR_JIT,
APP_RESUMED,
REQUEST_PLAY_SOUND,
WINDOW_MINIMIZED,
LOST_FOCUS,
GOT_FOCUS,
GPU_CONFIG_CHANGED,
GPU_RENDER_RESIZED,
GPU_DISPLAY_RESIZED,
POSTSHADER_UPDATED,
ACHIEVEMENT_LOGIN_STATE_CHANGE,
SAVESTATE_DISPLAY_SLOT,
GAMESETTINGS_SEARCH,
SAVEDATA_SEARCH,
};

std::string System_GetProperty(SystemProperty prop);
std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop);
int System_GetPropertyInt(SystemProperty prop);
Expand All @@ -221,7 +255,7 @@ bool System_AudioRecordingIsAvailable();
bool System_AudioRecordingState();

// This will be changed to take an enum. Replacement for the old NativeMessageReceived.
void System_PostUIMessage(const std::string &message, const std::string &param);
void System_PostUIMessage(UIMessage message, const std::string &param = "");

// For these functions, most platforms will use the implementation provided in UI/AudioCommon.cpp,
// no need to implement separately.
Expand Down
10 changes: 4 additions & 6 deletions Common/UI/Screen.cpp
Expand Up @@ -208,12 +208,10 @@ void ScreenManager::getFocusPosition(float &x, float &y, float &z) {
z = stack_.size();
}

void ScreenManager::sendMessage(const char *msg, const char *value) {
if (!msg) {
_dbg_assert_msg_(false, "Empty msg in ScreenManager::sendMessage");
} else if (!strcmp(msg, "recreateviews")) {
void ScreenManager::sendMessage(UIMessage message, const char *value) {
if (message == UIMessage::RECREATE_VIEWS) {
RecreateAllViews();
} else if (!strcmp(msg, "lost_focus")) {
} else if (message == UIMessage::LOST_FOCUS) {
TouchInput input{};
input.x = -50000.0f;
input.y = -50000.0f;
Expand All @@ -224,7 +222,7 @@ void ScreenManager::sendMessage(const char *msg, const char *value) {
}

if (!stack_.empty())
stack_.back().screen->sendMessage(msg, value);
stack_.back().screen->sendMessage(message, value);
}

Screen *ScreenManager::topScreen() const {
Expand Down
5 changes: 3 additions & 2 deletions Common/UI/Screen.h
Expand Up @@ -21,6 +21,7 @@

#include "Common/Common.h"
#include "Common/Input/InputState.h"
#include "Common/System/System.h"

namespace UI {
class View;
Expand Down Expand Up @@ -55,7 +56,7 @@ class Screen {
virtual void postRender() {}
virtual void resized() {}
virtual void dialogFinished(const Screen *dialog, DialogResult result) {}
virtual void sendMessage(const char *msg, const char *value) {}
virtual void sendMessage(UIMessage message, const char *value) {}
virtual void deviceLost() {}
virtual void deviceRestored() {}

Expand Down Expand Up @@ -138,7 +139,7 @@ class ScreenManager {
void axis(const AxisInput *axes, size_t count);

// Generic facility for gross hacks :P
void sendMessage(const char *msg, const char *value);
void sendMessage(UIMessage message, const char *value);

Screen *topScreen() const;

Expand Down
4 changes: 2 additions & 2 deletions Common/UI/UIScreen.cpp
Expand Up @@ -269,10 +269,10 @@ bool UIDialogScreen::key(const KeyInput &key) {
return retval;
}

void UIDialogScreen::sendMessage(const char *msg, const char *value) {
void UIDialogScreen::sendMessage(UIMessage message, const char *value) {
Screen *screen = screenManager()->dialogParent(this);
if (screen) {
screen->sendMessage(msg, value);
screen->sendMessage(message, value);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Common/UI/UIScreen.h
Expand Up @@ -88,7 +88,7 @@ class UIDialogScreen : public UIScreen {
public:
UIDialogScreen() : UIScreen(), finished_(false) {}
bool key(const KeyInput &key) override;
void sendMessage(const char *msg, const char *value) override;
void sendMessage(UIMessage message, const char *value) override;

private:
bool finished_;
Expand Down
2 changes: 1 addition & 1 deletion Core/PSPLoaders.cpp
Expand Up @@ -306,7 +306,7 @@ bool Load_PSP_ISO(FileLoader *fileLoader, std::string *error_string) {

//in case we didn't go through EmuScreen::boot
g_Config.loadGameConfig(id, g_paramSFO.GetValueString("TITLE"));
System_PostUIMessage("config_loaded", "");
System_PostUIMessage(UIMessage::CONFIG_LOADED);
INFO_LOG(LOADER, "Loading %s...", bootpath.c_str());

PSPLoaders_Shutdown();
Expand Down
10 changes: 5 additions & 5 deletions Core/RetroAchievements.cpp
Expand Up @@ -58,7 +58,7 @@ static inline const char *DeNull(const char *ptr) {
}

void OnAchievementsLoginStateChange() {
System_PostUIMessage("achievements_loginstatechange", "");
System_PostUIMessage(UIMessage::ACHIEVEMENT_LOGIN_STATE_CHANGE);
}

namespace Achievements {
Expand Down Expand Up @@ -228,7 +228,7 @@ static void event_handler_callback(const rc_client_event_t *event, rc_client_t *
case RC_CLIENT_EVENT_ACHIEVEMENT_TRIGGERED:
// An achievement was earned by the player. The handler should notify the player that the achievement was earned.
g_OSD.ShowAchievementUnlocked(event->achievement->id);
System_PostUIMessage("play_sound", "achievement_unlocked");
System_PostUIMessage(UIMessage::REQUEST_PLAY_SOUND, "achievement_unlocked");
INFO_LOG(ACHIEVEMENTS, "Achievement unlocked: '%s' (%d)", event->achievement->title, event->achievement->id);
break;

Expand All @@ -250,7 +250,7 @@ static void event_handler_callback(const rc_client_event_t *event, rc_client_t *

g_OSD.Show(OSDType::MESSAGE_INFO, title, message, DeNull(gameInfo->badge_name), 10.0f);

System_PostUIMessage("play_sound", "achievement_unlocked");
System_PostUIMessage(UIMessage::REQUEST_PLAY_SOUND, "achievement_unlocked");

INFO_LOG(ACHIEVEMENTS, "%s", message.c_str());
break;
Expand Down Expand Up @@ -284,7 +284,7 @@ static void event_handler_callback(const rc_client_event_t *event, rc_client_t *
title = event->leaderboard->description;
}
g_OSD.ShowLeaderboardSubmitted(ApplySafeSubstitutions(ac->T("Submitted %1 for %2"), DeNull(event->leaderboard->tracker_value), title), "");
System_PostUIMessage("play_sound", "leaderboard_submitted");
System_PostUIMessage(UIMessage::REQUEST_PLAY_SOUND, "leaderboard_submitted");
break;
}
case RC_CLIENT_EVENT_ACHIEVEMENT_CHALLENGE_INDICATOR_SHOW:
Expand Down Expand Up @@ -341,7 +341,7 @@ static void event_handler_callback(const rc_client_event_t *event, rc_client_t *
case RC_CLIENT_EVENT_RESET:
WARN_LOG(ACHIEVEMENTS, "Resetting game due to achievement setting change!");
// Challenge mode was enabled, or something else that forces a game reset.
System_PostUIMessage("reset", "");
System_PostUIMessage(UIMessage::REQUEST_GAME_RESET);
break;
case RC_CLIENT_EVENT_SERVER_ERROR:
ERROR_LOG(ACHIEVEMENTS, "Server error: %s: %s", event->server_error->api, event->server_error->error_message);
Expand Down
2 changes: 1 addition & 1 deletion Qt/QtMain.cpp
Expand Up @@ -542,7 +542,7 @@ QString MainUI::InputBoxGetQString(QString title, QString defaultValue) {

void MainUI::resizeGL(int w, int h) {
if (UpdateScreenScale(w, h)) {
System_PostUIMessage("gpu_displayResized", "");
System_PostUIMessage(UIMessage::GPU_RENDER_RESIZED);
}
xscale = w / this->width();
yscale = h / this->height();
Expand Down
13 changes: 6 additions & 7 deletions Qt/mainwindow.cpp
Expand Up @@ -130,15 +130,15 @@ void MainWindow::loadAct()
{
QFileInfo info(filename);
g_Config.currentDirectory = Path(info.absolutePath().toStdString());
System_PostUIMessage("boot", filename.toStdString().c_str());
System_PostUIMessage(UIMessage::REQUEST_GAME_BOOT, filename.toStdString().c_str());
}
}

void MainWindow::closeAct()
{
updateMenus();

System_PostUIMessage("stop", "");
System_PostUIMessage(UIMessage::REQUEST_GAME_STOP);
SetGameTitle("");
}

Expand Down Expand Up @@ -232,25 +232,24 @@ void MainWindow::exitAct()

void MainWindow::runAct()
{
System_PostUIMessage("run", "");
System_PostUIMessage(UIMessage::REQUEST_GAME_RUN);
}

void MainWindow::pauseAct()
{
System_PostUIMessage("pause", "");
System_PostUIMessage(UIMessage::REQUEST_GAME_PAUSE);
}

void MainWindow::stopAct()
{
Core_Stop();
System_PostUIMessage("stop", "");
System_PostUIMessage(UIMessage::REQUEST_GAME_STOP);
}

void MainWindow::resetAct()
{
updateMenus();

System_PostUIMessage("reset", "");
System_PostUIMessage(UIMessage::REQUEST_GAME_RESET);
}

void MainWindow::switchUMDAct()
Expand Down
26 changes: 13 additions & 13 deletions Qt/mainwindow.h
Expand Up @@ -113,28 +113,28 @@ private slots:
void consoleAct();

// Game settings
void languageAct() { System_PostUIMessage("language screen", ""); }
void controlMappingAct() { System_PostUIMessage("control mapping", ""); }
void displayLayoutEditorAct() { System_PostUIMessage("display layout editor", ""); }
void moreSettingsAct() { System_PostUIMessage("settings", ""); }
void languageAct() { System_PostUIMessage(UIMessage::SHOW_LANGUAGE_SCREEN); }
void controlMappingAct() { System_PostUIMessage(UIMessage::SHOW_CONTROL_MAPPING); }
void displayLayoutEditorAct() { System_PostUIMessage(UIMessage::SHOW_DISPLAY_LAYOUT_EDITOR); }
void moreSettingsAct() { System_PostUIMessage(UIMessage::SHOW_SETTINGS); }

void bufferRenderAct() {
System_PostUIMessage("gpu_renderResized", "");
System_PostUIMessage("gpu_configChanged", "");
System_PostUIMessage(UIMessage::GPU_RENDER_RESIZED);
System_PostUIMessage(UIMessage::GPU_CONFIG_CHANGED);
}
void linearAct() { g_Config.iTexFiltering = (g_Config.iTexFiltering != 0) ? 0 : 3; }

void renderingResolutionGroup_triggered(QAction *action) {
g_Config.iInternalResolution = action->data().toInt();
System_PostUIMessage("gpu_renderResized", "");
System_PostUIMessage(UIMessage::GPU_RENDER_RESIZED);
}
void windowGroup_triggered(QAction *action) { SetWindowScale(action->data().toInt()); }

void autoframeskipAct() {
g_Config.bAutoFrameSkip = !g_Config.bAutoFrameSkip;
if (g_Config.bSkipBufferEffects) {
g_Config.bSkipBufferEffects = false;
System_PostUIMessage("gpu_configChanged", "");
System_PostUIMessage(UIMessage::GPU_CONFIG_CHANGED);
}
}
void frameSkippingGroup_triggered(QAction *action) { g_Config.iFrameSkip = action->data().toInt(); }
Expand All @@ -143,19 +143,19 @@ private slots:
void screenScalingFilterGroup_triggered(QAction *action) { g_Config.iDisplayFilter = action->data().toInt(); }
void textureScalingLevelGroup_triggered(QAction *action) {
g_Config.iTexScalingLevel = action->data().toInt();
System_PostUIMessage("gpu_configChanged", "");
System_PostUIMessage(UIMessage::GPU_CONFIG_CHANGED);
}
void textureScalingTypeGroup_triggered(QAction *action) {
g_Config.iTexScalingType = action->data().toInt();
System_PostUIMessage("gpu_configChanged", "");
System_PostUIMessage(UIMessage::GPU_CONFIG_CHANGED);
}
void deposterizeAct() {
g_Config.bTexDeposterize = !g_Config.bTexDeposterize;
System_PostUIMessage("gpu_configChanged", "");
System_PostUIMessage(UIMessage::GPU_CONFIG_CHANGED);
}
void transformAct() {
g_Config.bHardwareTransform = !g_Config.bHardwareTransform;
System_PostUIMessage("gpu_configChanged", "");
System_PostUIMessage(UIMessage::GPU_CONFIG_CHANGED);
}
void vertexCacheAct() { g_Config.bVertexCache = !g_Config.bVertexCache; }
void frameskipAct() { g_Config.iFrameSkip = !g_Config.iFrameSkip; }
Expand All @@ -172,7 +172,7 @@ private slots:
// Chat
void chatAct() {
if (GetUIState() == UISTATE_INGAME) {
System_PostUIMessage("chat screen", "");
System_PostUIMessage(UIMessage::SHOW_CHAT_SCREEN);
}
}

Expand Down
12 changes: 6 additions & 6 deletions SDL/CocoaBarItems.mm
Expand Up @@ -442,17 +442,17 @@ -(void)breakAction: (NSMenuItem *)item {
}

-(void)pauseAction: (NSMenuItem *)item {
System_PostUIMessage("pause", "");
System_PostUIMessage(UIMessage::REQUEST_GAME_PAUSE);
}

-(void)resetAction: (NSMenuItem *)item {
System_PostUIMessage("reset", "");
System_PostUIMessage(UIMessage::REQUEST_GAME_RESET);
Core_EnableStepping(false);
}

-(void)chatAction: (NSMenuItem *)item {
if (GetUIState() == UISTATE_INGAME) {
System_PostUIMessage("chat screen", "");
System_PostUIMessage(UIMessage::SHOW_CHAT_SCREEN);
}
}

Expand Down Expand Up @@ -549,7 +549,7 @@ -(void)toggleShowDebugStats: (NSMenuItem *)item { \
} else {
g_Config.iDebugOverlay = (int)DebugOverlay::DEBUG_STATS;
}
System_PostUIMessage("clear jit", "");
System_PostUIMessage(UIMessage::REQUEST_CLEAR_JIT);
item.state = [self controlStateForBool: (DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS]; \
}

Expand Down Expand Up @@ -631,14 +631,14 @@ -(void)addOpenRecentlyItem {
}

-(void)openRecentItem: (NSMenuItem *)item {
System_PostUIMessage("boot", g_Config.RecentIsos()[item.tag].c_str());
System_PostUIMessage(UIMessage::REQUEST_GAME_BOOT, g_Config.RecentIsos()[item.tag].c_str());
}

-(void)openSystemFileBrowser {
int g = 0;
DarwinDirectoryPanelCallback callback = [g] (bool succ, Path thePathChosen) {
if (succ)
System_PostUIMessage("boot", thePathChosen.c_str());
System_PostUIMessage(UIMessage::REQUEST_GAME_BOOT, thePathChosen.c_str());
};

DarwinFileSystemServices services;
Expand Down
4 changes: 2 additions & 2 deletions SDL/SDLMain.cpp
Expand Up @@ -880,15 +880,15 @@ static void ProcessSDLEvent(SDL_Window *window, const SDL_Event &event, InputSta
if (Core_IsStepping())
Core_EnableStepping(false);
Core_Stop();
System_PostUIMessage("stop", "");
System_PostUIMessage(UIMessage::REQUEST_GAME_STOP);
// NOTE: Unlike Windows version, this
// does not need Core_WaitInactive();
// since SDL does not have a separate
// UI thread.
}
if (ctrl && (k == SDLK_b))
{
System_PostUIMessage("reset", "");
System_PostUIMessage(UIMessage::REQUEST_GAME_RESET);
Core_EnableStepping(false);
}
}
Expand Down

0 comments on commit aedd51f

Please sign in to comment.