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