CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/UI/ChatScreen.cpp
Views: 1401
#include <ctype.h>1#include "ppsspp_config.h"23#include "Common/UI/Root.h"4#include "Common/UI/Context.h"5#include "Common/UI/View.h"6#include "Common/UI/ViewGroup.h"7#include "Common/UI/ScrollView.h"8#include "Common/UI/UI.h"910#include "Common/Data/Text/I18n.h"11#include "Common/Data/Encoding/Utf8.h"12#include "Common/System/Request.h"13#include "Core/Config.h"14#include "Core/System.h"15#include "Core/HLE/proAdhoc.h"16#include "UI/ChatScreen.h"17#include "UI/PopupScreens.h"1819void ChatMenu::CreateContents(UI::ViewGroup *parent) {20using namespace UI;21auto n = GetI18NCategory(I18NCat::NETWORKING);22LinearLayout *outer = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT,400));23scroll_ = outer->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0)));24LinearLayout *bottom = outer->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, WRAP_CONTENT)));2526chatButton_ = nullptr;27chatEdit_ = nullptr;28chatVert_ = nullptr;2930if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_DESKTOP) {31// We have direct keyboard input.32chatEdit_ = bottom->Add(new TextEdit("", n->T("Chat message"), n->T("Chat Here"), new LinearLayoutParams(1.0)));33chatEdit_->OnEnter.Handle(this, &ChatMenu::OnSubmitMessage);34} else {35// If we have a native input box, like on Android, or at least we can do a popup text input with our UI...36chatButton_ = bottom->Add(new Button(n->T("Chat message"), new LayoutParams(FILL_PARENT, WRAP_CONTENT)));37chatButton_->OnClick.Handle(this, &ChatMenu::OnAskForChatMessage);38}3940if (g_Config.bEnableQuickChat) {41LinearLayout *quickChat = outer->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, WRAP_CONTENT)));42quickChat->Add(new Button("1", new LinearLayoutParams(1.0)))->OnClick.Handle(this, &ChatMenu::OnQuickChat1);43quickChat->Add(new Button("2", new LinearLayoutParams(1.0)))->OnClick.Handle(this, &ChatMenu::OnQuickChat2);44quickChat->Add(new Button("3", new LinearLayoutParams(1.0)))->OnClick.Handle(this, &ChatMenu::OnQuickChat3);45quickChat->Add(new Button("4", new LinearLayoutParams(1.0)))->OnClick.Handle(this, &ChatMenu::OnQuickChat4);46quickChat->Add(new Button("5", new LinearLayoutParams(1.0)))->OnClick.Handle(this, &ChatMenu::OnQuickChat5);47}48chatVert_ = scroll_->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));49chatVert_->SetSpacing(0);50parent->Add(outer);51}5253void ChatMenu::CreateSubviews(const Bounds &screenBounds) {54using namespace UI;5556float width = 550.0f;5758switch (g_Config.iChatScreenPosition) {59// the chat screen size is still static 280x240 need a dynamic size based on device resolution60case 0:61box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(width, WRAP_CONTENT, 280, NONE, NONE, 240, true));62break;63case 1:64box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(width, WRAP_CONTENT, screenBounds.centerX(), NONE, NONE, 240, true));65break;66case 2:67box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(width, WRAP_CONTENT, NONE, NONE, 280, 240, true));68break;69case 3:70box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(width, WRAP_CONTENT, 280, 240, NONE, NONE, true));71break;72case 4:73box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(width, WRAP_CONTENT, screenBounds.centerX(), 240, NONE, NONE, true));74break;75case 5:76box_ = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(width, WRAP_CONTENT, NONE, 240, 280, NONE, true));77break;78default:79box_ = nullptr;80break;81}8283if (box_) {84Add(box_);85box_->SetBG(UI::Drawable(0x99303030));86box_->SetHasDropShadow(false);8788auto n = GetI18NCategory(I18NCat::NETWORKING);89View *title = new PopupHeader(n->T("Chat"));90box_->Add(title);9192CreateContents(box_);93}9495UpdateChat();96}9798UI::EventReturn ChatMenu::OnSubmitMessage(UI::EventParams &e) {99std::string chat = chatEdit_->GetText();100chatEdit_->SetText("");101chatEdit_->SetFocus();102sendChat(chat);103return UI::EVENT_DONE;104}105106UI::EventReturn ChatMenu::OnAskForChatMessage(UI::EventParams &e) {107auto n = GetI18NCategory(I18NCat::NETWORKING);108109using namespace UI;110111if (System_GetPropertyBool(SYSPROP_HAS_TEXT_INPUT_DIALOG)) {112System_InputBoxGetString(token_, n->T("Chat"), "", false, [](const std::string &value, int) {113sendChat(value);114});115} else {116// We need to pop up a UI inputbox.117messageTemp_.clear();118TextEditPopupScreen *popupScreen = new TextEditPopupScreen(&messageTemp_, "", n->T("Chat message"), 256);119if (System_GetPropertyBool(SYSPROP_KEYBOARD_IS_SOFT)) {120popupScreen->SetAlignTop(true);121}122popupScreen->OnChange.Add([=](UI::EventParams &e) {123sendChat(messageTemp_);124return UI::EVENT_DONE;125});126popupScreen->SetPopupOrigin(chatButton_);127screenManager_->push(popupScreen);128}129return UI::EVENT_DONE;130}131132UI::EventReturn ChatMenu::OnQuickChat1(UI::EventParams &e) {133sendChat(g_Config.sQuickChat0);134return UI::EVENT_DONE;135}136137UI::EventReturn ChatMenu::OnQuickChat2(UI::EventParams &e) {138sendChat(g_Config.sQuickChat1);139return UI::EVENT_DONE;140}141142UI::EventReturn ChatMenu::OnQuickChat3(UI::EventParams &e) {143sendChat(g_Config.sQuickChat2);144return UI::EVENT_DONE;145}146147UI::EventReturn ChatMenu::OnQuickChat4(UI::EventParams &e) {148sendChat(g_Config.sQuickChat3);149return UI::EVENT_DONE;150}151152UI::EventReturn ChatMenu::OnQuickChat5(UI::EventParams &e) {153sendChat(g_Config.sQuickChat4);154return UI::EVENT_DONE;155}156157void ChatMenu::UpdateChat() {158using namespace UI;159if (chatVert_ != nullptr) {160chatVert_->Clear(); //read Access violation is proadhoc.cpp use NULL_->Clear() pointer?161std::vector<std::string> chatLog = getChatLog();162for (auto i : chatLog) {163uint32_t namecolor = 0x29B6F6;164uint32_t textcolor = 0xFFFFFF;165uint32_t infocolor = 0xFDD835;166167std::string name = g_Config.sNickName;168std::string displayname = i.substr(0, i.find(':'));169170if (name.substr(0, 8) == displayname) {171namecolor = 0xE53935;172}173174if (i.length() <= displayname.length() || i[displayname.length()] != ':') {175TextView *v = chatVert_->Add(new TextView(i, ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LayoutParams(FILL_PARENT, WRAP_CONTENT)));176v->SetTextColor(0xFF000000 | infocolor);177} else {178LinearLayout *line = chatVert_->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, FILL_PARENT)));179line->SetSpacing(0.0f);180TextView *nameView = line->Add(new TextView(displayname, ALIGN_LEFT, true, new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT, 0.0f)));181nameView->SetTextColor(0xFF000000 | namecolor);182183std::string chattext = i.substr(displayname.length());184TextView *chatView = line->Add(new TextView(chattext, ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, 1.0f)));185chatView->SetTextColor(0xFF000000 | textcolor);186}187}188toBottom_ = true;189}190}191192void ChatMenu::Update() {193AnchorLayout::Update();194if (scroll_ && toBottom_) {195toBottom_ = false;196scroll_->ScrollToBottom();197}198199if (chatChangeID_ != GetChatChangeID()) {200chatChangeID_ = GetChatChangeID();201UpdateChat();202}203204#if defined(USING_WIN_UI)205// Could remove the fullscreen check here, it works now.206auto n = GetI18NCategory(I18NCat::NETWORKING);207if (promptInput_ && g_Config.bBypassOSKWithKeyboard && !g_Config.UseFullScreen()) {208System_InputBoxGetString(token_, n->T("Chat"), n->T("Chat Here"), false, [](const std::string &value, int) {209sendChat(value);210});211promptInput_ = false;212}213#endif214}215216bool ChatMenu::SubviewFocused(UI::View *view) {217if (!AnchorLayout::SubviewFocused(view))218return false;219220promptInput_ = true;221return true;222}223224void ChatMenu::Close() {225SetVisibility(UI::V_GONE);226}227228229