2020-08-20 04:35:31 +00:00
|
|
|
#include <ctype.h>
|
2020-03-08 13:32:32 +00:00
|
|
|
#include "ppsspp_config.h"
|
2020-10-01 11:05:04 +00:00
|
|
|
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/UI/Root.h"
|
|
|
|
#include "Common/UI/Context.h"
|
|
|
|
#include "Common/UI/View.h"
|
|
|
|
#include "Common/UI/ViewGroup.h"
|
2023-01-11 09:36:00 +00:00
|
|
|
#include "Common/UI/ScrollView.h"
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/UI/UI.h"
|
2020-10-01 11:05:04 +00:00
|
|
|
|
|
|
|
#include "Common/Data/Text/I18n.h"
|
|
|
|
#include "Common/Data/Encoding/Utf8.h"
|
2023-03-22 11:26:14 +00:00
|
|
|
#include "Common/System/Request.h"
|
2016-10-21 10:35:54 +00:00
|
|
|
#include "Core/Config.h"
|
|
|
|
#include "Core/System.h"
|
|
|
|
#include "Core/HLE/proAdhoc.h"
|
2020-08-20 04:35:31 +00:00
|
|
|
#include "UI/ChatScreen.h"
|
2016-10-21 10:35:54 +00:00
|
|
|
|
2021-09-13 02:44:44 +00:00
|
|
|
void ChatMenu::CreateContents(UI::ViewGroup *parent) {
|
2016-10-21 10:35:54 +00:00
|
|
|
using namespace UI;
|
2023-04-05 22:34:50 +00:00
|
|
|
auto n = GetI18NCategory(I18NCat::NETWORKING);
|
2016-10-22 16:06:07 +00:00
|
|
|
LinearLayout *outer = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT,400));
|
2021-09-15 08:25:26 +00:00
|
|
|
scroll_ = outer->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0)));
|
2016-10-21 10:35:54 +00:00
|
|
|
LinearLayout *bottom = outer->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, WRAP_CONTENT)));
|
2020-03-08 22:51:23 +00:00
|
|
|
#if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI) || defined(SDL)
|
2021-02-22 00:38:02 +00:00
|
|
|
chatEdit_ = bottom->Add(new TextEdit("", n->T("Chat message"), n->T("Chat Here"), new LinearLayoutParams(1.0)));
|
2016-10-21 10:35:54 +00:00
|
|
|
chatEdit_->OnEnter.Handle(this, &ChatMenu::OnSubmit);
|
2020-03-11 03:44:30 +00:00
|
|
|
|
2020-03-08 13:32:32 +00:00
|
|
|
#elif PPSSPP_PLATFORM(ANDROID)
|
2016-10-23 17:49:12 +00:00
|
|
|
bottom->Add(new Button(n->T("Chat Here"),new LayoutParams(FILL_PARENT, WRAP_CONTENT)))->OnClick.Handle(this, &ChatMenu::OnSubmit);
|
2017-08-08 20:19:28 +00:00
|
|
|
bottom->Add(new Button(n->T("Send")))->OnClick.Handle(this, &ChatMenu::OnSubmit);
|
2016-10-23 17:49:12 +00:00
|
|
|
#endif
|
2017-07-06 13:43:39 +00:00
|
|
|
|
|
|
|
if (g_Config.bEnableQuickChat) {
|
|
|
|
LinearLayout *quickChat = outer->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, WRAP_CONTENT)));
|
2020-03-23 21:39:09 +00:00
|
|
|
quickChat->Add(new Button("1", new LinearLayoutParams(1.0)))->OnClick.Handle(this, &ChatMenu::OnQuickChat1);
|
|
|
|
quickChat->Add(new Button("2", new LinearLayoutParams(1.0)))->OnClick.Handle(this, &ChatMenu::OnQuickChat2);
|
|
|
|
quickChat->Add(new Button("3", new LinearLayoutParams(1.0)))->OnClick.Handle(this, &ChatMenu::OnQuickChat3);
|
|
|
|
quickChat->Add(new Button("4", new LinearLayoutParams(1.0)))->OnClick.Handle(this, &ChatMenu::OnQuickChat4);
|
|
|
|
quickChat->Add(new Button("5", new LinearLayoutParams(1.0)))->OnClick.Handle(this, &ChatMenu::OnQuickChat5);
|
2017-07-06 13:43:39 +00:00
|
|
|
}
|
2016-10-22 16:06:07 +00:00
|
|
|
chatVert_ = scroll_->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
|
|
|
|
chatVert_->SetSpacing(0);
|
2016-10-21 10:35:54 +00:00
|
|
|
parent->Add(outer);
|
|
|
|
}
|
|
|
|
|
2021-09-13 02:44:44 +00:00
|
|
|
void ChatMenu::CreateSubviews(const Bounds &screenBounds) {
|
2016-10-21 10:35:54 +00:00
|
|
|
using namespace UI;
|
|
|
|
|
2021-09-13 02:44:44 +00:00
|
|
|
float width = 550.0f;
|
2016-10-21 10:35:54 +00:00
|
|
|
|
2016-12-05 03:04:31 +00:00
|
|
|
switch (g_Config.iChatScreenPosition) {
|
2020-03-02 18:52:31 +00:00
|
|
|
// the chat screen size is still static 280x240 need a dynamic size based on device resolution
|
2016-12-05 03:04:31 +00:00
|
|
|
case 0:
|
2021-09-13 02:44:44 +00:00
|
|
|
box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(width, WRAP_CONTENT, 280, NONE, NONE, 240, true));
|
2016-12-05 03:04:31 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2021-09-13 02:44:44 +00:00
|
|
|
box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(width, WRAP_CONTENT, screenBounds.centerX(), NONE, NONE, 240, true));
|
2016-12-05 03:04:31 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2021-09-13 02:44:44 +00:00
|
|
|
box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(width, WRAP_CONTENT, NONE, NONE, 280, 240, true));
|
2016-12-05 03:04:31 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2021-09-13 02:44:44 +00:00
|
|
|
box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(width, WRAP_CONTENT, 280, 240, NONE, NONE, true));
|
2016-12-05 03:04:31 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2021-09-13 02:44:44 +00:00
|
|
|
box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(width, WRAP_CONTENT, screenBounds.centerX(), 240, NONE, NONE, true));
|
2016-12-05 03:04:31 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
2021-09-13 02:44:44 +00:00
|
|
|
box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(width, WRAP_CONTENT, NONE, 240, 280, NONE, true));
|
2016-12-05 03:04:31 +00:00
|
|
|
break;
|
2020-03-11 03:44:30 +00:00
|
|
|
default:
|
|
|
|
box_ = nullptr;
|
|
|
|
break;
|
2016-12-05 03:04:31 +00:00
|
|
|
}
|
2016-10-21 10:35:54 +00:00
|
|
|
|
2020-03-11 03:44:30 +00:00
|
|
|
if (box_) {
|
2021-09-13 02:44:44 +00:00
|
|
|
Add(box_);
|
2020-03-11 03:44:30 +00:00
|
|
|
box_->SetBG(UI::Drawable(0x99303030));
|
|
|
|
box_->SetHasDropShadow(false);
|
2016-10-21 10:35:54 +00:00
|
|
|
|
2023-12-20 09:35:02 +00:00
|
|
|
auto n = GetI18NCategory(I18NCat::NETWORKING);
|
2020-03-11 03:44:30 +00:00
|
|
|
View *title = new PopupHeader(n->T("Chat"));
|
|
|
|
box_->Add(title);
|
2016-10-21 10:35:54 +00:00
|
|
|
|
2021-09-13 02:44:44 +00:00
|
|
|
CreateContents(box_);
|
2020-03-11 03:44:30 +00:00
|
|
|
}
|
2017-07-08 10:08:33 +00:00
|
|
|
|
2017-06-07 18:18:45 +00:00
|
|
|
UpdateChat();
|
2016-10-21 10:35:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UI::EventReturn ChatMenu::OnSubmit(UI::EventParams &e) {
|
2023-06-21 22:47:00 +00:00
|
|
|
#if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI) || (defined(SDL) && !PPSSPP_PLATFORM(SWITCH))
|
2016-10-21 10:35:54 +00:00
|
|
|
std::string chat = chatEdit_->GetText();
|
|
|
|
chatEdit_->SetText("");
|
|
|
|
chatEdit_->SetFocus();
|
|
|
|
sendChat(chat);
|
2023-06-21 22:47:00 +00:00
|
|
|
#elif PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(SWITCH)
|
2023-04-05 22:34:50 +00:00
|
|
|
auto n = GetI18NCategory(I18NCat::NETWORKING);
|
2024-01-18 10:55:39 +00:00
|
|
|
System_InputBoxGetString(token_, n->T("Chat"), "", [](const std::string &value, int) {
|
2020-03-09 02:54:24 +00:00
|
|
|
sendChat(value);
|
|
|
|
});
|
2016-10-23 17:49:12 +00:00
|
|
|
#endif
|
2016-10-21 10:35:54 +00:00
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
2017-07-06 13:43:39 +00:00
|
|
|
UI::EventReturn ChatMenu::OnQuickChat1(UI::EventParams &e) {
|
|
|
|
sendChat(g_Config.sQuickChat0);
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UI::EventReturn ChatMenu::OnQuickChat2(UI::EventParams &e) {
|
|
|
|
sendChat(g_Config.sQuickChat1);
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UI::EventReturn ChatMenu::OnQuickChat3(UI::EventParams &e) {
|
|
|
|
sendChat(g_Config.sQuickChat2);
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UI::EventReturn ChatMenu::OnQuickChat4(UI::EventParams &e) {
|
|
|
|
sendChat(g_Config.sQuickChat3);
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UI::EventReturn ChatMenu::OnQuickChat5(UI::EventParams &e) {
|
|
|
|
sendChat(g_Config.sQuickChat4);
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
2016-10-21 10:35:54 +00:00
|
|
|
void ChatMenu::UpdateChat() {
|
|
|
|
using namespace UI;
|
2020-03-11 03:44:30 +00:00
|
|
|
if (chatVert_ != nullptr) {
|
2016-10-22 16:06:07 +00:00
|
|
|
chatVert_->Clear(); //read Access violation is proadhoc.cpp use NULL_->Clear() pointer?
|
2016-10-21 10:35:54 +00:00
|
|
|
std::vector<std::string> chatLog = getChatLog();
|
|
|
|
for (auto i : chatLog) {
|
2020-03-02 17:59:20 +00:00
|
|
|
uint32_t namecolor = 0x29B6F6;
|
2017-07-08 10:08:33 +00:00
|
|
|
uint32_t textcolor = 0xFFFFFF;
|
2020-03-02 17:59:20 +00:00
|
|
|
uint32_t infocolor = 0xFDD835;
|
2017-07-08 10:08:33 +00:00
|
|
|
|
2022-09-30 09:31:32 +00:00
|
|
|
std::string name = g_Config.sNickName;
|
2017-07-08 10:08:33 +00:00
|
|
|
std::string displayname = i.substr(0, i.find(':'));
|
|
|
|
|
|
|
|
if (name.substr(0, 8) == displayname) {
|
2020-03-02 17:59:20 +00:00
|
|
|
namecolor = 0xE53935;
|
2017-07-08 10:08:33 +00:00
|
|
|
}
|
|
|
|
|
2020-03-11 03:44:30 +00:00
|
|
|
if (i.length() <= displayname.length() || i[displayname.length()] != ':') {
|
2020-08-20 04:38:11 +00:00
|
|
|
TextView *v = chatVert_->Add(new TextView(i, ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LayoutParams(FILL_PARENT, WRAP_CONTENT)));
|
2017-07-08 10:08:33 +00:00
|
|
|
v->SetTextColor(0xFF000000 | infocolor);
|
2020-03-11 03:44:30 +00:00
|
|
|
} else {
|
2017-07-08 10:08:33 +00:00
|
|
|
LinearLayout *line = chatVert_->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, FILL_PARENT)));
|
2020-08-20 04:58:11 +00:00
|
|
|
line->SetSpacing(0.0f);
|
|
|
|
TextView *nameView = line->Add(new TextView(displayname, ALIGN_LEFT, true, new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT, 0.0f)));
|
2017-07-08 10:08:33 +00:00
|
|
|
nameView->SetTextColor(0xFF000000 | namecolor);
|
2020-08-20 04:35:31 +00:00
|
|
|
|
2023-12-20 09:35:02 +00:00
|
|
|
std::string chattext = i.substr(displayname.length());
|
2020-08-20 04:58:11 +00:00
|
|
|
TextView *chatView = line->Add(new TextView(chattext, ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, 1.0f)));
|
|
|
|
chatView->SetTextColor(0xFF000000 | textcolor);
|
2016-10-21 10:35:54 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-26 21:21:07 +00:00
|
|
|
toBottom_ = true;
|
2016-10-21 10:35:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-13 02:44:44 +00:00
|
|
|
void ChatMenu::Update() {
|
|
|
|
AnchorLayout::Update();
|
2017-07-08 10:08:33 +00:00
|
|
|
if (scroll_ && toBottom_) {
|
|
|
|
toBottom_ = false;
|
|
|
|
scroll_->ScrollToBottom();
|
|
|
|
}
|
|
|
|
|
2021-09-15 00:51:57 +00:00
|
|
|
if (chatChangeID_ != GetChatChangeID()) {
|
|
|
|
chatChangeID_ = GetChatChangeID();
|
2016-10-31 14:22:57 +00:00
|
|
|
UpdateChat();
|
2016-10-22 16:06:07 +00:00
|
|
|
}
|
2021-09-13 03:16:05 +00:00
|
|
|
|
|
|
|
#if defined(USING_WIN_UI)
|
|
|
|
// Could remove the fullscreen check here, it works now.
|
2023-12-20 09:35:02 +00:00
|
|
|
auto n = GetI18NCategory(I18NCat::NETWORKING);
|
2022-05-28 22:47:12 +00:00
|
|
|
if (promptInput_ && g_Config.bBypassOSKWithKeyboard && !g_Config.UseFullScreen()) {
|
2024-01-18 10:55:39 +00:00
|
|
|
System_InputBoxGetString(token_, n->T("Chat"), n->T("Chat Here"), [](const std::string &value, int) {
|
2023-03-22 11:26:14 +00:00
|
|
|
sendChat(value);
|
2021-09-13 03:16:05 +00:00
|
|
|
});
|
|
|
|
promptInput_ = false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ChatMenu::SubviewFocused(UI::View *view) {
|
|
|
|
if (!AnchorLayout::SubviewFocused(view))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
promptInput_ = true;
|
|
|
|
return true;
|
2016-10-22 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 03:20:17 +00:00
|
|
|
void ChatMenu::Close() {
|
|
|
|
SetVisibility(UI::V_GONE);
|
2016-10-22 18:44:28 +00:00
|
|
|
}
|