author | rubidium |
Sat, 22 Dec 2007 23:30:28 +0000 | |
changeset 8121 | 3bc6351e7369 |
parent 8116 | 8da76dcb3287 |
child 8131 | 160939e24ed3 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6328
diff
changeset
|
3 |
/** @file subsidy_gui.cpp */ |
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6328
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1093
diff
changeset
|
6 |
#include "openttd.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
193
diff
changeset
|
7 |
#include "table/strings.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
8 |
#include "functions.h" |
0 | 9 |
#include "station.h" |
10 |
#include "industry.h" |
|
11 |
#include "town.h" |
|
12 |
#include "player.h" |
|
8116
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8114
diff
changeset
|
13 |
#include "economy_func.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
1962
diff
changeset
|
14 |
#include "variables.h" |
4261
28670f743746
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4171
diff
changeset
|
15 |
#include "date.h" |
6328
1a886da998fa
(svn r9300) -Codechange: Use cargo's town effect property in the subsidy gui
peter1138
parents:
6247
diff
changeset
|
16 |
#include "cargotype.h" |
8106
e6790dd9e750
(svn r11667) -Codechange: split window.h into a header that defines some 'global' window related types, on that defined 'global' window functions and one that defines functions and types only used by *_gui.cpps.
rubidium
parents:
7956
diff
changeset
|
17 |
#include "window_gui.h" |
8114
dd6d21dc99c1
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8106
diff
changeset
|
18 |
#include "strings_func.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
59a0073914d8
(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
59a0073914d8
(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 |
||
6328
1a886da998fa
(svn r9300) -Codechange: Use cargo's town effect property in the subsidy gui
peter1138
parents:
6247
diff
changeset
|
56 |
TownEffect te = GetCargo(s->cargo_type)->town_effect; |
1a886da998fa
(svn r9300) -Codechange: Use cargo's town effect property in the subsidy gui
peter1138
parents:
6247
diff
changeset
|
57 |
|
0 | 58 |
/* determine from coordinate for subsidy and try to scroll to it */ |
59 |
offs = s->from; |
|
60 |
if (s->age >= 12) { |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
61 |
xy = GetStation(offs)->xy; |
6328
1a886da998fa
(svn r9300) -Codechange: Use cargo's town effect property in the subsidy gui
peter1138
parents:
6247
diff
changeset
|
62 |
} else if (te == TE_PASSENGERS || te == TE_MAIL) { |
919
544f374ee392
(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
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
65 |
xy = GetIndustry(offs)->xy; |
6328
1a886da998fa
(svn r9300) -Codechange: Use cargo's town effect property in the subsidy gui
peter1138
parents:
6247
diff
changeset
|
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
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
72 |
xy = GetStation(offs)->xy; |
6328
1a886da998fa
(svn r9300) -Codechange: Use cargo's town effect property in the subsidy gui
peter1138
parents:
6247
diff
changeset
|
73 |
} else if (te == TE_PASSENGERS || te == TE_MAIL || te == TE_GOODS || te == TE_FOOD) { |
919
544f374ee392
(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
544f374ee392
(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 |
||
4171 | 82 |
static void DrawSubsidiesWindow(const Window *w) |
0 | 83 |
{ |
84 |
YearMonthDay ymd; |
|
4171 | 85 |
const Subsidy *s; |
2639 | 86 |
uint num; |
87 |
int x; |
|
88 |
int y; |
|
0 | 89 |
|
90 |
DrawWindowWidgets(w); |
|
91 |
||
4288
393de75451b1
(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 |
|
7956
b6b1b5d53252
(svn r11512) -Change: make the subsidy window able to resize to something smaller than 640x127 (especially the 640 part) when the screen is really too small.
rubidium
parents:
7824
diff
changeset
|
94 |
int width = w->width - 2; |
0 | 95 |
y = 15; |
96 |
x = 1; |
|
7956
b6b1b5d53252
(svn r11512) -Change: make the subsidy window able to resize to something smaller than 640x127 (especially the 640 part) when the screen is really too small.
rubidium
parents:
7824
diff
changeset
|
97 |
DrawStringTruncated(x, y, STR_2026_SUBSIDIES_ON_OFFER_FOR, TC_FROMSTRING, width); |
0 | 98 |
y += 10; |
99 |
num = 0; |
|
100 |
||
2639 | 101 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
2469
59a0073914d8
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2186
diff
changeset
|
102 |
if (s->cargo_type != CT_INVALID && s->age < 12) { |
2639 | 103 |
int x2; |
104 |
||
0 | 105 |
SetupSubsidyDecodeParam(s, 1); |
7956
b6b1b5d53252
(svn r11512) -Change: make the subsidy window able to resize to something smaller than 640x127 (especially the 640 part) when the screen is really too small.
rubidium
parents:
7824
diff
changeset
|
106 |
x2 = DrawStringTruncated(x + 2, y, STR_2027_FROM_TO, TC_FROMSTRING, width); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
107 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
108 |
SetDParam(0, _date - ymd.day + 384 - s->age * 32); |
7956
b6b1b5d53252
(svn r11512) -Change: make the subsidy window able to resize to something smaller than 640x127 (especially the 640 part) when the screen is really too small.
rubidium
parents:
7824
diff
changeset
|
109 |
DrawStringTruncated(x2, y, STR_2028_BY, TC_FROMSTRING, width - x2); |
0 | 110 |
y += 10; |
111 |
num++; |
|
112 |
} |
|
113 |
} |
|
114 |
||
115 |
if (num == 0) { |
|
7956
b6b1b5d53252
(svn r11512) -Change: make the subsidy window able to resize to something smaller than 640x127 (especially the 640 part) when the screen is really too small.
rubidium
parents:
7824
diff
changeset
|
116 |
DrawStringTruncated(x + 2, y, STR_202A_NONE, TC_FROMSTRING, width - 2); |
0 | 117 |
y += 10; |
118 |
} |
|
119 |
||
7956
b6b1b5d53252
(svn r11512) -Change: make the subsidy window able to resize to something smaller than 640x127 (especially the 640 part) when the screen is really too small.
rubidium
parents:
7824
diff
changeset
|
120 |
DrawStringTruncated(x, y + 1, STR_202B_SERVICES_ALREADY_SUBSIDISED, TC_FROMSTRING, width); |
0 | 121 |
y += 10; |
122 |
num = 0; |
|
123 |
||
2639 | 124 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
2469
59a0073914d8
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2186
diff
changeset
|
125 |
if (s->cargo_type != CT_INVALID && s->age >= 12) { |
2639 | 126 |
int xt; |
2630 | 127 |
|
0 | 128 |
SetupSubsidyDecodeParam(s, 1); |
129 |
||
7058
8105bb13ce3d
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
6420
diff
changeset
|
130 |
PlayerID player = GetStation(s->to)->owner; |
8105bb13ce3d
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
6420
diff
changeset
|
131 |
SetDParam(3, player); |
0 | 132 |
|
7956
b6b1b5d53252
(svn r11512) -Change: make the subsidy window able to resize to something smaller than 640x127 (especially the 640 part) when the screen is really too small.
rubidium
parents:
7824
diff
changeset
|
133 |
xt = DrawStringTruncated(x + 2, y, STR_202C_FROM_TO, TC_FROMSTRING, width - 2); |
0 | 134 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
135 |
SetDParam(0, _date - ymd.day + 768 - s->age * 32); |
7956
b6b1b5d53252
(svn r11512) -Change: make the subsidy window able to resize to something smaller than 640x127 (especially the 640 part) when the screen is really too small.
rubidium
parents:
7824
diff
changeset
|
136 |
DrawStringTruncated(xt, y, STR_202D_UNTIL, TC_FROMSTRING, width - xt); |
0 | 137 |
y += 10; |
138 |
num++; |
|
139 |
} |
|
140 |
} |
|
141 |
||
7956
b6b1b5d53252
(svn r11512) -Change: make the subsidy window able to resize to something smaller than 640x127 (especially the 640 part) when the screen is really too small.
rubidium
parents:
7824
diff
changeset
|
142 |
if (num == 0) DrawStringTruncated(x + 2, y, STR_202A_NONE, TC_FROMSTRING, width - 2); |
0 | 143 |
} |
144 |
||
145 |
static void SubsidiesListWndProc(Window *w, WindowEvent *e) |
|
146 |
{ |
|
2639 | 147 |
switch (e->event) { |
148 |
case WE_PAINT: DrawSubsidiesWindow(w); break; |
|
149 |
||
150 |
case WE_CLICK: |
|
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4288
diff
changeset
|
151 |
switch (e->we.click.widget) { |
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4288
diff
changeset
|
152 |
case 3: |
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4288
diff
changeset
|
153 |
HandleSubsidyClick(e->we.click.pt.y - 25); |
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4288
diff
changeset
|
154 |
break; |
2639 | 155 |
} |
156 |
break; |
|
0 | 157 |
} |
158 |
} |
|
159 |
||
160 |
static const Widget _subsidies_list_widgets[] = { |
|
7956
b6b1b5d53252
(svn r11512) -Change: make the subsidy window able to resize to something smaller than 640x127 (especially the 640 part) when the screen is really too small.
rubidium
parents:
7824
diff
changeset
|
161 |
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
b6b1b5d53252
(svn r11512) -Change: make the subsidy window able to resize to something smaller than 640x127 (especially the 640 part) when the screen is really too small.
rubidium
parents:
7824
diff
changeset
|
162 |
{ WWT_CAPTION, RESIZE_RIGHT, 13, 11, 307, 0, 13, STR_2025_SUBSIDIES, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
b6b1b5d53252
(svn r11512) -Change: make the subsidy window able to resize to something smaller than 640x127 (especially the 640 part) when the screen is really too small.
rubidium
parents:
7824
diff
changeset
|
163 |
{ WWT_STICKYBOX, RESIZE_LR, 13, 308, 319, 0, 13, STR_NULL, STR_STICKY_BUTTON}, |
b6b1b5d53252
(svn r11512) -Change: make the subsidy window able to resize to something smaller than 640x127 (especially the 640 part) when the screen is really too small.
rubidium
parents:
7824
diff
changeset
|
164 |
{ WWT_PANEL, RESIZE_RIGHT, 13, 0, 319, 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
|
165 |
{ WIDGETS_END}, |
0 | 166 |
}; |
167 |
||
168 |
static const WindowDesc _subsidies_list_desc = { |
|
7956
b6b1b5d53252
(svn r11512) -Change: make the subsidy window able to resize to something smaller than 640x127 (especially the 640 part) when the screen is really too small.
rubidium
parents:
7824
diff
changeset
|
169 |
WDP_AUTO, WDP_AUTO, 320, 127, 630, 127, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5584
diff
changeset
|
170 |
WC_SUBSIDIES_LIST, WC_NONE, |
2857
33c1f9df1635
(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
|
171 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, |
0 | 172 |
_subsidies_list_widgets, |
173 |
SubsidiesListWndProc |
|
174 |
}; |
|
175 |
||
176 |
||
6247 | 177 |
void ShowSubsidiesList() |
0 | 178 |
{ |
179 |
AllocateWindowDescFront(&_subsidies_list_desc, 0); |
|
180 |
} |