1
0
Fork 0

(svn r13152) -Codechange: make a class of the subsidy window.

release/0.7
rubidium 2008-05-18 08:12:29 +00:00
parent f5681547ef
commit 62e36abd2e
1 changed files with 112 additions and 124 deletions

View File

@ -19,161 +19,149 @@
#include "table/strings.h" #include "table/strings.h"
static void HandleSubsidyClick(int y) struct SubsidyListWindow : Window {
{ SubsidyListWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
const Subsidy *s; {
uint num;
int offs;
TileIndex xy;
if (y < 0) return;
num = 0;
for (s = _subsidies; s != endof(_subsidies); s++) {
if (s->cargo_type != CT_INVALID && s->age < 12) {
y -= 10;
if (y < 0) goto handle_click;
num++;
}
} }
if (num == 0) { virtual void OnClick(Point pt, int widget)
y -= 10; {
if (widget != 3) return;
int y = pt.y - 25;
if (y < 0) return; if (y < 0) return;
}
y -= 11; uint num = 0;
if (y < 0) return; for (const Subsidy *s = _subsidies; s != endof(_subsidies); s++) {
if (s->cargo_type != CT_INVALID && s->age < 12) {
y -= 10;
if (y < 0) this->HandleClick(s);
num++;
}
}
for (s = _subsidies; s != endof(_subsidies); s++) { if (num == 0) {
if (s->cargo_type != CT_INVALID && s->age >= 12) {
y -= 10; y -= 10;
if (y < 0) goto handle_click; if (y < 0) return;
}
y -= 11;
if (y < 0) return;
for (const Subsidy *s = _subsidies; s != endof(_subsidies); s++) {
if (s->cargo_type != CT_INVALID && s->age >= 12) {
y -= 10;
if (y < 0) this->HandleClick(s);
}
} }
} }
return;
handle_click: void HandleClick(const Subsidy *s)
{
TownEffect te = GetCargo(s->cargo_type)->town_effect;
TileIndex xy;
TownEffect te = GetCargo(s->cargo_type)->town_effect; /* determine from coordinate for subsidy and try to scroll to it */
uint offs = s->from;
/* determine from coordinate for subsidy and try to scroll to it */
offs = s->from;
if (s->age >= 12) {
xy = GetStation(offs)->xy;
} else if (te == TE_PASSENGERS || te == TE_MAIL) {
xy = GetTown(offs)->xy;
} else {
xy = GetIndustry(offs)->xy;
}
if (_ctrl_pressed || !ScrollMainWindowToTile(xy)) {
if (_ctrl_pressed) ShowExtraViewPortWindow(xy);
/* otherwise determine to coordinate for subsidy and scroll to it */
offs = s->to;
if (s->age >= 12) { if (s->age >= 12) {
xy = GetStation(offs)->xy; xy = GetStation(offs)->xy;
} else if (te == TE_PASSENGERS || te == TE_MAIL || te == TE_GOODS || te == TE_FOOD) { } else if (te == TE_PASSENGERS || te == TE_MAIL) {
xy = GetTown(offs)->xy; xy = GetTown(offs)->xy;
} else { } else {
xy = GetIndustry(offs)->xy; xy = GetIndustry(offs)->xy;
} }
if (_ctrl_pressed) { if (_ctrl_pressed || !ScrollMainWindowToTile(xy)) {
ShowExtraViewPortWindow(xy); if (_ctrl_pressed) ShowExtraViewPortWindow(xy);
} else {
ScrollMainWindowToTile(xy);
}
}
}
static void DrawSubsidiesWindow(const Window *w) /* otherwise determine to coordinate for subsidy and scroll to it */
{ offs = s->to;
YearMonthDay ymd; if (s->age >= 12) {
const Subsidy *s; xy = GetStation(offs)->xy;
uint num; } else if (te == TE_PASSENGERS || te == TE_MAIL || te == TE_GOODS || te == TE_FOOD) {
int x; xy = GetTown(offs)->xy;
int y; } else {
xy = GetIndustry(offs)->xy;
}
w->DrawWidgets(); if (_ctrl_pressed) {
ShowExtraViewPortWindow(xy);
ConvertDateToYMD(_date, &ymd); } else {
ScrollMainWindowToTile(xy);
int width = w->width - 13; // scroll bar = 11 + pixel each side }
y = 15;
x = 1;
/* Section for drawing the offered subisidies */
DrawStringTruncated(x, y, STR_2026_SUBSIDIES_ON_OFFER_FOR, TC_FROMSTRING, width);
y += 10;
num = 0;
for (s = _subsidies; s != endof(_subsidies); s++) {
if (s->cargo_type != CT_INVALID && s->age < 12) {
int x2;
/* Displays the two offered towns */
SetupSubsidyDecodeParam(s, 1);
x2 = DrawStringTruncated(x + 2, y, STR_2027_FROM_TO, TC_FROMSTRING, width);
/* Displays the deadline before voiding the proposal */
SetDParam(0, _date - ymd.day + 384 - s->age * 32);
DrawStringTruncated(x2, y, STR_2028_BY, TC_FROMSTRING, width - x2);
y += 10;
num++;
} }
} }
if (num == 0) { virtual void OnPaint()
DrawStringTruncated(x + 2, y, STR_202A_NONE, TC_FROMSTRING, width - 2); {
YearMonthDay ymd;
const Subsidy *s;
this->DrawWidgets();
ConvertDateToYMD(_date, &ymd);
int width = this->width - 13; // scroll bar = 11 + pixel each side
int y = 15;
int x = 1;
/* Section for drawing the offered subisidies */
DrawStringTruncated(x, y, STR_2026_SUBSIDIES_ON_OFFER_FOR, TC_FROMSTRING, width);
y += 10; y += 10;
} uint num = 0;
/* Section for drawing the already granted subisidies */ for (s = _subsidies; s != endof(_subsidies); s++) {
DrawStringTruncated(x, y + 1, STR_202B_SERVICES_ALREADY_SUBSIDISED, TC_FROMSTRING, width); if (s->cargo_type != CT_INVALID && s->age < 12) {
y += 10; int x2;
num = 0;
for (s = _subsidies; s != endof(_subsidies); s++) { /* Displays the two offered towns */
if (s->cargo_type != CT_INVALID && s->age >= 12) { SetupSubsidyDecodeParam(s, 1);
int xt; x2 = DrawStringTruncated(x + 2, y, STR_2027_FROM_TO, TC_FROMSTRING, width);
SetupSubsidyDecodeParam(s, 1); /* Displays the deadline before voiding the proposal */
SetDParam(0, _date - ymd.day + 384 - s->age * 32);
PlayerID player = GetStation(s->to)->owner; DrawStringTruncated(x2, y, STR_2028_BY, TC_FROMSTRING, width - x2);
SetDParam(3, player); y += 10;
num++;
/* Displays the two connected stations */
xt = DrawStringTruncated(x + 2, y, STR_202C_FROM_TO, TC_FROMSTRING, width - 2);
/* Displays the date where the granted subsidy will end */
if ((xt > 3) && (width - xt) > 9 ) { // do not draw if previous drawing failed or if it will overlap on scrollbar
SetDParam(0, _date - ymd.day + 768 - s->age * 32);
DrawStringTruncated(xt, y, STR_202D_UNTIL, TC_FROMSTRING, width - xt);
} }
y += 10;
num++;
} }
}
if (num == 0) DrawStringTruncated(x + 2, y, STR_202A_NONE, TC_FROMSTRING, width - 2); if (num == 0) {
} DrawStringTruncated(x + 2, y, STR_202A_NONE, TC_FROMSTRING, width - 2);
y += 10;
}
static void SubsidiesListWndProc(Window *w, WindowEvent *e) /* Section for drawing the already granted subisidies */
{ DrawStringTruncated(x, y + 1, STR_202B_SERVICES_ALREADY_SUBSIDISED, TC_FROMSTRING, width);
switch (e->event) { y += 10;
case WE_PAINT: DrawSubsidiesWindow(w); break; num = 0;
case WE_CLICK: for (s = _subsidies; s != endof(_subsidies); s++) {
switch (e->we.click.widget) { if (s->cargo_type != CT_INVALID && s->age >= 12) {
case 3: int xt;
HandleSubsidyClick(e->we.click.pt.y - 25);
break; SetupSubsidyDecodeParam(s, 1);
PlayerID player = GetStation(s->to)->owner;
SetDParam(3, player);
/* Displays the two connected stations */
xt = DrawStringTruncated(x + 2, y, STR_202C_FROM_TO, TC_FROMSTRING, width - 2);
/* Displays the date where the granted subsidy will end */
if ((xt > 3) && (width - xt) > 9 ) { // do not draw if previous drawing failed or if it will overlap on scrollbar
SetDParam(0, _date - ymd.day + 768 - s->age * 32);
DrawStringTruncated(xt, y, STR_202D_UNTIL, TC_FROMSTRING, width - xt);
}
y += 10;
num++;
} }
break; }
if (num == 0) DrawStringTruncated(x + 2, y, STR_202A_NONE, TC_FROMSTRING, width - 2);
} }
} };
static const Widget _subsidies_list_widgets[] = { static const Widget _subsidies_list_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, { WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
@ -191,11 +179,11 @@ static const WindowDesc _subsidies_list_desc = {
WC_SUBSIDIES_LIST, WC_NONE, WC_SUBSIDIES_LIST, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
_subsidies_list_widgets, _subsidies_list_widgets,
SubsidiesListWndProc NULL
}; };
void ShowSubsidiesList() void ShowSubsidiesList()
{ {
AllocateWindowDescFront<Window>(&_subsidies_list_desc, 0); AllocateWindowDescFront<SubsidyListWindow>(&_subsidies_list_desc, 0);
} }