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 "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: { tron@2630: const Subsidy* s; tron@2639: uint num; tron@2639: int offs; truelight@0: TileIndex xy; truelight@0: tron@2639: if (y < 0) return; truelight@0: truelight@0: num = 0; tron@2639: 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: tron@2639: 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: tron@2630: static void DrawSubsidiesWindow(const Window* w) truelight@0: { truelight@0: YearMonthDay ymd; tron@2630: const Subsidy* s; tron@2639: uint num; tron@2639: int x; tron@2639: int y; 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: tron@2639: for (s = _subsidies; s != endof(_subsidies); s++) { tron@2469: if (s->cargo_type != CT_INVALID && s->age < 12) { tron@2639: int x2; tron@2639: truelight@0: SetupSubsidyDecodeParam(s, 1); tron@2639: 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) { tron@2639: DrawString(x + 2, y, STR_202A_NONE, 0); truelight@0: y += 10; truelight@0: } truelight@0: tron@2639: DrawString(x, y + 1, STR_202B_SERVICES_ALREADY_SUBSIDISED, 0); truelight@0: y += 10; truelight@0: num = 0; truelight@0: tron@2639: for (s = _subsidies; s != endof(_subsidies); s++) { tron@2469: if (s->cargo_type != CT_INVALID && s->age >= 12) { tron@2630: const Player* p; tron@2639: int xt; tron@2630: 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: tron@2639: 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: tron@2639: if (num == 0) DrawString(x + 2, y, STR_202A_NONE, 0); truelight@0: } truelight@0: truelight@0: static void SubsidiesListWndProc(Window *w, WindowEvent *e) truelight@0: { tron@2639: switch (e->event) { tron@2639: case WE_PAINT: DrawSubsidiesWindow(w); break; tron@2639: tron@2639: case WE_CLICK: tron@2639: switch (e->click.widget) { Darkvater@2857: case 3: HandleSubsidyClick(e->click.pt.y - 25); break; tron@2639: } tron@2639: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _subsidies_list_widgets[] = { Darkvater@2857: { WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, Darkvater@2857: { WWT_CAPTION, RESIZE_NONE, 13, 11, 617, 0, 13, STR_2025_SUBSIDIES, STR_018C_WINDOW_TITLE_DRAG_THIS}, Darkvater@2857: { WWT_STICKYBOX, RESIZE_NONE, 13, 618, 629, 0, 13, STR_NULL, STR_STICKY_BUTTON}, Darkvater@2857: { WWT_PANEL, RESIZE_NONE, 13, 0, 629, 14, 126, STR_NULL, 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, Darkvater@2857: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, 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: }