Skip to content

Commit

Permalink
Chat: Cleanup the selection of chat input method, allow in-ui popup (…
Browse files Browse the repository at this point in the history
…what iOS needs).
  • Loading branch information
hrydgard committed Oct 1, 2024
1 parent f2478b4 commit 4ac6ee4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
54 changes: 40 additions & 14 deletions UI/ChatScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,28 @@
#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;
auto n = GetI18NCategory(I18NCat::NETWORKING);
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)));
Expand Down Expand Up @@ -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);
System_InputBoxGetString(token_, n->T("Chat"), "", false, [](const std::string &value, int) {
sendChat(value);
});
#endif

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);
});
} 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;
}

Expand Down
11 changes: 8 additions & 3 deletions UI/ChatScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,7 +25,9 @@ class ChatMenu : public UI::AnchorLayout {
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);
Expand All @@ -38,9 +40,12 @@ class ChatMenu : public UI::AnchorLayout {
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;
};
7 changes: 6 additions & 1 deletion UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4ac6ee4

Please sign in to comment.