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