2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file town_gui.cpp GUI for towns. */
|
2007-04-04 03:21:14 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "town.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "viewport_func.h"
|
|
|
|
#include "gfx_func.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "gui.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_gui.h"
|
|
|
|
#include "textbuf_gui.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_func.h"
|
|
|
|
#include "company_base.h"
|
|
|
|
#include "company_gui.h"
|
2007-01-02 17:34:03 +00:00
|
|
|
#include "network/network.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2008-03-23 07:35:29 +00:00
|
|
|
#include "sound_func.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "economy_func.h"
|
2008-05-07 13:10:15 +00:00
|
|
|
#include "tilehighlight_func.h"
|
2008-05-27 20:05:36 +00:00
|
|
|
#include "sortlist_type.h"
|
2008-10-25 13:51:47 +00:00
|
|
|
#include "road_cmd.h"
|
2009-02-23 20:03:38 +00:00
|
|
|
#include "landscape_type.h"
|
|
|
|
#include "landscape.h"
|
|
|
|
#include "cargotype.h"
|
|
|
|
#include "tile_map.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/sprites.h"
|
|
|
|
#include "table/strings.h"
|
|
|
|
|
2008-05-27 20:05:36 +00:00
|
|
|
typedef GUIList<const Town*> GUITownList;
|
|
|
|
|
2009-04-12 19:25:59 +00:00
|
|
|
/** Widget numbers of the town authority window. */
|
|
|
|
enum TownAuthorityWidgets {
|
|
|
|
TWA_CLOSEBOX,
|
|
|
|
TWA_CAPTION,
|
|
|
|
TWA_RATING_INFO,
|
|
|
|
TWA_COMMAND_LIST,
|
|
|
|
TWA_SCROLLBAR,
|
|
|
|
TWA_ACTION_INFO,
|
|
|
|
TWA_EXECUTE,
|
|
|
|
};
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static const Widget _town_authority_widgets[] = {
|
2009-04-21 23:40:56 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_BROWN, 0, 10, 0, 13, STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW}, // TWA_CLOSEBOX
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, COLOUR_BROWN, 11, 316, 0, 13, STR_LOCAL_AUTHORITY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS}, // TWA_CAPTION
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, COLOUR_BROWN, 0, 316, 14, 105, 0x0, STR_NULL}, // TWA_RATING_INFO
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, COLOUR_BROWN, 0, 304, 106, 157, 0x0, STR_LOCAL_AUTHORITY_ACTIONS_TOOLTIP}, // TWA_COMMAND_LIST
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_NONE, COLOUR_BROWN, 305, 316, 106, 157, 0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST}, // TWA_SCROLLBAR
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, COLOUR_BROWN, 0, 316, 158, 209, 0x0, STR_NULL}, // TWA_ACTION_INFO
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_BROWN, 0, 316, 210, 221, STR_LOCAL_AUTHORITY_DO_IT_BUTTON, STR_LOCAL_AUTHORITY_DO_IT_TOOLTIP}, // TWA_EXECUTE
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2009-04-12 19:30:47 +00:00
|
|
|
static const NWidgetPart _nested_town_authority_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_BROWN, TWA_CLOSEBOX),
|
2009-04-21 23:40:56 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_BROWN, TWA_CAPTION), SetDataTip(STR_LOCAL_AUTHORITY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-04-12 19:30:47 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_BROWN, TWA_RATING_INFO), SetMinimalSize(317, 92), EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-04-21 23:40:56 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_BROWN, TWA_COMMAND_LIST), SetMinimalSize(305, 52), SetDataTip(0x0, STR_LOCAL_AUTHORITY_ACTIONS_TOOLTIP), EndContainer(),
|
2009-04-12 19:30:47 +00:00
|
|
|
NWidget(WWT_SCROLLBAR, COLOUR_BROWN, TWA_SCROLLBAR),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_BROWN, TWA_ACTION_INFO), SetMinimalSize(317, 52), EndContainer(),
|
2009-04-21 23:40:56 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, TWA_EXECUTE), SetMinimalSize(317, 12), SetDataTip(STR_LOCAL_AUTHORITY_DO_IT_BUTTON, STR_LOCAL_AUTHORITY_DO_IT_TOOLTIP),
|
2009-04-12 19:30:47 +00:00
|
|
|
};
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
extern const byte _town_action_costs[8];
|
|
|
|
|
2008-05-15 22:47:03 +00:00
|
|
|
struct TownAuthorityWindow : Window {
|
2008-05-22 02:03:05 +00:00
|
|
|
private:
|
2008-05-22 02:13:24 +00:00
|
|
|
Town *town;
|
2008-05-15 22:47:03 +00:00
|
|
|
int sel_index;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2008-07-09 02:18:51 +00:00
|
|
|
/**
|
|
|
|
* Get the position of the Nth set bit.
|
|
|
|
*
|
|
|
|
* If there is no Nth bit set return -1
|
|
|
|
*
|
|
|
|
* @param bits The value to search in
|
|
|
|
* @param n The Nth set bit from which we want to know the position
|
|
|
|
* @return The position of the Nth set bit
|
|
|
|
*/
|
|
|
|
static int GetNthSetBit(uint32 bits, int n)
|
|
|
|
{
|
|
|
|
if (n >= 0) {
|
|
|
|
uint i;
|
|
|
|
FOR_EACH_SET_BIT(i, bits) {
|
|
|
|
n--;
|
|
|
|
if (n < 0) return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-05-22 02:03:05 +00:00
|
|
|
public:
|
2008-05-15 22:47:03 +00:00
|
|
|
TownAuthorityWindow(const WindowDesc *desc, WindowNumber window_number) :
|
|
|
|
Window(desc, window_number), sel_index(-1)
|
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
this->town = Town::Get(this->window_number);
|
2008-05-15 22:47:03 +00:00
|
|
|
this->vscroll.cap = 5;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 22:47:03 +00:00
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 22:47:03 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
int numact;
|
2008-09-30 20:39:50 +00:00
|
|
|
uint buttons = GetMaskOfTownActions(&numact, _local_company, this->town);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 22:47:03 +00:00
|
|
|
SetVScrollCount(this, numact + 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 22:47:03 +00:00
|
|
|
if (this->sel_index != -1 && !HasBit(buttons, this->sel_index)) {
|
|
|
|
this->sel_index = -1;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 22:47:03 +00:00
|
|
|
this->SetWidgetDisabledState(6, this->sel_index == -1);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 22:47:03 +00:00
|
|
|
SetDParam(0, this->window_number);
|
2008-05-17 12:48:06 +00:00
|
|
|
this->DrawWidgets();
|
2008-04-14 17:06:36 +00:00
|
|
|
|
2009-01-15 12:36:24 +00:00
|
|
|
int y = this->widget[TWA_RATING_INFO].top + 1;
|
2008-04-14 17:06:36 +00:00
|
|
|
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(this->widget[TWA_RATING_INFO].left + 2, this->widget[TWA_RATING_INFO].right - 2, y, STR_LOCAL_AUTHORITY_COMPANY_RATINGS);
|
2009-01-15 12:36:24 +00:00
|
|
|
y += 10;
|
2008-05-15 22:47:03 +00:00
|
|
|
|
2009-01-15 12:36:24 +00:00
|
|
|
/* Draw list of companies */
|
2008-09-30 20:39:50 +00:00
|
|
|
const Company *c;
|
|
|
|
FOR_ALL_COMPANIES(c) {
|
|
|
|
if ((HasBit(this->town->have_ratings, c->index) || this->town->exclusivity == c->index)) {
|
|
|
|
DrawCompanyIcon(c->index, 2, y);
|
2008-05-15 22:47:03 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
SetDParam(0, c->index);
|
|
|
|
SetDParam(1, c->index);
|
2008-05-15 22:47:03 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
int r = this->town->ratings[c->index];
|
2008-05-15 22:47:03 +00:00
|
|
|
StringID str;
|
2009-04-21 23:40:56 +00:00
|
|
|
(str = STR_CARGO_RATING_APPALLING, r <= RATING_APPALLING) || // Apalling
|
2008-05-15 22:47:03 +00:00
|
|
|
(str++, r <= RATING_VERYPOOR) || // Very Poor
|
|
|
|
(str++, r <= RATING_POOR) || // Poor
|
|
|
|
(str++, r <= RATING_MEDIOCRE) || // Mediocore
|
|
|
|
(str++, r <= RATING_GOOD) || // Good
|
|
|
|
(str++, r <= RATING_VERYGOOD) || // Very Good
|
|
|
|
(str++, r <= RATING_EXCELLENT) || // Excellent
|
|
|
|
(str++, true); // Outstanding
|
|
|
|
|
|
|
|
SetDParam(2, str);
|
2008-09-30 20:39:50 +00:00
|
|
|
if (this->town->exclusivity == c->index) { // red icon for company with exclusive rights
|
2008-05-15 22:47:03 +00:00
|
|
|
DrawSprite(SPR_BLOT, PALETTE_TO_RED, 18, y);
|
2008-04-14 17:06:36 +00:00
|
|
|
}
|
2008-05-15 22:47:03 +00:00
|
|
|
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(this->widget[TWA_RATING_INFO].left + 28, this->widget[TWA_RATING_INFO].right - 2, y, STR_LOCAL_AUTHORITY_COMPANY_RATING);
|
2008-05-15 22:47:03 +00:00
|
|
|
y += 10;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-15 22:47:03 +00:00
|
|
|
}
|
2009-01-15 12:50:59 +00:00
|
|
|
|
|
|
|
if (y > this->widget[TWA_RATING_INFO].bottom) {
|
|
|
|
/* If the company list is too big to fit, mark ourself dirty and draw again. */
|
|
|
|
ResizeWindowForWidget(this, TWA_RATING_INFO, 0, y - this->widget[TWA_RATING_INFO].bottom);
|
|
|
|
this->SetDirty();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-15 12:36:24 +00:00
|
|
|
y = this->widget[TWA_COMMAND_LIST].top + 1;
|
2008-05-15 22:47:03 +00:00
|
|
|
int pos = this->vscroll.pos;
|
2004-08-23 21:12:51 +00:00
|
|
|
|
2008-05-15 22:47:03 +00:00
|
|
|
if (--pos < 0) {
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(this->widget[TWA_COMMAND_LIST].left + 2, this->widget[TWA_COMMAND_LIST].right - 2, y, STR_LOCAL_AUTHORITY_ACTIONS_TITLE);
|
2008-05-15 22:47:03 +00:00
|
|
|
y += 10;
|
|
|
|
}
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2008-05-15 22:47:03 +00:00
|
|
|
for (int i = 0; buttons; i++, buttons >>= 1) {
|
|
|
|
if (pos <= -5) break; ///< Draw only the 5 fitting lines
|
|
|
|
|
|
|
|
if ((buttons & 1) && --pos < 0) {
|
2009-04-21 23:40:56 +00:00
|
|
|
DrawString(this->widget[TWA_COMMAND_LIST].left + 3, this->widget[TWA_COMMAND_LIST].right - 2, y, STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i, TC_ORANGE);
|
2008-05-15 22:47:03 +00:00
|
|
|
y += 10;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-15 22:47:03 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2008-05-15 22:47:03 +00:00
|
|
|
if (this->sel_index != -1) {
|
|
|
|
SetDParam(1, (_price.build_industry >> 8) * _town_action_costs[this->sel_index]);
|
2009-04-21 23:40:56 +00:00
|
|
|
SetDParam(0, STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + this->sel_index);
|
|
|
|
DrawStringMultiLine(this->widget[TWA_ACTION_INFO].left + 2, this->widget[TWA_ACTION_INFO].right - 2, this->widget[TWA_ACTION_INFO].top + 1, this->widget[TWA_ACTION_INFO].bottom - 1, STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING + this->sel_index);
|
2008-05-15 22:47:03 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 22:47:03 +00:00
|
|
|
virtual void OnDoubleClick(Point pt, int widget) { HandleClick(pt, widget, true); }
|
|
|
|
virtual void OnClick(Point pt, int widget) { HandleClick(pt, widget, false); }
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2008-05-15 22:47:03 +00:00
|
|
|
void HandleClick(Point pt, int widget, bool double_click)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case TWA_COMMAND_LIST: {
|
2009-01-15 12:36:24 +00:00
|
|
|
int y = (pt.y - this->widget[TWA_COMMAND_LIST].top - 1) / 10;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 22:47:03 +00:00
|
|
|
if (!IsInsideMM(y, 0, 5)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
y = GetNthSetBit(GetMaskOfTownActions(NULL, _local_company, this->town), y + this->vscroll.pos - 1);
|
2008-05-15 22:47:03 +00:00
|
|
|
if (y >= 0) {
|
|
|
|
this->sel_index = y;
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
/* Fall through to clicking in case we are double-clicked */
|
|
|
|
if (!double_click || y < 0) break;
|
2008-04-14 17:06:36 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 22:47:03 +00:00
|
|
|
case TWA_EXECUTE:
|
2009-04-21 23:40:56 +00:00
|
|
|
DoCommandP(this->town->xy, this->window_number, this->sel_index, CMD_DO_TOWN_ACTION | CMD_MSG(STR_ERROR_CAN_T_DO_THIS));
|
2008-05-15 22:47:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-15 22:47:03 +00:00
|
|
|
|
|
|
|
virtual void OnHundredthTick()
|
|
|
|
{
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _town_authority_desc(
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 317, 222, 317, 222,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_TOWN_AUTHORITY, WC_NONE,
|
2004-08-09 17:04:08 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
2009-04-12 19:30:47 +00:00
|
|
|
_town_authority_widgets, _nested_town_authority_widgets, lengthof(_nested_town_authority_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-14 19:44:06 +00:00
|
|
|
static void ShowTownAuthorityWindow(uint town)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-05-15 22:47:03 +00:00
|
|
|
AllocateWindowDescFront<TownAuthorityWindow>(&_town_authority_desc, town);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-04-12 19:25:59 +00:00
|
|
|
/** Widget numbers of the town view window. */
|
|
|
|
enum TownViewWidgets {
|
|
|
|
TVW_CLOSEBOX,
|
|
|
|
TVW_CAPTION,
|
|
|
|
TVW_STICKY,
|
|
|
|
TVW_VIEWPORTPANEL,
|
|
|
|
TVW_VIEWPORTINSET,
|
|
|
|
TVW_INFOPANEL,
|
|
|
|
TVW_CENTERVIEW,
|
|
|
|
TVW_SHOWAUTHORITY,
|
|
|
|
TVW_CHANGENAME,
|
|
|
|
TVW_EXPAND,
|
|
|
|
TVW_DELETE,
|
|
|
|
};
|
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
struct TownViewWindow : Window {
|
2008-05-22 02:03:05 +00:00
|
|
|
private:
|
2008-05-22 02:13:24 +00:00
|
|
|
Town *town;
|
2008-05-22 02:03:05 +00:00
|
|
|
|
|
|
|
public:
|
2009-02-23 20:03:38 +00:00
|
|
|
enum {
|
|
|
|
TVW_HEIGHT_NORMAL = 150,
|
|
|
|
};
|
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
TownViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
this->town = Town::Get(this->window_number);
|
2008-05-22 02:13:24 +00:00
|
|
|
bool ingame = _game_mode != GM_EDITOR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
this->flags4 |= WF_DISABLE_VP_SCROLL;
|
2009-04-12 15:30:16 +00:00
|
|
|
int width = this->widget[TVW_VIEWPORTINSET].right - this->widget[TVW_VIEWPORTINSET].left - 1;
|
|
|
|
int height = this->widget[TVW_VIEWPORTINSET].bottom - this->widget[TVW_VIEWPORTINSET].top - 1;
|
|
|
|
InitializeWindowViewport(this, this->widget[TVW_VIEWPORTINSET].left + 1, this->widget[TVW_VIEWPORTINSET].top + 1, width, height, this->town->xy, ZOOM_LVL_TOWN);
|
2008-05-18 08:13:13 +00:00
|
|
|
|
2009-04-21 23:40:56 +00:00
|
|
|
if (this->town->larger_town) this->widget[TVW_CAPTION].data = STR_TOWN_VIEW_CITY_CAPTION;
|
2008-05-18 08:13:13 +00:00
|
|
|
|
|
|
|
if (ingame) {
|
2009-04-12 17:47:33 +00:00
|
|
|
/* Hide the expand button, and put the authority button over it. */
|
|
|
|
this->HideWidget(TVW_EXPAND);
|
|
|
|
this->widget[TVW_SHOWAUTHORITY].right = this->widget[TVW_EXPAND].right;
|
|
|
|
/* Resize caption bar */
|
2008-05-18 08:13:13 +00:00
|
|
|
this->widget[TVW_CAPTION].right = this->widget[TVW_STICKY].left -1;
|
2009-04-12 17:47:33 +00:00
|
|
|
/* Hide the delete button, and move the rename button from top on scenario to bottom in game. */
|
|
|
|
this->HideWidget(TVW_DELETE);
|
2008-05-18 08:13:13 +00:00
|
|
|
this->widget[TVW_CHANGENAME].top = this->widget[TVW_EXPAND].top;
|
|
|
|
this->widget[TVW_CHANGENAME].bottom = this->widget[TVW_EXPAND].bottom;
|
|
|
|
this->widget[TVW_CHANGENAME].right = this->widget[TVW_STICKY].right;
|
2009-04-12 17:47:33 +00:00
|
|
|
} else {
|
|
|
|
/* Hide the authority button, and put the expand button over it. */
|
|
|
|
this->HideWidget(TVW_SHOWAUTHORITY);
|
|
|
|
this->widget[TVW_EXPAND].left = this->widget[TVW_SHOWAUTHORITY].left;
|
2008-05-18 08:13:13 +00:00
|
|
|
}
|
2008-05-19 01:50:07 +00:00
|
|
|
|
2009-02-23 20:03:38 +00:00
|
|
|
this->ResizeWindowAsNeeded();
|
2008-05-24 02:54:47 +00:00
|
|
|
|
2008-05-19 01:50:07 +00:00
|
|
|
this->FindWindowPlacementAndResize(desc);
|
2008-05-18 08:13:13 +00:00
|
|
|
}
|
2008-03-22 11:27:46 +00:00
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
/* disable renaming town in network games if you are not the server */
|
|
|
|
this->SetWidgetDisabledState(TVW_CHANGENAME, _networking && !_network_server);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2008-05-22 02:13:24 +00:00
|
|
|
SetDParam(0, this->town->index);
|
2008-05-18 08:13:13 +00:00
|
|
|
this->DrawWidgets();
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2009-02-23 20:03:38 +00:00
|
|
|
uint y = 107;
|
|
|
|
|
2008-05-22 02:13:24 +00:00
|
|
|
SetDParam(0, this->town->population);
|
|
|
|
SetDParam(1, this->town->num_houses);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(2, this->width - 2, y, STR_TOWN_VIEW_POPULATION_HOUSES);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-22 02:13:24 +00:00
|
|
|
SetDParam(0, this->town->act_pass);
|
|
|
|
SetDParam(1, this->town->max_pass);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(2, this->width - 2, y += 10, STR_TOWN_VIEW_PASSENGERS_LAST_MONTH_MAX);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2008-05-22 02:13:24 +00:00
|
|
|
SetDParam(0, this->town->act_mail);
|
|
|
|
SetDParam(1, this->town->max_mail);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(2, this->width - 2, y += 10, STR_TOWN_VIEW_MAIL_LAST_MONTH_MAX);
|
2009-02-23 20:03:38 +00:00
|
|
|
|
|
|
|
uint cargo_needed_for_growth = 0;
|
|
|
|
switch (_settings_game.game_creation.landscape) {
|
|
|
|
case LT_ARCTIC:
|
|
|
|
if (TilePixelHeight(this->town->xy) >= LowestSnowLine()) cargo_needed_for_growth = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_TROPIC:
|
|
|
|
if (GetTropicZone(this->town->xy) == TROPICZONE_DESERT) cargo_needed_for_growth = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cargo_needed_for_growth > 0) {
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(2, this->width - 2, y += 10, STR_CARGO_FOR_TOWNGROWTH);
|
2009-02-23 20:03:38 +00:00
|
|
|
|
|
|
|
CargoID first_food_cargo = CT_INVALID;
|
2009-04-21 23:40:56 +00:00
|
|
|
StringID food_name = STR_CARGO_PLURAL_FOOD;
|
2009-02-23 20:03:38 +00:00
|
|
|
CargoID first_water_cargo = CT_INVALID;
|
2009-04-21 23:40:56 +00:00
|
|
|
StringID water_name = STR_CARGO_PLURAL_WATER;
|
2009-02-23 20:03:38 +00:00
|
|
|
for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
|
|
|
|
const CargoSpec *cs = GetCargo(cid);
|
|
|
|
if (first_food_cargo == CT_INVALID && cs->town_effect == TE_FOOD) {
|
|
|
|
first_food_cargo = cid;
|
|
|
|
food_name = cs->name;
|
|
|
|
}
|
|
|
|
if (first_water_cargo == CT_INVALID && cs->town_effect == TE_WATER) {
|
|
|
|
first_water_cargo = cid;
|
|
|
|
water_name = cs->name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (first_food_cargo != CT_INVALID && this->town->act_food > 0) {
|
|
|
|
SetDParam(0, first_food_cargo);
|
|
|
|
SetDParam(1, this->town->act_food);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(2, this->width - 2, y += 10, STR_CARGO_FOR_TOWNGROWTH_LAST_MONTH);
|
2009-02-23 20:03:38 +00:00
|
|
|
} else {
|
|
|
|
SetDParam(0, food_name);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(2, this->width - 2, y += 10, STR_CARGO_FOR_TOWNGROWTH_REQUIRED);
|
2009-02-23 20:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cargo_needed_for_growth > 1) {
|
|
|
|
if (first_water_cargo != CT_INVALID && this->town->act_water > 0) {
|
|
|
|
SetDParam(0, first_water_cargo);
|
|
|
|
SetDParam(1, this->town->act_water);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(2, this->width - 2, y += 10, STR_CARGO_FOR_TOWNGROWTH_LAST_MONTH);
|
2009-02-23 20:03:38 +00:00
|
|
|
} else {
|
|
|
|
SetDParam(0, water_name);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(2, this->width - 2, y += 10, STR_CARGO_FOR_TOWNGROWTH_REQUIRED);
|
2009-02-23 20:03:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
this->DrawViewport();
|
2008-05-24 02:54:47 +00:00
|
|
|
|
|
|
|
/* only show the town noise, if the noise option is activated. */
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.economy.station_noise_level) {
|
2008-05-24 02:54:47 +00:00
|
|
|
SetDParam(0, this->town->noise_reached);
|
|
|
|
SetDParam(1, this->town->MaxTownNoise());
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(2, this->width - 2, y += 10, STR_NOISE_IN_TOWN);
|
2008-05-24 02:54:47 +00:00
|
|
|
}
|
2008-05-18 08:13:13 +00:00
|
|
|
}
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2009-03-15 00:32:18 +00:00
|
|
|
case TVW_CENTERVIEW: // scroll to location
|
2008-05-18 08:13:13 +00:00
|
|
|
if (_ctrl_pressed) {
|
2008-05-22 02:13:24 +00:00
|
|
|
ShowExtraViewPortWindow(this->town->xy);
|
2008-05-18 08:13:13 +00:00
|
|
|
} else {
|
2008-05-22 02:13:24 +00:00
|
|
|
ScrollMainWindowToTile(this->town->xy);
|
2008-05-18 08:13:13 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2009-04-12 06:01:24 +00:00
|
|
|
case TVW_SHOWAUTHORITY: // town authority
|
2008-05-18 08:13:13 +00:00
|
|
|
ShowTownAuthorityWindow(this->window_number);
|
|
|
|
break;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case TVW_CHANGENAME: // rename
|
2008-05-18 08:13:13 +00:00
|
|
|
SetDParam(0, this->window_number);
|
2009-04-21 23:40:56 +00:00
|
|
|
ShowQueryString(STR_TOWN, STR_TOWN_VIEW_RENAME_TOWN_BUTTON, MAX_LENGTH_TOWN_NAME_BYTES, MAX_LENGTH_TOWN_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
|
2008-05-18 08:13:13 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case TVW_EXPAND: // expand town - only available on Scenario editor
|
2008-05-22 02:13:24 +00:00
|
|
|
ExpandTown(this->town);
|
2008-05-18 08:13:13 +00:00
|
|
|
break;
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case TVW_DELETE: // delete town - only available on Scenario editor
|
2008-05-22 02:13:24 +00:00
|
|
|
delete this->town;
|
2008-05-18 08:13:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-18 08:13:13 +00:00
|
|
|
|
2009-02-23 20:03:38 +00:00
|
|
|
void ResizeWindowAsNeeded()
|
|
|
|
{
|
|
|
|
int aimed_height = TVW_HEIGHT_NORMAL;
|
|
|
|
|
|
|
|
switch (_settings_game.game_creation.landscape) {
|
|
|
|
case LT_ARCTIC:
|
|
|
|
if (TilePixelHeight(this->town->xy) >= LowestSnowLine()) aimed_height += 20;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_TROPIC:
|
|
|
|
if (GetTropicZone(this->town->xy) == TROPICZONE_DESERT) aimed_height += 30;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_settings_game.economy.station_noise_level) aimed_height += 10;
|
|
|
|
|
|
|
|
if (this->height != aimed_height) ResizeWindowForWidget(this, TVW_INFOPANEL, 0, aimed_height - this->height);
|
|
|
|
}
|
|
|
|
|
2008-05-24 02:54:47 +00:00
|
|
|
virtual void OnInvalidateData(int data = 0)
|
|
|
|
{
|
|
|
|
/* Called when setting station noise have changed, in order to resize the window */
|
|
|
|
this->SetDirty(); // refresh display for current size. This will allow to avoid glitches when downgrading
|
2009-02-23 20:03:38 +00:00
|
|
|
this->ResizeWindowAsNeeded();
|
2008-05-24 02:54:47 +00:00
|
|
|
}
|
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
virtual void OnQueryTextFinished(char *str)
|
|
|
|
{
|
2008-09-15 19:02:50 +00:00
|
|
|
if (str == NULL) return;
|
|
|
|
|
2009-04-21 23:40:56 +00:00
|
|
|
DoCommandP(0, this->window_number, 0, CMD_RENAME_TOWN | CMD_MSG(STR_ERROR_CAN_T_RENAME_TOWN), NULL, str);
|
2008-05-18 08:13:13 +00:00
|
|
|
}
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
static const Widget _town_view_widgets[] = {
|
2009-04-21 23:40:56 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_BROWN, 0, 10, 0, 13, STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW}, // TVW_CLOSEBOX
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, COLOUR_BROWN, 11, 171, 0, 13, STR_TOWN_VIEW_TOWN_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS}, // TVW_CAPTION
|
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, COLOUR_BROWN, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON}, // TVW_STICKY
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, COLOUR_BROWN, 0, 259, 14, 105, 0x0, STR_NULL}, // TVW_VIEWPORTPANEL
|
|
|
|
{ WWT_INSET, RESIZE_NONE, COLOUR_BROWN, 2, 257, 16, 103, 0x0, STR_NULL}, // TVW_VIEWPORTINSET
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, COLOUR_BROWN, 0, 259, 106, 137, 0x0, STR_NULL}, // TVW_INFOPANEL
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_BROWN, 0, 85, 138, 149, STR_BUTTON_LOCATION, STR_TOWN_VIEW_CENTER_TOOLTIP}, // TVW_CENTERVIEW
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_BROWN, 86, 127, 138, 149, STR_TOWN_VIEW_LOCAL_AUTHORITY_BUTTON, STR_TOWN_VIEW_LOCAL_AUTHORITY_TOOLTIP}, // TVW_SHOWAUTHORITY
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_BROWN, 172, 247, 0, 13, STR_QUERY_RENAME, STR_TOWN_VIEW_RENAME_TOOLTIP}, // TVW_CHANGENAME
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_BROWN, 128, 171, 138, 149, STR_TOWN_VIEW_EXPAND_BUTTON, STR_TOWN_VIEW_EXPAND_TOOLTIP}, // TVW_EXPAND
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_BROWN, 172, 259, 138, 149, STR_TOWN_VIEW_DELETE_BUTTON, STR_TOWN_VIEW_DELETE_TOOLTIP}, // TVW_DELETE
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2009-04-12 19:30:47 +00:00
|
|
|
static const NWidgetPart _nested_town_view_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_BROWN, TVW_CLOSEBOX),
|
2009-04-21 23:40:56 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_BROWN, TVW_CAPTION), SetDataTip(STR_TOWN_VIEW_TOWN_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, TVW_CHANGENAME), SetMinimalSize(76, 14), SetDataTip(STR_QUERY_RENAME, STR_TOWN_VIEW_RENAME_TOOLTIP),
|
2009-04-12 19:30:47 +00:00
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_BROWN, TVW_STICKY),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_BROWN, TVW_VIEWPORTPANEL),
|
|
|
|
NWidget(WWT_INSET, COLOUR_BROWN, TVW_VIEWPORTINSET), SetMinimalSize(256, 88), SetPadding(2, 2, 2, 2), EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_BROWN, TVW_INFOPANEL), SetMinimalSize(260, 32), EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-04-21 23:40:56 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, TVW_CENTERVIEW), SetMinimalSize(86, 12), SetDataTip(STR_BUTTON_LOCATION, STR_TOWN_VIEW_CENTER_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, TVW_SHOWAUTHORITY), SetMinimalSize(42, 12), SetDataTip(STR_TOWN_VIEW_LOCAL_AUTHORITY_BUTTON, STR_TOWN_VIEW_LOCAL_AUTHORITY_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, TVW_EXPAND), SetMinimalSize(44, 12), SetDataTip(STR_TOWN_VIEW_EXPAND_BUTTON, STR_TOWN_VIEW_EXPAND_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, TVW_DELETE), SetMinimalSize(88, 12), SetDataTip(STR_TOWN_VIEW_DELETE_BUTTON, STR_TOWN_VIEW_DELETE_TOOLTIP),
|
2009-04-12 19:30:47 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _town_view_desc(
|
2009-02-23 20:03:38 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 260, TownViewWindow::TVW_HEIGHT_NORMAL, 260, TownViewWindow::TVW_HEIGHT_NORMAL,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_TOWN_VIEW, WC_NONE,
|
2004-12-22 01:32:30 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
|
2009-04-12 19:30:47 +00:00
|
|
|
_town_view_widgets, _nested_town_view_widgets, lengthof(_nested_town_view_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-26 22:58:11 +00:00
|
|
|
void ShowTownViewWindow(TownID town)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-05-18 08:13:13 +00:00
|
|
|
AllocateWindowDescFront<TownViewWindow>(&_town_view_desc, town);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-04-12 19:25:59 +00:00
|
|
|
/** Widget numbers of town directory window. */
|
|
|
|
enum TownDirectoryWidgets {
|
|
|
|
TDW_CLOSEBOX,
|
|
|
|
TDW_CAPTION,
|
|
|
|
TDW_STICKYBOX,
|
|
|
|
TDW_SORTNAME,
|
|
|
|
TDW_SORTPOPULATION,
|
|
|
|
TDW_CENTERTOWN,
|
|
|
|
TDW_SCROLLBAR,
|
|
|
|
TDW_EMPTYBOTTOM,
|
|
|
|
TDW_RESIZEBOX,
|
|
|
|
};
|
|
|
|
|
2009-04-12 19:30:47 +00:00
|
|
|
static const NWidgetPart _nested_town_directory_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_BROWN, TDW_CLOSEBOX),
|
2009-04-21 23:40:56 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_BROWN, TDW_CAPTION), SetDataTip(STR_TOWN_DIRECTORY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-04-12 19:30:47 +00:00
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_BROWN, TDW_STICKYBOX),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-07-03 22:25:59 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, TDW_SORTNAME), SetMinimalSize(99, 12), SetDataTip(STR_SORT_BY_NAME, STR_SORT_ORDER_TIP), SetFill(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, TDW_SORTPOPULATION), SetMinimalSize(97, 12), SetDataTip(STR_SORT_BY_POPULATION, STR_SORT_ORDER_TIP), SetFill(1, 0),
|
2009-04-12 19:30:47 +00:00
|
|
|
EndContainer(),
|
2009-04-21 23:40:56 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_BROWN, TDW_CENTERTOWN), SetMinimalSize(196, 164), SetDataTip(0x0, STR_TOWN_DIRECTORY_LIST_TOOLTIP),
|
2009-07-03 22:25:59 +00:00
|
|
|
SetFill(1, 0), SetResize(0, 10), EndContainer(),
|
2009-04-12 19:30:47 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_SCROLLBAR, COLOUR_BROWN, TDW_SCROLLBAR),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-07-03 22:25:59 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_BROWN, TDW_EMPTYBOTTOM), SetMinimalSize(196, 12), SetFill(1, 0), EndContainer(),
|
2009-04-12 19:30:47 +00:00
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_BROWN, TDW_RESIZEBOX),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-06-28 21:23:37 +00:00
|
|
|
/** Town directory window class. */
|
2008-05-27 20:05:36 +00:00
|
|
|
struct TownDirectoryWindow : public Window {
|
|
|
|
private:
|
|
|
|
/* Runtime saved values */
|
|
|
|
static Listing last_sorting;
|
|
|
|
static const Town *last_town;
|
2009-06-28 21:23:37 +00:00
|
|
|
int townline_height; ///< Height of a single town line in the town directory window.
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-27 20:05:36 +00:00
|
|
|
/* Constants for sorting towns */
|
2008-05-27 21:41:00 +00:00
|
|
|
static GUITownList::SortFunction * const sorter_funcs[];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-27 20:05:36 +00:00
|
|
|
GUITownList towns;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-07-03 21:38:41 +00:00
|
|
|
void BuildSortTownList()
|
2008-05-27 20:05:36 +00:00
|
|
|
{
|
2009-07-03 21:38:41 +00:00
|
|
|
if (this->towns.NeedRebuild()) {
|
|
|
|
this->towns.Clear();
|
2005-01-06 22:31:58 +00:00
|
|
|
|
2009-07-03 21:38:41 +00:00
|
|
|
const Town *t;
|
|
|
|
FOR_ALL_TOWNS(t) {
|
|
|
|
*this->towns.Append() = t;
|
|
|
|
}
|
2005-01-06 22:31:58 +00:00
|
|
|
|
2009-07-03 21:38:41 +00:00
|
|
|
this->towns.Compact();
|
|
|
|
this->towns.RebuildDone();
|
|
|
|
SetVScrollCount(this, this->towns.Length()); // Update scrollbar as well.
|
2008-05-27 20:05:36 +00:00
|
|
|
}
|
2009-07-03 21:38:41 +00:00
|
|
|
/* Always sort the towns. */
|
2008-05-27 20:05:36 +00:00
|
|
|
last_town = NULL;
|
|
|
|
this->towns.Sort();
|
|
|
|
}
|
2004-08-16 14:48:35 +00:00
|
|
|
|
2008-05-27 20:05:36 +00:00
|
|
|
/** Sort by town name */
|
|
|
|
static int CDECL TownNameSorter(const Town * const *a, const Town * const *b)
|
|
|
|
{
|
|
|
|
static char buf_cache[64];
|
|
|
|
const Town *ta = *a;
|
|
|
|
const Town *tb = *b;
|
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
SetDParam(0, ta->index);
|
|
|
|
GetString(buf, STR_TOWN, lastof(buf));
|
|
|
|
|
|
|
|
/* If 'b' is the same town as in the last round, use the cached value
|
|
|
|
* We do this to speed stuff up ('b' is called with the same value a lot of
|
|
|
|
* times after eachother) */
|
|
|
|
if (tb != last_town) {
|
|
|
|
last_town = tb;
|
|
|
|
SetDParam(0, tb->index);
|
|
|
|
GetString(buf_cache, STR_TOWN, lastof(buf_cache));
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-27 20:05:36 +00:00
|
|
|
return strcmp(buf, buf_cache);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-27 20:05:36 +00:00
|
|
|
/** Sort by population */
|
|
|
|
static int CDECL TownPopulationSorter(const Town * const *a, const Town * const *b)
|
|
|
|
{
|
|
|
|
return (*a)->population - (*b)->population;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-22 02:03:05 +00:00
|
|
|
public:
|
2009-06-04 14:34:38 +00:00
|
|
|
TownDirectoryWindow(const WindowDesc *desc) : Window()
|
2008-05-19 09:17:26 +00:00
|
|
|
{
|
2008-05-27 20:05:36 +00:00
|
|
|
this->towns.SetListing(this->last_sorting);
|
|
|
|
this->towns.SetSortFuncs(this->sorter_funcs);
|
|
|
|
this->towns.ForceRebuild();
|
2009-07-03 21:38:41 +00:00
|
|
|
this->BuildSortTownList();
|
2009-07-04 14:13:23 +00:00
|
|
|
|
|
|
|
this->townline_height = FONT_HEIGHT_NORMAL;
|
|
|
|
this->InitNested(desc, 0);
|
|
|
|
this->vscroll.cap = this->nested_array[TDW_CENTERTOWN]->current_y / this->resize.step_height;
|
2008-05-19 09:17:26 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2008-05-27 20:05:36 +00:00
|
|
|
~TownDirectoryWindow()
|
|
|
|
{
|
|
|
|
this->last_sorting = this->towns.GetListing();
|
|
|
|
}
|
|
|
|
|
2008-05-19 09:17:26 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
this->DrawWidgets();
|
2009-06-28 22:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
switch(widget) {
|
|
|
|
case TDW_SORTNAME:
|
|
|
|
if (this->towns.SortType() == 0) this->DrawSortButtonState(widget, this->towns.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
|
|
|
|
break;
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2009-06-28 22:23:26 +00:00
|
|
|
case TDW_SORTPOPULATION:
|
|
|
|
if (this->towns.SortType() != 0) this->DrawSortButtonState(widget, this->towns.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
|
|
|
|
break;
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2009-06-28 22:23:26 +00:00
|
|
|
case TDW_CENTERTOWN: {
|
|
|
|
int n = 0;
|
|
|
|
int y = r.top + 2;
|
|
|
|
for (uint i = this->vscroll.pos; i < this->towns.Length(); i++) {
|
|
|
|
const Town *t = this->towns[i];
|
2008-05-19 09:17:26 +00:00
|
|
|
|
2009-06-28 22:23:26 +00:00
|
|
|
assert(t->xy != INVALID_TILE);
|
2008-05-19 09:17:26 +00:00
|
|
|
|
2009-06-28 22:23:26 +00:00
|
|
|
SetDParam(0, t->index);
|
|
|
|
SetDParam(1, t->population);
|
|
|
|
DrawString(r.left + 2, r.right - 2, y, STR_TOWN_DIRECTORY_TOWN);
|
2008-05-19 09:17:26 +00:00
|
|
|
|
2009-06-28 22:23:26 +00:00
|
|
|
y += this->townline_height;
|
|
|
|
if (++n == this->vscroll.cap) break; // max number of towns in 1 window
|
|
|
|
}
|
|
|
|
} break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-06-28 22:23:26 +00:00
|
|
|
case TDW_EMPTYBOTTOM:
|
|
|
|
SetDParam(0, GetWorldPopulation());
|
|
|
|
DrawString(r.left + 3, r.right - 3, r.top + 2, STR_TOWN_POPULATION);
|
|
|
|
break;
|
2008-05-19 09:17:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-04 15:35:36 +00:00
|
|
|
virtual Dimension GetWidgetContentSize(int widget)
|
|
|
|
{
|
|
|
|
Dimension d = {0, 0};
|
|
|
|
switch (widget) {
|
2009-07-15 23:04:26 +00:00
|
|
|
case TDW_SORTNAME:
|
2009-07-04 15:35:36 +00:00
|
|
|
case TDW_SORTPOPULATION: {
|
2009-07-15 23:04:26 +00:00
|
|
|
d = GetStringBoundingBox(this->nested_array[widget]->widget_data);
|
2009-07-04 15:35:36 +00:00
|
|
|
d.width += WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the word is centered, also looks nice.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TDW_CENTERTOWN:
|
|
|
|
for (uint i = 0; i < this->towns.Length(); i++) {
|
|
|
|
const Town *t = this->towns[i];
|
|
|
|
|
|
|
|
assert(t != NULL);
|
|
|
|
|
|
|
|
SetDParam(0, t->index);
|
|
|
|
SetDParam(1, 10000000); // 10^7
|
|
|
|
d = maxdim(d, GetStringBoundingBox(STR_TOWN_DIRECTORY_TOWN));
|
|
|
|
}
|
|
|
|
d.width += 2 + 2; // Text is rendered with 2 pixel offset at both sides.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TDW_EMPTYBOTTOM:
|
|
|
|
SetDParam(0, 1000000000); // 10^9
|
|
|
|
d = GetStringBoundingBox(STR_TOWN_POPULATION);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2008-05-19 09:17:26 +00:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2009-03-15 00:32:18 +00:00
|
|
|
case TDW_SORTNAME: // Sort by Name ascending/descending
|
2008-05-27 20:05:36 +00:00
|
|
|
if (this->towns.SortType() == 0) {
|
|
|
|
this->towns.ToggleSortOrder();
|
|
|
|
} else {
|
|
|
|
this->towns.SetSortType(0);
|
|
|
|
}
|
2009-07-03 21:38:41 +00:00
|
|
|
this->BuildSortTownList();
|
2008-05-19 09:17:26 +00:00
|
|
|
this->SetDirty();
|
|
|
|
break;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case TDW_SORTPOPULATION: // Sort by Population ascending/descending
|
2008-05-27 20:05:36 +00:00
|
|
|
if (this->towns.SortType() == 1) {
|
|
|
|
this->towns.ToggleSortOrder();
|
|
|
|
} else {
|
|
|
|
this->towns.SetSortType(1);
|
|
|
|
}
|
2009-07-03 21:38:41 +00:00
|
|
|
this->BuildSortTownList();
|
2008-05-19 09:17:26 +00:00
|
|
|
this->SetDirty();
|
|
|
|
break;
|
2006-08-15 07:07:17 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case TDW_CENTERTOWN: { // Click on Town Matrix
|
2009-06-28 21:23:37 +00:00
|
|
|
uint16 id_v = (pt.y - this->nested_array[widget]->pos_y - 2) / this->townline_height;
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2008-05-19 09:17:26 +00:00
|
|
|
if (id_v >= this->vscroll.cap) return; // click out of bounds
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2008-05-19 09:17:26 +00:00
|
|
|
id_v += this->vscroll.pos;
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2008-05-27 20:05:36 +00:00
|
|
|
if (id_v >= this->towns.Length()) return; // click out of town bounds
|
2008-04-14 17:06:36 +00:00
|
|
|
|
2008-05-27 20:05:36 +00:00
|
|
|
const Town *t = this->towns[id_v];
|
2009-07-04 15:35:36 +00:00
|
|
|
assert(t != NULL);
|
2008-05-19 09:17:26 +00:00
|
|
|
if (_ctrl_pressed) {
|
|
|
|
ShowExtraViewPortWindow(t->xy);
|
|
|
|
} else {
|
|
|
|
ScrollMainWindowToTile(t->xy);
|
|
|
|
}
|
|
|
|
break;
|
2008-04-14 17:06:36 +00:00
|
|
|
}
|
2008-05-19 09:17:26 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2008-05-19 09:17:26 +00:00
|
|
|
virtual void OnHundredthTick()
|
|
|
|
{
|
2009-07-03 21:38:41 +00:00
|
|
|
this->BuildSortTownList();
|
2008-05-19 09:17:26 +00:00
|
|
|
this->SetDirty();
|
|
|
|
}
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2009-03-29 09:49:11 +00:00
|
|
|
virtual void OnResize(Point delta)
|
2008-05-19 09:17:26 +00:00
|
|
|
{
|
2009-06-28 21:23:37 +00:00
|
|
|
this->vscroll.cap += delta.y / this->townline_height;
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2008-05-27 20:05:36 +00:00
|
|
|
|
|
|
|
virtual void OnInvalidateData(int data)
|
|
|
|
{
|
|
|
|
if (data == 0) {
|
|
|
|
this->towns.ForceRebuild();
|
|
|
|
} else {
|
|
|
|
this->towns.ForceResort();
|
|
|
|
}
|
2009-07-03 21:38:41 +00:00
|
|
|
this->BuildSortTownList();
|
2008-05-27 20:05:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Listing TownDirectoryWindow::last_sorting = {false, 0};
|
|
|
|
const Town *TownDirectoryWindow::last_town = NULL;
|
|
|
|
|
|
|
|
/* Available town directory sorting functions */
|
2008-05-27 21:41:00 +00:00
|
|
|
GUITownList::SortFunction * const TownDirectoryWindow::sorter_funcs[] = {
|
2008-05-27 20:05:36 +00:00
|
|
|
&TownNameSorter,
|
|
|
|
&TownPopulationSorter,
|
2008-05-19 09:17:26 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _town_directory_desc(
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 208, 202, 208, 202,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_TOWN_DIRECTORY, WC_NONE,
|
2005-01-03 19:45:18 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
2009-06-04 14:34:38 +00:00
|
|
|
NULL, _nested_town_directory_widgets, lengthof(_nested_town_directory_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void ShowTownDirectory()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-05-25 15:57:45 +00:00
|
|
|
if (BringWindowToFrontById(WC_TOWN_DIRECTORY, 0)) return;
|
2008-05-19 09:17:26 +00:00
|
|
|
new TownDirectoryWindow(&_town_directory_desc);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-03-23 07:35:29 +00:00
|
|
|
|
|
|
|
void CcBuildTown(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
|
|
|
{
|
|
|
|
if (success) {
|
|
|
|
SndPlayTileFx(SND_1F_SPLAT, tile);
|
2009-01-07 17:40:17 +00:00
|
|
|
if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
|
2008-03-23 07:35:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-12 19:25:59 +00:00
|
|
|
/** Widget numbers of town scenario editor window. */
|
|
|
|
enum TownScenarioEditorWidgets {
|
|
|
|
TSEW_CLOSEBOX,
|
|
|
|
TSEW_CAPTION,
|
|
|
|
TSEW_STICKYBOX,
|
|
|
|
TSEW_BACKGROUND,
|
|
|
|
TSEW_NEWTOWN,
|
|
|
|
TSEW_RANDOMTOWN,
|
|
|
|
TSEW_MANYRANDOMTOWNS,
|
|
|
|
TSEW_TOWNSIZE,
|
|
|
|
TSEW_SIZE_SMALL,
|
|
|
|
TSEW_SIZE_MEDIUM,
|
|
|
|
TSEW_SIZE_LARGE,
|
|
|
|
TSEW_SIZE_RANDOM,
|
|
|
|
TSEW_CITY,
|
|
|
|
TSEW_TOWNLAYOUT,
|
|
|
|
TSEW_LAYOUT_ORIGINAL,
|
|
|
|
TSEW_LAYOUT_BETTER,
|
|
|
|
TSEW_LAYOUT_GRID2,
|
|
|
|
TSEW_LAYOUT_GRID3,
|
|
|
|
TSEW_LAYOUT_RANDOM,
|
|
|
|
};
|
|
|
|
|
2009-04-12 19:30:47 +00:00
|
|
|
static const NWidgetPart _nested_found_town_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN, TSEW_CLOSEBOX),
|
2009-04-21 23:40:56 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, TSEW_CAPTION), SetDataTip(STR_FOUND_TOWN_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-04-12 19:30:47 +00:00
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN, TSEW_STICKYBOX),
|
|
|
|
EndContainer(),
|
|
|
|
/* Construct new town(s) buttons. */
|
|
|
|
NWidget(WWT_PANEL, COLOUR_DARK_GREEN, TSEW_BACKGROUND),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 2),
|
2009-07-03 22:25:59 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, TSEW_NEWTOWN), SetMinimalSize(156, 12), SetFill(1, 0),
|
|
|
|
SetDataTip(STR_FOUND_TOWN_NEW_TOWN_BUTTON, STR_FOUND_TOWN_NEW_TOWN_TOOLTIP), SetPadding(0, 2, 1, 2),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, TSEW_RANDOMTOWN), SetMinimalSize(156, 12), SetFill(1, 0),
|
2009-04-21 23:40:56 +00:00
|
|
|
SetDataTip(STR_FOUND_TOWN_RANDOM_TOWN_BUTTON, STR_FOUND_TOWN_RANDOM_TOWN_TOOLTIP), SetPadding(0, 2, 1, 2),
|
2009-07-03 22:25:59 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, TSEW_MANYRANDOMTOWNS), SetMinimalSize(156, 12), SetFill(1, 0),
|
|
|
|
SetDataTip(STR_MANY_RANDOM_TOWNS, STR_RANDOM_TOWNS_TIP), SetPadding(0, 2, 0, 2),
|
2009-04-12 19:30:47 +00:00
|
|
|
/* Town size selection. */
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-07-03 22:25:59 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
2009-04-21 23:40:56 +00:00
|
|
|
NWidget(WWT_LABEL, COLOUR_DARK_GREEN, TSEW_TOWNSIZE), SetMinimalSize(148, 14), SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_TITLE, STR_NULL),
|
2009-04-12 19:30:47 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
|
|
|
EndContainer(),
|
2009-07-03 22:25:59 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(2, 0, 2),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, TSEW_SIZE_SMALL), SetMinimalSize(78, 12), SetFill(1, 0),
|
|
|
|
SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_SMALL_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, TSEW_SIZE_MEDIUM), SetMinimalSize(78, 12), SetFill(1, 0),
|
|
|
|
SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_MEDIUM_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
|
2009-04-12 19:30:47 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 1),
|
2009-07-03 22:25:59 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(2, 0, 2),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, TSEW_SIZE_LARGE), SetMinimalSize(78, 12), SetFill(1, 0),
|
|
|
|
SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_LARGE_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, TSEW_SIZE_RANDOM), SetMinimalSize(78, 12), SetFill(1, 0),
|
|
|
|
SetDataTip(STR_SELECT_TOWN_SIZE_RANDOM, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
|
2009-04-12 19:30:47 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 3),
|
2009-07-03 22:25:59 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, TSEW_CITY), SetPadding(0, 2, 0, 2), SetMinimalSize(156, 12), SetFill(1, 0),
|
2009-04-12 19:30:47 +00:00
|
|
|
SetDataTip(STR_FOUND_TOWN_CITY, STR_FOUND_TOWN_CITY_TOOLTIP), SetFill(1, 0),
|
|
|
|
/* Town roads selection. */
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-07-03 22:25:59 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
2009-04-12 19:30:47 +00:00
|
|
|
NWidget(WWT_LABEL, COLOUR_DARK_GREEN, TSEW_TOWNLAYOUT), SetMinimalSize(148, 14), SetDataTip(STR_TOWN_ROAD_LAYOUT, STR_NULL),
|
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
|
|
|
EndContainer(),
|
2009-07-03 22:25:59 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(2, 0, 2),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, TSEW_LAYOUT_ORIGINAL), SetMinimalSize(78, 12), SetFill(1, 0), SetDataTip(STR_SELECT_LAYOUT_ORIGINAL, STR_SELECT_TOWN_ROAD_LAYOUT),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, TSEW_LAYOUT_BETTER), SetMinimalSize(78, 12), SetFill(1, 0), SetDataTip(STR_SELECT_LAYOUT_BETTER_ROADS, STR_SELECT_TOWN_ROAD_LAYOUT),
|
2009-04-12 19:30:47 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 1),
|
2009-07-03 22:25:59 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(2, 0, 2),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, TSEW_LAYOUT_GRID2), SetMinimalSize(78, 12), SetFill(1, 0), SetDataTip(STR_SELECT_LAYOUT_2X2_GRID, STR_SELECT_TOWN_ROAD_LAYOUT),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, TSEW_LAYOUT_GRID3), SetMinimalSize(78, 12), SetFill(1, 0), SetDataTip(STR_SELECT_LAYOUT_3X3_GRID, STR_SELECT_TOWN_ROAD_LAYOUT),
|
2009-04-12 19:30:47 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 1),
|
2009-07-16 10:13:33 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, TSEW_LAYOUT_RANDOM), SetPadding(0, 2, 0, 2), SetMinimalSize(0, 12), SetFill(1, 0),
|
2009-04-12 19:30:47 +00:00
|
|
|
SetDataTip(STR_SELECT_LAYOUT_RANDOM, STR_SELECT_TOWN_ROAD_LAYOUT), SetFill(1, 0),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 2),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-06-28 21:23:37 +00:00
|
|
|
/** Found a town window class. */
|
2009-02-17 00:21:08 +00:00
|
|
|
struct FoundTownWindow : Window
|
2008-03-23 07:35:29 +00:00
|
|
|
{
|
2008-05-22 02:03:05 +00:00
|
|
|
private:
|
2009-02-05 15:59:40 +00:00
|
|
|
static TownSize town_size;
|
|
|
|
static bool city;
|
|
|
|
static TownLayout town_layout;
|
|
|
|
|
2008-05-22 02:03:05 +00:00
|
|
|
public:
|
2009-06-10 20:48:22 +00:00
|
|
|
FoundTownWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
|
2008-05-18 08:13:13 +00:00
|
|
|
{
|
2009-06-10 20:48:22 +00:00
|
|
|
this->InitNested(desc, window_number);
|
2009-02-05 15:59:40 +00:00
|
|
|
town_layout = _settings_game.economy.town_layout;
|
|
|
|
city = false;
|
2009-02-05 16:51:23 +00:00
|
|
|
this->UpdateButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateButtons()
|
|
|
|
{
|
|
|
|
for (int i = TSEW_SIZE_SMALL; i <= TSEW_SIZE_RANDOM; i++) {
|
|
|
|
this->SetWidgetLoweredState(i, i == TSEW_SIZE_SMALL + town_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->SetWidgetLoweredState(TSEW_CITY, city);
|
|
|
|
|
|
|
|
for (int i = TSEW_LAYOUT_ORIGINAL; i <= TSEW_LAYOUT_RANDOM; i++) {
|
|
|
|
this->SetWidgetLoweredState(i, i == TSEW_LAYOUT_ORIGINAL + town_layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->SetDirty();
|
2008-05-18 08:13:13 +00:00
|
|
|
}
|
2008-03-23 07:35:29 +00:00
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
this->DrawWidgets();
|
|
|
|
}
|
2008-03-23 07:35:29 +00:00
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case TSEW_NEWTOWN:
|
2009-04-19 10:31:30 +00:00
|
|
|
HandlePlacePushButton(this, TSEW_NEWTOWN, SPR_CURSOR_TOWN, HT_RECT, PlaceProc_Town);
|
2008-05-18 08:13:13 +00:00
|
|
|
break;
|
2008-04-14 17:06:36 +00:00
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
case TSEW_RANDOMTOWN: {
|
|
|
|
this->HandleButtonClick(TSEW_RANDOMTOWN);
|
|
|
|
_generating_world = true;
|
2008-11-18 22:43:59 +00:00
|
|
|
UpdateNearestTownForRoadTiles(true);
|
2009-02-05 15:59:40 +00:00
|
|
|
const Town *t = CreateRandomTown(20, town_size, city, town_layout);
|
2008-11-18 22:43:59 +00:00
|
|
|
UpdateNearestTownForRoadTiles(false);
|
2008-05-18 08:13:13 +00:00
|
|
|
_generating_world = false;
|
2008-04-14 17:06:36 +00:00
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
if (t == NULL) {
|
|
|
|
ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0);
|
|
|
|
} else {
|
|
|
|
ScrollMainWindowToTile(t->xy);
|
|
|
|
}
|
|
|
|
} break;
|
2008-04-14 17:06:36 +00:00
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
case TSEW_MANYRANDOMTOWNS:
|
|
|
|
this->HandleButtonClick(TSEW_MANYRANDOMTOWNS);
|
2008-04-14 17:06:36 +00:00
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
_generating_world = true;
|
2008-11-18 22:43:59 +00:00
|
|
|
UpdateNearestTownForRoadTiles(true);
|
2009-02-05 15:59:40 +00:00
|
|
|
if (!GenerateTowns(town_layout)) {
|
2008-10-25 13:51:47 +00:00
|
|
|
ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0);
|
|
|
|
}
|
2008-11-18 22:43:59 +00:00
|
|
|
UpdateNearestTownForRoadTiles(false);
|
2008-05-18 08:13:13 +00:00
|
|
|
_generating_world = false;
|
|
|
|
break;
|
2008-04-14 17:06:36 +00:00
|
|
|
|
2009-02-05 15:28:01 +00:00
|
|
|
case TSEW_SIZE_SMALL: case TSEW_SIZE_MEDIUM: case TSEW_SIZE_LARGE: case TSEW_SIZE_RANDOM:
|
2009-02-05 15:59:40 +00:00
|
|
|
town_size = (TownSize)(widget - TSEW_SIZE_SMALL);
|
2009-02-05 16:51:23 +00:00
|
|
|
this->UpdateButtons();
|
2009-02-05 15:28:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TSEW_CITY:
|
2009-02-05 15:59:40 +00:00
|
|
|
city ^= true;
|
|
|
|
this->SetWidgetLoweredState(TSEW_CITY, city);
|
2008-05-18 08:13:13 +00:00
|
|
|
this->SetDirty();
|
|
|
|
break;
|
2009-02-04 22:52:34 +00:00
|
|
|
|
|
|
|
case TSEW_LAYOUT_ORIGINAL: case TSEW_LAYOUT_BETTER: case TSEW_LAYOUT_GRID2:
|
|
|
|
case TSEW_LAYOUT_GRID3: case TSEW_LAYOUT_RANDOM:
|
2009-02-05 15:59:40 +00:00
|
|
|
town_layout = (TownLayout)(widget - TSEW_LAYOUT_ORIGINAL);
|
2009-02-05 16:51:23 +00:00
|
|
|
this->UpdateButtons();
|
2009-02-04 22:52:34 +00:00
|
|
|
break;
|
2008-05-18 08:13:13 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-14 17:06:36 +00:00
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
virtual void OnTimeout()
|
|
|
|
{
|
|
|
|
this->RaiseWidget(TSEW_RANDOMTOWN);
|
|
|
|
this->RaiseWidget(TSEW_MANYRANDOMTOWNS);
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
2008-04-14 17:06:36 +00:00
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
virtual void OnPlaceObject(Point pt, TileIndex tile)
|
|
|
|
{
|
|
|
|
_place_proc(tile);
|
|
|
|
}
|
2008-03-23 07:35:29 +00:00
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
virtual void OnPlaceObjectAbort()
|
|
|
|
{
|
|
|
|
this->RaiseButtons();
|
2009-02-05 16:51:23 +00:00
|
|
|
this->UpdateButtons();
|
2008-03-23 07:35:29 +00:00
|
|
|
}
|
2009-02-05 15:59:40 +00:00
|
|
|
|
|
|
|
static void PlaceProc_Town(TileIndex tile)
|
|
|
|
{
|
2009-02-16 23:23:33 +00:00
|
|
|
uint32 townnameparts;
|
|
|
|
if (!GenerateTownName(&townnameparts)) {
|
2009-04-21 23:40:56 +00:00
|
|
|
ShowErrorMessage(STR_ERROR_TOO_MANY_TOWNS, STR_ERROR_CAN_T_BUILD_TOWN_HERE, 0, 0);
|
2009-02-16 23:23:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-21 23:40:56 +00:00
|
|
|
DoCommandP(tile, town_size | city << 2 | town_layout << 3, townnameparts, CMD_BUILD_TOWN | CMD_MSG(STR_ERROR_CAN_T_BUILD_TOWN_HERE), CcBuildTown);
|
2009-02-05 15:59:40 +00:00
|
|
|
}
|
2008-05-18 08:13:13 +00:00
|
|
|
};
|
2008-03-23 07:35:29 +00:00
|
|
|
|
2009-02-17 00:21:08 +00:00
|
|
|
TownSize FoundTownWindow::town_size = TS_MEDIUM; // select medium-sized towns per default;
|
|
|
|
bool FoundTownWindow::city;
|
|
|
|
TownLayout FoundTownWindow::town_layout;
|
2009-02-05 15:59:40 +00:00
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _found_town_desc(
|
2009-02-05 15:28:01 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 160, 162, 160, 162,
|
2009-02-17 00:21:08 +00:00
|
|
|
WC_FOUND_TOWN, WC_NONE,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_CONSTRUCTION,
|
2009-06-10 20:48:22 +00:00
|
|
|
NULL, _nested_found_town_widgets, lengthof(_nested_found_town_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2008-03-23 07:35:29 +00:00
|
|
|
|
|
|
|
void ShowBuildTownWindow()
|
|
|
|
{
|
2009-05-17 01:00:56 +00:00
|
|
|
if (_game_mode != GM_EDITOR && !Company::IsValidID(_local_company)) return;
|
2009-02-17 00:21:08 +00:00
|
|
|
AllocateWindowDescFront<FoundTownWindow>(&_found_town_desc, 0);
|
2008-03-23 07:35:29 +00:00
|
|
|
}
|