Add basic TextureReplacement UI options.

This commit is contained in:
LunaMoo 2016-06-22 00:33:06 +02:00
parent 2bd0567448
commit 8b17793c9f
2 changed files with 75 additions and 0 deletions

View File

@ -1084,6 +1084,12 @@ void DeveloperToolsScreen::CreateViews() {
list->Add(new ItemHeader(dev->T("Language"))); list->Add(new ItemHeader(dev->T("Language")));
list->Add(new Choice(dev->T("Load language ini")))->OnClick.Handle(this, &DeveloperToolsScreen::OnLoadLanguageIni); list->Add(new Choice(dev->T("Load language ini")))->OnClick.Handle(this, &DeveloperToolsScreen::OnLoadLanguageIni);
list->Add(new Choice(dev->T("Save language ini")))->OnClick.Handle(this, &DeveloperToolsScreen::OnSaveLanguageIni); list->Add(new Choice(dev->T("Save language ini")))->OnClick.Handle(this, &DeveloperToolsScreen::OnSaveLanguageIni);
list->Add(new ItemHeader(dev->T("Texture Replacement")));
list->Add(new CheckBox(&g_Config.bSaveNewTextures, dev->T("Save new textures")));
list->Add(new CheckBox(&g_Config.bReplaceTextures, dev->T("Replace textures")));
#if !defined(MOBILE_DEVICE)
list->Add(new Choice(dev->T("Create/Open textures.ini file for current game")))->OnClick.Handle(this, &DeveloperToolsScreen::OnOpenTexturesIniFile);
#endif
list->Add(new ItemHeader("")); list->Add(new ItemHeader(""));
list->Add(new Choice(di->T("Back")))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack); list->Add(new Choice(di->T("Back")))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
} }
@ -1137,6 +1143,74 @@ UI::EventReturn DeveloperToolsScreen::OnLoadLanguageIni(UI::EventParams &e) {
return UI::EVENT_DONE; return UI::EVENT_DONE;
} }
UI::EventReturn DeveloperToolsScreen::OnOpenTexturesIniFile(UI::EventParams &e) {
std::string gameID = g_paramSFO.GetValueString("DISC_ID");
std::string texturesDirectory = GetSysDirectory(DIRECTORY_TEXTURES) + gameID + "/";
bool enabled_ = !gameID.empty();
if (enabled_) {
if (!File::Exists(texturesDirectory)) {
File::CreateFullPath(texturesDirectory);
}
if (!File::Exists(texturesDirectory + "textures.ini")) {
FILE *f = File::OpenCFile(texturesDirectory + "textures.ini", "wb");
if (f) {
fwrite("\xEF\xBB\xBF", 0, 3, f);
fclose(f);
}
}
enabled_ = File::Exists(texturesDirectory + "textures.ini");
}
if (enabled_) {
std::string texturesIniFile;
#if defined(_WIN32)
texturesIniFile = texturesDirectory + "textures.ini";
// Can't rely on a .txt file extension to auto-open in the right editor,
// so let's find notepad
wchar_t notepad_path[MAX_PATH + 1];
GetSystemDirectory(notepad_path, MAX_PATH);
wcscat(notepad_path, L"\\notepad.exe");
wchar_t ini_path[MAX_PATH + 1] = { 0 };
wcsncpy(ini_path, ConvertUTF8ToWString(texturesIniFile).c_str(), MAX_PATH);
// Flip any slashes...
for (size_t i = 0; i < wcslen(ini_path); i++) {
if (ini_path[i] == '/')
ini_path[i] = '\\';
}
// One for the space, one for the null.
wchar_t command_line[MAX_PATH * 2 + 1 + 1];
wsprintf(command_line, L"%s %s", notepad_path, ini_path);
STARTUPINFO si;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
si.wShowWindow = SW_SHOW;
PROCESS_INFORMATION pi;
memset(&pi, 0, sizeof(pi));
UINT retval = CreateProcess(0, command_line, 0, 0, 0, 0, 0, 0, &si, &pi);
if (!retval) {
ERROR_LOG(COMMON, "Failed creating notepad process");
}
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
#elif !defined(MOBILE_DEVICE)
#if defined(__APPLE__)
texturesIniFile = "open ";
#else
texturesIniFile = "xdg-open ";
#endif
texturesIniFile.append(texturesDirectory + "textures.ini");
NOTICE_LOG(BOOT, "Launching %s", texturesIniFile.c_str());
int retval = system(texturesIniFile.c_str());
if (retval != 0) {
ERROR_LOG(COMMON, "Failed to launch textures.ini file");
}
#endif
}
return UI::EVENT_DONE;
}
UI::EventReturn DeveloperToolsScreen::OnLogConfig(UI::EventParams &e) { UI::EventReturn DeveloperToolsScreen::OnLogConfig(UI::EventParams &e) {
screenManager()->push(new LogConfigScreen()); screenManager()->push(new LogConfigScreen());
return UI::EVENT_DONE; return UI::EVENT_DONE;

View File

@ -127,6 +127,7 @@ private:
UI::EventReturn OnLoggingChanged(UI::EventParams &e); UI::EventReturn OnLoggingChanged(UI::EventParams &e);
UI::EventReturn OnLoadLanguageIni(UI::EventParams &e); UI::EventReturn OnLoadLanguageIni(UI::EventParams &e);
UI::EventReturn OnSaveLanguageIni(UI::EventParams &e); UI::EventReturn OnSaveLanguageIni(UI::EventParams &e);
UI::EventReturn OnOpenTexturesIniFile(UI::EventParams &e);
UI::EventReturn OnLogConfig(UI::EventParams &e); UI::EventReturn OnLogConfig(UI::EventParams &e);
UI::EventReturn OnJitAffectingSetting(UI::EventParams &e); UI::EventReturn OnJitAffectingSetting(UI::EventParams &e);
}; };