Changeset - r13429:e3fbfc45e1b5
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2009-11-02 10:52:57
rubidium@openttd.org
(svn r17948) -Codechange: remove some magic numbers from the network client list GUIs / use ResizeWindow instead of custom resize code.
1 file changed with 17 insertions and 26 deletions:
0 comments (0 inline, 0 general)
src/network/network_gui.cpp
Show inline comments
 
@@ -1759,13 +1759,12 @@ typedef void ClientList_Action_Proc(byte
 

	
 
/* Max 10 actions per client */
 
#define MAX_CLIENTLIST_ACTION 10
 

	
 
enum {
 
	CLNWND_OFFSET = 16,
 
	CLNWND_ROWSIZE = 10
 
};
 

	
 
static const Widget _client_list_popup_widgets[] = {
 
{      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,     0,   99,     0,     0,     0, STR_NULL},
 
{   WIDGETS_END},
 
};
 
@@ -1925,45 +1924,45 @@ struct NetworkClientListPopupWindow : Wi
 
		for (int i = 0; i < MAX_CLIENTLIST_ACTION; i++) {
 
			if (this->action[i][0] == '\0') continue;
 
			if (this->proc[i] == NULL) continue;
 
			num++;
 
		}
 

	
 
		num *= CLNWND_ROWSIZE;
 
		num *= FONT_HEIGHT_NORMAL;
 

	
 
		return num + 1;
 
	}
 

	
 

	
 
	virtual void OnPaint()
 
	{
 
		this->DrawWidgets();
 

	
 
		/* Draw the actions */
 
		int sel = this->sel_index;
 
		int y = 1;
 
		for (int i = 0; i < MAX_CLIENTLIST_ACTION; i++, y += CLNWND_ROWSIZE) {
 
		for (int i = 0; i < MAX_CLIENTLIST_ACTION; i++, y += FONT_HEIGHT_NORMAL) {
 
			if (this->action[i][0] == '\0') continue;
 
			if (this->proc[i] == NULL) continue;
 

	
 
			TextColour colour;
 
			if (sel-- == 0) { // Selected item, highlight it
 
				GfxFillRect(1, y, 150 - 2, y + CLNWND_ROWSIZE - 1, 0);
 
				GfxFillRect(1, y, 150 - 2, y + FONT_HEIGHT_NORMAL - 1, 0);
 
				colour = TC_WHITE;
 
			} else {
 
				colour = TC_BLACK;
 
			}
 

	
 
			DrawString(4, this->width - 4, y, this->action[i], colour);
 
		}
 
	}
 

	
 
	virtual void OnMouseLoop()
 
	{
 
		/* We selected an action */
 
		int index = (_cursor.pos.y - this->top) / CLNWND_ROWSIZE;
 
		int index = (_cursor.pos.y - this->top) / FONT_HEIGHT_NORMAL;
 

	
 
		if (_left_button_down) {
 
			if (index == -1 || index == this->sel_index) return;
 

	
 
			this->sel_index = index;
 
			this->SetDirty();
 
@@ -2007,37 +2006,36 @@ enum ClientListWidgets {
 

	
 
static const Widget _client_list_widgets[] = {
 
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_BLACK_CROSS,          STR_TOOLTIP_CLOSE_WINDOW},
 
{    WWT_CAPTION,   RESIZE_NONE,  COLOUR_GREY,    11,   237,     0,    13, STR_NETWORK_COMPANY_LIST_CLIENT_LIST,  STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS},
 
{  WWT_STICKYBOX,   RESIZE_NONE,  COLOUR_GREY,   238,   249,     0,    13, STR_NULL,                 STR_TOOLTIP_STICKY},
 

	
 
{      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,     0,   249,    14,    14 + CLNWND_ROWSIZE + 1, 0x0, STR_NULL},
 
{      WWT_PANEL, RESIZE_BOTTOM,  COLOUR_GREY,     0,   249,    14,    15, 0x0, STR_NULL},
 
{   WIDGETS_END},
 
};
 

	
 
static const NWidgetPart _nested_client_list_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY, CLW_CLOSE),
 
		NWidget(WWT_CAPTION, COLOUR_GREY, CLW_CAPTION), SetDataTip(STR_NETWORK_COMPANY_LIST_CLIENT_LIST, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_STICKYBOX, COLOUR_GREY, CLW_STICKY),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_GREY, CLW_PANEL), SetMinimalSize(250, CLNWND_ROWSIZE + 2), EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_GREY, CLW_PANEL), SetMinimalSize(250, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM), SetResize(1, 1), EndContainer(),
 
};
 

	
 
static const WindowDesc _client_list_desc(
 
	WDP_AUTO, WDP_AUTO, 250, 1, 250, 1,
 
	WDP_AUTO, WDP_AUTO, 250, 16, 250, 16,
 
	WC_CLIENT_LIST, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
 
	_client_list_widgets, _nested_client_list_widgets, lengthof(_nested_client_list_widgets)
 
);
 

	
 
/**
 
 * Main handle for clientlist
 
 */
 
struct NetworkClientListWindow : Window
 
{
 
struct NetworkClientListWindow : Window {
 
	int selected_item;
 
	int selected_y;
 

	
 
	NetworkClientListWindow(const WindowDesc *desc, WindowNumber window_number) :
 
			Window(desc, window_number),
 
			selected_item(-1),
 
@@ -2056,21 +2054,18 @@ struct NetworkClientListWindow : Window
 

	
 
		/* Should be replaced with a loop through all clients */
 
		FOR_ALL_CLIENT_INFOS(ci) {
 
			if (ci->client_playas != COMPANY_INACTIVE_CLIENT) num++;
 
		}
 

	
 
		num *= CLNWND_ROWSIZE;
 
		num *= FONT_HEIGHT_NORMAL;
 

	
 
		int diff = (num + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM) - (this->widget[3].bottom - this->widget[3].top + 1);
 
		/* If height is changed */
 
		if (this->height != CLNWND_OFFSET + num + 1) {
 
			/* XXX - magic unfortunately; (num + 2) has to be one bigger than heigh (num + 1) */
 
			this->SetDirty();
 
			this->widget[3].bottom = this->widget[3].top + num + 2;
 
			this->height = CLNWND_OFFSET + num + 1;
 
			this->SetDirty();
 
		if (diff != 0) {
 
			ResizeWindow(this, 0, diff);
 
			return false;
 
		}
 
		return true;
 
	}
 

	
 
	virtual void OnPaint()
 
@@ -2080,18 +2075,18 @@ struct NetworkClientListWindow : Window
 

	
 
		/* Check if we need to reset the height */
 
		if (!this->CheckClientListHeight()) return;
 

	
 
		this->DrawWidgets();
 

	
 
		int y = CLNWND_OFFSET;
 
		int y = this->widget[3].top + WD_FRAMERECT_TOP;
 

	
 
		FOR_ALL_CLIENT_INFOS(ci) {
 
			TextColour colour;
 
			if (this->selected_item == i++) { // Selected item, highlight it
 
				GfxFillRect(1, y, 248, y + CLNWND_ROWSIZE - 1, 0);
 
				GfxFillRect(1, y, 248, y + FONT_HEIGHT_NORMAL - 1, 0);
 
				colour = TC_WHITE;
 
			} else {
 
				colour = TC_BLACK;
 
			}
 

	
 
			if (ci->client_id == CLIENT_ID_SERVER) {
 
@@ -2102,13 +2097,13 @@ struct NetworkClientListWindow : Window
 

	
 
			/* Filter out spectators */
 
			if (Company::IsValidID(ci->client_playas)) DrawCompanyIcon(ci->client_playas, 64, y + 1);
 

	
 
			DrawString(81, this->width - 2, y, ci->client_name, colour);
 

	
 
			y += CLNWND_ROWSIZE;
 
			y += FONT_HEIGHT_NORMAL;
 
		}
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		/* Show the popup with option */
 
@@ -2128,17 +2123,13 @@ struct NetworkClientListWindow : Window
 
		}
 
		/* It did not change.. no update! */
 
		if (pt.y == this->selected_y) return;
 

	
 
		/* Find the new selected item (if any) */
 
		this->selected_y = pt.y;
 
		if (pt.y > CLNWND_OFFSET) {
 
			this->selected_item = (pt.y - CLNWND_OFFSET) / CLNWND_ROWSIZE;
 
		} else {
 
			this->selected_item = -1;
 
		}
 
		this->selected_item = max((pt.y - this->widget[3].top - WD_FRAMERECT_TOP) / FONT_HEIGHT_NORMAL, -1);
 

	
 
		/* Repaint */
 
		this->SetDirty();
 
	}
 
};
 

	
0 comments (0 inline, 0 general)