author | rubidium |
Sat, 12 Apr 2008 21:38:49 +0000 | |
branch | noai |
changeset 10142 | 56ee7da4ad56 |
parent 9869 | 6404afe43575 |
child 10455 | 22c441f5adf9 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9574 | 3 |
/** @file subsidy_gui.cpp */ |
4 |
||
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1093
diff
changeset
|
6 |
#include "openttd.h" |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9724
diff
changeset
|
7 |
#include "station_base.h" |
0 | 8 |
#include "industry.h" |
9 |
#include "town.h" |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
10 |
#include "economy_func.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
1962
diff
changeset
|
11 |
#include "variables.h" |
9476 | 12 |
#include "cargotype.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
13 |
#include "window_gui.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
14 |
#include "strings_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
15 |
#include "date_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
16 |
#include "viewport_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
17 |
#include "gfx_func.h" |
0 | 18 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
19 |
#include "table/strings.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
20 |
|
0 | 21 |
static void HandleSubsidyClick(int y) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
22 |
{ |
4171 | 23 |
const Subsidy *s; |
2639 | 24 |
uint num; |
25 |
int offs; |
|
0 | 26 |
TileIndex xy; |
27 |
||
2639 | 28 |
if (y < 0) return; |
0 | 29 |
|
30 |
num = 0; |
|
2639 | 31 |
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
|
32 |
if (s->cargo_type != CT_INVALID && s->age < 12) { |
0 | 33 |
y -= 10; |
34 |
if (y < 0) goto handle_click; |
|
35 |
num++; |
|
36 |
} |
|
37 |
} |
|
38 |
||
39 |
if (num == 0) { |
|
40 |
y -= 10; |
|
41 |
if (y < 0) return; |
|
42 |
} |
|
43 |
||
44 |
y -= 11; |
|
45 |
if (y < 0) return; |
|
46 |
||
2639 | 47 |
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
|
48 |
if (s->cargo_type != CT_INVALID && s->age >= 12) { |
0 | 49 |
y -= 10; |
50 |
if (y < 0) goto handle_click; |
|
51 |
} |
|
52 |
} |
|
53 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
54 |
|
0 | 55 |
handle_click: |
56 |
||
9476 | 57 |
TownEffect te = GetCargo(s->cargo_type)->town_effect; |
58 |
||
0 | 59 |
/* determine from coordinate for subsidy and try to scroll to it */ |
60 |
offs = s->from; |
|
61 |
if (s->age >= 12) { |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
62 |
xy = GetStation(offs)->xy; |
9476 | 63 |
} else if (te == TE_PASSENGERS || te == TE_MAIL) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
64 |
xy = GetTown(offs)->xy; |
0 | 65 |
} else { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
66 |
xy = GetIndustry(offs)->xy; |
9476 | 67 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
68 |
|
0 | 69 |
if (!ScrollMainWindowToTile(xy)) { |
70 |
/* otherwise determine to coordinate for subsidy and scroll to it */ |
|
71 |
offs = s->to; |
|
72 |
if (s->age >= 12) { |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
73 |
xy = GetStation(offs)->xy; |
9476 | 74 |
} else if (te == TE_PASSENGERS || te == TE_MAIL || te == TE_GOODS || te == TE_FOOD) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
75 |
xy = GetTown(offs)->xy; |
0 | 76 |
} else { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
77 |
xy = GetIndustry(offs)->xy; |
0 | 78 |
} |
79 |
ScrollMainWindowToTile(xy); |
|
80 |
} |
|
81 |
} |
|
82 |
||
4171 | 83 |
static void DrawSubsidiesWindow(const Window *w) |
0 | 84 |
{ |
85 |
YearMonthDay ymd; |
|
4171 | 86 |
const Subsidy *s; |
2639 | 87 |
uint num; |
88 |
int x; |
|
89 |
int y; |
|
0 | 90 |
|
91 |
DrawWindowWidgets(w); |
|
92 |
||
4288
60398d0e64ee
(svn r5918) -Cleanup: rename ConvertDayToYMD/ConvertYMDToDay as they really convert a Date to/from a YearMonthDay.
rubidium
parents:
4261
diff
changeset
|
93 |
ConvertDateToYMD(_date, &ymd); |
0 | 94 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
95 |
int width = w->width - 13; // scroll bar = 11 + pixel each side |
0 | 96 |
y = 15; |
97 |
x = 1; |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
98 |
|
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
99 |
/* Section for drawing the offered subisidies */ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
100 |
DrawStringTruncated(x, y, STR_2026_SUBSIDIES_ON_OFFER_FOR, TC_FROMSTRING, width); |
0 | 101 |
y += 10; |
102 |
num = 0; |
|
103 |
||
2639 | 104 |
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
|
105 |
if (s->cargo_type != CT_INVALID && s->age < 12) { |
2639 | 106 |
int x2; |
107 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
108 |
/* Displays the two offered towns */ |
0 | 109 |
SetupSubsidyDecodeParam(s, 1); |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
110 |
x2 = DrawStringTruncated(x + 2, y, STR_2027_FROM_TO, TC_FROMSTRING, width); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
111 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
112 |
/* Displays the deadline before voiding the proposal */ |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
113 |
SetDParam(0, _date - ymd.day + 384 - s->age * 32); |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
114 |
DrawStringTruncated(x2, y, STR_2028_BY, TC_FROMSTRING, width - x2); |
0 | 115 |
y += 10; |
116 |
num++; |
|
117 |
} |
|
118 |
} |
|
119 |
||
120 |
if (num == 0) { |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
121 |
DrawStringTruncated(x + 2, y, STR_202A_NONE, TC_FROMSTRING, width - 2); |
0 | 122 |
y += 10; |
123 |
} |
|
124 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
125 |
/* Section for drawing the already granted subisidies */ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
126 |
DrawStringTruncated(x, y + 1, STR_202B_SERVICES_ALREADY_SUBSIDISED, TC_FROMSTRING, width); |
0 | 127 |
y += 10; |
128 |
num = 0; |
|
129 |
||
2639 | 130 |
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
|
131 |
if (s->cargo_type != CT_INVALID && s->age >= 12) { |
2639 | 132 |
int xt; |
2630 | 133 |
|
0 | 134 |
SetupSubsidyDecodeParam(s, 1); |
135 |
||
9629 | 136 |
PlayerID player = GetStation(s->to)->owner; |
137 |
SetDParam(3, player); |
|
0 | 138 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
139 |
/* Displays the two connected stations */ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
140 |
xt = DrawStringTruncated(x + 2, y, STR_202C_FROM_TO, TC_FROMSTRING, width - 2); |
0 | 141 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
142 |
/* Displays the date where the granted subsidy will end */ |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
143 |
if ((xt > 3) && (width - xt) > 9 ) { // do not draw if previous drawing failed or if it will overlap on scrollbar |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
144 |
SetDParam(0, _date - ymd.day + 768 - s->age * 32); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
145 |
DrawStringTruncated(xt, y, STR_202D_UNTIL, TC_FROMSTRING, width - xt); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
146 |
} |
0 | 147 |
y += 10; |
148 |
num++; |
|
149 |
} |
|
150 |
} |
|
151 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
152 |
if (num == 0) DrawStringTruncated(x + 2, y, STR_202A_NONE, TC_FROMSTRING, width - 2); |
0 | 153 |
} |
154 |
||
155 |
static void SubsidiesListWndProc(Window *w, WindowEvent *e) |
|
156 |
{ |
|
2639 | 157 |
switch (e->event) { |
158 |
case WE_PAINT: DrawSubsidiesWindow(w); break; |
|
159 |
||
160 |
case WE_CLICK: |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4288
diff
changeset
|
161 |
switch (e->we.click.widget) { |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4288
diff
changeset
|
162 |
case 3: |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4288
diff
changeset
|
163 |
HandleSubsidyClick(e->we.click.pt.y - 25); |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4288
diff
changeset
|
164 |
break; |
2639 | 165 |
} |
166 |
break; |
|
0 | 167 |
} |
168 |
} |
|
169 |
||
170 |
static const Widget _subsidies_list_widgets[] = { |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
171 |
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
172 |
{ WWT_CAPTION, RESIZE_RIGHT, 13, 11, 307, 0, 13, STR_2025_SUBSIDIES, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
173 |
{ WWT_STICKYBOX, RESIZE_LR, 13, 308, 319, 0, 13, STR_NULL, STR_STICKY_BUTTON}, |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
174 |
{ WWT_PANEL, RESIZE_RB, 13, 0, 307, 14, 126, 0x0, STR_01FD_CLICK_ON_SERVICE_TO_CENTER}, |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
175 |
{ WWT_SCROLLBAR, RESIZE_LRB, 13, 308, 319, 14, 114, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
176 |
{ WWT_RESIZEBOX, RESIZE_LRTB, 13, 308, 319, 115, 126, 0x0, STR_RESIZE_BUTTON}, |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
177 |
|
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
0
diff
changeset
|
178 |
{ WIDGETS_END}, |
0 | 179 |
}; |
180 |
||
181 |
static const WindowDesc _subsidies_list_desc = { |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
182 |
WDP_AUTO, WDP_AUTO, 320, 127, 320, 127, |
6144
5a0ffbf27ced
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5835
diff
changeset
|
183 |
WC_SUBSIDIES_LIST, WC_NONE, |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
184 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
0 | 185 |
_subsidies_list_widgets, |
186 |
SubsidiesListWndProc |
|
187 |
}; |
|
188 |
||
189 |
||
6573 | 190 |
void ShowSubsidiesList() |
0 | 191 |
{ |
192 |
AllocateWindowDescFront(&_subsidies_list_desc, 0); |
|
193 |
} |