From f45c5186ca734cdf37d81e9f5444eab5b6da80b1 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 12 Sep 2021 19:44:44 -0700 Subject: [PATCH] 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;