Changeset - r19812:4fb65ee58f68
[Not reviewed]
master
0 1 0
frosch - 12 years ago 2012-11-27 21:21:01
frosch@openttd.org
(svn r24767) -Codechange: Remove some fragile hacks from the multiplayer list who tried to disguised themself as optimisations.
1 file changed with 15 insertions and 28 deletions:
0 comments (0 inline, 0 general)
src/network/network_gui.cpp
Show inline comments
 
@@ -326,33 +326,25 @@ protected:
 
		return r;
 
	}
 

	
 
	/** Sort the server list */
 
	void SortNetworkGameList()
 
	{
 
		bool did_sort = this->servers.Sort();
 
		/* In case of 0 or 1 servers there is no sorting, thus this->list_pos
 
		 * isn't set to a "sane" value. So, we only take the short way out
 
		 * when we did not (re)sort and we have a valid this->list_pos, or
 
		 * there are no servers to actually select. */
 
		if (!did_sort && (this->list_pos != SLP_INVALID || this->servers.Length() == 0)) return;
 
		if (this->servers.Sort()) this->UpdateListPos();
 
	}
 

	
 
		/* After sorting ngl->sort_list contains the sorted items. Put these back
 
		 * into the original list. Basically nothing has changed, we are only
 
		 * shuffling the ->next pointers. While iterating, look for the
 
		 * currently selected server and set list_pos to its position */
 
	/** Set this->list_pos to match this->server */
 
	void UpdateListPos()
 
	{
 
		this->list_pos = SLP_INVALID;
 
		_network_game_list = this->servers[0];
 
		NetworkGameList *item = _network_game_list;
 
		if (item == this->server) this->list_pos = 0;
 
		for (uint i = 1; i != this->servers.Length(); i++) {
 
			item->next = this->servers[i];
 
			item = item->next;
 
			if (item == this->server) this->list_pos = i;
 
		for (uint i = 0; i != this->servers.Length(); i++) {
 
			if (this->servers[i] == this->server) {
 
				this->list_pos = i;
 
				break;
 
			}
 
		}
 
		item->next = NULL;
 
	}
 

	
 
	/**
 
	 * Draw a single server line.
 
	 * @param cur_item  the server to draw.
 
	 * @param y         from where to draw?
 
@@ -702,18 +694,13 @@ public:
 

	
 
			case WID_NG_LASTJOINED: {
 
				if (this->last_joined != NULL) {
 
					this->server = this->last_joined;
 

	
 
					/* search the position of the newly selected server */
 
					for (uint i = 0; i < this->servers.Length(); i++) {
 
						if (this->servers[i] == this->server) {
 
							this->list_pos = i;
 
							break;
 
						}
 
					}
 
					this->UpdateListPos();
 
					this->ScrollToSelectedServer();
 
					this->SetDirty();
 

	
 
					/* FIXME the disabling should go into some InvalidateData, which is called instead of the SetDirty */
 
					if (click_count > 1 && !this->IsWidgetDisabled(WID_NG_JOIN)) this->OnClick(pt, WID_NG_JOIN, 1);
 
				}
 
@@ -794,28 +781,28 @@ public:
 
		/* handle up, down, pageup, pagedown, home and end */
 
		if (keycode == WKC_UP || keycode == WKC_DOWN || keycode == WKC_PAGEUP || keycode == WKC_PAGEDOWN || keycode == WKC_HOME || keycode == WKC_END) {
 
			if (this->servers.Length() == 0) return ES_HANDLED;
 
			switch (keycode) {
 
				case WKC_UP:
 
					/* scroll up by one */
 
					if (this->server == NULL) return ES_HANDLED;
 
					if (this->list_pos == SLP_INVALID) return ES_HANDLED;
 
					if (this->list_pos > 0) this->list_pos--;
 
					break;
 
				case WKC_DOWN:
 
					/* scroll down by one */
 
					if (this->server == NULL) return ES_HANDLED;
 
					if (this->list_pos == SLP_INVALID) return ES_HANDLED;
 
					if (this->list_pos < this->servers.Length() - 1) this->list_pos++;
 
					break;
 
				case WKC_PAGEUP:
 
					/* scroll up a page */
 
					if (this->server == NULL) return ES_HANDLED;
 
					if (this->list_pos == SLP_INVALID) return ES_HANDLED;
 
					this->list_pos = (this->list_pos < this->vscroll->GetCapacity()) ? 0 : this->list_pos - this->vscroll->GetCapacity();
 
					break;
 
				case WKC_PAGEDOWN:
 
					/* scroll down a page */
 
					if (this->server == NULL) return ES_HANDLED;
 
					if (this->list_pos == SLP_INVALID) return ES_HANDLED;
 
					this->list_pos = min(this->list_pos + this->vscroll->GetCapacity(), (int)this->servers.Length() - 1);
 
					break;
 
				case WKC_HOME:
 
					/* jump to beginning */
 
					this->list_pos = 0;
 
					break;
0 comments (0 inline, 0 general)