author | belugas |
Wed, 26 Jul 2006 03:33:12 +0000 | |
changeset 4171 | 3fadda3afe70 |
parent 2857 | 1877bc2188fc |
child 4261 | 2ec8f5a9747b |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1093
diff
changeset
|
4 |
#include "openttd.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
193
diff
changeset
|
5 |
#include "table/strings.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
6 |
#include "functions.h" |
0 | 7 |
#include "window.h" |
8 |
#include "station.h" |
|
9 |
#include "industry.h" |
|
10 |
#include "town.h" |
|
11 |
#include "player.h" |
|
12 |
#include "gfx.h" |
|
13 |
#include "economy.h" |
|
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
1962
diff
changeset
|
14 |
#include "variables.h" |
0 | 15 |
|
16 |
static void HandleSubsidyClick(int y) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
17 |
{ |
4171 | 18 |
const Subsidy *s; |
2639 | 19 |
uint num; |
20 |
int offs; |
|
0 | 21 |
TileIndex xy; |
22 |
||
2639 | 23 |
if (y < 0) return; |
0 | 24 |
|
25 |
num = 0; |
|
2639 | 26 |
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
|
27 |
if (s->cargo_type != CT_INVALID && s->age < 12) { |
0 | 28 |
y -= 10; |
29 |
if (y < 0) goto handle_click; |
|
30 |
num++; |
|
31 |
} |
|
32 |
} |
|
33 |
||
34 |
if (num == 0) { |
|
35 |
y -= 10; |
|
36 |
if (y < 0) return; |
|
37 |
} |
|
38 |
||
39 |
y -= 11; |
|
40 |
if (y < 0) return; |
|
41 |
||
2639 | 42 |
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
|
43 |
if (s->cargo_type != CT_INVALID && s->age >= 12) { |
0 | 44 |
y -= 10; |
45 |
if (y < 0) goto handle_click; |
|
46 |
} |
|
47 |
} |
|
48 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
49 |
|
0 | 50 |
handle_click: |
51 |
||
52 |
/* determine from coordinate for subsidy and try to scroll to it */ |
|
53 |
offs = s->from; |
|
54 |
if (s->age >= 12) { |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
55 |
xy = GetStation(offs)->xy; |
0 | 56 |
} else if (s->cargo_type == CT_PASSENGERS || s->cargo_type == CT_MAIL) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
57 |
xy = GetTown(offs)->xy; |
0 | 58 |
} else { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
59 |
xy = GetIndustry(offs)->xy; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
60 |
|
0 | 61 |
} |
62 |
if (!ScrollMainWindowToTile(xy)) { |
|
63 |
/* otherwise determine to coordinate for subsidy and scroll to it */ |
|
64 |
offs = s->to; |
|
65 |
if (s->age >= 12) { |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
66 |
xy = GetStation(offs)->xy; |
0 | 67 |
} else if (s->cargo_type == CT_PASSENGERS || s->cargo_type == CT_MAIL || s->cargo_type == CT_GOODS || s->cargo_type == CT_FOOD) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
68 |
xy = GetTown(offs)->xy; |
0 | 69 |
} else { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
70 |
xy = GetIndustry(offs)->xy; |
0 | 71 |
} |
72 |
ScrollMainWindowToTile(xy); |
|
73 |
} |
|
74 |
} |
|
75 |
||
4171 | 76 |
static void DrawSubsidiesWindow(const Window *w) |
0 | 77 |
{ |
78 |
YearMonthDay ymd; |
|
4171 | 79 |
const Subsidy *s; |
2639 | 80 |
uint num; |
81 |
int x; |
|
82 |
int y; |
|
0 | 83 |
|
84 |
DrawWindowWidgets(w); |
|
85 |
||
86 |
ConvertDayToYMD(&ymd, _date); |
|
87 |
||
88 |
y = 15; |
|
89 |
x = 1; |
|
90 |
DrawString(x, y, STR_2026_SUBSIDIES_ON_OFFER_FOR, 0); |
|
91 |
y += 10; |
|
92 |
num = 0; |
|
93 |
||
2639 | 94 |
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
|
95 |
if (s->cargo_type != CT_INVALID && s->age < 12) { |
2639 | 96 |
int x2; |
97 |
||
0 | 98 |
SetupSubsidyDecodeParam(s, 1); |
2639 | 99 |
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
|
100 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
101 |
SetDParam(0, _date - ymd.day + 384 - s->age * 32); |
0 | 102 |
DrawString(x2, y, STR_2028_BY, 0); |
103 |
y += 10; |
|
104 |
num++; |
|
105 |
} |
|
106 |
} |
|
107 |
||
108 |
if (num == 0) { |
|
2639 | 109 |
DrawString(x + 2, y, STR_202A_NONE, 0); |
0 | 110 |
y += 10; |
111 |
} |
|
112 |
||
2639 | 113 |
DrawString(x, y + 1, STR_202B_SERVICES_ALREADY_SUBSIDISED, 0); |
0 | 114 |
y += 10; |
115 |
num = 0; |
|
116 |
||
2639 | 117 |
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
|
118 |
if (s->cargo_type != CT_INVALID && s->age >= 12) { |
4171 | 119 |
const Player *p; |
2639 | 120 |
int xt; |
2630 | 121 |
|
0 | 122 |
SetupSubsidyDecodeParam(s, 1); |
123 |
||
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1891
diff
changeset
|
124 |
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
|
125 |
SetDParam(3, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
126 |
SetDParam(4, p->name_2); |
0 | 127 |
|
2639 | 128 |
xt = DrawString(x + 2, y, STR_202C_FROM_TO, 0); |
0 | 129 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
130 |
SetDParam(0, _date - ymd.day + 768 - s->age * 32); |
0 | 131 |
DrawString(xt, y, STR_202D_UNTIL, 0); |
132 |
y += 10; |
|
133 |
num++; |
|
134 |
} |
|
135 |
} |
|
136 |
||
2639 | 137 |
if (num == 0) DrawString(x + 2, y, STR_202A_NONE, 0); |
0 | 138 |
} |
139 |
||
140 |
static void SubsidiesListWndProc(Window *w, WindowEvent *e) |
|
141 |
{ |
|
2639 | 142 |
switch (e->event) { |
143 |
case WE_PAINT: DrawSubsidiesWindow(w); break; |
|
144 |
||
145 |
case WE_CLICK: |
|
146 |
switch (e->click.widget) { |
|
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
|
147 |
case 3: HandleSubsidyClick(e->click.pt.y - 25); break; |
2639 | 148 |
} |
149 |
break; |
|
0 | 150 |
} |
151 |
} |
|
152 |
||
153 |
static const Widget _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
|
154 |
{ 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
|
155 |
{ 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
|
156 |
{ WWT_STICKYBOX, RESIZE_NONE, 13, 618, 629, 0, 13, STR_NULL, STR_STICKY_BUTTON}, |
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
|
157 |
{ WWT_PANEL, RESIZE_NONE, 13, 0, 629, 14, 126, STR_NULL, 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
|
158 |
{ WIDGETS_END}, |
0 | 159 |
}; |
160 |
||
161 |
static const WindowDesc _subsidies_list_desc = { |
|
162 |
-1, -1, 630, 127, |
|
163 |
WC_SUBSIDIES_LIST,0, |
|
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
|
164 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, |
0 | 165 |
_subsidies_list_widgets, |
166 |
SubsidiesListWndProc |
|
167 |
}; |
|
168 |
||
169 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
919
diff
changeset
|
170 |
void ShowSubsidiesList(void) |
0 | 171 |
{ |
172 |
AllocateWindowDescFront(&_subsidies_list_desc, 0); |
|
173 |
} |