author | KUDr |
Sat, 21 Apr 2007 08:23:57 +0000 | |
branch | cpp_gui |
changeset 6308 | 646711c5feaa |
parent 6307 | f40e88cff863 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6307 | 3 |
/** @file subsidy_gui.cpp */ |
4 |
||
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1093
diff
changeset
|
6 |
#include "openttd.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
193
diff
changeset
|
7 |
#include "table/strings.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
8 |
#include "functions.h" |
0 | 9 |
#include "window.h" |
10 |
#include "station.h" |
|
11 |
#include "industry.h" |
|
12 |
#include "town.h" |
|
13 |
#include "player.h" |
|
14 |
#include "gfx.h" |
|
15 |
#include "economy.h" |
|
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
1962
diff
changeset
|
16 |
#include "variables.h" |
4261
2ec8f5a9747b
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4171
diff
changeset
|
17 |
#include "date.h" |
6303 | 18 |
#include "cargotype.h" |
0 | 19 |
|
20 |
static void HandleSubsidyClick(int y) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
21 |
{ |
4171 | 22 |
const Subsidy *s; |
2639 | 23 |
uint num; |
24 |
int offs; |
|
0 | 25 |
TileIndex xy; |
26 |
||
2639 | 27 |
if (y < 0) return; |
0 | 28 |
|
29 |
num = 0; |
|
2639 | 30 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2186
diff
changeset
|
31 |
if (s->cargo_type != CT_INVALID && s->age < 12) { |
0 | 32 |
y -= 10; |
33 |
if (y < 0) goto handle_click; |
|
34 |
num++; |
|
35 |
} |
|
36 |
} |
|
37 |
||
38 |
if (num == 0) { |
|
39 |
y -= 10; |
|
40 |
if (y < 0) return; |
|
41 |
} |
|
42 |
||
43 |
y -= 11; |
|
44 |
if (y < 0) return; |
|
45 |
||
2639 | 46 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2186
diff
changeset
|
47 |
if (s->cargo_type != CT_INVALID && s->age >= 12) { |
0 | 48 |
y -= 10; |
49 |
if (y < 0) goto handle_click; |
|
50 |
} |
|
51 |
} |
|
52 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
53 |
|
0 | 54 |
handle_click: |
55 |
||
6303 | 56 |
TownEffect te = GetCargo(s->cargo_type)->town_effect; |
57 |
||
0 | 58 |
/* determine from coordinate for subsidy and try to scroll to it */ |
59 |
offs = s->from; |
|
60 |
if (s->age >= 12) { |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
61 |
xy = GetStation(offs)->xy; |
6303 | 62 |
} else if (te == TE_PASSENGERS || te == TE_MAIL) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
63 |
xy = GetTown(offs)->xy; |
0 | 64 |
} else { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
65 |
xy = GetIndustry(offs)->xy; |
6303 | 66 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
67 |
|
0 | 68 |
if (!ScrollMainWindowToTile(xy)) { |
69 |
/* otherwise determine to coordinate for subsidy and scroll to it */ |
|
70 |
offs = s->to; |
|
71 |
if (s->age >= 12) { |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
72 |
xy = GetStation(offs)->xy; |
6303 | 73 |
} else if (te == TE_PASSENGERS || te == TE_MAIL || te == TE_GOODS || te == TE_FOOD) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
74 |
xy = GetTown(offs)->xy; |
0 | 75 |
} else { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
76 |
xy = GetIndustry(offs)->xy; |
0 | 77 |
} |
78 |
ScrollMainWindowToTile(xy); |
|
79 |
} |
|
80 |
} |
|
81 |
||
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6241
diff
changeset
|
82 |
static void DrawSubsidiesWindow(const BaseWindow *w) |
0 | 83 |
{ |
84 |
YearMonthDay ymd; |
|
4171 | 85 |
const Subsidy *s; |
2639 | 86 |
uint num; |
87 |
int x; |
|
88 |
int y; |
|
0 | 89 |
|
6241
6a7a41b0cd32
(svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents:
6144
diff
changeset
|
90 |
w->DrawWidgets(); |
0 | 91 |
|
4288
60398d0e64ee
(svn r5918) -Cleanup: rename ConvertDayToYMD/ConvertYMDToDay as they really convert a Date to/from a YearMonthDay.
rubidium
parents:
4261
diff
changeset
|
92 |
ConvertDateToYMD(_date, &ymd); |
0 | 93 |
|
94 |
y = 15; |
|
95 |
x = 1; |
|
96 |
DrawString(x, y, STR_2026_SUBSIDIES_ON_OFFER_FOR, 0); |
|
97 |
y += 10; |
|
98 |
num = 0; |
|
99 |
||
2639 | 100 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2186
diff
changeset
|
101 |
if (s->cargo_type != CT_INVALID && s->age < 12) { |
2639 | 102 |
int x2; |
103 |
||
0 | 104 |
SetupSubsidyDecodeParam(s, 1); |
2639 | 105 |
x2 = DrawString(x + 2, y, STR_2027_FROM_TO, 0); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
106 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
107 |
SetDParam(0, _date - ymd.day + 384 - s->age * 32); |
0 | 108 |
DrawString(x2, y, STR_2028_BY, 0); |
109 |
y += 10; |
|
110 |
num++; |
|
111 |
} |
|
112 |
} |
|
113 |
||
114 |
if (num == 0) { |
|
2639 | 115 |
DrawString(x + 2, y, STR_202A_NONE, 0); |
0 | 116 |
y += 10; |
117 |
} |
|
118 |
||
2639 | 119 |
DrawString(x, y + 1, STR_202B_SERVICES_ALREADY_SUBSIDISED, 0); |
0 | 120 |
y += 10; |
121 |
num = 0; |
|
122 |
||
2639 | 123 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2186
diff
changeset
|
124 |
if (s->cargo_type != CT_INVALID && s->age >= 12) { |
4171 | 125 |
const Player *p; |
2639 | 126 |
int xt; |
2630 | 127 |
|
0 | 128 |
SetupSubsidyDecodeParam(s, 1); |
129 |
||
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1891
diff
changeset
|
130 |
p = GetPlayer(GetStation(s->to)->owner); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
131 |
SetDParam(3, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
132 |
SetDParam(4, p->name_2); |
0 | 133 |
|
2639 | 134 |
xt = DrawString(x + 2, y, STR_202C_FROM_TO, 0); |
0 | 135 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
136 |
SetDParam(0, _date - ymd.day + 768 - s->age * 32); |
0 | 137 |
DrawString(xt, y, STR_202D_UNTIL, 0); |
138 |
y += 10; |
|
139 |
num++; |
|
140 |
} |
|
141 |
} |
|
142 |
||
2639 | 143 |
if (num == 0) DrawString(x + 2, y, STR_202A_NONE, 0); |
0 | 144 |
} |
145 |
||
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6241
diff
changeset
|
146 |
static void SubsidiesListWndProc(BaseWindow *w, WindowEvent *e) |
0 | 147 |
{ |
2639 | 148 |
switch (e->event) { |
149 |
case WE_PAINT: DrawSubsidiesWindow(w); break; |
|
150 |
||
151 |
case WE_CLICK: |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4288
diff
changeset
|
152 |
switch (e->we.click.widget) { |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4288
diff
changeset
|
153 |
case 3: |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4288
diff
changeset
|
154 |
HandleSubsidyClick(e->we.click.pt.y - 25); |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4288
diff
changeset
|
155 |
break; |
2639 | 156 |
} |
157 |
break; |
|
0 | 158 |
} |
159 |
} |
|
160 |
||
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6241
diff
changeset
|
161 |
static const OldWidget _subsidies_list_widgets[] = { |
2857
1877bc2188fc
(svn r3405) - Feature: Make subsidies window pinnable. Don't ask me why this wasn't included in the first round of pinning.
Darkvater
parents:
2791
diff
changeset
|
162 |
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
1877bc2188fc
(svn r3405) - Feature: Make subsidies window pinnable. Don't ask me why this wasn't included in the first round of pinning.
Darkvater
parents:
2791
diff
changeset
|
163 |
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 617, 0, 13, STR_2025_SUBSIDIES, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
1877bc2188fc
(svn r3405) - Feature: Make subsidies window pinnable. Don't ask me why this wasn't included in the first round of pinning.
Darkvater
parents:
2791
diff
changeset
|
164 |
{ WWT_STICKYBOX, RESIZE_NONE, 13, 618, 629, 0, 13, STR_NULL, STR_STICKY_BUTTON}, |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4634
diff
changeset
|
165 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 629, 14, 126, 0x0, STR_01FD_CLICK_ON_SERVICE_TO_CENTER}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
0
diff
changeset
|
166 |
{ WIDGETS_END}, |
0 | 167 |
}; |
168 |
||
169 |
static const WindowDesc _subsidies_list_desc = { |
|
5070
0bbf5264bfb7
(svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents:
4938
diff
changeset
|
170 |
WDP_AUTO, WDP_AUTO, 630, 127, |
6144
5a0ffbf27ced
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5835
diff
changeset
|
171 |
WC_SUBSIDIES_LIST, WC_NONE, |
2857
1877bc2188fc
(svn r3405) - Feature: Make subsidies window pinnable. Don't ask me why this wasn't included in the first round of pinning.
Darkvater
parents:
2791
diff
changeset
|
172 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, |
0 | 173 |
_subsidies_list_widgets, |
174 |
SubsidiesListWndProc |
|
175 |
}; |
|
176 |
||
177 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6258
diff
changeset
|
178 |
void ShowSubsidiesList() |
0 | 179 |
{ |
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6241
diff
changeset
|
180 |
BaseWindow::AllocateFront(&_subsidies_list_desc, 0); |
0 | 181 |
} |