16 { 25, 13, 4, 23, 22, 11, 17, 10, 24, 19, 20, 21 }, |
16 { 25, 13, 4, 23, 22, 11, 17, 10, 24, 19, 20, 21 }, |
17 { 27, 30, 31, 33, 26, 28, 29, 32, 34, 35, 36 }, |
17 { 27, 30, 31, 33, 26, 28, 29, 32, 34, 35, 36 }, |
18 }; |
18 }; |
19 |
19 |
20 extern const byte _industry_type_costs[37]; |
20 extern const byte _industry_type_costs[37]; |
|
21 |
|
22 static void UpdateIndustryProduction(Industry *i); |
|
23 extern void DrawArrowButtons(int x, int y, int state); |
|
24 extern void ShowQueryString(StringID str, StringID caption, int maxlen, int maxwidth, byte window_class, uint16 window_number); |
21 |
25 |
22 static void BuildIndustryWndProc(Window *w, WindowEvent *e) |
26 static void BuildIndustryWndProc(Window *w, WindowEvent *e) |
23 { |
27 { |
24 switch(e->event) { |
28 switch(e->event) { |
25 case WE_PAINT: |
29 case WE_PAINT: |
263 void ShowBuildIndustryWindow() |
267 void ShowBuildIndustryWindow() |
264 { |
268 { |
265 AllocateWindowDescFront(_industry_window_desc[_patches.build_rawmaterial_ind][_opt.landscape],0); |
269 AllocateWindowDescFront(_industry_window_desc[_patches.build_rawmaterial_ind][_opt.landscape],0); |
266 } |
270 } |
267 |
271 |
|
272 #define NEED_ALTERB (_game_mode == GM_EDITOR && i->accepts_cargo[0] == CT_INVALID) |
268 static void IndustryViewWndProc(Window *w, WindowEvent *e) |
273 static void IndustryViewWndProc(Window *w, WindowEvent *e) |
269 { |
274 { |
270 Industry *i; |
275 // WP(w,vp2_d).data_1 is for the editbox line |
271 StringID str; |
276 // WP(w,vp2_d).data_2 is for the clickline |
|
277 // WP(w,vp2_d).data_3 is for the click pos (left or right) |
272 |
278 |
273 switch(e->event) { |
279 switch(e->event) { |
274 case WE_PAINT: |
280 case WE_PAINT: { |
|
281 const Industry *i; |
|
282 StringID str; |
275 // in editor, use bulldoze to destroy industry |
283 // in editor, use bulldoze to destroy industry |
276 // Destroy Industry button costing money removed per request of dominik |
284 // Destroy Industry button costing money removed per request of dominik |
277 //w->disabled_state = (_patches.extra_dynamite && !_networking && _game_mode != GM_EDITOR) ? 0 : (1 << 6); |
285 //w->disabled_state = (_patches.extra_dynamite && !_networking && _game_mode != GM_EDITOR) ? 0 : (1 << 6); |
278 i = GetIndustry(w->window_number); |
286 i = GetIndustry(w->window_number); |
279 SetDParam(0, i->town->index); |
287 SetDParam(0, i->town->index); |
280 SetDParam(1, i->type + STR_4802_COAL_MINE); |
288 SetDParam(1, i->type + STR_4802_COAL_MINE); |
281 DrawWindowWidgets(w); |
289 DrawWindowWidgets(w); |
282 |
290 |
283 if (i->accepts_cargo[0] != 0xFF) { |
291 if (i->accepts_cargo[0] != CT_INVALID) { |
284 SetDParam(0, _cargoc.names_s[i->accepts_cargo[0]]); |
292 SetDParam(0, _cargoc.names_s[i->accepts_cargo[0]]); |
285 str = STR_4827_REQUIRES; |
293 str = STR_4827_REQUIRES; |
286 if (i->accepts_cargo[1] != 0xFF) { |
294 if (i->accepts_cargo[1] != CT_INVALID) { |
287 SetDParam(1, _cargoc.names_s[i->accepts_cargo[1]]); |
295 SetDParam(1, _cargoc.names_s[i->accepts_cargo[1]]); |
288 str++; |
296 str++; |
289 if (i->accepts_cargo[2] != 0xFF) { |
297 if (i->accepts_cargo[2] != CT_INVALID) { |
290 SetDParam(2, _cargoc.names_s[i->accepts_cargo[2]]); |
298 SetDParam(2, _cargoc.names_s[i->accepts_cargo[2]]); |
291 str++; |
299 str++; |
292 } |
300 } |
293 } |
301 } |
294 DrawString(2, 107, str, 0); |
302 DrawString(2, 107, str, 0); |
295 } |
303 } |
296 |
304 |
297 if (i->produced_cargo[0] != 0xFF) { |
305 if (i->produced_cargo[0] != CT_INVALID) { |
298 DrawString(2, 117, STR_482A_PRODUCTION_LAST_MONTH, 0); |
306 DrawString(2, 117, STR_482A_PRODUCTION_LAST_MONTH, 0); |
299 |
307 |
300 SetDParam(1, i->total_production[0]); |
308 SetDParam(1, i->total_production[0]); |
301 SetDParam(0, _cargoc.names_long_s[i->produced_cargo[0]] + ((i->total_production[0]!=1)<<5)); |
309 SetDParam(0, _cargoc.names_long_s[i->produced_cargo[0]] + ((i->total_production[0]!=1)<<5)); |
302 SetDParam(2, i->pct_transported[0] * 100 >> 8); |
310 SetDParam(2, i->pct_transported[0] * 100 >> 8); |
303 DrawString(4, 127, STR_482B_TRANSPORTED, 0); |
311 DrawString(4 + (NEED_ALTERB ? 30 : 0), 127, STR_482B_TRANSPORTED, 0); |
304 |
312 // Let's put out those buttons.. |
305 if (i->produced_cargo[1] != 0xFF) { |
313 if (NEED_ALTERB) |
|
314 DrawArrowButtons(5, 127, (WP(w,vp2_d).data_2 == 1 ? WP(w,vp2_d).data_3 : 0)); |
|
315 |
|
316 if (i->produced_cargo[1] != CT_INVALID) { |
306 SetDParam(1, i->total_production[1]); |
317 SetDParam(1, i->total_production[1]); |
307 SetDParam(0, _cargoc.names_long_s[i->produced_cargo[1]] + ((i->total_production[1]!=1)<<5)); |
318 SetDParam(0, _cargoc.names_long_s[i->produced_cargo[1]] + ((i->total_production[1]!=1)<<5)); |
308 SetDParam(2, i->pct_transported[1] * 100 >> 8); |
319 SetDParam(2, i->pct_transported[1] * 100 >> 8); |
309 DrawString(4, 137, STR_482B_TRANSPORTED, 0); |
320 DrawString(4 + (NEED_ALTERB ? 30 : 0), 137, STR_482B_TRANSPORTED, 0); |
|
321 // Let's put out those buttons.. |
|
322 if (NEED_ALTERB) |
|
323 DrawArrowButtons(5, 137, (WP(w,vp2_d).data_2 == 2 ? WP(w,vp2_d).data_3 : 0)); |
310 } |
324 } |
311 } |
325 } |
312 |
326 |
313 DrawWindowViewport(w); |
327 DrawWindowViewport(w); |
314 break; |
328 } |
315 |
329 break; |
316 case WE_CLICK: |
330 |
|
331 case WE_CLICK: { |
|
332 Industry *i; |
|
333 |
317 switch(e->click.widget) { |
334 switch(e->click.widget) { |
|
335 case 5: { |
|
336 int line; |
|
337 int x; |
|
338 byte b; |
|
339 |
|
340 i = GetIndustry(w->window_number); |
|
341 |
|
342 // We should only work in editor |
|
343 if (_game_mode != GM_EDITOR) |
|
344 return; |
|
345 |
|
346 // And if the industry is raw-material producer |
|
347 if (i->accepts_cargo[0] != CT_INVALID) |
|
348 return; |
|
349 |
|
350 x = e->click.pt.x; |
|
351 line = (e->click.pt.y - 127) / 10; |
|
352 if (e->click.pt.y >= 127 && IS_INT_INSIDE(line, 0, 2) && i->produced_cargo[line]) { |
|
353 if (IS_INT_INSIDE(x, 5, 25) ) { |
|
354 // clicked buttons |
|
355 if (x < 15) { |
|
356 // decrease |
|
357 i->production_rate[line] /= 2; |
|
358 if (i->production_rate[line] < 4) |
|
359 i->production_rate[line] = 4; |
|
360 } else { |
|
361 // increase |
|
362 b = i->production_rate[line] * 2; |
|
363 if (i->production_rate[line] >= 128) |
|
364 b=255; |
|
365 i->production_rate[line] = b; |
|
366 } |
|
367 UpdateIndustryProduction(i); |
|
368 SetWindowDirty(w); |
|
369 w->flags4 |= 5 << WF_TIMEOUT_SHL; |
|
370 WP(w,vp2_d).data_2 = line+1; |
|
371 WP(w,vp2_d).data_3 = (x < 15 ? 1 : 2); |
|
372 } else if (IS_INT_INSIDE(x, 34, 160)) { |
|
373 // clicked the text |
|
374 WP(w,vp2_d).data_1 = line; |
|
375 SetDParam(0, i->production_rate[line] * 8); |
|
376 ShowQueryString(STR_CONFIG_PATCHES_INT32, |
|
377 STR_CONFIG_GAME_PRODUCTION, |
|
378 10, 100, w->window_class, |
|
379 w->window_number); |
|
380 } |
|
381 } |
|
382 } |
|
383 break; |
318 case 6: |
384 case 6: |
319 i = GetIndustry(w->window_number); |
385 i = GetIndustry(w->window_number); |
320 ScrollMainWindowToTile(i->xy + TILE_XY(1,1)); |
386 ScrollMainWindowToTile(i->xy + TILE_XY(1,1)); |
321 break; |
387 break; |
322 case 7: |
388 case 7: |
329 so passing i->xy to destroy industry will fail in called procedure |
395 so passing i->xy to destroy industry will fail in called procedure |
330 */ |
396 */ |
331 //DoCommandP(i->xy, w->window_number, 0, CcPlaySound10, CMD_DESTROY_INDUSTRY | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA)); |
397 //DoCommandP(i->xy, w->window_number, 0, CcPlaySound10, CMD_DESTROY_INDUSTRY | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA)); |
332 break; |
398 break; |
333 } |
399 } |
334 break; |
400 } |
335 } |
401 break; |
|
402 case WE_TIMEOUT: |
|
403 WP(w,vp2_d).data_2 = 0; |
|
404 WP(w,vp2_d).data_3 = 0; |
|
405 SetWindowDirty(w); |
|
406 break; |
|
407 |
|
408 case WE_ON_EDIT_TEXT: |
|
409 if (*e->edittext.str) { |
|
410 Industry *i; |
|
411 int val; |
|
412 int line; |
|
413 |
|
414 i = GetIndustry(w->window_number); |
|
415 line = WP(w,vp2_d).data_1; |
|
416 val = atoi(e->edittext.str); |
|
417 if (!IS_INT_INSIDE(val, 32, 2040)) { |
|
418 if (val < 32) val = 32; |
|
419 else val = 2040; |
|
420 } |
|
421 i->production_rate[line] = (byte)(val / 8); |
|
422 UpdateIndustryProduction(i); |
|
423 SetWindowDirty(w); |
|
424 } |
|
425 } |
|
426 } |
|
427 |
|
428 static void UpdateIndustryProduction(Industry *i) |
|
429 { |
|
430 if (i->produced_cargo[0] != CT_INVALID) |
|
431 i->total_production[0] = 8 * i->production_rate[0]; |
|
432 |
|
433 if (i->produced_cargo[1] != CT_INVALID) |
|
434 i->total_production[1] = 8 * i->production_rate[1]; |
336 } |
435 } |
337 |
436 |
338 static const Widget _industry_view_widgets[] = { |
437 static const Widget _industry_view_widgets[] = { |
339 { WWT_TEXTBTN, RESIZE_NONE, 9, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
438 { WWT_TEXTBTN, RESIZE_NONE, 9, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
340 { WWT_CAPTION, RESIZE_NONE, 9, 11, 247, 0, 13, STR_4801, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
439 { WWT_CAPTION, RESIZE_NONE, 9, 11, 247, 0, 13, STR_4801, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
341 { WWT_STICKYBOX, RESIZE_NONE, 9, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON}, |
440 { WWT_STICKYBOX, RESIZE_NONE, 9, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON}, |
342 { WWT_IMGBTN, RESIZE_NONE, 9, 0, 259, 14, 105, 0x0, STR_NULL}, |
441 { WWT_IMGBTN, RESIZE_NONE, 9, 0, 259, 14, 105, 0x0, STR_NULL}, |
343 { WWT_6, RESIZE_NONE, 9, 2, 257, 16, 103, 0x0, STR_NULL}, |
442 { WWT_6, RESIZE_NONE, 9, 2, 257, 16, 103, 0x0, STR_NULL}, |
344 { WWT_IMGBTN, RESIZE_NONE, 9, 0, 259, 106, 147, 0x0, STR_NULL}, |
443 { WWT_IMGBTN, RESIZE_NONE, 9, 0, 259, 106, 147, 0x0, STR_NULL}, |
345 { WWT_PUSHTXTBTN, RESIZE_NONE, 9, 0, 129, 148, 159, STR_00E4_LOCATION, STR_482C_CENTER_THE_MAIN_VIEW_ON}, |
444 { WWT_PUSHTXTBTN, RESIZE_NONE, 9, 0, 129, 148, 159, STR_00E4_LOCATION, STR_482C_CENTER_THE_MAIN_VIEW_ON}, |
346 { WWT_IMGBTN, RESIZE_NONE, 9, 130, 259, 148, 159, 0x0, STR_NULL}, |
445 { WWT_IMGBTN, RESIZE_NONE, 9, 130, 259, 148, 159, 0x0, STR_NULL}, |
347 // Destroy Industry button costing money removed per request of dominik |
446 // Destroy Industry button costing money removed per request of dominik |
348 //{ WWT_PUSHTXTBTN, RESIZE_NONE, 9, 130, 259, 148, 159, STR_INDUSTRYDIR_DESTROY, STR_482C_DESTROY_INDUSTRY}, |
447 //{ WWT_PUSHTXTBTN, RESIZE_NONE, 9, 130, 259, 148, 159, STR_INDUSTRYDIR_DESTROY, STR_482C_DESTROY_INDUSTRY}, |