diff --git a/Core/Config.h b/Core/Config.h index bc65c531cb..381a1b954b 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -425,7 +425,6 @@ public: int iWlanAdhocChannel; bool bWlanPowerSave; bool bEnableNetworkChat; - int iNewChat; int iPSPModel; int iFirmwareVersion; diff --git a/Core/HLE/proAdhoc.cpp b/Core/HLE/proAdhoc.cpp index f82351128a..fdd31c39b0 100644 --- a/Core/HLE/proAdhoc.cpp +++ b/Core/HLE/proAdhoc.cpp @@ -56,10 +56,12 @@ SceNetAdhocPdpStat * pdp[255]; SceNetAdhocPtpStat * ptp[255]; uint32_t localip; std::vector chatLog; -ChatMenu * ch; std::string name = ""; std::string incoming = ""; std::string message = ""; +bool chatScreenVisible = false; +bool updateChatScreen = false; +int newChat = 0; int isLocalMAC(const SceNetEtherAddr * addr) { SceNetEtherAddr saddr; @@ -986,14 +988,6 @@ void freeFriendsRecursive(SceNetAdhocctlPeerInfo * node) { free(node); } -//@params chatmenu pass NULL on destroy, and pass ChatMenu On Create (EmuScreen.cpp) -void setChatPointer(ChatMenu * chatmenu) { - if (chatmenu != NULL) { - delete ch; - } - ch = chatmenu; //setChatPointer -} - void sendChat(std::string chatString) { SceNetAdhocctlChatPacketC2S chat; I18NCategory *n = GetI18NCategory("Networking"); @@ -1011,20 +1005,19 @@ void sendChat(std::string chatString) { NOTICE_LOG(SCENET, "Send Chat %s to Adhoc Server", chat.message); name = g_Config.sNickName.c_str(); chatLog.push_back(name.substr(0, 8) + ": " + chat.message); - if (ch) { - ch->UpdateChat(); + if (chatScreenVisible) { + updateChatScreen = true; } } } else { chatLog.push_back(n->T("You're in Offline Mode, go to lobby or online hall")); - if (ch) { - ch->UpdateChat(); + if (chatScreenVisible) { + updateChatScreen = true; } } } - std::vector getChatLog() { // this log used by chat screen if (chatLog.size() > 50) { @@ -1133,12 +1126,12 @@ int friendFinder(){ incoming.append((char *)packet->base.message); chatLog.push_back(incoming); //im new to pointer btw :( doesn't know its safe or not this should update the chat screen when data coming - if (ch) { - ch->UpdateChat(); + if (chatScreenVisible) { + updateChatScreen = true; } else { - if (g_Config.iNewChat < 50) { - g_Config.iNewChat += 1; + if (newChat < 50) { + newChat += 1; } } // Move RX Buffer @@ -1169,8 +1162,8 @@ int friendFinder(){ //joined.append((char *)packet->ip); chatLog.push_back(incoming); //im new to pointer btw :( doesn't know its safe or not this should update the chat screen when data coming - if (ch) { - ch->UpdateChat(); + if (chatScreenVisible) { + updateChatScreen = true; } // Update HUD User Count #ifdef LOCALHOST_AS_PEER diff --git a/Core/HLE/proAdhoc.h b/Core/HLE/proAdhoc.h index 5247f56b76..6d83e793b2 100644 --- a/Core/HLE/proAdhoc.h +++ b/Core/HLE/proAdhoc.h @@ -33,7 +33,6 @@ #include "Core/HLE/sceKernel.h" #include "Core/HLE/sceKernelMutex.h" #include "Core/HLE/sceUtility.h" -#include "UI/ChatScreen.h" class PointerWrap; @@ -847,9 +846,11 @@ void addFriend(SceNetAdhocctlConnectPacketS2C * packet); * Send chat or get that * @param std::string ChatString */ -void setChatPointer(ChatMenu * chatmenu); void sendChat(std::string chatString); std::vector getChatLog(); +extern bool chatScreenVisible; +extern bool updateChatScreen; +extern int newChat; /* * Find a Peer/Friend by MAC address diff --git a/UI/ChatScreen.cpp b/UI/ChatScreen.cpp index 11c283e64d..1bbf7ceed5 100644 --- a/UI/ChatScreen.cpp +++ b/UI/ChatScreen.cpp @@ -69,7 +69,8 @@ void ChatMenu::CreateViews() { CreatePopupContents(box_); root_->SetDefaultFocusView(box_); UpdateChat(); - g_Config.iNewChat = 0; + chatScreenVisible = true; + newChat = 0; } void ChatMenu::dialogFinished(const Screen *dialog, DialogResult result) { @@ -142,6 +143,7 @@ void ChatMenu::UpdateChat() { } } toBottom_ = true; + updateChatScreen = false; } } @@ -157,6 +159,13 @@ bool ChatMenu::touch(const TouchInput &touch) { return UIDialogScreen::touch(touch); } +void ChatMenu::update(InputState &input) { + PopupScreen::update(input); + if (updateChatScreen) { + UpdateChat(); + } +} + void ChatMenu::postRender() { if (scroll_ && toBottom_) { scroll_->ScrollToBottom(); @@ -165,7 +174,5 @@ void ChatMenu::postRender() { } ChatMenu::~ChatMenu() { - setChatPointer(NULL); - scroll_ = NULL; - chatVert_ = NULL; + chatScreenVisible = false; } diff --git a/UI/ChatScreen.h b/UI/ChatScreen.h index c377f1fdcd..701643aabb 100644 --- a/UI/ChatScreen.h +++ b/UI/ChatScreen.h @@ -10,8 +10,9 @@ public: void CreateViews() override; void dialogFinished(const Screen *dialog, DialogResult result) override; bool touch(const TouchInput &touch) override; + void update(InputState &input) override; void postRender() override; - virtual void UpdateChat(); + void UpdateChat(); private: UI::EventReturn OnSubmit(UI::EventParams &e); UI::TextEdit *chatEdit_; diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index f1f342a1c6..5ffec9aff0 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -373,9 +373,7 @@ void EmuScreen::sendMessage(const char *message, const char *value) { } } else if (!strcmp(message, "chat screen")) { releaseButtons(); - ChatMenu * ch = new ChatMenu(); - setChatPointer(ch); - screenManager()->push(ch); + screenManager()->push(new ChatMenu()); } } @@ -785,7 +783,7 @@ void EmuScreen::CreateViews() { } if (g_Config.bEnableNetworkChat) { //root_->Add(new Button(sc->T("Chat"), new AnchorLayoutParams(50, NONE, NONE, 50, true)))->OnClick.Handle(this, &EmuScreen::OnChat); - root_->Add(new ChoiceWithValueDisplay(&g_Config.iNewChat, sc->T("Chat"), new AnchorLayoutParams(130,WRAP_CONTENT,80, NONE, NONE, 50, true)))->OnClick.Handle(this, &EmuScreen::OnChat); + root_->Add(new ChoiceWithValueDisplay(&newChat, sc->T("Chat"), new AnchorLayoutParams(130,WRAP_CONTENT,80, NONE, NONE, 50, true)))->OnClick.Handle(this, &EmuScreen::OnChat); } saveStatePreview_ = new AsyncImageFileView("", IS_FIXED, nullptr, new AnchorLayoutParams(bounds.centerX(), 100, NONE, NONE, true)); saveStatePreview_->SetFixedSize(160, 90); @@ -807,9 +805,7 @@ UI::EventReturn EmuScreen::OnDevTools(UI::EventParams ¶ms) { UI::EventReturn EmuScreen::OnChat(UI::EventParams ¶ms) { releaseButtons(); - ChatMenu * ch = new ChatMenu(); // memory leak or not? - setChatPointer(ch); - screenManager()->push(ch); + screenManager()->push(new ChatMenu()); return UI::EVENT_DONE; }