author | glx |
Wed, 04 Jun 2008 22:34:45 +0000 | |
branch | noai |
changeset 10829 | 8a0ec0f0f928 |
parent 10715 | 6bdf79ffb022 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10142
diff
changeset
|
3 |
/** @file subsidy_gui.cpp GUI for subsidies. */ |
9574 | 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" |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10142
diff
changeset
|
18 |
#include "gui.h" |
0 | 19 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
20 |
#include "table/strings.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
21 |
|
10645 | 22 |
struct SubsidyListWindow : Window { |
23 |
SubsidyListWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) |
|
24 |
{ |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
25 |
this->FindWindowPlacementAndResize(desc); |
10645 | 26 |
} |
0 | 27 |
|
10645 | 28 |
virtual void OnClick(Point pt, int widget) |
29 |
{ |
|
30 |
if (widget != 3) return; |
|
0 | 31 |
|
10645 | 32 |
int y = pt.y - 25; |
33 |
||
34 |
if (y < 0) return; |
|
35 |
||
36 |
uint num = 0; |
|
37 |
for (const Subsidy *s = _subsidies; s != endof(_subsidies); s++) { |
|
38 |
if (s->cargo_type != CT_INVALID && s->age < 12) { |
|
39 |
y -= 10; |
|
10829 | 40 |
if (y < 0) { |
41 |
this->HandleClick(s); |
|
42 |
return; |
|
43 |
} |
|
10645 | 44 |
num++; |
45 |
} |
|
46 |
} |
|
47 |
||
48 |
if (num == 0) { |
|
10829 | 49 |
y -= 10; // "None" |
10645 | 50 |
if (y < 0) return; |
51 |
} |
|
52 |
||
10829 | 53 |
y -= 11; // "Services already subsidised:" |
10645 | 54 |
if (y < 0) return; |
55 |
||
56 |
for (const Subsidy *s = _subsidies; s != endof(_subsidies); s++) { |
|
57 |
if (s->cargo_type != CT_INVALID && s->age >= 12) { |
|
58 |
y -= 10; |
|
10829 | 59 |
if (y < 0) { |
60 |
this->HandleClick(s); |
|
61 |
return; |
|
62 |
} |
|
10645 | 63 |
} |
0 | 64 |
} |
65 |
} |
|
66 |
||
10645 | 67 |
void HandleClick(const Subsidy *s) |
68 |
{ |
|
69 |
TownEffect te = GetCargo(s->cargo_type)->town_effect; |
|
70 |
TileIndex xy; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
71 |
|
10645 | 72 |
/* determine from coordinate for subsidy and try to scroll to it */ |
73 |
uint offs = s->from; |
|
0 | 74 |
if (s->age >= 12) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
75 |
xy = GetStation(offs)->xy; |
10645 | 76 |
} 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
|
77 |
xy = GetTown(offs)->xy; |
0 | 78 |
} else { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
867
diff
changeset
|
79 |
xy = GetIndustry(offs)->xy; |
0 | 80 |
} |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10142
diff
changeset
|
81 |
|
10645 | 82 |
if (_ctrl_pressed || !ScrollMainWindowToTile(xy)) { |
83 |
if (_ctrl_pressed) ShowExtraViewPortWindow(xy); |
|
0 | 84 |
|
10645 | 85 |
/* otherwise determine to coordinate for subsidy and scroll to it */ |
86 |
offs = s->to; |
|
87 |
if (s->age >= 12) { |
|
88 |
xy = GetStation(offs)->xy; |
|
89 |
} else if (te == TE_PASSENGERS || te == TE_MAIL || te == TE_GOODS || te == TE_FOOD) { |
|
90 |
xy = GetTown(offs)->xy; |
|
91 |
} else { |
|
92 |
xy = GetIndustry(offs)->xy; |
|
93 |
} |
|
0 | 94 |
|
10645 | 95 |
if (_ctrl_pressed) { |
96 |
ShowExtraViewPortWindow(xy); |
|
97 |
} else { |
|
98 |
ScrollMainWindowToTile(xy); |
|
99 |
} |
|
0 | 100 |
} |
101 |
} |
|
102 |
||
10645 | 103 |
virtual void OnPaint() |
104 |
{ |
|
105 |
YearMonthDay ymd; |
|
106 |
const Subsidy *s; |
|
0 | 107 |
|
10645 | 108 |
this->DrawWidgets(); |
0 | 109 |
|
10645 | 110 |
ConvertDateToYMD(_date, &ymd); |
2639 | 111 |
|
10645 | 112 |
int width = this->width - 13; // scroll bar = 11 + pixel each side |
113 |
int y = 15; |
|
114 |
int x = 1; |
|
115 |
||
116 |
/* Section for drawing the offered subisidies */ |
|
117 |
DrawStringTruncated(x, y, STR_2026_SUBSIDIES_ON_OFFER_FOR, TC_FROMSTRING, width); |
|
118 |
y += 10; |
|
119 |
uint num = 0; |
|
120 |
||
121 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
|
122 |
if (s->cargo_type != CT_INVALID && s->age < 12) { |
|
123 |
int x2; |
|
124 |
||
125 |
/* Displays the two offered towns */ |
|
126 |
SetupSubsidyDecodeParam(s, 1); |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
127 |
x2 = DrawStringTruncated(x + 2, y, STR_2027_FROM_TO, TC_FROMSTRING, width - 2); |
10645 | 128 |
|
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
129 |
if (width - x2 > 10) { |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
130 |
/* Displays the deadline before voiding the proposal */ |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
131 |
SetDParam(0, _date - ymd.day + 384 - s->age * 32); |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
132 |
DrawStringTruncated(x2, y, STR_2028_BY, TC_FROMSTRING, width - x2); |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
133 |
} |
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
134 |
|
10645 | 135 |
y += 10; |
136 |
num++; |
|
2639 | 137 |
} |
10645 | 138 |
} |
139 |
||
140 |
if (num == 0) { |
|
141 |
DrawStringTruncated(x + 2, y, STR_202A_NONE, TC_FROMSTRING, width - 2); |
|
142 |
y += 10; |
|
143 |
} |
|
144 |
||
145 |
/* Section for drawing the already granted subisidies */ |
|
146 |
DrawStringTruncated(x, y + 1, STR_202B_SERVICES_ALREADY_SUBSIDISED, TC_FROMSTRING, width); |
|
147 |
y += 10; |
|
148 |
num = 0; |
|
149 |
||
150 |
for (s = _subsidies; s != endof(_subsidies); s++) { |
|
151 |
if (s->cargo_type != CT_INVALID && s->age >= 12) { |
|
152 |
int xt; |
|
153 |
||
154 |
SetupSubsidyDecodeParam(s, 1); |
|
155 |
||
156 |
PlayerID player = GetStation(s->to)->owner; |
|
157 |
SetDParam(3, player); |
|
158 |
||
159 |
/* Displays the two connected stations */ |
|
160 |
xt = DrawStringTruncated(x + 2, y, STR_202C_FROM_TO, TC_FROMSTRING, width - 2); |
|
161 |
||
162 |
/* Displays the date where the granted subsidy will end */ |
|
163 |
if ((xt > 3) && (width - xt) > 9 ) { // do not draw if previous drawing failed or if it will overlap on scrollbar |
|
164 |
SetDParam(0, _date - ymd.day + 768 - s->age * 32); |
|
165 |
DrawStringTruncated(xt, y, STR_202D_UNTIL, TC_FROMSTRING, width - xt); |
|
166 |
} |
|
167 |
y += 10; |
|
168 |
num++; |
|
169 |
} |
|
170 |
} |
|
171 |
||
172 |
if (num == 0) DrawStringTruncated(x + 2, y, STR_202A_NONE, TC_FROMSTRING, width - 2); |
|
0 | 173 |
} |
10645 | 174 |
}; |
0 | 175 |
|
176 |
static const Widget _subsidies_list_widgets[] = { |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
177 |
{ 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
|
178 |
{ 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
|
179 |
{ 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
|
180 |
{ 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
|
181 |
{ 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
|
182 |
{ 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
|
183 |
|
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
0
diff
changeset
|
184 |
{ WIDGETS_END}, |
0 | 185 |
}; |
186 |
||
187 |
static const WindowDesc _subsidies_list_desc = { |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
188 |
WDP_AUTO, WDP_AUTO, 320, 127, 320, 127, |
6144
5a0ffbf27ced
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5835
diff
changeset
|
189 |
WC_SUBSIDIES_LIST, WC_NONE, |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
190 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
0 | 191 |
_subsidies_list_widgets, |
192 |
}; |
|
193 |
||
194 |
||
6573 | 195 |
void ShowSubsidiesList() |
0 | 196 |
{ |
10645 | 197 |
AllocateWindowDescFront<SubsidyListWindow>(&_subsidies_list_desc, 0); |
0 | 198 |
} |