tron@2186: /* $Id$ */ tron@2186: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" tron@507: #include "table/strings.h" tron@2163: #include "functions.h" truelight@0: #include "window.h" truelight@0: #include "gui.h" truelight@0: #include "station.h" truelight@0: #include "industry.h" truelight@0: #include "town.h" truelight@0: #include "player.h" truelight@0: #include "gfx.h" truelight@0: #include "economy.h" tron@2159: #include "variables.h" truelight@0: truelight@0: static void HandleSubsidyClick(int y) truelight@193: { truelight@0: Subsidy *s; truelight@0: int num,offs; truelight@0: TileIndex xy; truelight@0: truelight@0: if (y < 0) truelight@0: return; truelight@0: truelight@0: num = 0; truelight@0: for(s=_subsidies; s != endof(_subsidies); s++) { tron@2469: if (s->cargo_type != CT_INVALID && s->age < 12) { truelight@0: y -= 10; truelight@0: if (y < 0) goto handle_click; truelight@0: num++; truelight@0: } truelight@0: } truelight@0: truelight@0: if (num == 0) { truelight@0: y -= 10; truelight@0: if (y < 0) return; truelight@0: } truelight@0: truelight@0: y -= 11; truelight@0: if (y < 0) return; truelight@0: truelight@0: for(s=_subsidies; s != endof(_subsidies); s++) { tron@2469: if (s->cargo_type != CT_INVALID && s->age >= 12) { truelight@0: y -= 10; truelight@0: if (y < 0) goto handle_click; truelight@0: } truelight@0: } truelight@0: return; truelight@193: truelight@0: handle_click: truelight@0: truelight@0: /* determine from coordinate for subsidy and try to scroll to it */ truelight@0: offs = s->from; truelight@0: if (s->age >= 12) { truelight@919: xy = GetStation(offs)->xy; truelight@0: } else if (s->cargo_type == CT_PASSENGERS || s->cargo_type == CT_MAIL) { truelight@919: xy = GetTown(offs)->xy; truelight@0: } else { truelight@919: xy = GetIndustry(offs)->xy; truelight@193: truelight@0: } truelight@0: if (!ScrollMainWindowToTile(xy)) { truelight@0: /* otherwise determine to coordinate for subsidy and scroll to it */ truelight@0: offs = s->to; truelight@0: if (s->age >= 12) { truelight@919: xy = GetStation(offs)->xy; truelight@0: } else if (s->cargo_type == CT_PASSENGERS || s->cargo_type == CT_MAIL || s->cargo_type == CT_GOODS || s->cargo_type == CT_FOOD) { truelight@919: xy = GetTown(offs)->xy; truelight@0: } else { truelight@919: xy = GetIndustry(offs)->xy; truelight@0: } truelight@0: ScrollMainWindowToTile(xy); truelight@0: } truelight@0: } truelight@0: truelight@0: static void DrawSubsidiesWindow(Window *w) truelight@0: { truelight@0: YearMonthDay ymd; truelight@0: Subsidy *s; truelight@0: int x,xt,y,num,x2; truelight@0: Player *p; truelight@0: truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: ConvertDayToYMD(&ymd, _date); truelight@0: truelight@0: y = 15; truelight@0: x = 1; truelight@0: DrawString(x, y, STR_2026_SUBSIDIES_ON_OFFER_FOR, 0); truelight@0: y += 10; truelight@0: num = 0; truelight@0: truelight@0: for(s=_subsidies; s != endof(_subsidies); s++) { tron@2469: if (s->cargo_type != CT_INVALID && s->age < 12) { truelight@0: SetupSubsidyDecodeParam(s, 1); truelight@0: x2 = DrawString(x+2, y, STR_2027_FROM_TO, 0); truelight@193: tron@534: SetDParam(0, _date - ymd.day + 384 - s->age * 32); truelight@0: DrawString(x2, y, STR_2028_BY, 0); truelight@0: y += 10; truelight@0: num++; truelight@0: } truelight@0: } truelight@0: truelight@0: if (num == 0) { truelight@0: DrawString(x+2, y, STR_202A_NONE, 0); truelight@0: y += 10; truelight@0: } truelight@0: truelight@0: DrawString(x, y+1, STR_202B_SERVICES_ALREADY_SUBSIDISED, 0); truelight@0: y += 10; truelight@0: num = 0; truelight@0: truelight@0: for(s=_subsidies; s != endof(_subsidies); s++) { tron@2469: if (s->cargo_type != CT_INVALID && s->age >= 12) { truelight@0: SetupSubsidyDecodeParam(s, 1); truelight@0: celestar@1962: p = GetPlayer(GetStation(s->to)->owner); tron@534: SetDParam(3, p->name_1); tron@534: SetDParam(4, p->name_2); truelight@0: truelight@0: xt = DrawString(x+2, y, STR_202C_FROM_TO, 0); truelight@0: tron@534: SetDParam(0, _date - ymd.day + 768 - s->age * 32); truelight@0: DrawString(xt, y, STR_202D_UNTIL, 0); truelight@0: y += 10; truelight@0: num++; truelight@0: } truelight@0: } truelight@0: truelight@0: if (num == 0) { truelight@0: DrawString(x+2, y, STR_202A_NONE, 0); truelight@0: } truelight@0: } truelight@0: truelight@0: static void SubsidiesListWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: DrawSubsidiesWindow(w); break; truelight@0: case WE_CLICK: { truelight@0: switch(e->click.widget) { truelight@0: case 2: HandleSubsidyClick(e->click.pt.y - 25); break; truelight@0: } truelight@0: } truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _subsidies_list_widgets[] = { truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 13, 11, 629, 0, 13, STR_2025_SUBSIDIES, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_PANEL, RESIZE_NONE, 13, 0, 629, 14, 126, 0x0, STR_01FD_CLICK_ON_SERVICE_TO_CENTER}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _subsidies_list_desc = { truelight@0: -1, -1, 630, 127, truelight@0: WC_SUBSIDIES_LIST,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _subsidies_list_widgets, truelight@0: SubsidiesListWndProc truelight@0: }; truelight@0: truelight@0: tron@1093: void ShowSubsidiesList(void) truelight@0: { truelight@0: AllocateWindowDescFront(&_subsidies_list_desc, 0); truelight@0: }