2005-07-24 16:12:37 +02:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 17:11:33 +02:00
|
|
|
/** @file subsidy_gui.cpp GUI for subsidies. */
|
2007-04-04 03:35:16 +02:00
|
|
|
|
2004-08-09 19:04:08 +02:00
|
|
|
#include "stdafx.h"
|
2008-03-31 02:06:17 +02:00
|
|
|
#include "station_base.h"
|
2004-08-09 19:04:08 +02:00
|
|
|
#include "industry.h"
|
|
|
|
#include "town.h"
|
2007-12-21 22:50:46 +01:00
|
|
|
#include "economy_func.h"
|
2007-03-18 22:58:03 +01:00
|
|
|
#include "cargotype.h"
|
2007-12-19 20:44:29 +01:00
|
|
|
#include "window_gui.h"
|
2007-12-21 20:49:27 +01:00
|
|
|
#include "strings_func.h"
|
2007-12-26 14:50:40 +01:00
|
|
|
#include "date_func.h"
|
2008-01-09 10:45:45 +01:00
|
|
|
#include "viewport_func.h"
|
|
|
|
#include "gfx_func.h"
|
2008-05-05 13:36:43 +02:00
|
|
|
#include "gui.h"
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-01-13 02:21:35 +01:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
struct SubsidyListWindow : Window {
|
|
|
|
SubsidyListWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
|
|
|
{
|
2008-05-24 01:02:13 +02:00
|
|
|
this->FindWindowPlacementAndResize(desc);
|
2008-05-18 10:12:29 +02:00
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
if (widget != 3) return;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
int y = pt.y - 25;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
|
|
|
if (y < 0) return;
|
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
uint num = 0;
|
|
|
|
for (const Subsidy *s = _subsidies; s != endof(_subsidies); s++) {
|
|
|
|
if (s->cargo_type != CT_INVALID && s->age < 12) {
|
2009-03-25 21:16:09 +01:00
|
|
|
y -= FONT_HEIGHT_NORMAL;
|
2008-06-03 02:23:54 +02:00
|
|
|
if (y < 0) {
|
|
|
|
this->HandleClick(s);
|
|
|
|
return;
|
|
|
|
}
|
2008-05-18 10:12:29 +02:00
|
|
|
num++;
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
if (num == 0) {
|
2009-03-25 21:16:09 +01:00
|
|
|
y -= FONT_HEIGHT_NORMAL; // "None"
|
2008-05-18 10:12:29 +02:00
|
|
|
if (y < 0) return;
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
2004-09-10 21:02:27 +02:00
|
|
|
|
2008-06-03 13:39:15 +02:00
|
|
|
y -= 11; // "Services already subsidised:"
|
2008-05-18 10:12:29 +02:00
|
|
|
if (y < 0) return;
|
2007-03-18 22:58:03 +01:00
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
for (const Subsidy *s = _subsidies; s != endof(_subsidies); s++) {
|
|
|
|
if (s->cargo_type != CT_INVALID && s->age >= 12) {
|
2009-03-25 21:16:09 +01:00
|
|
|
y -= FONT_HEIGHT_NORMAL;
|
2008-06-03 02:23:54 +02:00
|
|
|
if (y < 0) {
|
|
|
|
this->HandleClick(s);
|
|
|
|
return;
|
|
|
|
}
|
2008-05-18 10:12:29 +02:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
2007-03-18 22:58:03 +01:00
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
void HandleClick(const Subsidy *s)
|
|
|
|
{
|
|
|
|
TownEffect te = GetCargo(s->cargo_type)->town_effect;
|
|
|
|
TileIndex xy;
|
2008-05-05 13:36:43 +02:00
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
/* determine from coordinate for subsidy and try to scroll to it */
|
|
|
|
uint offs = s->from;
|
2004-08-09 19:04:08 +02:00
|
|
|
if (s->age >= 12) {
|
2005-01-06 23:31:58 +01:00
|
|
|
xy = GetStation(offs)->xy;
|
2008-05-18 10:12:29 +02:00
|
|
|
} else if (te == TE_PASSENGERS || te == TE_MAIL) {
|
2005-01-06 23:31:58 +01:00
|
|
|
xy = GetTown(offs)->xy;
|
2004-08-09 19:04:08 +02:00
|
|
|
} else {
|
2005-01-06 23:31:58 +01:00
|
|
|
xy = GetIndustry(offs)->xy;
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
2008-05-05 13:36:43 +02:00
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
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) {
|
|
|
|
xy = GetStation(offs)->xy;
|
|
|
|
} else if (te == TE_PASSENGERS || te == TE_MAIL || te == TE_GOODS || te == TE_FOOD) {
|
|
|
|
xy = GetTown(offs)->xy;
|
|
|
|
} else {
|
|
|
|
xy = GetIndustry(offs)->xy;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_ctrl_pressed) {
|
|
|
|
ShowExtraViewPortWindow(xy);
|
|
|
|
} else {
|
|
|
|
ScrollMainWindowToTile(xy);
|
|
|
|
}
|
2008-05-05 13:36:43 +02:00
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
YearMonthDay ymd;
|
|
|
|
const Subsidy *s;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
this->DrawWidgets();
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
ConvertDateToYMD(_date, &ymd);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-03-21 21:12:12 +01:00
|
|
|
int right = this->width - 12; // scroll bar = 11 + pixel each side
|
2008-05-18 10:12:29 +02:00
|
|
|
int y = 15;
|
|
|
|
int x = 1;
|
2008-04-07 19:02:39 +02:00
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
/* Section for drawing the offered subisidies */
|
2009-03-21 21:12:12 +01:00
|
|
|
DrawString(x, right, y, STR_2026_SUBSIDIES_ON_OFFER_FOR, TC_FROMSTRING);
|
2009-03-25 21:16:09 +01:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2008-05-18 10:12:29 +02:00
|
|
|
uint num = 0;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
for (s = _subsidies; s != endof(_subsidies); s++) {
|
|
|
|
if (s->cargo_type != CT_INVALID && s->age < 12) {
|
|
|
|
/* Displays the two offered towns */
|
|
|
|
SetupSubsidyDecodeParam(s, 1);
|
2009-03-24 21:03:02 +01:00
|
|
|
SetDParam(7, _date - ymd.day + 384 - s->age * 32);
|
|
|
|
DrawString(x + 2, right - 2, y, STR_2027_FROM_TO, TC_FROMSTRING);
|
2004-09-10 21:02:27 +02:00
|
|
|
|
2009-03-25 21:16:09 +01:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2008-05-18 10:12:29 +02:00
|
|
|
num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num == 0) {
|
2009-03-21 21:12:12 +01:00
|
|
|
DrawString(x + 2, right - 2, y, STR_202A_NONE, TC_FROMSTRING);
|
2009-03-25 21:16:09 +01:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
/* Section for drawing the already granted subisidies */
|
2009-03-21 21:12:12 +01:00
|
|
|
DrawString(x, right, y + 1, STR_202B_SERVICES_ALREADY_SUBSIDISED, TC_FROMSTRING);
|
2009-03-25 21:16:09 +01:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2008-05-18 10:12:29 +02:00
|
|
|
num = 0;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
for (s = _subsidies; s != endof(_subsidies); s++) {
|
|
|
|
if (s->cargo_type != CT_INVALID && s->age >= 12) {
|
|
|
|
SetupSubsidyDecodeParam(s, 1);
|
2008-09-30 22:39:50 +02:00
|
|
|
SetDParam(3, GetStation(s->to)->owner);
|
2009-03-24 21:03:02 +01:00
|
|
|
SetDParam(4, _date - ymd.day + 768 - s->age * 32);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
/* Displays the two connected stations */
|
2009-03-24 21:03:02 +01:00
|
|
|
DrawString(x + 2, right - 2, y, STR_202C_FROM_TO, TC_FROMSTRING);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-03-25 21:16:09 +01:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2008-05-18 10:12:29 +02:00
|
|
|
num++;
|
2008-04-04 04:24:44 +02:00
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2009-03-21 21:12:12 +01:00
|
|
|
if (num == 0) DrawString(x + 2, right - 2, y, STR_202A_NONE, TC_FROMSTRING);
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
2008-05-18 10:12:29 +02:00
|
|
|
};
|
2004-08-09 19:04:08 +02:00
|
|
|
|
|
|
|
static const Widget _subsidies_list_widgets[] = {
|
2008-08-02 04:28:17 +02:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_BROWN, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, COLOUR_BROWN, 11, 307, 0, 13, STR_2025_SUBSIDIES, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_LR, COLOUR_BROWN, 308, 319, 0, 13, STR_NULL, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_PANEL, RESIZE_RB, COLOUR_BROWN, 0, 307, 14, 126, 0x0, STR_01FD_CLICK_ON_SERVICE_TO_CENTER},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, COLOUR_BROWN, 308, 319, 14, 114, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_BROWN, 308, 319, 115, 126, 0x0, STR_RESIZE_BUTTON},
|
2008-04-04 04:24:44 +02:00
|
|
|
|
2004-09-07 23:48:09 +02:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 19:04:08 +02:00
|
|
|
};
|
|
|
|
|
2009-03-15 16:12:06 +01:00
|
|
|
static const WindowDesc _subsidies_list_desc(
|
2008-04-04 04:24:44 +02:00
|
|
|
WDP_AUTO, WDP_AUTO, 320, 127, 320, 127,
|
2007-02-01 16:49:12 +01:00
|
|
|
WC_SUBSIDIES_LIST, WC_NONE,
|
2008-04-04 04:24:44 +02:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
2009-03-15 16:12:06 +01:00
|
|
|
_subsidies_list_widgets
|
|
|
|
);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
|
|
|
|
2007-03-07 12:47:46 +01:00
|
|
|
void ShowSubsidiesList()
|
2004-08-09 19:04:08 +02:00
|
|
|
{
|
2008-05-18 10:12:29 +02:00
|
|
|
AllocateWindowDescFront<SubsidyListWindow>(&_subsidies_list_desc, 0);
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|