author | rubidium |
Fri, 25 Apr 2008 15:22:32 +0000 | |
changeset 9055 | 4dc6a0c0ef47 |
parent 9019 | fe04abd3f58f |
child 9094 | 48004fcef409 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6200
diff
changeset
|
3 |
/** @file industry_gui.cpp */ |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6200
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1786
diff
changeset
|
6 |
#include "openttd.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1287
diff
changeset
|
7 |
#include "debug.h" |
1386
0de4f8541aea
(svn r1890) Begin to clean up the edit box: Remove one global variable and split the combined edit/original buffer into two
tron
parents:
1309
diff
changeset
|
8 |
#include "gui.h" |
8107
bb7deea89175
(svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents:
8106
diff
changeset
|
9 |
#include "window_gui.h" |
bb7deea89175
(svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents:
8106
diff
changeset
|
10 |
#include "textbuf_gui.h" |
8116
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8114
diff
changeset
|
11 |
#include "command_func.h" |
8224
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8179
diff
changeset
|
12 |
#include "viewport_func.h" |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8179
diff
changeset
|
13 |
#include "gfx_func.h" |
0 | 14 |
#include "industry.h" |
15 |
#include "town.h" |
|
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2084
diff
changeset
|
16 |
#include "variables.h" |
8965
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8779
diff
changeset
|
17 |
#include "cheat_func.h" |
6091
c8827d9ae04a
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
5893
diff
changeset
|
18 |
#include "cargotype.h" |
7195
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
19 |
#include "newgrf.h" |
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
20 |
#include "newgrf_callbacks.h" |
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
21 |
#include "newgrf_industries.h" |
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
22 |
#include "newgrf_text.h" |
8114
dd6d21dc99c1
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8107
diff
changeset
|
23 |
#include "strings_func.h" |
8139
4e91c448c409
(svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents:
8131
diff
changeset
|
24 |
#include "map_func.h" |
8254
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8237
diff
changeset
|
25 |
#include "player_func.h" |
8270
e7c342f6b14c
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8264
diff
changeset
|
26 |
#include "settings_type.h" |
0 | 27 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
28 |
#include "table/strings.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
29 |
#include "table/sprites.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
30 |
|
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
31 |
bool _ignore_restrictions; |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
32 |
|
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
33 |
/** Names of the widgets of the dynamic place industries gui */ |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
34 |
enum DynamicPlaceIndustriesWidgets { |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
35 |
DPIW_CLOSEBOX = 0, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
36 |
DPIW_CAPTION, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
37 |
DPIW_MATRIX_WIDGET, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
38 |
DPIW_SCROLLBAR, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
39 |
DPIW_INFOPANEL, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
40 |
DPIW_FUND_WIDGET, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
41 |
DPIW_RESIZE_WIDGET, |
4995
69dbe0e096dc
(svn r7001) -Codechange: _build_industry_trypes is now only used by industry_gui.c. Move it there.
belugas
parents:
4939
diff
changeset
|
42 |
}; |
0 | 43 |
|
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
44 |
/** Attached struct to the window extended data */ |
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
45 |
struct fnd_d { |
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
46 |
int index; ///< index of the element in the matrix |
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
47 |
IndustryType select; ///< industry corresponding to the above index |
7283
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
48 |
uint16 callback_timer; ///< timer counter for callback eventual verification |
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
49 |
bool timer_enabled; ///< timer can be used |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
50 |
}; |
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
51 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(fnd_d)); |
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
52 |
|
7280
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
53 |
/** Helper struct holding the available industries for current situation */ |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
54 |
static struct IndustryData { |
7280
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
55 |
uint16 count; ///< How many industries are loaded |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
56 |
IndustryType index[NUM_INDUSTRYTYPES + 1]; ///< Type of industry, in the order it was loaded |
7280
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
57 |
StringID text[NUM_INDUSTRYTYPES + 1]; ///< Text coming from CBM_IND_FUND_MORE_TEXT (if ever) |
7283
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
58 |
bool enabled[NUM_INDUSTRYTYPES + 1]; ///< availability state, coming from CBID_INDUSTRY_AVAILABLE (if ever) |
7280
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
59 |
} _fund_gui; |
1004 | 60 |
|
8476
513c39859cb6
(svn r12049) -Fix (r10496)(r10619): memset on multibyte array with wrong byte count
smatz
parents:
8436
diff
changeset
|
61 |
assert_compile(lengthof(_fund_gui.index) == lengthof(_fund_gui.text)); |
513c39859cb6
(svn r12049) -Fix (r10496)(r10619): memset on multibyte array with wrong byte count
smatz
parents:
8436
diff
changeset
|
62 |
assert_compile(lengthof(_fund_gui.index) == lengthof(_fund_gui.enabled)); |
513c39859cb6
(svn r12049) -Fix (r10496)(r10619): memset on multibyte array with wrong byte count
smatz
parents:
8436
diff
changeset
|
63 |
|
8759
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
64 |
/** |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
65 |
* Gets the string to display after the cargo name (using callback 37) |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
66 |
* @param cargo the cargo for which the suffix is requested |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
67 |
* - 00 - first accepted cargo type |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
68 |
* - 01 - second accepted cargo type |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
69 |
* - 02 - third accepted cargo type |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
70 |
* - 03 - first produced cargo type |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
71 |
* - 04 - second produced cargo type |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
72 |
* @param ind the industry (NULL if in fund window) |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
73 |
* @param ind_type the industry type |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
74 |
* @param indspec the industry spec |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
75 |
* @return the string to display |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
76 |
*/ |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
77 |
static StringID GetCargoSuffix(uint cargo, Industry *ind, IndustryType ind_type, const IndustrySpec *indspec) |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
78 |
{ |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
79 |
if (HasBit(indspec->callback_flags, CBM_IND_CARGO_SUFFIX)) { |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
80 |
bool fund = ind == NULL; |
9019
fe04abd3f58f
(svn r12818) -Codechange: make callbacks 31 and 37 behave like they do in TTDP according to frosch's survey.
rubidium
parents:
8994
diff
changeset
|
81 |
uint16 callback = GetIndustryCallback(CBID_INDUSTRY_CARGO_SUFFIX, 0, ((!fund) ? 1 << 8 : 0) | cargo, ind, ind_type, (!fund) ? ind->xy : INVALID_TILE); |
fe04abd3f58f
(svn r12818) -Codechange: make callbacks 31 and 37 behave like they do in TTDP according to frosch's survey.
rubidium
parents:
8994
diff
changeset
|
82 |
if (GB(callback, 0, 8) != 0xFF) return GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback); |
8759
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
83 |
} |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
84 |
return STR_EMPTY; |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
85 |
} |
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
86 |
|
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
87 |
static void BuildDynamicIndustryWndProc(Window *w, WindowEvent *e) |
0 | 88 |
{ |
2951 | 89 |
switch (e->event) { |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
90 |
case WE_CREATE: { |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
91 |
IndustryType ind; |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
92 |
const IndustrySpec *indsp; |
0 | 93 |
|
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
94 |
/* Shorten the window to the equivalant of the additionnal purchase |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
95 |
* info coming from the callback. SO it will only be available to tis full |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
96 |
* height when newindistries are loaded */ |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
97 |
if (!_loaded_newgrf_features.has_newindustries) { |
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
98 |
w->widget[DPIW_INFOPANEL].bottom -= 44; |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
99 |
w->widget[DPIW_FUND_WIDGET].bottom -= 44; |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
100 |
w->widget[DPIW_FUND_WIDGET].top -= 44; |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
101 |
w->widget[DPIW_RESIZE_WIDGET].bottom -= 44; |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
102 |
w->widget[DPIW_RESIZE_WIDGET].top -= 44; |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
103 |
w->resize.height = w->height -= 44; |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
104 |
} |
0 | 105 |
|
7283
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
106 |
WP(w, fnd_d).timer_enabled = _loaded_newgrf_features.has_newindustries; |
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
107 |
|
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
108 |
/* Initilialize structures */ |
7280
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
109 |
_fund_gui.count = 0; |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
110 |
|
8476
513c39859cb6
(svn r12049) -Fix (r10496)(r10619): memset on multibyte array with wrong byte count
smatz
parents:
8436
diff
changeset
|
111 |
for (uint i = 0; i < lengthof(_fund_gui.index); i++) { |
513c39859cb6
(svn r12049) -Fix (r10496)(r10619): memset on multibyte array with wrong byte count
smatz
parents:
8436
diff
changeset
|
112 |
_fund_gui.index[i] = 0xFF; |
513c39859cb6
(svn r12049) -Fix (r10496)(r10619): memset on multibyte array with wrong byte count
smatz
parents:
8436
diff
changeset
|
113 |
_fund_gui.text[i] = STR_NULL; |
513c39859cb6
(svn r12049) -Fix (r10496)(r10619): memset on multibyte array with wrong byte count
smatz
parents:
8436
diff
changeset
|
114 |
_fund_gui.enabled[i] = false; |
513c39859cb6
(svn r12049) -Fix (r10496)(r10619): memset on multibyte array with wrong byte count
smatz
parents:
8436
diff
changeset
|
115 |
} |
513c39859cb6
(svn r12049) -Fix (r10496)(r10619): memset on multibyte array with wrong byte count
smatz
parents:
8436
diff
changeset
|
116 |
|
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
117 |
w->vscroll.cap = 8; // rows in grid, same in scroller |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
118 |
w->resize.step_height = 13; |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
119 |
|
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
120 |
if (_game_mode == GM_EDITOR) { // give room for the Many Random "button" |
7280
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
121 |
_fund_gui.index[_fund_gui.count] = INVALID_INDUSTRYTYPE; |
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
122 |
_fund_gui.count++; |
7283
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
123 |
WP(w, fnd_d).timer_enabled = false; |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
124 |
} |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
125 |
|
7708
48d236e6fbf4
(svn r11242) -Codechange: When displaying the industry funding gui, present the industries in the same order as they are available.
belugas
parents:
7647
diff
changeset
|
126 |
/* Fill the _fund_gui structure with industries. |
48d236e6fbf4
(svn r11242) -Codechange: When displaying the industry funding gui, present the industries in the same order as they are available.
belugas
parents:
7647
diff
changeset
|
127 |
* The tests performed after the enabled allow to load the industries |
48d236e6fbf4
(svn r11242) -Codechange: When displaying the industry funding gui, present the industries in the same order as they are available.
belugas
parents:
7647
diff
changeset
|
128 |
* In the same way they are inserted by grf (if any) |
48d236e6fbf4
(svn r11242) -Codechange: When displaying the industry funding gui, present the industries in the same order as they are available.
belugas
parents:
7647
diff
changeset
|
129 |
*/ |
7319
9b20d1dbe5d6
(svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents:
7289
diff
changeset
|
130 |
for (ind = 0; ind < NUM_INDUSTRYTYPES; ind++) { |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
131 |
indsp = GetIndustrySpec(ind); |
7708
48d236e6fbf4
(svn r11242) -Codechange: When displaying the industry funding gui, present the industries in the same order as they are available.
belugas
parents:
7647
diff
changeset
|
132 |
if (indsp->enabled){ |
48d236e6fbf4
(svn r11242) -Codechange: When displaying the industry funding gui, present the industries in the same order as they are available.
belugas
parents:
7647
diff
changeset
|
133 |
/* Rule is that editor mode loads all industries. |
48d236e6fbf4
(svn r11242) -Codechange: When displaying the industry funding gui, present the industries in the same order as they are available.
belugas
parents:
7647
diff
changeset
|
134 |
* In game mode, all non raw industries are loaded too |
48d236e6fbf4
(svn r11242) -Codechange: When displaying the industry funding gui, present the industries in the same order as they are available.
belugas
parents:
7647
diff
changeset
|
135 |
* and raw ones are loaded only when setting allows it */ |
48d236e6fbf4
(svn r11242) -Codechange: When displaying the industry funding gui, present the industries in the same order as they are available.
belugas
parents:
7647
diff
changeset
|
136 |
if (_game_mode != GM_EDITOR && indsp->IsRawIndustry() && _patches.raw_industry_construction == 0) continue; |
7280
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
137 |
_fund_gui.index[_fund_gui.count] = ind; |
7647
6a1162b442ce
(svn r11178) -Fix: don't check newgrf callback 22 in scenario editor
glx
parents:
7645
diff
changeset
|
138 |
_fund_gui.enabled[_fund_gui.count] = (_game_mode == GM_EDITOR) || CheckIfCallBackAllowsAvailability(ind, IACT_USERCREATION); |
7280
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
139 |
_fund_gui.count++; |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
140 |
} |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
141 |
} |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
142 |
|
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
143 |
/* first indutry type is selected. |
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
144 |
* I'll be damned if there are none available ;) */ |
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
145 |
WP(w, fnd_d).index = 0; |
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
146 |
WP(w, fnd_d).select = _fund_gui.index[0]; |
7283
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
147 |
WP(w, fnd_d).callback_timer = DAY_TICKS; |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
148 |
} break; |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
149 |
|
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
150 |
case WE_PAINT: { |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
151 |
const IndustrySpec *indsp = (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(WP(w, fnd_d).select); |
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
152 |
int x_str = w->widget[DPIW_INFOPANEL].left + 3; |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
153 |
int y_str = w->widget[DPIW_INFOPANEL].top + 3; |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
154 |
const Widget *wi = &w->widget[DPIW_INFOPANEL]; |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
155 |
int max_width = wi->right - wi->left - 4; |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
156 |
|
7280
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
157 |
/* Raw industries might be prospected. Show this fact by changing the string |
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
158 |
* In Editor, you just build, while ingame, or you fund or you prospect */ |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
159 |
if (_game_mode == GM_EDITOR) { |
7283
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
160 |
/* We've chosen many random industries but no industries have been specified */ |
7289
9d5fe9be6f2f
(svn r10637) -Fix: Enable the Random Industries in scenario editor if setting Number of Industries is not NONE.
belugas
parents:
7284
diff
changeset
|
161 |
if (indsp == NULL) _fund_gui.enabled[WP(w, fnd_d).index] = _opt.diff.number_industries != 0; |
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
162 |
w->widget[DPIW_FUND_WIDGET].data = STR_BUILD_NEW_INDUSTRY; |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
163 |
} else { |
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
164 |
w->widget[DPIW_FUND_WIDGET].data = (_patches.raw_industry_construction == 2 && indsp->IsRawIndustry()) ? STR_PROSPECT_NEW_INDUSTRY : STR_FUND_NEW_INDUSTRY; |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
165 |
} |
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
166 |
w->SetWidgetDisabledState(DPIW_FUND_WIDGET, !_fund_gui.enabled[WP(w, fnd_d).index]); |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
167 |
|
7280
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
168 |
SetVScrollCount(w, _fund_gui.count); |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
169 |
|
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
170 |
DrawWindowWidgets(w); |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
171 |
|
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
172 |
/* and now with the matrix painting */ |
7280
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
173 |
for (byte i = 0; i < w->vscroll.cap && ((i + w->vscroll.pos) < _fund_gui.count); i++) { |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
174 |
int offset = i * 13; |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
175 |
int x = 3; |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
176 |
int y = 16; |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
177 |
bool selected = WP(w, fnd_d).index == i + w->vscroll.pos; |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
178 |
|
7280
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
179 |
if (_fund_gui.index[i + w->vscroll.pos] == INVALID_INDUSTRYTYPE) { |
7877
184477162db7
(svn r11427) -Fix: Forgot to Truncate the string "Many Random Industries" in the funding industry window. In some languages, it gets drawn outside of the gui.
belugas
parents:
7824
diff
changeset
|
180 |
DrawStringTruncated(20, y + offset, STR_MANY_RANDOM_INDUSTRIES, selected ? TC_WHITE : TC_ORANGE, max_width - 25); |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
181 |
continue; |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
182 |
} |
7280
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
183 |
const IndustrySpec *indsp = GetIndustrySpec(_fund_gui.index[i + w->vscroll.pos]); |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
184 |
|
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
185 |
/* Draw the name of the industry in white is selected, otherwise, in orange */ |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7822
diff
changeset
|
186 |
DrawStringTruncated(20, y + offset, indsp->name, selected ? TC_WHITE : TC_ORANGE, max_width - 25); |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
187 |
GfxFillRect(x, y + 1 + offset, x + 10, y + 7 + offset, selected ? 15 : 0); |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
188 |
GfxFillRect(x + 1, y + 2 + offset, x + 9, y + 6 + offset, indsp->map_colour); |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
189 |
} |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
190 |
|
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
191 |
if (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) { |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
192 |
DrawStringMultiLine(x_str, y_str, STR_RANDOM_INDUSTRIES_TIP, max_width, wi->bottom - wi->top - 40); |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
193 |
break; |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
194 |
} |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
195 |
|
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
196 |
if (_game_mode != GM_EDITOR) { |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
197 |
SetDParam(0, indsp->GetConstructionCost()); |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7822
diff
changeset
|
198 |
DrawStringTruncated(x_str, y_str, STR_482F_COST, TC_FROMSTRING, max_width); |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
199 |
y_str += 11; |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
200 |
} |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
201 |
|
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
202 |
/* Draw the accepted cargos, if any. Otherwhise, will print "Nothing" */ |
7822
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
203 |
StringID str = STR_4827_REQUIRES; |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
204 |
byte p = 0; |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
205 |
SetDParam(0, STR_00D0_NOTHING); |
8759
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
206 |
SetDParam(1, STR_EMPTY); |
7822
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
207 |
for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++) { |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
208 |
if (indsp->accepts_cargo[j] == CT_INVALID) continue; |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
209 |
if (p > 0) str++; |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
210 |
SetDParam(p++, GetCargo(indsp->accepts_cargo[j])->name); |
8759
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
211 |
SetDParam(p++, GetCargoSuffix(j, NULL, WP(w, fnd_d).select, indsp)); |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
212 |
} |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7822
diff
changeset
|
213 |
DrawStringTruncated(x_str, y_str, str, TC_FROMSTRING, max_width); |
7822
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
214 |
y_str += 11; |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
215 |
|
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
216 |
/* Draw the produced cargos, if any. Otherwhise, will print "Nothing" */ |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
217 |
str = STR_4827_PRODUCES; |
7822
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
218 |
p = 0; |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
219 |
SetDParam(0, STR_00D0_NOTHING); |
8759
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
220 |
SetDParam(1, STR_EMPTY); |
7822
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
221 |
for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) { |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
222 |
if (indsp->produced_cargo[j] == CT_INVALID) continue; |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
223 |
if (p > 0) str++; |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
224 |
SetDParam(p++, GetCargo(indsp->produced_cargo[j])->name); |
8759
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
225 |
SetDParam(p++, GetCargoSuffix(j + 3, NULL, WP(w, fnd_d).select, indsp)); |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
226 |
} |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7822
diff
changeset
|
227 |
DrawStringTruncated(x_str, y_str, str, TC_FROMSTRING, max_width); |
7822
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
228 |
y_str += 11; |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
229 |
|
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
230 |
/* Get the additional purchase info text, if it has not already been */ |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
231 |
if (_fund_gui.text[WP(w, fnd_d).index] == STR_NULL) { // Have i been called already? |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
232 |
if (HasBit(indsp->callback_flags, CBM_IND_FUND_MORE_TEXT)) { // No. Can it be called? |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
233 |
uint16 callback_res = GetIndustryCallback(CBID_INDUSTRY_FUND_MORE_TEXT, 0, 0, NULL, WP(w, fnd_d).select, INVALID_TILE); |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
234 |
if (callback_res != CALLBACK_FAILED) { // Did it failed? |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
235 |
StringID newtxt = GetGRFStringID(indsp->grf_prop.grffile->grfid, 0xD000 + callback_res); // No. here's the new string |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
236 |
_fund_gui.text[WP(w, fnd_d).index] = newtxt; // Store it for further usage |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
237 |
} |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
238 |
} |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
239 |
} |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
240 |
|
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
241 |
/* Draw the Additional purchase text, provided by newgrf callback, if any. |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
242 |
* Otherwhise, will print Nothing */ |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
243 |
str = _fund_gui.text[WP(w, fnd_d).index]; |
7280
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
244 |
if (str != STR_NULL && str != STR_UNDEFINED) { |
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
245 |
SetDParam(0, str); |
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
246 |
DrawStringMultiLine(x_str, y_str, STR_JUST_STRING, max_width, wi->bottom - wi->top - 40); |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
247 |
} |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
248 |
} break; |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
249 |
|
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
250 |
case WE_DOUBLE_CLICK: |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
251 |
if (e->we.click.widget != DPIW_MATRIX_WIDGET) break; |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
252 |
e->we.click.widget = DPIW_FUND_WIDGET; |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
253 |
/* Fall through */ |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
254 |
|
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
255 |
case WE_CLICK: |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
256 |
switch (e->we.click.widget) { |
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
257 |
case DPIW_MATRIX_WIDGET: { |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
258 |
const IndustrySpec *indsp; |
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
259 |
int y = (e->we.click.pt.y - w->widget[DPIW_MATRIX_WIDGET].top) / 13 + w->vscroll.pos ; |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
260 |
|
7280
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
261 |
if (y >= 0 && y < _fund_gui.count) { // Is it within the boundaries of available data? |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
262 |
WP(w, fnd_d).index = y; |
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
263 |
WP(w, fnd_d).select = _fund_gui.index[WP(w, fnd_d).index]; |
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
264 |
indsp = (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(WP(w, fnd_d).select); |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
265 |
|
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
266 |
SetWindowDirty(w); |
7280
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
267 |
|
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
268 |
if ((_game_mode != GM_EDITOR && _patches.raw_industry_construction == 2 && indsp != NULL && indsp->IsRawIndustry()) || |
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
269 |
WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) { |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
270 |
/* Reset the button state if going to prospecting or "build many industries" */ |
8032
f35fba9bacb0
(svn r11592) -Codechange: Use the Window member RaiseButtons and remove the now useless RaiseWindowButtons function
belugas
parents:
7997
diff
changeset
|
271 |
w->RaiseButtons(); |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
272 |
ResetObjectToPlace(); |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
273 |
} |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
274 |
} |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
275 |
} break; |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
276 |
|
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
277 |
case DPIW_FUND_WIDGET: { |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
278 |
if (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) { |
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
279 |
w->HandleButtonClick(DPIW_FUND_WIDGET); |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
280 |
|
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
281 |
if (GetNumTowns() == 0) { |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
282 |
ShowErrorMessage(STR_0286_MUST_BUILD_TOWN_FIRST, STR_CAN_T_GENERATE_INDUSTRIES, 0, 0); |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
283 |
} else { |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
284 |
extern void GenerateIndustries(); |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
285 |
_generating_world = true; |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
286 |
GenerateIndustries(); |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
287 |
_generating_world = false; |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
288 |
} |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
289 |
} else if (_game_mode != GM_EDITOR && _patches.raw_industry_construction == 2 && GetIndustrySpec(WP(w, fnd_d).select)->IsRawIndustry()) { |
8436
c2600da0d3e3
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8417
diff
changeset
|
290 |
DoCommandP(0, WP(w, fnd_d).select, InteractiveRandom(), NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY)); |
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
291 |
w->HandleButtonClick(DPIW_FUND_WIDGET); |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
292 |
} else { |
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
293 |
HandlePlacePushButton(w, DPIW_FUND_WIDGET, SPR_CURSOR_INDUSTRY, VHM_RECT, NULL); |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
294 |
} |
7271
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
295 |
} break; |
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
296 |
} |
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
297 |
break; |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
298 |
|
7271
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
299 |
case WE_RESIZE: { |
7280
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
300 |
/* Adjust the number of items in the matrix depending of the rezise */ |
7271
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
301 |
w->vscroll.cap += e->we.sizing.diff.y / (int)w->resize.step_height; |
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
302 |
w->widget[DPIW_MATRIX_WIDGET].data = (w->vscroll.cap << 8) + 1; |
7271
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
303 |
} break; |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
304 |
|
7271
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
305 |
case WE_PLACE_OBJ: { |
7747
b76ffa88b556
(svn r11284) -Codechange: don't reset build industry cursor if it failed
glx
parents:
7713
diff
changeset
|
306 |
bool success = true; |
7280
90c44142fb30
(svn r10619) -Codechange: Use shorter variable/member names and add some code separation.
belugas
parents:
7279
diff
changeset
|
307 |
/* We do not need to protect ourselves against "Random Many Industries" in this mode */ |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
308 |
const IndustrySpec *indsp = GetIndustrySpec(WP(w, fnd_d).select); |
8436
c2600da0d3e3
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8417
diff
changeset
|
309 |
uint32 seed = InteractiveRandom(); |
7271
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
310 |
|
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
311 |
if (_game_mode == GM_EDITOR) { |
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
312 |
/* Show error if no town exists at all */ |
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
313 |
if (GetNumTowns() == 0) { |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
314 |
SetDParam(0, indsp->name); |
7271
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
315 |
ShowErrorMessage(STR_0286_MUST_BUILD_TOWN_FIRST, STR_0285_CAN_T_BUILD_HERE, e->we.place.pt.x, e->we.place.pt.y); |
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
316 |
return; |
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
317 |
} |
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
318 |
|
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
319 |
_current_player = OWNER_NONE; |
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
320 |
_generating_world = true; |
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
321 |
_ignore_restrictions = true; |
8436
c2600da0d3e3
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8417
diff
changeset
|
322 |
success = DoCommandP(e->we.place.tile, (InteractiveRandomRange(indsp->num_table) << 16) | WP(w, fnd_d).select, seed, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY)); |
7747
b76ffa88b556
(svn r11284) -Codechange: don't reset build industry cursor if it failed
glx
parents:
7713
diff
changeset
|
323 |
if (!success) { |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
324 |
SetDParam(0, indsp->name); |
7271
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
325 |
ShowErrorMessage(_error_message, STR_0285_CAN_T_BUILD_HERE, e->we.place.pt.x, e->we.place.pt.y); |
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
326 |
} |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
327 |
|
7271
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
328 |
_ignore_restrictions = false; |
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
329 |
_generating_world = false; |
7747
b76ffa88b556
(svn r11284) -Codechange: don't reset build industry cursor if it failed
glx
parents:
7713
diff
changeset
|
330 |
} else { |
8436
c2600da0d3e3
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8417
diff
changeset
|
331 |
success = DoCommandP(e->we.place.tile, (InteractiveRandomRange(indsp->num_table) << 16) | WP(w, fnd_d).select, seed, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY)); |
7747
b76ffa88b556
(svn r11284) -Codechange: don't reset build industry cursor if it failed
glx
parents:
7713
diff
changeset
|
332 |
} |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
333 |
|
7747
b76ffa88b556
(svn r11284) -Codechange: don't reset build industry cursor if it failed
glx
parents:
7713
diff
changeset
|
334 |
/* If an industry has been built, just reset the cursor and the system */ |
b76ffa88b556
(svn r11284) -Codechange: don't reset build industry cursor if it failed
glx
parents:
7713
diff
changeset
|
335 |
if (success) ResetObjectToPlace(); |
7271
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
336 |
} break; |
0 | 337 |
|
7283
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
338 |
case WE_TICK: |
8179
60c4282e6de6
(svn r11742) -Codechange [FS#1319]: Run window tick events when paused, so that news pop-ups and the about window still progress. For other windows the events are ignored when paused.
peter1138
parents:
8140
diff
changeset
|
339 |
if (_pause_game != 0) break; |
7283
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
340 |
if (!WP(w, fnd_d).timer_enabled) break; |
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
341 |
if (--WP(w, fnd_d).callback_timer == 0) { |
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
342 |
/* We have just passed another day. |
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
343 |
* See if we need to update availability of currently selected industry */ |
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
344 |
WP(w, fnd_d).callback_timer = DAY_TICKS; //restart counter |
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
345 |
|
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
346 |
const IndustrySpec *indsp = GetIndustrySpec(WP(w, fnd_d).select); |
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
347 |
|
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
348 |
if (indsp->enabled) { |
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
349 |
bool call_back_result = CheckIfCallBackAllowsAvailability(WP(w, fnd_d).select, IACT_USERCREATION); |
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
350 |
|
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
351 |
/* Only if result does match the previous state would it require a redraw. */ |
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
352 |
if (call_back_result != _fund_gui.enabled[WP(w, fnd_d).index]) { |
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
353 |
_fund_gui.enabled[WP(w, fnd_d).index] = call_back_result; |
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
354 |
SetWindowDirty(w); |
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
355 |
} |
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
356 |
} |
510097a30c0c
(svn r10622) -Feature: Introduction of the CBID_INDUSTRY_AVAILABLE's handling, in fund industry window.
belugas
parents:
7282
diff
changeset
|
357 |
} |
7271
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
358 |
break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
359 |
|
7271
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
360 |
case WE_TIMEOUT: |
7282
33798f2d0bde
(svn r10621) -Codechange: install a struct holding the user's selection from _fund_gui.
belugas
parents:
7280
diff
changeset
|
361 |
case WE_ABORT_PLACE_OBJ: |
8032
f35fba9bacb0
(svn r11592) -Codechange: Use the Window member RaiseButtons and remove the now useless RaiseWindowButtons function
belugas
parents:
7997
diff
changeset
|
362 |
w->RaiseButtons(); |
7271
490a663678ad
(svn r10600) -Codechange: code-stylising the gui switch-case code
belugas
parents:
7218
diff
changeset
|
363 |
break; |
0 | 364 |
} |
365 |
} |
|
366 |
||
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
367 |
/** Widget definition of the dynamic place industries gui */ |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
368 |
static const Widget _build_dynamic_industry_widgets[] = { |
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
369 |
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // DPIW_CLOSEBOX |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
370 |
{ WWT_CAPTION, RESIZE_RIGHT, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS}, // DPIW_CAPTION |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
371 |
{ WWT_MATRIX, RESIZE_RB, 7, 0, 157, 14, 118, 0x801, STR_INDUSTRY_SELECTION_HINT}, // DPIW_MATRIX_WIDGET |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
372 |
{ WWT_SCROLLBAR, RESIZE_LRB, 7, 158, 169, 14, 118, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // DPIW_SCROLLBAR |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
373 |
{ WWT_PANEL, RESIZE_RTB, 7, 0, 169, 119, 199, 0x0, STR_NULL}, // DPIW_INFOPANEL |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
374 |
{ WWT_TEXTBTN, RESIZE_RTB, 7, 0, 157, 200, 211, STR_FUND_NEW_INDUSTRY, STR_NULL}, // DPIW_FUND_WIDGET |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
375 |
{ WWT_RESIZEBOX, RESIZE_LRTB, 7, 158, 169, 200, 211, 0x0, STR_RESIZE_BUTTON}, // DPIW_RESIZE_WIDGET |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
164
diff
changeset
|
376 |
{ WIDGETS_END}, |
0 | 377 |
}; |
378 |
||
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
379 |
/** Window definition of the dynamic place industries gui */ |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
380 |
static const WindowDesc _build_industry_dynamic_desc = { |
7341
02515d0d4ced
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7319
diff
changeset
|
381 |
WDP_AUTO, WDP_AUTO, 170, 212, 170, 212, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5609
diff
changeset
|
382 |
WC_BUILD_INDUSTRY, WC_NONE, |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
383 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE, |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
384 |
_build_dynamic_industry_widgets, |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
385 |
BuildDynamicIndustryWndProc, |
0 | 386 |
}; |
387 |
||
6247 | 388 |
void ShowBuildIndustryWindow() |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
389 |
{ |
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
390 |
if (_game_mode != GM_EDITOR && !IsValidPlayer(_current_player)) return; |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
391 |
AllocateWindowDescFront(&_build_industry_dynamic_desc, 0); |
0 | 392 |
} |
393 |
||
7218
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
394 |
static void UpdateIndustryProduction(Industry *i); |
8e73038b7586
(svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents:
7195
diff
changeset
|
395 |
|
7284
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
396 |
static inline bool isProductionMinimum(const Industry *i, int pt) |
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
397 |
{ |
7790
49e446d753b2
(svn r11340) -Fix[FS#1362]: Newindustries can provide no production at start. So the Modifying Production cheat was a bit puzzled on how to deal with it. This will help a bit.
belugas
parents:
7750
diff
changeset
|
398 |
return i->production_rate[pt] == 0; |
4211
5ee54ab361c9
(svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents:
4194
diff
changeset
|
399 |
} |
5ee54ab361c9
(svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents:
4194
diff
changeset
|
400 |
|
7284
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
401 |
static inline bool isProductionMaximum(const Industry *i, int pt) |
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
402 |
{ |
7790
49e446d753b2
(svn r11340) -Fix[FS#1362]: Newindustries can provide no production at start. So the Modifying Production cheat was a bit puzzled on how to deal with it. This will help a bit.
belugas
parents:
7750
diff
changeset
|
403 |
return i->production_rate[pt] >= 255; |
4211
5ee54ab361c9
(svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents:
4194
diff
changeset
|
404 |
} |
5ee54ab361c9
(svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents:
4194
diff
changeset
|
405 |
|
4194
7df740c3b712
(svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents:
4193
diff
changeset
|
406 |
static inline bool IsProductionAlterable(const Industry *i) |
7df740c3b712
(svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents:
4193
diff
changeset
|
407 |
{ |
7df740c3b712
(svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents:
4193
diff
changeset
|
408 |
return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) && |
7645
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7616
diff
changeset
|
409 |
(i->accepts_cargo[0] == CT_INVALID || i->accepts_cargo[0] == CT_VALUABLES)); |
4194
7df740c3b712
(svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents:
4193
diff
changeset
|
410 |
} |
7df740c3b712
(svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents:
4193
diff
changeset
|
411 |
|
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
412 |
/** Names of the widgets of the view industry gui */ |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
413 |
enum IndustryViewWidgets { |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
414 |
IVW_CLOSEBOX = 0, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
415 |
IVW_CAPTION, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
416 |
IVW_STICKY, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
417 |
IVW_BACKGROUND, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
418 |
IVW_VIEWPORT, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
419 |
IVW_INFO, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
420 |
IVW_GOTO, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
421 |
IVW_SPACER, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
422 |
}; |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
423 |
|
7284
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
424 |
/** Information to store about the industry window */ |
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
425 |
struct indview_d : public vp_d { |
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
426 |
byte editbox_line; ///< The line clicked to open the edit box |
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
427 |
byte clicked_line; ///< The line of the button that has been clicked |
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
428 |
byte clicked_button; ///< The button that has been clicked (to raise) |
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
429 |
byte production_offset_y; ///< The offset of the production texts/buttons |
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
430 |
}; |
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
431 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(indview_d)); |
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
432 |
|
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
433 |
|
0 | 434 |
static void IndustryViewWndProc(Window *w, WindowEvent *e) |
435 |
{ |
|
2951 | 436 |
switch (e->event) { |
1004 | 437 |
case WE_PAINT: { |
7195
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
438 |
Industry *i = GetIndustry(w->window_number); |
6636
fec086b5c340
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents:
6624
diff
changeset
|
439 |
const IndustrySpec *ind = GetIndustrySpec(i->type); |
8779
038e02efbc0a
(svn r12479) -Codechange [FS#1723]: Simplify the method used to resize the industry view window. The window is now shown the correct size so the resize button is also removed.
peter1138
parents:
8759
diff
changeset
|
440 |
int y = w->widget[IVW_INFO].top + 1; |
7822
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
441 |
bool first = true; |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
442 |
bool has_accept = false; |
2557 | 443 |
|
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
444 |
SetDParam(0, w->window_number); |
0 | 445 |
DrawWindowWidgets(w); |
446 |
||
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
447 |
if (HasBit(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) { |
7822
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
448 |
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) { |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
449 |
if (i->accepts_cargo[j] == CT_INVALID) continue; |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
450 |
has_accept = true; |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
451 |
if (first) { |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7822
diff
changeset
|
452 |
DrawString(2, y, STR_INDUSTRY_WINDOW_WAITING_FOR_PROCESSING, TC_FROMSTRING); |
7195
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
453 |
y += 10; |
7822
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
454 |
first = false; |
7195
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
455 |
} |
7645
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7616
diff
changeset
|
456 |
SetDParam(0, i->accepts_cargo[j]); |
7195
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
457 |
SetDParam(1, i->incoming_cargo_waiting[j]); |
8759
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
458 |
SetDParam(2, GetCargoSuffix(j, i, i->type, ind)); |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7822
diff
changeset
|
459 |
DrawString(4, y, STR_INDUSTRY_WINDOW_WAITING_STOCKPILE_CARGO, TC_FROMSTRING); |
7195
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
460 |
y += 10; |
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
461 |
} |
7822
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
462 |
} else { |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
463 |
StringID str = STR_4827_REQUIRES; |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
464 |
byte p = 0; |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
465 |
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) { |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
466 |
if (i->accepts_cargo[j] == CT_INVALID) continue; |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
467 |
has_accept = true; |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
468 |
if (p > 0) str++; |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
469 |
SetDParam(p++, GetCargo(i->accepts_cargo[j])->name); |
8759
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
470 |
SetDParam(p++, GetCargoSuffix(j, i, i->type, ind)); |
0 | 471 |
} |
7822
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
472 |
if (has_accept) { |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7822
diff
changeset
|
473 |
DrawString(2, y, str, TC_FROMSTRING); |
7822
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
474 |
y += 10; |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
475 |
} |
0 | 476 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
477 |
|
7822
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
478 |
first = true; |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
479 |
for (byte j = 0; j < lengthof(i->produced_cargo); j++) { |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
480 |
if (i->produced_cargo[j] == CT_INVALID) continue; |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
481 |
if (first) { |
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
482 |
if (has_accept) y += 10; |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7822
diff
changeset
|
483 |
DrawString(2, y, STR_482A_PRODUCTION_LAST_MONTH, TC_FROMSTRING); |
7195
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
484 |
y += 10; |
7284
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
485 |
WP(w, indview_d).production_offset_y = y; |
7822
dc5f1aa98fe9
(svn r11372) -Fix [FS#1394]: don't stop on first invalid cargo type when displaying industry acceptance
glx
parents:
7806
diff
changeset
|
486 |
first = false; |
7195
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
487 |
} |
0 | 488 |
|
7645
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7616
diff
changeset
|
489 |
SetDParam(0, i->produced_cargo[j]); |
7195
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
490 |
SetDParam(1, i->last_month_production[j]); |
8759
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
491 |
SetDParam(2, GetCargoSuffix(j + 3, i, i->type, ind)); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
1981
diff
changeset
|
492 |
|
8759
dc74629e649f
(svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents:
8476
diff
changeset
|
493 |
SetDParam(3, i->last_month_pct_transported[j] * 100 >> 8); |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7822
diff
changeset
|
494 |
DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), y, STR_482B_TRANSPORTED, TC_FROMSTRING); |
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6200
diff
changeset
|
495 |
/* Let's put out those buttons.. */ |
4211
5ee54ab361c9
(svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents:
4194
diff
changeset
|
496 |
if (IsProductionAlterable(i)) { |
7284
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
497 |
DrawArrowButtons(5, y, 3, (WP(w, indview_d).clicked_line == j + 1) ? WP(w, indview_d).clicked_button : 0, |
7195
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
498 |
!isProductionMinimum(i, j), !isProductionMaximum(i, j)); |
4211
5ee54ab361c9
(svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents:
4194
diff
changeset
|
499 |
} |
7195
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
500 |
y += 10; |
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
501 |
} |
0 | 502 |
|
7195
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
503 |
/* Get the extra message for the GUI */ |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
504 |
if (HasBit(ind->callback_flags, CBM_IND_WINDOW_MORE_TEXT)) { |
7195
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
505 |
uint16 callback_res = GetIndustryCallback(CBID_INDUSTRY_WINDOW_MORE_TEXT, 0, 0, i, i->type, i->xy); |
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
506 |
if (callback_res != CALLBACK_FAILED) { |
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
507 |
StringID message = GetGRFStringID(ind->grf_prop.grffile->grfid, 0xD000 + callback_res); |
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
508 |
if (message != STR_NULL && message != STR_UNDEFINED) { |
8417
2f68ba2e6523
(svn r11987) -Feature[newGRF]: Allow the industry view window to be resized only when callback 3A (Show additional text in industry window) is available for the current industry.
belugas
parents:
8349
diff
changeset
|
509 |
const Widget *wi = &w->widget[IVW_INFO]; |
7195
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
510 |
y += 10; |
7616
ebf15b08ac38
(svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents:
7341
diff
changeset
|
511 |
|
7750
7afbef1235e0
(svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents:
7747
diff
changeset
|
512 |
PrepareTextRefStackUsage(6); |
8417
2f68ba2e6523
(svn r11987) -Feature[newGRF]: Allow the industry view window to be resized only when callback 3A (Show additional text in industry window) is available for the current industry.
belugas
parents:
8349
diff
changeset
|
513 |
/* Use all the available space left from where we stand up to the end of the window */ |
8779
038e02efbc0a
(svn r12479) -Codechange [FS#1723]: Simplify the method used to resize the industry view window. The window is now shown the correct size so the resize button is also removed.
peter1138
parents:
8759
diff
changeset
|
514 |
y += DrawStringMultiLine(2, y, message, wi->right - wi->left - 4, -1); |
7616
ebf15b08ac38
(svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents:
7341
diff
changeset
|
515 |
StopTextRefStackUsage(); |
4211
5ee54ab361c9
(svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents:
4194
diff
changeset
|
516 |
} |
0 | 517 |
} |
518 |
} |
|
519 |
||
8779
038e02efbc0a
(svn r12479) -Codechange [FS#1723]: Simplify the method used to resize the industry view window. The window is now shown the correct size so the resize button is also removed.
peter1138
parents:
8759
diff
changeset
|
520 |
if (y > w->widget[IVW_INFO].bottom) { |
038e02efbc0a
(svn r12479) -Codechange [FS#1723]: Simplify the method used to resize the industry view window. The window is now shown the correct size so the resize button is also removed.
peter1138
parents:
8759
diff
changeset
|
521 |
SetWindowDirty(w); |
038e02efbc0a
(svn r12479) -Codechange [FS#1723]: Simplify the method used to resize the industry view window. The window is now shown the correct size so the resize button is also removed.
peter1138
parents:
8759
diff
changeset
|
522 |
ResizeWindowForWidget(w, IVW_INFO, 0, y - w->widget[IVW_INFO].top); |
038e02efbc0a
(svn r12479) -Codechange [FS#1723]: Simplify the method used to resize the industry view window. The window is now shown the correct size so the resize button is also removed.
peter1138
parents:
8759
diff
changeset
|
523 |
SetWindowDirty(w); |
038e02efbc0a
(svn r12479) -Codechange [FS#1723]: Simplify the method used to resize the industry view window. The window is now shown the correct size so the resize button is also removed.
peter1138
parents:
8759
diff
changeset
|
524 |
return; |
038e02efbc0a
(svn r12479) -Codechange [FS#1723]: Simplify the method used to resize the industry view window. The window is now shown the correct size so the resize button is also removed.
peter1138
parents:
8759
diff
changeset
|
525 |
} |
038e02efbc0a
(svn r12479) -Codechange [FS#1723]: Simplify the method used to resize the industry view window. The window is now shown the correct size so the resize button is also removed.
peter1138
parents:
8759
diff
changeset
|
526 |
|
0 | 527 |
DrawWindowViewport(w); |
7195
8c728b5fef43
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7185
diff
changeset
|
528 |
} break; |
0 | 529 |
|
1004 | 530 |
case WE_CLICK: { |
531 |
Industry *i; |
|
532 |
||
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4617
diff
changeset
|
533 |
switch (e->we.click.widget) { |
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
534 |
case IVW_INFO: { |
4193
9e82090fef58
(svn r5653) -Cleanup: Do a little cleanup of the industry gui code.
Darkvater
parents:
4192
diff
changeset
|
535 |
int line, x; |
1004 | 536 |
|
537 |
i = GetIndustry(w->window_number); |
|
538 |
||
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6200
diff
changeset
|
539 |
/* We should work if needed.. */ |
4194
7df740c3b712
(svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents:
4193
diff
changeset
|
540 |
if (!IsProductionAlterable(i)) return; |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4617
diff
changeset
|
541 |
x = e->we.click.pt.x; |
7284
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
542 |
line = (e->we.click.pt.y - WP(w, indview_d).production_offset_y) / 10; |
7954
57b51c69c072
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
7928
diff
changeset
|
543 |
if (e->we.click.pt.y >= WP(w, indview_d).production_offset_y && IsInsideMM(line, 0, 2) && i->produced_cargo[line] != CT_INVALID) { |
57b51c69c072
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
7928
diff
changeset
|
544 |
if (IsInsideMM(x, 5, 25) ) { |
4193
9e82090fef58
(svn r5653) -Cleanup: Do a little cleanup of the industry gui code.
Darkvater
parents:
4192
diff
changeset
|
545 |
/* Clicked buttons, decrease or increase production */ |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1004
diff
changeset
|
546 |
if (x < 15) { |
4211
5ee54ab361c9
(svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents:
4194
diff
changeset
|
547 |
if (isProductionMinimum(i, line)) return; |
7790
49e446d753b2
(svn r11340) -Fix[FS#1362]: Newindustries can provide no production at start. So the Modifying Production cheat was a bit puzzled on how to deal with it. This will help a bit.
belugas
parents:
7750
diff
changeset
|
548 |
i->production_rate[line] = max(i->production_rate[line] / 2, 0); |
1004 | 549 |
} else { |
7790
49e446d753b2
(svn r11340) -Fix[FS#1362]: Newindustries can provide no production at start. So the Modifying Production cheat was a bit puzzled on how to deal with it. This will help a bit.
belugas
parents:
7750
diff
changeset
|
550 |
/* a zero production industry is unlikely to give anything but zero, so push it a little bit */ |
49e446d753b2
(svn r11340) -Fix[FS#1362]: Newindustries can provide no production at start. So the Modifying Production cheat was a bit puzzled on how to deal with it. This will help a bit.
belugas
parents:
7750
diff
changeset
|
551 |
int new_prod = i->production_rate[line] == 0 ? 1 : i->production_rate[line] * 2; |
4211
5ee54ab361c9
(svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents:
4194
diff
changeset
|
552 |
if (isProductionMaximum(i, line)) return; |
7790
49e446d753b2
(svn r11340) -Fix[FS#1362]: Newindustries can provide no production at start. So the Modifying Production cheat was a bit puzzled on how to deal with it. This will help a bit.
belugas
parents:
7750
diff
changeset
|
553 |
i->production_rate[line] = minu(new_prod, 255); |
1004 | 554 |
} |
4193
9e82090fef58
(svn r5653) -Cleanup: Do a little cleanup of the industry gui code.
Darkvater
parents:
4192
diff
changeset
|
555 |
|
1004 | 556 |
UpdateIndustryProduction(i); |
557 |
SetWindowDirty(w); |
|
558 |
w->flags4 |= 5 << WF_TIMEOUT_SHL; |
|
7284
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
559 |
WP(w, indview_d).clicked_line = line + 1; |
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
560 |
WP(w, indview_d).clicked_button = (x < 15 ? 1 : 2); |
7954
57b51c69c072
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
7928
diff
changeset
|
561 |
} else if (IsInsideMM(x, 34, 160)) { |
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6200
diff
changeset
|
562 |
/* clicked the text */ |
7284
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
563 |
WP(w, indview_d).editbox_line = line; |
1004 | 564 |
SetDParam(0, i->production_rate[line] * 8); |
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5380
diff
changeset
|
565 |
ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_CONFIG_GAME_PRODUCTION, 10, 100, w, CS_ALPHANUMERAL); |
1004 | 566 |
} |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1004
diff
changeset
|
567 |
} |
4193
9e82090fef58
(svn r5653) -Cleanup: Do a little cleanup of the industry gui code.
Darkvater
parents:
4192
diff
changeset
|
568 |
} break; |
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
569 |
case IVW_GOTO: |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
570 |
i = GetIndustry(w->window_number); |
1981 | 571 |
ScrollMainWindowToTile(i->xy + TileDiffXY(1, 1)); |
6492
286a52449b54
(svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents:
6491
diff
changeset
|
572 |
} break; |
4193
9e82090fef58
(svn r5653) -Cleanup: Do a little cleanup of the industry gui code.
Darkvater
parents:
4192
diff
changeset
|
573 |
|
1004 | 574 |
} |
0 | 575 |
break; |
1004 | 576 |
case WE_TIMEOUT: |
7284
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
577 |
WP(w, indview_d).clicked_line = 0; |
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
578 |
WP(w, indview_d).clicked_button = 0; |
1004 | 579 |
SetWindowDirty(w); |
580 |
break; |
|
581 |
||
582 |
case WE_ON_EDIT_TEXT: |
|
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4617
diff
changeset
|
583 |
if (e->we.edittext.str[0] != '\0') { |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
584 |
Industry* i = GetIndustry(w->window_number); |
7284
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
585 |
int line = WP(w, indview_d).editbox_line; |
1004 | 586 |
|
7922
a7e266f966d9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7889
diff
changeset
|
587 |
i->production_rate[line] = ClampU(atoi(e->we.edittext.str), 0, 255); |
1004 | 588 |
UpdateIndustryProduction(i); |
589 |
SetWindowDirty(w); |
|
590 |
} |
|
0 | 591 |
} |
592 |
} |
|
593 |
||
1004 | 594 |
static void UpdateIndustryProduction(Industry *i) |
595 |
{ |
|
7645
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7616
diff
changeset
|
596 |
for (byte j = 0; j < lengthof(i->produced_cargo); j++) { |
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7616
diff
changeset
|
597 |
if (i->produced_cargo[j] != CT_INVALID) { |
6819
f986f54e2660
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
6815
diff
changeset
|
598 |
i->last_month_production[j] = 8 * i->production_rate[j]; |
6636
fec086b5c340
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents:
6624
diff
changeset
|
599 |
} |
fec086b5c340
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents:
6624
diff
changeset
|
600 |
} |
1004 | 601 |
} |
602 |
||
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
603 |
/** Widget definition of the view industy gui */ |
0 | 604 |
static const Widget _industry_view_widgets[] = { |
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
605 |
{ WWT_CLOSEBOX, RESIZE_NONE, 9, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // IVW_CLOSEBOX |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
606 |
{ WWT_CAPTION, RESIZE_NONE, 9, 11, 247, 0, 13, STR_4801, STR_018C_WINDOW_TITLE_DRAG_THIS}, // IVW_CAPTION |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
607 |
{ WWT_STICKYBOX, RESIZE_NONE, 9, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON}, // IVW_STICKY |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
608 |
{ WWT_PANEL, RESIZE_NONE, 9, 0, 259, 14, 105, 0x0, STR_NULL}, // IVW_BACKGROUND |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
609 |
{ WWT_INSET, RESIZE_NONE, 9, 2, 257, 16, 103, 0x0, STR_NULL}, // IVW_VIEWPORT |
8779
038e02efbc0a
(svn r12479) -Codechange [FS#1723]: Simplify the method used to resize the industry view window. The window is now shown the correct size so the resize button is also removed.
peter1138
parents:
8759
diff
changeset
|
610 |
{ WWT_PANEL, RESIZE_BOTTOM, 9, 0, 259, 106, 107, 0x0, STR_NULL}, // IVW_INFO |
038e02efbc0a
(svn r12479) -Codechange [FS#1723]: Simplify the method used to resize the industry view window. The window is now shown the correct size so the resize button is also removed.
peter1138
parents:
8759
diff
changeset
|
611 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 9, 0, 129, 108, 119, STR_00E4_LOCATION, STR_482C_CENTER_THE_MAIN_VIEW_ON}, // IVW_GOTO |
038e02efbc0a
(svn r12479) -Codechange [FS#1723]: Simplify the method used to resize the industry view window. The window is now shown the correct size so the resize button is also removed.
peter1138
parents:
8759
diff
changeset
|
612 |
{ WWT_PANEL, RESIZE_TB, 9, 130, 259, 108, 119, 0x0, STR_NULL}, // IVW_SPACER |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
164
diff
changeset
|
613 |
{ WIDGETS_END}, |
0 | 614 |
}; |
615 |
||
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
616 |
/** Window definition of the view industy gui */ |
0 | 617 |
static const WindowDesc _industry_view_desc = { |
8779
038e02efbc0a
(svn r12479) -Codechange [FS#1723]: Simplify the method used to resize the industry view window. The window is now shown the correct size so the resize button is also removed.
peter1138
parents:
8759
diff
changeset
|
618 |
WDP_AUTO, WDP_AUTO, 260, 120, 260, 120, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5609
diff
changeset
|
619 |
WC_INDUSTRY_VIEW, WC_NONE, |
8779
038e02efbc0a
(svn r12479) -Codechange [FS#1723]: Simplify the method used to resize the industry view window. The window is now shown the correct size so the resize button is also removed.
peter1138
parents:
8759
diff
changeset
|
620 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON, |
0 | 621 |
_industry_view_widgets, |
622 |
IndustryViewWndProc |
|
623 |
}; |
|
624 |
||
625 |
void ShowIndustryViewWindow(int industry) |
|
626 |
{ |
|
4171 | 627 |
Window *w = AllocateWindowDescFront(&_industry_view_desc, industry); |
0 | 628 |
|
2989 | 629 |
if (w != NULL) { |
0 | 630 |
w->flags4 |= WF_DISABLE_VP_SCROLL; |
7284
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
631 |
WP(w, indview_d).editbox_line = 0; |
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
632 |
WP(w, indview_d).clicked_line = 0; |
d7903fff2d0b
(svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents:
7283
diff
changeset
|
633 |
WP(w, indview_d).clicked_button = 0; |
8994
fb5e761cf141
(svn r12789) -Codechange: rename AssignWindowViewport to InitializeWindowViewport because the viewport is now part of the window struct. Patch by Alberth.
rubidium
parents:
8965
diff
changeset
|
634 |
InitializeWindowViewport(w, 3, 17, 254, 86, GetIndustry(w->window_number)->xy + TileDiffXY(1, 1), ZOOM_LVL_INDUSTRY); |
0 | 635 |
} |
636 |
} |
|
637 |
||
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
638 |
/** Names of the widgets of the industry directory gui */ |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
639 |
enum IndustryDirectoryWidgets { |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
640 |
IDW_CLOSEBOX = 0, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
641 |
IDW_CAPTION, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
642 |
IDW_STICKY, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
643 |
IDW_SORTBYNAME, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
644 |
IDW_SORTBYTYPE, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
645 |
IDW_SORTBYPROD, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
646 |
IDW_SORTBYTRANSPORT, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
647 |
IDW_SPACER, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
648 |
IDW_INDUSRTY_LIST, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
649 |
IDW_SCROLLBAR, |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
650 |
IDW_RESIZE, |
7278
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
651 |
}; |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
652 |
|
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
653 |
/** Widget definition of the industy directory gui */ |
0 | 654 |
static const Widget _industry_directory_widgets[] = { |
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
655 |
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // IDW_CLOSEBOX |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
656 |
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 495, 0, 13, STR_INDUSTRYDIR_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, // IDW_CAPTION |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
657 |
{ WWT_STICKYBOX, RESIZE_NONE, 13, 496, 507, 0, 13, 0x0, STR_STICKY_BUTTON}, // IDW_STICKY |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
658 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 100, 14, 25, STR_SORT_BY_NAME, STR_SORT_ORDER_TIP}, // IDW_SORTBYNAME |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
659 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 101, 200, 14, 25, STR_SORT_BY_TYPE, STR_SORT_ORDER_TIP}, // IDW_SORTBYTYPE |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
660 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 201, 300, 14, 25, STR_SORT_BY_PRODUCTION, STR_SORT_ORDER_TIP}, // IDW_SORTBYPROD |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
661 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 301, 400, 14, 25, STR_SORT_BY_TRANSPORTED, STR_SORT_ORDER_TIP}, // IDW_SORTBYTRANSPORT |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
662 |
{ WWT_PANEL, RESIZE_NONE, 13, 401, 495, 14, 25, 0x0, STR_NULL}, // IDW_SPACER |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
663 |
{ WWT_PANEL, RESIZE_BOTTOM, 13, 0, 495, 26, 189, 0x0, STR_200A_TOWN_NAMES_CLICK_ON_NAME}, // IDW_INDUSRTY_LIST |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
664 |
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 13, 496, 507, 14, 177, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // IDW_SCROLLBAR |
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
665 |
{ WWT_RESIZEBOX, RESIZE_TB, 13, 496, 507, 178, 189, 0x0, STR_RESIZE_BUTTON}, // IDW_RESIZE |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
164
diff
changeset
|
666 |
{ WIDGETS_END}, |
0 | 667 |
}; |
668 |
||
669 |
static uint _num_industry_sort; |
|
670 |
||
671 |
static char _bufcache[96]; |
|
4277
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4211
diff
changeset
|
672 |
static const Industry* _last_industry; |
0 | 673 |
|
674 |
static byte _industry_sort_order; |
|
675 |
||
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
69
diff
changeset
|
676 |
static int CDECL GeneralIndustrySorter(const void *a, const void *b) |
0 | 677 |
{ |
4277
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4211
diff
changeset
|
678 |
const Industry* i = *(const Industry**)a; |
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4211
diff
changeset
|
679 |
const Industry* j = *(const Industry**)b; |
4282
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
680 |
int r; |
0 | 681 |
|
682 |
switch (_industry_sort_order >> 1) { |
|
4282
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
683 |
default: NOT_REACHED(); |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
684 |
case 0: /* Sort by Name (handled later) */ |
0 | 685 |
r = 0; |
4282
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
686 |
break; |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
687 |
|
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
688 |
case 1: /* Sort by Type */ |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
689 |
r = i->type - j->type; |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
690 |
break; |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
691 |
|
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
692 |
case 2: /* Sort by Production */ |
7645
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7616
diff
changeset
|
693 |
if (i->produced_cargo[0] == CT_INVALID) { |
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7616
diff
changeset
|
694 |
r = (j->produced_cargo[0] == CT_INVALID ? 0 : -1); |
4282
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
695 |
} else { |
7645
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7616
diff
changeset
|
696 |
if (j->produced_cargo[0] == CT_INVALID) { |
4282
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
697 |
r = 1; |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
698 |
} else { |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
699 |
r = |
6819
f986f54e2660
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
6815
diff
changeset
|
700 |
(i->last_month_production[0] + i->last_month_production[1]) - |
f986f54e2660
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
6815
diff
changeset
|
701 |
(j->last_month_production[0] + j->last_month_production[1]); |
4282
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
702 |
} |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
703 |
} |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
704 |
break; |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
705 |
|
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
706 |
case 3: /* Sort by transported fraction */ |
7645
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7616
diff
changeset
|
707 |
if (i->produced_cargo[0] == CT_INVALID) { |
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7616
diff
changeset
|
708 |
r = (j->produced_cargo[0] == CT_INVALID ? 0 : -1); |
4282
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
709 |
} else { |
7645
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7616
diff
changeset
|
710 |
if (j->produced_cargo[0] == CT_INVALID) { |
4282
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
711 |
r = 1; |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
712 |
} else { |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
713 |
int pi; |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
714 |
int pj; |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
715 |
|
6819
f986f54e2660
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
6815
diff
changeset
|
716 |
pi = i->last_month_pct_transported[0] * 100 >> 8; |
7645
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7616
diff
changeset
|
717 |
if (i->produced_cargo[1] != CT_INVALID) { |
6819
f986f54e2660
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
6815
diff
changeset
|
718 |
int p = i->last_month_pct_transported[1] * 100 >> 8; |
4282
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
719 |
if (p < pi) pi = p; |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
720 |
} |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
721 |
|
6819
f986f54e2660
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
6815
diff
changeset
|
722 |
pj = j->last_month_pct_transported[0] * 100 >> 8; |
7645
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7616
diff
changeset
|
723 |
if (j->produced_cargo[1] != CT_INVALID) { |
6819
f986f54e2660
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
6815
diff
changeset
|
724 |
int p = j->last_month_pct_transported[1] * 100 >> 8; |
4282
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
725 |
if (p < pj) pj = p; |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
726 |
} |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
727 |
|
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
728 |
r = pi - pj; |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
729 |
} |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
730 |
} |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
731 |
break; |
0 | 732 |
} |
733 |
||
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6200
diff
changeset
|
734 |
/* default to string sorting if they are otherwise equal */ |
0 | 735 |
if (r == 0) { |
4282
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
736 |
char buf1[96]; |
9394aef5b65b
(svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents:
4277
diff
changeset
|
737 |
|
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
738 |
SetDParam(0, i->town->index); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4896
diff
changeset
|
739 |
GetString(buf1, STR_TOWN, lastof(buf1)); |
0 | 740 |
|
4277
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4211
diff
changeset
|
741 |
if (j != _last_industry) { |
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4211
diff
changeset
|
742 |
_last_industry = j; |
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
743 |
SetDParam(0, j->town->index); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4896
diff
changeset
|
744 |
GetString(_bufcache, STR_TOWN, lastof(_bufcache)); |
0 | 745 |
} |
746 |
r = strcmp(buf1, _bufcache); |
|
747 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
748 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
749 |
if (_industry_sort_order & 1) r = -r; |
0 | 750 |
return r; |
751 |
} |
|
752 |
||
6200
10efd7fb90d4
(svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents:
6091
diff
changeset
|
753 |
/** |
10efd7fb90d4
(svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents:
6091
diff
changeset
|
754 |
* Makes a sorted industry list. |
10efd7fb90d4
(svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents:
6091
diff
changeset
|
755 |
* When there are no industries, the list has to be made. This so when one |
10efd7fb90d4
(svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents:
6091
diff
changeset
|
756 |
* starts a new game without industries after playing a game with industries |
10efd7fb90d4
(svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents:
6091
diff
changeset
|
757 |
* the list is not populated with invalid industries from the previous game. |
10efd7fb90d4
(svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents:
6091
diff
changeset
|
758 |
*/ |
6247 | 759 |
static void MakeSortedIndustryList() |
0 | 760 |
{ |
4277
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4211
diff
changeset
|
761 |
const Industry* i; |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
762 |
int n = 0; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
763 |
|
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
764 |
/* Create array for sorting */ |
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5601
diff
changeset
|
765 |
_industry_sort = ReallocT(_industry_sort, GetMaxIndustryIndex() + 1); |
0 | 766 |
|
6200
10efd7fb90d4
(svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents:
6091
diff
changeset
|
767 |
/* Don't attempt a sort if there are no industries */ |
10efd7fb90d4
(svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents:
6091
diff
changeset
|
768 |
if (GetNumIndustries() != 0) { |
10efd7fb90d4
(svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents:
6091
diff
changeset
|
769 |
FOR_ALL_INDUSTRIES(i) _industry_sort[n++] = i; |
10efd7fb90d4
(svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents:
6091
diff
changeset
|
770 |
qsort((void*)_industry_sort, n, sizeof(_industry_sort[0]), GeneralIndustrySorter); |
10efd7fb90d4
(svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents:
6091
diff
changeset
|
771 |
} |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
772 |
|
0 | 773 |
_num_industry_sort = n; |
4277
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4211
diff
changeset
|
774 |
_last_industry = NULL; // used for "cache" |
0 | 775 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5247
diff
changeset
|
776 |
DEBUG(misc, 3, "Resorting industries list"); |
0 | 777 |
} |
778 |
||
779 |
||
780 |
static void IndustryDirectoryWndProc(Window *w, WindowEvent *e) |
|
781 |
{ |
|
2951 | 782 |
switch (e->event) { |
0 | 783 |
case WE_PAINT: { |
784 |
if (_industry_sort_dirty) { |
|
785 |
_industry_sort_dirty = false; |
|
786 |
MakeSortedIndustryList(); |
|
787 |
} |
|
788 |
||
1666
46dc094142b1
(svn r2170) -fix: [1179457] the industry list can now no longer scroll down then the end of the list is reached (Hackykid)
bjarni
parents:
1388
diff
changeset
|
789 |
SetVScrollCount(w, _num_industry_sort); |
0 | 790 |
|
791 |
DrawWindowWidgets(w); |
|
8349
e61105cb1f87
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138
parents:
8270
diff
changeset
|
792 |
DrawSortButtonState(w, IDW_SORTBYNAME + (_industry_sort_order >> 1), _industry_sort_order & 1 ? SBS_DOWN : SBS_UP); |
0 | 793 |
|
8349
e61105cb1f87
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138
parents:
8270
diff
changeset
|
794 |
uint p = w->vscroll.pos; |
e61105cb1f87
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138
parents:
8270
diff
changeset
|
795 |
int n = 0; |
0 | 796 |
|
797 |
while (p < _num_industry_sort) { |
|
4277
345e1bd9525a
(svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents:
4211
diff
changeset
|
798 |
const Industry* i = _industry_sort[p]; |
2989 | 799 |
|
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
800 |
SetDParam(0, i->index); |
7645
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7616
diff
changeset
|
801 |
if (i->produced_cargo[0] != CT_INVALID) { |
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7616
diff
changeset
|
802 |
SetDParam(1, i->produced_cargo[0]); |
6819
f986f54e2660
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
6815
diff
changeset
|
803 |
SetDParam(2, i->last_month_production[0]); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
804 |
|
7645
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7616
diff
changeset
|
805 |
if (i->produced_cargo[1] != CT_INVALID) { |
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7616
diff
changeset
|
806 |
SetDParam(3, i->produced_cargo[1]); |
6819
f986f54e2660
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
6815
diff
changeset
|
807 |
SetDParam(4, i->last_month_production[1]); |
f986f54e2660
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
6815
diff
changeset
|
808 |
SetDParam(5, i->last_month_pct_transported[0] * 100 >> 8); |
f986f54e2660
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
6815
diff
changeset
|
809 |
SetDParam(6, i->last_month_pct_transported[1] * 100 >> 8); |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7822
diff
changeset
|
810 |
DrawString(4, 28 + n * 10, STR_INDUSTRYDIR_ITEM_TWO, TC_FROMSTRING); |
0 | 811 |
} else { |
6819
f986f54e2660
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
6815
diff
changeset
|
812 |
SetDParam(3, i->last_month_pct_transported[0] * 100 >> 8); |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7822
diff
changeset
|
813 |
DrawString(4, 28 + n * 10, STR_INDUSTRYDIR_ITEM, TC_FROMSTRING); |
0 | 814 |
} |
815 |
} else { |
|
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7822
diff
changeset
|
816 |
DrawString(4, 28 + n * 10, STR_INDUSTRYDIR_ITEM_NOPROD, TC_FROMSTRING); |
0 | 817 |
} |
818 |
p++; |
|
2951 | 819 |
if (++n == w->vscroll.cap) break; |
0 | 820 |
} |
821 |
} break; |
|
822 |
||
823 |
case WE_CLICK: |
|
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4617
diff
changeset
|
824 |
switch (e->we.click.widget) { |
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
825 |
case IDW_SORTBYNAME: { |
7278
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
826 |
_industry_sort_order = _industry_sort_order == 0 ? 1 : 0; |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
827 |
_industry_sort_dirty = true; |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
828 |
SetWindowDirty(w); |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
829 |
} break; |
0 | 830 |
|
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
831 |
case IDW_SORTBYTYPE: { |
7278
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
832 |
_industry_sort_order = _industry_sort_order == 2 ? 3 : 2; |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
833 |
_industry_sort_dirty = true; |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
834 |
SetWindowDirty(w); |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
835 |
} break; |
0 | 836 |
|
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
837 |
case IDW_SORTBYPROD: { |
7278
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
838 |
_industry_sort_order = _industry_sort_order == 4 ? 5 : 4; |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
839 |
_industry_sort_dirty = true; |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
840 |
SetWindowDirty(w); |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
841 |
} break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
842 |
|
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
843 |
case IDW_SORTBYTRANSPORT: { |
7278
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
844 |
_industry_sort_order = _industry_sort_order == 6 ? 7 : 6; |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
845 |
_industry_sort_dirty = true; |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
846 |
SetWindowDirty(w); |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
847 |
} break; |
0 | 848 |
|
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
849 |
case IDW_INDUSRTY_LIST: { |
7278
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
850 |
int y = (e->we.click.pt.y - 28) / 10; |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
851 |
uint16 p; |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
852 |
|
7954
57b51c69c072
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
7928
diff
changeset
|
853 |
if (!IsInsideMM(y, 0, w->vscroll.cap)) return; |
7278
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
854 |
p = y + w->vscroll.pos; |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
855 |
if (p < _num_industry_sort) { |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
856 |
ScrollMainWindowToTile(_industry_sort[p]->xy); |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
857 |
} |
c5b4203c6e1c
(svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents:
7271
diff
changeset
|
858 |
} break; |
0 | 859 |
} |
860 |
break; |
|
861 |
||
862 |
case WE_4: |
|
863 |
SetWindowDirty(w); |
|
864 |
break; |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
830
diff
changeset
|
865 |
|
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
830
diff
changeset
|
866 |
case WE_RESIZE: |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4617
diff
changeset
|
867 |
w->vscroll.cap += e->we.sizing.diff.y / 10; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
830
diff
changeset
|
868 |
break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
869 |
} |
0 | 870 |
} |
871 |
||
8047
50d438fdf470
(svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents:
8040
diff
changeset
|
872 |
/** Window definition of the industy directory gui */ |
0 | 873 |
static const WindowDesc _industry_directory_desc = { |
7341
02515d0d4ced
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7319
diff
changeset
|
874 |
WDP_AUTO, WDP_AUTO, 508, 190, 508, 190, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5609
diff
changeset
|
875 |
WC_INDUSTRY_DIRECTORY, WC_NONE, |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
830
diff
changeset
|
876 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
0 | 877 |
_industry_directory_widgets, |
878 |
IndustryDirectoryWndProc |
|
879 |
}; |
|
880 |
||
6247 | 881 |
void ShowIndustryDirectory() |
0 | 882 |
{ |
4171 | 883 |
Window *w = AllocateWindowDescFront(&_industry_directory_desc, 0); |
0 | 884 |
|
2989 | 885 |
if (w != NULL) { |
0 | 886 |
w->vscroll.cap = 16; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
830
diff
changeset
|
887 |
w->resize.height = w->height - 6 * 10; // minimum 10 items |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
830
diff
changeset
|
888 |
w->resize.step_height = 10; |
0 | 889 |
SetWindowDirty(w); |
890 |
} |
|
891 |
} |