NewUI: Add new Language selector screen (uses the new popup list screen).

This commit is contained in:
Henrik Rydgard 2013-07-16 00:29:00 +02:00
parent e8a451e512
commit a8f87d17c9
5 changed files with 130 additions and 7 deletions

View File

@ -17,6 +17,7 @@
#include "base/colorutil.h"
#include "base/timeutil.h"
#include "i18n/i18n.h"
#include "math/curves.h"
#include "ui/ui_context.h"
#include "ui/view.h"
@ -32,6 +33,9 @@
void GameScreen::CreateViews() {
GameInfo *info = g_gameInfoCache.GetInfo(gamePath_, true);
I18NCategory *g = GetI18NCategory("General");
I18NCategory *ga = GetI18NCategory("Game");
// Information in the top left.
// Back button to the bottom left.
// Scrolling action menu to the right.
@ -44,7 +48,7 @@ void GameScreen::CreateViews() {
ViewGroup *leftColumn = new AnchorLayout(new LinearLayoutParams(1.0f));
root_->Add(leftColumn);
leftColumn->Add(new Choice("Back", "", new AnchorLayoutParams(150, WRAP_CONTENT, 10, NONE, NONE, 10)))->OnClick.Handle(this, &GameScreen::OnSwitchBack);
leftColumn->Add(new Choice(g->T("Back"), "", false, new AnchorLayoutParams(150, WRAP_CONTENT, 10, NONE, NONE, 10)))->OnClick.Handle(this, &GameScreen::OnSwitchBack);
if (info) {
texvGameIcon_ = leftColumn->Add(new TextureView(0, IS_DEFAULT, new AnchorLayoutParams(144 * 2, 80 * 2, 10, 10, NONE, NONE)));
tvTitle_ = leftColumn->Add(new TextView(0, info->title, ALIGN_LEFT, 1.0f, new AnchorLayoutParams(10, 200, NONE, NONE)));
@ -57,10 +61,10 @@ void GameScreen::CreateViews() {
ViewGroup *rightColumnItems = new LinearLayout(ORIENT_VERTICAL);
rightColumn->Add(rightColumnItems);
rightColumnItems->Add(new Choice("Play"))->OnClick.Handle(this, &GameScreen::OnPlay);
rightColumnItems->Add(new Choice("Game Settings"))->OnClick.Handle(this, &GameScreen::OnGameSettings);
rightColumnItems->Add(new Choice("Delete Save Data"))->OnClick.Handle(this, &GameScreen::OnDeleteSaveData);
rightColumnItems->Add(new Choice("Delete Game"))->OnClick.Handle(this, &GameScreen::OnDeleteGame);
rightColumnItems->Add(new Choice(ga->T("Play")))->OnClick.Handle(this, &GameScreen::OnPlay);
rightColumnItems->Add(new Choice(ga->T("Game Settings")))->OnClick.Handle(this, &GameScreen::OnGameSettings);
rightColumnItems->Add(new Choice(ga->T("Delete Save Data")))->OnClick.Handle(this, &GameScreen::OnDeleteSaveData);
rightColumnItems->Add(new Choice(ga->T("Delete Game")))->OnClick.Handle(this, &GameScreen::OnDeleteGame);
}
void DrawBackground(float alpha);

View File

@ -60,6 +60,7 @@
#include "UI/EmuScreen.h"
#include "UI/PluginScreen.h"
#include "UI/MainScreen.h"
#include "UI/MiscScreens.h"
#include "GameInfoCache.h"
#include "android/jni/TestRunner.h"
@ -1467,7 +1468,10 @@ void SystemScreen::render() {
ui_draw2d.DrawTextShadow(UBUNTU24, lang, x, y += stride, 0xFFFFFFFF, ALIGN_LEFT);
HLinear hlinear2(x + 400, y, 20);
if (UIButton(GEN_ID, hlinear2, 220, 0, s->T("Language"), ALIGN_TOPLEFT)) {
screenManager()->push(new LanguageScreen());
if (g_Config.bNewUI)
screenManager()->push(new NewLanguageScreen());
else
screenManager()->push(new LanguageScreen());
}
y+=20;

View File

@ -18,10 +18,14 @@
#include "base/colorutil.h"
#include "base/timeutil.h"
#include "gfx_es2/draw_buffer.h"
#include "file/vfs.h"
#include "i18n/i18n.h"
#include "ui/ui_context.h"
#include "ui/view.h"
#include "ui/viewgroup.h"
#include "UI/MiscScreens.h"
#include "Core/Config.h"
#include "Core/HLE/sceUtility.h"
void DrawBackground(float alpha);
@ -62,3 +66,93 @@ UI::EventReturn PromptScreen::OnNo(UI::EventParams &e) {
screenManager()->finishDialog(this, DR_CANCEL);
return UI::EVENT_DONE;
}
NewLanguageScreen::NewLanguageScreen() : ListPopupScreen("Language") {
langValuesMapping["ja_JP"] = std::make_pair("日本語", PSP_SYSTEMPARAM_LANGUAGE_JAPANESE);
langValuesMapping["en_US"] = std::make_pair("English",PSP_SYSTEMPARAM_LANGUAGE_ENGLISH);
langValuesMapping["fr_FR"] = std::make_pair("Français", PSP_SYSTEMPARAM_LANGUAGE_FRENCH);
langValuesMapping["es_ES"] = std::make_pair("Castellano", PSP_SYSTEMPARAM_LANGUAGE_SPANISH);
langValuesMapping["es_LA"] = std::make_pair("Latino", PSP_SYSTEMPARAM_LANGUAGE_SPANISH);
langValuesMapping["de_DE"] = std::make_pair("Deutsch", PSP_SYSTEMPARAM_LANGUAGE_GERMAN);
langValuesMapping["it_IT"] = std::make_pair("Italiano", PSP_SYSTEMPARAM_LANGUAGE_ITALIAN);
langValuesMapping["nl_NL"] = std::make_pair("Nederlands", PSP_SYSTEMPARAM_LANGUAGE_DUTCH);
langValuesMapping["pt_PT"] = std::make_pair("Português", PSP_SYSTEMPARAM_LANGUAGE_PORTUGUESE);
langValuesMapping["pt_BR"] = std::make_pair("Brasileiro", PSP_SYSTEMPARAM_LANGUAGE_PORTUGUESE);
langValuesMapping["ru_RU"] = std::make_pair("Русский", PSP_SYSTEMPARAM_LANGUAGE_RUSSIAN);
langValuesMapping["ko_KR"] = std::make_pair("한국어", PSP_SYSTEMPARAM_LANGUAGE_KOREAN);
langValuesMapping["zh_TW"] = std::make_pair("繁體中文", PSP_SYSTEMPARAM_LANGUAGE_CHINESE_TRADITIONAL);
langValuesMapping["zh_CN"] = std::make_pair("简体中文", PSP_SYSTEMPARAM_LANGUAGE_CHINESE_SIMPLIFIED);
//langValuesMapping["ar_AE"] = std::make_pair("العربية", PSP_SYSTEMPARAM_LANGUAGE_ENGLISH);
langValuesMapping["az_AZ"] = std::make_pair("Azeri", PSP_SYSTEMPARAM_LANGUAGE_ENGLISH);
langValuesMapping["ca_ES"] = std::make_pair("Català", PSP_SYSTEMPARAM_LANGUAGE_ENGLISH);
langValuesMapping["gr_EL"] = std::make_pair("ελληνικά", PSP_SYSTEMPARAM_LANGUAGE_ENGLISH);
langValuesMapping["he_IL"] = std::make_pair("עברית", PSP_SYSTEMPARAM_LANGUAGE_ENGLISH);
langValuesMapping["hu_HU"] = std::make_pair("Magyar", PSP_SYSTEMPARAM_LANGUAGE_ENGLISH);
langValuesMapping["id_ID"] = std::make_pair("Indonesia", PSP_SYSTEMPARAM_LANGUAGE_ENGLISH);
langValuesMapping["pl_PL"] = std::make_pair("Polski", PSP_SYSTEMPARAM_LANGUAGE_ENGLISH);
langValuesMapping["ro_RO"] = std::make_pair("Român", PSP_SYSTEMPARAM_LANGUAGE_ENGLISH);
langValuesMapping["sv_SE"] = std::make_pair("Svenska", PSP_SYSTEMPARAM_LANGUAGE_ENGLISH);
langValuesMapping["tr_TR"] = std::make_pair("Türk", PSP_SYSTEMPARAM_LANGUAGE_ENGLISH);
langValuesMapping["uk_UA"] = std::make_pair("Українська", PSP_SYSTEMPARAM_LANGUAGE_ENGLISH);
#ifdef ANDROID
VFSGetFileListing("assets/lang", &langs_, "ini");
#else
VFSGetFileListing("lang", &langs_, "ini");
#endif
std::vector<std::string> listing;
for (size_t i = 0; i < langs_.size(); i++) {
// Skip README
if (langs_[i].name.find("README") != std::string::npos) {
continue;
}
std::string code;
size_t dot = langs_[i].name.find('.');
if (dot != std::string::npos)
code = langs_[i].name.substr(0, dot);
std::string buttonTitle = langs_[i].name;
if (!code.empty()) {
if (langValuesMapping.find(code) == langValuesMapping.end()) {
// No title found, show locale code
buttonTitle = code;
} else {
buttonTitle = langValuesMapping[code].first;
}
}
listing.push_back(buttonTitle);
}
adaptor_ = UI::StringVectorListAdaptor(listing, 0);
}
void NewLanguageScreen::OnCompleted() {
std::string oldLang = g_Config.languageIni;
std::string iniFile = langs_[listView_->GetSelected()].name;
size_t dot = iniFile.find('.');
std::string code;
if (dot != std::string::npos)
code = iniFile.substr(0, dot);
if (code.empty())
return;
g_Config.languageIni = code;
if (i18nrepo.LoadIni(g_Config.languageIni)) {
// Dunno what else to do here.
if (langValuesMapping.find(code) == langValuesMapping.end()) {
// Fallback to English
g_Config.ilanguage = PSP_SYSTEMPARAM_LANGUAGE_ENGLISH;
} else {
g_Config.ilanguage = langValuesMapping[code].second;
}
} else {
g_Config.languageIni = oldLang;
}
}

View File

@ -17,7 +17,12 @@
#pragma once
#include <vector>
#include <map>
#include <string>
#include "base/functional.h"
#include "file/file_util.h"
#include "ui/ui_screen.h"
inline void NoOpVoidBool(bool) {}
@ -44,3 +49,19 @@ private:
std::string noButtonText_;
std::function<void(bool)> callback_;
};
class NewLanguageScreen : public ListPopupScreen {
public:
NewLanguageScreen();
private:
virtual void OnCompleted();
std::map<std::string, std::pair<std::string, int>> langValuesMapping;
std::map<std::string, std::string> titleCodeMapping;
std::vector<FileInfo> langs_;
};
// Utility functions that create various popup screens
ListPopupScreen *CreateLanguageScreen();

2
native

@ -1 +1 @@
Subproject commit 46c9fd38199263700ca721366923863d0d2cc025
Subproject commit a7b92d63d6a51f41b3fe8c89fee0bd5f85b8f4a6