tron@2186: /* $Id$ */ tron@2186: belugas@6916: /** @file subsidy_gui.cpp */ belugas@6916: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" rubidium@9281: #include "station_base.h" truelight@0: #include "industry.h" truelight@0: #include "town.h" rubidium@8612: #include "economy_func.h" tron@2159: #include "variables.h" peter1138@6654: #include "cargotype.h" rubidium@8602: #include "window_gui.h" rubidium@8610: #include "strings_func.h" rubidium@8636: #include "date_func.h" rubidium@8720: #include "viewport_func.h" rubidium@8720: #include "gfx_func.h" truelight@0: rubidium@8760: #include "table/strings.h" rubidium@8760: truelight@0: static void HandleSubsidyClick(int y) truelight@193: { belugas@4171: 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: peter1138@6654: TownEffect te = GetCargo(s->cargo_type)->town_effect; peter1138@6654: 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; peter1138@6654: } else if (te == TE_PASSENGERS || te == TE_MAIL) { truelight@919: xy = GetTown(offs)->xy; truelight@0: } else { truelight@919: xy = GetIndustry(offs)->xy; peter1138@6654: } truelight@193: 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; peter1138@6654: } else if (te == TE_PASSENGERS || te == TE_MAIL || te == TE_GOODS || te == TE_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: belugas@4171: static void DrawSubsidiesWindow(const Window *w) truelight@0: { truelight@0: YearMonthDay ymd; belugas@4171: const Subsidy *s; tron@2639: uint num; tron@2639: int x; tron@2639: int y; truelight@0: truelight@0: DrawWindowWidgets(w); truelight@0: rubidium@4288: ConvertDateToYMD(_date, &ymd); truelight@0: belugas@9309: int width = w->width - 13; // scroll bar = 11 + pixel each side truelight@0: y = 15; truelight@0: x = 1; belugas@10077: belugas@10077: /* Section for drawing the offered subisidies */ rubidium@8452: DrawStringTruncated(x, y, STR_2026_SUBSIDIES_ON_OFFER_FOR, TC_FROMSTRING, width); 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: belugas@10077: /* Displays the two offered towns */ truelight@0: SetupSubsidyDecodeParam(s, 1); rubidium@8452: x2 = DrawStringTruncated(x + 2, y, STR_2027_FROM_TO, TC_FROMSTRING, width); truelight@193: belugas@10077: /* Displays the deadline before voiding the proposal */ tron@534: SetDParam(0, _date - ymd.day + 384 - s->age * 32); rubidium@8452: DrawStringTruncated(x2, y, STR_2028_BY, TC_FROMSTRING, width - x2); truelight@0: y += 10; truelight@0: num++; truelight@0: } truelight@0: } truelight@0: truelight@0: if (num == 0) { rubidium@8452: DrawStringTruncated(x + 2, y, STR_202A_NONE, TC_FROMSTRING, width - 2); truelight@0: y += 10; truelight@0: } truelight@0: belugas@10077: /* Section for drawing the already granted subisidies */ rubidium@8452: DrawStringTruncated(x, y + 1, STR_202B_SERVICES_ALREADY_SUBSIDISED, TC_FROMSTRING, width); 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 xt; tron@2630: truelight@0: SetupSubsidyDecodeParam(s, 1); truelight@0: peter1138@7554: PlayerID player = GetStation(s->to)->owner; peter1138@7554: SetDParam(3, player); truelight@0: belugas@10077: /* Displays the two connected stations */ rubidium@8452: xt = DrawStringTruncated(x + 2, y, STR_202C_FROM_TO, TC_FROMSTRING, width - 2); truelight@0: belugas@10077: /* Displays the date where the granted subsidy will end */ belugas@10077: if ((xt > 3) && (width - xt) > 9 ) { // do not draw if previous drawing failed or if it will overlap on scrollbar belugas@9309: SetDParam(0, _date - ymd.day + 768 - s->age * 32); belugas@9309: DrawStringTruncated(xt, y, STR_202D_UNTIL, TC_FROMSTRING, width - xt); belugas@9309: } truelight@0: y += 10; truelight@0: num++; truelight@0: } truelight@0: } truelight@0: rubidium@8452: if (num == 0) DrawStringTruncated(x + 2, y, STR_202A_NONE, TC_FROMSTRING, width - 2); 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: belugas@4634: switch (e->we.click.widget) { belugas@4634: case 3: belugas@4634: HandleSubsidyClick(e->we.click.pt.y - 25); belugas@4634: break; tron@2639: } tron@2639: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _subsidies_list_widgets[] = { belugas@9309: { WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, belugas@9309: { WWT_CAPTION, RESIZE_RIGHT, 13, 11, 307, 0, 13, STR_2025_SUBSIDIES, STR_018C_WINDOW_TITLE_DRAG_THIS}, belugas@9309: { WWT_STICKYBOX, RESIZE_LR, 13, 308, 319, 0, 13, STR_NULL, STR_STICKY_BUTTON}, belugas@9309: { WWT_PANEL, RESIZE_RB, 13, 0, 307, 14, 126, 0x0, STR_01FD_CLICK_ON_SERVICE_TO_CENTER}, belugas@10077: { WWT_SCROLLBAR, RESIZE_LRB, 13, 308, 319, 14, 114, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, belugas@10077: { WWT_RESIZEBOX, RESIZE_LRTB, 13, 308, 319, 115, 126, 0x0, STR_RESIZE_BUTTON}, belugas@9309: darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _subsidies_list_desc = { belugas@9309: WDP_AUTO, WDP_AUTO, 320, 127, 320, 127, rubidium@6144: WC_SUBSIDIES_LIST, WC_NONE, belugas@9309: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE, truelight@0: _subsidies_list_widgets, truelight@0: SubsidiesListWndProc truelight@0: }; truelight@0: truelight@0: rubidium@6573: void ShowSubsidiesList() truelight@0: { truelight@0: AllocateWindowDescFront(&_subsidies_list_desc, 0); truelight@0: }