changeset 13230:3a074fb7b01d draft

(svn r17737) -Codechange: remove the chat window when you were chatting with someone who lost his/her connection or when you were team chatting and moved out of the company.
author rubidium <rubidium@openttd.org>
date Wed, 07 Oct 2009 17:36:33 +0000
parents b4f88b1fec09
children 97f296d541e0
files src/company_cmd.cpp src/network/network.cpp src/network/network_base.h src/network/network_chat_gui.cpp
diffstat 4 files changed, 23 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -89,6 +89,9 @@
 	/* company could also be COMPANY_SPECTATOR or OWNER_NONE */
 	assert(Company::IsValidID(new_company) || new_company == COMPANY_SPECTATOR || new_company == OWNER_NONE);
 
+	/* Delete the chat window, if you were team chatting. */
+	InvalidateWindowData(WC_SEND_NETWORK_MSG, DESTTYPE_TEAM, _local_company);
+
 	_local_company = new_company;
 
 	/* Delete any construction windows... */
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -95,6 +95,15 @@
 extern void StateGameLoop();
 
 /**
+ * Basically a client is leaving us right now.
+ */
+NetworkClientInfo::~NetworkClientInfo()
+{
+	/* Delete the chat window, if you were chatting with this client. */
+	InvalidateWindowData(WC_SEND_NETWORK_MSG, DESTTYPE_CLIENT, this->client_id);
+}
+
+/**
  * Return the CI given it's raw index
  * @param index the index to search for
  * @return return a pointer to the corresponding NetworkClientInfo struct
--- a/src/network/network_base.h
+++ b/src/network/network_base.h
@@ -30,7 +30,7 @@
 	char unique_id[NETWORK_UNIQUE_ID_LENGTH];       ///< Every play sends an unique id so we can indentify him
 
 	NetworkClientInfo(ClientID client_id = INVALID_CLIENT_ID) : client_id(client_id) {}
-	~NetworkClientInfo() { client_id = INVALID_CLIENT_ID; }
+	~NetworkClientInfo();
 };
 
 #define FOR_ALL_CLIENT_INFOS_FROM(var, start) FOR_ALL_ITEMS_FROM(NetworkClientInfo, clientinfo_index, var, start)
--- a/src/network/network_chat_gui.cpp
+++ b/src/network/network_chat_gui.cpp
@@ -277,7 +277,7 @@
 	StringID dest_string;
 	int dest;
 
-	NetworkChatWindow (const WindowDesc *desc, DestType type, int dest) : QueryStringBaseWindow(NETWORK_CHAT_LENGTH)
+	NetworkChatWindow(const WindowDesc *desc, DestType type, int dest) : QueryStringBaseWindow(NETWORK_CHAT_LENGTH)
 	{
 		this->dtype   = type;
 		this->dest    = dest;
@@ -292,14 +292,14 @@
 		assert((uint)this->dtype < lengthof(chat_captions));
 		this->dest_string = chat_captions[this->dtype];
 
-		this->InitNested(desc);
+		this->InitNested(desc, type);
 
 		this->SetFocusedWidget(NWCW_TEXTBOX);
 		InvalidateWindowData(WC_NEWS_WINDOW, 0, this->height);
 		_chat_tab_completion_active = false;
 	}
 
-	~NetworkChatWindow ()
+	~NetworkChatWindow()
 	{
 		InvalidateWindowData(WC_NEWS_WINDOW, 0, 0);
 	}
@@ -505,6 +505,11 @@
 	{
 		ShowOnScreenKeyboard(this, wid, NWCW_CLOSE, NWCW_SENDBUTTON);
 	}
+
+	virtual void OnInvalidateData(int data)
+	{
+		if (data == this->dest) delete this;
+	}
 };
 
 static const NWidgetPart _nested_chat_window_widgets[] = {
@@ -530,8 +535,8 @@
 
 void ShowNetworkChatQueryWindow(DestType type, int dest)
 {
-	DeleteWindowById(WC_SEND_NETWORK_MSG, 0);
-	new NetworkChatWindow (&_chat_window_desc, type, dest);
+	DeleteWindowByClass(WC_SEND_NETWORK_MSG);
+	new NetworkChatWindow(&_chat_window_desc, type, dest);
 }
 
 #endif /* ENABLE_NETWORK */