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"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "functions.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 "unmovable_map.h"
|
|
|
|
#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"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/sprites.h"
|
|
|
|
#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()) {
|
2004-12-04 09:26:39 +00:00
|
|
|
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;
|
(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;
|
|
|
|
/* FALL THROUGH */
|
|
|
|
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
|
|
|
|
|
|
|
if (success) SndPlayTileFx(SND_1F_SPLAT, end);
|
|
|
|
}
|
|
|
|
|
(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
|
(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
|
|
|
**/
|
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:
|
2009-04-21 23:40:56 +00:00
|
|
|
DoCommandP(end_tile, start_tile, 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:
|
2009-04-21 23:40:56 +00:00
|
|
|
DoCommandP(end_tile, start_tile, 1, 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:
|
2009-04-21 23:40:56 +00:00
|
|
|
DoCommandP(end_tile, start_tile, (uint32)-1, 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:
|
2009-04-21 23:40:56 +00:00
|
|
|
DoCommandP(end_tile, start_tile, 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
|
|
|
|
|
|
|
typedef void OnButtonClick(Window *w);
|
|
|
|
|
|
|
|
static const uint16 _terraform_keycodes[] = {
|
2004-12-12 17:42:04 +00:00
|
|
|
'Q',
|
|
|
|
'W',
|
|
|
|
'E',
|
2005-01-08 09:24:15 +00:00
|
|
|
'D',
|
2004-12-12 17:42:04 +00:00
|
|
|
'U',
|
|
|
|
'I',
|
2004-12-12 18:51:24 +00:00
|
|
|
'O',
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2008-05-08 13:30:50 +00:00
|
|
|
static void PlaceProc_BuyLand(TileIndex tile)
|
|
|
|
{
|
2009-04-21 23:40:56 +00:00
|
|
|
DoCommandP(tile, 0, 0, CMD_PURCHASE_LAND_AREA | CMD_MSG(STR_ERROR_CAN_T_PURCHASE_THIS_LAND), CcPlaySound1E);
|
2008-05-08 13:30:50 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-01-05 12:40:50 +00:00
|
|
|
static void PlaceProc_RaiseLand(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-01-04 18:18:46 +00:00
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_RAISE_AND_LEVEL_AREA);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-01-05 12:40:50 +00:00
|
|
|
static void PlaceProc_LowerLand(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-01-04 18:18:46 +00:00
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_LOWER_AND_LEVEL_AREA);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-05-08 13:30:50 +00:00
|
|
|
static void PlaceProc_LevelLand(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_LEVEL_AREA);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-05-22 20:44:24 +00:00
|
|
|
/** Enum referring to the widgets of the terraform toolbar */
|
|
|
|
enum TerraformToolbarWidgets {
|
|
|
|
TTW_BUTTONS_START, ///< Start of pushable buttons
|
|
|
|
TTW_LOWER_LAND = TTW_BUTTONS_START, ///< Lower land button
|
|
|
|
TTW_RAISE_LAND, ///< Raise land button
|
|
|
|
TTW_LEVEL_LAND, ///< Level land button
|
|
|
|
TTW_DEMOLISH, ///< Demolish aka dynamite button
|
|
|
|
TTW_BUY_LAND, ///< Buy land button
|
|
|
|
TTW_PLANT_TREES, ///< Plant trees button (note: opens seperate window, no place-push-button)
|
|
|
|
TTW_PLACE_SIGN, ///< Place sign button
|
|
|
|
};
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static void TerraformClick_Lower(Window *w)
|
|
|
|
{
|
2009-04-19 10:31:30 +00:00
|
|
|
HandlePlacePushButton(w, TTW_LOWER_LAND, ANIMCURSOR_LOWERLAND, HT_POINT, PlaceProc_LowerLand);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TerraformClick_Raise(Window *w)
|
|
|
|
{
|
2009-04-19 10:31:30 +00:00
|
|
|
HandlePlacePushButton(w, TTW_RAISE_LAND, ANIMCURSOR_RAISELAND, HT_POINT, PlaceProc_RaiseLand);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TerraformClick_Level(Window *w)
|
|
|
|
{
|
2009-04-19 10:31:30 +00:00
|
|
|
HandlePlacePushButton(w, TTW_LEVEL_LAND, SPR_CURSOR_LEVEL_LAND, HT_POINT, PlaceProc_LevelLand);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-01-08 09:24:15 +00:00
|
|
|
static void TerraformClick_Dynamite(Window *w)
|
|
|
|
{
|
2009-10-02 15:13:15 +00:00
|
|
|
HandlePlacePushButton(w, TTW_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT, PlaceProc_DemolishArea);
|
2005-01-08 09:24:15 +00:00
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static void TerraformClick_BuyLand(Window *w)
|
|
|
|
{
|
2009-04-19 10:31:30 +00:00
|
|
|
HandlePlacePushButton(w, TTW_BUY_LAND, SPR_CURSOR_BUY_LAND, HT_RECT, PlaceProc_BuyLand);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TerraformClick_Trees(Window *w)
|
|
|
|
{
|
2006-05-11 14:05:23 +00:00
|
|
|
/* This button is NOT a place-push-button, so don't treat it as such */
|
|
|
|
ShowBuildTreesToolbar();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TerraformClick_PlaceSign(Window *w)
|
|
|
|
{
|
2009-04-19 10:31:30 +00:00
|
|
|
HandlePlacePushButton(w, TTW_PLACE_SIGN, SPR_CURSOR_SIGN, HT_RECT, PlaceProc_Sign);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static OnButtonClick * const _terraform_button_proc[] = {
|
|
|
|
TerraformClick_Lower,
|
|
|
|
TerraformClick_Raise,
|
|
|
|
TerraformClick_Level,
|
2005-01-08 09:24:15 +00:00
|
|
|
TerraformClick_Dynamite,
|
2004-12-12 17:42:04 +00:00
|
|
|
TerraformClick_BuyLand,
|
2004-08-09 17:04:08 +00:00
|
|
|
TerraformClick_Trees,
|
|
|
|
TerraformClick_PlaceSign,
|
|
|
|
};
|
|
|
|
|
2008-05-18 21:53:45 +00:00
|
|
|
struct TerraformToolbarWindow : Window {
|
2009-07-18 15:29:16 +00:00
|
|
|
TerraformToolbarWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
|
2008-05-18 21:53:45 +00:00
|
|
|
{
|
2009-07-18 15:29:16 +00:00
|
|
|
this->InitNested(desc, window_number);
|
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
|
|
|
|
2008-05-18 21:53:45 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
this->DrawWidgets();
|
|
|
|
}
|
2004-12-12 22:05:08 +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
|
|
|
{
|
2008-05-22 20:44:24 +00:00
|
|
|
if (widget >= TTW_BUTTONS_START) _terraform_button_proc[widget - TTW_BUTTONS_START](this);
|
2008-05-18 21:53:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
|
|
|
{
|
|
|
|
for (uint i = 0; i != lengthof(_terraform_keycodes); i++) {
|
|
|
|
if (keycode == _terraform_keycodes[i]) {
|
|
|
|
_terraform_button_proc[i](this);
|
|
|
|
return ES_HANDLED;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2008-05-18 21:53:45 +00:00
|
|
|
return ES_NOT_HANDLED;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 21:53:45 +00:00
|
|
|
virtual void OnPlaceObject(Point pt, TileIndex tile)
|
|
|
|
{
|
|
|
|
_place_proc(tile);
|
|
|
|
}
|
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
|
|
|
|
2009-11-28 14:30:00 +00:00
|
|
|
virtual Point OnInitialPosition(const WindowDesc *desc, int16 sm_width, int16 sm_height, int window_number)
|
|
|
|
{
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
this->RaiseButtons();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-18 21:53:45 +00:00
|
|
|
};
|
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),
|
2009-07-18 15:29:16 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_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),
|
2009-07-18 15:29:16 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_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),
|
2009-07-18 15:29:16 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_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
|
|
|
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_DEMOLISH), SetMinimalSize(22,22),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
|
2009-07-18 15:29:16 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_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),
|
2009-07-18 15:29:16 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_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),
|
2009-07-18 15:29:16 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_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),
|
2009-04-18 07:49:20 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _terraform_desc(
|
2009-11-28 15:01:49 +00:00
|
|
|
WDP_MANUAL, 0, 0,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_SCEN_LAND_GEN, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
WDF_CONSTRUCTION,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_terraform_widgets, lengthof(_nested_terraform_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
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. */
|
2009-11-28 14:30:00 +00:00
|
|
|
link->left = w->left + (_dynlang.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShowTerraformToolbarWithTool(uint16 key, uint16 keycode)
|
|
|
|
{
|
|
|
|
Window *w = FindWindowById(WC_SCEN_LAND_GEN, 0);
|
|
|
|
|
|
|
|
if (w == NULL) w = ShowTerraformToolbar(NULL);
|
|
|
|
if (w == NULL) return;
|
|
|
|
|
|
|
|
w->OnKeyPress(key, keycode);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
int sizex, sizey;
|
|
|
|
uint h;
|
|
|
|
|
|
|
|
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);
|
|
|
|
/* check out for map overflows */
|
2009-01-21 02:31:55 +00:00
|
|
|
sizex = min(MapSizeX() - TileX(tile), _terraform_size);
|
|
|
|
sizey = min(MapSizeY() - TileY(tile), _terraform_size);
|
2008-01-06 18:56:43 +00:00
|
|
|
|
|
|
|
if (sizex == 0 || sizey == 0) return;
|
|
|
|
|
2008-06-24 15:58:01 +00:00
|
|
|
SndPlayTileFx(SND_1F_SPLAT, tile);
|
|
|
|
|
2008-01-06 18:56:43 +00:00
|
|
|
if (mode != 0) {
|
|
|
|
/* Raise land */
|
|
|
|
h = 15; // XXX - max height
|
2009-07-26 21:50:30 +00:00
|
|
|
TILE_LOOP(tile2, sizex, sizey, tile) {
|
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;
|
2009-07-26 21:50:30 +00:00
|
|
|
TILE_LOOP(tile2, sizex, sizey, tile) {
|
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
|
|
|
}
|
|
|
|
|
2009-07-26 21:50:30 +00:00
|
|
|
TILE_LOOP(tile2, sizex, sizey, tile) {
|
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 void PlaceProc_RaiseBigLand(TileIndex tile)
|
|
|
|
{
|
|
|
|
CommonRaiseLowerBigLand(tile, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PlaceProc_LowerBigLand(TileIndex tile)
|
|
|
|
{
|
|
|
|
CommonRaiseLowerBigLand(tile, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PlaceProc_RockyArea(TileIndex tile)
|
|
|
|
{
|
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_ROCKS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PlaceProc_LightHouse(TileIndex tile)
|
|
|
|
{
|
2008-02-02 20:15:20 +00:00
|
|
|
/* not flat || not(trees || clear without bridge above) */
|
|
|
|
if (GetTileSlope(tile, NULL) != SLOPE_FLAT || !(IsTileType(tile, MP_TREES) || (IsTileType(tile, MP_CLEAR) && !IsBridgeAbove(tile)))) {
|
2008-01-06 18:56:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MakeLighthouse(tile);
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
SndPlayTileFx(SND_1F_SPLAT, tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PlaceProc_Transmitter(TileIndex tile)
|
|
|
|
{
|
2008-02-02 20:15:20 +00:00
|
|
|
/* not flat || not(trees || clear without bridge above) */
|
|
|
|
if (GetTileSlope(tile, NULL) != SLOPE_FLAT || !(IsTileType(tile, MP_TREES) || (IsTileType(tile, MP_CLEAR) && !IsBridgeAbove(tile)))) {
|
2008-01-06 18:56:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MakeTransmitter(tile);
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
SndPlayTileFx(SND_1F_SPLAT, tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PlaceProc_DesertArea(TileIndex tile)
|
|
|
|
{
|
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_DESERT);
|
|
|
|
}
|
|
|
|
|
|
|
|
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},
|
|
|
|
};
|
|
|
|
|
2008-05-22 20:44:24 +00:00
|
|
|
/** Enum referring to the widgets of the editor terraform toolbar */
|
|
|
|
enum EditorTerraformToolbarWidgets {
|
|
|
|
ETTW_START = 0, ///< Used for iterations
|
2009-11-24 21:13:36 +00:00
|
|
|
ETTW_DOTS = ETTW_START, ///< Invisible widget for rendering the terraform size on.
|
2008-05-22 20:44:24 +00:00
|
|
|
ETTW_BUTTONS_START, ///< Start of pushable buttons
|
|
|
|
ETTW_DEMOLISH = ETTW_BUTTONS_START, ///< Demolish aka dynamite button
|
|
|
|
ETTW_LOWER_LAND, ///< Lower land button
|
|
|
|
ETTW_RAISE_LAND, ///< Raise land button
|
|
|
|
ETTW_LEVEL_LAND, ///< Level land button
|
|
|
|
ETTW_PLACE_ROCKS, ///< Place rocks button
|
|
|
|
ETTW_PLACE_DESERT_LIGHTHOUSE, ///< Place desert button (in tropical climate) / place lighthouse button (else)
|
|
|
|
ETTW_PLACE_TRANSMITTER, ///< Place transmitter button
|
|
|
|
ETTW_BUTTONS_END, ///< End of pushable buttons
|
|
|
|
ETTW_INCREASE_SIZE = ETTW_BUTTONS_END, ///< Upwards arrow button to increase terraforming size
|
|
|
|
ETTW_DECREASE_SIZE, ///< Downwards arrow button to decrease terraforming size
|
|
|
|
ETTW_NEW_SCENARIO, ///< Button for generating a new scenario
|
2008-09-30 20:39:50 +00:00
|
|
|
ETTW_RESET_LANDSCAPE, ///< Button for removing all company-owned property
|
2008-05-22 20:44:24 +00:00
|
|
|
};
|
|
|
|
|
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),
|
2009-07-18 15:29:16 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, ETTW_DEMOLISH), SetMinimalSize(22, 22),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
|
2009-07-18 15:29:16 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, ETTW_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),
|
2009-07-18 15:29:16 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, ETTW_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),
|
2009-07-18 15:29:16 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, ETTW_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
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, ETTW_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),
|
2009-07-18 15:29:16 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, ETTW_PLACE_DESERT_LIGHTHOUSE), SetMinimalSize(22, 22),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_LIGHTHOUSE_DESERT, STR_NULL),
|
2009-07-18 15:29:16 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, ETTW_PLACE_TRANSMITTER), SetMinimalSize(23, 22),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(0, 1), SetDataTip(SPR_IMG_TRANSMITTER, STR_TERRAFORM_TOOLTIP_PLACE_TRANSMITTER),
|
|
|
|
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),
|
2009-07-18 15:29:16 +00:00
|
|
|
NWidget(WWT_EMPTY, COLOUR_DARK_GREEN, ETTW_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),
|
2009-04-21 23:40:56 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, ETTW_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),
|
2009-04-21 23:40:56 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, ETTW_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),
|
2009-07-18 15:29:16 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, ETTW_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),
|
2009-07-18 15:29:16 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, ETTW_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(),
|
|
|
|
};
|
|
|
|
|
2008-01-06 18:56:43 +00:00
|
|
|
/**
|
|
|
|
* @todo Merge with terraform_gui.cpp (move there) after I have cooled down at its braindeadness
|
|
|
|
* and changed OnButtonClick to include the widget as well in the function declaration. Post 0.4.0 - Darkvater
|
|
|
|
*/
|
|
|
|
static void EditorTerraformClick_Dynamite(Window *w)
|
|
|
|
{
|
2009-04-19 10:31:30 +00:00
|
|
|
HandlePlacePushButton(w, ETTW_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT, PlaceProc_DemolishArea);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EditorTerraformClick_LowerBigLand(Window *w)
|
|
|
|
{
|
2009-04-19 10:31:30 +00:00
|
|
|
HandlePlacePushButton(w, ETTW_LOWER_LAND, ANIMCURSOR_LOWERLAND, HT_POINT, PlaceProc_LowerBigLand);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EditorTerraformClick_RaiseBigLand(Window *w)
|
|
|
|
{
|
2009-04-19 10:31:30 +00:00
|
|
|
HandlePlacePushButton(w, ETTW_RAISE_LAND, ANIMCURSOR_RAISELAND, HT_POINT, PlaceProc_RaiseBigLand);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EditorTerraformClick_LevelLand(Window *w)
|
|
|
|
{
|
2009-04-19 10:31:30 +00:00
|
|
|
HandlePlacePushButton(w, ETTW_LEVEL_LAND, SPR_CURSOR_LEVEL_LAND, HT_POINT, PlaceProc_LevelLand);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EditorTerraformClick_RockyArea(Window *w)
|
|
|
|
{
|
2009-04-19 10:31:30 +00:00
|
|
|
HandlePlacePushButton(w, ETTW_PLACE_ROCKS, SPR_CURSOR_ROCKY_AREA, HT_RECT, PlaceProc_RockyArea);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EditorTerraformClick_DesertLightHouse(Window *w)
|
|
|
|
{
|
2009-04-19 10:31:30 +00:00
|
|
|
HandlePlacePushButton(w, ETTW_PLACE_DESERT_LIGHTHOUSE, SPR_CURSOR_LIGHTHOUSE, HT_RECT, (_settings_game.game_creation.landscape == LT_TROPIC) ? PlaceProc_DesertArea : PlaceProc_LightHouse);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EditorTerraformClick_Transmitter(Window *w)
|
|
|
|
{
|
2009-04-19 10:31:30 +00:00
|
|
|
HandlePlacePushButton(w, ETTW_PLACE_TRANSMITTER, SPR_CURSOR_TRANSMITTER, HT_RECT, PlaceProc_Transmitter);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const uint16 _editor_terraform_keycodes[] = {
|
|
|
|
'D',
|
|
|
|
'Q',
|
|
|
|
'W',
|
|
|
|
'E',
|
|
|
|
'R',
|
|
|
|
'T',
|
2008-06-25 17:30:16 +00:00
|
|
|
'Y'
|
2008-01-06 18:56:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef void OnButtonClick(Window *w);
|
|
|
|
static OnButtonClick * const _editor_terraform_button_proc[] = {
|
|
|
|
EditorTerraformClick_Dynamite,
|
|
|
|
EditorTerraformClick_LowerBigLand,
|
|
|
|
EditorTerraformClick_RaiseBigLand,
|
|
|
|
EditorTerraformClick_LevelLand,
|
|
|
|
EditorTerraformClick_RockyArea,
|
|
|
|
EditorTerraformClick_DesertLightHouse,
|
|
|
|
EditorTerraformClick_Transmitter
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** Callback function for the scenario editor 'reset landscape' confirmation window
|
|
|
|
* @param w Window unused
|
|
|
|
* @param confirmed boolean value, true when yes was clicked, false otherwise */
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
MarkWholeScreenDirty();
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-18 21:53:45 +00:00
|
|
|
struct ScenarioEditorLandscapeGenerationWindow : Window {
|
2009-07-18 15:29:16 +00:00
|
|
|
ScenarioEditorLandscapeGenerationWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
|
2008-05-18 21:53:45 +00:00
|
|
|
{
|
2009-07-18 15:29:16 +00:00
|
|
|
this->InitNested(desc, window_number);
|
2009-09-19 11:31:12 +00:00
|
|
|
this->GetWidget<NWidgetCore>(ETTW_PLACE_DESERT_LIGHTHOUSE)->tool_tip = (_settings_game.game_creation.landscape == LT_TROPIC) ? STR_TERRAFORM_TOOLTIP_DEFINE_DESERT_AREA : STR_TERRAFORM_TOOLTIP_PLACE_LIGHTHOUSE;
|
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
|
|
|
|
2009-07-18 15:29:16 +00:00
|
|
|
if (this->IsWidgetLowered(ETTW_LOWER_LAND) || this->IsWidgetLowered(ETTW_RAISE_LAND)) { // change area-size if raise/lower corner is selected
|
|
|
|
SetTileSelectSize(_terraform_size, _terraform_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
if (widget != ETTW_DOTS) return;
|
|
|
|
|
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
|
|
|
|
2008-05-18 21:53:45 +00:00
|
|
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
|
|
|
{
|
|
|
|
for (uint i = 0; i != lengthof(_editor_terraform_keycodes); i++) {
|
|
|
|
if (keycode == _editor_terraform_keycodes[i]) {
|
|
|
|
_editor_terraform_button_proc[i](this);
|
|
|
|
return ES_HANDLED;
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
2008-05-18 21:53:45 +00:00
|
|
|
}
|
|
|
|
return ES_NOT_HANDLED;
|
|
|
|
}
|
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
|
|
|
{
|
2008-05-22 20:44:24 +00:00
|
|
|
if (IsInsideMM(widget, ETTW_BUTTONS_START, ETTW_BUTTONS_END)) {
|
|
|
|
_editor_terraform_button_proc[widget - ETTW_BUTTONS_START](this);
|
|
|
|
} else {
|
|
|
|
switch (widget) {
|
|
|
|
case ETTW_INCREASE_SIZE:
|
|
|
|
case ETTW_DECREASE_SIZE: { // Increase/Decrease terraform size
|
|
|
|
int size = (widget == ETTW_INCREASE_SIZE) ? 1 : -1;
|
|
|
|
this->HandleButtonClick(widget);
|
|
|
|
size += _terraform_size;
|
|
|
|
|
|
|
|
if (!IsInsideMM(size, 1, 8 + 1)) return;
|
|
|
|
_terraform_size = size;
|
|
|
|
|
|
|
|
SndPlayFx(SND_15_BEEP);
|
|
|
|
this->SetDirty();
|
|
|
|
} break;
|
|
|
|
case ETTW_NEW_SCENARIO: // gen random land
|
|
|
|
this->HandleButtonClick(widget);
|
|
|
|
ShowCreateScenario();
|
|
|
|
break;
|
|
|
|
case ETTW_RESET_LANDSCAPE: // Reset landscape
|
|
|
|
ShowQuery(
|
2009-04-21 23:40:56 +00:00
|
|
|
STR_QUERY_RESET_LANDSCAPE_CAPTION,
|
2008-05-22 20:44:24 +00:00
|
|
|
STR_RESET_LANDSCAPE_CONFIRMATION_TEXT,
|
|
|
|
NULL,
|
|
|
|
ResetLandscapeConfirmationCallback);
|
|
|
|
break;
|
|
|
|
}
|
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()
|
|
|
|
{
|
2009-07-18 15:29:16 +00:00
|
|
|
for (uint i = ETTW_START; i < this->nested_array_size; i++) {
|
2008-05-22 20:44:24 +00:00
|
|
|
if (i == ETTW_BUTTONS_START) i = ETTW_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)
|
|
|
|
{
|
|
|
|
_place_proc(tile);
|
|
|
|
}
|
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();
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
2008-05-18 21:53:45 +00:00
|
|
|
};
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _scen_edit_land_gen_desc(
|
2009-11-28 15:01:49 +00:00
|
|
|
WDP_AUTO, 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,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_scen_edit_land_gen_widgets, lengthof(_nested_scen_edit_land_gen_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2009-06-01 14:36:36 +00:00
|
|
|
Window *ShowEditorTerraformToolbar()
|
|
|
|
{
|
|
|
|
return AllocateWindowDescFront<ScenarioEditorLandscapeGenerationWindow>(&_scen_edit_land_gen_desc, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShowEditorTerraformToolbarWithTool(uint16 key, uint16 keycode)
|
2008-01-06 18:56:43 +00:00
|
|
|
{
|
2009-06-01 14:36:36 +00:00
|
|
|
Window *w = FindWindowById(WC_SCEN_LAND_GEN, 0);
|
|
|
|
|
|
|
|
if (w == NULL) w = ShowEditorTerraformToolbar();
|
|
|
|
if (w == NULL) return;
|
|
|
|
|
|
|
|
w->OnKeyPress(key, keycode);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|