From 9403947b6791903b314fe428dabc082f1cd4b5bd Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 14 Sep 2021 17:59:46 -0700 Subject: [PATCH] UI: Decouple new chat display and tracking logic. --- Core/HLE/proAdhoc.cpp | 13 ++++++------- Core/HLE/proAdhoc.h | 4 +--- UI/ChatScreen.cpp | 4 ---- UI/EmuScreen.cpp | 14 +++++++++++++- UI/EmuScreen.h | 4 ++++ 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/Core/HLE/proAdhoc.cpp b/Core/HLE/proAdhoc.cpp index 270d9ee322..bf88907b87 100644 --- a/Core/HLE/proAdhoc.cpp +++ b/Core/HLE/proAdhoc.cpp @@ -115,8 +115,6 @@ std::vector chatLog; std::string name = ""; std::string incoming = ""; std::string message = ""; -bool chatScreenVisible = false; -int newChat = 0; bool isOriPort = false; bool isLocalServer = false; SockAddrIN4 g_adhocServerIP; @@ -125,6 +123,7 @@ sockaddr LocalIP; int defaultWlanChannel = PSP_SYSTEMPARAM_ADHOC_CHANNEL_11; // Don't put 0(Auto) here, it needed to be a valid/actual channel number static int chatMessageGeneration = 0; +static int chatMessageCount = 0; bool isMacMatch(const SceNetEtherAddr* addr1, const SceNetEtherAddr* addr2) { // Ignoring the 1st byte since there are games (ie. Gran Turismo) who tamper with the 1st byte of OUI to change the unicast/multicast bit @@ -1325,6 +1324,10 @@ int GetChatChangeID() { return chatMessageGeneration; } +int GetChatMessageCount() { + return chatMessageCount; +} + int friendFinder(){ SetCurrentThreadName("FriendFinder"); auto n = GetI18NCategory("Networking"); @@ -1522,11 +1525,7 @@ int friendFinder(){ incoming.append((char*)packet->base.message); chatLog.push_back(incoming); chatMessageGeneration++; - if (!chatScreenVisible) { - if (newChat < 50) { - newChat += 1; - } - } + chatMessageCount++; // Move RX Buffer memmove(rx, rx + sizeof(SceNetAdhocctlChatPacketS2C), sizeof(rx) - sizeof(SceNetAdhocctlChatPacketS2C)); diff --git a/Core/HLE/proAdhoc.h b/Core/HLE/proAdhoc.h index 0a261ff245..a1343d25dd 100644 --- a/Core/HLE/proAdhoc.h +++ b/Core/HLE/proAdhoc.h @@ -1016,9 +1016,7 @@ void addFriend(SceNetAdhocctlConnectPacketS2C * packet); void sendChat(std::string chatString); std::vector getChatLog(); int GetChatChangeID(); - -extern bool chatScreenVisible; -extern int newChat; +int GetChatMessageCount(); /* * Find a Peer/Friend by MAC address diff --git a/UI/ChatScreen.cpp b/UI/ChatScreen.cpp index 39907c031d..41eef866ae 100644 --- a/UI/ChatScreen.cpp +++ b/UI/ChatScreen.cpp @@ -177,9 +177,6 @@ void ChatMenu::Update() { UpdateChat(); } - 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) { @@ -203,5 +200,4 @@ bool ChatMenu::SubviewFocused(UI::View *view) { void ChatMenu::Close() { SetVisibility(UI::V_GONE); - chatScreenVisible = false; } diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 1b499a4708..f85f65243a 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -862,7 +862,7 @@ void EmuScreen::CreateViews() { break; } - ChoiceWithValueDisplay *btn = new ChoiceWithValueDisplay(&newChat, n->T("Chat"), layoutParams); + ChoiceWithValueDisplay *btn = new ChoiceWithValueDisplay(&newChatMessages_, 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))); @@ -987,6 +987,18 @@ void EmuScreen::update() { resumeButton_->SetVisibility(coreState == CoreState::CORE_RUNTIME_ERROR && Memory::MemFault_MayBeResumable() ? V_VISIBLE : V_GONE); resetButton_->SetVisibility(coreState == CoreState::CORE_RUNTIME_ERROR ? V_VISIBLE : V_GONE); + if (chatButton_ && chatMenu_) { + if (chatMenu_->GetVisibility() != V_GONE) { + chatMessages_ = GetChatMessageCount(); + newChatMessages_ = 0; + } else { + int diff = GetChatMessageCount() - chatMessages_; + chatMessages_ += diff; + // Cap the count at 50. + newChatMessages_ = diff > 50 ? 50 : diff; + } + } + if (bootPending_) { bootGame(gamePath_); } diff --git a/UI/EmuScreen.h b/UI/EmuScreen.h index 79f47982d6..ff41bd81a4 100644 --- a/UI/EmuScreen.h +++ b/UI/EmuScreen.h @@ -86,6 +86,10 @@ private: // If set, pauses at the end of the frame. bool pauseTrigger_ = false; + // The last read chat message count, and how many new ones there are. + int chatMessages_ = 0; + int newChatMessages_ = 0; + // In-memory save state used for freezeFrame, which is useful for debugging. std::vector freezeState_;