mirror of
https://github.com/libretro/ppsspp.git
synced 2024-11-23 16:19:44 +00:00
Win32 UI: Add a System Language menu that's dynamically created. Also fix several small bugs where the UI wouldn't switch languages on the Pause screen, and in a couple other spots.
This commit is contained in:
parent
d69d33b0da
commit
aebd5156a5
@ -44,8 +44,9 @@
|
||||
#ifdef _WIN32
|
||||
namespace MainWindow {
|
||||
enum {
|
||||
WM_USER_LOG_STATUS_CHANGED = WM_USER + 200,
|
||||
WM_USER_ATRAC_STATUS_CHANGED = WM_USER + 300,
|
||||
WM_USER_LOG_STATUS_CHANGED = WM_USER + 101,
|
||||
WM_USER_ATRAC_STATUS_CHANGED = WM_USER + 102,
|
||||
WM_USER_UPDATE_UI = WM_USER + 103,
|
||||
};
|
||||
extern HWND hwndMain;
|
||||
}
|
||||
@ -454,6 +455,12 @@ void GameSettingsScreen::update(InputState &input) {
|
||||
g_Config.iFpsLimit = alternateSpeedTable[iAlternateSpeedPercent_];
|
||||
}
|
||||
|
||||
void GameSettingsScreen::sendMessage(const char *message, const char *value) {
|
||||
if (!strcmp(message, "language")) {
|
||||
RecreateViews();
|
||||
}
|
||||
}
|
||||
|
||||
UI::EventReturn GameSettingsScreen::OnDownloadPlugin(UI::EventParams &e) {
|
||||
screenManager()->push(new PluginScreen());
|
||||
return UI::EVENT_DONE;
|
||||
@ -525,6 +532,9 @@ UI::EventReturn GameSettingsScreen::OnLanguage(UI::EventParams &e) {
|
||||
UI::EventReturn GameSettingsScreen::OnLanguageChange(UI::EventParams &e) {
|
||||
RecreateViews();
|
||||
OnLanguageChanged.Trigger(e);
|
||||
#ifdef _WIN32
|
||||
PostMessage(MainWindow::hwndMain, MainWindow::WM_USER_UPDATE_UI, 0, 0);
|
||||
#endif
|
||||
return UI::EVENT_DONE;
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
protected:
|
||||
virtual void CreateViews();
|
||||
virtual void DrawBackground(UIContext &dc);
|
||||
virtual void sendMessage(const char *message, const char *value);
|
||||
|
||||
private:
|
||||
std::string gamePath_, gameID_;
|
||||
|
@ -551,6 +551,9 @@ void MainScreen::sendMessage(const char *message, const char *value) {
|
||||
if (!strcmp(message, "boot")) {
|
||||
screenManager()->switchScreen(new EmuScreen(value));
|
||||
}
|
||||
if (!strcmp(message, "language")) {
|
||||
RecreateViews();
|
||||
}
|
||||
}
|
||||
|
||||
void MainScreen::update(InputState &input) {
|
||||
@ -710,7 +713,8 @@ void GamePauseScreen::CreateViews() {
|
||||
}
|
||||
|
||||
UI::EventReturn GamePauseScreen::OnGameSettings(UI::EventParams &e) {
|
||||
screenManager()->push(new GameSettingsScreen(gamePath_));
|
||||
screenManager()->push(new GameSettingsScreen(gamePath_));
|
||||
RecreateViews();
|
||||
return UI::EVENT_DONE;
|
||||
}
|
||||
|
||||
@ -748,3 +752,9 @@ UI::EventReturn GamePauseScreen::OnCwCheat(UI::EventParams &e) {
|
||||
screenManager()->push(new CwCheatScreen());
|
||||
return UI::EVENT_DONE;
|
||||
}
|
||||
|
||||
void GamePauseScreen::sendMessage(const char *message, const char *value) {
|
||||
if (!strcmp(message, "language")) {
|
||||
RecreateViews();
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ protected:
|
||||
virtual void DrawBackground(UIContext &dc);
|
||||
virtual void CreateViews();
|
||||
virtual void update(InputState &input);
|
||||
virtual void sendMessage(const char *message, const char *value);
|
||||
|
||||
private:
|
||||
UI::EventReturn OnMainSettings(UI::EventParams &e);
|
||||
|
@ -89,12 +89,15 @@ extern InputState input_state;
|
||||
#define HID_USAGE_GENERIC_MOUSE ((USHORT) 0x02)
|
||||
#endif
|
||||
|
||||
extern std::map<std::string, std::pair<std::string, int>> GetLangValuesMapping();
|
||||
|
||||
namespace MainWindow
|
||||
{
|
||||
HWND hwndMain;
|
||||
HWND hwndDisplay;
|
||||
HWND hwndGameList;
|
||||
static HMENU menu;
|
||||
static HMENU systemLangMenu;
|
||||
|
||||
static HINSTANCE hInst;
|
||||
static int cursorCounter = 0;
|
||||
@ -106,6 +109,7 @@ namespace MainWindow
|
||||
static size_t rawInputBufferSize;
|
||||
static int currentSavestateSlot = 0;
|
||||
static std::map<int, std::string> initialMenuKeys;
|
||||
static std::vector<std::string> countryCodes;
|
||||
|
||||
#define MAX_LOADSTRING 100
|
||||
const TCHAR *szTitle = TEXT("PPSSPP");
|
||||
@ -275,6 +279,7 @@ namespace MainWindow
|
||||
MENU_HELP = 4,
|
||||
|
||||
// Emulation submenus
|
||||
SUBMENU_SYSTEM_LANGUAGE = 18,
|
||||
SUBMENU_RENDERING_BACKEND = 11,
|
||||
|
||||
// Game Settings submenus
|
||||
@ -285,6 +290,50 @@ namespace MainWindow
|
||||
SUBMENU_TEXTURE_SCALING = 8,
|
||||
};
|
||||
|
||||
void CreateSystemLanguageMenu() {
|
||||
// Please don't remove this boolean. We don't want this menu to be created multiple times.
|
||||
static bool systemLangMenuCreated = false;
|
||||
|
||||
if(systemLangMenuCreated) return;
|
||||
|
||||
HMENU emulationSubMenu = GetSubMenu(menu, MENU_EMULATION);
|
||||
systemLangMenu = CreatePopupMenu();
|
||||
|
||||
AppendMenu(emulationSubMenu, MF_SEPARATOR, 0, 0);
|
||||
|
||||
I18NCategory *c = GetI18NCategory("DesktopUI");
|
||||
// Don't translate this. Think of it as a string defined in ppsspp.rc.
|
||||
const std::wstring languageKey = L"System Language";
|
||||
// Insert the new menu.
|
||||
InsertMenu(emulationSubMenu, SUBMENU_SYSTEM_LANGUAGE, MF_POPUP | MF_STRING | MF_BYPOSITION, (UINT_PTR)systemLangMenu, languageKey.c_str());
|
||||
|
||||
// Get the new menu's info and then set its ID so we can have it be translatable.
|
||||
MENUITEMINFO mii;
|
||||
mii.cbSize = sizeof(MENUITEMINFO);
|
||||
GetMenuItemInfo(emulationSubMenu, SUBMENU_SYSTEM_LANGUAGE, TRUE, &mii);
|
||||
mii.fMask = MIIM_ID;
|
||||
mii.wID = ID_LANGUAGE_BASE;
|
||||
SetMenuItemInfo(emulationSubMenu, SUBMENU_SYSTEM_LANGUAGE, TRUE, &mii);
|
||||
|
||||
// Create the System Language menu items by creating a new menu item for each
|
||||
// language with its full name("English", "Magyar", etc.) as the value.
|
||||
// Also collect the country codes while we're at it so we can send them to
|
||||
// NativeMessageReceived easier.
|
||||
auto langValuesMap = GetLangValuesMapping();
|
||||
|
||||
// Start adding items after ID_LANGUAGE_BASE.
|
||||
int item = ID_LANGUAGE_BASE + 1;
|
||||
std::wstring fullLanguageName;
|
||||
|
||||
for(auto i = langValuesMap.begin(); i != langValuesMap.end(); ++i) {
|
||||
fullLanguageName = ConvertUTF8ToWString(i->second.first);
|
||||
AppendMenu(systemLangMenu, MF_STRING | MF_BYPOSITION, item++, fullLanguageName.c_str());
|
||||
countryCodes.push_back(i->first);
|
||||
}
|
||||
|
||||
systemLangMenuCreated = true;
|
||||
}
|
||||
|
||||
void TranslateMenuItembyText(const int menuID, const char *menuText, const char *category="", const bool enabled = true, const bool checked = false, const std::wstring& accelerator = L"") {
|
||||
I18NCategory *c = GetI18NCategory(category);
|
||||
std::string key = c->T(menuText);
|
||||
@ -354,7 +403,8 @@ namespace MainWindow
|
||||
TranslateMenuItem(ID_CPU_DYNAREC, desktopUI);
|
||||
TranslateMenuItem(ID_CPU_MULTITHREADED, desktopUI);
|
||||
TranslateMenuItem(ID_IO_MULTITHREADED, desktopUI);
|
||||
|
||||
TranslateMenuItem(ID_LANGUAGE_BASE, desktopUI);
|
||||
|
||||
// Debug menu
|
||||
TranslateMenuItem(ID_DEBUG_LOADMAPFILE, desktopUI);
|
||||
TranslateMenuItem(ID_DEBUG_SAVEMAPFILE, desktopUI);
|
||||
@ -1292,7 +1342,26 @@ namespace MainWindow
|
||||
break;
|
||||
|
||||
default:
|
||||
MessageBox(hwndMain, L"Unimplemented", L"Sorry",0);
|
||||
{
|
||||
// Just handle language switching here.
|
||||
// The Menu ID is contained in wParam, so subtract
|
||||
// ID_LANGUAGE_BASE and an additional 1 off it.
|
||||
int index = (wParam - ID_LANGUAGE_BASE - 1);
|
||||
if(index >= 0 && index < countryCodes.size()) {
|
||||
std::string oldLang = g_Config.languageIni;
|
||||
g_Config.languageIni = countryCodes[index];
|
||||
|
||||
if(i18nrepo.LoadIni(g_Config.languageIni)) {
|
||||
NativeMessageReceived("language", g_Config.languageIni.c_str());
|
||||
PostMessage(hwndMain, WM_USER_UPDATE_UI, 0, 0);
|
||||
}
|
||||
else
|
||||
g_Config.languageIni = oldLang;
|
||||
|
||||
break;
|
||||
}
|
||||
MessageBox(hwndMain, L"Unimplemented", L"Sorry",0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1429,6 +1498,7 @@ namespace MainWindow
|
||||
break;
|
||||
|
||||
case WM_USER_UPDATE_UI:
|
||||
CreateSystemLanguageMenu();
|
||||
TranslateMenus();
|
||||
Update();
|
||||
break;
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user