147 |
148 |
148 public: |
149 public: |
149 TownAuthorityWindow(const WindowDesc *desc, WindowNumber window_number) : |
150 TownAuthorityWindow(const WindowDesc *desc, WindowNumber window_number) : |
150 Window(desc, window_number), sel_index(-1) |
151 Window(desc, window_number), sel_index(-1) |
151 { |
152 { |
|
153 this->town = GetTown(this->window_number); |
152 this->vscroll.cap = 5; |
154 this->vscroll.cap = 5; |
153 |
155 |
154 this->FindWindowPlacementAndResize(desc); |
156 this->FindWindowPlacementAndResize(desc); |
155 } |
157 } |
156 |
158 |
157 virtual void OnPaint() |
159 virtual void OnPaint() |
158 { |
160 { |
159 const Town *t = GetTown(this->window_number); |
|
160 int numact; |
161 int numact; |
161 uint buttons = GetMaskOfTownActions(&numact, _local_player, t); |
162 uint buttons = GetMaskOfTownActions(&numact, _local_player, this->town); |
162 |
163 |
163 SetVScrollCount(this, numact + 1); |
164 SetVScrollCount(this, numact + 1); |
164 |
165 |
165 if (this->sel_index != -1 && !HasBit(buttons, this->sel_index)) { |
166 if (this->sel_index != -1 && !HasBit(buttons, this->sel_index)) { |
166 this->sel_index = -1; |
167 this->sel_index = -1; |
176 /* Draw list of players */ |
177 /* Draw list of players */ |
177 int y = 25; |
178 int y = 25; |
178 |
179 |
179 const Player *p; |
180 const Player *p; |
180 FOR_ALL_PLAYERS(p) { |
181 FOR_ALL_PLAYERS(p) { |
181 if (p->is_active && (HasBit(t->have_ratings, p->index) || t->exclusivity == p->index)) { |
182 if (p->is_active && (HasBit(this->town->have_ratings, p->index) || this->town->exclusivity == p->index)) { |
182 DrawPlayerIcon(p->index, 2, y); |
183 DrawPlayerIcon(p->index, 2, y); |
183 |
184 |
184 SetDParam(0, p->index); |
185 SetDParam(0, p->index); |
185 SetDParam(1, p->index); |
186 SetDParam(1, p->index); |
186 |
187 |
187 int r = t->ratings[p->index]; |
188 int r = this->town->ratings[p->index]; |
188 StringID str; |
189 StringID str; |
189 (str = STR_3035_APPALLING, r <= RATING_APPALLING) || // Apalling |
190 (str = STR_3035_APPALLING, r <= RATING_APPALLING) || // Apalling |
190 (str++, r <= RATING_VERYPOOR) || // Very Poor |
191 (str++, r <= RATING_VERYPOOR) || // Very Poor |
191 (str++, r <= RATING_POOR) || // Poor |
192 (str++, r <= RATING_POOR) || // Poor |
192 (str++, r <= RATING_MEDIOCRE) || // Mediocore |
193 (str++, r <= RATING_MEDIOCRE) || // Mediocore |
194 (str++, r <= RATING_VERYGOOD) || // Very Good |
195 (str++, r <= RATING_VERYGOOD) || // Very Good |
195 (str++, r <= RATING_EXCELLENT) || // Excellent |
196 (str++, r <= RATING_EXCELLENT) || // Excellent |
196 (str++, true); // Outstanding |
197 (str++, true); // Outstanding |
197 |
198 |
198 SetDParam(2, str); |
199 SetDParam(2, str); |
199 if (t->exclusivity == p->index) { // red icon for player with exclusive rights |
200 if (this->town->exclusivity == p->index) { // red icon for player with exclusive rights |
200 DrawSprite(SPR_BLOT, PALETTE_TO_RED, 18, y); |
201 DrawSprite(SPR_BLOT, PALETTE_TO_RED, 18, y); |
201 } |
202 } |
202 |
203 |
203 DrawString(28, y, STR_2024, TC_FROMSTRING); |
204 DrawString(28, y, STR_2024, TC_FROMSTRING); |
204 y += 10; |
205 y += 10; |
233 |
234 |
234 void HandleClick(Point pt, int widget, bool double_click) |
235 void HandleClick(Point pt, int widget, bool double_click) |
235 { |
236 { |
236 switch (widget) { |
237 switch (widget) { |
237 case TWA_COMMAND_LIST: { |
238 case TWA_COMMAND_LIST: { |
238 const Town *t = GetTown(this->window_number); |
|
239 int y = (pt.y - 0x6B) / 10; |
239 int y = (pt.y - 0x6B) / 10; |
240 |
240 |
241 if (!IsInsideMM(y, 0, 5)) return; |
241 if (!IsInsideMM(y, 0, 5)) return; |
242 |
242 |
243 y = GetNthSetBit(GetMaskOfTownActions(NULL, _local_player, t), y + this->vscroll.pos - 1); |
243 y = GetNthSetBit(GetMaskOfTownActions(NULL, _local_player, this->town), y + this->vscroll.pos - 1); |
244 if (y >= 0) { |
244 if (y >= 0) { |
245 this->sel_index = y; |
245 this->sel_index = y; |
246 this->SetDirty(); |
246 this->SetDirty(); |
247 } |
247 } |
248 /* Fall through to clicking in case we are double-clicked */ |
248 /* Fall through to clicking in case we are double-clicked */ |
249 if (!double_click || y < 0) break; |
249 if (!double_click || y < 0) break; |
250 } |
250 } |
251 |
251 |
252 case TWA_EXECUTE: |
252 case TWA_EXECUTE: |
253 DoCommandP(GetTown(this->window_number)->xy, this->window_number, this->sel_index, NULL, CMD_DO_TOWN_ACTION | CMD_MSG(STR_00B4_CAN_T_DO_THIS)); |
253 DoCommandP(this->town->xy, this->window_number, this->sel_index, NULL, CMD_DO_TOWN_ACTION | CMD_MSG(STR_00B4_CAN_T_DO_THIS)); |
254 break; |
254 break; |
255 } |
255 } |
256 } |
256 } |
257 |
257 |
258 virtual void OnHundredthTick() |
258 virtual void OnHundredthTick() |
287 }; |
288 }; |
288 |
289 |
289 public: |
290 public: |
290 TownViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) |
291 TownViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) |
291 { |
292 { |
292 const Town *t = GetTown(this->window_number); |
293 this->town = GetTown(this->window_number); |
|
294 bool ingame = _game_mode != GM_EDITOR; |
293 |
295 |
294 this->flags4 |= WF_DISABLE_VP_SCROLL; |
296 this->flags4 |= WF_DISABLE_VP_SCROLL; |
295 InitializeWindowViewport(this, 3, 17, 254, 86, t->xy, ZOOM_LVL_TOWN); |
297 InitializeWindowViewport(this, 3, 17, 254, 86, this->town->xy, ZOOM_LVL_TOWN); |
296 |
298 |
297 bool ingame = _game_mode != GM_EDITOR; |
299 if (this->town->larger_town) this->widget[TVW_CAPTION].data = STR_CITY; |
298 if (t->larger_town) this->widget[TVW_CAPTION].data = STR_CITY; |
|
299 this->SetWidgetHiddenState(TVW_DELETE, ingame); // hide delete button on game mode |
300 this->SetWidgetHiddenState(TVW_DELETE, ingame); // hide delete button on game mode |
300 this->SetWidgetHiddenState(TVW_EXPAND, ingame); // hide expand button on game mode |
301 this->SetWidgetHiddenState(TVW_EXPAND, ingame); // hide expand button on game mode |
301 this->SetWidgetHiddenState(TVW_SHOWAUTORITY, !ingame); // hide autority button on editor mode |
302 this->SetWidgetHiddenState(TVW_SHOWAUTORITY, !ingame); // hide autority button on editor mode |
302 |
303 |
303 if (ingame) { |
304 if (ingame) { |
312 this->FindWindowPlacementAndResize(desc); |
313 this->FindWindowPlacementAndResize(desc); |
313 } |
314 } |
314 |
315 |
315 virtual void OnPaint() |
316 virtual void OnPaint() |
316 { |
317 { |
317 const Town *t = GetTown(this->window_number); |
|
318 |
|
319 /* disable renaming town in network games if you are not the server */ |
318 /* disable renaming town in network games if you are not the server */ |
320 this->SetWidgetDisabledState(TVW_CHANGENAME, _networking && !_network_server); |
319 this->SetWidgetDisabledState(TVW_CHANGENAME, _networking && !_network_server); |
321 |
320 |
322 SetDParam(0, t->index); |
321 SetDParam(0, this->town->index); |
323 this->DrawWidgets(); |
322 this->DrawWidgets(); |
324 |
323 |
325 SetDParam(0, t->population); |
324 SetDParam(0, this->town->population); |
326 SetDParam(1, t->num_houses); |
325 SetDParam(1, this->town->num_houses); |
327 DrawString(2, 107, STR_2006_POPULATION, TC_FROMSTRING); |
326 DrawString(2, 107, STR_2006_POPULATION, TC_FROMSTRING); |
328 |
327 |
329 SetDParam(0, t->act_pass); |
328 SetDParam(0, this->town->act_pass); |
330 SetDParam(1, t->max_pass); |
329 SetDParam(1, this->town->max_pass); |
331 DrawString(2, 117, STR_200D_PASSENGERS_LAST_MONTH_MAX, TC_FROMSTRING); |
330 DrawString(2, 117, STR_200D_PASSENGERS_LAST_MONTH_MAX, TC_FROMSTRING); |
332 |
331 |
333 SetDParam(0, t->act_mail); |
332 SetDParam(0, this->town->act_mail); |
334 SetDParam(1, t->max_mail); |
333 SetDParam(1, this->town->max_mail); |
335 DrawString(2, 127, STR_200E_MAIL_LAST_MONTH_MAX, TC_FROMSTRING); |
334 DrawString(2, 127, STR_200E_MAIL_LAST_MONTH_MAX, TC_FROMSTRING); |
336 |
335 |
337 this->DrawViewport(); |
336 this->DrawViewport(); |
338 } |
337 } |
339 |
338 |
340 virtual void OnClick(Point pt, int widget) |
339 virtual void OnClick(Point pt, int widget) |
341 { |
340 { |
342 Town *t = GetTown(this->window_number); |
|
343 |
|
344 switch (widget) { |
341 switch (widget) { |
345 case TVW_CENTERVIEW: /* scroll to location */ |
342 case TVW_CENTERVIEW: /* scroll to location */ |
346 if (_ctrl_pressed) { |
343 if (_ctrl_pressed) { |
347 ShowExtraViewPortWindow(t->xy); |
344 ShowExtraViewPortWindow(this->town->xy); |
348 } else { |
345 } else { |
349 ScrollMainWindowToTile(t->xy); |
346 ScrollMainWindowToTile(this->town->xy); |
350 } |
347 } |
351 break; |
348 break; |
352 |
349 |
353 case TVW_SHOWAUTORITY: /* town authority */ |
350 case TVW_SHOWAUTORITY: /* town authority */ |
354 ShowTownAuthorityWindow(this->window_number); |
351 ShowTownAuthorityWindow(this->window_number); |
358 SetDParam(0, this->window_number); |
355 SetDParam(0, this->window_number); |
359 ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, 31, 130, this, CS_ALPHANUMERAL); |
356 ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, 31, 130, this, CS_ALPHANUMERAL); |
360 break; |
357 break; |
361 |
358 |
362 case TVW_EXPAND: /* expand town - only available on Scenario editor */ |
359 case TVW_EXPAND: /* expand town - only available on Scenario editor */ |
363 ExpandTown(t); |
360 ExpandTown(this->town); |
364 break; |
361 break; |
365 |
362 |
366 case TVW_DELETE: /* delete town - only available on Scenario editor */ |
363 case TVW_DELETE: /* delete town - only available on Scenario editor */ |
367 delete t; |
364 delete this->town; |
368 break; |
365 break; |
369 } |
366 } |
370 } |
367 } |
371 |
368 |
372 virtual void OnQueryTextFinished(char *str) |
369 virtual void OnQueryTextFinished(char *str) |