Changeset - r11677:627f7f0cc1a2
[Not reviewed]
master
0 2 0
rubidium - 16 years ago 2009-04-15 20:37:00
rubidium@openttd.org
(svn r16065) -Fix: don't readd (and resolve) the last joined server each time the window gets repainted
2 files changed with 12 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/network/core/address.h
Show inline comments
 
@@ -170,58 +170,58 @@ public:
 
	 * Checks whether this IP address is contained by the given netmask.
 
	 * @param netmask the netmask in CIDR notation to test against.
 
	 * @note netmask without /n assumes all bits need to match.
 
	 * @return true if this IP is within the netmask.
 
	 */
 
	bool IsInNetmask(char *netmask);
 

	
 
	/**
 
	 * Compare the address of this class with the address of another.
 
	 * @param address the other address.
 
	 * @return < 0 if address is less, 0 if equal and > 0 if address is more
 
	 */
 
	int CompareTo(NetworkAddress address)
 
	int CompareTo(NetworkAddress &address)
 
	{
 
		int r = this->GetAddressLength() - address.GetAddressLength();
 
		if (r == 0) r = this->address.ss_family - address.address.ss_family;
 
		if (r == 0) r = memcmp(&this->address, &address.address, this->address_length);
 
		if (r == 0) r = this->GetPort() - address.GetPort();
 
		return r;
 
	}
 

	
 
	/**
 
	 * Compare the address of this class with the address of another.
 
	 * @param address the other address.
 
	 * @return true if both match.
 
	 */
 
	bool operator == (NetworkAddress address)
 
	bool operator == (NetworkAddress &address)
 
	{
 
		return this->CompareTo(address) == 0;
 
	}
 

	
 
	/**
 
	 * Compare the address of this class with the address of another.
 
	 * @param address the other address.
 
	 * @return true if both match.
 
	 */
 
	bool operator == (NetworkAddress address) const
 
	bool operator == (NetworkAddress &address) const
 
	{
 
		return const_cast<NetworkAddress*>(this)->CompareTo(address) == 0;
 
	}
 

	
 
	/**
 
	 * Compare the address of this class with the address of another.
 
	 * @param address the other address.
 
	 */
 
	bool operator < (NetworkAddress address)
 
	bool operator < (NetworkAddress &address)
 
	{
 
		return this->CompareTo(address) < 0;
 
	}
 

	
 
	/**
 
	 * Connect to the given address.
 
	 * @return the connected socket or INVALID_SOCKET.
 
	 */
 
	SOCKET Connect();
 

	
 
	/**
 
	 * Make the given socket listen.
src/network/network_gui.cpp
Show inline comments
 
@@ -111,28 +111,29 @@ enum NetworkGameWindowWidgets {
 
typedef GUIList<NetworkGameList*> GUIGameServerList;
 
typedef uint16 ServerListPosition;
 
static const ServerListPosition SLP_INVALID = 0xFFFF;
 

	
 
class NetworkGameWindow : public QueryStringBaseWindow {
 
protected:
 
	/* Runtime saved values */
 
	static Listing last_sorting;
 

	
 
	/* Constants for sorting servers */
 
	static GUIGameServerList::SortFunction * const sorter_funcs[];
 

	
 
	byte field;                  ///< selected text-field
 
	NetworkGameList *server;     ///< selected server
 
	GUIGameServerList servers;   ///< list with game servers.
 
	ServerListPosition list_pos; ///< position of the selected server
 
	byte field;                   ///< selected text-field
 
	NetworkGameList *server;      ///< selected server
 
	NetworkGameList *last_joined; ///< the last joined server
 
	GUIGameServerList servers;    ///< list with game servers.
 
	ServerListPosition list_pos;  ///< position of the selected server
 

	
 
	/**
 
	 * (Re)build the network game list as its amount has changed because
 
	 * an item has been added or deleted for example
 
	 */
 
	void BuildNetworkGameList()
 
	{
 
		if (!this->servers.NeedRebuild()) return;
 

	
 
		/* Create temporary array of games to use for listing */
 
		this->servers.Clear();
 

	
 
@@ -328,24 +329,26 @@ public:
 
		InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 120);
 
		this->SetFocusedWidget(NGWW_CLIENT);
 

	
 
		UpdateNetworkGameWindow(true);
 

	
 
		this->vscroll.cap = 11;
 
		this->resize.step_height = NET_PRC__SIZE_OF_ROW;
 

	
 
		this->field = NGWW_CLIENT;
 
		this->server = NULL;
 
		this->list_pos = SLP_INVALID;
 

	
 
		this->last_joined = NetworkGameListAddItem(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port));
 

	
 
		this->servers.SetListing(this->last_sorting);
 
		this->servers.SetSortFuncs(this->sorter_funcs);
 
		this->servers.ForceRebuild();
 
		this->SortNetworkGameList();
 

	
 
		this->FindWindowPlacementAndResize(desc);
 
	}
 

	
 
	~NetworkGameWindow()
 
	{
 
		this->last_sorting = this->servers.GetListing();
 
	}
 
@@ -394,27 +397,26 @@ public:
 
		}
 

	
 
		uint16 y = NET_PRC__OFFSET_TOP_WIDGET + 3;
 

	
 
		const int max = min(this->vscroll.pos + this->vscroll.cap, (int)this->servers.Length());
 

	
 
		for (int i = this->vscroll.pos; i < max; ++i) {
 
			const NetworkGameList *ngl = this->servers[i];
 
			this->DrawServerLine(ngl, y, ngl == sel);
 
			y += NET_PRC__SIZE_OF_ROW;
 
		}
 

	
 
		const NetworkGameList *last_joined = NetworkGameListAddItem(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port));
 
		/* Draw the last joined server, if any */
 
		if (last_joined != NULL) this->DrawServerLine(last_joined, y = this->widget[NGWW_LASTJOINED].top + 3, last_joined == sel);
 
		if (this->last_joined != NULL) this->DrawServerLine(this->last_joined, y = this->widget[NGWW_LASTJOINED].top + 3, this->last_joined == sel);
 

	
 
		/* Draw the right menu */
 
		GfxFillRect(this->widget[NGWW_DETAILS].left + 1, 43, this->widget[NGWW_DETAILS].right - 1, 92, 157);
 
		if (sel == NULL) {
 
			DrawString(this->widget[NGWW_DETAILS].left + 1, this->widget[NGWW_DETAILS].right - 1, 58, STR_NETWORK_GAME_INFO, TC_FROMSTRING, SA_CENTER);
 
		} else if (!sel->online) {
 
			SetDParamStr(0, sel->info.server_name);
 
			DrawString(this->widget[NGWW_DETAILS].left + 1, this->widget[NGWW_DETAILS].right - 1, 68, STR_JUST_RAW_STRING, TC_ORANGE, SA_CENTER); // game name
 

	
 
			DrawString(this->widget[NGWW_DETAILS].left + 1, this->widget[NGWW_DETAILS].right - 1, 132, STR_NETWORK_SERVER_OFFLINE, TC_FROMSTRING, SA_CENTER); // server offline
 
		} else { // show game info
 
			uint16 y = 100;
0 comments (0 inline, 0 general)