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-12-27 12:38:02 +00:00
|
|
|
#include "bridge_map.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "clear_map.h"
|
2008-01-12 14:10:35 +00:00
|
|
|
#include "player_func.h"
|
|
|
|
#include "player_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"
|
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-13 14:37:30 +00:00
|
|
|
#include "settings_type.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"
|
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);
|
2005-05-08 22:00:56 +01:00
|
|
|
DoCommandP(tile, 0, 0, NULL, 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
|
|
|
**/
|
2006-09-23 03:39:24 +01:00
|
|
|
bool GUIPlaceProcDragXY(const WindowEvent *e)
|
(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-09-23 03:39:24 +01:00
|
|
|
TileIndex start_tile = e->we.place.starttile;
|
|
|
|
TileIndex end_tile = e->we.place.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
|
|
|
|
2007-05-23 13:45:56 +01:00
|
|
|
switch (e->we.place.select_proc) {
|
2007-05-23 14:52:10 +01:00
|
|
|
case DDSP_DEMOLISH_AREA:
|
2007-05-23 13:45:56 +01:00
|
|
|
DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA));
|
|
|
|
break;
|
2008-01-04 18:18:46 +00:00
|
|
|
case DDSP_RAISE_AND_LEVEL_AREA:
|
2008-01-06 11:39:40 +00:00
|
|
|
DoCommandP(end_tile, start_tile, 1, CcTerraform, CMD_LEVEL_LAND | CMD_MSG(STR_0808_CAN_T_RAISE_LAND_HERE));
|
2008-01-04 18:18:46 +00:00
|
|
|
break;
|
|
|
|
case DDSP_LOWER_AND_LEVEL_AREA:
|
2008-01-05 22:34:04 +00:00
|
|
|
DoCommandP(end_tile, start_tile, (uint32)-1, CcTerraform, CMD_LEVEL_LAND | CMD_MSG(STR_0809_CAN_T_LOWER_LAND_HERE));
|
2008-01-04 18:18:46 +00:00
|
|
|
break;
|
2007-05-23 14:52:10 +01:00
|
|
|
case DDSP_LEVEL_AREA:
|
2007-09-04 12:58:27 +01:00
|
|
|
DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_LEVEL_LAND);
|
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;
|
2007-05-23 14:52:10 +01:00
|
|
|
case DDSP_CREATE_WATER:
|
2007-09-04 12:58:27 +01:00
|
|
|
DoCommandP(end_tile, start_tile, _ctrl_pressed, CcBuildCanal, CMD_BUILD_CANAL | CMD_MSG(STR_CANT_BUILD_CANALS));
|
2007-05-23 13:45:56 +01:00
|
|
|
break;
|
2008-01-19 17:00:54 +00:00
|
|
|
case DDSP_CREATE_RIVER:
|
|
|
|
DoCommandP(end_tile, start_tile, 2, CcBuildCanal, CMD_BUILD_CANAL | CMD_MSG(STR_CANT_BUILD_CANALS));
|
|
|
|
break;
|
2007-05-23 13:45:56 +01:00
|
|
|
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:30:50 +01:00
|
|
|
static void PlaceProc_BuyLand(TileIndex tile)
|
|
|
|
{
|
|
|
|
DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_PURCHASE_LAND_AREA | CMD_NO_WATER | CMD_MSG(STR_5806_CAN_T_PURCHASE_THIS_LAND));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void TerraformClick_Lower(Window *w)
|
|
|
|
{
|
2007-11-15 18:28:00 +00:00
|
|
|
HandlePlacePushButton(w, 4, ANIMCURSOR_LOWERLAND, VHM_POINT, PlaceProc_LowerLand);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TerraformClick_Raise(Window *w)
|
|
|
|
{
|
2007-11-15 18:28:00 +00:00
|
|
|
HandlePlacePushButton(w, 5, ANIMCURSOR_RAISELAND, VHM_POINT, PlaceProc_RaiseLand);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TerraformClick_Level(Window *w)
|
|
|
|
{
|
2007-11-15 18:28:00 +00:00
|
|
|
HandlePlacePushButton(w, 6, 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)
|
|
|
|
{
|
2007-11-15 18:28:00 +00:00
|
|
|
HandlePlacePushButton(w, 7, 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)
|
|
|
|
{
|
2007-11-15 18:28:00 +00:00
|
|
|
HandlePlacePushButton(w, 8, 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)
|
|
|
|
{
|
2007-11-15 18:28:00 +00:00
|
|
|
HandlePlacePushButton(w, 10, 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,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void TerraformToolbWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2006-02-01 07:36:15 +00:00
|
|
|
switch (e->event) {
|
2004-08-09 18:04:08 +01:00
|
|
|
case WE_PAINT:
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
break;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2004-08-09 18:04:08 +01:00
|
|
|
case WE_CLICK:
|
2006-09-23 03:39:24 +01:00
|
|
|
if (e->we.click.widget >= 4) _terraform_button_proc[e->we.click.widget - 4](w);
|
2004-08-09 18:04:08 +01:00
|
|
|
break;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
case WE_KEYPRESS: {
|
|
|
|
uint i;
|
2004-12-12 22:05:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (i = 0; i != lengthof(_terraform_keycodes); i++) {
|
2006-09-23 03:39:24 +01:00
|
|
|
if (e->we.keypress.keycode == _terraform_keycodes[i]) {
|
|
|
|
e->we.keypress.cont = false;
|
2004-08-09 18:04:08 +01:00
|
|
|
_terraform_button_proc[i](w);
|
|
|
|
break;
|
|
|
|
}
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
break;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
|
|
|
case WE_PLACE_OBJ:
|
2006-09-23 03:39:24 +01:00
|
|
|
_place_proc(e->we.place.tile);
|
2004-08-09 18:04:08 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
case WE_PLACE_DRAG:
|
2007-05-23 13:45:56 +01:00
|
|
|
VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method);
|
2004-08-09 18:04:08 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_PLACE_MOUSEUP:
|
2007-05-23 14:52:10 +01:00
|
|
|
if (e->we.place.pt.x != -1) {
|
|
|
|
switch (e->we.place.select_proc) {
|
|
|
|
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:
|
|
|
|
GUIPlaceProcDragXY(e);
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_ABORT_PLACE_OBJ:
|
2007-12-08 01:20:47 +00:00
|
|
|
w->RaiseButtons();
|
2004-08-09 18:04:08 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _terraform_widgets[] = {
|
(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
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 145, 0, 13, STR_LANDSCAPING_TOOLBAR, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{WWT_STICKYBOX, RESIZE_NONE, 7, 146, 157, 0, 13, STR_NULL, STR_STICKY_BUTTON},
|
|
|
|
|
2006-10-24 15:15:17 +01:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 66, 69, 14, 35, 0x0, STR_NULL},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 7, 0, 21, 14, 35, SPR_IMG_TERRAFORM_DOWN, STR_018E_LOWER_A_CORNER_OF_LAND},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 7, 22, 43, 14, 35, SPR_IMG_TERRAFORM_UP, STR_018F_RAISE_A_CORNER_OF_LAND},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 7, 44, 65, 14, 35, SPR_IMG_LEVEL_LAND, STR_LEVEL_LAND_TOOLTIP},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 7, 70, 91, 14, 35, SPR_IMG_DYNAMITE, STR_018D_DEMOLISH_BUILDINGS_ETC},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 7, 92, 113, 14, 35, SPR_IMG_BUY_LAND, STR_0329_PURCHASE_LAND_FOR_FUTURE},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 7, 114, 135, 14, 35, SPR_IMG_PLANTTREES, STR_0185_PLANT_TREES_PLACE_SIGNS},
|
2007-05-08 15:28:55 +01:00
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 7, 136, 157, 14, 35, SPR_IMG_SIGN, STR_0289_PLACE_SIGN},
|
2004-09-07 22:48:09 +01:00
|
|
|
|
|
|
|
{ WIDGETS_END},
|
2004-08-09 18:04:08 +01: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,
|
2004-12-22 00:18:40 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
2004-08-09 18:04:08 +01:00
|
|
|
_terraform_widgets,
|
|
|
|
TerraformToolbWndProc
|
|
|
|
};
|
|
|
|
|
2007-01-28 10:09:40 +00:00
|
|
|
void ShowTerraformToolbar(Window *link)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2006-10-31 21:15:56 +00:00
|
|
|
if (!IsValidPlayer(_current_player)) return;
|
2008-05-08 12:50:34 +01:00
|
|
|
Window *w = AllocateWindowDescFront<Window>(&_terraform_desc, 0);
|
2007-01-28 10:09:40 +00:00
|
|
|
if (w != NULL && link != NULL) {
|
|
|
|
/* Align the terraform toolbar under the main toolbar and put the linked
|
|
|
|
* toolbar to left of it
|
|
|
|
*/
|
|
|
|
w->top = 22;
|
|
|
|
link->left = w->left - link->width;
|
2007-07-25 12:27:30 +01:00
|
|
|
|
2008-05-06 23:08:18 +01:00
|
|
|
link->SetDirty();
|
2007-01-28 10:09:40 +00:00
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
_generating_world = true; // used to create green terraformed land
|
|
|
|
|
|
|
|
if (_terraform_size == 1) {
|
|
|
|
StringID msg =
|
|
|
|
mode ? STR_0808_CAN_T_RAISE_LAND_HERE : STR_0809_CAN_T_LOWER_LAND_HERE;
|
|
|
|
|
|
|
|
DoCommandP(tile, SLOPE_N, (uint32)mode, CcTerraform, CMD_TERRAFORM_LAND | CMD_MSG(msg));
|
|
|
|
} else {
|
|
|
|
SndPlayTileFx(SND_1F_SPLAT, tile);
|
|
|
|
|
|
|
|
assert(_terraform_size != 0);
|
|
|
|
/* check out for map overflows */
|
|
|
|
sizex = min(MapSizeX() - TileX(tile) - 1, _terraform_size);
|
|
|
|
sizey = min(MapSizeY() - TileY(tile) - 1, _terraform_size);
|
|
|
|
|
|
|
|
if (sizex == 0 || sizey == 0) return;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
DoCommandP(tile2, SLOPE_N, (uint32)mode, NULL, CMD_TERRAFORM_LAND);
|
|
|
|
}
|
|
|
|
} END_TILE_LOOP(tile2, sizex, sizey, tile)
|
|
|
|
}
|
|
|
|
|
|
|
|
_generating_world = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 void PlaceProc_WaterArea(TileIndex tile)
|
|
|
|
{
|
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_WATER);
|
|
|
|
}
|
|
|
|
|
2008-01-19 17:00:54 +00:00
|
|
|
static void PlaceProc_RiverArea(TileIndex tile)
|
|
|
|
{
|
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_RIVER);
|
|
|
|
}
|
|
|
|
|
2008-01-06 18:56:43 +00:00
|
|
|
static const Widget _scen_edit_land_gen_widgets[] = {
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
2008-01-19 17:00:54 +00:00
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 191, 0, 13, STR_0223_LAND_GENERATION, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, 7, 192, 203, 0, 13, STR_NULL, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 203, 14, 102, 0x0, STR_NULL},
|
2008-01-06 18:56:43 +00:00
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 2, 23, 16, 37, SPR_IMG_DYNAMITE, STR_018D_DEMOLISH_BUILDINGS_ETC},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 24, 45, 16, 37, SPR_IMG_TERRAFORM_DOWN, STR_018E_LOWER_A_CORNER_OF_LAND},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 46, 67, 16, 37, SPR_IMG_TERRAFORM_UP, STR_018F_RAISE_A_CORNER_OF_LAND},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 68, 89, 16, 37, SPR_IMG_LEVEL_LAND, STR_LEVEL_LAND_TOOLTIP},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 90, 111, 16, 37, SPR_IMG_BUILD_CANAL, STR_CREATE_LAKE},
|
2008-01-22 20:04:30 +00:00
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 112, 133, 16, 37, SPR_IMG_BUILD_RIVER, STR_CREATE_RIVER},
|
2008-01-19 17:00:54 +00:00
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 134, 156, 16, 37, SPR_IMG_ROCKS, STR_028C_PLACE_ROCKY_AREAS_ON_LANDSCAPE},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 157, 179, 16, 37, SPR_IMG_LIGHTHOUSE_DESERT, STR_NULL}, // XXX - dynamic
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 180, 201, 16, 37, SPR_IMG_TRANSMITTER, STR_028E_PLACE_TRANSMITTER},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 150, 161, 45, 56, SPR_ARROW_UP, STR_0228_INCREASE_SIZE_OF_LAND_AREA},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 150, 161, 58, 69, SPR_ARROW_DOWN, STR_0229_DECREASE_SIZE_OF_LAND_AREA},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 24, 179, 76, 87, STR_SE_NEW_WORLD, STR_022A_GENERATE_RANDOM_LAND},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 24, 179, 89, 100, STR_022B_RESET_LANDSCAPE, STR_RESET_LANDSCAPE_TOOLTIP},
|
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},
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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)
|
|
|
|
{
|
|
|
|
HandlePlacePushButton(w, 4, ANIMCURSOR_DEMOLISH, VHM_RECT, PlaceProc_DemolishArea);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void EditorTerraformClick_LowerBigLand(Window *w)
|
|
|
|
{
|
|
|
|
HandlePlacePushButton(w, 5, ANIMCURSOR_LOWERLAND, VHM_POINT, PlaceProc_LowerBigLand);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void EditorTerraformClick_RaiseBigLand(Window *w)
|
|
|
|
{
|
|
|
|
HandlePlacePushButton(w, 6, ANIMCURSOR_RAISELAND, VHM_POINT, PlaceProc_RaiseBigLand);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void EditorTerraformClick_LevelLand(Window *w)
|
|
|
|
{
|
|
|
|
HandlePlacePushButton(w, 7, SPR_CURSOR_LEVEL_LAND, VHM_POINT, PlaceProc_LevelLand);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void EditorTerraformClick_WaterArea(Window *w)
|
|
|
|
{
|
|
|
|
HandlePlacePushButton(w, 8, SPR_CURSOR_CANAL, VHM_RECT, PlaceProc_WaterArea);
|
|
|
|
}
|
|
|
|
|
2008-01-19 17:00:54 +00:00
|
|
|
static void EditorTerraformClick_RiverArea(Window *w)
|
|
|
|
{
|
2008-01-22 20:04:30 +00:00
|
|
|
HandlePlacePushButton(w, 9, SPR_CURSOR_RIVER, VHM_RECT, PlaceProc_RiverArea);
|
2008-01-19 17:00:54 +00:00
|
|
|
}
|
|
|
|
|
2008-01-06 18:56:43 +00:00
|
|
|
static void EditorTerraformClick_RockyArea(Window *w)
|
|
|
|
{
|
2008-01-19 17:00:54 +00:00
|
|
|
HandlePlacePushButton(w, 10, SPR_CURSOR_ROCKY_AREA, VHM_RECT, PlaceProc_RockyArea);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EditorTerraformClick_DesertLightHouse(Window *w)
|
|
|
|
{
|
2008-01-19 17:00:54 +00:00
|
|
|
HandlePlacePushButton(w, 11, SPR_CURSOR_LIGHTHOUSE, VHM_RECT, (_opt.landscape == LT_TROPIC) ? PlaceProc_DesertArea : PlaceProc_LightHouse);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EditorTerraformClick_Transmitter(Window *w)
|
|
|
|
{
|
2008-01-19 17:00:54 +00:00
|
|
|
HandlePlacePushButton(w, 12, 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',
|
|
|
|
'Y',
|
2008-01-19 17:00:54 +00:00
|
|
|
'U',
|
|
|
|
'I'
|
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_WaterArea,
|
2008-01-19 17:00:54 +00:00
|
|
|
EditorTerraformClick_RiverArea,
|
2008-01-06 18:56:43 +00:00
|
|
|
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) {
|
|
|
|
Player *p;
|
|
|
|
|
|
|
|
/* Set generating_world to true to get instant-green grass after removing
|
|
|
|
* player property. */
|
|
|
|
_generating_world = true;
|
|
|
|
/* Delete all players */
|
|
|
|
FOR_ALL_PLAYERS(p) {
|
|
|
|
if (p->is_active) {
|
|
|
|
ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR);
|
|
|
|
p->is_active = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_generating_world = false;
|
|
|
|
|
|
|
|
/* Delete all stations owned by a player */
|
|
|
|
Station *st;
|
|
|
|
FOR_ALL_STATIONS(st) {
|
|
|
|
if (IsValidPlayer(st->owner)) delete st;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ScenEditLandGenWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
|
|
|
switch (e->event) {
|
|
|
|
case WE_CREATE:
|
2008-01-19 17:00:54 +00:00
|
|
|
/* XXX - lighthouse button is widget 11!! Don't forget when changing */
|
|
|
|
w->widget[11].tooltips = (_opt.landscape == LT_TROPIC) ? STR_028F_DEFINE_DESERT_AREA : STR_028D_PLACE_LIGHTHOUSE;
|
2008-01-06 18:56:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_PAINT: {
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
int n = _terraform_size * _terraform_size;
|
|
|
|
const int8 *coords = &_multi_terraform_coords[0][0];
|
|
|
|
|
|
|
|
assert(n != 0);
|
|
|
|
do {
|
2008-01-19 17:00:54 +00:00
|
|
|
DrawSprite(SPR_WHITE_POINT, PAL_NONE, 88 + coords[0], 55 + coords[1]);
|
2008-01-06 18:56:43 +00:00
|
|
|
coords += 2;
|
|
|
|
} while (--n);
|
|
|
|
|
|
|
|
if (w->IsWidgetLowered(5) || w->IsWidgetLowered(6)) // change area-size if raise/lower corner is selected
|
|
|
|
SetTileSelectSize(_terraform_size, _terraform_size);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_KEYPRESS:
|
|
|
|
for (uint i = 0; i != lengthof(_editor_terraform_keycodes); i++) {
|
|
|
|
if (e->we.keypress.keycode == _editor_terraform_keycodes[i]) {
|
|
|
|
e->we.keypress.cont = false;
|
|
|
|
_editor_terraform_button_proc[i](w);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_CLICK:
|
|
|
|
switch (e->we.click.widget) {
|
2008-01-19 17:00:54 +00:00
|
|
|
case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12:
|
2008-01-06 18:56:43 +00:00
|
|
|
_editor_terraform_button_proc[e->we.click.widget - 4](w);
|
|
|
|
break;
|
2008-01-19 17:00:54 +00:00
|
|
|
case 13: case 14: { // Increase/Decrease terraform size
|
|
|
|
int size = (e->we.click.widget == 13) ? 1 : -1;
|
2008-01-06 18:56:43 +00:00
|
|
|
w->HandleButtonClick(e->we.click.widget);
|
|
|
|
size += _terraform_size;
|
|
|
|
|
|
|
|
if (!IsInsideMM(size, 1, 8 + 1)) return;
|
|
|
|
_terraform_size = size;
|
|
|
|
|
|
|
|
SndPlayFx(SND_15_BEEP);
|
2008-05-06 23:08:18 +01:00
|
|
|
w->SetDirty();
|
2008-01-06 18:56:43 +00:00
|
|
|
} break;
|
2008-01-19 17:00:54 +00:00
|
|
|
case 15: // gen random land
|
|
|
|
w->HandleButtonClick(15);
|
2008-01-06 18:56:43 +00:00
|
|
|
ShowCreateScenario();
|
|
|
|
break;
|
2008-01-19 17:00:54 +00:00
|
|
|
case 16: // Reset landscape
|
2008-01-06 18:56:43 +00:00
|
|
|
ShowQuery(
|
|
|
|
STR_022C_RESET_LANDSCAPE,
|
|
|
|
STR_RESET_LANDSCAPE_CONFIRMATION_TEXT,
|
|
|
|
NULL,
|
|
|
|
ResetLandscapeConfirmationCallback);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_TIMEOUT:
|
|
|
|
for (uint i = 0; i < w->widget_count; i++) {
|
|
|
|
if (w->IsWidgetLowered(i)) {
|
|
|
|
w->RaiseWidget(i);
|
|
|
|
w->InvalidateWidget(i);
|
|
|
|
}
|
2008-01-19 17:00:54 +00:00
|
|
|
if (i == 3) i = 12;
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_PLACE_OBJ:
|
|
|
|
_place_proc(e->we.place.tile);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_PLACE_DRAG:
|
|
|
|
VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_PLACE_MOUSEUP:
|
|
|
|
if (e->we.place.pt.x != -1) {
|
|
|
|
switch (e->we.place.select_proc) {
|
|
|
|
case DDSP_CREATE_ROCKS:
|
|
|
|
case DDSP_CREATE_DESERT:
|
|
|
|
case DDSP_CREATE_WATER:
|
2008-01-19 17:00:54 +00:00
|
|
|
case DDSP_CREATE_RIVER:
|
2008-01-06 18:56:43 +00:00
|
|
|
case DDSP_RAISE_AND_LEVEL_AREA:
|
|
|
|
case DDSP_LOWER_AND_LEVEL_AREA:
|
|
|
|
case DDSP_LEVEL_AREA:
|
|
|
|
case DDSP_DEMOLISH_AREA:
|
|
|
|
GUIPlaceProcDragXY(e);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_ABORT_PLACE_OBJ:
|
|
|
|
w->RaiseButtons();
|
2008-05-06 23:08:18 +01:00
|
|
|
w->SetDirty();
|
2008-01-06 18:56:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const WindowDesc _scen_edit_land_gen_desc = {
|
2008-01-19 17:00:54 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 204, 103, 204, 103,
|
2008-01-06 18:56:43 +00:00
|
|
|
WC_SCEN_LAND_GEN, WC_NONE,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
|
|
|
_scen_edit_land_gen_widgets,
|
|
|
|
ScenEditLandGenWndProc,
|
|
|
|
};
|
|
|
|
|
|
|
|
void ShowEditorTerraformToolbar()
|
|
|
|
{
|
2008-05-08 12:50:34 +01:00
|
|
|
AllocateWindowDescFront<Window>(&_scen_edit_land_gen_desc, 0);
|
2008-01-06 18:56:43 +00:00
|
|
|
}
|