00001
00002
00005 #include "stdafx.h"
00006 #include "openttd.h"
00007 #include "window_gui.h"
00008 #include "gfx_func.h"
00009 #include "tilehighlight_func.h"
00010 #include "company_func.h"
00011 #include "company_base.h"
00012 #include "command_func.h"
00013 #include "sound_func.h"
00014 #include "settings_type.h"
00015
00016 #include "table/sprites.h"
00017 #include "table/strings.h"
00018 #include "table/tree_land.h"
00019
00020 void PlaceTreesRandomly();
00021
00022 class BuildTreesWindow : public Window
00023 {
00024 uint16 base;
00025 uint16 count;
00026 uint tree_to_plant;
00027
00028 enum BuildTreesWidgets {
00029 BTW_CLOSE,
00030 BTW_CAPTION,
00031 BTW_BACKGROUND,
00032 BTW_TYPE_11,
00033 BTW_TYPE_12,
00034 BTW_TYPE_13,
00035 BTW_TYPE_14,
00036 BTW_TYPE_21,
00037 BTW_TYPE_22,
00038 BTW_TYPE_23,
00039 BTW_TYPE_24,
00040 BTW_TYPE_31,
00041 BTW_TYPE_32,
00042 BTW_TYPE_33,
00043 BTW_TYPE_34,
00044 BTW_TYPE_RANDOM,
00045 BTW_MANY_RANDOM,
00046 };
00047
00048 public:
00049 BuildTreesWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
00050 {
00051 if (_game_mode != GM_EDITOR) {
00052 this->HideWidget(BTW_MANY_RANDOM);
00053 int offset = this->widget[BTW_MANY_RANDOM].bottom - this->widget[BTW_MANY_RANDOM].top;
00054 this->height -= offset;
00055 this->widget[BTW_BACKGROUND].bottom -= offset;
00056 }
00057 ResetObjectToPlace();
00058 this->FindWindowPlacementAndResize(desc);
00059 }
00060
00061 virtual void OnPaint()
00062 {
00063 static const PalSpriteID tree_sprites[] = {
00064 { 0x655, PAL_NONE }, { 0x663, PAL_NONE }, { 0x678, PAL_NONE }, { 0x62B, PAL_NONE },
00065 { 0x647, PAL_NONE }, { 0x639, PAL_NONE }, { 0x64E, PAL_NONE }, { 0x632, PAL_NONE },
00066 { 0x67F, PAL_NONE }, { 0x68D, PAL_NONE }, { 0x69B, PAL_NONE }, { 0x6A9, PAL_NONE },
00067 { 0x6AF, PAL_NONE }, { 0x6D2, PAL_NONE }, { 0x6D9, PAL_NONE }, { 0x6C4, PAL_NONE },
00068 { 0x6CB, PAL_NONE }, { 0x6B6, PAL_NONE }, { 0x6BD, PAL_NONE }, { 0x6E0, PAL_NONE },
00069 { 0x72E, PAL_NONE }, { 0x734, PAL_NONE }, { 0x74A, PAL_NONE }, { 0x74F, PAL_NONE },
00070 { 0x76B, PAL_NONE }, { 0x78F, PAL_NONE }, { 0x788, PAL_NONE }, { 0x77B, PAL_NONE },
00071 { 0x75F, PAL_NONE }, { 0x774, PAL_NONE }, { 0x720, PAL_NONE }, { 0x797, PAL_NONE },
00072 { 0x79E, PAL_NONE }, { 0x7A5, PALETTE_TO_GREEN }, { 0x7AC, PALETTE_TO_RED }, { 0x7B3, PAL_NONE },
00073 { 0x7BA, PAL_NONE }, { 0x7C1, PALETTE_TO_RED, }, { 0x7C8, PALETTE_TO_PALE_GREEN }, { 0x7CF, PALETTE_TO_YELLOW }, { 0x7D6, PALETTE_TO_RED }
00074 };
00075
00076 this->DrawWidgets();
00077
00078 int i = this->base = _tree_base_by_landscape[_settings_game.game_creation.landscape];
00079 int count = this->count = _tree_count_by_landscape[_settings_game.game_creation.landscape];
00080
00081 int x = 18;
00082 int y = 54;
00083 do {
00084 DrawSprite(tree_sprites[i].sprite, tree_sprites[i].pal, x, y);
00085 x += 35;
00086 if (!(++i & 3)) {
00087 x -= 35 * 4;
00088 y += 47;
00089 }
00090 } while (--count);
00091 }
00092
00093 virtual void OnClick(Point pt, int widget)
00094 {
00095 switch (widget) {
00096 case BTW_TYPE_11: case BTW_TYPE_12: case BTW_TYPE_13: case BTW_TYPE_14:
00097 case BTW_TYPE_21: case BTW_TYPE_22: case BTW_TYPE_23: case BTW_TYPE_24:
00098 case BTW_TYPE_31: case BTW_TYPE_32: case BTW_TYPE_33: case BTW_TYPE_34:
00099 if (widget - BTW_TYPE_11 >= this->count) break;
00100
00101 if (HandlePlacePushButton(this, widget, SPR_CURSOR_TREE, VHM_RECT, NULL)) {
00102 this->tree_to_plant = this->base + widget - BTW_TYPE_11;
00103 }
00104 break;
00105
00106 case BTW_TYPE_RANDOM:
00107 if (HandlePlacePushButton(this, BTW_TYPE_RANDOM, SPR_CURSOR_TREE, VHM_RECT, NULL)) {
00108 this->tree_to_plant = UINT_MAX;
00109 }
00110 break;
00111
00112 case BTW_MANY_RANDOM:
00113 this->LowerWidget(BTW_MANY_RANDOM);
00114 this->flags4 |= WF_TIMEOUT_BEGIN;
00115 SndPlayFx(SND_15_BEEP);
00116 PlaceTreesRandomly();
00117 MarkWholeScreenDirty();
00118 break;
00119 }
00120 }
00121
00122 virtual void OnPlaceObject(Point pt, TileIndex tile)
00123 {
00124 VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED, DDSP_PLANT_TREES);
00125 VpSetPlaceSizingLimit(20);
00126 }
00127
00128 virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
00129 {
00130 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
00131 }
00132
00133 virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
00134 {
00135 if (pt.x != -1 && select_proc == DDSP_PLANT_TREES) {
00136 DoCommandP(end_tile, this->tree_to_plant, start_tile,
00137 CMD_PLANT_TREE | CMD_MSG(STR_2805_CAN_T_PLANT_TREE_HERE));
00138 }
00139 }
00140
00141 virtual void OnTimeout()
00142 {
00143 this->RaiseWidget(BTW_MANY_RANDOM);
00144 this->InvalidateWidget(BTW_MANY_RANDOM);
00145 }
00146
00147 virtual void OnPlaceObjectAbort()
00148 {
00149 this->RaiseButtons();
00150 }
00151 };
00152
00153 static const Widget _build_trees_widgets[] = {
00154 { WWT_CLOSEBOX, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
00155 { WWT_CAPTION, RESIZE_NONE, COLOUR_DARK_GREEN, 11, 142, 0, 13, STR_2802_TREES, STR_018C_WINDOW_TITLE_DRAG_THIS},
00156 { WWT_PANEL, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 142, 14, 183, 0x0, STR_NULL},
00157 { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 2, 35, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
00158 { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 37, 70, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
00159 { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 72, 105, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
00160 { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 107, 140, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
00161 { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 2, 35, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
00162 { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 37, 70, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
00163 { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 72, 105, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
00164 { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 107, 140, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
00165 { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 2, 35, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
00166 { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 37, 70, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
00167 { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 72, 105, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
00168 { WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 107, 140, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
00169 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 140, 157, 168, STR_TREES_RANDOM_TYPE, STR_TREES_RANDOM_TYPE_TIP},
00170 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 140, 170, 181, STR_028A_RANDOM_TREES, STR_028B_PLANT_TREES_RANDOMLY_OVER},
00171 { WIDGETS_END},
00172 };
00173
00174 static const WindowDesc _build_trees_desc(
00175 WDP_AUTO, WDP_AUTO, 143, 184, 143, 184,
00176 WC_BUILD_TREES, WC_NONE,
00177 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_CONSTRUCTION,
00178 _build_trees_widgets
00179 );
00180
00181 void ShowBuildTreesToolbar()
00182 {
00183 if (_game_mode != GM_EDITOR && !IsValidCompanyID(_local_company)) return;
00184 AllocateWindowDescFront<BuildTreesWindow>(&_build_trees_desc, 0);
00185 }