make client list resize properly for double/quad size
This commit is contained in:
@@ -1898,7 +1898,9 @@ struct NetworkClientListWindow : Window {
|
|||||||
int selected_item;
|
int selected_item;
|
||||||
|
|
||||||
uint server_client_width;
|
uint server_client_width;
|
||||||
uint company_icon_width;
|
uint line_height;
|
||||||
|
|
||||||
|
Dimension icon_size;
|
||||||
|
|
||||||
NetworkClientListWindow(WindowDesc *desc, WindowNumber window_number) :
|
NetworkClientListWindow(WindowDesc *desc, WindowNumber window_number) :
|
||||||
Window(desc),
|
Window(desc),
|
||||||
@@ -1920,7 +1922,7 @@ struct NetworkClientListWindow : Window {
|
|||||||
if (ci->client_playas != COMPANY_INACTIVE_CLIENT) num++;
|
if (ci->client_playas != COMPANY_INACTIVE_CLIENT) num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
num *= FONT_HEIGHT_NORMAL;
|
num *= this->line_height;
|
||||||
|
|
||||||
int diff = (num + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM) - (this->GetWidget<NWidgetBase>(WID_CL_PANEL)->current_y);
|
int diff = (num + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM) - (this->GetWidget<NWidgetBase>(WID_CL_PANEL)->current_y);
|
||||||
/* If height is changed */
|
/* If height is changed */
|
||||||
@@ -1936,7 +1938,8 @@ struct NetworkClientListWindow : Window {
|
|||||||
if (widget != WID_CL_PANEL) return;
|
if (widget != WID_CL_PANEL) return;
|
||||||
|
|
||||||
this->server_client_width = max(GetStringBoundingBox(STR_NETWORK_SERVER).width, GetStringBoundingBox(STR_NETWORK_CLIENT).width) + WD_FRAMERECT_RIGHT;
|
this->server_client_width = max(GetStringBoundingBox(STR_NETWORK_SERVER).width, GetStringBoundingBox(STR_NETWORK_CLIENT).width) + WD_FRAMERECT_RIGHT;
|
||||||
this->company_icon_width = GetSpriteSize(SPR_COMPANY_ICON).width + WD_FRAMERECT_LEFT;
|
this->icon_size = GetSpriteSize(SPR_COMPANY_ICON);
|
||||||
|
this->line_height = max(this->icon_size.height + 2U, (uint)FONT_HEIGHT_NORMAL);
|
||||||
|
|
||||||
uint width = 100; // Default width
|
uint width = 100; // Default width
|
||||||
const NetworkClientInfo *ci;
|
const NetworkClientInfo *ci;
|
||||||
@@ -1946,7 +1949,7 @@ struct NetworkClientListWindow : Window {
|
|||||||
SetDParam(0, 0xFFFF);
|
SetDParam(0, 0xFFFF);
|
||||||
SetDParam(1, INVALID_COMPANY);
|
SetDParam(1, INVALID_COMPANY);
|
||||||
uint width2 = GetStringBoundingBox(STR_NETWORK_CLIENT_EXTRA).width;
|
uint width2 = GetStringBoundingBox(STR_NETWORK_CLIENT_EXTRA).width;
|
||||||
size->width = WD_FRAMERECT_LEFT + this->server_client_width + this->company_icon_width + width + WD_FRAMERECT_RIGHT + width2;
|
size->width = WD_FRAMERECT_LEFT + this->server_client_width + this->icon_size.width + WD_FRAMERECT_LEFT + width + WD_FRAMERECT_RIGHT + width2;
|
||||||
//size->width = WD_FRAMERECT_LEFT + this->server_client_width + this->company_icon_width + width + WD_FRAMERECT_RIGHT;
|
//size->width = WD_FRAMERECT_LEFT + this->server_client_width + this->company_icon_width + width + WD_FRAMERECT_RIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1963,11 +1966,13 @@ struct NetworkClientListWindow : Window {
|
|||||||
if (widget != WID_CL_PANEL) return;
|
if (widget != WID_CL_PANEL) return;
|
||||||
|
|
||||||
bool rtl = _current_text_dir == TD_RTL;
|
bool rtl = _current_text_dir == TD_RTL;
|
||||||
int icon_y_offset = 1 + (FONT_HEIGHT_NORMAL - 10) / 2;
|
int icon_offset = (this->line_height - icon_size.height) / 2;
|
||||||
|
int text_offset = (this->line_height - FONT_HEIGHT_NORMAL) / 2;
|
||||||
|
|
||||||
uint y = r.top + WD_FRAMERECT_TOP;
|
uint y = r.top + WD_FRAMERECT_TOP;
|
||||||
uint left = r.left + WD_FRAMERECT_LEFT;
|
uint left = r.left + WD_FRAMERECT_LEFT;
|
||||||
uint right = r.right - WD_FRAMERECT_RIGHT;
|
uint right = r.right - WD_FRAMERECT_RIGHT;
|
||||||
uint type_icon_width = this->server_client_width + this->company_icon_width;
|
uint type_icon_width = this->server_client_width + this->icon_size.width + WD_FRAMERECT_LEFT;
|
||||||
|
|
||||||
|
|
||||||
uint type_left = rtl ? right - this->server_client_width : left;
|
uint type_left = rtl ? right - this->server_client_width : left;
|
||||||
@@ -1981,29 +1986,29 @@ struct NetworkClientListWindow : Window {
|
|||||||
FOR_ALL_CLIENT_INFOS(ci) {
|
FOR_ALL_CLIENT_INFOS(ci) {
|
||||||
TextColour colour;
|
TextColour colour;
|
||||||
if (this->selected_item == i++) { // Selected item, highlight it
|
if (this->selected_item == i++) { // Selected item, highlight it
|
||||||
GfxFillRect(r.left + 1, y, r.right - 1, y + FONT_HEIGHT_NORMAL - 1, PC_BLACK);
|
GfxFillRect(r.left + 1, y, r.right - 1, y + this->line_height - 1, PC_BLACK);
|
||||||
colour = TC_WHITE;
|
colour = TC_WHITE;
|
||||||
} else {
|
} else {
|
||||||
colour = TC_BLACK;
|
colour = TC_BLACK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ci->client_id == CLIENT_ID_SERVER) {
|
if (ci->client_id == CLIENT_ID_SERVER) {
|
||||||
DrawString(type_left, type_right, y, STR_NETWORK_SERVER, colour);
|
DrawString(type_left, type_right, y + text_offset, STR_NETWORK_SERVER, colour);
|
||||||
} else {
|
} else {
|
||||||
DrawString(type_left, type_right, y, STR_NETWORK_CLIENT, colour);
|
DrawString(type_left, type_right, y + text_offset, STR_NETWORK_CLIENT, colour);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Filter out spectators */
|
/* Filter out spectators */
|
||||||
if (Company::IsValidID(ci->client_playas)) DrawCompanyIcon(ci->client_playas, icon_left, y + icon_y_offset);
|
if (Company::IsValidID(ci->client_playas)) DrawCompanyIcon(ci->client_playas, icon_left, y + icon_offset);
|
||||||
|
|
||||||
DrawString(name_left, name_right, y, ci->client_name, colour);
|
DrawString(name_left, name_right, y + text_offset, ci->client_name, colour);
|
||||||
|
|
||||||
uint extra = GetStringBoundingBox(ci->client_name).width + 15;
|
uint extra = GetStringBoundingBox(ci->client_name).width + 15;
|
||||||
SetDParam(0, ci->client_id);
|
SetDParam(0, ci->client_id);
|
||||||
SetDParam(1, ci->client_playas == INVALID_COMPANY ? ci->client_playas : ci->client_playas + 1);
|
SetDParam(1, ci->client_playas == INVALID_COMPANY ? ci->client_playas : ci->client_playas + 1);
|
||||||
DrawString(name_left + extra, right, y, STR_NETWORK_CLIENT_EXTRA, TC_FROMSTRING, SA_RIGHT);
|
DrawString(name_left + extra, right, y + text_offset, STR_NETWORK_CLIENT_EXTRA, TC_FROMSTRING, SA_RIGHT);
|
||||||
|
|
||||||
y += FONT_HEIGHT_NORMAL;
|
y += this->line_height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user