2005-07-24 16:12:37 +02:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 22:21:05 +02:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
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"
|
2009-05-23 17:46:00 +02:00
|
|
|
#include "subsidy_func.h"
|
2009-07-01 20:45:05 +02:00
|
|
|
#include "subsidy_base.h"
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-01-13 02:21:35 +01:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2009-04-17 21:47:21 +02: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 10:12:29 +02:00
|
|
|
struct SubsidyListWindow : Window {
|
2009-09-01 21:29:16 +02:00
|
|
|
SubsidyListWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
|
2008-05-18 10:12:29 +02:00
|
|
|
{
|
2009-09-01 21:29:16 +02:00
|
|
|
this->InitNested(desc, window_number);
|
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)
|
|
|
|
{
|
2009-04-17 21:47:21 +02:00
|
|
|
if (widget != SLW_PANEL) return;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-09-01 21:29:16 +02:00
|
|
|
int y = pt.y - this->nested_array[SLW_PANEL]->pos_y - FONT_HEIGHT_NORMAL - WD_FRAMERECT_TOP; // Skip 'subsidies on offer' line
|
2004-08-09 19:04:08 +02:00
|
|
|
|
|
|
|
if (y < 0) return;
|
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
uint num = 0;
|
2009-07-01 19:43:26 +02:00
|
|
|
|
|
|
|
const Subsidy *s;
|
|
|
|
FOR_ALL_SUBSIDIES(s) {
|
2009-07-18 21:54:35 +02:00
|
|
|
if (!s->IsAwarded()) {
|
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
|
|
|
|
2009-09-01 21:29:16 +02:00
|
|
|
y -= FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP; // "Services already subsidised:"
|
2008-05-18 10:12:29 +02:00
|
|
|
if (y < 0) return;
|
2007-03-18 22:58:03 +01:00
|
|
|
|
2009-07-01 19:43:26 +02:00
|
|
|
FOR_ALL_SUBSIDIES(s) {
|
2009-07-18 21:54:35 +02:00
|
|
|
if (s->IsAwarded()) {
|
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)
|
|
|
|
{
|
2009-08-08 00:23:34 +02:00
|
|
|
/* determine src coordinate for subsidy and try to scroll to it */
|
2008-05-18 10:12:29 +02:00
|
|
|
TileIndex xy;
|
2009-08-08 00:23:34 +02:00
|
|
|
switch (s->src_type) {
|
|
|
|
case ST_INDUSTRY: xy = Industry::Get(s->src)->xy; break;
|
|
|
|
case ST_TOWN: xy = Town::Get(s->src)->xy; break;
|
|
|
|
default: NOT_REACHED();
|
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);
|
|
|
|
|
2009-08-08 00:23:34 +02:00
|
|
|
/* otherwise determine dst coordinate for subsidy and scroll to it */
|
|
|
|
switch (s->dst_type) {
|
|
|
|
case ST_INDUSTRY: xy = Industry::Get(s->dst)->xy; break;
|
|
|
|
case ST_TOWN: xy = Town::Get(s->dst)->xy; break;
|
|
|
|
default: NOT_REACHED();
|
2008-05-18 10:12:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
this->DrawWidgets();
|
2009-09-01 21:29:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
if (widget != SLW_PANEL) return;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-09-01 21:29:16 +02:00
|
|
|
YearMonthDay ymd;
|
2008-05-18 10:12:29 +02:00
|
|
|
ConvertDateToYMD(_date, &ymd);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-09-01 21:29:16 +02:00
|
|
|
int right = r.right - WD_FRAMERECT_RIGHT;
|
|
|
|
int y = r.top + WD_FRAMERECT_TOP;
|
|
|
|
int x = r.left + WD_FRAMERECT_LEFT;
|
2008-04-07 19:02:39 +02:00
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
/* Section for drawing the offered subisidies */
|
2009-04-26 16:52:56 +02:00
|
|
|
DrawString(x, right, y, STR_SUBSIDIES_OFFERED_TITLE);
|
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
|
|
|
|
2009-09-01 21:29:16 +02:00
|
|
|
const Subsidy *s;
|
2009-07-01 19:43:26 +02:00
|
|
|
FOR_ALL_SUBSIDIES(s) {
|
2009-07-18 21:54:35 +02:00
|
|
|
if (!s->IsAwarded()) {
|
2008-05-18 10:12:29 +02:00
|
|
|
/* Displays the two offered towns */
|
|
|
|
SetupSubsidyDecodeParam(s, 1);
|
2009-08-08 18:42:55 +02:00
|
|
|
SetDParam(7, _date - ymd.day + s->remaining * 32);
|
2009-09-01 21:29:16 +02:00
|
|
|
DrawString(x, right, y, STR_SUBSIDIES_OFFERED_FROM_TO);
|
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-09-01 21:29:16 +02:00
|
|
|
DrawString(x, right, y, STR_SUBSIDIES_NONE);
|
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-09-01 21:29:16 +02:00
|
|
|
DrawString(x, right, y + WD_FRAMERECT_TOP, STR_SUBSIDIES_SUBSIDISED_TITLE);
|
|
|
|
y += FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP;
|
2008-05-18 10:12:29 +02:00
|
|
|
num = 0;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-07-01 19:43:26 +02:00
|
|
|
FOR_ALL_SUBSIDIES(s) {
|
2009-07-18 21:54:35 +02:00
|
|
|
if (s->IsAwarded()) {
|
2008-05-18 10:12:29 +02:00
|
|
|
SetupSubsidyDecodeParam(s, 1);
|
2009-08-08 18:42:55 +02:00
|
|
|
SetDParam(7, s->awarded);
|
|
|
|
SetDParam(8, _date - ymd.day + s->remaining * 32);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-05-18 10:12:29 +02:00
|
|
|
/* Displays the two connected stations */
|
2009-09-01 21:29:16 +02:00
|
|
|
DrawString(x, right, y, STR_SUBSIDIES_SUBSIDISED_FROM_TO);
|
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-09-01 21:29:16 +02:00
|
|
|
if (num == 0) DrawString(x, right, y, STR_SUBSIDIES_NONE);
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
2008-05-18 10:12:29 +02:00
|
|
|
};
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-04-17 22:03:44 +02:00
|
|
|
static const NWidgetPart _nested_subsidies_list_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_BROWN, SLW_CLOSEBOX),
|
2009-04-22 01:40:56 +02:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_BROWN, SLW_CAPTION), SetDataTip(STR_SUBSIDIES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-04-17 22:03:44 +02:00
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_BROWN, SLW_STICKYBOX),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-08-05 19:59:21 +02:00
|
|
|
NWidget(WWT_PANEL, COLOUR_BROWN, SLW_PANEL), SetMinimalSize(308, 113), SetDataTip(0x0, STR_SUBSIDIES_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER), SetResize(1, 1), EndContainer(),
|
2009-04-17 22:03:44 +02:00
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(WWT_SCROLLBAR, COLOUR_BROWN, SLW_SCROLLBAR),
|
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_BROWN, SLW_RESIZEBOX),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
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-09-01 21:29:16 +02:00
|
|
|
NULL, _nested_subsidies_list_widgets, lengthof(_nested_subsidies_list_widgets)
|
2009-03-15 16:12:06 +01:00
|
|
|
);
|
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
|
|
|
}
|