Chat: Cleanup the selection of chat input method, allow in-ui popup (what iOS needs).

This commit is contained in:
Henrik Rydgård 2024-10-02 00:59:57 +02:00
parent 3d31b4ac4c
commit b40098effd
3 changed files with 54 additions and 18 deletions

View File

@ -15,6 +15,7 @@
#include "Core/System.h"
#include "Core/HLE/proAdhoc.h"
#include "UI/ChatScreen.h"
#include "UI/PopupScreens.h"
void ChatMenu::CreateContents(UI::ViewGroup *parent) {
using namespace UI;
@ -22,14 +23,20 @@ void ChatMenu::CreateContents(UI::ViewGroup *parent) {
LinearLayout *outer = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT,400));
scroll_ = outer->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0)));
LinearLayout *bottom = outer->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, WRAP_CONTENT)));
#if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI) || defined(SDL)
chatEdit_ = bottom->Add(new TextEdit("", n->T("Chat message"), n->T("Chat Here"), new LinearLayoutParams(1.0)));
chatEdit_->OnEnter.Handle(this, &ChatMenu::OnSubmit);
#elif PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(IOS)
bottom->Add(new Button(n->T("Chat Here"),new LayoutParams(FILL_PARENT, WRAP_CONTENT)))->OnClick.Handle(this, &ChatMenu::OnSubmit);
bottom->Add(new Button(n->T("Send")))->OnClick.Handle(this, &ChatMenu::OnSubmit);
#endif
chatButton_ = nullptr;
chatEdit_ = nullptr;
chatVert_ = nullptr;
if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_DESKTOP) {
// We have direct keyboard input.
chatEdit_ = bottom->Add(new TextEdit("", n->T("Chat message"), n->T("Chat Here"), new LinearLayoutParams(1.0)));
chatEdit_->OnEnter.Handle(this, &ChatMenu::OnSubmitMessage);
} else {
// If we have a native input box, like on Android, or at least we can do a popup text input with our UI...
chatButton_ = bottom->Add(new Button(n->T("Chat message"), new LayoutParams(FILL_PARENT, WRAP_CONTENT)));
chatButton_->OnClick.Handle(this, &ChatMenu::OnAskForChatMessage);
}
if (g_Config.bEnableQuickChat) {
LinearLayout *quickChat = outer->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, WRAP_CONTENT)));
@ -89,18 +96,37 @@ void ChatMenu::CreateSubviews(const Bounds &screenBounds) {
UpdateChat();
}
UI::EventReturn ChatMenu::OnSubmit(UI::EventParams &e) {
#if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI) || (defined(SDL) && !PPSSPP_PLATFORM(SWITCH))
UI::EventReturn ChatMenu::OnSubmitMessage(UI::EventParams &e) {
std::string chat = chatEdit_->GetText();
chatEdit_->SetText("");
chatEdit_->SetFocus();
sendChat(chat);
#elif PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(SWITCH) || PPSSPP_PLATFORM(IOS)
return UI::EVENT_DONE;
}
UI::EventReturn ChatMenu::OnAskForChatMessage(UI::EventParams &e) {
auto n = GetI18NCategory(I18NCat::NETWORKING);
using namespace UI;
if (System_GetPropertyBool(SYSPROP_HAS_TEXT_INPUT_DIALOG)) {
System_InputBoxGetString(token_, n->T("Chat"), "", false, [](const std::string &value, int) {
sendChat(value);
});
#endif
} else {
// We need to pop up a UI inputbox.
messageTemp_.clear();
TextEditPopupScreen *popupScreen = new TextEditPopupScreen(&messageTemp_, "", n->T("Chat message"), 256);
if (System_GetPropertyBool(SYSPROP_KEYBOARD_IS_SOFT)) {
popupScreen->SetAlignTop(true);
}
popupScreen->OnChange.Add([=](UI::EventParams &e) {
sendChat(messageTemp_);
return UI::EVENT_DONE;
});
popupScreen->SetPopupOrigin(chatButton_);
screenManager_->push(popupScreen);
}
return UI::EVENT_DONE;
}

View File

@ -5,8 +5,8 @@
class ChatMenu : public UI::AnchorLayout {
public:
ChatMenu(int token, const Bounds &screenBounds, UI::LayoutParams *lp = nullptr)
: UI::AnchorLayout(lp), token_(token) {
ChatMenu(int token, const Bounds &screenBounds, ScreenManager *screenManager, UI::LayoutParams *lp = nullptr)
: UI::AnchorLayout(lp), screenManager_(screenManager), token_(token) {
CreateSubviews(screenBounds);
}
void Update() override;
@ -25,7 +25,9 @@ private:
void CreateContents(UI::ViewGroup *parent);
void UpdateChat();
UI::EventReturn OnSubmit(UI::EventParams &e);
UI::EventReturn OnAskForChatMessage(UI::EventParams &e);
UI::EventReturn OnSubmitMessage(UI::EventParams &e);
UI::EventReturn OnQuickChat1(UI::EventParams &e);
UI::EventReturn OnQuickChat2(UI::EventParams &e);
UI::EventReturn OnQuickChat3(UI::EventParams &e);
@ -38,9 +40,12 @@ private:
UI::ScrollView *scroll_ = nullptr;
UI::LinearLayout *chatVert_ = nullptr;
UI::ViewGroup *box_ = nullptr;
ScreenManager *screenManager_;
int chatChangeID_ = 0;
bool toBottom_ = true;
bool promptInput_ = false;
int token_;
std::string messageTemp_;
UI::Button *chatButton_ = nullptr;
};

View File

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