mirror of https://github.com/OpenTTD/OpenTTD
(svn r13152) -Codechange: make a class of the subsidy window.
parent
f5681547ef
commit
62e36abd2e
|
@ -19,20 +19,24 @@
|
|||
|
||||
#include "table/strings.h"
|
||||
|
||||
static void HandleSubsidyClick(int y)
|
||||
{
|
||||
const Subsidy *s;
|
||||
uint num;
|
||||
int offs;
|
||||
TileIndex xy;
|
||||
struct SubsidyListWindow : Window {
|
||||
SubsidyListWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void OnClick(Point pt, int widget)
|
||||
{
|
||||
if (widget != 3) return;
|
||||
|
||||
int y = pt.y - 25;
|
||||
|
||||
if (y < 0) return;
|
||||
|
||||
num = 0;
|
||||
for (s = _subsidies; s != endof(_subsidies); s++) {
|
||||
uint num = 0;
|
||||
for (const Subsidy *s = _subsidies; s != endof(_subsidies); s++) {
|
||||
if (s->cargo_type != CT_INVALID && s->age < 12) {
|
||||
y -= 10;
|
||||
if (y < 0) goto handle_click;
|
||||
if (y < 0) this->HandleClick(s);
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
@ -45,20 +49,21 @@ static void HandleSubsidyClick(int y)
|
|||
y -= 11;
|
||||
if (y < 0) return;
|
||||
|
||||
for (s = _subsidies; s != endof(_subsidies); s++) {
|
||||
for (const Subsidy *s = _subsidies; s != endof(_subsidies); s++) {
|
||||
if (s->cargo_type != CT_INVALID && s->age >= 12) {
|
||||
y -= 10;
|
||||
if (y < 0) goto handle_click;
|
||||
if (y < 0) this->HandleClick(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
handle_click:
|
||||
|
||||
void HandleClick(const Subsidy *s)
|
||||
{
|
||||
TownEffect te = GetCargo(s->cargo_type)->town_effect;
|
||||
TileIndex xy;
|
||||
|
||||
/* determine from coordinate for subsidy and try to scroll to it */
|
||||
offs = s->from;
|
||||
uint offs = s->from;
|
||||
if (s->age >= 12) {
|
||||
xy = GetStation(offs)->xy;
|
||||
} else if (te == TE_PASSENGERS || te == TE_MAIL) {
|
||||
|
@ -86,28 +91,25 @@ handle_click:
|
|||
ScrollMainWindowToTile(xy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void DrawSubsidiesWindow(const Window *w)
|
||||
{
|
||||
virtual void OnPaint()
|
||||
{
|
||||
YearMonthDay ymd;
|
||||
const Subsidy *s;
|
||||
uint num;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
w->DrawWidgets();
|
||||
this->DrawWidgets();
|
||||
|
||||
ConvertDateToYMD(_date, &ymd);
|
||||
|
||||
int width = w->width - 13; // scroll bar = 11 + pixel each side
|
||||
y = 15;
|
||||
x = 1;
|
||||
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;
|
||||
num = 0;
|
||||
uint num = 0;
|
||||
|
||||
for (s = _subsidies; s != endof(_subsidies); s++) {
|
||||
if (s->cargo_type != CT_INVALID && s->age < 12) {
|
||||
|
@ -158,22 +160,8 @@ static void DrawSubsidiesWindow(const Window *w)
|
|||
}
|
||||
|
||||
if (num == 0) DrawStringTruncated(x + 2, y, STR_202A_NONE, TC_FROMSTRING, width - 2);
|
||||
}
|
||||
|
||||
static void SubsidiesListWndProc(Window *w, WindowEvent *e)
|
||||
{
|
||||
switch (e->event) {
|
||||
case WE_PAINT: DrawSubsidiesWindow(w); break;
|
||||
|
||||
case WE_CLICK:
|
||||
switch (e->we.click.widget) {
|
||||
case 3:
|
||||
HandleSubsidyClick(e->we.click.pt.y - 25);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static const Widget _subsidies_list_widgets[] = {
|
||||
{ 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,
|
||||
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
||||
_subsidies_list_widgets,
|
||||
SubsidiesListWndProc
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
void ShowSubsidiesList()
|
||||
{
|
||||
AllocateWindowDescFront<Window>(&_subsidies_list_desc, 0);
|
||||
AllocateWindowDescFront<SubsidyListWindow>(&_subsidies_list_desc, 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue