author | darkvater |
Mon, 16 Aug 2004 14:48:35 +0000 | |
changeset 65 | f9f866bc609c |
parent 0 | 29654efe3188 |
child 69 | f8c29cdb388e |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
3 |
//#include "gui.h" |
|
4 |
#include "window.h" |
|
5 |
#include "gfx.h" |
|
6 |
#include "command.h" |
|
7 |
#include "viewport.h" |
|
8 |
#include "industry.h" |
|
9 |
#include "town.h" |
|
10 |
||
11 |
static const byte _build_industry_types[4][12] = { |
|
12 |
{ 1, 2, 4, 6, 8, 0, 3, 5, 9, 11, 18 }, |
|
13 |
{ 1, 14, 4, 13, 7, 0, 3, 9, 11, 15 }, |
|
14 |
{ 25, 13, 4, 23, 22, 11, 17, 10, 24, 19, 20, 21 }, |
|
15 |
{ 27, 30, 31, 33, 26, 28, 29, 32, 34, 35, 36 }, |
|
16 |
}; |
|
17 |
||
18 |
extern const byte _industry_type_costs[37]; |
|
19 |
||
20 |
static void BuildIndustryWndProc(Window *w, WindowEvent *e) |
|
21 |
{ |
|
22 |
switch(e->event) { |
|
23 |
case WE_PAINT: |
|
24 |
DrawWindowWidgets(w); |
|
25 |
if (_thd.place_mode == 1 && _thd.window_class == WC_BUILD_INDUSTRY) { |
|
26 |
int ind_type = _build_industry_types[_opt.landscape][WP(w,def_d).data_1]; |
|
27 |
||
28 |
SET_DPARAM32(0, (_price.build_industry >> 5) * _industry_type_costs[ind_type]); |
|
29 |
DrawStringCentered(85, w->height - 21, STR_482F_COST, 0); |
|
30 |
} |
|
31 |
break; |
|
32 |
||
33 |
case WE_CLICK: { |
|
34 |
int wid = e->click.widget; |
|
35 |
if (wid >= 3) { |
|
36 |
if (HandlePlacePushButton(w, wid, 0xFF1, 1, NULL)) |
|
37 |
WP(w,def_d).data_1 = wid - 3; |
|
38 |
} |
|
39 |
} break; |
|
40 |
||
41 |
case WE_PLACE_OBJ: |
|
42 |
if (DoCommandP(e->place.tile, _build_industry_types[_opt.landscape][WP(w,def_d).data_1], 0, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY))) |
|
43 |
ResetObjectToPlace(); |
|
44 |
break; |
|
45 |
||
46 |
case WE_ABORT_PLACE_OBJ: |
|
47 |
w->click_state = 0; |
|
48 |
SetWindowDirty(w); |
|
49 |
break; |
|
50 |
} |
|
51 |
} |
|
52 |
||
53 |
static const Widget _build_industry_land0_widgets[] = { |
|
54 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, |
|
55 |
{ WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY,STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
56 |
{ WWT_PANEL, 7, 0, 169, 14, 115, 0x0,0}, |
|
57 |
{ WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0241_POWER_STATION,STR_0263_CONSTRUCT_POWER_STATION}, |
|
58 |
{ WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_0242_SAWMILL,STR_0264_CONSTRUCT_SAWMILL}, |
|
59 |
{ WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY,STR_0266_CONSTRUCT_OIL_REFINERY}, |
|
60 |
{ WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_0246_FACTORY,STR_0268_CONSTRUCT_FACTORY}, |
|
61 |
{ WWT_CLOSEBOX, 14, 2, 167, 68, 79, STR_0247_STEEL_MILL,STR_0269_CONSTRUCT_STEEL_MILL}, |
|
62 |
{ WWT_LAST}, |
|
63 |
}; |
|
64 |
||
65 |
static const Widget _build_industry_land1_widgets[] = { |
|
66 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, |
|
67 |
{ WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY,STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
68 |
{ WWT_PANEL, 7, 0, 169, 14, 115, 0x0,0}, |
|
69 |
{ WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0241_POWER_STATION,STR_0263_CONSTRUCT_POWER_STATION}, |
|
70 |
{ WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_024C_PAPER_MILL, STR_026E_CONSTRUCT_PAPER_MILL}, |
|
71 |
{ WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY,STR_0266_CONSTRUCT_OIL_REFINERY}, |
|
72 |
{ WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING}, |
|
73 |
{ WWT_CLOSEBOX, 14, 2, 167, 68, 79, STR_024E_PRINTING_WORKS,STR_0270_CONSTRUCT_PRINTING_WORKS}, |
|
74 |
{ WWT_LAST}, |
|
75 |
}; |
|
76 |
||
77 |
static const Widget _build_industry_land2_widgets[] = { |
|
78 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, |
|
79 |
{ WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY,STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
80 |
{ WWT_PANEL, 7, 0, 169, 14, 115, 0x0,0}, |
|
81 |
{ WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0250_LUMBER_MILL,STR_0273_CONSTRUCT_LUMBER_MILL_TO}, |
|
82 |
{ WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING}, |
|
83 |
{ WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY,STR_0266_CONSTRUCT_OIL_REFINERY}, |
|
84 |
{ WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_0246_FACTORY,STR_0268_CONSTRUCT_FACTORY}, |
|
85 |
{ WWT_CLOSEBOX, 14, 2, 167, 68, 79, STR_0254_WATER_TOWER,STR_0277_CONSTRUCT_WATER_TOWER_CAN}, |
|
86 |
{ WWT_LAST}, |
|
87 |
}; |
|
88 |
||
89 |
static const Widget _build_industry_land3_widgets[] = { |
|
90 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, |
|
91 |
{ WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY,STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
92 |
{ WWT_PANEL, 7, 0, 169, 14, 115, 0x0,0}, |
|
93 |
{ WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0258_CANDY_FACTORY,STR_027B_CONSTRUCT_CANDY_FACTORY}, |
|
94 |
{ WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_025B_TOY_SHOP,STR_027E_CONSTRUCT_TOY_SHOP}, |
|
95 |
{ WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_025C_TOY_FACTORY,STR_027F_CONSTRUCT_TOY_FACTORY}, |
|
96 |
{ WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_025E_FIZZY_DRINK_FACTORY,STR_0281_CONSTRUCT_FIZZY_DRINK_FACTORY}, |
|
97 |
{ WWT_LAST}, |
|
98 |
}; |
|
99 |
||
100 |
static const Widget _build_industry_land0_widgets_extra[] = { |
|
101 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, |
|
102 |
{ WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY,STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
103 |
{ WWT_PANEL, 7, 0, 169, 14, 187, 0x0,0}, |
|
104 |
||
105 |
{ WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0241_POWER_STATION,STR_0263_CONSTRUCT_POWER_STATION}, |
|
106 |
{ WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_0242_SAWMILL,STR_0264_CONSTRUCT_SAWMILL}, |
|
107 |
{ WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY,STR_0266_CONSTRUCT_OIL_REFINERY}, |
|
108 |
{ WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_0246_FACTORY,STR_0268_CONSTRUCT_FACTORY}, |
|
109 |
{ WWT_CLOSEBOX, 14, 2, 167, 68, 79, STR_0247_STEEL_MILL,STR_0269_CONSTRUCT_STEEL_MILL}, |
|
110 |
||
111 |
{ WWT_CLOSEBOX, 14, 2, 167, 84, 95, STR_0240_COAL_MINE, STR_CONSTRUCT_COAL_MINE_TIP}, |
|
112 |
{ WWT_CLOSEBOX, 14, 2, 167, 97, 108, STR_0243_FOREST, STR_CONSTRUCT_FOREST_TIP}, |
|
113 |
{ WWT_CLOSEBOX, 14, 2, 167, 110, 121, STR_0245_OIL_RIG, STR_CONSTRUCT_OIL_RIG_TIP}, |
|
114 |
{ WWT_CLOSEBOX, 14, 2, 167, 123, 134, STR_0248_FARM, STR_CONSTRUCT_FARM_TIP}, |
|
115 |
{ WWT_CLOSEBOX, 14, 2, 167, 136, 147, STR_024A_OIL_WELLS, STR_CONSTRUCT_OIL_WELLS_TIP}, |
|
116 |
{ WWT_CLOSEBOX, 14, 2, 167, 149, 160, STR_0249_IRON_ORE_MINE, STR_CONSTRUCT_IRON_ORE_MINE_TIP}, |
|
117 |
||
118 |
{ WWT_LAST}, |
|
119 |
}; |
|
120 |
||
121 |
static const Widget _build_industry_land1_widgets_extra[] = { |
|
122 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, |
|
123 |
{ WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY,STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
124 |
{ WWT_PANEL, 7, 0, 169, 14, 174, 0x0,0}, |
|
125 |
||
126 |
{ WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0241_POWER_STATION,STR_0263_CONSTRUCT_POWER_STATION}, |
|
127 |
{ WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_024C_PAPER_MILL, STR_026E_CONSTRUCT_PAPER_MILL}, |
|
128 |
{ WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY,STR_0266_CONSTRUCT_OIL_REFINERY}, |
|
129 |
{ WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING}, |
|
130 |
{ WWT_CLOSEBOX, 14, 2, 167, 68, 79, STR_024E_PRINTING_WORKS,STR_0270_CONSTRUCT_PRINTING_WORKS}, |
|
131 |
||
132 |
{ WWT_CLOSEBOX, 14, 2, 167, 81+3, 92+3, STR_0240_COAL_MINE,STR_CONSTRUCT_COAL_MINE_TIP}, |
|
133 |
{ WWT_CLOSEBOX, 14, 2, 167, 94+3, 105+3, STR_0243_FOREST,STR_CONSTRUCT_FOREST_TIP}, |
|
134 |
{ WWT_CLOSEBOX, 14, 2, 167, 107+3, 118+3, STR_0248_FARM,STR_CONSTRUCT_FARM_TIP}, |
|
135 |
{ WWT_CLOSEBOX, 14, 2, 167, 120+3, 131+3, STR_024A_OIL_WELLS,STR_CONSTRUCT_OIL_WELLS_TIP}, |
|
136 |
{ WWT_CLOSEBOX, 14, 2, 167, 133+3, 144+3, STR_024F_GOLD_MINE,STR_CONSTRUCT_GOLD_MINE_TIP}, |
|
137 |
{ WWT_LAST}, |
|
138 |
}; |
|
139 |
||
140 |
static const Widget _build_industry_land2_widgets_extra[] = { |
|
141 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, |
|
142 |
{ WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY,STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
143 |
{ WWT_PANEL, 7, 0, 169, 14, 200, 0x0,0}, |
|
144 |
||
145 |
{ WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0250_LUMBER_MILL,STR_0273_CONSTRUCT_LUMBER_MILL_TO}, |
|
146 |
{ WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING}, |
|
147 |
{ WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY,STR_0266_CONSTRUCT_OIL_REFINERY}, |
|
148 |
{ WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_0246_FACTORY,STR_0268_CONSTRUCT_FACTORY}, |
|
149 |
{ WWT_CLOSEBOX, 14, 2, 167, 68, 79, STR_0254_WATER_TOWER,STR_0277_CONSTRUCT_WATER_TOWER_CAN}, |
|
150 |
||
151 |
{ WWT_CLOSEBOX, 14, 2, 167, 81+3, 92+3, STR_024A_OIL_WELLS,STR_CONSTRUCT_OIL_WELLS_TIP}, |
|
152 |
{ WWT_CLOSEBOX, 14, 2, 167, 94+3, 105+3, STR_0255_DIAMOND_MINE,STR_CONSTRUCT_DIAMOND_MINE_TIP}, |
|
153 |
{ WWT_CLOSEBOX, 14, 2, 167, 107+3, 118+3, STR_0256_COPPER_ORE_MINE,STR_CONSTRUCT_COPPER_ORE_MINE_TIP}, |
|
154 |
{ WWT_CLOSEBOX, 14, 2, 167, 120+3, 131+3, STR_0248_FARM,STR_CONSTRUCT_FARM_TIP}, |
|
155 |
{ WWT_CLOSEBOX, 14, 2, 167, 133+3, 144+3, STR_0251_FRUIT_PLANTATION,STR_CONSTRUCT_FRUIT_PLANTATION_TIP}, |
|
156 |
{ WWT_CLOSEBOX, 14, 2, 167, 146+3, 157+3, STR_0252_RUBBER_PLANTATION,STR_CONSTRUCT_RUBBER_PLANTATION_TIP}, |
|
157 |
{ WWT_CLOSEBOX, 14, 2, 167, 159+3, 170+3, STR_0253_WATER_SUPPLY,STR_CONSTRUCT_WATER_SUPPLY_TIP}, |
|
158 |
{ WWT_LAST}, |
|
159 |
}; |
|
160 |
||
161 |
static const Widget _build_industry_land3_widgets_extra[] = { |
|
162 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, |
|
163 |
{ WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY,STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
164 |
{ WWT_PANEL, 7, 0, 169, 14, 187, 0x0,0}, |
|
165 |
||
166 |
{ WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0258_CANDY_FACTORY,STR_027B_CONSTRUCT_CANDY_FACTORY}, |
|
167 |
{ WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_025B_TOY_SHOP,STR_027E_CONSTRUCT_TOY_SHOP}, |
|
168 |
{ WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_025C_TOY_FACTORY,STR_027F_CONSTRUCT_TOY_FACTORY}, |
|
169 |
{ WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_025E_FIZZY_DRINK_FACTORY,STR_0281_CONSTRUCT_FIZZY_DRINK_FACTORY}, |
|
170 |
||
171 |
{ WWT_CLOSEBOX, 14, 2, 167, 68+3, 79+3, STR_0257_COTTON_CANDY_FOREST,STR_CONSTRUCT_COTTON_CANDY_TIP}, |
|
172 |
{ WWT_CLOSEBOX, 14, 2, 167, 81+3, 92+3, STR_0259_BATTERY_FARM,STR_CONSTRUCT_BATTERY_FARM_TIP}, |
|
173 |
{ WWT_CLOSEBOX, 14, 2, 167, 94+3, 105+3, STR_025A_COLA_WELLS,STR_CONSTRUCT_COLA_WELLS_TIP}, |
|
174 |
{ WWT_CLOSEBOX, 14, 2, 167, 107+3, 118+3, STR_025D_PLASTIC_FOUNTAINS,STR_CONSTRUCT_PLASTIC_FOUNTAINS_TIP}, |
|
175 |
{ WWT_CLOSEBOX, 14, 2, 167, 120+3, 131+3, STR_025F_BUBBLE_GENERATOR,STR_CONSTRUCT_BUBBLE_GENERATOR_TIP}, |
|
176 |
{ WWT_CLOSEBOX, 14, 2, 167, 133+3, 144+3, STR_0260_TOFFEE_QUARRY,STR_CONSTRUCT_TOFFEE_QUARRY_TIP}, |
|
177 |
{ WWT_CLOSEBOX, 14, 2, 167, 146+3, 157+3, STR_0261_SUGAR_MINE,STR_CONSTRUCT_SUGAR_MINE_TIP}, |
|
178 |
{ WWT_LAST}, |
|
179 |
}; |
|
180 |
||
181 |
||
182 |
static const WindowDesc _build_industry_land0_desc = { |
|
183 |
-1, -1, 170, 116, |
|
184 |
WC_BUILD_INDUSTRY,0, |
|
185 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
186 |
_build_industry_land0_widgets, |
|
187 |
BuildIndustryWndProc |
|
188 |
}; |
|
189 |
||
190 |
static const WindowDesc _build_industry_land1_desc = { |
|
191 |
-1, -1, 170, 116, |
|
192 |
WC_BUILD_INDUSTRY,0, |
|
193 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
194 |
_build_industry_land1_widgets, |
|
195 |
BuildIndustryWndProc |
|
196 |
}; |
|
197 |
||
198 |
static const WindowDesc _build_industry_land2_desc = { |
|
199 |
-1, -1, 170, 116, |
|
200 |
WC_BUILD_INDUSTRY,0, |
|
201 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
202 |
_build_industry_land2_widgets, |
|
203 |
BuildIndustryWndProc |
|
204 |
}; |
|
205 |
||
206 |
static const WindowDesc _build_industry_land3_desc = { |
|
207 |
-1, -1, 170, 116, |
|
208 |
WC_BUILD_INDUSTRY,0, |
|
209 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
210 |
_build_industry_land3_widgets, |
|
211 |
BuildIndustryWndProc |
|
212 |
}; |
|
213 |
||
214 |
static const WindowDesc _build_industry_land0_desc_extra = { |
|
215 |
-1, -1, 170, 188, |
|
216 |
WC_BUILD_INDUSTRY,0, |
|
217 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
218 |
_build_industry_land0_widgets_extra, |
|
219 |
BuildIndustryWndProc |
|
220 |
}; |
|
221 |
||
222 |
static const WindowDesc _build_industry_land1_desc_extra = { |
|
223 |
-1, -1, 170, 175, |
|
224 |
WC_BUILD_INDUSTRY,0, |
|
225 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
226 |
_build_industry_land1_widgets_extra, |
|
227 |
BuildIndustryWndProc |
|
228 |
}; |
|
229 |
||
230 |
static const WindowDesc _build_industry_land2_desc_extra = { |
|
231 |
-1, -1, 170, 201, |
|
232 |
WC_BUILD_INDUSTRY,0, |
|
233 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
234 |
_build_industry_land2_widgets_extra, |
|
235 |
BuildIndustryWndProc |
|
236 |
}; |
|
237 |
||
238 |
static const WindowDesc _build_industry_land3_desc_extra = { |
|
239 |
-1, -1, 170, 188, |
|
240 |
WC_BUILD_INDUSTRY,0, |
|
241 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
242 |
_build_industry_land3_widgets_extra, |
|
243 |
BuildIndustryWndProc |
|
244 |
}; |
|
245 |
||
246 |
static const WindowDesc * const _industry_window_desc[2][4] = { |
|
247 |
{ |
|
248 |
&_build_industry_land0_desc, |
|
249 |
&_build_industry_land1_desc, |
|
250 |
&_build_industry_land2_desc, |
|
251 |
&_build_industry_land3_desc, |
|
252 |
}, |
|
253 |
{ |
|
254 |
&_build_industry_land0_desc_extra, |
|
255 |
&_build_industry_land1_desc_extra, |
|
256 |
&_build_industry_land2_desc_extra, |
|
257 |
&_build_industry_land3_desc_extra, |
|
258 |
}, |
|
259 |
}; |
|
260 |
||
261 |
void ShowBuildIndustryWindow() |
|
262 |
{ |
|
263 |
AllocateWindowDescFront(_industry_window_desc[_patches.build_rawmaterial_ind][_opt.landscape],0); |
|
264 |
} |
|
265 |
||
266 |
static void IndustryViewWndProc(Window *w, WindowEvent *e) |
|
267 |
{ |
|
268 |
Industry *i; |
|
269 |
StringID str; |
|
270 |
||
271 |
switch(e->event) { |
|
272 |
case WE_PAINT: |
|
273 |
// in editor, use bulldoze to destroy industry |
|
274 |
// Destroy Industry button costing money removed per request of dominik |
|
275 |
//w->disabled_state = (_patches.extra_dynamite && !_networking && _game_mode != GM_EDITOR) ? 0 : (1 << 6); |
|
276 |
i = DEREF_INDUSTRY(w->window_number); |
|
277 |
SET_DPARAM16(0, i->town->index); |
|
278 |
SET_DPARAM16(1, i->type + STR_4802_COAL_MINE); |
|
279 |
DrawWindowWidgets(w); |
|
280 |
||
281 |
if (i->accepts_cargo[0] != 0xFF) { |
|
282 |
SET_DPARAM16(0, _cargoc.names_s[i->accepts_cargo[0]]); |
|
283 |
str = STR_4827_REQUIRES; |
|
284 |
if (i->accepts_cargo[1] != 0xFF) { |
|
285 |
SET_DPARAM16(1, _cargoc.names_s[i->accepts_cargo[1]]); |
|
286 |
str++; |
|
287 |
if (i->accepts_cargo[2] != 0xFF) { |
|
288 |
SET_DPARAM16(2, _cargoc.names_s[i->accepts_cargo[2]]); |
|
289 |
str++; |
|
290 |
} |
|
291 |
} |
|
292 |
DrawString(2, 107, str, 0); |
|
293 |
} |
|
294 |
||
295 |
if (i->produced_cargo[0] != 0xFF) { |
|
296 |
DrawString(2, 117, STR_482A_PRODUCTION_LAST_MONTH, 0); |
|
297 |
||
298 |
SET_DPARAM16(1, i->total_production[0]); |
|
299 |
SET_DPARAM16(0, _cargoc.names_long_s[i->produced_cargo[0]] + ((i->total_production[0]!=1)<<5)); |
|
300 |
SET_DPARAM16(2, i->pct_transported[0] * 100 >> 8); |
|
301 |
DrawString(4, 127, STR_482B_TRANSPORTED, 0); |
|
302 |
||
303 |
if (i->produced_cargo[1] != 0xFF) { |
|
304 |
SET_DPARAM16(1, i->total_production[1]); |
|
305 |
SET_DPARAM16(0, _cargoc.names_long_s[i->produced_cargo[1]] + ((i->total_production[1]!=1)<<5)); |
|
306 |
SET_DPARAM16(2, i->pct_transported[1] * 100 >> 8); |
|
307 |
DrawString(4, 137, STR_482B_TRANSPORTED, 0); |
|
308 |
} |
|
309 |
} |
|
310 |
||
311 |
DrawWindowViewport(w); |
|
312 |
break; |
|
313 |
||
314 |
case WE_CLICK: |
|
315 |
switch(e->click.widget) { |
|
316 |
case 5: |
|
317 |
i = DEREF_INDUSTRY(w->window_number); |
|
318 |
ScrollMainWindowToTile(i->xy + TILE_XY(1,1)); |
|
319 |
break; |
|
320 |
case 6: |
|
321 |
// Destroy Industry button costing money removed per request of dominik |
|
322 |
//i = DEREF_INDUSTRY(w->window_number); |
|
323 |
/* passing only i->xy is not safe if industry has a weird shape like: |
|
324 |
_ X X |
|
325 |
X X X |
|
326 |
_ <--- grass, no industry, but i->xy points there (first top-left tile)!, |
|
327 |
so passing i->xy to destroy industry will fail in called procedure |
|
328 |
*/ |
|
329 |
//DoCommandP(i->xy, w->window_number, 0, CcPlaySound10, CMD_DESTROY_INDUSTRY | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA)); |
|
330 |
break; |
|
331 |
} |
|
332 |
break; |
|
333 |
} |
|
334 |
} |
|
335 |
||
336 |
static const Widget _industry_view_widgets[] = { |
|
337 |
{ WWT_TEXTBTN, 9, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
338 |
{ WWT_CAPTION, 9, 11, 259, 0, 13, STR_4801, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
339 |
{ WWT_IMGBTN, 9, 0, 259, 14, 105, 0x0}, |
|
340 |
{ WWT_6, 9, 2, 257, 16, 103, 0x0}, |
|
341 |
{ WWT_IMGBTN, 9, 0, 259, 106, 147, 0x0}, |
|
342 |
{ WWT_PUSHTXTBTN, 9, 0, 129, 148, 159, STR_00E4_LOCATION, STR_482C_CENTER_THE_MAIN_VIEW_ON}, |
|
343 |
{ WWT_IMGBTN, 9, 130, 259, 148, 159, 0x0, 0}, |
|
344 |
// Destroy Industry button costing money removed per request of dominik |
|
345 |
//{ WWT_PUSHTXTBTN, 9, 130, 259, 148, 159, STR_INDUSTRYDIR_DESTROY, STR_482C_DESTROY_INDUSTRY}, |
|
346 |
{ WWT_LAST}, |
|
347 |
}; |
|
348 |
||
349 |
static const WindowDesc _industry_view_desc = { |
|
350 |
-1, -1, 260, 160, |
|
351 |
WC_INDUSTRY_VIEW,0, |
|
352 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
353 |
_industry_view_widgets, |
|
354 |
IndustryViewWndProc |
|
355 |
}; |
|
356 |
||
357 |
void ShowIndustryViewWindow(int industry) |
|
358 |
{ |
|
359 |
Window *w; |
|
360 |
Industry *i; |
|
361 |
||
362 |
w = AllocateWindowDescFront(&_industry_view_desc, industry); |
|
363 |
if (w) { |
|
364 |
w->flags4 |= WF_DISABLE_VP_SCROLL; |
|
365 |
i = DEREF_INDUSTRY(w->window_number); |
|
366 |
AssignWindowViewport(w, 3, 17, 0xFE, 0x56, i->xy + TILE_XY(1,1), 1); |
|
367 |
} |
|
368 |
} |
|
369 |
||
370 |
static const Widget _industry_directory_widgets[] = { |
|
371 |
{ WWT_TEXTBTN, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
372 |
{ WWT_CAPTION, 13, 11, 507, 0, 13, STR_INDUSTRYDIR_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
373 |
{ WWT_PUSHTXTBTN, 13, 0, 100, 14, 25, STR_SORT_BY_NAME, STR_SORT_TIP}, |
|
374 |
{ WWT_PUSHTXTBTN, 13, 101, 200, 14, 25, STR_SORT_BY_TYPE, STR_SORT_TIP}, |
|
375 |
{ WWT_PUSHTXTBTN, 13, 201, 300, 14, 25, STR_SORT_BY_PRODUCTION, STR_SORT_TIP}, |
|
376 |
{ WWT_PUSHTXTBTN, 13, 301, 400, 14, 25, STR_SORT_BY_TRANSPORTED, STR_SORT_TIP}, |
|
377 |
{ WWT_PANEL, 13, 401, 496, 14, 25, 0x0, 0}, |
|
378 |
{ WWT_IMGBTN, 13, 0, 496, 26, 189, 0x0, STR_200A_TOWN_NAMES_CLICK_ON_NAME}, |
|
379 |
{ WWT_SCROLLBAR, 13, 497, 507, 14, 189, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
380 |
{ WWT_LAST}, |
|
381 |
}; |
|
382 |
||
383 |
static byte _industry_sort[lengthof(_industries)]; |
|
384 |
static uint _num_industry_sort; |
|
385 |
||
386 |
static char _bufcache[96]; |
|
387 |
static byte _last_industry_idx; |
|
388 |
||
389 |
static byte _industry_sort_order; |
|
390 |
||
391 |
static int CDECL IndustrySorter(const void *a, const void *b) |
|
392 |
{ |
|
393 |
char buf1[96]; |
|
394 |
Industry *i, *j; |
|
395 |
byte val; |
|
396 |
int r = 0; |
|
397 |
||
398 |
i = DEREF_INDUSTRY(*(byte*)a); |
|
399 |
j = DEREF_INDUSTRY(*(byte*)b); |
|
400 |
||
401 |
switch (_industry_sort_order >> 1) { |
|
402 |
case 0: |
|
403 |
r = 0; |
|
404 |
break; |
|
405 |
case 1: /* Case 1, sort by type */ |
|
406 |
r = i->type - j->type; |
|
407 |
break; |
|
408 |
case 2: /* Case 2, sort by production */ |
|
409 |
if (i->produced_cargo[0] != 0xFF && j->produced_cargo[0] != 0xFF) { //producing any cargo? |
|
410 |
if (i->produced_cargo[1] == 0xFF) //producing one or two things? |
|
411 |
r = j->total_production[0] - i->total_production[0]; |
|
412 |
else |
|
413 |
r = (j->total_production[0] + j->total_production[1]) / 2 - (i->total_production[0] + i->total_production[1]) / 2; |
|
414 |
} else if (i->produced_cargo[0] == 0xFF && j->produced_cargo[0] == 0xFF) //None of them producing anything, let them go to the name-sorting |
|
415 |
r = 0; |
|
416 |
else if (i->produced_cargo[0] == 0xFF) //Non-producers, end up last/first in list |
|
417 |
r = 1; |
|
418 |
else |
|
419 |
r = -1; |
|
420 |
break; |
|
421 |
case 3: /* Case 3, sort by transportation */ |
|
422 |
if (i->produced_cargo[0] != 0xFF && j->produced_cargo[0] != 0xFF) { //producing any cargo? |
|
423 |
if (i->produced_cargo[1] == 0xFF) //producing one or two things? |
|
424 |
r = (j->pct_transported[0] * 100 >> 8) - (i->pct_transported[0] * 100 >> 8); |
|
425 |
else |
|
426 |
r = ((j->pct_transported[0] * 100 >> 8) + (j->pct_transported[1] * 100 >> 8)) / 2 - ((i->pct_transported[0] * 100 >> 8) + (i->pct_transported[1] * 100 >> 8)) / 2; |
|
427 |
} else if (i->produced_cargo[0] == 0xFF && j->produced_cargo[0] == 0xFF) //None of them producing anything, let them go to the name-sorting |
|
428 |
r = 0; |
|
429 |
else if (i->produced_cargo[0] == 0xFF) //Non-producers, end up last/first in list |
|
430 |
r = 1; |
|
431 |
else |
|
432 |
r = -1; |
|
433 |
break; |
|
434 |
} |
|
435 |
||
436 |
// default to string sorting if they are otherwise equal |
|
437 |
if (r == 0) { |
|
438 |
SET_DPARAM32(0, i->town->townnameparts); |
|
439 |
GetString(buf1, i->town->townnametype); |
|
440 |
||
441 |
if ( (val=*(byte*)b) != _last_industry_idx) { |
|
442 |
_last_industry_idx = val; |
|
443 |
SET_DPARAM32(0, j->town->townnameparts); |
|
444 |
GetString(_bufcache, j->town->townnametype); |
|
445 |
} |
|
446 |
r = strcmp(buf1, _bufcache); |
|
447 |
} |
|
448 |
||
449 |
if (_industry_sort_order & 1) |
|
450 |
r = -r; |
|
451 |
||
452 |
return r; |
|
453 |
} |
|
454 |
||
455 |
static void MakeSortedIndustryList() |
|
456 |
{ |
|
457 |
Industry *i; |
|
458 |
int n = 0, index = 0; |
|
459 |
||
460 |
for(i=_industries; i != endof(_industries); i++) { |
|
461 |
if(i->xy) _industry_sort[n++] = index; |
|
462 |
index++; |
|
463 |
} |
|
464 |
_num_industry_sort = n; |
|
465 |
_last_industry_idx = 255; // used for "cache" |
|
466 |
||
467 |
qsort(_industry_sort, n, 1, IndustrySorter); |
|
65
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
0
diff
changeset
|
468 |
|
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
0
diff
changeset
|
469 |
//DEBUG(misc, 1) ("Resorting Industries list..."); |
0 | 470 |
} |
471 |
||
472 |
||
473 |
static void IndustryDirectoryWndProc(Window *w, WindowEvent *e) |
|
474 |
{ |
|
475 |
switch(e->event) { |
|
476 |
case WE_PAINT: { |
|
477 |
int n; |
|
478 |
uint p; |
|
479 |
Industry *i; |
|
480 |
static const uint16 _indicator_positions[4] = {88, 187, 284, 387}; |
|
481 |
||
482 |
if (_industry_sort_dirty) { |
|
483 |
_industry_sort_dirty = false; |
|
484 |
MakeSortedIndustryList(); |
|
485 |
} |
|
486 |
||
487 |
w->vscroll.count = _num_industry_sort; |
|
488 |
||
489 |
DrawWindowWidgets(w); |
|
490 |
DoDrawString(_industry_sort_order & 1 ? "\xAA" : "\xA0", _indicator_positions[_industry_sort_order>>1], 15, 0x10); |
|
491 |
||
492 |
p = w->vscroll.pos; |
|
493 |
n = 0; |
|
494 |
||
495 |
while (p < _num_industry_sort) { |
|
496 |
i = DEREF_INDUSTRY(_industry_sort[p]); |
|
497 |
SET_DPARAM16(0, i->town->index); |
|
498 |
SET_DPARAM16(1, i->type + STR_4802_COAL_MINE); |
|
499 |
if (i->produced_cargo[0] != 0xFF) { |
|
500 |
SET_DPARAM16(3, i->total_production[0] * 100 >> 8); |
|
501 |
SET_DPARAM16(2, _cargoc.names_long_s[i->produced_cargo[0]] + ((i->total_production[0]!=1)<<5)); |
|
502 |
||
503 |
if (i->produced_cargo[1] != 0xFF) { |
|
504 |
SET_DPARAM16(5, i->total_production[1] * 100 >> 8); |
|
505 |
SET_DPARAM16(4, _cargoc.names_long_s[i->produced_cargo[1]] + ((i->total_production[1]!=1)<<5)); |
|
506 |
SET_DPARAM16(6, i->pct_transported[0] * 100 >> 8); |
|
507 |
SET_DPARAM16(7, i->pct_transported[1] * 100 >> 8); |
|
508 |
DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM_TWO, 0); |
|
509 |
} else { |
|
510 |
SET_DPARAM16(4, i->pct_transported[0] * 100 >> 8); |
|
511 |
DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM, 0); |
|
512 |
} |
|
513 |
} else { |
|
514 |
DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM_NOPROD, 0); |
|
515 |
} |
|
516 |
p++; |
|
517 |
if (++n == 16) |
|
518 |
break; |
|
519 |
} |
|
520 |
} break; |
|
521 |
||
522 |
case WE_CLICK: |
|
523 |
switch(e->click.widget) { |
|
524 |
case 2: { |
|
525 |
_industry_sort_order = _industry_sort_order==0 ? 1 : 0; |
|
526 |
_industry_sort_dirty = true; |
|
527 |
SetWindowDirty(w); |
|
528 |
} break; |
|
529 |
||
530 |
case 3: { |
|
531 |
_industry_sort_order = _industry_sort_order==2 ? 3 : 2; |
|
532 |
_industry_sort_dirty = true; |
|
533 |
SetWindowDirty(w); |
|
534 |
} break; |
|
535 |
||
536 |
case 4: { |
|
537 |
_industry_sort_order = _industry_sort_order==4 ? 5 : 4; |
|
538 |
_industry_sort_dirty = true; |
|
539 |
SetWindowDirty(w); |
|
540 |
} break; |
|
541 |
||
542 |
case 5: { |
|
543 |
_industry_sort_order = _industry_sort_order==6 ? 7 : 6; |
|
544 |
_industry_sort_dirty = true; |
|
545 |
SetWindowDirty(w); |
|
546 |
} break; |
|
547 |
||
548 |
case 7: { |
|
549 |
int y = (e->click.pt.y - 28) / 10; |
|
550 |
byte p; |
|
551 |
Industry *c; |
|
552 |
||
553 |
if (!IS_INT_INSIDE(y, 0, 16)) |
|
554 |
return; |
|
555 |
p = y + w->vscroll.pos; |
|
556 |
if (p < _num_industry_sort) { |
|
557 |
c = DEREF_INDUSTRY(_industry_sort[p]); |
|
558 |
ScrollMainWindowToTile(c->xy); |
|
559 |
} |
|
560 |
} break; |
|
561 |
} |
|
562 |
break; |
|
563 |
||
564 |
case WE_4: |
|
565 |
SetWindowDirty(w); |
|
566 |
break; |
|
567 |
} |
|
568 |
} |
|
569 |
||
570 |
||
571 |
/* Industry List */ |
|
572 |
static const WindowDesc _industry_directory_desc = { |
|
573 |
-1, -1, 508, 190, |
|
574 |
WC_INDUSTRY_DIRECTORY,0, |
|
575 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
576 |
_industry_directory_widgets, |
|
577 |
IndustryDirectoryWndProc |
|
578 |
}; |
|
579 |
||
580 |
||
581 |
||
582 |
void ShowIndustryDirectory() |
|
583 |
{ |
|
584 |
/* Industry List */ |
|
585 |
Window *w; |
|
586 |
||
587 |
w = AllocateWindowDescFront(&_industry_directory_desc, 0); |
|
588 |
if (w) { |
|
589 |
w->vscroll.cap = 16; |
|
590 |
SetWindowDirty(w); |
|
591 |
} |
|
592 |
} |