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"
|
2005-02-05 15:58:59 +00:00
|
|
|
#include "debug.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-01-12 14:10:35 +00:00
|
|
|
#include "player_func.h"
|
|
|
|
#include "player_base.h"
|
|
|
|
#include "player_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"
|
2007-12-25 09:48:53 +00:00
|
|
|
#include "core/alloc_func.hpp"
|
2008-01-13 14:37:30 +00:00
|
|
|
#include "settings_type.h"
|
2008-05-07 13:10:15 +00:00
|
|
|
#include "tilehighlight_func.h"
|
2008-05-10 08:58:52 +00:00
|
|
|
#include "string_func.h"
|
2008-05-27 20:05:36 +00:00
|
|
|
#include "sortlist_type.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;
|
|
|
|
|
2008-03-23 07:35:29 +00:00
|
|
|
extern bool GenerateTowns();
|
|
|
|
static int _scengen_town_size = 1; // depress medium-sized towns per default
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static const Widget _town_authority_widgets[] = {
|
2007-09-30 17:38:42 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // TWA_CLOSEBOX
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 316, 0, 13, STR_2022_LOCAL_AUTHORITY, STR_018C_WINDOW_TITLE_DRAG_THIS}, // TWA_CAPTION
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 13, 0, 316, 14, 105, 0x0, STR_NULL}, // TWA_RATING_INFO
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 13, 0, 304, 106, 157, 0x0, STR_2043_LIST_OF_THINGS_TO_DO_AT}, // TWA_COMMAND_LIST
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_NONE, 13, 305, 316, 106, 157, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // TWA_SCROLLBAR
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 13, 0, 316, 158, 209, 0x0, STR_NULL}, // TWA_ACTION_INFO
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 316, 210, 221, STR_2042_DO_IT, STR_2044_CARRY_OUT_THE_HIGHLIGHTED}, // TWA_EXECUTE
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern const byte _town_action_costs[8];
|
|
|
|
|
2007-09-30 17:38:42 +00:00
|
|
|
enum TownActions {
|
|
|
|
TACT_NONE = 0x00,
|
|
|
|
|
|
|
|
TACT_ADVERTISE_SMALL = 0x01,
|
|
|
|
TACT_ADVERTISE_MEDIUM = 0x02,
|
|
|
|
TACT_ADVERTISE_LARGE = 0x04,
|
|
|
|
TACT_ROAD_REBUILD = 0x08,
|
|
|
|
TACT_BUILD_STATUE = 0x10,
|
|
|
|
TACT_FOUND_BUILDINGS = 0x20,
|
|
|
|
TACT_BUY_RIGHTS = 0x40,
|
|
|
|
TACT_BRIBE = 0x80,
|
|
|
|
|
|
|
|
TACT_ADVERTISE = TACT_ADVERTISE_SMALL | TACT_ADVERTISE_MEDIUM | TACT_ADVERTISE_LARGE,
|
|
|
|
TACT_CONSTRUCTION = TACT_ROAD_REBUILD | TACT_BUILD_STATUE | TACT_FOUND_BUILDINGS,
|
|
|
|
TACT_FUNDS = TACT_BUY_RIGHTS | TACT_BRIBE,
|
|
|
|
TACT_ALL = TACT_ADVERTISE | TACT_CONSTRUCTION | TACT_FUNDS,
|
|
|
|
};
|
|
|
|
|
|
|
|
DECLARE_ENUM_AS_BIT_SET(TownActions);
|
|
|
|
|
2005-05-12 00:11:37 +00:00
|
|
|
/** Get a list of available actions to do at a town.
|
2007-04-04 03:21:14 +00:00
|
|
|
* @param nump if not NULL add put the number of available actions in it
|
2005-05-12 00:11:37 +00:00
|
|
|
* @param pid the player that is querying the town
|
2007-04-04 03:21:14 +00:00
|
|
|
* @param t the town that is queried
|
2005-05-12 00:11:37 +00:00
|
|
|
* @return bitmasked value of enabled actions
|
|
|
|
*/
|
|
|
|
uint GetMaskOfTownActions(int *nump, PlayerID pid, const Town *t)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-05-12 00:11:37 +00:00
|
|
|
int num = 0;
|
2007-09-30 17:38:42 +00:00
|
|
|
TownActions buttons = TACT_NONE;
|
|
|
|
|
|
|
|
/* Spectators and unwanted have no options */
|
2008-05-29 15:13:28 +00:00
|
|
|
if (pid != PLAYER_SPECTATOR && !(_settings_game.economy.bribe && t->unwanted[pid])) {
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* Things worth more than this are not shown */
|
2007-09-30 17:38:42 +00:00
|
|
|
Money avail = GetPlayer(pid)->player_money + _price.station_value * 200;
|
|
|
|
Money ref = _price.build_industry >> 8;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-09-30 17:38:42 +00:00
|
|
|
/* Check the action bits for validity and
|
|
|
|
* if they are valid add them */
|
|
|
|
for (uint i = 0; i != lengthof(_town_action_costs); i++) {
|
|
|
|
const TownActions cur = (TownActions)(1 << i);
|
|
|
|
|
|
|
|
/* Is the player not able to bribe ? */
|
2008-05-29 15:13:28 +00:00
|
|
|
if (cur == TACT_BRIBE && (!_settings_game.economy.bribe || t->ratings[pid] >= RATING_BRIBE_MAXIMUM))
|
2007-09-30 17:38:42 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Is the player not able to buy exclusive rights ? */
|
2008-05-29 15:13:28 +00:00
|
|
|
if (cur == TACT_BUY_RIGHTS && !_settings_game.economy.exclusive_rights)
|
2007-09-30 17:38:42 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Is the player not able to build a statue ? */
|
2007-11-19 21:02:30 +00:00
|
|
|
if (cur == TACT_BUILD_STATUE && HasBit(t->statues, pid))
|
2007-09-30 17:38:42 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (avail >= _town_action_costs[i] * ref) {
|
|
|
|
buttons |= cur;
|
2004-08-09 17:04:08 +00:00
|
|
|
num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-12 00:11:37 +00:00
|
|
|
if (nump != NULL) *nump = num;
|
2004-08-09 17:04:08 +00:00
|
|
|
return buttons;
|
|
|
|
}
|
|
|
|
|
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-05-22 02:03:05 +00:00
|
|
|
enum TownAuthorityWidget {
|
|
|
|
TWA_CLOSEBOX = 0,
|
|
|
|
TWA_CAPTION,
|
|
|
|
TWA_RATING_INFO,
|
|
|
|
TWA_COMMAND_LIST,
|
|
|
|
TWA_SCROLLBAR,
|
|
|
|
TWA_ACTION_INFO,
|
|
|
|
TWA_EXECUTE,
|
|
|
|
};
|
|
|
|
|
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)
|
|
|
|
{
|
2008-05-22 02:13:24 +00:00
|
|
|
this->town = GetTown(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-05-22 02:13:24 +00:00
|
|
|
uint buttons = GetMaskOfTownActions(&numact, _local_player, 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
|
|
|
|
2008-05-15 22:47:03 +00:00
|
|
|
DrawString(2, 15, STR_2023_TRANSPORT_COMPANY_RATINGS, TC_FROMSTRING);
|
2008-04-14 17:06:36 +00:00
|
|
|
|
2008-05-15 22:47:03 +00:00
|
|
|
/* Draw list of players */
|
|
|
|
int y = 25;
|
|
|
|
|
|
|
|
const Player *p;
|
|
|
|
FOR_ALL_PLAYERS(p) {
|
2008-05-22 02:13:24 +00:00
|
|
|
if (p->is_active && (HasBit(this->town->have_ratings, p->index) || this->town->exclusivity == p->index)) {
|
2008-05-15 22:47:03 +00:00
|
|
|
DrawPlayerIcon(p->index, 2, y);
|
|
|
|
|
|
|
|
SetDParam(0, p->index);
|
|
|
|
SetDParam(1, p->index);
|
|
|
|
|
2008-05-22 02:13:24 +00:00
|
|
|
int r = this->town->ratings[p->index];
|
2008-05-15 22:47:03 +00:00
|
|
|
StringID str;
|
|
|
|
(str = STR_3035_APPALLING, r <= RATING_APPALLING) || // Apalling
|
|
|
|
(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-05-22 02:13:24 +00:00
|
|
|
if (this->town->exclusivity == p->index) { // red icon for player 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
|
|
|
|
|
|
|
DrawString(28, y, STR_2024, TC_FROMSTRING);
|
|
|
|
y += 10;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-15 22:47:03 +00:00
|
|
|
}
|
|
|
|
y = 107;
|
|
|
|
int pos = this->vscroll.pos;
|
2004-08-23 21:12:51 +00:00
|
|
|
|
2008-05-15 22:47:03 +00:00
|
|
|
if (--pos < 0) {
|
|
|
|
DrawString(2, y, STR_2045_ACTIONS_AVAILABLE, TC_FROMSTRING);
|
|
|
|
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) {
|
|
|
|
DrawString(3, y, STR_2046_SMALL_ADVERTISING_CAMPAIGN + i, TC_ORANGE);
|
|
|
|
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]);
|
|
|
|
SetDParam(0, STR_2046_SMALL_ADVERTISING_CAMPAIGN + this->sel_index);
|
|
|
|
DrawStringMultiLine(2, 159, STR_204D_INITIATE_A_SMALL_LOCAL + this->sel_index, 313);
|
|
|
|
}
|
|
|
|
}
|
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: {
|
|
|
|
int y = (pt.y - 0x6B) / 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-05-22 02:13:24 +00:00
|
|
|
y = GetNthSetBit(GetMaskOfTownActions(NULL, _local_player, 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:
|
2008-05-22 02:13:24 +00:00
|
|
|
DoCommandP(this->town->xy, this->window_number, this->sel_index, NULL, CMD_DO_TOWN_ACTION | CMD_MSG(STR_00B4_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
|
|
|
|
|
|
|
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,
|
|
|
|
_town_authority_widgets,
|
|
|
|
};
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
enum TownViewWidget {
|
|
|
|
TVW_CAPTION = 1,
|
|
|
|
TVW_STICKY,
|
2008-05-24 02:54:47 +00:00
|
|
|
TVW_VIEWPORTPANEL,
|
|
|
|
TVW_INFOPANEL = 5,
|
|
|
|
TVW_CENTERVIEW,
|
2008-05-22 02:03:05 +00:00
|
|
|
TVW_SHOWAUTORITY,
|
|
|
|
TVW_CHANGENAME,
|
|
|
|
TVW_EXPAND,
|
|
|
|
TVW_DELETE,
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2008-05-18 08:13:13 +00:00
|
|
|
TownViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
|
|
|
{
|
2008-05-22 02:13:24 +00:00
|
|
|
this->town = GetTown(this->window_number);
|
|
|
|
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;
|
2008-05-22 02:13:24 +00:00
|
|
|
InitializeWindowViewport(this, 3, 17, 254, 86, this->town->xy, ZOOM_LVL_TOWN);
|
2008-05-18 08:13:13 +00:00
|
|
|
|
2008-05-22 02:13:24 +00:00
|
|
|
if (this->town->larger_town) this->widget[TVW_CAPTION].data = STR_CITY;
|
2008-05-18 08:13:13 +00:00
|
|
|
this->SetWidgetHiddenState(TVW_DELETE, ingame); // hide delete button on game mode
|
|
|
|
this->SetWidgetHiddenState(TVW_EXPAND, ingame); // hide expand button on game mode
|
|
|
|
this->SetWidgetHiddenState(TVW_SHOWAUTORITY, !ingame); // hide autority button on editor mode
|
|
|
|
|
|
|
|
if (ingame) {
|
|
|
|
/* resize caption bar */
|
|
|
|
this->widget[TVW_CAPTION].right = this->widget[TVW_STICKY].left -1;
|
|
|
|
/* move the rename from top on scenario to bottom in game */
|
|
|
|
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;
|
|
|
|
}
|
2008-05-19 01:50:07 +00:00
|
|
|
|
2008-05-24 02:54:47 +00:00
|
|
|
/* Space required for showing noise level information */
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.economy.station_noise_level) {
|
2008-05-24 02:54:47 +00:00
|
|
|
ResizeWindowForWidget(this, TVW_INFOPANEL, 0, 10);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2008-05-22 02:13:24 +00:00
|
|
|
SetDParam(0, this->town->population);
|
|
|
|
SetDParam(1, this->town->num_houses);
|
2008-05-18 08:13:13 +00:00
|
|
|
DrawString(2, 107, STR_2006_POPULATION, TC_FROMSTRING);
|
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);
|
2008-05-18 08:13:13 +00:00
|
|
|
DrawString(2, 117, STR_200D_PASSENGERS_LAST_MONTH_MAX, TC_FROMSTRING);
|
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);
|
2008-05-18 08:13:13 +00:00
|
|
|
DrawString(2, 127, STR_200E_MAIL_LAST_MONTH_MAX, TC_FROMSTRING);
|
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());
|
|
|
|
DrawString(2, 137, STR_NOISE_IN_TOWN, 0);
|
|
|
|
}
|
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) {
|
|
|
|
case TVW_CENTERVIEW: /* scroll to location */
|
|
|
|
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
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
case TVW_SHOWAUTORITY: /* town authority */
|
|
|
|
ShowTownAuthorityWindow(this->window_number);
|
|
|
|
break;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
case TVW_CHANGENAME: /* rename */
|
|
|
|
SetDParam(0, this->window_number);
|
|
|
|
ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, 31, 130, this, CS_ALPHANUMERAL);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 08:13:13 +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;
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.economy.station_noise_level) { // adjust depending
|
2008-05-24 02:54:47 +00:00
|
|
|
if (this->height == 150) { // window is smaller, needs to be bigger
|
|
|
|
ResizeWindowForWidget(this, TVW_INFOPANEL, 0, 10);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (this->height != 150) { // window is bigger, needs to be smaller
|
|
|
|
ResizeWindowForWidget(this, TVW_INFOPANEL, 0, -10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
virtual void OnQueryTextFinished(char *str)
|
|
|
|
{
|
|
|
|
if (!StrEmpty(str)) {
|
|
|
|
_cmd_text = str;
|
|
|
|
DoCommandP(0, this->window_number, 0, NULL,
|
|
|
|
CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
static const Widget _town_view_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
2008-04-16 03:05:56 +00:00
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 172, 0, 13, STR_2005, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, 13, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 13, 0, 259, 14, 105, 0x0, STR_NULL},
|
2006-10-24 16:27:18 +00:00
|
|
|
{ WWT_INSET, RESIZE_NONE, 13, 2, 257, 16, 103, 0x0, STR_NULL},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 13, 0, 259, 106, 137, 0x0, STR_NULL},
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 85, 138, 149, STR_00E4_LOCATION, STR_200B_CENTER_THE_MAIN_VIEW_ON},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 86, 171, 138, 149, STR_2020_LOCAL_AUTHORITY, STR_2021_SHOW_INFORMATION_ON_LOCAL},
|
2008-04-16 03:05:56 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 172, 247, 0, 13, STR_0130_RENAME, STR_200C_CHANGE_TOWN_NAME},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 86, 171, 138, 149, STR_023C_EXPAND, STR_023B_INCREASE_SIZE_OF_TOWN},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 172, 259, 138, 149, STR_0290_DELETE, STR_0291_DELETE_THIS_TOWN_COMPLETELY},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _town_view_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 260, 150, 260, 150,
|
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,
|
2004-08-09 17:04:08 +00:00
|
|
|
_town_view_widgets,
|
|
|
|
};
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _town_directory_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 195, 0, 13, STR_2000_TOWNS, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, 13, 196, 207, 0, 13, 0x0, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 98, 14, 25, STR_SORT_BY_NAME, STR_SORT_ORDER_TIP},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 99, 195, 14, 25, STR_SORT_BY_POPULATION, STR_SORT_ORDER_TIP},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_BOTTOM, 13, 0, 195, 26, 189, 0x0, STR_200A_TOWN_NAMES_CLICK_ON_NAME},
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 13, 196, 207, 14, 189, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_TB, 13, 0, 195, 190, 201, 0x0, STR_NULL},
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_RESIZEBOX, RESIZE_TB, 13, 196, 207, 190, 201, 0x0, STR_RESIZE_BUTTON},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-05-27 20:05:36 +00:00
|
|
|
struct TownDirectoryWindow : public Window {
|
|
|
|
private:
|
|
|
|
enum TownDirectoryWidget {
|
|
|
|
TDW_SORTNAME = 3,
|
|
|
|
TDW_SORTPOPULATION,
|
|
|
|
TDW_CENTERTOWN,
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-27 20:05:36 +00:00
|
|
|
/* Runtime saved values */
|
|
|
|
static Listing last_sorting;
|
|
|
|
static const Town *last_town;
|
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
|
|
|
|
2008-05-27 20:05:36 +00:00
|
|
|
void BuildTownList()
|
|
|
|
{
|
|
|
|
if (!this->towns.NeedRebuild()) return;
|
2005-01-06 22:31:58 +00:00
|
|
|
|
2008-05-27 20:05:36 +00:00
|
|
|
this->towns.Clear();
|
2005-01-06 22:31:58 +00:00
|
|
|
|
2008-05-27 20:05:36 +00:00
|
|
|
const Town *t;
|
|
|
|
FOR_ALL_TOWNS(t) {
|
|
|
|
*this->towns.Append() = t;
|
|
|
|
}
|
2004-12-28 17:50:17 +00:00
|
|
|
|
2008-05-27 20:05:36 +00:00
|
|
|
this->towns.Compact();
|
|
|
|
this->towns.RebuildDone();
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-27 20:05:36 +00:00
|
|
|
void SortTownList()
|
|
|
|
{
|
|
|
|
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:
|
2008-05-19 09:17:26 +00:00
|
|
|
TownDirectoryWindow(const WindowDesc *desc) : Window(desc, 0)
|
|
|
|
{
|
|
|
|
this->vscroll.cap = 16;
|
|
|
|
this->resize.step_height = 10;
|
|
|
|
this->resize.height = this->height - 10 * 6; // minimum of 10 items in the list, each item 10 high
|
2004-08-09 17:04:08 +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();
|
|
|
|
|
2008-05-19 09:17:26 +00:00
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
|
}
|
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()
|
|
|
|
{
|
2008-05-27 20:05:36 +00:00
|
|
|
this->BuildTownList();
|
|
|
|
this->SortTownList();
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2008-05-27 20:05:36 +00:00
|
|
|
SetVScrollCount(this, this->towns.Length());
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2008-05-19 09:17:26 +00:00
|
|
|
this->DrawWidgets();
|
2008-06-16 17:05:17 +00:00
|
|
|
this->DrawSortButtonState(this->towns.SortType() == 0 ? TDW_SORTNAME : TDW_SORTPOPULATION, this->towns.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2008-05-19 09:17:26 +00:00
|
|
|
{
|
|
|
|
int n = 0;
|
|
|
|
uint16 i = this->vscroll.pos;
|
|
|
|
int y = 28;
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2008-05-27 20:05:36 +00:00
|
|
|
while (i < this->towns.Length()) {
|
|
|
|
const Town *t = this->towns[i];
|
2008-05-19 09:17:26 +00:00
|
|
|
|
|
|
|
assert(t->xy);
|
|
|
|
|
|
|
|
SetDParam(0, t->index);
|
|
|
|
SetDParam(1, t->population);
|
|
|
|
DrawString(2, y, STR_2057, TC_FROMSTRING);
|
|
|
|
|
|
|
|
y += 10;
|
|
|
|
i++;
|
|
|
|
if (++n == this->vscroll.cap) break; // max number of towns in 1 window
|
2004-09-07 19:01:06 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-19 09:17:26 +00:00
|
|
|
SetDParam(0, GetWorldPopulation());
|
|
|
|
DrawString(3, this->height - 12 + 2, STR_TOWN_POPULATION, TC_FROMSTRING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
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);
|
|
|
|
}
|
2008-05-19 09:17:26 +00:00
|
|
|
this->SetDirty();
|
|
|
|
break;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2008-05-19 09:17:26 +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);
|
|
|
|
}
|
2008-05-19 09:17:26 +00:00
|
|
|
this->SetDirty();
|
|
|
|
break;
|
2006-08-15 07:07:17 +00:00
|
|
|
|
2008-05-19 09:17:26 +00:00
|
|
|
case TDW_CENTERTOWN: { /* Click on Town Matrix */
|
|
|
|
uint16 id_v = (pt.y - 28) / 10;
|
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];
|
2008-05-19 09:17:26 +00:00
|
|
|
assert(t->xy);
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2008-05-19 09:17:26 +00:00
|
|
|
virtual void OnResize(Point new_size, Point delta)
|
|
|
|
{
|
|
|
|
this->vscroll.cap += delta.y / 10;
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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,
|
2004-08-09 17:04:08 +00:00
|
|
|
_town_directory_widgets,
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
ResetObjectToPlace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PlaceProc_Town(TileIndex tile)
|
|
|
|
{
|
|
|
|
uint32 size = min(_scengen_town_size, (int)TSM_CITY);
|
|
|
|
uint32 mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED;
|
|
|
|
DoCommandP(tile, size, mode, CcBuildTown, CMD_BUILD_TOWN | CMD_MSG(STR_0236_CAN_T_BUILD_TOWN_HERE));
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _scen_edit_town_gen_widgets[] = {
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 147, 0, 13, STR_0233_TOWN_GENERATION, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, 7, 148, 159, 0, 13, 0x0, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 159, 14, 94, 0x0, STR_NULL},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 157, 16, 27, STR_0234_NEW_TOWN, STR_0235_CONSTRUCT_NEW_TOWN},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 157, 29, 40, STR_023D_RANDOM_TOWN, STR_023E_BUILD_TOWN_IN_RANDOM_LOCATION},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 157, 42, 53, STR_MANY_RANDOM_TOWNS, STR_RANDOM_TOWNS_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 53, 68, 79, STR_02A1_SMALL, STR_02A4_SELECT_TOWN_SIZE},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 54, 105, 68, 79, STR_02A2_MEDIUM, STR_02A4_SELECT_TOWN_SIZE},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 106, 157, 68, 79, STR_02A3_LARGE, STR_02A4_SELECT_TOWN_SIZE},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 157, 81, 92, STR_SCENARIO_EDITOR_CITY, STR_02A4_SELECT_TOWN_SIZE},
|
|
|
|
{ WWT_LABEL, RESIZE_NONE, 7, 0, 147, 54, 67, STR_02A5_TOWN_SIZE, STR_NULL},
|
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
struct ScenarioEditorTownGenerationWindow : Window
|
2008-03-23 07:35:29 +00:00
|
|
|
{
|
2008-05-22 02:03:05 +00:00
|
|
|
private:
|
|
|
|
enum TownScenarioEditorWidget {
|
|
|
|
TSEW_NEWTOWN = 4,
|
|
|
|
TSEW_RANDOMTOWN,
|
|
|
|
TSEW_MANYRANDOMTOWNS,
|
|
|
|
TSEW_SMALLTOWN,
|
|
|
|
TSEW_MEDIUMTOWN,
|
|
|
|
TSEW_LARGETOWN,
|
|
|
|
TSEW_CITY,
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2008-05-18 08:13:13 +00:00
|
|
|
ScenarioEditorTownGenerationWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
|
|
|
{
|
|
|
|
this->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
|
2008-05-23 23:02:13 +00:00
|
|
|
this->FindWindowPlacementAndResize(desc);
|
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:
|
|
|
|
HandlePlacePushButton(this, TSEW_NEWTOWN, SPR_CURSOR_TOWN, VHM_RECT, PlaceProc_Town);
|
|
|
|
break;
|
2008-04-14 17:06:36 +00:00
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
case TSEW_RANDOMTOWN: {
|
|
|
|
Town *t;
|
|
|
|
uint size = min(_scengen_town_size, (int)TSM_CITY);
|
|
|
|
TownSizeMode mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED;
|
2008-04-14 17:06:36 +00:00
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
this->HandleButtonClick(TSEW_RANDOMTOWN);
|
|
|
|
_generating_world = true;
|
|
|
|
t = CreateRandomTown(20, mode, size);
|
|
|
|
_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;
|
|
|
|
if (!GenerateTowns()) ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0);
|
|
|
|
_generating_world = false;
|
|
|
|
break;
|
2008-04-14 17:06:36 +00:00
|
|
|
|
2008-05-18 08:13:13 +00:00
|
|
|
case TSEW_SMALLTOWN: case TSEW_MEDIUMTOWN: case TSEW_LARGETOWN: case TSEW_CITY:
|
|
|
|
this->RaiseWidget(_scengen_town_size + TSEW_SMALLTOWN);
|
|
|
|
_scengen_town_size = widget - TSEW_SMALLTOWN;
|
|
|
|
this->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
|
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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();
|
|
|
|
this->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
|
|
|
|
this->SetDirty();
|
2008-03-23 07:35:29 +00:00
|
|
|
}
|
2008-05-18 08:13:13 +00:00
|
|
|
};
|
2008-03-23 07:35:29 +00:00
|
|
|
|
|
|
|
static const WindowDesc _scen_edit_town_gen_desc = {
|
|
|
|
WDP_AUTO, WDP_AUTO, 160, 95, 160, 95,
|
|
|
|
WC_SCEN_TOWN_GEN, WC_NONE,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
|
|
|
_scen_edit_town_gen_widgets,
|
|
|
|
};
|
|
|
|
|
|
|
|
void ShowBuildTownWindow()
|
|
|
|
{
|
2008-07-17 20:13:01 +00:00
|
|
|
if (_game_mode != GM_EDITOR && !IsValidPlayerID(_current_player)) return;
|
2008-05-18 08:13:13 +00:00
|
|
|
AllocateWindowDescFront<ScenarioEditorTownGenerationWindow>(&_scen_edit_town_gen_desc, 0);
|
2008-03-23 07:35:29 +00:00
|
|
|
}
|
|
|
|
|