00001
00002
00005 #include "stdafx.h"
00006 #include "openttd.h"
00007 #include "station.h"
00008 #include "industry.h"
00009 #include "town.h"
00010 #include "economy_func.h"
00011 #include "variables.h"
00012 #include "cargotype.h"
00013 #include "window_gui.h"
00014 #include "strings_func.h"
00015 #include "date_func.h"
00016 #include "viewport_func.h"
00017 #include "gfx_func.h"
00018
00019 #include "table/strings.h"
00020
00021 static void HandleSubsidyClick(int y)
00022 {
00023 const Subsidy *s;
00024 uint num;
00025 int offs;
00026 TileIndex xy;
00027
00028 if (y < 0) return;
00029
00030 num = 0;
00031 for (s = _subsidies; s != endof(_subsidies); s++) {
00032 if (s->cargo_type != CT_INVALID && s->age < 12) {
00033 y -= 10;
00034 if (y < 0) goto handle_click;
00035 num++;
00036 }
00037 }
00038
00039 if (num == 0) {
00040 y -= 10;
00041 if (y < 0) return;
00042 }
00043
00044 y -= 11;
00045 if (y < 0) return;
00046
00047 for (s = _subsidies; s != endof(_subsidies); s++) {
00048 if (s->cargo_type != CT_INVALID && s->age >= 12) {
00049 y -= 10;
00050 if (y < 0) goto handle_click;
00051 }
00052 }
00053 return;
00054
00055 handle_click:
00056
00057 TownEffect te = GetCargo(s->cargo_type)->town_effect;
00058
00059
00060 offs = s->from;
00061 if (s->age >= 12) {
00062 xy = GetStation(offs)->xy;
00063 } else if (te == TE_PASSENGERS || te == TE_MAIL) {
00064 xy = GetTown(offs)->xy;
00065 } else {
00066 xy = GetIndustry(offs)->xy;
00067 }
00068
00069 if (!ScrollMainWindowToTile(xy)) {
00070
00071 offs = s->to;
00072 if (s->age >= 12) {
00073 xy = GetStation(offs)->xy;
00074 } else if (te == TE_PASSENGERS || te == TE_MAIL || te == TE_GOODS || te == TE_FOOD) {
00075 xy = GetTown(offs)->xy;
00076 } else {
00077 xy = GetIndustry(offs)->xy;
00078 }
00079 ScrollMainWindowToTile(xy);
00080 }
00081 }
00082
00083 static void DrawSubsidiesWindow(const Window *w)
00084 {
00085 YearMonthDay ymd;
00086 const Subsidy *s;
00087 uint num;
00088 int x;
00089 int y;
00090
00091 DrawWindowWidgets(w);
00092
00093 ConvertDateToYMD(_date, &ymd);
00094
00095 int width = w->width - 2;
00096 y = 15;
00097 x = 1;
00098 DrawStringTruncated(x, y, STR_2026_SUBSIDIES_ON_OFFER_FOR, TC_FROMSTRING, width);
00099 y += 10;
00100 num = 0;
00101
00102 for (s = _subsidies; s != endof(_subsidies); s++) {
00103 if (s->cargo_type != CT_INVALID && s->age < 12) {
00104 int x2;
00105
00106 SetupSubsidyDecodeParam(s, 1);
00107 x2 = DrawStringTruncated(x + 2, y, STR_2027_FROM_TO, TC_FROMSTRING, width);
00108
00109 SetDParam(0, _date - ymd.day + 384 - s->age * 32);
00110 DrawStringTruncated(x2, y, STR_2028_BY, TC_FROMSTRING, width - x2);
00111 y += 10;
00112 num++;
00113 }
00114 }
00115
00116 if (num == 0) {
00117 DrawStringTruncated(x + 2, y, STR_202A_NONE, TC_FROMSTRING, width - 2);
00118 y += 10;
00119 }
00120
00121 DrawStringTruncated(x, y + 1, STR_202B_SERVICES_ALREADY_SUBSIDISED, TC_FROMSTRING, width);
00122 y += 10;
00123 num = 0;
00124
00125 for (s = _subsidies; s != endof(_subsidies); s++) {
00126 if (s->cargo_type != CT_INVALID && s->age >= 12) {
00127 int xt;
00128
00129 SetupSubsidyDecodeParam(s, 1);
00130
00131 PlayerID player = GetStation(s->to)->owner;
00132 SetDParam(3, player);
00133
00134 xt = DrawStringTruncated(x + 2, y, STR_202C_FROM_TO, TC_FROMSTRING, width - 2);
00135
00136 SetDParam(0, _date - ymd.day + 768 - s->age * 32);
00137 DrawStringTruncated(xt, y, STR_202D_UNTIL, TC_FROMSTRING, width - xt);
00138 y += 10;
00139 num++;
00140 }
00141 }
00142
00143 if (num == 0) DrawStringTruncated(x + 2, y, STR_202A_NONE, TC_FROMSTRING, width - 2);
00144 }
00145
00146 static void SubsidiesListWndProc(Window *w, WindowEvent *e)
00147 {
00148 switch (e->event) {
00149 case WE_PAINT: DrawSubsidiesWindow(w); break;
00150
00151 case WE_CLICK:
00152 switch (e->we.click.widget) {
00153 case 3:
00154 HandleSubsidyClick(e->we.click.pt.y - 25);
00155 break;
00156 }
00157 break;
00158 }
00159 }
00160
00161 static const Widget _subsidies_list_widgets[] = {
00162 { WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
00163 { WWT_CAPTION, RESIZE_RIGHT, 13, 11, 307, 0, 13, STR_2025_SUBSIDIES, STR_018C_WINDOW_TITLE_DRAG_THIS},
00164 { WWT_STICKYBOX, RESIZE_LR, 13, 308, 319, 0, 13, STR_NULL, STR_STICKY_BUTTON},
00165 { WWT_PANEL, RESIZE_RIGHT, 13, 0, 319, 14, 126, 0x0, STR_01FD_CLICK_ON_SERVICE_TO_CENTER},
00166 { WIDGETS_END},
00167 };
00168
00169 static const WindowDesc _subsidies_list_desc = {
00170 WDP_AUTO, WDP_AUTO, 320, 127, 630, 127,
00171 WC_SUBSIDIES_LIST, WC_NONE,
00172 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
00173 _subsidies_list_widgets,
00174 SubsidiesListWndProc
00175 };
00176
00177
00178 void ShowSubsidiesList()
00179 {
00180 AllocateWindowDescFront(&_subsidies_list_desc, 0);
00181 }