author | rubidium |
Mon, 26 May 2008 13:52:59 +0000 | |
branch | noai |
changeset 10715 | 6bdf79ffb022 |
parent 10645 | 8cbdb511a674 |
child 10776 | 07203fc29812 |
permissions | -rw-r--r-- |
10513 | 1 |
/* $Id$ */ |
2 |
||
3 |
/** @file tree_gui.cpp GUIs for building trees. */ |
|
4 |
||
5 |
#include "stdafx.h" |
|
6 |
#include "openttd.h" |
|
7 |
#include "window_gui.h" |
|
8 |
#include "gfx_func.h" |
|
9 |
#include "tilehighlight_func.h" |
|
10 |
#include "player_func.h" |
|
11 |
#include "command_func.h" |
|
12 |
#include "sound_func.h" |
|
13 |
#include "settings_type.h" |
|
14 |
||
15 |
#include "table/sprites.h" |
|
16 |
#include "table/strings.h" |
|
17 |
#include "table/tree_land.h" |
|
18 |
||
19 |
void PlaceTreesRandomly(); |
|
20 |
||
10645 | 21 |
class BuildTreesWindow : public Window |
22 |
{ |
|
23 |
uint16 base; |
|
24 |
uint16 count; |
|
25 |
int tree_to_plant; |
|
26 |
||
27 |
enum BuildTreesWidgets { |
|
28 |
BTW_CLOSE, |
|
29 |
BTW_CAPTION, |
|
30 |
BTW_BACKGROUND, |
|
31 |
BTW_TYPE_11, |
|
32 |
BTW_TYPE_12, |
|
33 |
BTW_TYPE_13, |
|
34 |
BTW_TYPE_14, |
|
35 |
BTW_TYPE_21, |
|
36 |
BTW_TYPE_22, |
|
37 |
BTW_TYPE_23, |
|
38 |
BTW_TYPE_24, |
|
39 |
BTW_TYPE_31, |
|
40 |
BTW_TYPE_32, |
|
41 |
BTW_TYPE_33, |
|
42 |
BTW_TYPE_34, |
|
43 |
BTW_TYPE_RANDOM, |
|
44 |
BTW_MANY_RANDOM, |
|
45 |
}; |
|
46 |
||
47 |
public: |
|
48 |
BuildTreesWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) |
|
49 |
{ |
|
50 |
if (_game_mode != GM_EDITOR) { |
|
51 |
this->HideWidget(BTW_MANY_RANDOM); |
|
52 |
int offset = this->widget[BTW_MANY_RANDOM].bottom - this->widget[BTW_MANY_RANDOM].top; |
|
53 |
this->height -= offset; |
|
54 |
this->widget[BTW_BACKGROUND].bottom -= offset; |
|
55 |
} |
|
56 |
ResetObjectToPlace(); |
|
57 |
this->FindWindowPlacementAndResize(desc); |
|
58 |
} |
|
59 |
||
60 |
virtual void OnPaint() |
|
61 |
{ |
|
62 |
static const PalSpriteID tree_sprites[] = { |
|
63 |
{ 0x655, PAL_NONE }, { 0x663, PAL_NONE }, { 0x678, PAL_NONE }, { 0x62B, PAL_NONE }, |
|
64 |
{ 0x647, PAL_NONE }, { 0x639, PAL_NONE }, { 0x64E, PAL_NONE }, { 0x632, PAL_NONE }, |
|
65 |
{ 0x67F, PAL_NONE }, { 0x68D, PAL_NONE }, { 0x69B, PAL_NONE }, { 0x6A9, PAL_NONE }, |
|
66 |
{ 0x6AF, PAL_NONE }, { 0x6D2, PAL_NONE }, { 0x6D9, PAL_NONE }, { 0x6C4, PAL_NONE }, |
|
67 |
{ 0x6CB, PAL_NONE }, { 0x6B6, PAL_NONE }, { 0x6BD, PAL_NONE }, { 0x6E0, PAL_NONE }, |
|
68 |
{ 0x72E, PAL_NONE }, { 0x734, PAL_NONE }, { 0x74A, PAL_NONE }, { 0x74F, PAL_NONE }, |
|
69 |
{ 0x76B, PAL_NONE }, { 0x78F, PAL_NONE }, { 0x788, PAL_NONE }, { 0x77B, PAL_NONE }, |
|
70 |
{ 0x75F, PAL_NONE }, { 0x774, PAL_NONE }, { 0x720, PAL_NONE }, { 0x797, PAL_NONE }, |
|
71 |
{ 0x79E, PAL_NONE }, { 0x7A5, PALETTE_TO_GREEN }, { 0x7AC, PALETTE_TO_RED }, { 0x7B3, PAL_NONE }, |
|
72 |
{ 0x7BA, PAL_NONE }, { 0x7C1, PALETTE_TO_RED, }, { 0x7C8, PALETTE_TO_PALE_GREEN }, { 0x7CF, PALETTE_TO_YELLOW }, { 0x7D6, PALETTE_TO_RED } |
|
73 |
}; |
|
74 |
||
75 |
this->DrawWidgets(); |
|
76 |
||
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
77 |
int i = this->base = _tree_base_by_landscape[_settings.game_creation.landscape]; |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
78 |
int count = this->count = _tree_count_by_landscape[_settings.game_creation.landscape]; |
10645 | 79 |
|
80 |
int x = 18; |
|
81 |
int y = 54; |
|
82 |
do { |
|
83 |
DrawSprite(tree_sprites[i].sprite, tree_sprites[i].pal, x, y); |
|
84 |
x += 35; |
|
85 |
if (!(++i & 3)) { |
|
86 |
x -= 35 * 4; |
|
87 |
y += 47; |
|
88 |
} |
|
89 |
} while (--count); |
|
90 |
} |
|
91 |
||
92 |
virtual void OnClick(Point pt, int widget) |
|
93 |
{ |
|
94 |
switch (widget) { |
|
95 |
case BTW_TYPE_11: case BTW_TYPE_12: case BTW_TYPE_13: case BTW_TYPE_14: |
|
96 |
case BTW_TYPE_21: case BTW_TYPE_22: case BTW_TYPE_23: case BTW_TYPE_24: |
|
97 |
case BTW_TYPE_31: case BTW_TYPE_32: case BTW_TYPE_33: case BTW_TYPE_34: |
|
98 |
if (widget - BTW_TYPE_11 >= this->count) break; |
|
99 |
||
100 |
if (HandlePlacePushButton(this, widget, SPR_CURSOR_TREE, VHM_RECT, NULL)) { |
|
101 |
this->tree_to_plant = this->base + widget - BTW_TYPE_11; |
|
102 |
} |
|
103 |
break; |
|
104 |
||
105 |
case BTW_TYPE_RANDOM: // tree of random type. |
|
106 |
if (HandlePlacePushButton(this, BTW_TYPE_RANDOM, SPR_CURSOR_TREE, VHM_RECT, NULL)) { |
|
107 |
this->tree_to_plant = -1; |
|
108 |
} |
|
109 |
break; |
|
110 |
||
111 |
case BTW_MANY_RANDOM: // place trees randomly over the landscape |
|
112 |
this->LowerWidget(BTW_MANY_RANDOM); |
|
113 |
this->flags4 |= 5 << WF_TIMEOUT_SHL; |
|
114 |
SndPlayFx(SND_15_BEEP); |
|
115 |
PlaceTreesRandomly(); |
|
116 |
MarkWholeScreenDirty(); |
|
117 |
break; |
|
118 |
} |
|
119 |
} |
|
120 |
||
121 |
virtual void OnPlaceObject(Point pt, TileIndex tile) |
|
122 |
{ |
|
123 |
VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED, DDSP_PLANT_TREES); |
|
124 |
VpSetPlaceSizingLimit(20); |
|
125 |
} |
|
126 |
||
127 |
virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) |
|
128 |
{ |
|
129 |
VpSelectTilesWithMethod(pt.x, pt.y, select_method); |
|
130 |
} |
|
131 |
||
132 |
virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) |
|
133 |
{ |
|
134 |
if (pt.x != -1 && select_proc == DDSP_PLANT_TREES) { |
|
135 |
DoCommandP(end_tile, this->tree_to_plant, start_tile, NULL, |
|
136 |
CMD_PLANT_TREE | CMD_MSG(STR_2805_CAN_T_PLANT_TREE_HERE)); |
|
137 |
} |
|
138 |
} |
|
139 |
||
140 |
virtual void OnTimeout() |
|
141 |
{ |
|
142 |
this->RaiseWidget(BTW_MANY_RANDOM); |
|
143 |
this->InvalidateWidget(BTW_MANY_RANDOM); |
|
144 |
} |
|
145 |
||
146 |
virtual void OnPlaceObjectAbort() |
|
147 |
{ |
|
148 |
this->RaiseButtons(); |
|
149 |
} |
|
10513 | 150 |
}; |
151 |
||
152 |
static const Widget _build_trees_widgets[] = { |
|
10645 | 153 |
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // BTW_CLOSE |
154 |
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 142, 0, 13, STR_2802_TREES, STR_018C_WINDOW_TITLE_DRAG_THIS}, // BTW_CAPTION |
|
155 |
{ WWT_PANEL, RESIZE_NONE, 7, 0, 142, 14, 183, 0x0, STR_NULL}, // BTW_BACKGROUND |
|
156 |
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_11 |
|
157 |
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_12 |
|
158 |
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_13 |
|
159 |
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_14 |
|
160 |
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_21 |
|
161 |
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_22 |
|
162 |
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_23 |
|
163 |
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_24 |
|
164 |
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_31 |
|
165 |
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_32 |
|
166 |
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_33 |
|
167 |
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_34 |
|
168 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 140, 157, 168, STR_TREES_RANDOM_TYPE, STR_TREES_RANDOM_TYPE_TIP}, // BTW_TYPE_RANDOM |
|
169 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 140, 170, 181, STR_028A_RANDOM_TREES, STR_028B_PLANT_TREES_RANDOMLY_OVER}, // BTW_MANY_RANDOM |
|
10513 | 170 |
{ WIDGETS_END}, |
171 |
}; |
|
172 |
||
173 |
static const WindowDesc _build_trees_desc = { |
|
174 |
WDP_AUTO, WDP_AUTO, 143, 184, 143, 184, |
|
175 |
WC_BUILD_TREES, WC_NONE, |
|
176 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
10645 | 177 |
_build_trees_widgets, |
10513 | 178 |
}; |
179 |
||
180 |
void ShowBuildTreesToolbar() |
|
181 |
{ |
|
10645 | 182 |
if (_game_mode != GM_EDITOR && !IsValidPlayer(_current_player)) return; |
183 |
AllocateWindowDescFront<BuildTreesWindow>(&_build_trees_desc, 0); |
|
10513 | 184 |
} |