author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1093 | 4fdc46eaf423 |
child 1891 | 862800791170 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
193
diff
changeset
|
3 |
#include "table/strings.h" |
0 | 4 |
#include "window.h" |
5 |
#include "gui.h" |
|
6 |
#include "station.h" |
|
7 |
#include "industry.h" |
|
8 |
#include "town.h" |
|
9 |
#include "player.h" |
|
10 |
#include "gfx.h" |
|
11 |
#include "economy.h" |
|
12 |
||
13 |
static void HandleSubsidyClick(int y) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
14 |
{ |
0 | 15 |
Subsidy *s; |
16 |
int num,offs; |
|
17 |
TileIndex xy; |
|
18 |
||
19 |
if (y < 0) |
|
20 |
return; |
|
21 |
||
22 |
num = 0; |
|
23 |
for(s=_subsidies; s != endof(_subsidies); s++) { |
|
24 |
if (s->cargo_type != 0xFF && s->age < 12) { |
|
25 |
y -= 10; |
|
26 |
if (y < 0) goto handle_click; |
|
27 |
num++; |
|
28 |
} |
|
29 |
} |
|
30 |
||
31 |
if (num == 0) { |
|
32 |
y -= 10; |
|
33 |
if (y < 0) return; |
|
34 |
} |
|
35 |
||
36 |
y -= 11; |
|
37 |
if (y < 0) return; |
|
38 |
||
39 |
for(s=_subsidies; s != endof(_subsidies); s++) { |
|
40 |
if (s->cargo_type != 0xFF && s->age >= 12) { |
|
41 |
y -= 10; |
|
42 |
if (y < 0) goto handle_click; |
|
43 |
} |
|
44 |
} |
|
45 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
46 |
|
0 | 47 |
handle_click: |
48 |
||
49 |
/* determine from coordinate for subsidy and try to scroll to it */ |
|
50 |
offs = s->from; |
|
51 |
if (s->age >= 12) { |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
52 |
xy = GetStation(offs)->xy; |
0 | 53 |
} else if (s->cargo_type == CT_PASSENGERS || s->cargo_type == CT_MAIL) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
54 |
xy = GetTown(offs)->xy; |
0 | 55 |
} else { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
56 |
xy = GetIndustry(offs)->xy; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
57 |
|
0 | 58 |
} |
59 |
if (!ScrollMainWindowToTile(xy)) { |
|
60 |
/* otherwise determine to coordinate for subsidy and scroll to it */ |
|
61 |
offs = s->to; |
|
62 |
if (s->age >= 12) { |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
63 |
xy = GetStation(offs)->xy; |
0 | 64 |
} else if (s->cargo_type == CT_PASSENGERS || s->cargo_type == CT_MAIL || s->cargo_type == CT_GOODS || s->cargo_type == CT_FOOD) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
65 |
xy = GetTown(offs)->xy; |
0 | 66 |
} else { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
67 |
xy = GetIndustry(offs)->xy; |
0 | 68 |
} |
69 |
ScrollMainWindowToTile(xy); |
|
70 |
} |
|
71 |
} |
|
72 |
||
73 |
static void DrawSubsidiesWindow(Window *w) |
|
74 |
{ |
|
75 |
YearMonthDay ymd; |
|
76 |
Subsidy *s; |
|
77 |
int x,xt,y,num,x2; |
|
78 |
Player *p; |
|
79 |
||
80 |
DrawWindowWidgets(w); |
|
81 |
||
82 |
ConvertDayToYMD(&ymd, _date); |
|
83 |
||
84 |
y = 15; |
|
85 |
x = 1; |
|
86 |
DrawString(x, y, STR_2026_SUBSIDIES_ON_OFFER_FOR, 0); |
|
87 |
y += 10; |
|
88 |
num = 0; |
|
89 |
||
90 |
for(s=_subsidies; s != endof(_subsidies); s++) { |
|
91 |
if (s->cargo_type != 0xFF && s->age < 12) { |
|
92 |
SetupSubsidyDecodeParam(s, 1); |
|
93 |
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
|
94 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
95 |
SetDParam(0, _date - ymd.day + 384 - s->age * 32); |
0 | 96 |
DrawString(x2, y, STR_2028_BY, 0); |
97 |
y += 10; |
|
98 |
num++; |
|
99 |
} |
|
100 |
} |
|
101 |
||
102 |
if (num == 0) { |
|
103 |
DrawString(x+2, y, STR_202A_NONE, 0); |
|
104 |
y += 10; |
|
105 |
} |
|
106 |
||
107 |
DrawString(x, y+1, STR_202B_SERVICES_ALREADY_SUBSIDISED, 0); |
|
108 |
y += 10; |
|
109 |
num = 0; |
|
110 |
||
111 |
for(s=_subsidies; s != endof(_subsidies); s++) { |
|
112 |
if (s->cargo_type != 0xFF && s->age >= 12) { |
|
113 |
SetupSubsidyDecodeParam(s, 1); |
|
114 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
115 |
p = DEREF_PLAYER(GetStation(s->to)->owner); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
116 |
SetDParam(3, p->name_1); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
117 |
SetDParam(4, p->name_2); |
0 | 118 |
|
119 |
xt = DrawString(x+2, y, STR_202C_FROM_TO, 0); |
|
120 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
121 |
SetDParam(0, _date - ymd.day + 768 - s->age * 32); |
0 | 122 |
DrawString(xt, y, STR_202D_UNTIL, 0); |
123 |
y += 10; |
|
124 |
num++; |
|
125 |
} |
|
126 |
} |
|
127 |
||
128 |
if (num == 0) { |
|
129 |
DrawString(x+2, y, STR_202A_NONE, 0); |
|
130 |
} |
|
131 |
} |
|
132 |
||
133 |
static void SubsidiesListWndProc(Window *w, WindowEvent *e) |
|
134 |
{ |
|
135 |
switch(e->event) { |
|
136 |
case WE_PAINT: DrawSubsidiesWindow(w); break; |
|
137 |
case WE_CLICK: { |
|
138 |
switch(e->click.widget) { |
|
139 |
case 2: HandleSubsidyClick(e->click.pt.y - 25); break; |
|
140 |
} |
|
141 |
} |
|
142 |
break; |
|
143 |
} |
|
144 |
} |
|
145 |
||
146 |
static const Widget _subsidies_list_widgets[] = { |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
534
diff
changeset
|
147 |
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
534
diff
changeset
|
148 |
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 629, 0, 13, STR_2025_SUBSIDIES, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
534
diff
changeset
|
149 |
{ 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
|
150 |
{ WIDGETS_END}, |
0 | 151 |
}; |
152 |
||
153 |
static const WindowDesc _subsidies_list_desc = { |
|
154 |
-1, -1, 630, 127, |
|
155 |
WC_SUBSIDIES_LIST,0, |
|
156 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
157 |
_subsidies_list_widgets, |
|
158 |
SubsidiesListWndProc |
|
159 |
}; |
|
160 |
||
161 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
919
diff
changeset
|
162 |
void ShowSubsidiesList(void) |
0 | 163 |
{ |
164 |
AllocateWindowDescFront(&_subsidies_list_desc, 0); |
|
165 |
} |