2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "ttd.h"
|
2005-02-13 11:18:02 +00:00
|
|
|
#include "table/sprites.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "window.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
#include "gfx.h"
|
2004-11-05 23:12:33 +00:00
|
|
|
#include "sound.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "command.h"
|
|
|
|
#include "vehicle.h"
|
2005-01-12 11:21:28 +00:00
|
|
|
#include "signs.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-04 18:17:52 +00:00
|
|
|
void CcTerraform(bool success, uint tile, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
if (success) {
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayTileFx(SND_1F_SPLAT, tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
|
|
|
SetRedErrorSquare(_terraform_err_tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void GenericRaiseLowerLand(uint tile, int mode)
|
|
|
|
{
|
|
|
|
if (mode) {
|
2004-09-10 19:02:27 +00:00
|
|
|
DoCommandP(tile, 8, (uint32)mode, CcTerraform, CMD_TERRAFORM_LAND | CMD_AUTO | CMD_MSG(STR_0808_CAN_T_RAISE_LAND_HERE));
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2004-09-10 19:02:27 +00:00
|
|
|
DoCommandP(tile, 8, (uint32)mode, CcTerraform, CMD_TERRAFORM_LAND | CMD_AUTO | CMD_MSG(STR_0809_CAN_T_LOWER_LAND_HERE));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef void OnButtonClick(Window *w);
|
|
|
|
|
|
|
|
static const uint16 _terraform_keycodes[] = {
|
2004-12-12 17:42:04 +00:00
|
|
|
'Q',
|
|
|
|
'W',
|
|
|
|
'E',
|
2005-01-08 09:24:15 +00:00
|
|
|
'D',
|
2004-12-12 17:42:04 +00:00
|
|
|
'U',
|
|
|
|
'I',
|
2004-12-12 18:51:24 +00:00
|
|
|
'O',
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void PlaceProc_DemolishArea(uint tile)
|
|
|
|
{
|
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaceProc_RaiseLand(uint tile)
|
|
|
|
{
|
|
|
|
GenericRaiseLowerLand(tile, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaceProc_LowerLand(uint tile)
|
|
|
|
{
|
|
|
|
GenericRaiseLowerLand(tile, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaceProc_LevelLand(uint tile)
|
|
|
|
{
|
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y | (2<<4));
|
|
|
|
}
|
|
|
|
|
2005-01-22 22:47:58 +00:00
|
|
|
static void PlaceProc_PlantTree(uint tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TerraformClick_Lower(Window *w)
|
|
|
|
{
|
2004-12-22 00:18:40 +00:00
|
|
|
HandlePlacePushButton(w, 4, ANIMCURSOR_LOWERLAND, 2, PlaceProc_LowerLand);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TerraformClick_Raise(Window *w)
|
|
|
|
{
|
2004-12-22 00:18:40 +00:00
|
|
|
HandlePlacePushButton(w, 5, ANIMCURSOR_RAISELAND, 2, PlaceProc_RaiseLand);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TerraformClick_Level(Window *w)
|
|
|
|
{
|
2004-12-22 00:18:40 +00:00
|
|
|
HandlePlacePushButton(w, 6, SPR_OPENTTD_BASE+69, 2, PlaceProc_LevelLand);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-01-08 09:24:15 +00:00
|
|
|
static void TerraformClick_Dynamite(Window *w)
|
|
|
|
{
|
|
|
|
HandlePlacePushButton(w, 7, SPR_IMG_DYNAMITE+1 , 1, PlaceProc_DemolishArea);
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static void TerraformClick_BuyLand(Window *w)
|
|
|
|
{
|
2005-01-08 09:24:15 +00:00
|
|
|
HandlePlacePushButton(w, 8, 4792, 1, PlaceProc_BuyLand);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TerraformClick_Trees(Window *w)
|
|
|
|
{
|
2005-01-08 09:24:15 +00:00
|
|
|
if (HandlePlacePushButton(w, 9, 0, 1, PlaceProc_PlantTree)) ShowBuildTreesToolbar();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TerraformClick_PlaceSign(Window *w)
|
|
|
|
{
|
2005-01-08 09:24:15 +00:00
|
|
|
HandlePlacePushButton(w, 10, 722, 1, PlaceProc_Sign);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static OnButtonClick * const _terraform_button_proc[] = {
|
|
|
|
TerraformClick_Lower,
|
|
|
|
TerraformClick_Raise,
|
|
|
|
TerraformClick_Level,
|
2005-01-08 09:24:15 +00:00
|
|
|
TerraformClick_Dynamite,
|
2004-12-12 17:42:04 +00:00
|
|
|
TerraformClick_BuyLand,
|
2004-08-09 17:04:08 +00:00
|
|
|
TerraformClick_Trees,
|
|
|
|
TerraformClick_PlaceSign,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void TerraformToolbWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
|
|
|
switch(e->event) {
|
|
|
|
case WE_PAINT:
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
break;
|
|
|
|
case WE_CLICK:
|
2004-12-22 00:18:40 +00:00
|
|
|
if (e->click.widget >= 4) {
|
|
|
|
_terraform_button_proc[e->click.widget - 4](w);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_KEYPRESS:
|
|
|
|
{
|
|
|
|
int i;
|
2004-12-12 22:05:08 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
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) {
|
|
|
|
uint start_tile = e->place.starttile;
|
|
|
|
uint end_tile = e->place.tile;
|
|
|
|
|
|
|
|
if (e->place.userdata == VPM_X_AND_Y) {
|
|
|
|
DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA));
|
|
|
|
} else if (e->place.userdata == (VPM_X_AND_Y | (2<<4))) {
|
|
|
|
DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_LEVEL_LAND | CMD_AUTO);
|
|
|
|
} else if (e->place.userdata == VPM_X_AND_Y_LIMITED) {
|
|
|
|
// if (e->click.pt.x != -1) {
|
2004-09-10 19:02:27 +00:00
|
|
|
// DoCommandP(e->place.tile, _tree_to_plant, e->place.starttile, NULL,
|
2004-08-09 17:04:08 +00:00
|
|
|
// CMD_PLANT_TREE | CMD_AUTO | CMD_MSG(STR_2805_CAN_T_PLANT_TREE_HERE));
|
|
|
|
} else {
|
|
|
|
assert(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_ABORT_PLACE_OBJ:
|
2004-12-22 00:18:40 +00:00
|
|
|
UnclickWindowButtons(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
|
|
|
|
w = FindWindowById(WC_BUILD_STATION, 0);
|
|
|
|
if (w != NULL) WP(w,def_d).close=true;
|
|
|
|
w = FindWindowById(WC_BUILD_DEPOT, 0);
|
|
|
|
if (w != NULL) WP(w,def_d).close=true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_PLACE_PRESIZE: {
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _terraform_widgets[] = {
|
2005-01-03 19:45:18 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
2005-01-08 09:24:15 +00:00
|
|
|
{ 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, 0x0, STR_STICKY_BUTTON},
|
2005-01-03 19:45:18 +00:00
|
|
|
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 66, 69, 14, 35, 0x0, STR_NULL},
|
|
|
|
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 21, 14, 35, 695, STR_018E_LOWER_A_CORNER_OF_LAND},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 22, 43, 14, 35, 694, STR_018F_RAISE_A_CORNER_OF_LAND},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 44, 65, 14, 35, SPR_OPENTTD_BASE+68, STR_LEVEL_LAND_TOOLTIP},
|
2005-01-08 09:24:15 +00:00
|
|
|
{ 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, 4791, STR_0329_PURCHASE_LAND_FOR_FUTURE},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 114, 135, 14, 35, 742, STR_0185_PLANT_TREES_PLACE_SIGNS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 136, 157, 14, 35, SPR_OPENTTD_BASE+70, STR_0289_PLACE_SIGN},
|
|
|
|
|
2004-09-07 21:48:09 +00:00
|
|
|
|
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _terraform_desc = {
|
2005-01-12 00:50:08 +00:00
|
|
|
640-157, 22+36, 158, 36,
|
2004-08-09 17:04:08 +00:00
|
|
|
WC_SCEN_LAND_GEN,0,
|
2004-12-22 00:18:40 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
2004-08-09 17:04:08 +00:00
|
|
|
_terraform_widgets,
|
|
|
|
TerraformToolbWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void ShowTerraformToolbar(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-01-08 20:55:21 +00:00
|
|
|
if (_current_player == OWNER_SPECTATOR) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
AllocateWindowDescFront(&_terraform_desc, 0);
|
|
|
|
}
|