From 84606b5212303f3b955f090a28a44f451c759207 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 6 Jan 2008 18:56:43 +0000 Subject: (svn r11768) -Codechange: move some terraform related gui stuff from main_gui.cpp to terraform_gui.cpp (and introduce terraform_gui.h). Based on a patch by Roujin. --- src/airport_gui.cpp | 1 + src/dock_gui.cpp | 1 + src/gui.h | 4 - src/main_gui.cpp | 360 +------------------------------------------------- src/rail_gui.cpp | 1 + src/road_gui.cpp | 1 + src/terraform_gui.cpp | 353 +++++++++++++++++++++++++++++++++++++++++++++++++ src/terraform_gui.h | 15 +++ 8 files changed, 375 insertions(+), 361 deletions(-) create mode 100644 src/terraform_gui.h (limited to 'src') diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index 32d00bc8b..7c17aa0c5 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -9,6 +9,7 @@ #include "window_gui.h" #include "gui.h" #include "station_gui.h" +#include "terraform_gui.h" #include "viewport.h" #include "command_func.h" #include "station.h" diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp index d64a30134..59c13cbf2 100644 --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -9,6 +9,7 @@ #include "tile_map.h" #include "station.h" #include "gui.h" +#include "terraform_gui.h" #include "window_gui.h" #include "station_gui.h" #include "viewport.h" diff --git a/src/gui.h b/src/gui.h index 38d41175a..48d15e20e 100644 --- a/src/gui.h +++ b/src/gui.h @@ -14,7 +14,6 @@ /* main_gui.cpp */ void CcPlaySound10(bool success, TileIndex tile, uint32 p1, uint32 p2); void CcBuildCanal(bool success, TileIndex tile, uint32 p1, uint32 p2); -void CcTerraform(bool success, TileIndex tile, uint32 p1, uint32 p2); /* settings_gui.cpp */ void ShowGameOptions(); @@ -46,9 +45,6 @@ void ShowBuildDocksToolbar(); /* aircraft_gui.cpp */ void ShowBuildAirToolbar(); -/* terraform_gui.cpp */ -void ShowTerraformToolbar(Window *link = NULL); - /* tgp_gui.cpp */ void ShowGenerateLandscape(); void ShowHeightmapLoad(); diff --git a/src/main_gui.cpp b/src/main_gui.cpp index 73a51f6e5..ed1e46403 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -7,7 +7,6 @@ #include "heightmap.h" #include "currency.h" #include "spritecache.h" -#include "station.h" #include "table/sprites.h" #include "table/strings.h" #include "gui.h" @@ -27,7 +26,6 @@ #include "train.h" #include "roadveh.h" #include "bridge_map.h" -#include "unmovable_map.h" #include "string.h" #include "screenshot.h" #include "genworld.h" @@ -42,6 +40,7 @@ #include "vehicle_func.h" #include "sound_func.h" #include "fios.h" +#include "terraform_gui.h" #include "network/network_data.h" #include "network/network_client.h" @@ -55,7 +54,6 @@ static int _rename_id = 1; static int _rename_what = -1; -static byte _terraform_size = 1; RailType _last_built_railtype; RoadType _last_built_roadtype; static int _scengen_town_size = 1; // depress medium-sized towns per default @@ -1060,364 +1058,12 @@ void ZoomInOrOutToCursorWindow(bool in, Window *w) } } -/** - * 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) -{ - if (!IsTileType(tile, MP_CLEAR) || IsSteepSlope(GetTileSlope(tile, NULL)) || IsBridgeAbove(tile)) { - return; - } - - MakeLighthouse(tile); - MarkTileDirtyByTile(tile); - SndPlayTileFx(SND_1F_SPLAT, tile); -} - -static void PlaceProc_Transmitter(TileIndex tile) -{ - if (!IsTileType(tile, MP_CLEAR) || IsSteepSlope(GetTileSlope(tile, NULL)) || IsBridgeAbove(tile)) { - 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); -} - -static const Widget _scen_edit_land_gen_widgets[] = { -{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, -{ WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_0223_LAND_GENERATION, STR_018C_WINDOW_TITLE_DRAG_THIS}, -{ WWT_STICKYBOX, RESIZE_NONE, 7, 170, 181, 0, 13, STR_NULL, STR_STICKY_BUTTON}, -{ WWT_PANEL, RESIZE_NONE, 7, 0, 181, 14, 102, 0x0, STR_NULL}, -{ 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}, -{ WWT_IMGBTN, RESIZE_NONE, 14, 112, 134, 16, 37, SPR_IMG_ROCKS, STR_028C_PLACE_ROCKY_AREAS_ON_LANDSCAPE}, -{ WWT_IMGBTN, RESIZE_NONE, 14, 135, 157, 16, 37, SPR_IMG_LIGHTHOUSE_DESERT, STR_NULL}, // XXX - dynamic -{ WWT_IMGBTN, RESIZE_NONE, 14, 158, 179, 16, 37, SPR_IMG_TRANSMITTER, STR_028E_PLACE_TRANSMITTER}, -{ WWT_IMGBTN, RESIZE_NONE, 14, 139, 150, 45, 56, SPR_ARROW_UP, STR_0228_INCREASE_SIZE_OF_LAND_AREA}, -{ WWT_IMGBTN, RESIZE_NONE, 14, 139, 150, 58, 69, SPR_ARROW_DOWN, STR_0229_DECREASE_SIZE_OF_LAND_AREA}, -{ WWT_TEXTBTN, RESIZE_NONE, 14, 24, 157, 76, 87, STR_SE_NEW_WORLD, STR_022A_GENERATE_RANDOM_LAND}, -{ WWT_TEXTBTN, RESIZE_NONE, 14, 24, 157, 89, 100, STR_022B_RESET_LANDSCAPE, STR_RESET_LANDSCAPE_TOOLTIP}, -{ 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); -} - -static void EditorTerraformClick_RockyArea(Window *w) -{ - HandlePlacePushButton(w, 9, SPR_CURSOR_ROCKY_AREA, VHM_RECT, PlaceProc_RockyArea); -} - -static void EditorTerraformClick_DesertLightHouse(Window *w) -{ - HandlePlacePushButton(w, 10, SPR_CURSOR_LIGHTHOUSE, VHM_RECT, (_opt.landscape == LT_TROPIC) ? PlaceProc_DesertArea : PlaceProc_LightHouse); -} - -static void EditorTerraformClick_Transmitter(Window *w) -{ - HandlePlacePushButton(w, 11, SPR_CURSOR_TRANSMITTER, VHM_RECT, PlaceProc_Transmitter); -} - -static const uint16 _editor_terraform_keycodes[] = { - 'D', - 'Q', - 'W', - 'E', - 'R', - 'T', - 'Y', - 'U' -}; - -typedef void OnButtonClick(Window *w); -static OnButtonClick * const _editor_terraform_button_proc[] = { - EditorTerraformClick_Dynamite, - EditorTerraformClick_LowerBigLand, - EditorTerraformClick_RaiseBigLand, - EditorTerraformClick_LevelLand, - EditorTerraformClick_WaterArea, - 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: - /* XXX - lighthouse button is widget 10!! Don't forget when changing */ - w->widget[10].tooltips = (_opt.landscape == LT_TROPIC) ? STR_028F_DEFINE_DESERT_AREA : STR_028D_PLACE_LIGHTHOUSE; - break; - - case WE_PAINT: - DrawWindowWidgets(w); - - { - int n = _terraform_size * _terraform_size; - const int8 *coords = &_multi_terraform_coords[0][0]; - - assert(n != 0); - do { - DrawSprite(SPR_WHITE_POINT, PAL_NONE, 77 + coords[0], 55 + coords[1]); - 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: { - uint i; - - for (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) { - case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: - _editor_terraform_button_proc[e->we.click.widget - 4](w); - break; - case 12: case 13: { // Increase/Decrease terraform size - int size = (e->we.click.widget == 12) ? 1 : -1; - w->HandleButtonClick(e->we.click.widget); - size += _terraform_size; - - if (!IsInsideMM(size, 1, 8 + 1)) return; - _terraform_size = size; - - SndPlayFx(SND_15_BEEP); - SetWindowDirty(w); - } break; - case 14: // gen random land - w->HandleButtonClick(14); - ShowCreateScenario(); - break; - case 15: // Reset landscape - ShowQuery( - STR_022C_RESET_LANDSCAPE, - STR_RESET_LANDSCAPE_CONFIRMATION_TEXT, - NULL, - ResetLandscapeConfirmationCallback); - break; - } - break; - - case WE_TIMEOUT: { - uint i; - for (i = 0; i < w->widget_count; i++) { - if (w->IsWidgetLowered(i)) { - w->RaiseWidget(i); - w->InvalidateWidget(i); - } - if (i == 3) i = 11; - } - 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: - 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(); - SetWindowDirty(w); - break; - } -} - -static const WindowDesc _scen_edit_land_gen_desc = { - WDP_AUTO, WDP_AUTO, 182, 103, 182, 103, - WC_SCEN_LAND_GEN, WC_NONE, - WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, - _scen_edit_land_gen_widgets, - ScenEditLandGenWndProc, -}; - -static inline void ShowEditorTerraformToolBar() -{ - AllocateWindowDescFront(&_scen_edit_land_gen_desc, 0); -} - static void ToolbarScenGenLand(Window *w) { w->HandleButtonClick(11); SndPlayFx(SND_15_BEEP); - ShowEditorTerraformToolBar(); + ShowEditorTerraformToolbar(); } void CcBuildTown(bool success, TileIndex tile, uint32 p1, uint32 p2) @@ -1906,7 +1552,7 @@ static void ScenEditToolbarWndProc(Window *w, WindowEvent *e) case WKC_SHIFT | WKC_MINUS: case WKC_SHIFT | WKC_F6: ToolbarZoomOutClick(w); break; - case 'L': ShowEditorTerraformToolBar(); break; + case 'L': ShowEditorTerraformToolbar(); break; case 'M': ShowSmallMap(); break; case 'V': ShowExtraViewPortWindow(); break; default: return; diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 659fd070e..ed364ff5a 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -11,6 +11,7 @@ #include "gui.h" #include "window_gui.h" #include "station_gui.h" +#include "terraform_gui.h" #include "viewport.h" #include "command_func.h" #include "station.h" diff --git a/src/road_gui.cpp b/src/road_gui.cpp index ce9ce1582..4be2be022 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -9,6 +9,7 @@ #include "gui.h" #include "window_gui.h" #include "station_gui.h" +#include "terraform_gui.h" #include "viewport.h" #include "command_func.h" #include "variables.h" diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp index a80912af5..f33db131a 100644 --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -17,6 +17,9 @@ #include "variables.h" #include "functions.h" #include "sound_func.h" +#include "station.h" +#include "unmovable_map.h" +#include "textbuf_gui.h" void CcTerraform(bool success, TileIndex tile, uint32 p1, uint32 p2) { @@ -298,3 +301,353 @@ void ShowTerraformToolbar(Window *link) SetWindowDirty(link); } } + +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) +{ + if (!IsTileType(tile, MP_CLEAR) || IsSteepSlope(GetTileSlope(tile, NULL)) || IsBridgeAbove(tile)) { + return; + } + + MakeLighthouse(tile); + MarkTileDirtyByTile(tile); + SndPlayTileFx(SND_1F_SPLAT, tile); +} + +static void PlaceProc_Transmitter(TileIndex tile) +{ + if (!IsTileType(tile, MP_CLEAR) || IsSteepSlope(GetTileSlope(tile, NULL)) || IsBridgeAbove(tile)) { + 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); +} + +static const Widget _scen_edit_land_gen_widgets[] = { +{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, +{ WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_0223_LAND_GENERATION, STR_018C_WINDOW_TITLE_DRAG_THIS}, +{ WWT_STICKYBOX, RESIZE_NONE, 7, 170, 181, 0, 13, STR_NULL, STR_STICKY_BUTTON}, +{ WWT_PANEL, RESIZE_NONE, 7, 0, 181, 14, 102, 0x0, STR_NULL}, +{ 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}, +{ WWT_IMGBTN, RESIZE_NONE, 14, 112, 134, 16, 37, SPR_IMG_ROCKS, STR_028C_PLACE_ROCKY_AREAS_ON_LANDSCAPE}, +{ WWT_IMGBTN, RESIZE_NONE, 14, 135, 157, 16, 37, SPR_IMG_LIGHTHOUSE_DESERT, STR_NULL}, // XXX - dynamic +{ WWT_IMGBTN, RESIZE_NONE, 14, 158, 179, 16, 37, SPR_IMG_TRANSMITTER, STR_028E_PLACE_TRANSMITTER}, +{ WWT_IMGBTN, RESIZE_NONE, 14, 139, 150, 45, 56, SPR_ARROW_UP, STR_0228_INCREASE_SIZE_OF_LAND_AREA}, +{ WWT_IMGBTN, RESIZE_NONE, 14, 139, 150, 58, 69, SPR_ARROW_DOWN, STR_0229_DECREASE_SIZE_OF_LAND_AREA}, +{ WWT_TEXTBTN, RESIZE_NONE, 14, 24, 157, 76, 87, STR_SE_NEW_WORLD, STR_022A_GENERATE_RANDOM_LAND}, +{ WWT_TEXTBTN, RESIZE_NONE, 14, 24, 157, 89, 100, STR_022B_RESET_LANDSCAPE, STR_RESET_LANDSCAPE_TOOLTIP}, +{ 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); +} + +static void EditorTerraformClick_RockyArea(Window *w) +{ + HandlePlacePushButton(w, 9, SPR_CURSOR_ROCKY_AREA, VHM_RECT, PlaceProc_RockyArea); +} + +static void EditorTerraformClick_DesertLightHouse(Window *w) +{ + HandlePlacePushButton(w, 10, SPR_CURSOR_LIGHTHOUSE, VHM_RECT, (_opt.landscape == LT_TROPIC) ? PlaceProc_DesertArea : PlaceProc_LightHouse); +} + +static void EditorTerraformClick_Transmitter(Window *w) +{ + HandlePlacePushButton(w, 11, SPR_CURSOR_TRANSMITTER, VHM_RECT, PlaceProc_Transmitter); +} + +static const uint16 _editor_terraform_keycodes[] = { + 'D', + 'Q', + 'W', + 'E', + 'R', + 'T', + 'Y', + 'U' +}; + +typedef void OnButtonClick(Window *w); +static OnButtonClick * const _editor_terraform_button_proc[] = { + EditorTerraformClick_Dynamite, + EditorTerraformClick_LowerBigLand, + EditorTerraformClick_RaiseBigLand, + EditorTerraformClick_LevelLand, + EditorTerraformClick_WaterArea, + 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: + /* XXX - lighthouse button is widget 10!! Don't forget when changing */ + w->widget[10].tooltips = (_opt.landscape == LT_TROPIC) ? STR_028F_DEFINE_DESERT_AREA : STR_028D_PLACE_LIGHTHOUSE; + break; + + case WE_PAINT: { + DrawWindowWidgets(w); + + int n = _terraform_size * _terraform_size; + const int8 *coords = &_multi_terraform_coords[0][0]; + + assert(n != 0); + do { + DrawSprite(SPR_WHITE_POINT, PAL_NONE, 77 + coords[0], 55 + coords[1]); + 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) { + case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: + _editor_terraform_button_proc[e->we.click.widget - 4](w); + break; + case 12: case 13: { // Increase/Decrease terraform size + int size = (e->we.click.widget == 12) ? 1 : -1; + w->HandleButtonClick(e->we.click.widget); + size += _terraform_size; + + if (!IsInsideMM(size, 1, 8 + 1)) return; + _terraform_size = size; + + SndPlayFx(SND_15_BEEP); + SetWindowDirty(w); + } break; + case 14: // gen random land + w->HandleButtonClick(14); + ShowCreateScenario(); + break; + case 15: // Reset landscape + 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); + } + if (i == 3) i = 11; + } + 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: + 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(); + SetWindowDirty(w); + break; + } +} + +static const WindowDesc _scen_edit_land_gen_desc = { + WDP_AUTO, WDP_AUTO, 182, 103, 182, 103, + 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() +{ + AllocateWindowDescFront(&_scen_edit_land_gen_desc, 0); +} diff --git a/src/terraform_gui.h b/src/terraform_gui.h new file mode 100644 index 000000000..b81f67d28 --- /dev/null +++ b/src/terraform_gui.h @@ -0,0 +1,15 @@ +/* $Id$ */ + +/** @file terraform_gui.h GUI stuff related to terraforming. */ + +#ifndef TERRAFORM_GUI_H +#define TERRAFORM_GUI_H + +#include "window_type.h" + +void CcTerraform(bool success, TileIndex tile, uint32 p1, uint32 p2); + +void ShowTerraformToolbar(Window *link = NULL); +void ShowEditorTerraformToolbar(); + +#endif /* GUI_H */ -- cgit v1.2.3-54-g00ecf