(svn r17884) -Codechange: remove (most) magic numbers from drawing the details of the network lobby and split detail drawing to its own function

This commit is contained in:
rubidium 2009-10-27 12:03:12 +00:00
parent c82d2a1fa6
commit 4376af5b04

View File

@ -1451,67 +1451,72 @@ struct NetworkLobbyWindow : public Window {
DrawSprite(SPR_BLOT, income ? PALETTE_TO_GREEN : PALETTE_TO_RED, 145, y); DrawSprite(SPR_BLOT, income ? PALETTE_TO_GREEN : PALETTE_TO_RED, 145, y);
pos++; pos++;
y += NET_PRC__SIZE_OF_ROW; y += this->resize.step_height;
if (pos >= this->vscroll.GetPosition() + this->vscroll.GetCapacity()) break; if (pos >= this->vscroll.GetPosition() + this->vscroll.GetCapacity()) break;
} }
const Widget *wi = &this->widget[NLWW_DETAILS];
Rect r = {wi->left, wi->top, wi->right, wi->bottom};
this->DrawDetails(r);
}
void DrawDetails(const Rect &r) const
{
const int detail_height = 12 + FONT_HEIGHT_NORMAL + 12;
/* Draw info about selected company when it is selected in the left window */ /* Draw info about selected company when it is selected in the left window */
GfxFillRect(174, 39, 403, 75, 157); GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.top + detail_height - 1, 157);
DrawString(this->widget[NLWW_DETAILS].left + 10, this->widget[NLWW_DETAILS].right - 10, 50, STR_NETWORK_GAME_LOBBY_COMPANY_INFO, TC_FROMSTRING, SA_CENTER); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 12, STR_NETWORK_GAME_LOBBY_COMPANY_INFO, TC_FROMSTRING, SA_CENTER);
if (this->company != INVALID_COMPANY && !StrEmpty(this->company_info[this->company].company_name)) {
const uint x = this->widget[NLWW_DETAILS].left + 10; if (this->company == INVALID_COMPANY || StrEmpty(this->company_info[this->company].company_name)) return;
y = 80;
int y = r.top + detail_height + 4;
const NetworkGameInfo *gi = &this->server->info;
SetDParam(0, gi->clients_on); SetDParam(0, gi->clients_on);
SetDParam(1, gi->clients_max); SetDParam(1, gi->clients_max);
SetDParam(2, gi->companies_on); SetDParam(2, gi->companies_on);
SetDParam(3, gi->companies_max); SetDParam(3, gi->companies_max);
DrawString(x, this->widget[NLWW_DETAILS].right, y, STR_NETWORK_SERVER_LIST_CLIENTS); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_CLIENTS);
y += 10; y += FONT_HEIGHT_NORMAL;
SetDParamStr(0, this->company_info[this->company].company_name); SetDParamStr(0, this->company_info[this->company].company_name);
DrawString(x, this->widget[NLWW_DETAILS].right, y, STR_NETWORK_GAME_LOBBY_COMPANY_NAME); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_GAME_LOBBY_COMPANY_NAME);
y += 10; y += FONT_HEIGHT_NORMAL;
SetDParam(0, this->company_info[this->company].inaugurated_year); SetDParam(0, this->company_info[this->company].inaugurated_year);
DrawString(x, this->widget[NLWW_DETAILS].right, y, STR_NETWORK_GAME_LOBBY_INAUGURATION_YEAR); // inauguration year DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_GAME_LOBBY_INAUGURATION_YEAR); // inauguration year
y += 10; y += FONT_HEIGHT_NORMAL;
SetDParam(0, this->company_info[this->company].company_value); SetDParam(0, this->company_info[this->company].company_value);
DrawString(x, this->widget[NLWW_DETAILS].right, y, STR_NETWORK_GAME_LOBBY_VALUE); // company value DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_GAME_LOBBY_VALUE); // company value
y += 10; y += FONT_HEIGHT_NORMAL;
SetDParam(0, this->company_info[this->company].money); SetDParam(0, this->company_info[this->company].money);
DrawString(x, this->widget[NLWW_DETAILS].right, y, STR_NETWORK_GAME_LOBBY_CURRENT_BALANCE); // current balance DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_GAME_LOBBY_CURRENT_BALANCE); // current balance
y += 10; y += FONT_HEIGHT_NORMAL;
SetDParam(0, this->company_info[this->company].income); SetDParam(0, this->company_info[this->company].income);
DrawString(x, this->widget[NLWW_DETAILS].right, y, STR_NETWORK_GAME_LOBBY_LAST_YEARS_INCOME); // last year's income DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_GAME_LOBBY_LAST_YEARS_INCOME); // last year's income
y += 10; y += FONT_HEIGHT_NORMAL;
SetDParam(0, this->company_info[this->company].performance); SetDParam(0, this->company_info[this->company].performance);
DrawString(x, this->widget[NLWW_DETAILS].right, y, STR_NETWORK_GAME_LOBBY_PERFORMANCE); // performance DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_GAME_LOBBY_PERFORMANCE); // performance
y += 10; y += FONT_HEIGHT_NORMAL;
SetDParam(0, this->company_info[this->company].num_vehicle[0]); for (uint i = 0; i < lengthof(this->company_info[this->company].num_vehicle); i++) {
SetDParam(1, this->company_info[this->company].num_vehicle[1]); SetDParam(i, this->company_info[this->company].num_vehicle[i]);
SetDParam(2, this->company_info[this->company].num_vehicle[2]); }
SetDParam(3, this->company_info[this->company].num_vehicle[3]); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_GAME_LOBBY_VEHICLES); // vehicles
SetDParam(4, this->company_info[this->company].num_vehicle[4]); y += FONT_HEIGHT_NORMAL;
DrawString(x, this->widget[NLWW_DETAILS].right, y, STR_NETWORK_GAME_LOBBY_VEHICLES); // vehicles
y += 10;
SetDParam(0, this->company_info[this->company].num_station[0]); for (uint i = 0; i < lengthof(this->company_info[this->company].num_station); i++) {
SetDParam(1, this->company_info[this->company].num_station[1]); SetDParam(i, this->company_info[this->company].num_station[i]);
SetDParam(2, this->company_info[this->company].num_station[2]); }
SetDParam(3, this->company_info[this->company].num_station[3]); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_GAME_LOBBY_STATIONS); // stations
SetDParam(4, this->company_info[this->company].num_station[4]); y += FONT_HEIGHT_NORMAL;
DrawString(x, this->widget[NLWW_DETAILS].right, y, STR_NETWORK_GAME_LOBBY_STATIONS); // stations
y += 10;
SetDParamStr(0, this->company_info[this->company].clients); SetDParamStr(0, this->company_info[this->company].clients);
DrawString(x, this->widget[NLWW_DETAILS].right, y, STR_NETWORK_GAME_LOBBY_PLAYERS); // players DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_GAME_LOBBY_PLAYERS); // players
}
} }
virtual void OnClick(Point pt, int widget) virtual void OnClick(Point pt, int widget)
@ -1523,7 +1528,7 @@ struct NetworkLobbyWindow : public Window {
break; break;
case NLWW_MATRIX: { // Company list case NLWW_MATRIX: { // Company list
uint32 id_v = (pt.y - NET_PRC__OFFSET_TOP_WIDGET_COMPANY) / NET_PRC__SIZE_OF_ROW; uint32 id_v = (pt.y - NET_PRC__OFFSET_TOP_WIDGET_COMPANY) / this->resize.step_height;
if (id_v >= this->vscroll.GetCapacity()) break; if (id_v >= this->vscroll.GetCapacity()) break;