truelight@0: #include "stdafx.h" truelight@0: #include "ttd.h" truelight@0: truelight@0: #include "window.h" truelight@0: #include "gui.h" truelight@0: #include "viewport.h" truelight@0: #include "gfx.h" truelight@0: #include "command.h" truelight@0: #include "vehicle.h" truelight@0: truelight@0: truelight@0: static void CcTerraform(bool success, uint tile, uint32 p1, uint32 p2) truelight@0: { truelight@0: if (success) { truelight@0: SndPlayTileFx(0x1D, tile); truelight@0: } else { truelight@0: SetRedErrorSquare(_terraform_err_tile); truelight@0: } truelight@0: } truelight@0: truelight@0: static void GenericRaiseLowerLand(uint tile, int mode) truelight@0: { truelight@0: if (mode) { truelight@0: DoCommandP(tile, 8, (uint32)mode, CcTerraform, CMD_TERRAFORM_LAND | CMD_AUTO | CMD_MSG(STR_0808_CAN_T_RAISE_LAND_HERE)); truelight@0: } else { truelight@0: DoCommandP(tile, 8, (uint32)mode, CcTerraform, CMD_TERRAFORM_LAND | CMD_AUTO | CMD_MSG(STR_0809_CAN_T_LOWER_LAND_HERE)); truelight@0: } truelight@0: } truelight@0: truelight@0: truelight@0: typedef void OnButtonClick(Window *w); truelight@0: truelight@0: static const uint16 _terraform_keycodes[] = { truelight@0: '1', truelight@0: '2', truelight@0: '3', truelight@0: '4', truelight@0: '5', dominik@30: 0, truelight@0: '7', truelight@0: }; truelight@0: truelight@0: void PlaceProc_DemolishArea(uint tile) truelight@0: { truelight@0: VpStartPlaceSizing(tile, VPM_X_AND_Y); truelight@0: } truelight@0: truelight@0: void PlaceProc_RaiseLand(uint tile) truelight@0: { truelight@0: GenericRaiseLowerLand(tile, 1); truelight@0: } truelight@0: truelight@0: void PlaceProc_LowerLand(uint tile) truelight@0: { truelight@0: GenericRaiseLowerLand(tile, 0); truelight@0: } truelight@0: truelight@0: void PlaceProc_LevelLand(uint tile) truelight@0: { truelight@0: VpStartPlaceSizing(tile, VPM_X_AND_Y | (2<<4)); truelight@0: } truelight@0: truelight@0: void PlaceProc_PlantTree(uint tile) truelight@0: { truelight@0: } truelight@0: truelight@0: truelight@0: truelight@0: truelight@0: static void TerraformClick_Dynamite(Window *w) truelight@0: { truelight@0: HandlePlacePushButton(w, 2, ANIMCURSOR_DEMOLISH, 1, PlaceProc_DemolishArea); truelight@0: } truelight@0: truelight@0: static void TerraformClick_Lower(Window *w) truelight@0: { truelight@0: HandlePlacePushButton(w, 3, ANIMCURSOR_LOWERLAND, 2, PlaceProc_LowerLand); truelight@0: } truelight@0: truelight@0: static void TerraformClick_Raise(Window *w) truelight@0: { truelight@0: HandlePlacePushButton(w, 4, ANIMCURSOR_RAISELAND, 2, PlaceProc_RaiseLand); truelight@0: } truelight@0: truelight@0: static void TerraformClick_Level(Window *w) truelight@0: { truelight@0: HandlePlacePushButton(w, 5, SPR_OPENTTD_BASE+69, 2, PlaceProc_LevelLand); truelight@0: } truelight@0: truelight@0: static void TerraformClick_BuyLand(Window *w) truelight@0: { truelight@0: HandlePlacePushButton(w, 6, 4792, 1, PlaceProc_BuyLand); truelight@0: } truelight@0: truelight@0: static void TerraformClick_Trees(Window *w) truelight@0: { truelight@0: if (HandlePlacePushButton(w, 8, 0, 1, PlaceProc_PlantTree)) ShowBuildTreesToolbar(); truelight@0: } truelight@0: truelight@0: static void TerraformClick_PlaceSign(Window *w) truelight@0: { truelight@0: HandlePlacePushButton(w, 9, 722, 1, PlaceProc_Sign); truelight@0: } truelight@0: truelight@0: truelight@0: static OnButtonClick * const _terraform_button_proc[] = { truelight@0: TerraformClick_Dynamite, truelight@0: TerraformClick_Lower, truelight@0: TerraformClick_Raise, truelight@0: TerraformClick_Level, truelight@0: TerraformClick_BuyLand, truelight@0: 0, truelight@0: TerraformClick_Trees, truelight@0: TerraformClick_PlaceSign, truelight@0: }; truelight@0: truelight@0: truelight@0: truelight@0: static void TerraformToolbWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: truelight@0: DrawWindowWidgets(w); truelight@0: break; truelight@0: case WE_CLICK: truelight@0: if (e->click.widget >= 2 && e->click.widget != 7) { truelight@0: _terraform_button_proc[e->click.widget - 2](w); truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_KEYPRESS: truelight@0: { truelight@0: int i; truelight@0: for(i=0; i!=lengthof(_terraform_keycodes); i++) truelight@0: if (e->keypress.keycode == _terraform_keycodes[i]) { truelight@0: e->keypress.cont = false; truelight@0: _terraform_button_proc[i](w); truelight@0: break; truelight@0: } truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_PLACE_OBJ: truelight@0: _place_proc(e->place.tile); truelight@0: return; truelight@0: truelight@0: case WE_PLACE_DRAG: truelight@0: VpSelectTilesWithMethod(e->place.pt.x, e->place.pt.y, e->place.userdata & 0xF); truelight@0: break; truelight@0: truelight@0: case WE_PLACE_MOUSEUP: truelight@0: if (e->click.pt.x != -1) { truelight@0: uint start_tile = e->place.starttile; truelight@0: uint end_tile = e->place.tile; truelight@0: truelight@0: if (e->place.userdata == VPM_X_AND_Y) { truelight@0: DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA)); truelight@0: } else if (e->place.userdata == (VPM_X_AND_Y | (2<<4))) { truelight@0: DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_LEVEL_LAND | CMD_AUTO); truelight@0: } else if (e->place.userdata == VPM_X_AND_Y_LIMITED) { truelight@0: // if (e->click.pt.x != -1) { truelight@0: // DoCommandP(e->place.tile, _tree_to_plant, e->place.starttile, NULL, truelight@0: // CMD_PLANT_TREE | CMD_AUTO | CMD_MSG(STR_2805_CAN_T_PLANT_TREE_HERE)); truelight@0: } else { truelight@0: assert(true); truelight@0: } truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_ABORT_PLACE_OBJ: truelight@0: w->click_state = 0; truelight@0: SetWindowDirty(w); truelight@0: truelight@0: w = FindWindowById(WC_BUILD_STATION, 0); truelight@0: if (w != NULL) WP(w,def_d).close=true; truelight@0: w = FindWindowById(WC_BUILD_DEPOT, 0); truelight@0: if (w != NULL) WP(w,def_d).close=true; truelight@0: break; truelight@0: truelight@0: case WE_PLACE_PRESIZE: { truelight@0: } break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _terraform_widgets[] = { truelight@0: { WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 7, 11, 157, 0, 13, STR_LANDSCAPING_TOOLBAR, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: truelight@0: truelight@0: { WWT_PANEL, 7, 0, 21, 14, 35, 703, STR_018D_DEMOLISH_BUILDINGS_ETC}, truelight@0: { WWT_PANEL, 7, 22, 43, 14, 35, 695, STR_018E_LOWER_A_CORNER_OF_LAND}, truelight@0: { WWT_PANEL, 7, 44, 65, 14, 35, 694, STR_018F_RAISE_A_CORNER_OF_LAND}, truelight@0: { WWT_PANEL, 7, 66, 87, 14, 35, SPR_OPENTTD_BASE+68, STR_LEVEL_LAND_TOOLTIP}, truelight@0: { WWT_PANEL, 7, 88, 109, 14, 35, 4791, STR_0329_PURCHASE_LAND_FOR_FUTURE}, truelight@0: { WWT_PANEL, 7, 110, 113, 14, 35, 0, 0x0}, truelight@0: { WWT_PANEL, 7, 114, 135, 14, 35, 742, STR_0185_PLANT_TREES_PLACE_SIGNS}, truelight@0: { WWT_PANEL, 7, 136, 157, 14, 35, SPR_OPENTTD_BASE+70, STR_0289_PLACE_SIGN}, truelight@0: truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _terraform_desc = { truelight@0: 640-158, 22+36, 158, 36, truelight@0: WC_SCEN_LAND_GEN,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _terraform_widgets, truelight@0: TerraformToolbWndProc truelight@0: }; truelight@0: truelight@0: truelight@0: truelight@0: void ShowTerraformToolbar() truelight@0: { truelight@0: AllocateWindowDescFront(&_terraform_desc, 0); truelight@0: }