|
15 | 15 | #include "Core/System.h"
|
16 | 16 | #include "Core/HLE/proAdhoc.h"
|
17 | 17 | #include "UI/ChatScreen.h"
|
| 18 | +#include "UI/PopupScreens.h" |
18 | 19 |
|
19 | 20 | void ChatMenu::CreateContents(UI::ViewGroup *parent) {
|
20 | 21 | using namespace UI;
|
21 | 22 | auto n = GetI18NCategory(I18NCat::NETWORKING);
|
22 | 23 | LinearLayout *outer = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT,400));
|
23 | 24 | scroll_ = outer->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0)));
|
24 | 25 | 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); |
28 | 26 |
|
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 | + } |
33 | 40 |
|
34 | 41 | if (g_Config.bEnableQuickChat) {
|
35 | 42 | LinearLayout *quickChat = outer->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, WRAP_CONTENT)));
|
@@ -89,18 +96,37 @@ void ChatMenu::CreateSubviews(const Bounds &screenBounds) {
|
89 | 96 | UpdateChat();
|
90 | 97 | }
|
91 | 98 |
|
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) { |
94 | 100 | std::string chat = chatEdit_->GetText();
|
95 | 101 | chatEdit_->SetText("");
|
96 | 102 | chatEdit_->SetFocus();
|
97 | 103 | 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) { |
99 | 108 | 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 | + } |
104 | 130 | return UI::EVENT_DONE;
|
105 | 131 | }
|
106 | 132 |
|
|
0 commit comments