rubidium@10513: /* $Id$ */ rubidium@10513: rubidium@10513: /** @file tree_gui.cpp GUIs for building trees. */ rubidium@10513: rubidium@10513: #include "stdafx.h" rubidium@10513: #include "openttd.h" rubidium@10513: #include "window_gui.h" rubidium@10513: #include "gfx_func.h" rubidium@10513: #include "tilehighlight_func.h" rubidium@10513: #include "player_func.h" rubidium@10513: #include "command_func.h" rubidium@10513: #include "sound_func.h" rubidium@10513: #include "settings_type.h" rubidium@10513: rubidium@10513: #include "table/sprites.h" rubidium@10513: #include "table/strings.h" rubidium@10513: #include "table/tree_land.h" rubidium@10513: rubidium@10513: void PlaceTreesRandomly(); rubidium@10513: glx@10645: class BuildTreesWindow : public Window glx@10645: { glx@10645: uint16 base; glx@10645: uint16 count; glx@10645: int tree_to_plant; glx@10645: glx@10645: enum BuildTreesWidgets { glx@10645: BTW_CLOSE, glx@10645: BTW_CAPTION, glx@10645: BTW_BACKGROUND, glx@10645: BTW_TYPE_11, glx@10645: BTW_TYPE_12, glx@10645: BTW_TYPE_13, glx@10645: BTW_TYPE_14, glx@10645: BTW_TYPE_21, glx@10645: BTW_TYPE_22, glx@10645: BTW_TYPE_23, glx@10645: BTW_TYPE_24, glx@10645: BTW_TYPE_31, glx@10645: BTW_TYPE_32, glx@10645: BTW_TYPE_33, glx@10645: BTW_TYPE_34, glx@10645: BTW_TYPE_RANDOM, glx@10645: BTW_MANY_RANDOM, glx@10645: }; glx@10645: glx@10645: public: glx@10645: BuildTreesWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) glx@10645: { glx@10645: if (_game_mode != GM_EDITOR) { glx@10645: this->HideWidget(BTW_MANY_RANDOM); glx@10645: int offset = this->widget[BTW_MANY_RANDOM].bottom - this->widget[BTW_MANY_RANDOM].top; glx@10645: this->height -= offset; glx@10645: this->widget[BTW_BACKGROUND].bottom -= offset; glx@10645: } glx@10645: ResetObjectToPlace(); glx@10645: this->FindWindowPlacementAndResize(desc); glx@10645: } glx@10645: glx@10645: virtual void OnPaint() glx@10645: { glx@10645: static const PalSpriteID tree_sprites[] = { glx@10645: { 0x655, PAL_NONE }, { 0x663, PAL_NONE }, { 0x678, PAL_NONE }, { 0x62B, PAL_NONE }, glx@10645: { 0x647, PAL_NONE }, { 0x639, PAL_NONE }, { 0x64E, PAL_NONE }, { 0x632, PAL_NONE }, glx@10645: { 0x67F, PAL_NONE }, { 0x68D, PAL_NONE }, { 0x69B, PAL_NONE }, { 0x6A9, PAL_NONE }, glx@10645: { 0x6AF, PAL_NONE }, { 0x6D2, PAL_NONE }, { 0x6D9, PAL_NONE }, { 0x6C4, PAL_NONE }, glx@10645: { 0x6CB, PAL_NONE }, { 0x6B6, PAL_NONE }, { 0x6BD, PAL_NONE }, { 0x6E0, PAL_NONE }, glx@10645: { 0x72E, PAL_NONE }, { 0x734, PAL_NONE }, { 0x74A, PAL_NONE }, { 0x74F, PAL_NONE }, glx@10645: { 0x76B, PAL_NONE }, { 0x78F, PAL_NONE }, { 0x788, PAL_NONE }, { 0x77B, PAL_NONE }, glx@10645: { 0x75F, PAL_NONE }, { 0x774, PAL_NONE }, { 0x720, PAL_NONE }, { 0x797, PAL_NONE }, glx@10645: { 0x79E, PAL_NONE }, { 0x7A5, PALETTE_TO_GREEN }, { 0x7AC, PALETTE_TO_RED }, { 0x7B3, PAL_NONE }, glx@10645: { 0x7BA, PAL_NONE }, { 0x7C1, PALETTE_TO_RED, }, { 0x7C8, PALETTE_TO_PALE_GREEN }, { 0x7CF, PALETTE_TO_YELLOW }, { 0x7D6, PALETTE_TO_RED } glx@10645: }; glx@10645: glx@10645: this->DrawWidgets(); glx@10645: glx@10776: int i = this->base = _tree_base_by_landscape[_settings_game.game_creation.landscape]; glx@10776: int count = this->count = _tree_count_by_landscape[_settings_game.game_creation.landscape]; glx@10645: glx@10645: int x = 18; glx@10645: int y = 54; glx@10645: do { glx@10645: DrawSprite(tree_sprites[i].sprite, tree_sprites[i].pal, x, y); glx@10645: x += 35; glx@10645: if (!(++i & 3)) { glx@10645: x -= 35 * 4; glx@10645: y += 47; glx@10645: } glx@10645: } while (--count); glx@10645: } glx@10645: glx@10645: virtual void OnClick(Point pt, int widget) glx@10645: { glx@10645: switch (widget) { glx@10645: case BTW_TYPE_11: case BTW_TYPE_12: case BTW_TYPE_13: case BTW_TYPE_14: glx@10645: case BTW_TYPE_21: case BTW_TYPE_22: case BTW_TYPE_23: case BTW_TYPE_24: glx@10645: case BTW_TYPE_31: case BTW_TYPE_32: case BTW_TYPE_33: case BTW_TYPE_34: glx@10645: if (widget - BTW_TYPE_11 >= this->count) break; glx@10645: glx@10645: if (HandlePlacePushButton(this, widget, SPR_CURSOR_TREE, VHM_RECT, NULL)) { glx@10645: this->tree_to_plant = this->base + widget - BTW_TYPE_11; glx@10645: } glx@10645: break; glx@10645: glx@10645: case BTW_TYPE_RANDOM: // tree of random type. glx@10645: if (HandlePlacePushButton(this, BTW_TYPE_RANDOM, SPR_CURSOR_TREE, VHM_RECT, NULL)) { glx@10645: this->tree_to_plant = -1; glx@10645: } glx@10645: break; glx@10645: glx@10645: case BTW_MANY_RANDOM: // place trees randomly over the landscape glx@10645: this->LowerWidget(BTW_MANY_RANDOM); glx@10645: this->flags4 |= 5 << WF_TIMEOUT_SHL; glx@10645: SndPlayFx(SND_15_BEEP); glx@10645: PlaceTreesRandomly(); glx@10645: MarkWholeScreenDirty(); glx@10645: break; glx@10645: } glx@10645: } glx@10645: glx@10645: virtual void OnPlaceObject(Point pt, TileIndex tile) glx@10645: { glx@10645: VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED, DDSP_PLANT_TREES); glx@10645: VpSetPlaceSizingLimit(20); glx@10645: } glx@10645: glx@10645: virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) glx@10645: { glx@10645: VpSelectTilesWithMethod(pt.x, pt.y, select_method); glx@10645: } glx@10645: glx@10645: virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) glx@10645: { glx@10645: if (pt.x != -1 && select_proc == DDSP_PLANT_TREES) { glx@10645: DoCommandP(end_tile, this->tree_to_plant, start_tile, NULL, glx@10645: CMD_PLANT_TREE | CMD_MSG(STR_2805_CAN_T_PLANT_TREE_HERE)); glx@10645: } glx@10645: } glx@10645: glx@10645: virtual void OnTimeout() glx@10645: { glx@10645: this->RaiseWidget(BTW_MANY_RANDOM); glx@10645: this->InvalidateWidget(BTW_MANY_RANDOM); glx@10645: } glx@10645: glx@10645: virtual void OnPlaceObjectAbort() glx@10645: { glx@10645: this->RaiseButtons(); glx@10645: } rubidium@10513: }; rubidium@10513: rubidium@10513: static const Widget _build_trees_widgets[] = { glx@10645: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // BTW_CLOSE glx@10645: { WWT_CAPTION, RESIZE_NONE, 7, 11, 142, 0, 13, STR_2802_TREES, STR_018C_WINDOW_TITLE_DRAG_THIS}, // BTW_CAPTION glx@10645: { WWT_PANEL, RESIZE_NONE, 7, 0, 142, 14, 183, 0x0, STR_NULL}, // BTW_BACKGROUND glx@10645: { WWT_PANEL, RESIZE_NONE, 14, 2, 35, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_11 glx@10645: { WWT_PANEL, RESIZE_NONE, 14, 37, 70, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_12 glx@10645: { WWT_PANEL, RESIZE_NONE, 14, 72, 105, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_13 glx@10645: { WWT_PANEL, RESIZE_NONE, 14, 107, 140, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_14 glx@10645: { WWT_PANEL, RESIZE_NONE, 14, 2, 35, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_21 glx@10645: { WWT_PANEL, RESIZE_NONE, 14, 37, 70, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_22 glx@10645: { WWT_PANEL, RESIZE_NONE, 14, 72, 105, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_23 glx@10645: { WWT_PANEL, RESIZE_NONE, 14, 107, 140, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_24 glx@10645: { WWT_PANEL, RESIZE_NONE, 14, 2, 35, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_31 glx@10645: { WWT_PANEL, RESIZE_NONE, 14, 37, 70, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_32 glx@10645: { WWT_PANEL, RESIZE_NONE, 14, 72, 105, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_33 glx@10645: { WWT_PANEL, RESIZE_NONE, 14, 107, 140, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_34 glx@10645: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 140, 157, 168, STR_TREES_RANDOM_TYPE, STR_TREES_RANDOM_TYPE_TIP}, // BTW_TYPE_RANDOM glx@10645: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 140, 170, 181, STR_028A_RANDOM_TREES, STR_028B_PLANT_TREES_RANDOMLY_OVER}, // BTW_MANY_RANDOM rubidium@10513: { WIDGETS_END}, rubidium@10513: }; rubidium@10513: rubidium@10513: static const WindowDesc _build_trees_desc = { rubidium@10513: WDP_AUTO, WDP_AUTO, 143, 184, 143, 184, rubidium@10513: WC_BUILD_TREES, WC_NONE, rubidium@10513: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, glx@10645: _build_trees_widgets, rubidium@10513: }; rubidium@10513: rubidium@10513: void ShowBuildTreesToolbar() rubidium@10513: { glx@10645: if (_game_mode != GM_EDITOR && !IsValidPlayer(_current_player)) return; glx@10645: AllocateWindowDescFront(&_build_trees_desc, 0); rubidium@10513: }