Skip to content

Commit 4ac6ee4

Browse files
committed
Chat: Cleanup the selection of chat input method, allow in-ui popup (what iOS needs).
1 parent f2478b4 commit 4ac6ee4

File tree

3 files changed

+54
-18
lines changed

3 files changed

+54
-18
lines changed

UI/ChatScreen.cpp

+40-14
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,28 @@
1515
#include "Core/System.h"
1616
#include "Core/HLE/proAdhoc.h"
1717
#include "UI/ChatScreen.h"
18+
#include "UI/PopupScreens.h"
1819

1920
void ChatMenu::CreateContents(UI::ViewGroup *parent) {
2021
using namespace UI;
2122
auto n = GetI18NCategory(I18NCat::NETWORKING);
2223
LinearLayout *outer = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT,400));
2324
scroll_ = outer->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0)));
2425
LinearLayout *bottom = outer->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, WRAP_CONTENT)));
25-
#if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI) || defined(SDL)
26-
chatEdit_ = bottom->Add(new TextEdit("", n->T("Chat message"), n->T("Chat Here"), new LinearLayoutParams(1.0)));
27-
chatEdit_->OnEnter.Handle(this, &ChatMenu::OnSubmit);
2826

29-
#elif PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(IOS)
30-
bottom->Add(new Button(n->T("Chat Here"),new LayoutParams(FILL_PARENT, WRAP_CONTENT)))->OnClick.Handle(this, &ChatMenu::OnSubmit);
31-
bottom->Add(new Button(n->T("Send")))->OnClick.Handle(this, &ChatMenu::OnSubmit);
32-
#endif
27+
chatButton_ = nullptr;
28+
chatEdit_ = nullptr;
29+
chatVert_ = nullptr;
30+
31+
if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_DESKTOP) {
32+
// We have direct keyboard input.
33+
chatEdit_ = bottom->Add(new TextEdit("", n->T("Chat message"), n->T("Chat Here"), new LinearLayoutParams(1.0)));
34+
chatEdit_->OnEnter.Handle(this, &ChatMenu::OnSubmitMessage);
35+
} else {
36+
// If we have a native input box, like on Android, or at least we can do a popup text input with our UI...
37+
chatButton_ = bottom->Add(new Button(n->T("Chat message"), new LayoutParams(FILL_PARENT, WRAP_CONTENT)));
38+
chatButton_->OnClick.Handle(this, &ChatMenu::OnAskForChatMessage);
39+
}
3340

3441
if (g_Config.bEnableQuickChat) {
3542
LinearLayout *quickChat = outer->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, WRAP_CONTENT)));
@@ -89,18 +96,37 @@ void ChatMenu::CreateSubviews(const Bounds &screenBounds) {
8996
UpdateChat();
9097
}
9198

92-
UI::EventReturn ChatMenu::OnSubmit(UI::EventParams &e) {
93-
#if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI) || (defined(SDL) && !PPSSPP_PLATFORM(SWITCH))
99+
UI::EventReturn ChatMenu::OnSubmitMessage(UI::EventParams &e) {
94100
std::string chat = chatEdit_->GetText();
95101
chatEdit_->SetText("");
96102
chatEdit_->SetFocus();
97103
sendChat(chat);
98-
#elif PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(SWITCH) || PPSSPP_PLATFORM(IOS)
104+
return UI::EVENT_DONE;
105+
}
106+
107+
UI::EventReturn ChatMenu::OnAskForChatMessage(UI::EventParams &e) {
99108
auto n = GetI18NCategory(I18NCat::NETWORKING);
100-
System_InputBoxGetString(token_, n->T("Chat"), "", false, [](const std::string &value, int) {
101-
sendChat(value);
102-
});
103-
#endif
109+
110+
using namespace UI;
111+
112+
if (System_GetPropertyBool(SYSPROP_HAS_TEXT_INPUT_DIALOG)) {
113+
System_InputBoxGetString(token_, n->T("Chat"), "", false, [](const std::string &value, int) {
114+
sendChat(value);
115+
});
116+
} else {
117+
// We need to pop up a UI inputbox.
118+
messageTemp_.clear();
119+
TextEditPopupScreen *popupScreen = new TextEditPopupScreen(&messageTemp_, "", n->T("Chat message"), 256);
120+
if (System_GetPropertyBool(SYSPROP_KEYBOARD_IS_SOFT)) {
121+
popupScreen->SetAlignTop(true);
122+
}
123+
popupScreen->OnChange.Add([=](UI::EventParams &e) {
124+
sendChat(messageTemp_);
125+
return UI::EVENT_DONE;
126+
});
127+
popupScreen->SetPopupOrigin(chatButton_);
128+
screenManager_->push(popupScreen);
129+
}
104130
return UI::EVENT_DONE;
105131
}
106132

UI/ChatScreen.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
class ChatMenu : public UI::AnchorLayout {
77
public:
8-
ChatMenu(int token, const Bounds &screenBounds, UI::LayoutParams *lp = nullptr)
9-
: UI::AnchorLayout(lp), token_(token) {
8+
ChatMenu(int token, const Bounds &screenBounds, ScreenManager *screenManager, UI::LayoutParams *lp = nullptr)
9+
: UI::AnchorLayout(lp), screenManager_(screenManager), token_(token) {
1010
CreateSubviews(screenBounds);
1111
}
1212
void Update() override;
@@ -25,7 +25,9 @@ class ChatMenu : public UI::AnchorLayout {
2525
void CreateContents(UI::ViewGroup *parent);
2626
void UpdateChat();
2727

28-
UI::EventReturn OnSubmit(UI::EventParams &e);
28+
UI::EventReturn OnAskForChatMessage(UI::EventParams &e);
29+
30+
UI::EventReturn OnSubmitMessage(UI::EventParams &e);
2931
UI::EventReturn OnQuickChat1(UI::EventParams &e);
3032
UI::EventReturn OnQuickChat2(UI::EventParams &e);
3133
UI::EventReturn OnQuickChat3(UI::EventParams &e);
@@ -38,9 +40,12 @@ class ChatMenu : public UI::AnchorLayout {
3840
UI::ScrollView *scroll_ = nullptr;
3941
UI::LinearLayout *chatVert_ = nullptr;
4042
UI::ViewGroup *box_ = nullptr;
43+
ScreenManager *screenManager_;
4144

4245
int chatChangeID_ = 0;
4346
bool toBottom_ = true;
4447
bool promptInput_ = false;
4548
int token_;
49+
std::string messageTemp_;
50+
UI::Button *chatButton_ = nullptr;
4651
};

UI/EmuScreen.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,11 @@ EmuScreen::~EmuScreen() {
468468
}
469469

470470
void EmuScreen::dialogFinished(const Screen *dialog, DialogResult result) {
471+
if (std::string_view(dialog->tag()) == "TextEditPopup") {
472+
// Chat message finished.
473+
return;
474+
}
475+
471476
// TODO: improve the way with which we got commands from PauseMenu.
472477
// DR_CANCEL/DR_BACK means clicked on "continue", DR_OK means clicked on "back to menu",
473478
// DR_YES means a message sent to PauseMenu by System_PostUIMessage.
@@ -1055,7 +1060,7 @@ void EmuScreen::CreateViews() {
10551060
root_->Add(btn)->OnClick.Handle(this, &EmuScreen::OnChat);
10561061
chatButton_ = btn;
10571062
}
1058-
chatMenu_ = root_->Add(new ChatMenu(GetRequesterToken(), screenManager()->getUIContext()->GetBounds(), new LayoutParams(FILL_PARENT, FILL_PARENT)));
1063+
chatMenu_ = root_->Add(new ChatMenu(GetRequesterToken(), screenManager()->getUIContext()->GetBounds(), screenManager(), new LayoutParams(FILL_PARENT, FILL_PARENT)));
10591064
chatMenu_->SetVisibility(UI::V_GONE);
10601065
} else {
10611066
chatButton_ = nullptr;

0 commit comments

Comments
 (0)