From 6b107a884b50d272bf907277341828aad9732ccd Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 12 Sep 2021 20:16:05 -0700 Subject: [PATCH] UI: Cleanup input box for chat. --- UI/ChatScreen.cpp | 33 +++++++++++++++++++++++---------- UI/ChatScreen.h | 2 ++ UI/EmuScreen.cpp | 5 +++++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/UI/ChatScreen.cpp b/UI/ChatScreen.cpp index e72b14f9ef..1e3ad6ed90 100644 --- a/UI/ChatScreen.cpp +++ b/UI/ChatScreen.cpp @@ -23,16 +23,6 @@ void ChatMenu::CreateContents(UI::ViewGroup *parent) { 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))); -#if defined(USING_WIN_UI) - // freeze the ui when using ctrl + C hotkey need workaround - if (g_Config.bBypassOSKWithKeyboard && !g_Config.bFullScreen) { - 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); #elif PPSSPP_PLATFORM(ANDROID) @@ -176,6 +166,8 @@ void ChatMenu::UpdateChat() { } void ChatMenu::Update() { + auto n = GetI18NCategory("Networking"); + AnchorLayout::Update(); if (scroll_ && toBottom_) { toBottom_ = false; @@ -186,6 +178,27 @@ void ChatMenu::Update() { UpdateChat(); updateChatScreen = false; } + +#if defined(USING_WIN_UI) + // Could remove the fullscreen check here, it works now. + if (promptInput_ && g_Config.bBypassOSKWithKeyboard && !g_Config.bFullScreen) { + System_InputBoxGetString(n->T("Chat"), n->T("Chat Here"), [](bool result, const std::string &value) { + if (result) { + sendChat(value); + } + }); + promptInput_ = false; + } +#endif +} + +bool ChatMenu::SubviewFocused(UI::View *view) { + if (!AnchorLayout::SubviewFocused(view)) + return false; + + promptInput_ = true; + + return true; } ChatMenu::~ChatMenu() { diff --git a/UI/ChatScreen.h b/UI/ChatScreen.h index 54c791af09..11fa3ac880 100644 --- a/UI/ChatScreen.h +++ b/UI/ChatScreen.h @@ -10,6 +10,7 @@ public: } ~ChatMenu(); void Update() override; + bool SubviewFocused(UI::View *view) override; bool Contains(float x, float y) const { if (box_) @@ -37,4 +38,5 @@ private: UI::ViewGroup *box_ = nullptr; bool toBottom_ = true; + bool promptInput_ = false; }; diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 9ce3c2820f..619bf70c1f 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -952,7 +952,12 @@ UI::EventReturn EmuScreen::OnChat(UI::EventParams ¶ms) { #if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI) || defined(SDL) UI::EnableFocusMovement(true); root_->SetDefaultFocusView(chatMenu_); + chatMenu_->SetFocus(); + UI::View *focused = UI::GetFocusedView(); + if (focused) { + root_->SubviewFocused(focused); + } #endif } return UI::EVENT_DONE;