|
1 /* $Id$ */ |
|
2 |
|
3 #include "stdafx.h" |
|
4 #include "openttd.h" |
|
5 #include "table/strings.h" |
|
6 #include "functions.h" |
|
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" |
|
14 #include "variables.h" |
|
15 #include "date.h" |
|
16 |
|
17 static void HandleSubsidyClick(int y) |
|
18 { |
|
19 const Subsidy *s; |
|
20 uint num; |
|
21 int offs; |
|
22 TileIndex xy; |
|
23 |
|
24 if (y < 0) return; |
|
25 |
|
26 num = 0; |
|
27 for (s = _subsidies; s != endof(_subsidies); s++) { |
|
28 if (s->cargo_type != CT_INVALID && s->age < 12) { |
|
29 y -= 10; |
|
30 if (y < 0) goto handle_click; |
|
31 num++; |
|
32 } |
|
33 } |
|
34 |
|
35 if (num == 0) { |
|
36 y -= 10; |
|
37 if (y < 0) return; |
|
38 } |
|
39 |
|
40 y -= 11; |
|
41 if (y < 0) return; |
|
42 |
|
43 for (s = _subsidies; s != endof(_subsidies); s++) { |
|
44 if (s->cargo_type != CT_INVALID && s->age >= 12) { |
|
45 y -= 10; |
|
46 if (y < 0) goto handle_click; |
|
47 } |
|
48 } |
|
49 return; |
|
50 |
|
51 handle_click: |
|
52 |
|
53 /* determine from coordinate for subsidy and try to scroll to it */ |
|
54 offs = s->from; |
|
55 if (s->age >= 12) { |
|
56 xy = GetStation(offs)->xy; |
|
57 } else if (s->cargo_type == CT_PASSENGERS || s->cargo_type == CT_MAIL) { |
|
58 xy = GetTown(offs)->xy; |
|
59 } else { |
|
60 xy = GetIndustry(offs)->xy; |
|
61 |
|
62 } |
|
63 if (!ScrollMainWindowToTile(xy)) { |
|
64 /* otherwise determine to coordinate for subsidy and scroll to it */ |
|
65 offs = s->to; |
|
66 if (s->age >= 12) { |
|
67 xy = GetStation(offs)->xy; |
|
68 } else if (s->cargo_type == CT_PASSENGERS || s->cargo_type == CT_MAIL || s->cargo_type == CT_GOODS || s->cargo_type == CT_FOOD) { |
|
69 xy = GetTown(offs)->xy; |
|
70 } else { |
|
71 xy = GetIndustry(offs)->xy; |
|
72 } |
|
73 ScrollMainWindowToTile(xy); |
|
74 } |
|
75 } |
|
76 |
|
77 static void DrawSubsidiesWindow(const Window *w) |
|
78 { |
|
79 YearMonthDay ymd; |
|
80 const Subsidy *s; |
|
81 uint num; |
|
82 int x; |
|
83 int y; |
|
84 |
|
85 DrawWindowWidgets(w); |
|
86 |
|
87 ConvertDateToYMD(_date, &ymd); |
|
88 |
|
89 y = 15; |
|
90 x = 1; |
|
91 DrawString(x, y, STR_2026_SUBSIDIES_ON_OFFER_FOR, 0); |
|
92 y += 10; |
|
93 num = 0; |
|
94 |
|
95 for (s = _subsidies; s != endof(_subsidies); s++) { |
|
96 if (s->cargo_type != CT_INVALID && s->age < 12) { |
|
97 int x2; |
|
98 |
|
99 SetupSubsidyDecodeParam(s, 1); |
|
100 x2 = DrawString(x + 2, y, STR_2027_FROM_TO, 0); |
|
101 |
|
102 SetDParam(0, _date - ymd.day + 384 - s->age * 32); |
|
103 DrawString(x2, y, STR_2028_BY, 0); |
|
104 y += 10; |
|
105 num++; |
|
106 } |
|
107 } |
|
108 |
|
109 if (num == 0) { |
|
110 DrawString(x + 2, y, STR_202A_NONE, 0); |
|
111 y += 10; |
|
112 } |
|
113 |
|
114 DrawString(x, y + 1, STR_202B_SERVICES_ALREADY_SUBSIDISED, 0); |
|
115 y += 10; |
|
116 num = 0; |
|
117 |
|
118 for (s = _subsidies; s != endof(_subsidies); s++) { |
|
119 if (s->cargo_type != CT_INVALID && s->age >= 12) { |
|
120 const Player *p; |
|
121 int xt; |
|
122 |
|
123 SetupSubsidyDecodeParam(s, 1); |
|
124 |
|
125 p = GetPlayer(GetStation(s->to)->owner); |
|
126 SetDParam(3, p->name_1); |
|
127 SetDParam(4, p->name_2); |
|
128 |
|
129 xt = DrawString(x + 2, y, STR_202C_FROM_TO, 0); |
|
130 |
|
131 SetDParam(0, _date - ymd.day + 768 - s->age * 32); |
|
132 DrawString(xt, y, STR_202D_UNTIL, 0); |
|
133 y += 10; |
|
134 num++; |
|
135 } |
|
136 } |
|
137 |
|
138 if (num == 0) DrawString(x + 2, y, STR_202A_NONE, 0); |
|
139 } |
|
140 |
|
141 static void SubsidiesListWndProc(Window *w, WindowEvent *e) |
|
142 { |
|
143 switch (e->event) { |
|
144 case WE_PAINT: DrawSubsidiesWindow(w); break; |
|
145 |
|
146 case WE_CLICK: |
|
147 switch (e->we.click.widget) { |
|
148 case 3: |
|
149 HandleSubsidyClick(e->we.click.pt.y - 25); |
|
150 break; |
|
151 } |
|
152 break; |
|
153 } |
|
154 } |
|
155 |
|
156 static const Widget _subsidies_list_widgets[] = { |
|
157 { WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
158 { WWT_CAPTION, RESIZE_NONE, 13, 11, 617, 0, 13, STR_2025_SUBSIDIES, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
159 { WWT_STICKYBOX, RESIZE_NONE, 13, 618, 629, 0, 13, STR_NULL, STR_STICKY_BUTTON}, |
|
160 { WWT_PANEL, RESIZE_NONE, 13, 0, 629, 14, 126, 0x0, STR_01FD_CLICK_ON_SERVICE_TO_CENTER}, |
|
161 { WIDGETS_END}, |
|
162 }; |
|
163 |
|
164 static const WindowDesc _subsidies_list_desc = { |
|
165 WDP_AUTO, WDP_AUTO, 630, 127, |
|
166 WC_SUBSIDIES_LIST,0, |
|
167 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, |
|
168 _subsidies_list_widgets, |
|
169 SubsidiesListWndProc |
|
170 }; |
|
171 |
|
172 |
|
173 void ShowSubsidiesList(void) |
|
174 { |
|
175 AllocateWindowDescFront(&_subsidies_list_desc, 0); |
|
176 } |