UI: Decouple new chat display and tracking logic.

This commit is contained in:
Unknown W. Brackets 2021-09-14 17:59:46 -07:00
parent be0b0cd88d
commit 9403947b67
5 changed files with 24 additions and 15 deletions

View File

@ -115,8 +115,6 @@ std::vector<std::string> 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));

View File

@ -1016,9 +1016,7 @@ void addFriend(SceNetAdhocctlConnectPacketS2C * packet);
void sendChat(std::string chatString);
std::vector<std::string> getChatLog();
int GetChatChangeID();
extern bool chatScreenVisible;
extern int newChat;
int GetChatMessageCount();
/*
* Find a Peer/Friend by MAC address

View File

@ -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;
}

View File

@ -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_);
}

View File

@ -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<u8> freezeState_;