2005-07-24 15:12:37 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 16:11:33 +01:00
|
|
|
/** @file terraform_gui.cpp GUI related to terraforming the map. */
|
2007-04-04 04:21:14 +01:00
|
|
|
|
2004-08-09 18:04:08 +01:00
|
|
|
#include "stdafx.h"
|
2005-06-02 20:30:21 +01:00
|
|
|
#include "openttd.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "clear_map.h"
|
2008-09-30 21:51:04 +01:00
|
|
|
#include "company_func.h"
|
|
|
|
#include "company_base.h"
|
2004-08-09 18:04:08 +01: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"
|
|
|
|
#include "gfx_func.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2008-03-31 08:25:49 +01:00
|
|
|
#include "signs_func.h"
|
2005-07-21 23:15:02 +01: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"
|
2008-03-31 01:17:39 +01:00
|
|
|
#include "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 10:07:19 +01:00
|
|
|
#include "landscape_type.h"
|
2008-05-07 14:10:15 +01:00
|
|
|
#include "tilehighlight_func.h"
|
2009-01-31 20:16:06 +00:00
|
|
|
#include "settings_type.h"
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/sprites.h"
|
|
|
|
#include "table/strings.h"
|
|
|
|
|
2005-06-24 13:38:35 +01:00
|
|
|
void CcTerraform(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
|
|
|
if (success) {
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayTileFx(SND_1F_SPLAT, tile);
|
2004-08-09 18:04:08 +01:00
|
|
|
} else {
|
2008-01-07 00:45:05 +00:00
|
|
|
extern TileIndex _terraform_err_tile;
|
2004-08-09 18:04:08 +01: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-03 00:05:09 +01:00
|
|
|
/** Scenario editor command that generates desert areas */
|
|
|
|
static void GenerateDesertArea(TileIndex end, TileIndex start)
|
|
|
|
{
|
|
|
|
int size_x, size_y;
|
|
|
|
int sx = TileX(start);
|
|
|
|
int sy = TileY(start);
|
|
|
|
int ex = TileX(end);
|
|
|
|
int ey = TileY(end);
|
|
|
|
|
|
|
|
if (_game_mode != GM_EDITOR) return;
|
|
|
|
|
2007-02-22 08:43:02 +00:00
|
|
|
if (ex < sx) Swap(ex, sx);
|
|
|
|
if (ey < sy) Swap(ey, sy);
|
(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-03 00:05:09 +01:00
|
|
|
size_x = (ex - sx) + 1;
|
|
|
|
size_y = (ey - sy) + 1;
|
|
|
|
|
2005-04-19 19:30:31 +01:00
|
|
|
_generating_world = true;
|
2005-06-25 17:44:57 +01:00
|
|
|
BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
|
2005-04-19 19:30:31 +01:00
|
|
|
if (GetTileType(tile) != MP_WATER) {
|
2008-01-30 17:22:06 +00:00
|
|
|
SetTropicZone(tile, (_ctrl_pressed) ? TROPICZONE_NORMAL : TROPICZONE_DESERT);
|
2008-12-28 14:37:19 +00:00
|
|
|
DoCommandP(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
|
2005-04-19 19:30:31 +01:00
|
|
|
MarkTileDirtyByTile(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-03 00:05:09 +01:00
|
|
|
} END_TILE_LOOP(tile, size_x, size_y, 0);
|
2005-04-19 19:30:31 +01: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-03 00:05:09 +01: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)
|
|
|
|
{
|
|
|
|
int size_x, size_y;
|
|
|
|
bool success = false;
|
|
|
|
int sx = TileX(start);
|
|
|
|
int sy = TileY(start);
|
|
|
|
int ex = TileX(end);
|
|
|
|
int ey = TileY(end);
|
|
|
|
|
|
|
|
if (_game_mode != GM_EDITOR) return;
|
|
|
|
|
2007-02-22 08:43:02 +00:00
|
|
|
if (ex < sx) Swap(ex, sx);
|
|
|
|
if (ey < sy) Swap(ey, sy);
|
2005-11-07 16:19:45 +00:00
|
|
|
size_x = (ex - sx) + 1;
|
|
|
|
size_y = (ey - sy) + 1;
|
|
|
|
|
|
|
|
BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
|
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;
|
2005-11-07 16:19:45 +00:00
|
|
|
} END_TILE_LOOP(tile, size_x, size_y, 0);
|
|
|
|
|
|
|
|
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-03 00:05:09 +01:00
|
|
|
/**
|
|
|
|
* A central place to handle all X_AND_Y dragged GUI functions.
|
2007-04-04 04:21:14 +01:00
|
|
|
* @param e WindowEvent variable holding in its higher bits (excluding the lower
|
(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-03 00:05:09 +01:00
|
|
|
* 4, since that defined the X_Y drag) the type of action to be performed
|
|
|
|
* @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 04:21:14 +01: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-03 00:05:09 +01:00
|
|
|
**/
|
2008-05-18 13:40:38 +01: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-03 00:05:09 +01: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 13:40:38 +01:00
|
|
|
switch (proc) {
|
2007-05-23 14:52:10 +01:00
|
|
|
case DDSP_DEMOLISH_AREA:
|
2008-12-28 14:37:19 +00:00
|
|
|
DoCommandP(end_tile, start_tile, 0, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA), CcPlaySound10);
|
2007-05-23 13:45:56 +01:00
|
|
|
break;
|
2008-01-04 18:18:46 +00:00
|
|
|
case DDSP_RAISE_AND_LEVEL_AREA:
|
2008-12-28 14:37:19 +00:00
|
|
|
DoCommandP(end_tile, start_tile, 1, CMD_LEVEL_LAND | CMD_MSG(STR_0808_CAN_T_RAISE_LAND_HERE), CcTerraform);
|
2008-01-04 18:18:46 +00:00
|
|
|
break;
|
|
|
|
case DDSP_LOWER_AND_LEVEL_AREA:
|
2008-12-28 14:37:19 +00:00
|
|
|
DoCommandP(end_tile, start_tile, (uint32)-1, CMD_LEVEL_LAND | CMD_MSG(STR_0809_CAN_T_LOWER_LAND_HERE), CcTerraform);
|
2008-01-04 18:18:46 +00:00
|
|
|
break;
|
2007-05-23 14:52:10 +01:00
|
|
|
case DDSP_LEVEL_AREA:
|
2008-12-30 15:32:46 +00:00
|
|
|
DoCommandP(end_tile, start_tile, 0, CMD_LEVEL_LAND | CMD_MSG(STR_CAN_T_LEVEL_LAND_HERE), CcTerraform);
|
2007-05-23 13:45:56 +01:00
|
|
|
break;
|
2007-05-23 14:52:10 +01:00
|
|
|
case DDSP_CREATE_ROCKS:
|
2007-05-23 13:45:56 +01:00
|
|
|
GenerateRockyArea(end_tile, start_tile);
|
|
|
|
break;
|
2007-05-23 14:52:10 +01:00
|
|
|
case DDSP_CREATE_DESERT:
|
2007-05-23 13:45:56 +01: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-03 00:05:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2004-08-09 18:04:08 +01: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 18:04:08 +01:00
|
|
|
};
|
|
|
|
|
2008-05-08 14:48:34 +01:00
|
|
|
void CcPlaySound1E(bool success, TileIndex tile, uint32 p1, uint32 p2);
|
|
|
|
|
2008-05-08 14:30:50 +01:00
|
|
|
static void PlaceProc_BuyLand(TileIndex tile)
|
|
|
|
{
|
2009-01-07 14:45:07 +00:00
|
|
|
DoCommandP(tile, 0, 0, CMD_PURCHASE_LAND_AREA | CMD_MSG(STR_5806_CAN_T_PURCHASE_THIS_LAND), CcPlaySound1E);
|
2008-05-08 14:30:50 +01:00
|
|
|
}
|
|
|
|
|
2005-06-24 13:38:35 +01:00
|
|
|
void PlaceProc_DemolishArea(TileIndex tile)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2007-05-23 14:52:10 +01:00
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_DEMOLISH_AREA);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2006-01-05 12:40:50 +00:00
|
|
|
static void PlaceProc_RaiseLand(TileIndex tile)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2008-01-04 18:18:46 +00:00
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_RAISE_AND_LEVEL_AREA);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2006-01-05 12:40:50 +00:00
|
|
|
static void PlaceProc_LowerLand(TileIndex tile)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2008-01-04 18:18:46 +00:00
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_LOWER_AND_LEVEL_AREA);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2008-05-08 14:30:50 +01:00
|
|
|
static void PlaceProc_LevelLand(TileIndex tile)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2007-05-23 14:52:10 +01:00
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_LEVEL_AREA);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2008-05-22 21:44:24 +01:00
|
|
|
/** Enum referring to the widgets of the terraform toolbar */
|
|
|
|
enum TerraformToolbarWidgets {
|
|
|
|
TTW_CLOSEBOX = 0, ///< Close window button
|
|
|
|
TTW_CAPTION, ///< Window caption
|
|
|
|
TTW_STICKY, ///< Sticky window button
|
|
|
|
TTW_SEPERATOR, ///< Thin seperator line between level land button and demolish button
|
|
|
|
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 18:04:08 +01:00
|
|
|
static void TerraformClick_Lower(Window *w)
|
|
|
|
{
|
2008-05-22 21:44:24 +01:00
|
|
|
HandlePlacePushButton(w, TTW_LOWER_LAND, ANIMCURSOR_LOWERLAND, VHM_POINT, PlaceProc_LowerLand);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TerraformClick_Raise(Window *w)
|
|
|
|
{
|
2008-05-22 21:44:24 +01:00
|
|
|
HandlePlacePushButton(w, TTW_RAISE_LAND, ANIMCURSOR_RAISELAND, VHM_POINT, PlaceProc_RaiseLand);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TerraformClick_Level(Window *w)
|
|
|
|
{
|
2008-05-22 21:44:24 +01:00
|
|
|
HandlePlacePushButton(w, TTW_LEVEL_LAND, SPR_CURSOR_LEVEL_LAND, VHM_POINT, PlaceProc_LevelLand);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2005-01-08 09:24:15 +00:00
|
|
|
static void TerraformClick_Dynamite(Window *w)
|
|
|
|
{
|
2008-05-22 21:44:24 +01:00
|
|
|
HandlePlacePushButton(w, TTW_DEMOLISH, ANIMCURSOR_DEMOLISH , VHM_RECT, PlaceProc_DemolishArea);
|
2005-01-08 09:24:15 +00:00
|
|
|
}
|
|
|
|
|
2004-08-09 18:04:08 +01:00
|
|
|
static void TerraformClick_BuyLand(Window *w)
|
|
|
|
{
|
2008-05-22 21:44:24 +01:00
|
|
|
HandlePlacePushButton(w, TTW_BUY_LAND, SPR_CURSOR_BUY_LAND, VHM_RECT, PlaceProc_BuyLand);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TerraformClick_Trees(Window *w)
|
|
|
|
{
|
2006-05-11 15:05:23 +01:00
|
|
|
/* This button is NOT a place-push-button, so don't treat it as such */
|
|
|
|
ShowBuildTreesToolbar();
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TerraformClick_PlaceSign(Window *w)
|
|
|
|
{
|
2008-05-22 21:44:24 +01:00
|
|
|
HandlePlacePushButton(w, TTW_PLACE_SIGN, SPR_CURSOR_SIGN, VHM_RECT, PlaceProc_Sign);
|
2004-08-09 18:04:08 +01: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 18:04:08 +01:00
|
|
|
TerraformClick_Trees,
|
|
|
|
TerraformClick_PlaceSign,
|
|
|
|
};
|
|
|
|
|
2008-05-18 22:53:45 +01:00
|
|
|
struct TerraformToolbarWindow : Window {
|
|
|
|
TerraformToolbarWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
|
|
|
{
|
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
|
}
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2008-05-18 22:53:45 +01:00
|
|
|
~TerraformToolbarWindow()
|
|
|
|
{
|
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-18 22:53:45 +01:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
this->DrawWidgets();
|
|
|
|
}
|
2004-12-12 22:05:08 +00:00
|
|
|
|
2008-05-18 22:53:45 +01:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
2008-05-22 21:44:24 +01:00
|
|
|
if (widget >= TTW_BUTTONS_START) _terraform_button_proc[widget - TTW_BUTTONS_START](this);
|
2008-05-18 22:53:45 +01: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 18:04:08 +01:00
|
|
|
}
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2008-05-18 22:53:45 +01:00
|
|
|
return ES_NOT_HANDLED;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-18 22:53:45 +01:00
|
|
|
virtual void OnPlaceObject(Point pt, TileIndex tile)
|
|
|
|
{
|
|
|
|
_place_proc(tile);
|
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-18 22:53:45 +01:00
|
|
|
virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
|
|
|
|
{
|
|
|
|
VpSelectTilesWithMethod(pt.x, pt.y, select_method);
|
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-18 22:53:45 +01: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 13:40:38 +01:00
|
|
|
default: NOT_REACHED();
|
2007-05-23 14:52:10 +01: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 14:52:10 +01:00
|
|
|
case DDSP_LEVEL_AREA:
|
2008-05-18 22:53:45 +01:00
|
|
|
GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
|
2007-05-23 14:52:10 +01:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
2008-05-18 22:53:45 +01:00
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-18 22:53:45 +01:00
|
|
|
virtual void OnPlaceObjectAbort()
|
|
|
|
{
|
|
|
|
this->RaiseButtons();
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
2008-05-18 22:53:45 +01:00
|
|
|
};
|
2004-08-09 18:04:08 +01:00
|
|
|
|
|
|
|
static const Widget _terraform_widgets[] = {
|
2008-08-02 03:28:17 +01:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // TTW_CLOSEBOX
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, COLOUR_DARK_GREEN, 11, 145, 0, 13, STR_LANDSCAPING_TOOLBAR, STR_018C_WINDOW_TITLE_DRAG_THIS}, // TTW_CAPTION
|
|
|
|
{WWT_STICKYBOX, RESIZE_NONE, COLOUR_DARK_GREEN, 146, 157, 0, 13, STR_NULL, STR_STICKY_BUTTON}, // TTW_STICKY
|
|
|
|
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, COLOUR_DARK_GREEN, 66, 69, 14, 35, 0x0, STR_NULL}, // TTW_SEPERATOR
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 21, 14, 35, SPR_IMG_TERRAFORM_DOWN, STR_018E_LOWER_A_CORNER_OF_LAND}, // TTW_LOWER_LAND
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_DARK_GREEN, 22, 43, 14, 35, SPR_IMG_TERRAFORM_UP, STR_018F_RAISE_A_CORNER_OF_LAND}, // TTW_RAISE_LAND
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_DARK_GREEN, 44, 65, 14, 35, SPR_IMG_LEVEL_LAND, STR_LEVEL_LAND_TOOLTIP}, // TTW_LEVEL_LAND
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_DARK_GREEN, 70, 91, 14, 35, SPR_IMG_DYNAMITE, STR_018D_DEMOLISH_BUILDINGS_ETC}, // TTW_DEMOLISH
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_DARK_GREEN, 92, 113, 14, 35, SPR_IMG_BUY_LAND, STR_0329_PURCHASE_LAND_FOR_FUTURE}, // TTW_BUY_LAND
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_DARK_GREEN, 114, 135, 14, 35, SPR_IMG_PLANTTREES, STR_0185_PLANT_TREES_PLACE_SIGNS}, // TTW_PLANT_TREES
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_DARK_GREEN, 136, 157, 14, 35, SPR_IMG_SIGN, STR_0289_PLACE_SIGN}, // TTW_PLACE_SIGN
|
2004-09-07 22:48:09 +01:00
|
|
|
|
|
|
|
{ WIDGETS_END},
|
2004-08-09 18:04:08 +01:00
|
|
|
};
|
|
|
|
|
2009-04-18 08:49:20 +01:00
|
|
|
static const NWidgetPart _nested_terraform_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN, TTW_CLOSEBOX),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, TTW_CAPTION), SetDataTip(STR_LANDSCAPING_TOOLBAR, STR_018C_WINDOW_TITLE_DRAG_THIS),
|
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN, TTW_STICKY),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_LOWER_LAND), SetMinimalSize(22,22), SetDataTip(SPR_IMG_TERRAFORM_DOWN, STR_018E_LOWER_A_CORNER_OF_LAND),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_RAISE_LAND), SetMinimalSize(22,22), SetDataTip(SPR_IMG_TERRAFORM_UP, STR_018F_RAISE_A_CORNER_OF_LAND),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_LEVEL_LAND), SetMinimalSize(22,22), SetDataTip(SPR_IMG_LEVEL_LAND, STR_LEVEL_LAND_TOOLTIP),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_DARK_GREEN, TTW_SEPERATOR), SetMinimalSize(4, 22), EndContainer(),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_DEMOLISH), SetMinimalSize(22,22), SetDataTip(SPR_IMG_DYNAMITE, STR_018D_DEMOLISH_BUILDINGS_ETC),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_BUY_LAND), SetMinimalSize(22,22), SetDataTip(SPR_IMG_BUY_LAND, STR_0329_PURCHASE_LAND_FOR_FUTURE),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_PLANT_TREES), SetMinimalSize(22,22), SetDataTip(SPR_IMG_PLANTTREES, STR_0185_PLANT_TREES_PLACE_SIGNS),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_PLACE_SIGN), SetMinimalSize(22,22), SetDataTip(SPR_IMG_SIGN, STR_0289_PLACE_SIGN),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _terraform_desc(
|
2007-07-27 13:49:04 +01:00
|
|
|
WDP_ALIGN_TBR, 22 + 36, 158, 36, 158, 36,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_SCEN_LAND_GEN, WC_NONE,
|
2009-02-04 16:59:41 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_CONSTRUCTION,
|
2009-04-18 08:49:20 +01:00
|
|
|
_terraform_widgets, _nested_terraform_widgets, lengthof(_nested_terraform_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-01-28 10:09:40 +00:00
|
|
|
void ShowTerraformToolbar(Window *link)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2009-02-04 16:45:07 +00:00
|
|
|
if (!IsValidCompanyID(_local_company)) return;
|
2009-01-02 21:01:13 +00:00
|
|
|
|
2008-05-18 22:53:45 +01:00
|
|
|
Window *w = AllocateWindowDescFront<TerraformToolbarWindow>(&_terraform_desc, 0);
|
2009-01-02 21:01:13 +00:00
|
|
|
if (link == NULL) return;
|
|
|
|
|
|
|
|
if (w == NULL) {
|
|
|
|
w = FindWindowById(WC_SCEN_LAND_GEN, 0);
|
|
|
|
} else {
|
2007-01-28 10:09:40 +00:00
|
|
|
w->top = 22;
|
2008-05-26 11:41:30 +01:00
|
|
|
w->SetDirty();
|
2007-01-28 10:09:40 +00:00
|
|
|
}
|
2009-01-02 21:01:13 +00:00
|
|
|
if (w == NULL) return;
|
|
|
|
|
|
|
|
/* Align the terraform toolbar under the main toolbar and put the linked
|
|
|
|
* toolbar to left of it
|
|
|
|
*/
|
|
|
|
link->top = w->top;
|
|
|
|
link->left = w->left - link->width;
|
|
|
|
link->SetDirty();
|
2004-08-09 18:04:08 +01: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 =
|
|
|
|
mode ? STR_0808_CAN_T_RAISE_LAND_HERE : STR_0809_CAN_T_LOWER_LAND_HERE;
|
|
|
|
|
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 16:58:01 +01:00
|
|
|
SndPlayTileFx(SND_1F_SPLAT, tile);
|
|
|
|
|
2008-01-06 18:56:43 +00:00
|
|
|
if (mode != 0) {
|
|
|
|
/* Raise land */
|
|
|
|
h = 15; // XXX - max height
|
|
|
|
BEGIN_TILE_LOOP(tile2, sizex, sizey, tile) {
|
|
|
|
h = min(h, TileHeight(tile2));
|
|
|
|
} END_TILE_LOOP(tile2, sizex, sizey, tile)
|
|
|
|
} else {
|
|
|
|
/* Lower land */
|
|
|
|
h = 0;
|
|
|
|
BEGIN_TILE_LOOP(tile2, sizex, sizey, tile) {
|
|
|
|
h = max(h, TileHeight(tile2));
|
|
|
|
} END_TILE_LOOP(tile2, sizex, sizey, tile)
|
|
|
|
}
|
|
|
|
|
|
|
|
BEGIN_TILE_LOOP(tile2, sizex, sizey, tile) {
|
|
|
|
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
|
|
|
}
|
|
|
|
} END_TILE_LOOP(tile2, sizex, sizey, tile)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-01-19 17:00:54 +00:00
|
|
|
|
2008-01-06 18:56:43 +00:00
|
|
|
static const Widget _scen_edit_land_gen_widgets[] = {
|
2008-08-02 03:28:17 +01:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // ETTW_CLOSEBOX
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, COLOUR_DARK_GREEN, 11, 150, 0, 13, STR_0223_LAND_GENERATION, STR_018C_WINDOW_TITLE_DRAG_THIS}, // ETTW_CAPTION
|
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, COLOUR_DARK_GREEN, 151, 162, 0, 13, STR_NULL, STR_STICKY_BUTTON}, // ETTW_STICKY
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 162, 14, 102, 0x0, STR_NULL}, // ETTW_BACKGROUND
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_GREY, 2, 23, 16, 37, SPR_IMG_DYNAMITE, STR_018D_DEMOLISH_BUILDINGS_ETC}, // ETTW_DEMOLISH
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_GREY, 24, 45, 16, 37, SPR_IMG_TERRAFORM_DOWN, STR_018E_LOWER_A_CORNER_OF_LAND}, // ETTW_LOWER_LAND
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_GREY, 46, 67, 16, 37, SPR_IMG_TERRAFORM_UP, STR_018F_RAISE_A_CORNER_OF_LAND}, // ETTW_RAISE_LAND
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_GREY, 68, 89, 16, 37, SPR_IMG_LEVEL_LAND, STR_LEVEL_LAND_TOOLTIP}, // ETTW_LEVEL_LAND
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_GREY, 90, 111, 16, 37, SPR_IMG_ROCKS, STR_028C_PLACE_ROCKY_AREAS_ON_LANDSCAPE}, // ETTW_PLACE_ROCKS
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_GREY, 112, 133, 16, 37, SPR_IMG_LIGHTHOUSE_DESERT, STR_NULL}, // ETTW_PLACE_DESERT_LIGHTHOUSE XXX - dynamic
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_GREY, 134, 156, 16, 37, SPR_IMG_TRANSMITTER, STR_028E_PLACE_TRANSMITTER}, // ETTW_PLACE_TRANSMITTER
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_GREY, 150, 161, 45, 56, SPR_ARROW_UP, STR_0228_INCREASE_SIZE_OF_LAND_AREA}, // ETTW_INCREASE_SIZE
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_GREY, 150, 161, 58, 69, SPR_ARROW_DOWN, STR_0229_DECREASE_SIZE_OF_LAND_AREA}, // ETTW_DECREASE_SIZE
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 161, 76, 87, STR_SE_NEW_WORLD, STR_022A_GENERATE_RANDOM_LAND}, // ETTW_NEW_SCENARIO
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 161, 89, 100, STR_022B_RESET_LANDSCAPE, STR_RESET_LANDSCAPE_TOOLTIP}, // ETTW_RESET_LANDSCAPE
|
2008-01-06 18:56:43 +00:00
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
|
|
|
|
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 21:44:24 +01:00
|
|
|
/** Enum referring to the widgets of the editor terraform toolbar */
|
|
|
|
enum EditorTerraformToolbarWidgets {
|
|
|
|
ETTW_START = 0, ///< Used for iterations
|
|
|
|
ETTW_CLOSEBOX = ETTW_START, ///< Close window button
|
|
|
|
ETTW_CAPTION, ///< Window caption
|
|
|
|
ETTW_STICKY, ///< Sticky window button
|
|
|
|
ETTW_BACKGROUND, ///< Background of the lower part of the window
|
|
|
|
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 21:39:50 +01:00
|
|
|
ETTW_RESET_LANDSCAPE, ///< Button for removing all company-owned property
|
2008-05-22 21:44:24 +01:00
|
|
|
};
|
|
|
|
|
2009-04-18 08:49:20 +01:00
|
|
|
static const NWidgetPart _nested_scen_edit_land_gen_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN, ETTW_CLOSEBOX),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, ETTW_CAPTION), SetDataTip(STR_0223_LAND_GENERATION, STR_018C_WINDOW_TITLE_DRAG_THIS),
|
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN, ETTW_STICKY),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_DARK_GREEN, ETTW_BACKGROUND),
|
|
|
|
NWidget(NWID_HORIZONTAL), SetPadding(2, 0, 0, 2),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, ETTW_DEMOLISH), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_018D_DEMOLISH_BUILDINGS_ETC),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, ETTW_LOWER_LAND), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TERRAFORM_DOWN, STR_018E_LOWER_A_CORNER_OF_LAND),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, ETTW_RAISE_LAND), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TERRAFORM_UP, STR_018F_RAISE_A_CORNER_OF_LAND),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, ETTW_LEVEL_LAND), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_LEVEL_LAND, STR_LEVEL_LAND_TOOLTIP),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, ETTW_PLACE_ROCKS), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROCKS, STR_028C_PLACE_ROCKY_AREAS_ON_LANDSCAPE),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, ETTW_PLACE_DESERT_LIGHTHOUSE), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_LIGHTHOUSE_DESERT, STR_NULL),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, ETTW_PLACE_TRANSMITTER), SetMinimalSize(23, 22), SetDataTip(SPR_IMG_TRANSMITTER, STR_028E_PLACE_TRANSMITTER),
|
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 7),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0), // Makes room for displaying the size of the land area affected.
|
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, ETTW_INCREASE_SIZE), SetMinimalSize(12, 12), SetDataTip(SPR_ARROW_UP, STR_0228_INCREASE_SIZE_OF_LAND_AREA),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 1),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_GREY, ETTW_DECREASE_SIZE), SetMinimalSize(12, 12), SetDataTip(SPR_ARROW_DOWN, STR_0229_DECREASE_SIZE_OF_LAND_AREA),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(1, 0),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 6),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, ETTW_NEW_SCENARIO), SetMinimalSize(160, 12), SetDataTip(STR_SE_NEW_WORLD, STR_022A_GENERATE_RANDOM_LAND), SetPadding(0, 1, 0, 2),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, ETTW_RESET_LANDSCAPE), SetMinimalSize(160, 12), SetDataTip(STR_022B_RESET_LANDSCAPE, STR_RESET_LANDSCAPE_TOOLTIP), SetPadding(1, 1, 2, 2),
|
|
|
|
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)
|
|
|
|
{
|
2008-05-22 21:44:24 +01:00
|
|
|
HandlePlacePushButton(w, ETTW_DEMOLISH, ANIMCURSOR_DEMOLISH, VHM_RECT, PlaceProc_DemolishArea);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EditorTerraformClick_LowerBigLand(Window *w)
|
|
|
|
{
|
2008-05-22 21:44:24 +01:00
|
|
|
HandlePlacePushButton(w, ETTW_LOWER_LAND, ANIMCURSOR_LOWERLAND, VHM_POINT, PlaceProc_LowerBigLand);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EditorTerraformClick_RaiseBigLand(Window *w)
|
|
|
|
{
|
2008-05-22 21:44:24 +01:00
|
|
|
HandlePlacePushButton(w, ETTW_RAISE_LAND, ANIMCURSOR_RAISELAND, VHM_POINT, PlaceProc_RaiseBigLand);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EditorTerraformClick_LevelLand(Window *w)
|
|
|
|
{
|
2008-05-22 21:44:24 +01:00
|
|
|
HandlePlacePushButton(w, ETTW_LEVEL_LAND, SPR_CURSOR_LEVEL_LAND, VHM_POINT, PlaceProc_LevelLand);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EditorTerraformClick_RockyArea(Window *w)
|
|
|
|
{
|
2008-05-22 21:44:24 +01:00
|
|
|
HandlePlacePushButton(w, ETTW_PLACE_ROCKS, SPR_CURSOR_ROCKY_AREA, VHM_RECT, PlaceProc_RockyArea);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EditorTerraformClick_DesertLightHouse(Window *w)
|
|
|
|
{
|
2008-05-29 16:13:28 +01:00
|
|
|
HandlePlacePushButton(w, ETTW_PLACE_DESERT_LIGHTHOUSE, SPR_CURSOR_LIGHTHOUSE, VHM_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)
|
|
|
|
{
|
2008-05-22 21:44:24 +01:00
|
|
|
HandlePlacePushButton(w, ETTW_PLACE_TRANSMITTER, SPR_CURSOR_TRANSMITTER, VHM_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 18:30:16 +01: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) {
|
2008-09-30 21:39:50 +01:00
|
|
|
Company *c;
|
2008-01-06 18:56:43 +00:00
|
|
|
|
|
|
|
/* Set generating_world to true to get instant-green grass after removing
|
2008-09-30 21:39:50 +01:00
|
|
|
* company property. */
|
2008-01-06 18:56:43 +00:00
|
|
|
_generating_world = true;
|
|
|
|
|
2008-09-30 21:39:50 +01:00
|
|
|
/* Delete all stations owned by a company */
|
2008-01-06 18:56:43 +00:00
|
|
|
Station *st;
|
|
|
|
FOR_ALL_STATIONS(st) {
|
2008-09-30 21:39:50 +01:00
|
|
|
if (IsValidCompanyID(st->owner)) delete st;
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
2008-07-18 17:40:29 +01:00
|
|
|
|
2008-09-30 21:39:50 +01:00
|
|
|
/* Delete all companies */
|
|
|
|
FOR_ALL_COMPANIES(c) {
|
|
|
|
ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER);
|
|
|
|
delete c;
|
2008-07-18 17:40:29 +01:00
|
|
|
}
|
|
|
|
_generating_world = false;
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-18 22:53:45 +01:00
|
|
|
struct ScenarioEditorLandscapeGenerationWindow : Window {
|
|
|
|
ScenarioEditorLandscapeGenerationWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
|
|
|
{
|
2008-05-29 16:13:28 +01:00
|
|
|
this->widget[ETTW_PLACE_DESERT_LIGHTHOUSE].tooltips = (_settings_game.game_creation.landscape == LT_TROPIC) ? STR_028F_DEFINE_DESERT_AREA : STR_028D_PLACE_LIGHTHOUSE;
|
2008-05-18 22:53:45 +01:00
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
|
}
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2008-05-18 22:53:45 +01:00
|
|
|
virtual void OnPaint() {
|
|
|
|
this->DrawWidgets();
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2008-05-18 22:53:45 +01: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 22:53:45 +01:00
|
|
|
assert(n != 0);
|
|
|
|
do {
|
|
|
|
DrawSprite(SPR_WHITE_POINT, PAL_NONE, 88 + coords[0], 55 + coords[1]);
|
|
|
|
coords += 2;
|
|
|
|
} while (--n);
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2008-05-22 21:44:24 +01:00
|
|
|
if (this->IsWidgetLowered(ETTW_LOWER_LAND) || this->IsWidgetLowered(ETTW_RAISE_LAND)) { // change area-size if raise/lower corner is selected
|
2008-05-18 22:53:45 +01:00
|
|
|
SetTileSelectSize(_terraform_size, _terraform_size);
|
|
|
|
}
|
|
|
|
}
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2008-05-18 22:53:45 +01: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 22:53:45 +01:00
|
|
|
}
|
|
|
|
return ES_NOT_HANDLED;
|
|
|
|
}
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2008-05-18 22:53:45 +01:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
2008-05-22 21:44:24 +01: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(
|
|
|
|
STR_022C_RESET_LANDSCAPE,
|
|
|
|
STR_RESET_LANDSCAPE_CONFIRMATION_TEXT,
|
|
|
|
NULL,
|
|
|
|
ResetLandscapeConfirmationCallback);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-18 22:53:45 +01:00
|
|
|
}
|
|
|
|
}
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2008-05-18 22:53:45 +01:00
|
|
|
virtual void OnTimeout()
|
|
|
|
{
|
2008-05-22 21:44:24 +01:00
|
|
|
for (uint i = ETTW_START; i < this->widget_count; i++) {
|
|
|
|
if (i == ETTW_BUTTONS_START) i = ETTW_BUTTONS_END; // skip the buttons
|
2008-05-18 22:53:45 +01:00
|
|
|
if (this->IsWidgetLowered(i)) {
|
|
|
|
this->RaiseWidget(i);
|
|
|
|
this->InvalidateWidget(i);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
2008-05-18 22:53:45 +01:00
|
|
|
}
|
|
|
|
}
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2008-05-18 22:53:45 +01:00
|
|
|
virtual void OnPlaceObject(Point pt, TileIndex tile)
|
|
|
|
{
|
|
|
|
_place_proc(tile);
|
|
|
|
}
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2008-05-18 22:53:45 +01: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 22:53:45 +01: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 22:53:45 +01:00
|
|
|
}
|
|
|
|
}
|
2008-01-06 18:56:43 +00:00
|
|
|
|
2008-05-18 22:53:45 +01:00
|
|
|
virtual void OnPlaceObjectAbort()
|
|
|
|
{
|
|
|
|
this->RaiseButtons();
|
|
|
|
this->SetDirty();
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
2008-05-18 22:53:45 +01: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(
|
2008-06-25 18:30:16 +01:00
|
|
|
WDP_AUTO, WDP_AUTO, 163, 103, 163, 103,
|
2008-01-06 18:56:43 +00:00
|
|
|
WC_SCEN_LAND_GEN, WC_NONE,
|
2009-02-04 16:59:41 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_CONSTRUCTION,
|
2009-04-18 08:49:20 +01:00
|
|
|
_scen_edit_land_gen_widgets, _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
|
|
|
|
|
|
|
void ShowEditorTerraformToolbar()
|
|
|
|
{
|
2008-05-18 22:53:45 +01:00
|
|
|
AllocateWindowDescFront<ScenarioEditorLandscapeGenerationWindow>(&_scen_edit_land_gen_desc, 0);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|