|
|
@ -283,34 +283,39 @@ enum TownViewWidget {
|
|
|
|
TVW_DELETE,
|
|
|
|
TVW_DELETE,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void TownViewWndProc(Window *w, WindowEvent *e)
|
|
|
|
struct TownViewWindow : Window {
|
|
|
|
|
|
|
|
TownViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Town *t = GetTown(w->window_number);
|
|
|
|
const Town *t = GetTown(this->window_number);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this->flags4 |= WF_DISABLE_VP_SCROLL;
|
|
|
|
|
|
|
|
InitializeWindowViewport(this, 3, 17, 254, 86, t->xy, ZOOM_LVL_TOWN);
|
|
|
|
|
|
|
|
|
|
|
|
switch (e->event) {
|
|
|
|
|
|
|
|
case WE_CREATE: {
|
|
|
|
|
|
|
|
bool ingame = _game_mode != GM_EDITOR;
|
|
|
|
bool ingame = _game_mode != GM_EDITOR;
|
|
|
|
if (t->larger_town) w->widget[TVW_CAPTION].data = STR_CITY;
|
|
|
|
if (t->larger_town) this->widget[TVW_CAPTION].data = STR_CITY;
|
|
|
|
w->SetWidgetHiddenState(TVW_DELETE, ingame); // hide delete button on game mode
|
|
|
|
this->SetWidgetHiddenState(TVW_DELETE, ingame); // hide delete button on game mode
|
|
|
|
w->SetWidgetHiddenState(TVW_EXPAND, ingame); // hide expand button on game mode
|
|
|
|
this->SetWidgetHiddenState(TVW_EXPAND, ingame); // hide expand button on game mode
|
|
|
|
w->SetWidgetHiddenState(TVW_SHOWAUTORITY, !ingame); // hide autority button on editor mode
|
|
|
|
this->SetWidgetHiddenState(TVW_SHOWAUTORITY, !ingame); // hide autority button on editor mode
|
|
|
|
|
|
|
|
|
|
|
|
if (ingame) {
|
|
|
|
if (ingame) {
|
|
|
|
/* resize caption bar */
|
|
|
|
/* resize caption bar */
|
|
|
|
w->widget[TVW_CAPTION].right = w->widget[TVW_STICKY].left -1;
|
|
|
|
this->widget[TVW_CAPTION].right = this->widget[TVW_STICKY].left -1;
|
|
|
|
/* move the rename from top on scenario to bottom in game */
|
|
|
|
/* move the rename from top on scenario to bottom in game */
|
|
|
|
w->widget[TVW_CHANGENAME].top = w->widget[TVW_EXPAND].top;
|
|
|
|
this->widget[TVW_CHANGENAME].top = this->widget[TVW_EXPAND].top;
|
|
|
|
w->widget[TVW_CHANGENAME].bottom = w->widget[TVW_EXPAND].bottom;
|
|
|
|
this->widget[TVW_CHANGENAME].bottom = this->widget[TVW_EXPAND].bottom;
|
|
|
|
w->widget[TVW_CHANGENAME].right = w->widget[TVW_STICKY].right;
|
|
|
|
this->widget[TVW_CHANGENAME].right = this->widget[TVW_STICKY].right;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
const Town *t = GetTown(this->window_number);
|
|
|
|
|
|
|
|
|
|
|
|
case WE_PAINT:
|
|
|
|
|
|
|
|
/* disable renaming town in network games if you are not the server */
|
|
|
|
/* disable renaming town in network games if you are not the server */
|
|
|
|
w->SetWidgetDisabledState(TVW_CHANGENAME, _networking && !_network_server);
|
|
|
|
this->SetWidgetDisabledState(TVW_CHANGENAME, _networking && !_network_server);
|
|
|
|
|
|
|
|
|
|
|
|
SetDParam(0, t->index);
|
|
|
|
SetDParam(0, t->index);
|
|
|
|
w->DrawWidgets();
|
|
|
|
this->DrawWidgets();
|
|
|
|
|
|
|
|
|
|
|
|
SetDParam(0, t->population);
|
|
|
|
SetDParam(0, t->population);
|
|
|
|
SetDParam(1, t->num_houses);
|
|
|
|
SetDParam(1, t->num_houses);
|
|
|
@ -324,11 +329,14 @@ static void TownViewWndProc(Window *w, WindowEvent *e)
|
|
|
|
SetDParam(1, t->max_mail);
|
|
|
|
SetDParam(1, t->max_mail);
|
|
|
|
DrawString(2, 127, STR_200E_MAIL_LAST_MONTH_MAX, TC_FROMSTRING);
|
|
|
|
DrawString(2, 127, STR_200E_MAIL_LAST_MONTH_MAX, TC_FROMSTRING);
|
|
|
|
|
|
|
|
|
|
|
|
w->DrawViewport();
|
|
|
|
this->DrawViewport();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case WE_CLICK:
|
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
switch (e->we.click.widget) {
|
|
|
|
{
|
|
|
|
|
|
|
|
Town *t = GetTown(this->window_number);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (widget) {
|
|
|
|
case TVW_CENTERVIEW: /* scroll to location */
|
|
|
|
case TVW_CENTERVIEW: /* scroll to location */
|
|
|
|
if (_ctrl_pressed) {
|
|
|
|
if (_ctrl_pressed) {
|
|
|
|
ShowExtraViewPortWindow(t->xy);
|
|
|
|
ShowExtraViewPortWindow(t->xy);
|
|
|
@ -338,12 +346,12 @@ static void TownViewWndProc(Window *w, WindowEvent *e)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case TVW_SHOWAUTORITY: /* town authority */
|
|
|
|
case TVW_SHOWAUTORITY: /* town authority */
|
|
|
|
ShowTownAuthorityWindow(w->window_number);
|
|
|
|
ShowTownAuthorityWindow(this->window_number);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case TVW_CHANGENAME: /* rename */
|
|
|
|
case TVW_CHANGENAME: /* rename */
|
|
|
|
SetDParam(0, w->window_number);
|
|
|
|
SetDParam(0, this->window_number);
|
|
|
|
ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, 31, 130, w, CS_ALPHANUMERAL);
|
|
|
|
ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, 31, 130, this, CS_ALPHANUMERAL);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case TVW_EXPAND: /* expand town - only available on Scenario editor */
|
|
|
|
case TVW_EXPAND: /* expand town - only available on Scenario editor */
|
|
|
@ -353,17 +361,18 @@ static void TownViewWndProc(Window *w, WindowEvent *e)
|
|
|
|
case TVW_DELETE: /* delete town - only available on Scenario editor */
|
|
|
|
case TVW_DELETE: /* delete town - only available on Scenario editor */
|
|
|
|
delete t;
|
|
|
|
delete t;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case WE_ON_EDIT_TEXT:
|
|
|
|
virtual void OnQueryTextFinished(char *str)
|
|
|
|
if (!StrEmpty(e->we.edittext.str)) {
|
|
|
|
{
|
|
|
|
_cmd_text = e->we.edittext.str;
|
|
|
|
if (!StrEmpty(str)) {
|
|
|
|
DoCommandP(0, w->window_number, 0, NULL,
|
|
|
|
_cmd_text = str;
|
|
|
|
|
|
|
|
DoCommandP(0, this->window_number, 0, NULL,
|
|
|
|
CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN));
|
|
|
|
CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const Widget _town_view_widgets[] = {
|
|
|
|
static const Widget _town_view_widgets[] = {
|
|
|
@ -386,19 +395,12 @@ static const WindowDesc _town_view_desc = {
|
|
|
|
WC_TOWN_VIEW, WC_NONE,
|
|
|
|
WC_TOWN_VIEW, WC_NONE,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
|
|
|
|
_town_view_widgets,
|
|
|
|
_town_view_widgets,
|
|
|
|
TownViewWndProc
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void ShowTownViewWindow(TownID town)
|
|
|
|
void ShowTownViewWindow(TownID town)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
AllocateWindowDescFront<TownViewWindow>(&_town_view_desc, town);
|
|
|
|
|
|
|
|
|
|
|
|
w = AllocateWindowDescFront<Window>(&_town_view_desc, town);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (w != NULL) {
|
|
|
|
|
|
|
|
w->flags4 |= WF_DISABLE_VP_SCROLL;
|
|
|
|
|
|
|
|
InitializeWindowViewport(w, 3, 17, 254, 86, GetTown(town)->xy, ZOOM_LVL_TOWN);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum TownDirectoryWidget {
|
|
|
|
enum TownDirectoryWidget {
|
|
|
@ -622,21 +624,23 @@ static const Widget _scen_edit_town_gen_widgets[] = {
|
|
|
|
{ WIDGETS_END},
|
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void ScenEditTownGenWndProc(Window *w, WindowEvent *e)
|
|
|
|
struct ScenarioEditorTownGenerationWindow : Window
|
|
|
|
{
|
|
|
|
{
|
|
|
|
switch (e->event) {
|
|
|
|
ScenarioEditorTownGenerationWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
|
|
|
case WE_PAINT:
|
|
|
|
{
|
|
|
|
w->DrawWidgets();
|
|
|
|
this->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case WE_CREATE:
|
|
|
|
virtual void OnPaint()
|
|
|
|
w->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
this->DrawWidgets();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case WE_CLICK:
|
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
switch (e->we.click.widget) {
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (widget) {
|
|
|
|
case TSEW_NEWTOWN:
|
|
|
|
case TSEW_NEWTOWN:
|
|
|
|
HandlePlacePushButton(w, TSEW_NEWTOWN, SPR_CURSOR_TOWN, VHM_RECT, PlaceProc_Town);
|
|
|
|
HandlePlacePushButton(this, TSEW_NEWTOWN, SPR_CURSOR_TOWN, VHM_RECT, PlaceProc_Town);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case TSEW_RANDOMTOWN: {
|
|
|
|
case TSEW_RANDOMTOWN: {
|
|
|
@ -644,7 +648,7 @@ static void ScenEditTownGenWndProc(Window *w, WindowEvent *e)
|
|
|
|
uint size = min(_scengen_town_size, (int)TSM_CITY);
|
|
|
|
uint size = min(_scengen_town_size, (int)TSM_CITY);
|
|
|
|
TownSizeMode mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED;
|
|
|
|
TownSizeMode mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED;
|
|
|
|
|
|
|
|
|
|
|
|
w->HandleButtonClick(TSEW_RANDOMTOWN);
|
|
|
|
this->HandleButtonClick(TSEW_RANDOMTOWN);
|
|
|
|
_generating_world = true;
|
|
|
|
_generating_world = true;
|
|
|
|
t = CreateRandomTown(20, mode, size);
|
|
|
|
t = CreateRandomTown(20, mode, size);
|
|
|
|
_generating_world = false;
|
|
|
|
_generating_world = false;
|
|
|
@ -657,7 +661,7 @@ static void ScenEditTownGenWndProc(Window *w, WindowEvent *e)
|
|
|
|
} break;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
|
|
case TSEW_MANYRANDOMTOWNS:
|
|
|
|
case TSEW_MANYRANDOMTOWNS:
|
|
|
|
w->HandleButtonClick(TSEW_MANYRANDOMTOWNS);
|
|
|
|
this->HandleButtonClick(TSEW_MANYRANDOMTOWNS);
|
|
|
|
|
|
|
|
|
|
|
|
_generating_world = true;
|
|
|
|
_generating_world = true;
|
|
|
|
if (!GenerateTowns()) ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0);
|
|
|
|
if (!GenerateTowns()) ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0);
|
|
|
@ -665,42 +669,45 @@ static void ScenEditTownGenWndProc(Window *w, WindowEvent *e)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case TSEW_SMALLTOWN: case TSEW_MEDIUMTOWN: case TSEW_LARGETOWN: case TSEW_CITY:
|
|
|
|
case TSEW_SMALLTOWN: case TSEW_MEDIUMTOWN: case TSEW_LARGETOWN: case TSEW_CITY:
|
|
|
|
w->RaiseWidget(_scengen_town_size + TSEW_SMALLTOWN);
|
|
|
|
this->RaiseWidget(_scengen_town_size + TSEW_SMALLTOWN);
|
|
|
|
_scengen_town_size = e->we.click.widget - TSEW_SMALLTOWN;
|
|
|
|
_scengen_town_size = widget - TSEW_SMALLTOWN;
|
|
|
|
w->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
|
|
|
|
this->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
|
|
|
|
w->SetDirty();
|
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case WE_TIMEOUT:
|
|
|
|
|
|
|
|
w->RaiseWidget(TSEW_RANDOMTOWN);
|
|
|
|
|
|
|
|
w->RaiseWidget(TSEW_MANYRANDOMTOWNS);
|
|
|
|
|
|
|
|
w->SetDirty();
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case WE_PLACE_OBJ:
|
|
|
|
virtual void OnTimeout()
|
|
|
|
_place_proc(e->we.place.tile);
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
this->RaiseWidget(TSEW_RANDOMTOWN);
|
|
|
|
|
|
|
|
this->RaiseWidget(TSEW_MANYRANDOMTOWNS);
|
|
|
|
|
|
|
|
this->SetDirty();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case WE_ABORT_PLACE_OBJ:
|
|
|
|
virtual void OnPlaceObject(Point pt, TileIndex tile)
|
|
|
|
w->RaiseButtons();
|
|
|
|
{
|
|
|
|
w->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
|
|
|
|
_place_proc(tile);
|
|
|
|
w->SetDirty();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual void OnPlaceObjectAbort()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this->RaiseButtons();
|
|
|
|
|
|
|
|
this->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
|
|
|
|
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const WindowDesc _scen_edit_town_gen_desc = {
|
|
|
|
static const WindowDesc _scen_edit_town_gen_desc = {
|
|
|
|
WDP_AUTO, WDP_AUTO, 160, 95, 160, 95,
|
|
|
|
WDP_AUTO, WDP_AUTO, 160, 95, 160, 95,
|
|
|
|
WC_SCEN_TOWN_GEN, WC_NONE,
|
|
|
|
WC_SCEN_TOWN_GEN, WC_NONE,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
|
|
|
_scen_edit_town_gen_widgets,
|
|
|
|
_scen_edit_town_gen_widgets,
|
|
|
|
ScenEditTownGenWndProc,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void ShowBuildTownWindow()
|
|
|
|
void ShowBuildTownWindow()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (_game_mode != GM_EDITOR && !IsValidPlayer(_current_player)) return;
|
|
|
|
if (_game_mode != GM_EDITOR && !IsValidPlayer(_current_player)) return;
|
|
|
|
AllocateWindowDescFront<Window>(&_scen_edit_town_gen_desc, 0);
|
|
|
|
AllocateWindowDescFront<ScenarioEditorTownGenerationWindow>(&_scen_edit_town_gen_desc, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|