mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
UI: Make System_InputBox API asynchronous.
Doing this as a precursor to cleaning up the Android madness.
This commit is contained in:
parent
f648a82df9
commit
efceb031ce
8 changed files with 70 additions and 88 deletions
|
@ -15,9 +15,10 @@
|
|||
// Official git repository and contact information can be found at
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include <algorithm>
|
||||
#include "i18n/i18n.h"
|
||||
#include "math/math_util.h"
|
||||
#include <algorithm>
|
||||
#include "util/text/utf8.h"
|
||||
|
||||
#include "Core/Dialog/PSPOskDialog.h"
|
||||
#include "Core/Util/PPGeDraw.h"
|
||||
|
@ -853,14 +854,19 @@ int PSPOskDialog::NativeKeyboard() {
|
|||
if (defaultText.empty())
|
||||
defaultText.assign(L"VALUE");
|
||||
|
||||
if (System_InputBoxGetWString(titleText.c_str(), defaultText, inputChars)) {
|
||||
u32 maxLength = FieldMaxLength();
|
||||
if (inputChars.length() > maxLength) {
|
||||
ERROR_LOG(SCEUTILITY, "NativeKeyboard: input text too long(%d characters/glyphs max), truncating to game-requested length.", maxLength);
|
||||
inputChars.erase(maxLength, std::string::npos);
|
||||
// TODO: This is USING_WIN_UI only, so we rely on it being synchronous...
|
||||
// But we should really have this set some state that is checked each time NativeKeyboard is called.
|
||||
System_InputBoxGetString(ConvertWStringToUTF8(titleText), ConvertWStringToUTF8(defaultText), [&](bool result, const std::string &value) {
|
||||
if (result) {
|
||||
inputChars = ConvertUTF8ToWString(value);
|
||||
u32 maxLength = FieldMaxLength();
|
||||
if (inputChars.length() > maxLength) {
|
||||
ERROR_LOG(SCEUTILITY, "NativeKeyboard: input text too long(%d characters/glyphs max), truncating to game-requested length.", maxLength);
|
||||
inputChars.erase(maxLength, std::string::npos);
|
||||
}
|
||||
}
|
||||
}
|
||||
ChangeStatus(SCE_UTILITY_STATUS_FINISHED, 0);
|
||||
ChangeStatus(SCE_UTILITY_STATUS_FINISHED, 0);
|
||||
});
|
||||
|
||||
u16_le *outText = oskParams->fields[0].outtext;
|
||||
|
||||
|
|
|
@ -227,13 +227,13 @@ void System_SendMessage(const char *command, const char *parameter) {
|
|||
void System_AskForPermission(SystemPermission permission) {}
|
||||
PermissionStatus System_GetPermissionStatus(SystemPermission permission) { return PERMISSION_STATUS_GRANTED; }
|
||||
|
||||
bool System_InputBoxGetString(const char *title, const char *defaultValue, char *outValue, size_t outLength)
|
||||
{
|
||||
QString text = emugl->InputBoxGetQString(QString(title), QString(defaultValue));
|
||||
if (text.isEmpty())
|
||||
return false;
|
||||
strcpy(outValue, text.toStdString().c_str());
|
||||
return true;
|
||||
void System_InputBoxGetString(const std::string &title, const std::string &defaultValue, std::function<void(bool, const std::string &)> cb) {
|
||||
QString text = emugl->InputBoxGetQString(QString::fromStdString(title), QString::fromStdString(defaultValue));
|
||||
if (text.isEmpty()) {
|
||||
cb(false, "");
|
||||
} else {
|
||||
cb(true, text.toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
void Vibrate(int length_ms) {
|
||||
|
|
|
@ -26,13 +26,11 @@ void ChatMenu::CreatePopupContents(UI::ViewGroup *parent) {
|
|||
#if defined(USING_WIN_UI)
|
||||
//freeze the ui when using ctrl + C hotkey need workaround
|
||||
if (g_Config.bBypassOSKWithKeyboard && !g_Config.bFullScreen) {
|
||||
std::wstring titleText = ConvertUTF8ToWString(n->T("Chat"));
|
||||
std::wstring defaultText = ConvertUTF8ToWString(n->T("Chat Here"));
|
||||
std::wstring inputChars;
|
||||
if (System_InputBoxGetWString(titleText.c_str(), defaultText, inputChars)) {
|
||||
//chatEdit_->SetText(ConvertWStringToUTF8(inputChars));
|
||||
sendChat(ConvertWStringToUTF8(inputChars));
|
||||
}
|
||||
System_InputBoxGetString(n->T("Chat"), n->T("Chat Here"), [](bool result, const std::string &value) {
|
||||
if (result) {
|
||||
sendChat(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
#endif
|
||||
chatEdit_->OnEnter.Handle(this, &ChatMenu::OnSubmit);
|
||||
|
|
|
@ -1290,14 +1290,12 @@ UI::EventReturn GameSettingsScreen::OnAudioDevice(UI::EventParams &e) {
|
|||
|
||||
UI::EventReturn GameSettingsScreen::OnChangeQuickChat0(UI::EventParams &e) {
|
||||
#if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI)
|
||||
const size_t chat_len = 64;
|
||||
|
||||
char chat[chat_len];
|
||||
memset(chat, 0, sizeof(chat));
|
||||
|
||||
if (System_InputBoxGetString("Enter Quick Chat 1", g_Config.sQuickChat0.c_str(), chat, chat_len)) {
|
||||
g_Config.sQuickChat0 = chat;
|
||||
}
|
||||
auto n = GetI18NCategory("Networking");
|
||||
System_InputBoxGetString(n->T("Enter Quick Chat 1"), g_Config.sQuickChat0, [](bool result, const std::string &value) {
|
||||
if (result) {
|
||||
g_Config.sQuickChat0 = value;
|
||||
}
|
||||
});
|
||||
#elif defined(__ANDROID__)
|
||||
System_SendMessage("inputbox", ("quickchat0:" + g_Config.sQuickChat0).c_str());
|
||||
#endif
|
||||
|
@ -1306,14 +1304,12 @@ UI::EventReturn GameSettingsScreen::OnChangeQuickChat0(UI::EventParams &e) {
|
|||
|
||||
UI::EventReturn GameSettingsScreen::OnChangeQuickChat1(UI::EventParams &e) {
|
||||
#if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI)
|
||||
const size_t chat_len = 64;
|
||||
|
||||
char chat[chat_len];
|
||||
memset(chat, 0, sizeof(chat));
|
||||
|
||||
if (System_InputBoxGetString("Enter Quick Chat 2", g_Config.sQuickChat1.c_str(), chat, chat_len)) {
|
||||
g_Config.sQuickChat1 = chat;
|
||||
}
|
||||
auto n = GetI18NCategory("Networking");
|
||||
System_InputBoxGetString(n->T("Enter Quick Chat 2"), g_Config.sQuickChat1, [](bool result, const std::string &value) {
|
||||
if (result) {
|
||||
g_Config.sQuickChat1 = value;
|
||||
}
|
||||
});
|
||||
#elif defined(__ANDROID__)
|
||||
System_SendMessage("inputbox", ("quickchat1:" + g_Config.sQuickChat1).c_str());
|
||||
#endif
|
||||
|
@ -1322,14 +1318,12 @@ UI::EventReturn GameSettingsScreen::OnChangeQuickChat1(UI::EventParams &e) {
|
|||
|
||||
UI::EventReturn GameSettingsScreen::OnChangeQuickChat2(UI::EventParams &e) {
|
||||
#if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI)
|
||||
const size_t chat_len = 64;
|
||||
|
||||
char chat[chat_len];
|
||||
memset(chat, 0, sizeof(chat));
|
||||
|
||||
if (System_InputBoxGetString("Enter Quick Chat 3", g_Config.sQuickChat2.c_str(), chat, chat_len)) {
|
||||
g_Config.sQuickChat2 = chat;
|
||||
}
|
||||
auto n = GetI18NCategory("Networking");
|
||||
System_InputBoxGetString(n->T("Enter Quick Chat 3"), g_Config.sQuickChat2, [](bool result, const std::string &value) {
|
||||
if (result) {
|
||||
g_Config.sQuickChat2 = value;
|
||||
}
|
||||
});
|
||||
#elif defined(__ANDROID__)
|
||||
System_SendMessage("inputbox", ("quickchat2:" + g_Config.sQuickChat2).c_str());
|
||||
#endif
|
||||
|
@ -1338,14 +1332,12 @@ UI::EventReturn GameSettingsScreen::OnChangeQuickChat2(UI::EventParams &e) {
|
|||
|
||||
UI::EventReturn GameSettingsScreen::OnChangeQuickChat3(UI::EventParams &e) {
|
||||
#if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI)
|
||||
const size_t chat_len = 64;
|
||||
|
||||
char chat[chat_len];
|
||||
memset(chat, 0, sizeof(chat));
|
||||
|
||||
if (System_InputBoxGetString("Enter Quick Chat 4", g_Config.sQuickChat3.c_str(), chat, chat_len)) {
|
||||
g_Config.sQuickChat3 = chat;
|
||||
}
|
||||
auto n = GetI18NCategory("Networking");
|
||||
System_InputBoxGetString(n->T("Enter Quick Chat 4"), g_Config.sQuickChat3, [](bool result, const std::string &value) {
|
||||
if (result) {
|
||||
g_Config.sQuickChat3 = value;
|
||||
}
|
||||
});
|
||||
#elif defined(__ANDROID__)
|
||||
System_SendMessage("inputbox", ("quickchat3:" + g_Config.sQuickChat3).c_str());
|
||||
#endif
|
||||
|
@ -1354,14 +1346,12 @@ UI::EventReturn GameSettingsScreen::OnChangeQuickChat3(UI::EventParams &e) {
|
|||
|
||||
UI::EventReturn GameSettingsScreen::OnChangeQuickChat4(UI::EventParams &e) {
|
||||
#if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI)
|
||||
const size_t chat_len = 64;
|
||||
|
||||
char chat[chat_len];
|
||||
memset(chat, 0, sizeof(chat));
|
||||
|
||||
if (System_InputBoxGetString("Enter Quick Chat 5", g_Config.sQuickChat4.c_str(), chat, chat_len)) {
|
||||
g_Config.sQuickChat4 = chat;
|
||||
}
|
||||
auto n = GetI18NCategory("Networking");
|
||||
System_InputBoxGetString(n->T("Enter Quick Chat 5"), g_Config.sQuickChat4, [](bool result, const std::string &value) {
|
||||
if (result) {
|
||||
g_Config.sQuickChat4 = value;
|
||||
}
|
||||
});
|
||||
#elif defined(__ANDROID__)
|
||||
System_SendMessage("inputbox", ("quickchat4:" + g_Config.sQuickChat4).c_str());
|
||||
#endif
|
||||
|
@ -1370,14 +1360,12 @@ UI::EventReturn GameSettingsScreen::OnChangeQuickChat4(UI::EventParams &e) {
|
|||
|
||||
UI::EventReturn GameSettingsScreen::OnChangeNickname(UI::EventParams &e) {
|
||||
#if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI)
|
||||
const size_t name_len = 256;
|
||||
|
||||
char name[name_len];
|
||||
memset(name, 0, sizeof(name));
|
||||
|
||||
if (System_InputBoxGetString("Enter a new PSP nickname", g_Config.sNickName.c_str(), name, name_len)) {
|
||||
g_Config.sNickName = StripSpaces(name);
|
||||
}
|
||||
auto n = GetI18NCategory("Networking");
|
||||
System_InputBoxGetString(n->T("Enter a new PSP nickname"), g_Config.sNickName, [](bool result, const std::string &value) {
|
||||
if (result) {
|
||||
g_Config.sNickName = StripSpaces(value);
|
||||
}
|
||||
});
|
||||
#elif defined(__ANDROID__)
|
||||
// TODO: The return value is handled in NativeApp::inputbox_completed. This is horrific.
|
||||
System_SendMessage("inputbox", ("nickname:" + g_Config.sNickName).c_str());
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "stdafx.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
|
||||
#include "Common/CommonWindows.h"
|
||||
#include "Common/OSVersion.h"
|
||||
|
@ -337,23 +338,12 @@ void EnableCrashingOnCrashes() {
|
|||
FreeLibrary(kernel32);
|
||||
}
|
||||
|
||||
bool System_InputBoxGetString(const char *title, const char *defaultValue, char *outValue, size_t outLength)
|
||||
{
|
||||
void System_InputBoxGetString(const std::string &title, const std::string &defaultValue, std::function<void(bool, const std::string &)> cb) {
|
||||
std::string out;
|
||||
if (InputBox_GetString(MainWindow::GetHInstance(), MainWindow::GetHWND(), ConvertUTF8ToWString(title).c_str(), defaultValue, out)) {
|
||||
strcpy(outValue, out.c_str());
|
||||
return true;
|
||||
cb(true, out);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool System_InputBoxGetWString(const wchar_t *title, const std::wstring &defaultvalue, std::wstring &outvalue)
|
||||
{
|
||||
if (InputBox_GetWString(MainWindow::GetHInstance(), MainWindow::GetHWND(), title, defaultvalue, outvalue)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
cb(false, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -119,8 +120,7 @@ void OpenDirectory(const char *path);
|
|||
void LaunchBrowser(const char *url);
|
||||
void LaunchMarket(const char *url);
|
||||
void LaunchEmail(const char *email_address);
|
||||
bool System_InputBoxGetString(const char *title, const char *defaultValue, char *outValue, size_t outlength);
|
||||
bool System_InputBoxGetWString(const wchar_t *title, const std::wstring &defaultValue, std::wstring &outValue);
|
||||
void System_InputBoxGetString(const std::string &title, const std::string &defaultValue, std::function<void(bool, const std::string &)> cb);
|
||||
void System_SendMessage(const char *command, const char *parameter);
|
||||
PermissionStatus System_GetPermissionStatus(SystemPermission permission);
|
||||
void System_AskForPermission(SystemPermission permission);
|
||||
|
|
|
@ -81,7 +81,7 @@ bool System_GetPropertyBool(SystemProperty prop) {
|
|||
return false;
|
||||
}
|
||||
void System_SendMessage(const char *command, const char *parameter) {}
|
||||
bool System_InputBoxGetWString(const wchar_t *title, const std::wstring &defaultvalue, std::wstring &outvalue) { return false; }
|
||||
void System_InputBoxGetString(const std::string &title, const std::string &defaultValue, std::function<void(bool, const std::string &)> cb) { cb(false, ""); }
|
||||
void System_AskForPermission(SystemPermission permission) {}
|
||||
PermissionStatus System_GetPermissionStatus(SystemPermission permission) { return PERMISSION_STATUS_GRANTED; }
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ void NativeRender(GraphicsContext *graphicsContext) { }
|
|||
void NativeResized() { }
|
||||
|
||||
void System_SendMessage(const char *command, const char *parameter) {}
|
||||
bool System_InputBoxGetWString(const wchar_t *title, const std::wstring &defaultvalue, std::wstring &outvalue) { return false; }
|
||||
void System_InputBoxGetString(const std::string &title, const std::string &defaultValue, std::function<void(bool, const std::string &)> cb) { cb(false, ""); }
|
||||
void System_AskForPermission(SystemPermission permission) {}
|
||||
PermissionStatus System_GetPermissionStatus(SystemPermission permission) { return PERMISSION_STATUS_GRANTED; }
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue