Changeset - r17586:4de9e61ce543
[Not reviewed]
master
0 1 0
rubidium - 14 years ago 2011-04-22 15:52:50
rubidium@openttd.org
(svn r22360) -Codechange: use globally unique client id to mark the selected client instead of the position in the client list
1 file changed with 17 insertions and 22 deletions:
0 comments (0 inline, 0 general)
src/network/network_gui.cpp
Show inline comments
 
@@ -1706,25 +1706,12 @@ static const WindowDesc _client_list_pop
 
	WDP_AUTO, 0, 0,
 
	WC_CLIENT_LIST_POPUP, WC_CLIENT_LIST,
 
	0,
 
	_nested_client_list_popup_widgets, lengthof(_nested_client_list_popup_widgets)
 
);
 

	
 
/* Finds the Xth client-info that is active */
 
static NetworkClientInfo *NetworkFindClientInfo(byte client_no)
 
{
 
	NetworkClientInfo *ci;
 

	
 
	FOR_ALL_CLIENT_INFOS(ci) {
 
		if (client_no == 0) return ci;
 
		client_no--;
 
	}
 

	
 
	return NULL;
 
}
 

	
 
/* Here we start to define the options out of the menu */
 
static void ClientList_Kick(const NetworkClientInfo *ci)
 
{
 
	NetworkServerKickClient(ci->client_id);
 
}
 

	
 
@@ -1759,13 +1746,13 @@ struct NetworkClientListPopupWindow : Wi
 
	struct ClientListAction {
 
		StringID name;                ///< Name of the action to execute
 
		ClientList_Action_Proc *proc; ///< Action to execute
 
	};
 

	
 
	uint sel_index;
 
	int client_no;
 
	ClientID client_id;
 
	Point desired_location;
 
	SmallVector<ClientListAction, 2> actions; ///< Actions to execute
 

	
 
	/**
 
	 * Add an action to the list of actions to execute.
 
	 * @param name the name of the action
 
@@ -1775,20 +1762,20 @@ struct NetworkClientListPopupWindow : Wi
 
	{
 
		ClientListAction *action = this->actions.Append();
 
		action->name = name;
 
		action->proc = proc;
 
	}
 

	
 
	NetworkClientListPopupWindow(const WindowDesc *desc, int x, int y, int client_no) :
 
	NetworkClientListPopupWindow(const WindowDesc *desc, int x, int y, ClientID client_id) :
 
			Window(),
 
			sel_index(0), client_no(client_no)
 
			sel_index(0), client_id(client_id)
 
	{
 
		this->desired_location.x = x;
 
		this->desired_location.y = y;
 

	
 
		const NetworkClientInfo *ci = NetworkFindClientInfo(client_no);
 
		const NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id);
 

	
 
		if (_network_own_client_id != ci->client_id) {
 
			this->AddAction(STR_NETWORK_CLIENTLIST_SPEAK_TO_CLIENT, &ClientList_SpeakToClient);
 
		}
 

	
 
		if (Company::IsValidID(ci->client_playas) || ci->client_playas == COMPANY_SPECTATOR) {
 
@@ -1858,31 +1845,31 @@ struct NetworkClientListPopupWindow : Wi
 
			if (index == this->sel_index || index >= this->actions.Length()) return;
 

	
 
			this->sel_index = index;
 
			this->SetDirty();
 
		} else {
 
			if (index < this->actions.Length() && _cursor.pos.y >= this->top) {
 
				const NetworkClientInfo *ci = NetworkFindClientInfo(this->client_no);
 
				const NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(this->client_id);
 
				if (ci != NULL) this->actions[index].proc(ci);
 
			}
 

	
 
			DeleteWindowById(WC_CLIENT_LIST_POPUP, 0);
 
		}
 
	}
 
};
 

	
 
/**
 
 * Show the popup (action list)
 
 */
 
static void PopupClientList(int client_no, int x, int y)
 
static void PopupClientList(ClientID client_id, int x, int y)
 
{
 
	DeleteWindowById(WC_CLIENT_LIST_POPUP, 0);
 

	
 
	if (NetworkFindClientInfo(client_no) == NULL) return;
 
	if (NetworkFindClientInfoFromClientID(client_id) == NULL) return;
 

	
 
	new NetworkClientListPopupWindow(&_client_list_popup_desc, x, y, client_no);
 
	new NetworkClientListPopupWindow(&_client_list_popup_desc, x, y, client_id);
 
}
 

	
 

	
 
/** Widget numbers of the client list window. */
 
enum ClientListWidgets {
 
	CLW_PANEL,
 
@@ -2013,13 +2000,21 @@ struct NetworkClientListWindow : Window 
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		/* Show the popup with option */
 
		if (this->selected_item != -1) {
 
			PopupClientList(this->selected_item, pt.x + this->left, pt.y + this->top);
 
			NetworkClientInfo *ci;
 

	
 
			int client_no = this->selected_item;
 
			FOR_ALL_CLIENT_INFOS(ci) {
 
				if (client_no == 0) break;
 
				client_no--;
 
			}
 

	
 
			if (ci != NULL) PopupClientList(ci->client_id, pt.x + this->left, pt.y + this->top);
 
		}
 
	}
 

	
 
	virtual void OnMouseOver(Point pt, int widget)
 
	{
 
		/* -1 means we left the current window */
0 comments (0 inline, 0 general)