Files
@ r4410:dd3a8e5ed49b
Branch filter:
Location: cpp/openttd-patchpack/source/terraform_gui.c - annotation
r4410:dd3a8e5ed49b
7.5 KiB
text/x-c
(svn r6163) -Codechange: distance rounded up (correction of r6162)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | r2186:5ee653b1b5e1 r2186:5ee653b1b5e1 r0:d63b455452f6 r1891:c5c5466afa35 r3144:5b175fed4b0b r1363:a54abce83b4b r507:b1b0a0a3c313 r2163:ae001e2aa5b0 r2154:83cf5a3d6634 r1632:8af4ffbe5d97 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r2790:746efac15ce7 r337:998f55d0b04c r0:d63b455452f6 r0:d63b455452f6 r988:49007d1ff1d3 r2159:2c706fe6b0a7 r0:d63b455452f6 r1977:1f8b99c96041 r0:d63b455452f6 r0:d63b455452f6 r541:062eeec7f0a4 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1710:b794df984bea r1981:addba4bccc89 r1710:b794df984bea r3379:e72a0eb00c30 r1780:3dca839502b1 r1710:b794df984bea r1710:b794df984bea r1632:8af4ffbe5d97 r1710:b794df984bea r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r3017:1bf2ce772ffa r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r3977:63d936e7e5a8 r3977:63d936e7e5a8 r3977:63d936e7e5a8 r3977:63d936e7e5a8 r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r2615:16760befc4ae r2615:16760befc4ae r2615:16760befc4ae r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r4087:fcaef5928f56 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r606:8ecd7d248197 r606:8ecd7d248197 r606:8ecd7d248197 r936:e07e4357b7ec r606:8ecd7d248197 r606:8ecd7d248197 r613:563e8c791adb r0:d63b455452f6 r0:d63b455452f6 r1977:1f8b99c96041 r0:d63b455452f6 r1632:8af4ffbe5d97 r0:d63b455452f6 r0:d63b455452f6 r2817:7ad46034031f r0:d63b455452f6 r4007:3ecaff1027a1 r4007:3ecaff1027a1 r4007:3ecaff1027a1 r4007:3ecaff1027a1 r0:d63b455452f6 r0:d63b455452f6 r2817:7ad46034031f r0:d63b455452f6 r4007:3ecaff1027a1 r4007:3ecaff1027a1 r4007:3ecaff1027a1 r4007:3ecaff1027a1 r0:d63b455452f6 r0:d63b455452f6 r1977:1f8b99c96041 r0:d63b455452f6 r1632:8af4ffbe5d97 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r756:682ff57c5eb0 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r756:682ff57c5eb0 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r1919:1df377f92ea9 r0:d63b455452f6 r0:d63b455452f6 r936:e07e4357b7ec r936:e07e4357b7ec r1914:63c34ade2fdf r936:e07e4357b7ec r936:e07e4357b7ec r0:d63b455452f6 r0:d63b455452f6 r1914:63c34ade2fdf r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r3817:2b40ad9bfab6 r3817:2b40ad9bfab6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r1914:63c34ade2fdf r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r936:e07e4357b7ec r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r2952:e97f823d2dbe r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r2639:e298192a7c03 r0:d63b455452f6 r2639:e298192a7c03 r0:d63b455452f6 r0:d63b455452f6 r2639:e298192a7c03 r2639:e298192a7c03 r616:5c76bbd060a7 r2639:e298192a7c03 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r2639:e298192a7c03 r2639:e298192a7c03 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r4077:259c4c4aacad r4077:259c4c4aacad r4077:259c4c4aacad r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r756:682ff57c5eb0 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r608:ee775077aad7 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r1632:8af4ffbe5d97 r0:d63b455452f6 r176:7d9100f64c27 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r987:e472bedb6e61 r0:d63b455452f6 r756:682ff57c5eb0 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r0:d63b455452f6 r1093:18f56ef2d029 r0:d63b455452f6 r946:70fe894a35f5 r0:d63b455452f6 r0:d63b455452f6 | /* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "clear_map.h"
#include "table/sprites.h"
#include "table/strings.h"
#include "functions.h"
#include "player.h"
#include "tile.h"
#include "window.h"
#include "gui.h"
#include "viewport.h"
#include "gfx.h"
#include "sound.h"
#include "command.h"
#include "vehicle.h"
#include "signs.h"
#include "variables.h"
void CcTerraform(bool success, TileIndex tile, uint32 p1, uint32 p2)
{
if (success) {
SndPlayTileFx(SND_1F_SPLAT, tile);
} else {
SetRedErrorSquare(_terraform_err_tile);
}
}
/** 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;
if (ex < sx) intswap(ex, sx);
if (ey < sy) intswap(ey, sy);
size_x = (ex - sx) + 1;
size_y = (ey - sy) + 1;
_generating_world = true;
BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
if (GetTileType(tile) != MP_WATER) {
SetTropicZone(tile, (_ctrl_pressed) ? TROPICZONE_INVALID : TROPICZONE_DESERT);
DoCommandP(tile, 0, 0, NULL, CMD_LANDSCAPE_CLEAR);
MarkTileDirtyByTile(tile);
}
} END_TILE_LOOP(tile, size_x, size_y, 0);
_generating_world = false;
}
/** Scenario editor command that generates rocky areas */
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;
if (ex < sx) intswap(ex, sx);
if (ey < sy) intswap(ey, sy);
size_x = (ex - sx) + 1;
size_y = (ey - sy) + 1;
BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) {
MakeClear(tile, CLEAR_ROCKS, 3);
MarkTileDirtyByTile(tile);
success = true;
}
} END_TILE_LOOP(tile, size_x, size_y, 0);
if (success) SndPlayTileFx(SND_1F_SPLAT, end);
}
/**
* A central place to handle all X_AND_Y dragged GUI functions.
* @param we @WindowEvent variable holding in its higher bits (excluding the lower
* 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
* of convertrail which belongs in rail_gui.c and not terraform_gui.c
**/
bool GUIPlaceProcDragXY(const WindowEvent *we)
{
TileIndex start_tile = we->place.starttile;
TileIndex end_tile = we->place.tile;
switch (we->place.userdata >> 4) {
case GUI_PlaceProc_DemolishArea >> 4:
DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA));
break;
case GUI_PlaceProc_LevelArea >> 4:
DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_LEVEL_LAND | CMD_AUTO);
break;
case GUI_PlaceProc_RockyArea >> 4:
GenerateRockyArea(end_tile, start_tile);
break;
case GUI_PlaceProc_DesertArea >> 4:
GenerateDesertArea(end_tile, start_tile);
break;
case GUI_PlaceProc_WaterArea >> 4:
DoCommandP(end_tile, start_tile, _ctrl_pressed, CcBuildCanal, CMD_BUILD_CANAL | CMD_AUTO | CMD_MSG(STR_CANT_BUILD_CANALS));
break;
default: return false;
}
return true;
}
typedef void OnButtonClick(Window *w);
static const uint16 _terraform_keycodes[] = {
'Q',
'W',
'E',
'D',
'U',
'I',
'O',
};
void PlaceProc_DemolishArea(TileIndex tile)
{
VpStartPlaceSizing(tile, VPM_X_AND_Y | GUI_PlaceProc_DemolishArea);
}
static void PlaceProc_RaiseLand(TileIndex tile)
{
DoCommandP(
tile, SLOPE_N, 1, CcTerraform,
CMD_TERRAFORM_LAND | CMD_AUTO | CMD_MSG(STR_0808_CAN_T_RAISE_LAND_HERE)
);
}
static void PlaceProc_LowerLand(TileIndex tile)
{
DoCommandP(
tile, SLOPE_N, 0, CcTerraform,
CMD_TERRAFORM_LAND | CMD_AUTO | CMD_MSG(STR_0809_CAN_T_LOWER_LAND_HERE)
);
}
void PlaceProc_LevelLand(TileIndex tile)
{
VpStartPlaceSizing(tile, VPM_X_AND_Y | GUI_PlaceProc_LevelArea);
}
static void TerraformClick_Lower(Window *w)
{
HandlePlacePushButton(w, 4, ANIMCURSOR_LOWERLAND, 2, PlaceProc_LowerLand);
}
static void TerraformClick_Raise(Window *w)
{
HandlePlacePushButton(w, 5, ANIMCURSOR_RAISELAND, 2, PlaceProc_RaiseLand);
}
static void TerraformClick_Level(Window *w)
{
HandlePlacePushButton(w, 6, SPR_CURSOR_LEVEL_LAND, 2, PlaceProc_LevelLand);
}
static void TerraformClick_Dynamite(Window *w)
{
HandlePlacePushButton(w, 7, ANIMCURSOR_DEMOLISH , 1, PlaceProc_DemolishArea);
}
static void TerraformClick_BuyLand(Window *w)
{
HandlePlacePushButton(w, 8, SPR_CURSOR_BUY_LAND, 1, PlaceProc_BuyLand);
}
static void TerraformClick_Trees(Window *w)
{
/* This button is NOT a place-push-button, so don't treat it as such */
ShowBuildTreesToolbar();
}
static void TerraformClick_PlaceSign(Window *w)
{
HandlePlacePushButton(w, 10, SPR_CURSOR_SIGN, 1, PlaceProc_Sign);
}
static OnButtonClick * const _terraform_button_proc[] = {
TerraformClick_Lower,
TerraformClick_Raise,
TerraformClick_Level,
TerraformClick_Dynamite,
TerraformClick_BuyLand,
TerraformClick_Trees,
TerraformClick_PlaceSign,
};
static void TerraformToolbWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT:
DrawWindowWidgets(w);
break;
case WE_CLICK:
if (e->click.widget >= 4) _terraform_button_proc[e->click.widget - 4](w);
break;
case WE_KEYPRESS: {
uint i;
for (i = 0; i != lengthof(_terraform_keycodes); i++) {
if (e->keypress.keycode == _terraform_keycodes[i]) {
e->keypress.cont = false;
_terraform_button_proc[i](w);
break;
}
}
break;
}
case WE_PLACE_OBJ:
_place_proc(e->place.tile);
return;
case WE_PLACE_DRAG:
VpSelectTilesWithMethod(e->place.pt.x, e->place.pt.y, e->place.userdata & 0xF);
break;
case WE_PLACE_MOUSEUP:
if (e->click.pt.x != -1 &&
(e->place.userdata & 0xF) == VPM_X_AND_Y) { // dragged actions
GUIPlaceProcDragXY(e);
}
break;
case WE_ABORT_PLACE_OBJ:
UnclickWindowButtons(w);
SetWindowDirty(w);
break;
}
}
static const Widget _terraform_widgets[] = {
{ 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},
{ WWT_PANEL, RESIZE_NONE, 7, 66, 69, 14, 35, STR_NULL, STR_NULL},
{ WWT_PANEL, RESIZE_NONE, 7, 0, 21, 14, 35, SPR_IMG_TERRAFORM_DOWN, STR_018E_LOWER_A_CORNER_OF_LAND},
{ WWT_PANEL, RESIZE_NONE, 7, 22, 43, 14, 35, SPR_IMG_TERRAFORM_UP, STR_018F_RAISE_A_CORNER_OF_LAND},
{ WWT_PANEL, RESIZE_NONE, 7, 44, 65, 14, 35, SPR_IMG_LEVEL_LAND, STR_LEVEL_LAND_TOOLTIP},
{ WWT_PANEL, RESIZE_NONE, 7, 70, 91, 14, 35, SPR_IMG_DYNAMITE, STR_018D_DEMOLISH_BUILDINGS_ETC},
{ WWT_PANEL, RESIZE_NONE, 7, 92, 113, 14, 35, SPR_IMG_BUY_LAND, STR_0329_PURCHASE_LAND_FOR_FUTURE},
{ WWT_PANEL, RESIZE_NONE, 7, 114, 135, 14, 35, SPR_IMG_PLANTTREES, STR_0185_PLANT_TREES_PLACE_SIGNS},
{ WWT_PANEL, RESIZE_NONE, 7, 136, 157, 14, 35, SPR_IMG_PLACE_SIGN, STR_0289_PLACE_SIGN},
{ WIDGETS_END},
};
static const WindowDesc _terraform_desc = {
640-157, 22+36, 158, 36,
WC_SCEN_LAND_GEN,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
_terraform_widgets,
TerraformToolbWndProc
};
void ShowTerraformToolbar(void)
{
if (_current_player == OWNER_SPECTATOR) return;
AllocateWindowDescFront(&_terraform_desc, 0);
}
|