tron@2186: /* $Id$ */ tron@2186: rubidium@10467: /** @file tree_gui.cpp GUIs for building trees. */ belugas@6527: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" rubidium@8603: #include "window_gui.h" rubidium@8720: #include "gfx_func.h" rubidium@10467: #include "tilehighlight_func.h" rubidium@8750: #include "player_func.h" rubidium@10467: #include "command_func.h" rubidium@8653: #include "sound_func.h" rubidium@8766: #include "settings_type.h" rubidium@8615: rubidium@8760: #include "table/sprites.h" rubidium@8760: #include "table/strings.h" rubidium@8760: #include "table/tree_land.h" rubidium@8760: rubidium@10467: struct tree_d { rubidium@10467: uint16 base; rubidium@10467: uint16 count; truelight@0: }; rubidium@10467: assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(tree_d)); truelight@0: truelight@0: static int _tree_to_plant; rubidium@10467: void PlaceTreesRandomly(); truelight@0: peter1138@5919: static const PalSpriteID _tree_sprites[] = { peter1138@5919: { 0x655, PAL_NONE }, { 0x663, PAL_NONE }, { 0x678, PAL_NONE }, { 0x62B, PAL_NONE }, peter1138@5919: { 0x647, PAL_NONE }, { 0x639, PAL_NONE }, { 0x64E, PAL_NONE }, { 0x632, PAL_NONE }, peter1138@5919: { 0x67F, PAL_NONE }, { 0x68D, PAL_NONE }, { 0x69B, PAL_NONE }, { 0x6A9, PAL_NONE }, peter1138@5919: { 0x6AF, PAL_NONE }, { 0x6D2, PAL_NONE }, { 0x6D9, PAL_NONE }, { 0x6C4, PAL_NONE }, peter1138@5919: { 0x6CB, PAL_NONE }, { 0x6B6, PAL_NONE }, { 0x6BD, PAL_NONE }, { 0x6E0, PAL_NONE }, peter1138@5919: { 0x72E, PAL_NONE }, { 0x734, PAL_NONE }, { 0x74A, PAL_NONE }, { 0x74F, PAL_NONE }, peter1138@5919: { 0x76B, PAL_NONE }, { 0x78F, PAL_NONE }, { 0x788, PAL_NONE }, { 0x77B, PAL_NONE }, peter1138@5919: { 0x75F, PAL_NONE }, { 0x774, PAL_NONE }, { 0x720, PAL_NONE }, { 0x797, PAL_NONE }, peter1138@5919: { 0x79E, PAL_NONE }, { 0x7A5, PALETTE_TO_GREEN }, { 0x7AC, PALETTE_TO_RED }, { 0x7B3, PAL_NONE }, peter1138@5919: { 0x7BA, PAL_NONE }, { 0x7C1, PALETTE_TO_RED, }, { 0x7C8, PALETTE_TO_PALE_GREEN }, { 0x7CF, PALETTE_TO_YELLOW }, { 0x7D6, PALETTE_TO_RED } truelight@0: }; truelight@0: truelight@0: static void BuildTreesWndProc(Window *w, WindowEvent *e) truelight@0: { tron@2639: switch (e->event) { smatz@9327: case WE_CREATE: smatz@9327: ResetObjectToPlace(); smatz@9327: break; smatz@9327: rubidium@9234: case WE_PAINT: { rubidium@9234: DrawWindowWidgets(w); truelight@0: smatz@9315: int i = WP(w, tree_d).base = _tree_base_by_landscape[_opt.landscape]; smatz@9315: int count = WP(w, tree_d).count = _tree_count_by_landscape[_opt.landscape]; rubidium@9234: rubidium@9234: int x = 18; rubidium@9234: int y = 54; rubidium@9234: do { rubidium@9234: DrawSprite(_tree_sprites[i].sprite, _tree_sprites[i].pal, x, y); rubidium@9234: x += 35; rubidium@9234: if (!(++i & 3)) { rubidium@9234: x -= 35 * 4; rubidium@9234: y += 47; rubidium@9234: } rubidium@9234: } while (--count); rubidium@9234: } break; rubidium@9234: rubidium@9234: case WE_CLICK: { rubidium@9234: int wid = e->we.click.widget; rubidium@9234: rubidium@9234: switch (wid) { smatz@9315: case 0: rubidium@9234: ResetObjectToPlace(); rubidium@9234: break; rubidium@9234: rubidium@9234: case 3: case 4: case 5: case 6: rubidium@9234: case 7: case 8: case 9: case 10: rubidium@9234: case 11:case 12: case 13: case 14: rubidium@9234: if (wid - 3 >= WP(w, tree_d).count) break; rubidium@9234: rubidium@9234: if (HandlePlacePushButton(w, wid, SPR_CURSOR_TREE, VHM_RECT, NULL)) { rubidium@9234: _tree_to_plant = WP(w, tree_d).base + wid - 3; rubidium@9234: } rubidium@9234: break; rubidium@9234: rubidium@9234: case 15: // tree of random type. rubidium@9234: if (HandlePlacePushButton(w, 15, SPR_CURSOR_TREE, VHM_RECT, NULL)) { rubidium@9234: _tree_to_plant = -1; rubidium@9234: } rubidium@9234: break; rubidium@9234: rubidium@9234: case 16: // place trees randomly over the landscape rubidium@9234: w->LowerWidget(16); rubidium@9234: w->flags4 |= 5 << WF_TIMEOUT_SHL; rubidium@9234: SndPlayFx(SND_15_BEEP); rubidium@9234: PlaceTreesRandomly(); rubidium@9234: MarkWholeScreenDirty(); rubidium@9234: break; truelight@0: } rubidium@9234: } break; truelight@0: rubidium@9234: case WE_PLACE_OBJ: rubidium@9234: VpStartPlaceSizing(e->we.place.tile, VPM_X_AND_Y_LIMITED, DDSP_PLANT_TREES); rubidium@9234: VpSetPlaceSizingLimit(20); truelight@0: break; truelight@0: rubidium@9234: case WE_PLACE_DRAG: rubidium@9234: VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method); rubidium@9234: return; rubidium@9234: rubidium@9234: case WE_PLACE_MOUSEUP: rubidium@9234: if (e->we.place.pt.x != -1 && e->we.place.select_proc == DDSP_PLANT_TREES) { rubidium@9234: DoCommandP(e->we.place.tile, _tree_to_plant, e->we.place.starttile, NULL, rubidium@9234: CMD_PLANT_TREE | CMD_MSG(STR_2805_CAN_T_PLANT_TREE_HERE)); rubidium@9234: } truelight@0: break; truelight@0: rubidium@9234: case WE_TIMEOUT: rubidium@9234: w->RaiseWidget(16); truelight@0: break; truelight@0: rubidium@9234: case WE_ABORT_PLACE_OBJ: rubidium@9234: w->RaiseButtons(); rubidium@9234: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _build_trees_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@4344: { WWT_CAPTION, RESIZE_NONE, 7, 11, 142, 0, 13, STR_2802_TREES, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 7, 0, 142, 14, 170, 0x0, STR_NULL}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 2, 35, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 37, 70, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 72, 105, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 107, 140, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 2, 35, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 37, 70, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 72, 105, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 107, 140, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 2, 35, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 37, 70, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 72, 105, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 107, 140, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 140, 157, 168, STR_TREES_RANDOM_TYPE, STR_TREES_RANDOM_TYPE_TIP}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_trees_desc = { rubidium@7837: 497, 22, 143, 171, 143, 171, dominik@606: WC_BUILD_TREES, WC_SCEN_LAND_GEN, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _build_trees_widgets, truelight@0: BuildTreesWndProc truelight@0: }; truelight@0: truelight@0: static const Widget _build_trees_scen_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@4344: { WWT_CAPTION, RESIZE_NONE, 7, 11, 142, 0, 13, STR_2802_TREES, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 7, 0, 142, 14, 183, 0x0, STR_NULL}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 2, 35, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 37, 70, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 72, 105, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 107, 140, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 2, 35, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 37, 70, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 72, 105, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 107, 140, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 2, 35, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 37, 70, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 72, 105, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 107, 140, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 140, 157, 168, STR_TREES_RANDOM_TYPE, STR_TREES_RANDOM_TYPE_TIP}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 140, 170, 181, STR_028A_RANDOM_TREES, STR_028B_PLANT_TREES_RANDOMLY_OVER}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_trees_scen_desc = { rubidium@7837: WDP_AUTO, WDP_AUTO, 143, 184, 143, 184, rubidium@6144: WC_BUILD_TREES, WC_NONE, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _build_trees_scen_widgets, truelight@0: BuildTreesWndProc truelight@0: }; truelight@0: truelight@193: rubidium@6573: void ShowBuildTreesToolbar() truelight@0: { Darkvater@5005: if (!IsValidPlayer(_current_player)) return; rubidium@10462: AllocateWindowDescFront(&_build_trees_desc, 0); truelight@0: } truelight@0: rubidium@6573: void ShowBuildTreesScenToolbar() truelight@0: { rubidium@10462: AllocateWindowDescFront(&_build_trees_scen_desc, 0); truelight@0: }