2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/** @file subsidy_gui.cpp */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.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"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.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"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static void HandleSubsidyClick(int y)
|
2004-09-10 19:02:27 +00:00
|
|
|
{
|
2006-07-26 03:33:12 +00:00
|
|
|
const Subsidy *s;
|
2005-11-14 19:48:04 +00:00
|
|
|
uint num;
|
|
|
|
int offs;
|
2004-08-09 17:04:08 +00:00
|
|
|
TileIndex xy;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (y < 0) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
num = 0;
|
2005-11-14 19:48:04 +00:00
|
|
|
for (s = _subsidies; s != endof(_subsidies); s++) {
|
2005-09-28 19:35:36 +00:00
|
|
|
if (s->cargo_type != CT_INVALID && s->age < 12) {
|
2004-08-09 17:04:08 +00:00
|
|
|
y -= 10;
|
|
|
|
if (y < 0) goto handle_click;
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num == 0) {
|
|
|
|
y -= 10;
|
|
|
|
if (y < 0) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
y -= 11;
|
|
|
|
if (y < 0) return;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (s = _subsidies; s != endof(_subsidies); s++) {
|
2005-09-28 19:35:36 +00:00
|
|
|
if (s->cargo_type != CT_INVALID && s->age >= 12) {
|
2004-08-09 17:04:08 +00:00
|
|
|
y -= 10;
|
|
|
|
if (y < 0) goto handle_click;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
handle_click:
|
|
|
|
|
2007-03-18 21:58:03 +00:00
|
|
|
TownEffect te = GetCargo(s->cargo_type)->town_effect;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/* determine from coordinate for subsidy and try to scroll to it */
|
|
|
|
offs = s->from;
|
|
|
|
if (s->age >= 12) {
|
2005-01-06 22:31:58 +00:00
|
|
|
xy = GetStation(offs)->xy;
|
2007-03-18 21:58:03 +00:00
|
|
|
} else if (te == TE_PASSENGERS || te == TE_MAIL) {
|
2005-01-06 22:31:58 +00:00
|
|
|
xy = GetTown(offs)->xy;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-01-06 22:31:58 +00:00
|
|
|
xy = GetIndustry(offs)->xy;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-03-18 21:58:03 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (!ScrollMainWindowToTile(xy)) {
|
|
|
|
/* otherwise determine to coordinate for subsidy and scroll to it */
|
|
|
|
offs = s->to;
|
|
|
|
if (s->age >= 12) {
|
2005-01-06 22:31:58 +00:00
|
|
|
xy = GetStation(offs)->xy;
|
2007-03-18 21:58:03 +00:00
|
|
|
} else if (te == TE_PASSENGERS || te == TE_MAIL || te == TE_GOODS || te == TE_FOOD) {
|
2005-01-06 22:31:58 +00:00
|
|
|
xy = GetTown(offs)->xy;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-01-06 22:31:58 +00:00
|
|
|
xy = GetIndustry(offs)->xy;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
ScrollMainWindowToTile(xy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
static void DrawSubsidiesWindow(const Window *w)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
YearMonthDay ymd;
|
2006-07-26 03:33:12 +00:00
|
|
|
const Subsidy *s;
|
2005-11-14 19:48:04 +00:00
|
|
|
uint num;
|
|
|
|
int x;
|
|
|
|
int y;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
2006-08-15 16:49:48 +00:00
|
|
|
ConvertDateToYMD(_date, &ymd);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-04 02:24:44 +00:00
|
|
|
int width = w->width - 13; // scroll bar = 11 + pixel each side
|
2004-08-09 17:04:08 +00:00
|
|
|
y = 15;
|
|
|
|
x = 1;
|
2007-11-24 13:00:32 +00:00
|
|
|
DrawStringTruncated(x, y, STR_2026_SUBSIDIES_ON_OFFER_FOR, TC_FROMSTRING, width);
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 10;
|
|
|
|
num = 0;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (s = _subsidies; s != endof(_subsidies); s++) {
|
2005-09-28 19:35:36 +00:00
|
|
|
if (s->cargo_type != CT_INVALID && s->age < 12) {
|
2005-11-14 19:48:04 +00:00
|
|
|
int x2;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
SetupSubsidyDecodeParam(s, 1);
|
2007-11-24 13:00:32 +00:00
|
|
|
x2 = DrawStringTruncated(x + 2, y, STR_2027_FROM_TO, TC_FROMSTRING, width);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, _date - ymd.day + 384 - s->age * 32);
|
2007-11-24 13:00:32 +00:00
|
|
|
DrawStringTruncated(x2, y, STR_2028_BY, TC_FROMSTRING, width - x2);
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 10;
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num == 0) {
|
2007-11-24 13:00:32 +00:00
|
|
|
DrawStringTruncated(x + 2, y, STR_202A_NONE, TC_FROMSTRING, width - 2);
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
|
2007-11-24 13:00:32 +00:00
|
|
|
DrawStringTruncated(x, y + 1, STR_202B_SERVICES_ALREADY_SUBSIDISED, TC_FROMSTRING, width);
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 10;
|
|
|
|
num = 0;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (s = _subsidies; s != endof(_subsidies); s++) {
|
2005-09-28 19:35:36 +00:00
|
|
|
if (s->cargo_type != CT_INVALID && s->age >= 12) {
|
2005-11-14 19:48:04 +00:00
|
|
|
int xt;
|
2005-11-13 13:43:55 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
SetupSubsidyDecodeParam(s, 1);
|
|
|
|
|
2007-06-25 13:30:38 +00:00
|
|
|
PlayerID player = GetStation(s->to)->owner;
|
|
|
|
SetDParam(3, player);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-11-24 13:00:32 +00:00
|
|
|
xt = DrawStringTruncated(x + 2, y, STR_202C_FROM_TO, TC_FROMSTRING, width - 2);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-04 02:24:44 +00:00
|
|
|
if ((xt > 3) && (width - xt) > 9 ) { // do not draw if it will get on the scrollbar or if last drawing did nothing
|
|
|
|
SetDParam(0, _date - ymd.day + 768 - s->age * 32);
|
|
|
|
DrawStringTruncated(xt, y, STR_202D_UNTIL, TC_FROMSTRING, width - xt);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 10;
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-24 13:00:32 +00:00
|
|
|
if (num == 0) DrawStringTruncated(x + 2, y, STR_202A_NONE, TC_FROMSTRING, width - 2);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void SubsidiesListWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
switch (e->event) {
|
|
|
|
case WE_PAINT: DrawSubsidiesWindow(w); break;
|
|
|
|
|
|
|
|
case WE_CLICK:
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.click.widget) {
|
|
|
|
case 3:
|
|
|
|
HandleSubsidyClick(e->we.click.pt.y - 25);
|
|
|
|
break;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _subsidies_list_widgets[] = {
|
2008-04-04 02:24:44 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 13, 11, 307, 0, 13, STR_2025_SUBSIDIES, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_LR, 13, 308, 319, 0, 13, STR_NULL, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_PANEL, RESIZE_RB, 13, 0, 307, 14, 126, 0x0, STR_01FD_CLICK_ON_SERVICE_TO_CENTER},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, 13, 308, 319, 14, 114, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // IDW_SCROLLBAR
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 13, 308, 319, 115, 126, 0x0, STR_RESIZE_BUTTON}, // IDW_RESIZE
|
|
|
|
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +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,
|
2004-08-09 17:04:08 +00:00
|
|
|
_subsidies_list_widgets,
|
|
|
|
SubsidiesListWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void ShowSubsidiesList()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
AllocateWindowDescFront(&_subsidies_list_desc, 0);
|
|
|
|
}
|