From 96fd29c86f89e8b3fcb30a3729be9572d23027aa Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 12 Sep 2021 19:41:47 -0700 Subject: [PATCH 1/4] UI: Allow UI keys on emuscreen of focused. This is only if you already focus something. --- UI/EmuScreen.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 6d9f0360cc..ff383d82fc 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -728,6 +728,12 @@ void EmuScreen::onVKeyUp(int virtualKeyCode) { bool EmuScreen::key(const KeyInput &key) { Core_NotifyActivity(); + if (UI::IsFocusMovementEnabled()) { + if (UIScreen::key(key)) { + return true; + } + } + return controlMapper_.Key(key, &pauseTrigger_); } From f45c5186ca734cdf37d81e9f5444eab5b6da80b1 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 12 Sep 2021 19:44:44 -0700 Subject: [PATCH 2/4] UI: Move the chat message box to just a view. Instead of being a popup. This should make it easier to make sure things work normally, and avoids some of the strange overrides of PopupScreen it previously had. --- UI/ChatScreen.cpp | 58 +++++++++++------------------------------------ UI/ChatScreen.h | 25 ++++++++++++-------- UI/EmuScreen.cpp | 29 ++++++++++++++++++++++-- UI/EmuScreen.h | 2 ++ 4 files changed, 58 insertions(+), 56 deletions(-) diff --git a/UI/ChatScreen.cpp b/UI/ChatScreen.cpp index c93d755e42..e72b14f9ef 100644 --- a/UI/ChatScreen.cpp +++ b/UI/ChatScreen.cpp @@ -15,7 +15,7 @@ #include "Core/HLE/proAdhoc.h" #include "UI/ChatScreen.h" -void ChatMenu::CreatePopupContents(UI::ViewGroup *parent) { +void ChatMenu::CreateContents(UI::ViewGroup *parent) { using namespace UI; auto n = GetI18NCategory("Networking"); LinearLayout *outer = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT,400)); @@ -53,37 +53,31 @@ void ChatMenu::CreatePopupContents(UI::ViewGroup *parent) { parent->Add(outer); } -void ChatMenu::CreateViews() { +void ChatMenu::CreateSubviews(const Bounds &screenBounds) { using namespace UI; auto n = GetI18NCategory("Networking"); - UIContext &dc = *screenManager()->getUIContext(); - - AnchorLayout *anchor = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT)); - anchor->Overflow(false); - root_ = anchor; - - float yres = screenManager()->getUIContext()->GetBounds().h; + float width = 550.0f; switch (g_Config.iChatScreenPosition) { // the chat screen size is still static 280x240 need a dynamic size based on device resolution case 0: - box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(PopupWidth(), FillVertical() ? yres - 30 : WRAP_CONTENT, 280, NONE, NONE, 240, true)); + box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(width, WRAP_CONTENT, 280, NONE, NONE, 240, true)); break; case 1: - box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(PopupWidth(), FillVertical() ? yres - 30 : WRAP_CONTENT, dc.GetBounds().centerX(), NONE, NONE, 240, true)); + box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(width, WRAP_CONTENT, screenBounds.centerX(), NONE, NONE, 240, true)); break; case 2: - box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(PopupWidth(), FillVertical() ? yres - 30 : WRAP_CONTENT, NONE, NONE, 280, 240, true)); + box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(width, WRAP_CONTENT, NONE, NONE, 280, 240, true)); break; case 3: - box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(PopupWidth(), FillVertical() ? yres - 30 : WRAP_CONTENT, 280, 240, NONE, NONE, true)); + box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(width, WRAP_CONTENT, 280, 240, NONE, NONE, true)); break; case 4: - box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(PopupWidth(), FillVertical() ? yres - 30 : WRAP_CONTENT, dc.GetBounds().centerX(), 240, NONE, NONE, true)); + box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(width, WRAP_CONTENT, screenBounds.centerX(), 240, NONE, NONE, true)); break; case 5: - box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(PopupWidth(), FillVertical() ? yres - 30 : WRAP_CONTENT, NONE, 240, 280, NONE, true)); + box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(width, WRAP_CONTENT, NONE, 240, 280, NONE, true)); break; default: box_ = nullptr; @@ -91,24 +85,14 @@ void ChatMenu::CreateViews() { } if (box_) { - root_->Add(box_); + Add(box_); box_->SetBG(UI::Drawable(0x99303030)); box_->SetHasDropShadow(false); View *title = new PopupHeader(n->T("Chat")); box_->Add(title); - CreatePopupContents(box_); -#if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI) || defined(SDL) - UI::EnableFocusMovement(true); - root_->SetDefaultFocusView(box_); - box_->SubviewFocused(chatEdit_); - root_->SetFocus(); -#else - //root_->SetDefaultFocusView(box_); - //box_->SubviewFocused(scroll_); - //root_->SetFocus(); -#endif + CreateContents(box_); } chatScreenVisible = true; newChat = 0; @@ -116,10 +100,6 @@ void ChatMenu::CreateViews() { UpdateChat(); } -void ChatMenu::dialogFinished(const Screen *dialog, DialogResult result) { - UpdateUIState(UISTATE_INGAME); -} - UI::EventReturn ChatMenu::OnSubmit(UI::EventParams &e) { #if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI) || defined(SDL) std::string chat = chatEdit_->GetText(); @@ -195,20 +175,8 @@ void ChatMenu::UpdateChat() { } } -bool ChatMenu::touch(const TouchInput &touch) { - if (!box_ || (touch.flags & TOUCH_DOWN) == 0) { - return UIDialogScreen::touch(touch); - } - - if (!box_->GetBounds().Contains(touch.x, touch.y)){ - screenManager()->finishDialog(this, DR_BACK); - } - - return UIDialogScreen::touch(touch); -} - -void ChatMenu::update() { - PopupScreen::update(); +void ChatMenu::Update() { + AnchorLayout::Update(); if (scroll_ && toBottom_) { toBottom_ = false; scroll_->ScrollToBottom(); diff --git a/UI/ChatScreen.h b/UI/ChatScreen.h index 48fe7165f1..54c791af09 100644 --- a/UI/ChatScreen.h +++ b/UI/ChatScreen.h @@ -3,20 +3,25 @@ #include "ppsspp_config.h" #include "Common/UI/UIScreen.h" -class ChatMenu : public PopupScreen { +class ChatMenu : public UI::AnchorLayout { public: - ChatMenu(): PopupScreen("Chat") {} + ChatMenu(const Bounds &screenBounds, UI::LayoutParams *lp = nullptr): UI::AnchorLayout(lp) { + CreateSubviews(screenBounds); + } ~ChatMenu(); - void CreatePopupContents(UI::ViewGroup *parent) override; - void CreateViews() override; - void dialogFinished(const Screen *dialog, DialogResult result) override; - bool touch(const TouchInput &touch) override; - void update() override; - void UpdateChat(); + void Update() override; - bool toBottom_ = true; + bool Contains(float x, float y) const { + if (box_) + return box_->GetBounds().Contains(x, y); + return false; + } private: + void CreateSubviews(const Bounds &screenBounds); + void CreateContents(UI::ViewGroup *parent); + void UpdateChat(); + UI::EventReturn OnSubmit(UI::EventParams &e); UI::EventReturn OnQuickChat1(UI::EventParams &e); UI::EventReturn OnQuickChat2(UI::EventParams &e); @@ -30,4 +35,6 @@ private: UI::ScrollView *scroll_ = nullptr; UI::LinearLayout *chatVert_ = nullptr; UI::ViewGroup *box_ = nullptr; + + bool toBottom_ = true; }; diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index ff383d82fc..9ce3c2820f 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -541,6 +541,13 @@ inline float clamp1(float x) { bool EmuScreen::touch(const TouchInput &touch) { Core_NotifyActivity(); + if (chatMenu_ && (touch.flags & TOUCH_DOWN) != 0 && !chatMenu_->Contains(touch.x, touch.y)) { + chatMenu_->SetVisibility(UI::V_GONE); + if (chatButton_) + chatButton_->SetVisibility(UI::V_VISIBLE); + UI::EnableFocusMovement(false); + } + if (root_) { root_->Touch(touch); return true; @@ -729,7 +736,14 @@ bool EmuScreen::key(const KeyInput &key) { Core_NotifyActivity(); if (UI::IsFocusMovementEnabled()) { - if (UIScreen::key(key)) { + if ((key.flags & KEY_DOWN) != 0 && UI::IsEscapeKey(key)) { + if (chatMenu_) + chatMenu_->SetVisibility(UI::V_GONE); + if (chatButton_) + chatButton_->SetVisibility(UI::V_VISIBLE); + UI::EnableFocusMovement(false); + return true; + } else if (UIScreen::key(key)) { return true; } } @@ -851,8 +865,11 @@ void EmuScreen::CreateViews() { ChoiceWithValueDisplay *btn = new ChoiceWithValueDisplay(&newChat, n->T("Chat"), layoutParams); root_->Add(btn)->OnClick.Handle(this, &EmuScreen::OnChat); chatButton_ = btn; + chatMenu_ = root_->Add(new ChatMenu(screenManager()->getUIContext()->GetBounds(), new LayoutParams(FILL_PARENT, FILL_PARENT))); + chatMenu_->SetVisibility(UI::V_GONE); } else { chatButton_ = nullptr; + chatMenu_ = nullptr; } saveStatePreview_ = new AsyncImageFileView(Path(), IS_FIXED, new AnchorLayoutParams(bounds.centerX(), 100, NONE, NONE, true)); @@ -929,7 +946,15 @@ UI::EventReturn EmuScreen::OnChat(UI::EventParams ¶ms) { if (chatButton_ != nullptr && chatButton_->GetVisibility() == UI::V_VISIBLE) { chatButton_->SetVisibility(UI::V_GONE); } - screenManager()->push(new ChatMenu()); + if (chatMenu_ != nullptr) { + chatMenu_->SetVisibility(UI::V_VISIBLE); + +#if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI) || defined(SDL) + UI::EnableFocusMovement(true); + root_->SetDefaultFocusView(chatMenu_); + chatMenu_->SetFocus(); +#endif + } return UI::EVENT_DONE; } diff --git a/UI/EmuScreen.h b/UI/EmuScreen.h index a61d6a2b11..79f47982d6 100644 --- a/UI/EmuScreen.h +++ b/UI/EmuScreen.h @@ -33,6 +33,7 @@ struct AxisInput; class AsyncImageFileView; class OnScreenMessagesView; +class ChatMenu; class EmuScreen : public UIScreen { public: @@ -101,6 +102,7 @@ private: UI::Button *resumeButton_ = nullptr; UI::Button *resetButton_ = nullptr; UI::View *chatButton_ = nullptr; + ChatMenu *chatMenu_ = nullptr; UI::Button *cardboardDisableButton_ = nullptr; OnScreenMessagesView *onScreenMessagesView_ = nullptr; From 6b107a884b50d272bf907277341828aad9732ccd Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 12 Sep 2021 20:16:05 -0700 Subject: [PATCH 3/4] 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; From 40c233fa777c4728f8c8de4294e9a9ee1e3d8c9a Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 12 Sep 2021 20:20:17 -0700 Subject: [PATCH 4/4] UI: Update flags more correctly in chat. Not the ideal interface here, though... --- UI/ChatScreen.cpp | 9 +++++---- UI/ChatScreen.h | 3 ++- UI/EmuScreen.cpp | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/UI/ChatScreen.cpp b/UI/ChatScreen.cpp index 1e3ad6ed90..dfb1acb14d 100644 --- a/UI/ChatScreen.cpp +++ b/UI/ChatScreen.cpp @@ -84,8 +84,6 @@ void ChatMenu::CreateSubviews(const Bounds &screenBounds) { CreateContents(box_); } - chatScreenVisible = true; - newChat = 0; UpdateChat(); } @@ -179,6 +177,9 @@ void ChatMenu::Update() { updateChatScreen = false; } + chatScreenVisible = true; + newChat = 0; + #if defined(USING_WIN_UI) // Could remove the fullscreen check here, it works now. if (promptInput_ && g_Config.bBypassOSKWithKeyboard && !g_Config.bFullScreen) { @@ -197,10 +198,10 @@ bool ChatMenu::SubviewFocused(UI::View *view) { return false; promptInput_ = true; - return true; } -ChatMenu::~ChatMenu() { +void ChatMenu::Close() { + SetVisibility(UI::V_GONE); chatScreenVisible = false; } diff --git a/UI/ChatScreen.h b/UI/ChatScreen.h index 11fa3ac880..83ca61b7b4 100644 --- a/UI/ChatScreen.h +++ b/UI/ChatScreen.h @@ -8,10 +8,11 @@ public: ChatMenu(const Bounds &screenBounds, UI::LayoutParams *lp = nullptr): UI::AnchorLayout(lp) { CreateSubviews(screenBounds); } - ~ChatMenu(); void Update() override; bool SubviewFocused(UI::View *view) override; + void Close(); + bool Contains(float x, float y) const { if (box_) return box_->GetBounds().Contains(x, y); diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 619bf70c1f..1b499a4708 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -542,7 +542,7 @@ bool EmuScreen::touch(const TouchInput &touch) { Core_NotifyActivity(); if (chatMenu_ && (touch.flags & TOUCH_DOWN) != 0 && !chatMenu_->Contains(touch.x, touch.y)) { - chatMenu_->SetVisibility(UI::V_GONE); + chatMenu_->Close(); if (chatButton_) chatButton_->SetVisibility(UI::V_VISIBLE); UI::EnableFocusMovement(false); @@ -738,7 +738,7 @@ bool EmuScreen::key(const KeyInput &key) { if (UI::IsFocusMovementEnabled()) { if ((key.flags & KEY_DOWN) != 0 && UI::IsEscapeKey(key)) { if (chatMenu_) - chatMenu_->SetVisibility(UI::V_GONE); + chatMenu_->Close(); if (chatButton_) chatButton_->SetVisibility(UI::V_VISIBLE); UI::EnableFocusMovement(false);