2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file subsidy_gui.cpp GUI for subsidies. */
|
2007-04-04 01:35:16 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2008-03-31 00:06:17 +00:00
|
|
|
#include "station_base.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "industry.h"
|
|
|
|
#include "town.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "economy_func.h"
|
2007-03-18 21:58:03 +00:00
|
|
|
#include "cargotype.h"
|
2007-12-19 19:44:29 +00:00
|
|
|
#include "window_gui.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-26 13:50:40 +00:00
|
|
|
#include "date_func.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "viewport_func.h"
|
|
|
|
#include "gfx_func.h"
|
2008-05-05 11:36:43 +00:00
|
|
|
#include "gui.h"
|
2009-05-23 15:46:00 +00:00
|
|
|
#include "subsidy_func.h"
|
2009-07-01 18:45:05 +00:00
|
|
|
#include "subsidy_base.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2009-04-17 19:47:21 +00:00
|
|
|
/** Widget numbers for the subsidy list window. */
|
|
|
|
enum SubsidyListWidgets {
|
|
|
|
SLW_CLOSEBOX,
|
|
|
|
SLW_CAPTION,
|
|
|
|
SLW_STICKYBOX,
|
|
|
|
SLW_PANEL,
|
|
|
|
SLW_SCROLLBAR,
|
|
|
|
SLW_RESIZEBOX,
|
|
|
|
};
|
|
|
|
|
2008-05-18 08:12:29 +00:00
|
|
|
struct SubsidyListWindow : Window {
|
|
|
|
SubsidyListWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
|
|
|
{
|
2008-05-23 23:02:13 +00:00
|
|
|
this->FindWindowPlacementAndResize(desc);
|
2008-05-18 08:12:29 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 08:12:29 +00:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
2009-04-17 19:47:21 +00:00
|
|
|
if (widget != SLW_PANEL) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-04-17 19:55:39 +00:00
|
|
|
int y = pt.y - this->widget[SLW_PANEL].top - FONT_HEIGHT_NORMAL - 1; // Skip 'subsidies on offer' line
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (y < 0) return;
|
|
|
|
|
2008-05-18 08:12:29 +00:00
|
|
|
uint num = 0;
|
2009-07-01 17:43:26 +00:00
|
|
|
|
|
|
|
const Subsidy *s;
|
|
|
|
FOR_ALL_SUBSIDIES(s) {
|
|
|
|
if (s->age < 12) {
|
2009-03-25 20:16:09 +00:00
|
|
|
y -= FONT_HEIGHT_NORMAL;
|
2008-06-03 00:23:54 +00:00
|
|
|
if (y < 0) {
|
|
|
|
this->HandleClick(s);
|
|
|
|
return;
|
|
|
|
}
|
2008-05-18 08:12:29 +00:00
|
|
|
num++;
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 08:12:29 +00:00
|
|
|
if (num == 0) {
|
2009-03-25 20:16:09 +00:00
|
|
|
y -= FONT_HEIGHT_NORMAL; // "None"
|
2008-05-18 08:12:29 +00:00
|
|
|
if (y < 0) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2008-06-03 11:39:15 +00:00
|
|
|
y -= 11; // "Services already subsidised:"
|
2008-05-18 08:12:29 +00:00
|
|
|
if (y < 0) return;
|
2007-03-18 21:58:03 +00:00
|
|
|
|
2009-07-01 17:43:26 +00:00
|
|
|
FOR_ALL_SUBSIDIES(s) {
|
|
|
|
if (s->age >= 12) {
|
2009-03-25 20:16:09 +00:00
|
|
|
y -= FONT_HEIGHT_NORMAL;
|
2008-06-03 00:23:54 +00:00
|
|
|
if (y < 0) {
|
|
|
|
this->HandleClick(s);
|
|
|
|
return;
|
|
|
|
}
|
2008-05-18 08:12:29 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-03-18 21:58:03 +00:00
|
|
|
|
2008-05-18 08:12:29 +00:00
|
|
|
void HandleClick(const Subsidy *s)
|
|
|
|
{
|
2009-07-16 19:00:13 +00:00
|
|
|
TownEffect te = CargoSpec::Get(s->cargo_type)->town_effect;
|
2008-05-18 08:12:29 +00:00
|
|
|
TileIndex xy;
|
2008-05-05 11:36:43 +00:00
|
|
|
|
2008-05-18 08:12:29 +00:00
|
|
|
/* determine from coordinate for subsidy and try to scroll to it */
|
|
|
|
uint offs = s->from;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (s->age >= 12) {
|
2009-05-16 23:34:14 +00:00
|
|
|
xy = Station::Get(offs)->xy;
|
2008-05-18 08:12:29 +00:00
|
|
|
} else if (te == TE_PASSENGERS || te == TE_MAIL) {
|
2009-05-16 23:34:14 +00:00
|
|
|
xy = Town::Get(offs)->xy;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2009-05-16 23:34:14 +00:00
|
|
|
xy = Industry::Get(offs)->xy;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-05 11:36:43 +00:00
|
|
|
|
2008-05-18 08:12:29 +00: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) {
|
2009-05-16 23:34:14 +00:00
|
|
|
xy = Station::Get(offs)->xy;
|
2008-05-18 08:12:29 +00:00
|
|
|
} else if (te == TE_PASSENGERS || te == TE_MAIL || te == TE_GOODS || te == TE_FOOD) {
|
2009-05-16 23:34:14 +00:00
|
|
|
xy = Town::Get(offs)->xy;
|
2008-05-18 08:12:29 +00:00
|
|
|
} else {
|
2009-05-16 23:34:14 +00:00
|
|
|
xy = Industry::Get(offs)->xy;
|
2008-05-18 08:12:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_ctrl_pressed) {
|
|
|
|
ShowExtraViewPortWindow(xy);
|
|
|
|
} else {
|
|
|
|
ScrollMainWindowToTile(xy);
|
|
|
|
}
|
2008-05-05 11:36:43 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-05-18 08:12:29 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
YearMonthDay ymd;
|
|
|
|
const Subsidy *s;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 08:12:29 +00:00
|
|
|
this->DrawWidgets();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 08:12:29 +00:00
|
|
|
ConvertDateToYMD(_date, &ymd);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-04-17 19:55:39 +00:00
|
|
|
int right = this->widget[SLW_PANEL].right;
|
|
|
|
int y = this->widget[SLW_PANEL].top + 1;
|
|
|
|
int x = this->widget[SLW_PANEL].left + 1;
|
2008-04-07 17:02:39 +00:00
|
|
|
|
2008-05-18 08:12:29 +00:00
|
|
|
/* Section for drawing the offered subisidies */
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(x, right, y, STR_SUBSIDIES_OFFERED_TITLE);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2008-05-18 08:12:29 +00:00
|
|
|
uint num = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-07-01 17:43:26 +00:00
|
|
|
FOR_ALL_SUBSIDIES(s) {
|
|
|
|
if (s->age < 12) {
|
2008-05-18 08:12:29 +00:00
|
|
|
/* Displays the two offered towns */
|
|
|
|
SetupSubsidyDecodeParam(s, 1);
|
2009-03-24 20:03:02 +00:00
|
|
|
SetDParam(7, _date - ymd.day + 384 - s->age * 32);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(x + 2, right - 2, y, STR_SUBSIDIES_OFFERED_FROM_TO);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2008-05-18 08:12:29 +00:00
|
|
|
num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num == 0) {
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(x + 2, right - 2, y, STR_SUBSIDIES_NONE);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-05-18 08:12:29 +00:00
|
|
|
/* Section for drawing the already granted subisidies */
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(x, right, y + 1, STR_SUBSIDIES_SUBSIDISED_TITLE);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2008-05-18 08:12:29 +00:00
|
|
|
num = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-07-01 17:43:26 +00:00
|
|
|
FOR_ALL_SUBSIDIES(s) {
|
|
|
|
if (s->age >= 12) {
|
2008-05-18 08:12:29 +00:00
|
|
|
SetupSubsidyDecodeParam(s, 1);
|
2009-05-16 23:34:14 +00:00
|
|
|
SetDParam(3, Station::Get(s->to)->owner);
|
2009-03-24 20:03:02 +00:00
|
|
|
SetDParam(4, _date - ymd.day + 768 - s->age * 32);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 08:12:29 +00:00
|
|
|
/* Displays the two connected stations */
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(x + 2, right - 2, y, STR_SUBSIDIES_SUBSIDISED_FROM_TO);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2008-05-18 08:12:29 +00:00
|
|
|
num++;
|
2008-04-04 02:24:44 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-04-26 14:52:56 +00:00
|
|
|
if (num == 0) DrawString(x + 2, right - 2, y, STR_SUBSIDIES_NONE);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-18 08:12:29 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static const Widget _subsidies_list_widgets[] = {
|
2009-04-21 23:40:56 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_BROWN, 0, 10, 0, 13, STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW}, // SLW_CLOSEBOX
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, COLOUR_BROWN, 11, 307, 0, 13, STR_SUBSIDIES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS}, // SLW_CAPTION
|
|
|
|
{ WWT_STICKYBOX, RESIZE_LR, COLOUR_BROWN, 308, 319, 0, 13, STR_NULL, STR_STICKY_BUTTON}, // SLW_STICKYBOX
|
|
|
|
{ WWT_PANEL, RESIZE_RB, COLOUR_BROWN, 0, 307, 14, 126, 0x0, STR_SUBSIDY_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER}, // SLW_PANEL
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, COLOUR_BROWN, 308, 319, 14, 114, 0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST}, // SLW_SCROLLBAR
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_BROWN, 308, 319, 115, 126, 0x0, STR_RESIZE_BUTTON}, // SLW_RESIZEBOX
|
2008-04-04 02:24:44 +00:00
|
|
|
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2009-04-17 20:03:44 +00:00
|
|
|
static const NWidgetPart _nested_subsidies_list_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_BROWN, SLW_CLOSEBOX),
|
2009-04-21 23:40:56 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_BROWN, SLW_CAPTION), SetDataTip(STR_SUBSIDIES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-04-17 20:03:44 +00:00
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_BROWN, SLW_STICKYBOX),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-04-21 23:40:56 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_BROWN, SLW_PANEL), SetMinimalSize(308, 113), SetDataTip(0x0, STR_SUBSIDY_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER), SetResize(1, 1), EndContainer(),
|
2009-04-17 20:03:44 +00:00
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(WWT_SCROLLBAR, COLOUR_BROWN, SLW_SCROLLBAR),
|
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_BROWN, SLW_RESIZEBOX),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _subsidies_list_desc(
|
2008-04-04 02:24:44 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 320, 127, 320, 127,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_SUBSIDIES_LIST, WC_NONE,
|
2008-04-04 02:24:44 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
2009-04-17 20:03:44 +00:00
|
|
|
_subsidies_list_widgets, _nested_subsidies_list_widgets, lengthof(_nested_subsidies_list_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void ShowSubsidiesList()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-05-18 08:12:29 +00:00
|
|
|
AllocateWindowDescFront<SubsidyListWindow>(&_subsidies_list_desc, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|