From 4420719a860d97d17eed4e7c869d3bf1e0a42979 Mon Sep 17 00:00:00 2001 From: Gde Made Novan Priambhada Date: Sat, 8 Jul 2017 18:08:33 +0800 Subject: [PATCH] Bug fix --- Core/Config.cpp | 1 + UI/ChatScreen.cpp | 80 ++++++++++++++++++++++++--------------- UI/ChatScreen.h | 4 +- UI/EmuScreen.cpp | 15 +++++--- UI/EmuScreen.h | 2 +- UI/GameSettingsScreen.cpp | 20 +++++----- android/ab.cmd | 2 +- 7 files changed, 74 insertions(+), 50 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index a3f8d99a04..49ba96f07e 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -711,6 +711,7 @@ static ConfigSetting networkSettings[] = { ConfigSetting("EnableNetworkChat", &g_Config.bEnableNetworkChat, false, true, true), ConfigSetting("ChatButtonPosition",&g_Config.iChatButtonPosition,BOTTOM_LEFT,true,true), ConfigSetting("ChatScreenPosition",&g_Config.iChatScreenPosition,BOTTOM_LEFT,true,true), + ConfigSetting("EnableQuickChat", &g_Config.bEnableQuickChat, true, true, true), ConfigSetting("QuickChat1", &g_Config.sQuickChat0, "Quick Chat 1", true, true), ConfigSetting("QuickChat2", &g_Config.sQuickChat1, "Quick Chat 2", true, true), ConfigSetting("QuickChat3", &g_Config.sQuickChat2, "Quick Chat 3", true, true), diff --git a/UI/ChatScreen.cpp b/UI/ChatScreen.cpp index 29d5b647b6..817aff9d70 100644 --- a/UI/ChatScreen.cpp +++ b/UI/ChatScreen.cpp @@ -88,7 +88,7 @@ void ChatMenu::CreateViews() { } root_->Add(box_); - box_->SetBG(UI::Drawable(0x66303030)); + box_->SetBG(UI::Drawable(0x99303030)); box_->SetHasDropShadow(false); View *title = new PopupHeader(n->T("Chat")); @@ -96,15 +96,18 @@ void ChatMenu::CreateViews() { CreatePopupContents(box_); #if defined(_WIN32) || defined(USING_QT_UI) + UI::EnableFocusMovement(true); root_->SetDefaultFocusView(box_); box_->SubviewFocused(chatEdit_); root_->SetFocus(); #else - root_->SetDefaultFocusView(box_); + //root_->SetDefaultFocusView(box_); + //box_->SubviewFocused(scroll_); + //root_->SetFocus(); #endif chatScreenVisible = true; newChat = 0; - UI::EnableFocusMovement(true); + UpdateChat(); } @@ -162,28 +165,25 @@ std::vector Split(const std::string& str) int counter = 0; int firstSentenceEnd = 0; int secondSentenceEnd = 0; + int spliton = 45; + for (auto i = 0; i 35) { - secondSentenceEnd = i; + else if (i > spliton) { + firstSentenceEnd = spliton; } } } if (firstSentenceEnd == 0) { - firstSentenceEnd = 35; + firstSentenceEnd = spliton; } - - if(secondSentenceEnd == 0){ - secondSentenceEnd = str.length(); - } - ret.push_back(str.substr(0, firstSentenceEnd)); - ret.push_back(str.substr(firstSentenceEnd, secondSentenceEnd)); + ret.push_back(str.substr(firstSentenceEnd)); return ret; } @@ -194,22 +194,42 @@ void ChatMenu::UpdateChat() { std::vector chatLog = getChatLog(); for (auto i : chatLog) { //split long text - if (i.length() > 30) { - std::vector splitted = Split(i); - for (auto j : splitted) { - TextView *v = chatVert_->Add(new TextView(j, FLAG_DYNAMIC_ASCII, false)); - uint32_t color = 0xFFFFFF; - v->SetTextColor(0xFF000000 | color); - } + uint32_t namecolor = 0xF6B629; + uint32_t textcolor = 0xFFFFFF; + uint32_t infocolor = 0x35D8FD; + + std::string name = g_Config.sNickName.c_str(); + std::string displayname = i.substr(0, i.find(':')); + std::string chattext = i.substr(displayname.length()); + + if (name.substr(0, 8) == displayname) { + namecolor = 0x3539E5; + } + + if (i[displayname.length()] != ':') { + TextView *v = chatVert_->Add(new TextView(i, FLAG_DYNAMIC_ASCII, true)); + v->SetTextColor(0xFF000000 | infocolor); } else { - TextView *v = chatVert_->Add(new TextView(i, FLAG_DYNAMIC_ASCII, false)); - uint32_t color = 0xFFFFFF; - v->SetTextColor(0xFF000000 | color); + LinearLayout *line = chatVert_->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, FILL_PARENT))); + TextView *nameView = line->Add(new TextView(displayname, FLAG_DYNAMIC_ASCII, true)); + nameView->SetTextColor(0xFF000000 | namecolor); + if (chattext.length() > 45) { + std::vector splitted = Split(chattext); + std::string one = splitted[0]; + std::string two = splitted[1]; + TextView *oneview = line->Add(new TextView(one, FLAG_DYNAMIC_ASCII, true)); + oneview->SetTextColor(0xFF000000 | textcolor); + TextView *twoview = chatVert_->Add(new TextView(two, FLAG_DYNAMIC_ASCII, true)); + twoview->SetTextColor(0xFF000000 | textcolor); + } + else { + TextView *chatView = line->Add(new TextView(chattext, FLAG_DYNAMIC_ASCII, true)); + chatView->SetTextColor(0xFF000000 | textcolor); + } } } toBottom_ = true; - updateChatScreen = false; } } @@ -227,14 +247,14 @@ bool ChatMenu::touch(const TouchInput &touch) { void ChatMenu::update() { PopupScreen::update(); + if (scroll_ && toBottom_) { + toBottom_ = false; + scroll_->ScrollToBottom(); + } + if (updateChatScreen) { UpdateChat(); - } - else { - if (scroll_ && toBottom_) { - toBottom_ = false; - scroll_->ScrollToBottom(); - } + updateChatScreen = false; } } diff --git a/UI/ChatScreen.h b/UI/ChatScreen.h index c99297a524..ecb6d1546e 100644 --- a/UI/ChatScreen.h +++ b/UI/ChatScreen.h @@ -4,7 +4,7 @@ class ChatMenu : public PopupScreen { public: - ChatMenu() : PopupScreen("Chat") , toBottom_(false) {} + ChatMenu() : PopupScreen("Chat") , toBottom_(true) {} ~ChatMenu(); void CreatePopupContents(UI::ViewGroup *parent) override; void CreateViews() override; @@ -12,6 +12,7 @@ public: bool touch(const TouchInput &touch) override; void update() override; void UpdateChat(); + bool toBottom_; private: UI::EventReturn OnSubmit(UI::EventParams &e); UI::EventReturn OnQuickChat1(UI::EventParams &e); @@ -23,5 +24,4 @@ private: UI::ScrollView *scroll_; UI::LinearLayout *chatVert_; UI::ViewGroup *box_; - bool toBottom_; }; \ No newline at end of file diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index bbc804b5e3..34f5089bfd 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -129,6 +129,7 @@ EmuScreen::EmuScreen(const std::string &filename) startDumping = false; OnDevMenu.Handle(this, &EmuScreen::OnDevTools); + OnChatMenu.Handle(this, &EmuScreen::OnChat); } void EmuScreen::bootGame(const std::string &filename) { @@ -381,14 +382,16 @@ void EmuScreen::sendMessage(const char *message, const char *value) { osm.Show("Disable windows native keyboard options to use ctrl + c hotkey", 2.0f); } else { if (g_Config.bEnableNetworkChat) { - chatButtons->SetVisibility(UI::V_GONE); - screenManager()->push(new ChatMenu()); + releaseButtons(); + UI::EventParams e{}; + OnChatMenu.Trigger(e); } } #else if (g_Config.bEnableNetworkChat) { - chatButtons->SetVisibility(UI::V_GONE); - screenManager()->push(new ChatMenu()); + releaseButtons(); + UI::EventParams e{}; + OnChatMenu.Trigger(e); } #endif } @@ -465,8 +468,8 @@ void EmuScreen::onVKeyDown(int virtualKeyCode) { case VIRTKEY_OPENCHAT: if (g_Config.bEnableNetworkChat) { releaseButtons(); - chatButtons->SetVisibility(UI::V_GONE); - screenManager()->push(new ChatMenu()); + UI::EventParams e{}; + OnChatMenu.Trigger(e); } break; diff --git a/UI/EmuScreen.h b/UI/EmuScreen.h index 2057f6835b..4fe120c96c 100644 --- a/UI/EmuScreen.h +++ b/UI/EmuScreen.h @@ -71,7 +71,7 @@ private: void checkPowerDown(); UI::Event OnDevMenu; - + UI::Event OnChatMenu; bool bootPending_; std::string gamePath_; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 9b7e5cb6ce..deb06ec15e 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -655,19 +655,19 @@ void GameSettingsScreen::CreateViews() { qc5->SetEnabledPtr(&g_Config.bEnableQuickChat); qc5->OnClick.Handle(this, &GameSettingsScreen::OnChangeQuickChat4); #elif defined(__ANDROID__) - ChoiceWithValueDisplay *qc1 = networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.sNickName, sy->T("Quick Chat 1"), nullptr)); + ChoiceWithValueDisplay *qc1 = networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.sQuickChat0, sy->T("Quick Chat 1"), nullptr)); qc1->OnClick.Handle(this, &GameSettingsScreen::OnChangeQuickChat0); qc1->SetEnabledPtr(&g_Config.bEnableQuickChat); - ChoiceWithValueDisplay *qc2 = networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.sNickName, sy->T("Quick Chat 2"), nullptr)); + ChoiceWithValueDisplay *qc2 = networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.sQuickChat1, sy->T("Quick Chat 2"), nullptr)); qc2->OnClick.Handle(this, &GameSettingsScreen::OnChangeQuickChat1); qc2->SetEnabledPtr(&g_Config.bEnableQuickChat); - ChoiceWithValueDisplay *qc3 = networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.sNickName, sy->T("Quick Chat 3"), nullptr)); + ChoiceWithValueDisplay *qc3 = networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.sQuickChat2, sy->T("Quick Chat 3"), nullptr)); qc3->OnClick.Handle(this, &GameSettingsScreen::OnChangeQuickChat2); qc3->SetEnabledPtr(&g_Config.bEnableQuickChat); - ChoiceWithValueDisplay *qc4 = networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.sNickName, sy->T("Quick Chat 4"), nullptr)); + ChoiceWithValueDisplay *qc4 = networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.sQuickChat3, sy->T("Quick Chat 4"), nullptr)); qc4->OnClick.Handle(this, &GameSettingsScreen::OnChangeQuickChat3); qc4->SetEnabledPtr(&g_Config.bEnableQuickChat); - ChoiceWithValueDisplay *qc5 = networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.sNickName, sy->T("Quick Chat 5"), nullptr)); + ChoiceWithValueDisplay *qc5 = networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.sQuickChat4, sy->T("Quick Chat 5"), nullptr)); qc5->OnClick.Handle(this, &GameSettingsScreen::OnChangeQuickChat4); qc5->SetEnabledPtr(&g_Config.bEnableQuickChat); #endif @@ -1154,7 +1154,7 @@ UI::EventReturn GameSettingsScreen::OnChangeQuickChat0(UI::EventParams &e) { g_Config.sQuickChat0 = chat; } #elif defined(__ANDROID__) - System_SendMessage("inputbox", ("quickchat0:" + g_Config.).c_str()); + System_SendMessage("inputbox", ("quickchat0:" + g_Config.sQuickChat0).c_str()); #endif return UI::EVENT_DONE; } @@ -1170,7 +1170,7 @@ UI::EventReturn GameSettingsScreen::OnChangeQuickChat1(UI::EventParams &e) { g_Config.sQuickChat1 = chat; } #elif defined(__ANDROID__) - System_SendMessage("inputbox", ("quickchat1:" + g_Config.).c_str()); + System_SendMessage("inputbox", ("quickchat1:" + g_Config.sQuickChat1).c_str()); #endif return UI::EVENT_DONE; } @@ -1186,7 +1186,7 @@ UI::EventReturn GameSettingsScreen::OnChangeQuickChat2(UI::EventParams &e) { g_Config.sQuickChat2 = chat; } #elif defined(__ANDROID__) - System_SendMessage("inputbox", ("quickchat2:" + g_Config.).c_str()); + System_SendMessage("inputbox", ("quickchat2:" + g_Config.sQuickChat2).c_str()); #endif return UI::EVENT_DONE; } @@ -1202,7 +1202,7 @@ UI::EventReturn GameSettingsScreen::OnChangeQuickChat3(UI::EventParams &e) { g_Config.sQuickChat3 = chat; } #elif defined(__ANDROID__) - System_SendMessage("inputbox", ("quickchat3:" + g_Config.).c_str()); + System_SendMessage("inputbox", ("quickchat3:" + g_Config.sQuickChat3).c_str()); #endif return UI::EVENT_DONE; } @@ -1218,7 +1218,7 @@ UI::EventReturn GameSettingsScreen::OnChangeQuickChat4(UI::EventParams &e) { g_Config.sQuickChat4 = chat; } #elif defined(__ANDROID__) - System_SendMessage("inputbox", ("quickchat4:" + g_Config.).c_str()); + System_SendMessage("inputbox", ("quickchat4:" + g_Config.sQuickChat4).c_str()); #endif return UI::EVENT_DONE; } diff --git a/android/ab.cmd b/android/ab.cmd index 6befeb03b3..c2506530a9 100644 --- a/android/ab.cmd +++ b/android/ab.cmd @@ -5,6 +5,6 @@ copy ..\assets\langregion.ini assets\langregion.ini copy ..\assets\compat.ini assets\compat.ini copy ..\assets\Roboto-Condensed.ttf assets\Roboto-Condensed.ttf copy ..\assets\*.png assets\ -SET NDK=C:\AndroidNDK +SET NDK=D:\Android\NDK SET NDK_MODULE_PATH=..\ext;..\ext\native\ext %NDK%/ndk-build -j9 %*