2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file terraform_gui.cpp GUI related to terraforming the map. */
|
2007-04-04 03:21:14 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "clear_map.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_func.h"
|
|
|
|
#include "company_base.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "gui.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_gui.h"
|
2009-01-02 21:01:13 +00:00
|
|
|
#include "window_func.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "viewport_func.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2008-03-31 07:25:49 +00:00
|
|
|
#include "signs_func.h"
|
2007-12-29 09:24:26 +00:00
|
|
|
#include "sound_func.h"
|
2009-07-22 11:35:35 +00:00
|
|
|
#include "base_station_base.h"
|
2008-01-06 18:56:43 +00:00
|
|
|
#include "textbuf_gui.h"
|
2008-01-09 21:05:03 +00:00
|
|
|
#include "genworld.h"
|
2008-01-31 17:54:13 +00:00
|
|
|
#include "tree_map.h"
|
2008-05-07 09:07:19 +00:00
|
|
|
#include "landscape_type.h"
|
2008-05-07 13:10:15 +00:00
|
|
|
#include "tilehighlight_func.h"
|
2009-11-28 14:30:00 +00:00
|
|
|
#include "strings_func.h"
|
2010-08-28 19:43:41 +00:00
|
|
|
#include "newgrf_object.h"
|
|
|
|
#include "object.h"
|
2010-07-03 13:28:48 +00:00
|
|
|
#include "hotkeys.h"
|
2011-02-05 16:07:23 +00:00
|
|
|
#include "engine_base.h"
|
2013-06-15 15:05:54 +00:00
|
|
|
#include "terraform_gui.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-12-15 22:22:55 +00:00
|
|
|
#include "widgets/terraform_widget.h"
|
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2010-01-11 18:46:09 +00:00
|
|
|
void CcTerraform(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-01-11 18:46:09 +00:00
|
|
|
if (result.Succeeded()) {
|
2012-12-23 21:09:09 +00:00
|
|
|
if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_SPLAT, tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2008-01-07 00:45:05 +00:00
|
|
|
extern TileIndex _terraform_err_tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
SetRedErrorSquare(_terraform_err_tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
- Fix: 'L' no longer opens ingame terraform bar in scenario editor bar, but the land generator one
- Feature: [ 1095110 ] Create Lake and draggable Create Desert tools (initial implementation GoneWacko), also added sticky buttons to land generator and town generator
- CodeChange: moved around some of the draggable tools, demystifying them
- CodeChange: change CmdBuildCanal to allow for XANDY dragging not only X or Y (only scenario editor)
- CodeChange: add some more enums to sprites.
- TODO: merge most of the ingame and scenario editor land terraform code. This can only be done after OnClickButton function is changed so it also includes the backreference to the widget being clicked, postponed to after 0.4.0
2005-04-02 23:05:09 +00:00
|
|
|
/** Scenario editor command that generates desert areas */
|
|
|
|
static void GenerateDesertArea(TileIndex end, TileIndex start)
|
|
|
|
{
|
|
|
|
if (_game_mode != GM_EDITOR) return;
|
|
|
|
|
2005-04-19 18:30:31 +00:00
|
|
|
_generating_world = true;
|
2010-01-04 18:49:27 +00:00
|
|
|
|
|
|
|
TileArea ta(start, end);
|
|
|
|
TILE_AREA_LOOP(tile, ta) {
|
2009-05-13 10:57:32 +00:00
|
|
|
SetTropicZone(tile, (_ctrl_pressed) ? TROPICZONE_NORMAL : TROPICZONE_DESERT);
|
|
|
|
DoCommandP(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
|
|
|
|
MarkTileDirtyByTile(tile);
|
2009-07-26 21:50:30 +00:00
|
|
|
}
|
2005-04-19 18:30:31 +00:00
|
|
|
_generating_world = false;
|
2011-01-30 19:14:48 +00:00
|
|
|
InvalidateWindowClassesData(WC_TOWN_VIEW, 0);
|
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
- Fix: 'L' no longer opens ingame terraform bar in scenario editor bar, but the land generator one
- Feature: [ 1095110 ] Create Lake and draggable Create Desert tools (initial implementation GoneWacko), also added sticky buttons to land generator and town generator
- CodeChange: moved around some of the draggable tools, demystifying them
- CodeChange: change CmdBuildCanal to allow for XANDY dragging not only X or Y (only scenario editor)
- CodeChange: add some more enums to sprites.
- TODO: merge most of the ingame and scenario editor land terraform code. This can only be done after OnClickButton function is changed so it also includes the backreference to the widget being clicked, postponed to after 0.4.0
2005-04-02 23:05:09 +00:00
|
|
|
}
|
|
|
|
|
2006-02-13 21:15:00 +00:00
|
|
|
/** Scenario editor command that generates rocky areas */
|
2005-11-07 16:19:45 +00:00
|
|
|
static void GenerateRockyArea(TileIndex end, TileIndex start)
|
|
|
|
{
|
|
|
|
if (_game_mode != GM_EDITOR) return;
|
|
|
|
|
2010-01-04 18:49:27 +00:00
|
|
|
bool success = false;
|
|
|
|
TileArea ta(start, end);
|
2005-11-07 16:19:45 +00:00
|
|
|
|
2010-01-04 18:49:27 +00:00
|
|
|
TILE_AREA_LOOP(tile, ta) {
|
2006-12-27 12:38:02 +00:00
|
|
|
switch (GetTileType(tile)) {
|
|
|
|
case MP_TREES:
|
2008-01-31 17:54:13 +00:00
|
|
|
if (GetTreeGround(tile) == TREE_GROUND_SHORE) continue;
|
2010-08-01 20:52:11 +00:00
|
|
|
/* FALL THROUGH */
|
2008-01-31 17:54:13 +00:00
|
|
|
case MP_CLEAR:
|
2006-12-27 12:38:02 +00:00
|
|
|
MakeClear(tile, CLEAR_ROCKS, 3);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: continue;
|
2005-11-07 16:19:45 +00:00
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
success = true;
|
2009-07-26 21:50:30 +00:00
|
|
|
}
|
2005-11-07 16:19:45 +00:00
|
|
|
|
2012-12-23 21:09:09 +00:00
|
|
|
if (success && _settings_client.sound.confirm) SndPlayTileFx(SND_1F_SPLAT, end);
|
2005-11-07 16:19:45 +00:00
|
|
|
}
|
|
|
|
|
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
- Fix: 'L' no longer opens ingame terraform bar in scenario editor bar, but the land generator one
- Feature: [ 1095110 ] Create Lake and draggable Create Desert tools (initial implementation GoneWacko), also added sticky buttons to land generator and town generator
- CodeChange: moved around some of the draggable tools, demystifying them
- CodeChange: change CmdBuildCanal to allow for XANDY dragging not only X or Y (only scenario editor)
- CodeChange: add some more enums to sprites.
- TODO: merge most of the ingame and scenario editor land terraform code. This can only be done after OnClickButton function is changed so it also includes the backreference to the widget being clicked, postponed to after 0.4.0
2005-04-02 23:05:09 +00:00
|
|
|
/**
|
|
|
|
* A central place to handle all X_AND_Y dragged GUI functions.
|
2009-09-19 09:51:14 +00:00
|
|
|
* @param proc Procedure related to the dragging
|
|
|
|
* @param start_tile Begin of the dragging
|
|
|
|
* @param end_tile End of the dragging
|
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
- Fix: 'L' no longer opens ingame terraform bar in scenario editor bar, but the land generator one
- Feature: [ 1095110 ] Create Lake and draggable Create Desert tools (initial implementation GoneWacko), also added sticky buttons to land generator and town generator
- CodeChange: moved around some of the draggable tools, demystifying them
- CodeChange: change CmdBuildCanal to allow for XANDY dragging not only X or Y (only scenario editor)
- CodeChange: add some more enums to sprites.
- TODO: merge most of the ingame and scenario editor land terraform code. This can only be done after OnClickButton function is changed so it also includes the backreference to the widget being clicked, postponed to after 0.4.0
2005-04-02 23:05:09 +00:00
|
|
|
* @return Returns true if the action was found and handled, and false otherwise. This
|
|
|
|
* allows for additional implements that are more local. For example X_Y drag
|
2007-04-04 03:21:14 +00:00
|
|
|
* of convertrail which belongs in rail_gui.cpp and not terraform_gui.cpp
|
2010-08-01 19:44:49 +00:00
|
|
|
*/
|
2008-05-18 12:40:38 +00:00
|
|
|
bool GUIPlaceProcDragXY(ViewportDragDropSelectionProcess proc, TileIndex start_tile, TileIndex end_tile)
|
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
- Fix: 'L' no longer opens ingame terraform bar in scenario editor bar, but the land generator one
- Feature: [ 1095110 ] Create Lake and draggable Create Desert tools (initial implementation GoneWacko), also added sticky buttons to land generator and town generator
- CodeChange: moved around some of the draggable tools, demystifying them
- CodeChange: change CmdBuildCanal to allow for XANDY dragging not only X or Y (only scenario editor)
- CodeChange: add some more enums to sprites.
- TODO: merge most of the ingame and scenario editor land terraform code. This can only be done after OnClickButton function is changed so it also includes the backreference to the widget being clicked, postponed to after 0.4.0
2005-04-02 23:05:09 +00:00
|
|
|
{
|
2009-01-21 02:31:55 +00:00
|
|
|
if (!_settings_game.construction.freeform_edges) {
|
|
|
|
/* When end_tile is MP_VOID, the error tile will not be visible to the
|
|
|
|
* user. This happens when terraforming at the southern border. */
|
|
|
|
if (TileX(end_tile) == MapMaxX()) end_tile += TileDiffXY(-1, 0);
|
|
|
|
if (TileY(end_tile) == MapMaxY()) end_tile += TileDiffXY(0, -1);
|
|
|
|
}
|
2009-01-14 13:11:39 +00:00
|
|
|
|
2008-05-18 12:40:38 +00:00
|
|
|
switch (proc) {
|
2007-05-23 13:52:10 +00:00
|
|
|
case DDSP_DEMOLISH_AREA:
|
2010-12-13 15:34:30 +00:00
|
|
|
DoCommandP(end_tile, start_tile, _ctrl_pressed ? 1 : 0, CMD_CLEAR_AREA | CMD_MSG(STR_ERROR_CAN_T_CLEAR_THIS_AREA), CcPlaySound10);
|
2007-05-23 12:45:56 +00:00
|
|
|
break;
|
2008-01-04 18:18:46 +00:00
|
|
|
case DDSP_RAISE_AND_LEVEL_AREA:
|
2010-12-13 15:34:30 +00:00
|
|
|
DoCommandP(end_tile, start_tile, LM_RAISE << 1 | (_ctrl_pressed ? 1 : 0), CMD_LEVEL_LAND | CMD_MSG(STR_ERROR_CAN_T_RAISE_LAND_HERE), CcTerraform);
|
2008-01-04 18:18:46 +00:00
|
|
|
break;
|
|
|
|
case DDSP_LOWER_AND_LEVEL_AREA:
|
2010-12-13 15:34:30 +00:00
|
|
|
DoCommandP(end_tile, start_tile, LM_LOWER << 1 | (_ctrl_pressed ? 1 : 0), CMD_LEVEL_LAND | CMD_MSG(STR_ERROR_CAN_T_LOWER_LAND_HERE), CcTerraform);
|
2008-01-04 18:18:46 +00:00
|
|
|
break;
|
2007-05-23 13:52:10 +00:00
|
|
|
case DDSP_LEVEL_AREA:
|
2010-12-13 15:34:30 +00:00
|
|
|
DoCommandP(end_tile, start_tile, LM_LEVEL << 1 | (_ctrl_pressed ? 1 : 0), CMD_LEVEL_LAND | CMD_MSG(STR_ERROR_CAN_T_LEVEL_LAND_HERE), CcTerraform);
|
2007-05-23 12:45:56 +00:00
|
|
|
break;
|
2007-05-23 13:52:10 +00:00
|
|
|
case DDSP_CREATE_ROCKS:
|
2007-05-23 12:45:56 +00:00
|
|
|
GenerateRockyArea(end_tile, start_tile);
|
|
|
|
break;
|
2007-05-23 13:52:10 +00:00
|
|
|
case DDSP_CREATE_DESERT:
|
2007-05-23 12:45:56 +00:00
|
|
|
GenerateDesertArea(end_tile, start_tile);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
- Fix: 'L' no longer opens ingame terraform bar in scenario editor bar, but the land generator one
- Feature: [ 1095110 ] Create Lake and draggable Create Desert tools (initial implementation GoneWacko), also added sticky buttons to land generator and town generator
- CodeChange: moved around some of the draggable tools, demystifying them
- CodeChange: change CmdBuildCanal to allow for XANDY dragging not only X or Y (only scenario editor)
- CodeChange: add some more enums to sprites.
- TODO: merge most of the ingame and scenario editor land terraform code. This can only be done after OnClickButton function is changed so it also includes the backreference to the widget being clicked, postponed to after 0.4.0
2005-04-02 23:05:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-12-24 15:06:58 +00:00
|
|
|
/**
|
|
|
|
* Start a drag for demolishing an area.
|
|
|
|
* @param tile Position of one corner.
|
|
|
|
*/
|
2005-06-24 12:38:35 +00:00
|
|
|
void PlaceProc_DemolishArea(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-05-23 13:52:10 +00:00
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_DEMOLISH_AREA);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2010-12-24 15:06:18 +00:00
|
|
|
/** Terra form toolbar managing class. */
|
2008-05-18 21:53:45 +00:00
|
|
|
struct TerraformToolbarWindow : Window {
|
2010-12-24 15:06:18 +00:00
|
|
|
int last_user_action; ///< Last started user action.
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
TerraformToolbarWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
|
2008-05-18 21:53:45 +00:00
|
|
|
{
|
2010-08-28 19:43:41 +00:00
|
|
|
/* This is needed as we like to have the tree available on OnInit. */
|
2013-05-26 19:23:42 +00:00
|
|
|
this->CreateNestedTree();
|
|
|
|
this->FinishInitNested(window_number);
|
2010-12-24 15:06:18 +00:00
|
|
|
this->last_user_action = WIDGET_LIST_END;
|
2008-05-18 21:53:45 +00:00
|
|
|
}
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2008-05-18 21:53:45 +00:00
|
|
|
~TerraformToolbarWindow()
|
|
|
|
{
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-08-28 19:43:41 +00:00
|
|
|
virtual void OnInit()
|
|
|
|
{
|
|
|
|
/* Don't show the place object button when there are no objects to place. */
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidgetStacked *show_object = this->GetWidget<NWidgetStacked>(WID_TT_SHOW_PLACE_OBJECT);
|
2012-04-22 16:28:37 +00:00
|
|
|
show_object->SetDisplayedPlane(ObjectClass::GetUIClassCount() != 0 ? 0 : SZSP_NONE);
|
2010-08-28 19:43:41 +00:00
|
|
|
}
|
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
2008-05-18 21:53:45 +00:00
|
|
|
{
|
2011-12-16 18:21:13 +00:00
|
|
|
if (widget < WID_TT_BUTTONS_START) return;
|
2010-12-24 15:03:19 +00:00
|
|
|
|
|
|
|
switch (widget) {
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_TT_LOWER_LAND: // Lower land button
|
|
|
|
HandlePlacePushButton(this, WID_TT_LOWER_LAND, ANIMCURSOR_LOWERLAND, HT_POINT | HT_DIAGONAL);
|
2010-12-24 15:06:18 +00:00
|
|
|
this->last_user_action = widget;
|
2010-12-24 15:03:19 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_TT_RAISE_LAND: // Raise land button
|
|
|
|
HandlePlacePushButton(this, WID_TT_RAISE_LAND, ANIMCURSOR_RAISELAND, HT_POINT | HT_DIAGONAL);
|
2010-12-24 15:06:18 +00:00
|
|
|
this->last_user_action = widget;
|
2010-12-24 15:03:19 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_TT_LEVEL_LAND: // Level land button
|
|
|
|
HandlePlacePushButton(this, WID_TT_LEVEL_LAND, SPR_CURSOR_LEVEL_LAND, HT_POINT | HT_DIAGONAL);
|
2010-12-24 15:06:18 +00:00
|
|
|
this->last_user_action = widget;
|
2010-12-24 15:03:19 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_TT_DEMOLISH: // Demolish aka dynamite button
|
|
|
|
HandlePlacePushButton(this, WID_TT_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL);
|
2010-12-24 15:06:18 +00:00
|
|
|
this->last_user_action = widget;
|
2010-12-24 15:03:19 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_TT_BUY_LAND: // Buy land button
|
|
|
|
HandlePlacePushButton(this, WID_TT_BUY_LAND, SPR_CURSOR_BUY_LAND, HT_RECT);
|
2010-12-24 15:06:18 +00:00
|
|
|
this->last_user_action = widget;
|
2010-12-24 15:03:19 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_TT_PLANT_TREES: // Plant trees button
|
2010-12-24 15:04:33 +00:00
|
|
|
ShowBuildTreesToolbar();
|
2010-12-24 15:03:19 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_TT_PLACE_SIGN: // Place sign button
|
|
|
|
HandlePlacePushButton(this, WID_TT_PLACE_SIGN, SPR_CURSOR_SIGN, HT_RECT);
|
2010-12-24 15:06:18 +00:00
|
|
|
this->last_user_action = widget;
|
2010-12-24 15:03:19 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_TT_PLACE_OBJECT: // Place object button
|
2010-12-24 15:04:33 +00:00
|
|
|
/* Don't show the place object button when there are no objects to place. */
|
2012-04-22 16:28:37 +00:00
|
|
|
if (ObjectClass::GetUIClassCount() == 0) return;
|
2011-12-16 18:21:13 +00:00
|
|
|
if (HandlePlacePushButton(this, WID_TT_PLACE_OBJECT, SPR_CURSOR_TRANSMITTER, HT_RECT)) {
|
2010-12-24 15:06:18 +00:00
|
|
|
ShowBuildObjectPicker(this);
|
|
|
|
this->last_user_action = widget;
|
|
|
|
}
|
2010-12-24 15:03:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
2008-05-18 21:53:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnPlaceObject(Point pt, TileIndex tile)
|
|
|
|
{
|
2010-12-24 15:06:18 +00:00
|
|
|
switch (this->last_user_action) {
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_TT_LOWER_LAND: // Lower land button
|
2010-12-24 15:06:58 +00:00
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_LOWER_AND_LEVEL_AREA);
|
2010-12-24 15:06:18 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_TT_RAISE_LAND: // Raise land button
|
2010-12-24 15:06:58 +00:00
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_RAISE_AND_LEVEL_AREA);
|
2010-12-24 15:06:18 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_TT_LEVEL_LAND: // Level land button
|
2010-12-24 15:06:58 +00:00
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_LEVEL_AREA);
|
2010-12-24 15:06:18 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_TT_DEMOLISH: // Demolish aka dynamite button
|
2010-12-24 15:06:18 +00:00
|
|
|
PlaceProc_DemolishArea(tile);
|
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_TT_BUY_LAND: // Buy land button
|
2010-12-24 15:06:58 +00:00
|
|
|
DoCommandP(tile, OBJECT_OWNED_LAND, 0, CMD_BUILD_OBJECT | CMD_MSG(STR_ERROR_CAN_T_PURCHASE_THIS_LAND), CcPlaySound1E);
|
2010-12-24 15:06:18 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_TT_PLACE_SIGN: // Place sign button
|
2010-12-24 15:06:18 +00:00
|
|
|
PlaceProc_Sign(tile);
|
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_TT_PLACE_OBJECT: // Place object button
|
2010-12-24 15:06:18 +00:00
|
|
|
PlaceProc_Object(tile);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
2008-05-18 21:53:45 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 21:53:45 +00:00
|
|
|
virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
|
|
|
|
{
|
|
|
|
VpSelectTilesWithMethod(pt.x, pt.y, select_method);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
|
2009-11-28 14:30:00 +00:00
|
|
|
{
|
|
|
|
Point pt = GetToolbarAlignedWindowPosition(sm_width);
|
|
|
|
pt.y += sm_height;
|
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
2008-05-18 21:53:45 +00:00
|
|
|
virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
|
|
|
|
{
|
|
|
|
if (pt.x != -1) {
|
|
|
|
switch (select_proc) {
|
2008-05-18 12:40:38 +00:00
|
|
|
default: NOT_REACHED();
|
2007-05-23 13:52:10 +00:00
|
|
|
case DDSP_DEMOLISH_AREA:
|
2008-01-04 18:18:46 +00:00
|
|
|
case DDSP_RAISE_AND_LEVEL_AREA:
|
|
|
|
case DDSP_LOWER_AND_LEVEL_AREA:
|
2007-05-23 13:52:10 +00:00
|
|
|
case DDSP_LEVEL_AREA:
|
2008-05-18 21:53:45 +00:00
|
|
|
GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
|
2007-05-23 13:52:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-18 21:53:45 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 21:53:45 +00:00
|
|
|
virtual void OnPlaceObjectAbort()
|
|
|
|
{
|
2010-08-28 19:43:41 +00:00
|
|
|
DeleteWindowById(WC_BUILD_OBJECT, 0);
|
2008-05-18 21:53:45 +00:00
|
|
|
this->RaiseButtons();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2010-07-03 13:28:48 +00:00
|
|
|
|
2013-06-15 15:28:09 +00:00
|
|
|
static HotkeyList hotkeys;
|
2010-07-03 13:28:48 +00:00
|
|
|
};
|
|
|
|
|
2013-06-15 15:31:22 +00:00
|
|
|
/**
|
|
|
|
* Handler for global hotkeys of the TerraformToolbarWindow.
|
|
|
|
* @param hotkey Hotkey
|
|
|
|
* @return ES_HANDLED if hotkey was accepted.
|
|
|
|
*/
|
|
|
|
static EventState TerraformToolbarGlobalHotkeys(int hotkey)
|
|
|
|
{
|
|
|
|
if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
|
|
|
|
Window *w = ShowTerraformToolbar(NULL);
|
|
|
|
if (w == NULL) return ES_NOT_HANDLED;
|
|
|
|
return w->OnHotkey(hotkey);
|
|
|
|
}
|
|
|
|
|
2013-06-15 15:28:09 +00:00
|
|
|
static Hotkey terraform_hotkeys[] = {
|
2013-06-15 15:27:33 +00:00
|
|
|
Hotkey('Q' | WKC_GLOBAL_HOTKEY, "lower", WID_TT_LOWER_LAND),
|
|
|
|
Hotkey('W' | WKC_GLOBAL_HOTKEY, "raise", WID_TT_RAISE_LAND),
|
|
|
|
Hotkey('E' | WKC_GLOBAL_HOTKEY, "level", WID_TT_LEVEL_LAND),
|
|
|
|
Hotkey('D' | WKC_GLOBAL_HOTKEY, "dynamite", WID_TT_DEMOLISH),
|
|
|
|
Hotkey('U', "buyland", WID_TT_BUY_LAND),
|
|
|
|
Hotkey('I', "trees", WID_TT_PLANT_TREES),
|
|
|
|
Hotkey('O', "placesign", WID_TT_PLACE_SIGN),
|
|
|
|
Hotkey('P', "placeobject", WID_TT_PLACE_OBJECT),
|
|
|
|
HOTKEY_LIST_END
|
2008-05-18 21:53:45 +00:00
|
|
|
};
|
2013-06-15 15:31:22 +00:00
|
|
|
HotkeyList TerraformToolbarWindow::hotkeys("terraform", terraform_hotkeys, TerraformToolbarGlobalHotkeys);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-04-18 07:49:20 +00:00
|
|
|
static const NWidgetPart _nested_terraform_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_LANDSCAPING_TOOLBAR, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
|
2009-04-18 07:49:20 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_LOWER_LAND), SetMinimalSize(22, 22),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_TERRAFORM_DOWN, STR_LANDSCAPING_TOOLTIP_LOWER_A_CORNER_OF_LAND),
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_RAISE_LAND), SetMinimalSize(22, 22),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_TERRAFORM_UP, STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND),
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_LEVEL_LAND), SetMinimalSize(22, 22),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_LEVEL_LAND, STR_LANDSCAPING_LEVEL_LAND_TOOLTIP),
|
2009-07-18 15:29:16 +00:00
|
|
|
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(4, 22), EndContainer(),
|
2009-07-18 15:29:16 +00:00
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_DEMOLISH), SetMinimalSize(22, 22),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_BUY_LAND), SetMinimalSize(22, 22),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_BUY_LAND, STR_LANDSCAPING_TOOLTIP_PURCHASE_LAND),
|
2012-11-11 16:07:46 +00:00
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_DARK_GREEN, WID_TT_PLANT_TREES), SetMinimalSize(22, 22),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_PLANTTREES, STR_SCENEDIT_TOOLBAR_PLANT_TREES),
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_PLACE_SIGN), SetMinimalSize(22, 22),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_SIGN, STR_SCENEDIT_TOOLBAR_PLACE_SIGN),
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_TT_SHOW_PLACE_OBJECT),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_PLACE_OBJECT), SetMinimalSize(22, 22),
|
2010-08-28 19:43:41 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_TRANSMITTER, STR_SCENEDIT_TOOLBAR_PLACE_OBJECT),
|
|
|
|
EndContainer(),
|
2009-04-18 07:49:20 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc _terraform_desc(
|
2013-05-26 19:25:01 +00:00
|
|
|
WDP_MANUAL, "toolbar_landscape", 0, 0,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_SCEN_LAND_GEN, WC_NONE,
|
2012-11-11 16:10:43 +00:00
|
|
|
WDF_CONSTRUCTION,
|
2013-06-15 15:30:44 +00:00
|
|
|
_nested_terraform_widgets, lengthof(_nested_terraform_widgets),
|
|
|
|
&TerraformToolbarWindow::hotkeys
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-05-01 19:14:12 +00:00
|
|
|
/**
|
|
|
|
* Show the toolbar for terraforming in the game.
|
|
|
|
* @param link The toolbar we might want to link to.
|
|
|
|
* @return The allocated toolbar.
|
|
|
|
*/
|
2009-06-01 14:36:36 +00:00
|
|
|
Window *ShowTerraformToolbar(Window *link)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-06-01 14:36:36 +00:00
|
|
|
if (!Company::IsValidID(_local_company)) return NULL;
|
2009-01-02 21:01:13 +00:00
|
|
|
|
2010-04-22 19:41:36 +00:00
|
|
|
Window *w;
|
|
|
|
if (link == NULL) {
|
|
|
|
w = AllocateWindowDescFront<TerraformToolbarWindow>(&_terraform_desc, 0);
|
|
|
|
return w;
|
2007-01-28 10:09:40 +00:00
|
|
|
}
|
2009-01-02 21:01:13 +00:00
|
|
|
|
2010-04-22 19:41:36 +00:00
|
|
|
/* Delete the terraform toolbar to place it again. */
|
|
|
|
DeleteWindowById(WC_SCEN_LAND_GEN, 0, true);
|
|
|
|
w = AllocateWindowDescFront<TerraformToolbarWindow>(&_terraform_desc, 0);
|
|
|
|
/* Align the terraform toolbar under the main toolbar. */
|
|
|
|
w->top -= w->height;
|
|
|
|
w->SetDirty();
|
|
|
|
/* Put the linked toolbar to the left / right of it. */
|
2010-11-13 09:56:25 +00:00
|
|
|
link->left = w->left + (_current_text_dir == TD_RTL ? w->width : -link->width);
|
2009-01-02 21:01:13 +00:00
|
|
|
link->top = w->top;
|
|
|
|
link->SetDirty();
|
2009-06-01 14:36:36 +00:00
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2008-01-06 18:56:43 +00:00
|
|
|
static byte _terraform_size = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Raise/Lower a bigger chunk of land at the same time in the editor. When
|
|
|
|
* raising get the lowest point, when lowering the highest point, and set all
|
|
|
|
* tiles in the selection to that height.
|
|
|
|
* @todo : Incorporate into game itself to allow for ingame raising/lowering of
|
|
|
|
* larger chunks at the same time OR remove altogether, as we have 'level land' ?
|
|
|
|
* @param tile The top-left tile where the terraforming will start
|
|
|
|
* @param mode 1 for raising, 0 for lowering land
|
|
|
|
*/
|
|
|
|
static void CommonRaiseLowerBigLand(TileIndex tile, int mode)
|
|
|
|
{
|
|
|
|
if (_terraform_size == 1) {
|
|
|
|
StringID msg =
|
2009-04-21 23:40:56 +00:00
|
|
|
mode ? STR_ERROR_CAN_T_RAISE_LAND_HERE : STR_ERROR_CAN_T_LOWER_LAND_HERE;
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2008-12-28 14:37:19 +00:00
|
|
|
DoCommandP(tile, SLOPE_N, (uint32)mode, CMD_TERRAFORM_LAND | CMD_MSG(msg), CcTerraform);
|
2008-01-06 18:56:43 +00:00
|
|
|
} else {
|
|
|
|
assert(_terraform_size != 0);
|
2010-12-12 18:05:34 +00:00
|
|
|
TileArea ta(tile, _terraform_size, _terraform_size);
|
|
|
|
ta.ClampToMap();
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2010-12-12 18:05:34 +00:00
|
|
|
if (ta.w == 0 || ta.h == 0) return;
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2012-12-23 21:09:09 +00:00
|
|
|
if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_SPLAT, tile);
|
2008-06-24 15:58:01 +00:00
|
|
|
|
2010-12-12 18:05:34 +00:00
|
|
|
uint h;
|
2008-01-06 18:56:43 +00:00
|
|
|
if (mode != 0) {
|
|
|
|
/* Raise land */
|
2010-12-12 18:05:34 +00:00
|
|
|
h = MAX_TILE_HEIGHT;
|
|
|
|
TILE_AREA_LOOP(tile2, ta) {
|
2008-01-06 18:56:43 +00:00
|
|
|
h = min(h, TileHeight(tile2));
|
2009-07-26 21:50:30 +00:00
|
|
|
}
|
2008-01-06 18:56:43 +00:00
|
|
|
} else {
|
|
|
|
/* Lower land */
|
|
|
|
h = 0;
|
2010-12-12 18:05:34 +00:00
|
|
|
TILE_AREA_LOOP(tile2, ta) {
|
2008-01-06 18:56:43 +00:00
|
|
|
h = max(h, TileHeight(tile2));
|
2009-07-26 21:50:30 +00:00
|
|
|
}
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
2010-12-12 18:05:34 +00:00
|
|
|
TILE_AREA_LOOP(tile2, ta) {
|
2008-01-06 18:56:43 +00:00
|
|
|
if (TileHeight(tile2) == h) {
|
2008-12-28 14:37:19 +00:00
|
|
|
DoCommandP(tile2, SLOPE_N, (uint32)mode, CMD_TERRAFORM_LAND);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
2009-07-26 21:50:30 +00:00
|
|
|
}
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const int8 _multi_terraform_coords[][2] = {
|
|
|
|
{ 0, -2},
|
|
|
|
{ 4, 0}, { -4, 0}, { 0, 2},
|
|
|
|
{ -8, 2}, { -4, 4}, { 0, 6}, { 4, 4}, { 8, 2},
|
|
|
|
{-12, 0}, { -8, -2}, { -4, -4}, { 0, -6}, { 4, -4}, { 8, -2}, { 12, 0},
|
|
|
|
{-16, 2}, {-12, 4}, { -8, 6}, { -4, 8}, { 0, 10}, { 4, 8}, { 8, 6}, { 12, 4}, { 16, 2},
|
|
|
|
{-20, 0}, {-16, -2}, {-12, -4}, { -8, -6}, { -4, -8}, { 0,-10}, { 4, -8}, { 8, -6}, { 12, -4}, { 16, -2}, { 20, 0},
|
|
|
|
{-24, 2}, {-20, 4}, {-16, 6}, {-12, 8}, { -8, 10}, { -4, 12}, { 0, 14}, { 4, 12}, { 8, 10}, { 12, 8}, { 16, 6}, { 20, 4}, { 24, 2},
|
|
|
|
{-28, 0}, {-24, -2}, {-20, -4}, {-16, -6}, {-12, -8}, { -8,-10}, { -4,-12}, { 0,-14}, { 4,-12}, { 8,-10}, { 12, -8}, { 16, -6}, { 20, -4}, { 24, -2}, { 28, 0},
|
|
|
|
};
|
|
|
|
|
2009-04-18 07:49:20 +00:00
|
|
|
static const NWidgetPart _nested_scen_edit_land_gen_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_TERRAFORM_TOOLBAR_LAND_GENERATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-12-21 16:24:29 +00:00
|
|
|
NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
|
2009-04-18 07:49:20 +00:00
|
|
|
EndContainer(),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
|
2009-07-18 15:29:16 +00:00
|
|
|
NWidget(NWID_HORIZONTAL), SetPadding(2, 2, 7, 2),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_DEMOLISH), SetMinimalSize(22, 22),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_LOWER_LAND), SetMinimalSize(22, 22),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_TERRAFORM_DOWN, STR_LANDSCAPING_TOOLTIP_LOWER_A_CORNER_OF_LAND),
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_RAISE_LAND), SetMinimalSize(22, 22),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_TERRAFORM_UP, STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND),
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_LEVEL_LAND), SetMinimalSize(22, 22),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_LEVEL_LAND, STR_LANDSCAPING_LEVEL_LAND_TOOLTIP),
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_PLACE_ROCKS), SetMinimalSize(22, 22),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_ROCKS, STR_TERRAFORM_TOOLTIP_PLACE_ROCKY_AREAS_ON_LANDSCAPE),
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_ETT_SHOW_PLACE_DESERT),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_PLACE_DESERT), SetMinimalSize(22, 22),
|
2010-08-28 19:45:56 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_DESERT, STR_TERRAFORM_TOOLTIP_DEFINE_DESERT_AREA),
|
|
|
|
EndContainer(),
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_PLACE_OBJECT), SetMinimalSize(23, 22),
|
2010-08-28 19:45:56 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_TRANSMITTER, STR_SCENEDIT_TOOLBAR_PLACE_OBJECT),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
2009-04-18 07:49:20 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(WWT_EMPTY, COLOUR_DARK_GREEN, WID_ETT_DOTS), SetMinimalSize(59, 31), SetDataTip(STR_EMPTY, STR_NULL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
2009-04-18 07:49:20 +00:00
|
|
|
NWidget(NWID_VERTICAL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(0, 1),
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_INCREASE_SIZE), SetMinimalSize(12, 12), SetDataTip(SPR_ARROW_UP, STR_TERRAFORM_TOOLTIP_INCREASE_SIZE_OF_LAND_AREA),
|
2009-04-18 07:49:20 +00:00
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 1),
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_DECREASE_SIZE), SetMinimalSize(12, 12), SetDataTip(SPR_ARROW_DOWN, STR_TERRAFORM_TOOLTIP_DECREASE_SIZE_OF_LAND_AREA),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(0, 1),
|
2009-04-18 07:49:20 +00:00
|
|
|
EndContainer(),
|
2009-07-18 15:29:16 +00:00
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(2, 0),
|
2009-04-18 07:49:20 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 6),
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_ETT_NEW_SCENARIO), SetMinimalSize(160, 12),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(1, 0), SetDataTip(STR_TERRAFORM_SE_NEW_WORLD, STR_TERRAFORM_TOOLTIP_GENERATE_RANDOM_LAND), SetPadding(0, 2, 0, 2),
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_ETT_RESET_LANDSCAPE), SetMinimalSize(160, 12),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(1, 0), SetDataTip(STR_TERRAFORM_RESET_LANDSCAPE, STR_TERRAFORM_RESET_LANDSCAPE_TOOLTIP), SetPadding(1, 2, 2, 2),
|
2009-04-18 07:49:20 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Callback function for the scenario editor 'reset landscape' confirmation window
|
2008-01-06 18:56:43 +00:00
|
|
|
* @param w Window unused
|
2010-08-01 19:44:49 +00:00
|
|
|
* @param confirmed boolean value, true when yes was clicked, false otherwise
|
|
|
|
*/
|
2008-01-06 18:56:43 +00:00
|
|
|
static void ResetLandscapeConfirmationCallback(Window *w, bool confirmed)
|
|
|
|
{
|
|
|
|
if (confirmed) {
|
|
|
|
/* Set generating_world to true to get instant-green grass after removing
|
2008-09-30 20:39:50 +00:00
|
|
|
* company property. */
|
2008-01-06 18:56:43 +00:00
|
|
|
_generating_world = true;
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
/* Delete all companies */
|
2009-05-11 18:17:21 +00:00
|
|
|
Company *c;
|
2008-09-30 20:39:50 +00:00
|
|
|
FOR_ALL_COMPANIES(c) {
|
|
|
|
ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER);
|
|
|
|
delete c;
|
2008-07-18 16:40:29 +00:00
|
|
|
}
|
2009-05-11 18:17:21 +00:00
|
|
|
|
2008-07-18 16:40:29 +00:00
|
|
|
_generating_world = false;
|
2009-05-11 18:17:21 +00:00
|
|
|
|
|
|
|
/* Delete all station signs */
|
2009-07-22 08:59:57 +00:00
|
|
|
BaseStation *st;
|
|
|
|
FOR_ALL_BASE_STATIONS(st) {
|
2009-05-11 18:17:21 +00:00
|
|
|
/* There can be buoys, remove them */
|
2009-07-22 08:59:57 +00:00
|
|
|
if (IsBuoyTile(st->xy)) DoCommand(st->xy, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
|
2009-07-24 07:38:10 +00:00
|
|
|
if (!st->IsInUse()) delete st;
|
2009-05-11 18:17:21 +00:00
|
|
|
}
|
|
|
|
|
2011-02-05 16:07:23 +00:00
|
|
|
/* Now that all vehicles are gone, we can reset the engine pool. Maybe it reduces some NewGRF changing-mess */
|
|
|
|
EngineOverrideManager::ResetToCurrentNewGRFConfig();
|
|
|
|
|
2009-05-11 18:17:21 +00:00
|
|
|
MarkWholeScreenDirty();
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-24 15:06:18 +00:00
|
|
|
/** Landscape generation window handler in the scenario editor. */
|
2008-05-18 21:53:45 +00:00
|
|
|
struct ScenarioEditorLandscapeGenerationWindow : Window {
|
2010-12-24 15:06:18 +00:00
|
|
|
int last_user_action; ///< Last started user action.
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
ScenarioEditorLandscapeGenerationWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
|
2008-05-18 21:53:45 +00:00
|
|
|
{
|
2013-05-26 19:23:42 +00:00
|
|
|
this->CreateNestedTree();
|
2011-12-16 18:21:13 +00:00
|
|
|
NWidgetStacked *show_desert = this->GetWidget<NWidgetStacked>(WID_ETT_SHOW_PLACE_DESERT);
|
2010-08-28 19:45:56 +00:00
|
|
|
show_desert->SetDisplayedPlane(_settings_game.game_creation.landscape == LT_TROPIC ? 0 : SZSP_NONE);
|
2013-05-26 19:23:42 +00:00
|
|
|
this->FinishInitNested(window_number);
|
2010-12-24 15:06:18 +00:00
|
|
|
this->last_user_action = WIDGET_LIST_END;
|
2008-05-18 21:53:45 +00:00
|
|
|
}
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2009-10-04 17:10:57 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
2008-05-18 21:53:45 +00:00
|
|
|
this->DrawWidgets();
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
if (this->IsWidgetLowered(WID_ETT_LOWER_LAND) || this->IsWidgetLowered(WID_ETT_RAISE_LAND)) { // change area-size if raise/lower corner is selected
|
2009-07-18 15:29:16 +00:00
|
|
|
SetTileSelectSize(_terraform_size, _terraform_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
2011-12-16 18:21:13 +00:00
|
|
|
if (widget != WID_ETT_DOTS) return;
|
2009-07-18 15:29:16 +00:00
|
|
|
|
2010-04-18 17:13:01 +00:00
|
|
|
int center_x = RoundDivSU(r.left + r.right, 2);
|
|
|
|
int center_y = RoundDivSU(r.top + r.bottom, 2);
|
2009-07-18 15:29:16 +00:00
|
|
|
|
2008-05-18 21:53:45 +00:00
|
|
|
int n = _terraform_size * _terraform_size;
|
|
|
|
const int8 *coords = &_multi_terraform_coords[0][0];
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2008-05-18 21:53:45 +00:00
|
|
|
assert(n != 0);
|
|
|
|
do {
|
2009-07-18 15:29:16 +00:00
|
|
|
DrawSprite(SPR_WHITE_POINT, PAL_NONE, center_x + coords[0], center_y + coords[1]);
|
2008-05-18 21:53:45 +00:00
|
|
|
coords += 2;
|
|
|
|
} while (--n);
|
|
|
|
}
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
2008-05-18 21:53:45 +00:00
|
|
|
{
|
2011-12-16 18:21:13 +00:00
|
|
|
if (widget < WID_ETT_BUTTONS_START) return;
|
2010-12-24 15:03:19 +00:00
|
|
|
|
|
|
|
switch (widget) {
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_ETT_DEMOLISH: // Demolish aka dynamite button
|
|
|
|
HandlePlacePushButton(this, WID_ETT_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL);
|
2010-12-24 15:06:18 +00:00
|
|
|
this->last_user_action = widget;
|
2010-12-24 15:03:19 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_ETT_LOWER_LAND: // Lower land button
|
|
|
|
HandlePlacePushButton(this, WID_ETT_LOWER_LAND, ANIMCURSOR_LOWERLAND, HT_POINT);
|
2010-12-24 15:06:18 +00:00
|
|
|
this->last_user_action = widget;
|
2010-12-24 15:03:19 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_ETT_RAISE_LAND: // Raise land button
|
|
|
|
HandlePlacePushButton(this, WID_ETT_RAISE_LAND, ANIMCURSOR_RAISELAND, HT_POINT);
|
2010-12-24 15:06:18 +00:00
|
|
|
this->last_user_action = widget;
|
2010-12-24 15:03:19 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_ETT_LEVEL_LAND: // Level land button
|
|
|
|
HandlePlacePushButton(this, WID_ETT_LEVEL_LAND, SPR_CURSOR_LEVEL_LAND, HT_POINT | HT_DIAGONAL);
|
2010-12-24 15:06:18 +00:00
|
|
|
this->last_user_action = widget;
|
2010-12-24 15:03:19 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_ETT_PLACE_ROCKS: // Place rocks button
|
|
|
|
HandlePlacePushButton(this, WID_ETT_PLACE_ROCKS, SPR_CURSOR_ROCKY_AREA, HT_RECT);
|
2010-12-24 15:06:18 +00:00
|
|
|
this->last_user_action = widget;
|
2010-12-24 15:03:19 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_ETT_PLACE_DESERT: // Place desert button (in tropical climate)
|
|
|
|
HandlePlacePushButton(this, WID_ETT_PLACE_DESERT, SPR_CURSOR_DESERT, HT_RECT);
|
2010-12-24 15:06:18 +00:00
|
|
|
this->last_user_action = widget;
|
2010-12-24 15:03:19 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_ETT_PLACE_OBJECT: // Place transmitter button
|
|
|
|
if (HandlePlacePushButton(this, WID_ETT_PLACE_OBJECT, SPR_CURSOR_TRANSMITTER, HT_RECT)) {
|
2010-12-24 15:06:18 +00:00
|
|
|
ShowBuildObjectPicker(this);
|
|
|
|
this->last_user_action = widget;
|
|
|
|
}
|
2010-12-24 15:03:19 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_ETT_INCREASE_SIZE:
|
|
|
|
case WID_ETT_DECREASE_SIZE: { // Increase/Decrease terraform size
|
|
|
|
int size = (widget == WID_ETT_INCREASE_SIZE) ? 1 : -1;
|
2010-12-24 15:03:19 +00:00
|
|
|
this->HandleButtonClick(widget);
|
|
|
|
size += _terraform_size;
|
|
|
|
|
|
|
|
if (!IsInsideMM(size, 1, 8 + 1)) return;
|
|
|
|
_terraform_size = size;
|
|
|
|
|
2012-12-23 21:09:09 +00:00
|
|
|
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
|
2010-12-24 15:03:19 +00:00
|
|
|
this->SetDirty();
|
|
|
|
break;
|
2008-05-22 20:44:24 +00:00
|
|
|
}
|
2010-12-24 15:03:19 +00:00
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_ETT_NEW_SCENARIO: // gen random land
|
2010-12-24 15:03:19 +00:00
|
|
|
this->HandleButtonClick(widget);
|
|
|
|
ShowCreateScenario();
|
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_ETT_RESET_LANDSCAPE: // Reset landscape
|
2010-12-24 15:03:19 +00:00
|
|
|
ShowQuery(STR_QUERY_RESET_LANDSCAPE_CAPTION, STR_RESET_LANDSCAPE_CONFIRMATION_TEXT, NULL, ResetLandscapeConfirmationCallback);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
2008-05-18 21:53:45 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2008-05-18 21:53:45 +00:00
|
|
|
virtual void OnTimeout()
|
|
|
|
{
|
2011-12-16 18:21:13 +00:00
|
|
|
for (uint i = WID_ETT_START; i < this->nested_array_size; i++) {
|
|
|
|
if (i == WID_ETT_BUTTONS_START) i = WID_ETT_BUTTONS_END; // skip the buttons
|
2008-05-18 21:53:45 +00:00
|
|
|
if (this->IsWidgetLowered(i)) {
|
|
|
|
this->RaiseWidget(i);
|
2009-09-13 19:15:59 +00:00
|
|
|
this->SetWidgetDirty(i);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
2008-05-18 21:53:45 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2008-05-18 21:53:45 +00:00
|
|
|
virtual void OnPlaceObject(Point pt, TileIndex tile)
|
|
|
|
{
|
2010-12-24 15:06:18 +00:00
|
|
|
switch (this->last_user_action) {
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_ETT_DEMOLISH: // Demolish aka dynamite button
|
2010-12-24 15:06:18 +00:00
|
|
|
PlaceProc_DemolishArea(tile);
|
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_ETT_LOWER_LAND: // Lower land button
|
2010-12-24 15:06:58 +00:00
|
|
|
CommonRaiseLowerBigLand(tile, 0);
|
2010-12-24 15:06:18 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_ETT_RAISE_LAND: // Raise land button
|
2010-12-24 15:06:58 +00:00
|
|
|
CommonRaiseLowerBigLand(tile, 1);
|
2010-12-24 15:06:18 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_ETT_LEVEL_LAND: // Level land button
|
2010-12-24 15:06:58 +00:00
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_LEVEL_AREA);
|
2010-12-24 15:06:18 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_ETT_PLACE_ROCKS: // Place rocks button
|
2010-12-24 15:06:58 +00:00
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_ROCKS);
|
2010-12-24 15:06:18 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_ETT_PLACE_DESERT: // Place desert button (in tropical climate)
|
2010-12-24 15:06:58 +00:00
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_DESERT);
|
2010-12-24 15:06:18 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 18:21:13 +00:00
|
|
|
case WID_ETT_PLACE_OBJECT: // Place transmitter button
|
2010-12-24 15:06:18 +00:00
|
|
|
PlaceProc_Object(tile);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
2008-05-18 21:53:45 +00:00
|
|
|
}
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2008-05-18 21:53:45 +00:00
|
|
|
virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
|
|
|
|
{
|
|
|
|
VpSelectTilesWithMethod(pt.x, pt.y, select_method);
|
|
|
|
}
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2008-05-18 21:53:45 +00:00
|
|
|
virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
|
|
|
|
{
|
|
|
|
if (pt.x != -1) {
|
|
|
|
switch (select_proc) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case DDSP_CREATE_ROCKS:
|
|
|
|
case DDSP_CREATE_DESERT:
|
|
|
|
case DDSP_RAISE_AND_LEVEL_AREA:
|
|
|
|
case DDSP_LOWER_AND_LEVEL_AREA:
|
|
|
|
case DDSP_LEVEL_AREA:
|
|
|
|
case DDSP_DEMOLISH_AREA:
|
|
|
|
GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
|
|
|
|
break;
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
2008-05-18 21:53:45 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2008-05-18 21:53:45 +00:00
|
|
|
virtual void OnPlaceObjectAbort()
|
|
|
|
{
|
|
|
|
this->RaiseButtons();
|
|
|
|
this->SetDirty();
|
2010-08-28 19:45:56 +00:00
|
|
|
DeleteWindowById(WC_BUILD_OBJECT, 0);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
2010-07-03 13:29:01 +00:00
|
|
|
|
2013-06-15 15:28:09 +00:00
|
|
|
static HotkeyList hotkeys;
|
2010-07-03 13:29:01 +00:00
|
|
|
};
|
|
|
|
|
2013-06-15 15:31:22 +00:00
|
|
|
/**
|
|
|
|
* Handler for global hotkeys of the ScenarioEditorLandscapeGenerationWindow.
|
|
|
|
* @param hotkey Hotkey
|
|
|
|
* @return ES_HANDLED if hotkey was accepted.
|
|
|
|
*/
|
|
|
|
static EventState TerraformToolbarEditorGlobalHotkeys(int hotkey)
|
|
|
|
{
|
|
|
|
if (_game_mode != GM_EDITOR) return ES_NOT_HANDLED;
|
|
|
|
Window *w = ShowEditorTerraformToolbar();
|
|
|
|
if (w == NULL) return ES_NOT_HANDLED;
|
|
|
|
return w->OnHotkey(hotkey);
|
|
|
|
}
|
|
|
|
|
2013-06-15 15:28:09 +00:00
|
|
|
static Hotkey terraform_editor_hotkeys[] = {
|
2013-06-15 15:27:33 +00:00
|
|
|
Hotkey('D' | WKC_GLOBAL_HOTKEY, "dynamite", WID_ETT_DEMOLISH),
|
|
|
|
Hotkey('Q' | WKC_GLOBAL_HOTKEY, "lower", WID_ETT_LOWER_LAND),
|
|
|
|
Hotkey('W' | WKC_GLOBAL_HOTKEY, "raise", WID_ETT_RAISE_LAND),
|
|
|
|
Hotkey('E' | WKC_GLOBAL_HOTKEY, "level", WID_ETT_LEVEL_LAND),
|
|
|
|
Hotkey('R', "rocky", WID_ETT_PLACE_ROCKS),
|
|
|
|
Hotkey('T', "desert", WID_ETT_PLACE_DESERT),
|
|
|
|
Hotkey('O', "object", WID_ETT_PLACE_OBJECT),
|
|
|
|
HOTKEY_LIST_END
|
2008-05-18 21:53:45 +00:00
|
|
|
};
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2013-06-15 15:31:22 +00:00
|
|
|
HotkeyList ScenarioEditorLandscapeGenerationWindow::hotkeys("terraform_editor", terraform_editor_hotkeys, TerraformToolbarEditorGlobalHotkeys);
|
2010-07-03 13:29:01 +00:00
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc _scen_edit_land_gen_desc(
|
2013-05-26 19:25:01 +00:00
|
|
|
WDP_AUTO, "toolbar_landscape_scen", 0, 0,
|
2008-01-06 18:56:43 +00:00
|
|
|
WC_SCEN_LAND_GEN, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
WDF_CONSTRUCTION,
|
2013-06-15 15:30:44 +00:00
|
|
|
_nested_scen_edit_land_gen_widgets, lengthof(_nested_scen_edit_land_gen_widgets),
|
|
|
|
&ScenarioEditorLandscapeGenerationWindow::hotkeys
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2011-05-01 19:14:12 +00:00
|
|
|
/**
|
|
|
|
* Show the toolbar for terraforming in the scenario editor.
|
|
|
|
* @return The allocated toolbar.
|
|
|
|
*/
|
2009-06-01 14:36:36 +00:00
|
|
|
Window *ShowEditorTerraformToolbar()
|
|
|
|
{
|
|
|
|
return AllocateWindowDescFront<ScenarioEditorLandscapeGenerationWindow>(&_scen_edit_land_gen_desc, 0);
|
|
|
|
}
|