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.
This commit is contained in:
Unknown W. Brackets 2021-09-12 19:44:44 -07:00
parent 96fd29c86f
commit f45c5186ca
4 changed files with 58 additions and 56 deletions

View file

@ -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();

View file

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

View file

@ -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 &params) {
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;
}

View file

@ -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;