truelight@0: #include "stdafx.h" truelight@0: #include "ttd.h" tron@507: #include "table/strings.h" truelight@0: #include "window.h" truelight@0: #include "gui.h" truelight@0: #include "viewport.h" truelight@0: #include "gfx.h" truelight@0: #include "engine.h" truelight@0: #include "command.h" truelight@0: #include "news.h" truelight@0: truelight@0: tron@1095: static StringID GetEngineCategoryName(byte engine) truelight@0: { darkvater@460: if (engine < NUM_TRAIN_ENGINES) { darkvater@460: switch (_engines[engine].railtype) { darkvater@460: case 0: darkvater@460: return STR_8102_RAILROAD_LOCOMOTIVE; darkvater@460: case 1: darkvater@460: return STR_8106_MONORAIL_LOCOMOTIVE; darkvater@460: case 2: darkvater@460: return STR_8107_MAGLEV_LOCOMOTIVE; darkvater@460: } darkvater@460: } truelight@0: truelight@0: if (engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) truelight@0: return STR_8103_ROAD_VEHICLE; truelight@0: truelight@0: if (engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) truelight@0: return STR_8105_SHIP; truelight@0: truelight@0: return STR_8104_AIRCRAFT; truelight@0: } truelight@0: truelight@0: static const Widget _engine_preview_widgets[] = { truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 5, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 5, 11, 299, 0, 13, STR_8100_MESSAGE_FROM_VEHICLE_MANUFACTURE, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_IMGBTN, RESIZE_NONE, 5, 0, 299, 14, 191, 0x0, STR_NULL}, truelight@867: { WWT_PUSHTXTBTN, RESIZE_NONE, 5, 85, 144, 172, 183, STR_00C9_NO, STR_NULL}, truelight@867: { WWT_PUSHTXTBTN, RESIZE_NONE, 5, 155, 214, 172, 183, STR_00C8_YES, STR_NULL}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: typedef void DrawEngineProc(int x, int y, int engine, uint32 image_ormod); truelight@0: typedef void DrawEngineInfoProc(int x, int y, int engine, int maxw); truelight@0: truelight@0: typedef struct DrawEngineInfo { truelight@0: DrawEngineProc *engine_proc; truelight@0: DrawEngineInfoProc *info_proc; truelight@0: } DrawEngineInfo; truelight@0: truelight@0: static const DrawEngineInfo _draw_engine_list[4] = { truelight@0: {DrawTrainEngine,DrawTrainEngineInfo}, truelight@0: {DrawRoadVehEngine,DrawRoadVehEngineInfo}, truelight@0: {DrawShipEngine,DrawShipEngineInfo}, truelight@0: {DrawAircraftEngine,DrawAircraftEngineInfo}, truelight@0: }; truelight@0: truelight@0: static void EnginePreviewWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: byte eng; truelight@0: int engine; truelight@0: const DrawEngineInfo *dei; truelight@0: int width; truelight@0: truelight@0: switch(e->event) { truelight@0: case WE_PAINT: truelight@0: DrawWindowWidgets(w); truelight@0: engine = w->window_number; truelight@0: tron@534: SetDParam(0, GetEngineCategoryName(engine)); truelight@0: DrawStringMultiCenter(150, 44, STR_8101_WE_HAVE_JUST_DESIGNED_A, 296); truelight@0: truelight@0: DrawStringCentered(w->width >> 1, 80, GetCustomEngineName(engine), 0x10); truelight@0: truelight@0: eng = (byte)engine; truelight@0: (dei = _draw_engine_list,eng < NUM_TRAIN_ENGINES) || truelight@0: (dei++,eng < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) || truelight@0: (dei++,eng < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) || truelight@0: (dei++, true); truelight@0: truelight@0: width = w->width; truelight@0: dei->engine_proc(width >> 1, 100, engine, 0); truelight@0: dei->info_proc(engine, width >> 1, 130, width - 52); truelight@0: break; truelight@0: truelight@0: case WE_CLICK: truelight@0: switch(e->click.widget) { truelight@0: case 3: DeleteWindow(w); break; truelight@193: case 4: truelight@0: DoCommandP(0, w->window_number, 0, NULL, CMD_WANT_ENGINE_PREVIEW); truelight@0: DeleteWindow(w); truelight@0: break; truelight@0: } truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const WindowDesc _engine_preview_desc = { truelight@0: WDP_CENTER, WDP_CENTER, 300, 192, truelight@0: WC_ENGINE_PREVIEW,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _engine_preview_widgets, truelight@0: EnginePreviewWndProc truelight@0: }; truelight@0: truelight@0: truelight@0: void ShowEnginePreviewWindow(int engine) truelight@0: { truelight@0: Window *w; truelight@0: truelight@0: w = AllocateWindowDesc(&_engine_preview_desc); truelight@0: w->window_number = engine; truelight@0: } truelight@0: truelight@0: void DrawNewsNewTrainAvail(Window *w) truelight@0: { truelight@0: int engine; truelight@0: truelight@0: DrawNewsBorder(w); truelight@0: truelight@0: engine = WP(w,news_d).ni->string_id; tron@534: SetDParam(0, GetEngineCategoryName(engine)); truelight@0: DrawStringMultiCenter(w->width >> 1, 20, STR_8859_NEW_NOW_AVAILABLE, w->width - 2); truelight@0: truelight@0: GfxFillRect(25, 56, w->width - 25, w->height - 2, 10); truelight@0: tron@534: SetDParam(0, GetCustomEngineName(engine)); truelight@0: DrawStringMultiCenter(w->width >> 1, 57, STR_885A, w->width - 2); truelight@0: truelight@0: DrawTrainEngine(w->width >> 1, 88, engine, 0); truelight@0: GfxFillRect(25, 56, w->width - 56, 112, 0x4323); truelight@0: DrawTrainEngineInfo(engine, w->width >> 1, 129, w->width - 52); truelight@0: } truelight@0: truelight@0: StringID GetNewsStringNewTrainAvail(NewsItem *ni) truelight@0: { truelight@0: int engine = ni->string_id; tron@534: SetDParam(0, STR_8859_NEW_NOW_AVAILABLE); tron@534: SetDParam(1, GetEngineCategoryName(engine)); tron@534: SetDParam(2, GetCustomEngineName(engine)); truelight@0: return STR_02B6; truelight@0: } truelight@0: truelight@0: void DrawNewsNewAircraftAvail(Window *w) truelight@0: { truelight@0: int engine; truelight@0: truelight@0: DrawNewsBorder(w); truelight@0: truelight@0: engine = WP(w,news_d).ni->string_id; truelight@193: truelight@0: DrawStringMultiCenter(w->width >> 1, 20, STR_A02C_NEW_AIRCRAFT_NOW_AVAILABLE, w->width - 2); truelight@0: GfxFillRect(25, 56, w->width - 25, w->height - 2, 10); truelight@0: tron@534: SetDParam(0, GetCustomEngineName(engine)); truelight@0: DrawStringMultiCenter(w->width >> 1, 57, STR_A02D, w->width - 2); truelight@0: truelight@0: DrawAircraftEngine(w->width >> 1, 93, engine, 0); truelight@0: GfxFillRect(25, 56, w->width - 56, 110, 0x4323); truelight@0: DrawAircraftEngineInfo(engine, w->width >> 1, 131, w->width - 52); truelight@0: } truelight@0: truelight@0: StringID GetNewsStringNewAircraftAvail(NewsItem *ni) truelight@0: { truelight@0: int engine = ni->string_id; tron@534: SetDParam(0, STR_A02C_NEW_AIRCRAFT_NOW_AVAILABLE); tron@534: SetDParam(1, GetCustomEngineName(engine)); truelight@0: return STR_02B6; truelight@0: } truelight@0: truelight@0: void DrawNewsNewRoadVehAvail(Window *w) truelight@0: { truelight@0: int engine; truelight@0: truelight@0: DrawNewsBorder(w); truelight@0: truelight@0: engine = WP(w,news_d).ni->string_id; truelight@0: DrawStringMultiCenter(w->width >> 1, 20, STR_9028_NEW_ROAD_VEHICLE_NOW_AVAILABLE, w->width - 2); truelight@0: GfxFillRect(25, 56, w->width - 25, w->height - 2, 10); truelight@0: tron@534: SetDParam(0, GetCustomEngineName(engine)); truelight@0: DrawStringMultiCenter(w->width >> 1, 57, STR_9029, w->width - 2); truelight@0: truelight@0: DrawRoadVehEngine(w->width >> 1, 88, engine, 0); truelight@0: GfxFillRect(25, 56, w->width - 56, 112, 0x4323); truelight@0: DrawRoadVehEngineInfo(engine, w->width >> 1, 129, w->width - 52); truelight@0: } truelight@0: truelight@0: StringID GetNewsStringNewRoadVehAvail(NewsItem *ni) truelight@0: { truelight@0: int engine = ni->string_id; tron@534: SetDParam(0, STR_9028_NEW_ROAD_VEHICLE_NOW_AVAILABLE); tron@534: SetDParam(1, GetCustomEngineName(engine)); truelight@0: return STR_02B6; truelight@0: } truelight@0: truelight@0: void DrawNewsNewShipAvail(Window *w) truelight@0: { truelight@0: int engine; truelight@0: truelight@0: DrawNewsBorder(w); truelight@0: truelight@0: engine = WP(w,news_d).ni->string_id; truelight@193: truelight@0: DrawStringMultiCenter(w->width >> 1, 20, STR_982C_NEW_SHIP_NOW_AVAILABLE, w->width - 2); truelight@0: GfxFillRect(25, 56, w->width - 25, w->height - 2, 10); truelight@0: tron@534: SetDParam(0, GetCustomEngineName(engine)); truelight@0: DrawStringMultiCenter(w->width >> 1, 57, STR_982D, w->width - 2); truelight@0: truelight@0: DrawShipEngine(w->width >> 1, 93, engine, 0); truelight@0: GfxFillRect(25, 56, w->width - 56, 110, 0x4323); truelight@0: DrawShipEngineInfo(engine, w->width >> 1, 131, w->width - 52); truelight@0: } truelight@0: truelight@0: StringID GetNewsStringNewShipAvail(NewsItem *ni) truelight@0: { truelight@0: int engine = ni->string_id; tron@534: SetDParam(0, STR_982C_NEW_SHIP_NOW_AVAILABLE); tron@534: SetDParam(1, GetCustomEngineName(engine)); truelight@0: return STR_02B6; truelight@0: }