mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-17 19:34:39 +01:00
Merge pull request #14841 from unknownbrackets/ui-chat-view
Use a view for the chat log
This commit is contained in:
4 files changed
+98
-68
No files matched your search
+39
-57
@@ -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));
|
||||
@@ -23,16 +23,6 @@ void ChatMenu::CreatePopupContents(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)
|
||||
@@ -53,37 +43,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,35 +75,19 @@ 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;
|
||||
|
||||
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 +163,10 @@ void ChatMenu::UpdateChat() {
|
||||
}
|
||||
}
|
||||
|
||||
bool ChatMenu::touch(const TouchInput &touch) {
|
||||
if (!box_ || (touch.flags & TOUCH_DOWN) == 0) {
|
||||
return UIDialogScreen::touch(touch);
|
||||
}
|
||||
void ChatMenu::Update() {
|
||||
auto n = GetI18NCategory("Networking");
|
||||
|
||||
if (!box_->GetBounds().Contains(touch.x, touch.y)){
|
||||
screenManager()->finishDialog(this, DR_BACK);
|
||||
}
|
||||
|
||||
return UIDialogScreen::touch(touch);
|
||||
}
|
||||
|
||||
void ChatMenu::update() {
|
||||
PopupScreen::update();
|
||||
AnchorLayout::Update();
|
||||
if (scroll_ && toBottom_) {
|
||||
toBottom_ = false;
|
||||
scroll_->ScrollToBottom();
|
||||
@@ -218,8 +176,32 @@ void ChatMenu::update() {
|
||||
UpdateChat();
|
||||
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) {
|
||||
System_InputBoxGetString(n->T("Chat"), n->T("Chat Here"), [](bool result, const std::string &value) {
|
||||
if (result) {
|
||||
sendChat(value);
|
||||
}
|
||||
});
|
||||
promptInput_ = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
ChatMenu::~ChatMenu() {
|
||||
bool ChatMenu::SubviewFocused(UI::View *view) {
|
||||
if (!AnchorLayout::SubviewFocused(view))
|
||||
return false;
|
||||
|
||||
promptInput_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void ChatMenu::Close() {
|
||||
SetVisibility(UI::V_GONE);
|
||||
chatScreenVisible = false;
|
||||
}
|
||||
+20
-10
@@ -3,20 +3,27 @@
|
||||
#include "ppsspp_config.h"
|
||||
#include "Common/UI/UIScreen.h"
|
||||
|
||||
class ChatMenu : public PopupScreen {
|
||||
class ChatMenu : public UI::AnchorLayout {
|
||||
public:
|
||||
ChatMenu(): PopupScreen("Chat") {}
|
||||
~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();
|
||||
ChatMenu(const Bounds &screenBounds, UI::LayoutParams *lp = nullptr): UI::AnchorLayout(lp) {
|
||||
CreateSubviews(screenBounds);
|
||||
}
|
||||
void Update() override;
|
||||
bool SubviewFocused(UI::View *view) override;
|
||||
|
||||
bool toBottom_ = true;
|
||||
void Close();
|
||||
|
||||
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 +37,7 @@ private:
|
||||
UI::ScrollView *scroll_ = nullptr;
|
||||
UI::LinearLayout *chatVert_ = nullptr;
|
||||
UI::ViewGroup *box_ = nullptr;
|
||||
|
||||
bool toBottom_ = true;
|
||||
bool promptInput_ = false;
|
||||
};
|
||||
+37
-1
@@ -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_->Close();
|
||||
if (chatButton_)
|
||||
chatButton_->SetVisibility(UI::V_VISIBLE);
|
||||
UI::EnableFocusMovement(false);
|
||||
}
|
||||
|
||||
if (root_) {
|
||||
root_->Touch(touch);
|
||||
return true;
|
||||
@@ -728,6 +735,19 @@ void EmuScreen::onVKeyUp(int virtualKeyCode) {
|
||||
bool EmuScreen::key(const KeyInput &key) {
|
||||
Core_NotifyActivity();
|
||||
|
||||
if (UI::IsFocusMovementEnabled()) {
|
||||
if ((key.flags & KEY_DOWN) != 0 && UI::IsEscapeKey(key)) {
|
||||
if (chatMenu_)
|
||||
chatMenu_->Close();
|
||||
if (chatButton_)
|
||||
chatButton_->SetVisibility(UI::V_VISIBLE);
|
||||
UI::EnableFocusMovement(false);
|
||||
return true;
|
||||
} else if (UIScreen::key(key)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return controlMapper_.Key(key, &pauseTrigger_);
|
||||
}
|
||||
|
||||
@@ -845,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));
|
||||
@@ -923,7 +946,20 @@ 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();
|
||||
UI::View *focused = UI::GetFocusedView();
|
||||
if (focused) {
|
||||
root_->SubviewFocused(focused);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return UI::EVENT_DONE;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user