From 6ccbfffbeabf2c7c814a5b251265201f86581571 Mon Sep 17 00:00:00 2001 From: bjarni Date: Mon, 22 Jan 2007 02:09:51 +0000 Subject: [PATCH] (svn r8338) -Codechange: merged road vehicle build window into the other ones Note: now all build vehicle windows are merged into build_vehicle_gui.cpp --- src/build_vehicle_gui.cpp | 78 +++++++++++++++- src/depot_gui.cpp | 10 +-- src/roadveh.h | 1 + src/roadveh_gui.cpp | 183 -------------------------------------- src/vehicle_gui.cpp | 22 +---- src/vehicle_gui.h | 2 - 6 files changed, 80 insertions(+), 216 deletions(-) diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index a8dbf7b75c..de4c35f3e7 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -3,6 +3,7 @@ #include "stdafx.h" #include "openttd.h" #include "train.h" +#include "roadveh.h" #include "ship.h" #include "aircraft.h" #include "debug.h" @@ -75,6 +76,14 @@ static void SetupWindowStrings(const Window *w, byte type) w->widget[BUILD_VEHICLE_WIDGET_RENAME].data = STR_8820_RENAME; w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_8845_RENAME_TRAIN_VEHICLE_TYPE; break; + case VEH_Road: + w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data = STR_9006_NEW_ROAD_VEHICLES; + w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips = STR_9026_ROAD_VEHICLE_SELECTION; + w->widget[BUILD_VEHICLE_WIDGET_BUILD].data = STR_9007_BUILD_VEHICLE; + w->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips = STR_9027_BUILD_THE_HIGHLIGHTED_ROAD; + w->widget[BUILD_VEHICLE_WIDGET_RENAME].data = STR_9034_RENAME; + w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_9035_RENAME_ROAD_VEHICLE_TYPE; + break; case VEH_Ship: w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data = STR_9808_NEW_SHIPS; w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips = STR_9825_SHIP_SELECTION_LIST_CLICK; @@ -416,6 +425,32 @@ static int DrawVehiclePurchaseInfo(int x, int y, EngineID engine_number, const R return y; } +/* Draw road vehicle specific details */ +static int DrawVehiclePurchaseInfo(int x, int y, EngineID engine_number, const RoadVehicleInfo *rvi) +{ + bool refittable = (_engine_info[engine_number].refit_mask != 0); + + /* Purchase cost - Max speed */ + SetDParam(0, rvi->base_cost * (_price.roadveh_base>>3)>>5); + SetDParam(1, rvi->max_speed / 2); + DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0); + y += 10; + + /* Running cost */ + SetDParam(0, rvi->running_cost * _price.roadveh_running >> 8); + DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0); + y += 10; + + /* Cargo type + capacity */ + SetDParam(0, rvi->cargo_type); + SetDParam(1, rvi->capacity); + SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY); + DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0); + y += 10; + + return y; +} + /* Draw ship specific details */ static int DrawVehiclePurchaseInfo(int x, int y, EngineID engine_number, const ShipVehicleInfo *svi) { @@ -511,13 +546,15 @@ void DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number) y += 10; } break; + case VEH_Road: + y = DrawVehiclePurchaseInfo(x, y, engine_number, RoadVehInfo(engine_number)); + break; case VEH_Ship: y = DrawVehiclePurchaseInfo(x, y, engine_number, ShipVehInfo(engine_number)); break; case VEH_Aircraft: y = DrawVehiclePurchaseInfo(x, y, engine_number, AircraftVehInfo(engine_number)); break; - default: NOT_REACHED(); } /* Draw details, that applies to all types except rail wagons */ @@ -598,7 +635,26 @@ static void GenerateBuildTrainList(Window *w) EngList_SortPartial(&bv->eng_list, _sorter[0][bv->sort_criteria], num_engines, num_wagons); } -/* Figure out what aircraft EngineIDs to put in the list */ +/* Figure out what road vehicle EngineIDs to put in the list */ +static void GenerateBuildRoadVehList(Window *w) +{ + EngineID eid, sel_id; + buildvehicle_d *bv = &WP(w, buildvehicle_d); + + EngList_RemoveAll(&bv->eng_list); + + sel_id = INVALID_ENGINE; + + for (eid = ROAD_ENGINES_INDEX; eid < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; eid++) { + if (!IsEngineBuildable(eid, VEH_Road, _local_player)) continue; + EngList_Add(&bv->eng_list, eid); + + if (eid == bv->sel_engine) sel_id = eid; + } + bv->sel_engine = sel_id; +} + +/* Figure out what ship EngineIDs to put in the list */ static void GenerateBuildShipList(Window *w) { EngineID eid, sel_id; @@ -664,6 +720,9 @@ static void GenerateBuildList(Window *w) case VEH_Train: GenerateBuildTrainList(w); return; // trains should not reach the last sorting + case VEH_Road: + GenerateBuildRoadVehList(w); + break; case VEH_Ship: GenerateBuildShipList(w); break; @@ -701,6 +760,14 @@ static void DrawBuildVehicleWindow(Window *w) DrawTrainEngine(x + 29, y + 6, engine, GetEnginePalette(engine, _local_player)); } break; + case VEH_Road: + for (; position < max; position++, y += 14) { + const EngineID engine = bv->eng_list[position]; + + DrawString(x + 58, y + 2, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10); + DrawRoadVehEngine(x + 28, y + 6, engine, GetEnginePalette(engine, _local_player)); + } + break; case VEH_Ship: for (; position < max; position++, y += 24) { const EngineID engine = bv->eng_list[position]; @@ -760,6 +827,9 @@ static void BuildVehicleClickEvent(Window *w, WindowEvent *e) DoCommandP(w->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->flags & RVI_WAGON) ? CcBuildWagon : CcBuildLoco, CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE)); break; + case VEH_Road: + DoCommandP(w->window_number, sel_eng, 0, CcBuildRoadVeh, CMD_BUILD_ROAD_VEH | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE)); + break; case VEH_Ship: DoCommandP(w->window_number, sel_eng, 0, CcBuildShip, CMD_BUILD_SHIP | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP)); break; @@ -779,6 +849,7 @@ static void BuildVehicleClickEvent(Window *w, WindowEvent *e) bv->rename_engine = sel_eng; switch (bv->vehicle_type) { case VEH_Train: str = STR_886A_RENAME_TRAIN_VEHICLE_TYPE; break; + case VEH_Road: str = STR_9036_RENAME_ROAD_VEHICLE_TYPE; break; case VEH_Ship: str = STR_9838_RENAME_SHIP_TYPE; break; case VEH_Aircraft: str = STR_A039_RENAME_AIRCRAFT_TYPE; break; } @@ -821,6 +892,7 @@ static void NewVehicleWndProc(Window *w, WindowEvent *e) _cmd_text = e->we.edittext.str; switch (bv->vehicle_type) { case VEH_Train: str = STR_886B_CAN_T_RENAME_TRAIN_VEHICLE; break; + case VEH_Road: str = STR_9037_CAN_T_RENAME_ROAD_VEHICLE; break; case VEH_Ship: str = STR_9839_CAN_T_RENAME_SHIP_TYPE; break; case VEH_Aircraft: str = STR_A03A_CAN_T_RENAME_AIRCRAFT_TYPE; break; } @@ -889,6 +961,8 @@ void ShowBuildVehicleWindow(TileIndex tile, byte type) WP(w,buildvehicle_d).filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile); ResizeWindow(w, 0, 16); break; + case VEH_Road: + ResizeWindow(w, 20, 16); case VEH_Ship: ResizeWindow(w, 27, 0); break; diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index bae5637fea..71ab1e799f 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -735,15 +735,7 @@ static void DepotWndProc(Window *w, WindowEvent *e) case DEPOT_WIDGET_BUILD: // Build vehicle ResetObjectToPlace(); - switch (WP(w, depot_d).type) { - case VEH_Road: ShowBuildRoadVehWindow(w->window_number); break; - case VEH_Ship: - case VEH_Train: - case VEH_Aircraft: - ShowBuildVehicleWindow(w->window_number, WP(w, depot_d).type); - break; - default: NOT_REACHED(); - } + ShowBuildVehicleWindow(w->window_number, WP(w, depot_d).type); break; case DEPOT_WIDGET_CLONE: // Clone button diff --git a/src/roadveh.h b/src/roadveh.h index e0c497b467..7490d35d88 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -17,6 +17,7 @@ static inline bool IsRoadVehInDepotStopped(const Vehicle* v) return IsRoadVehInDepot(v) && v->vehstatus & VS_STOPPED; } +void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2); void CcCloneRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2); #endif /* ROADVEH_H */ diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp index c112f5891e..8d525f3955 100644 --- a/src/roadveh_gui.cpp +++ b/src/roadveh_gui.cpp @@ -22,53 +22,6 @@ #include "newgrf_engine.h" #include "date.h" -/** - * Draw the purchase info details of road vehicle at a given location. - * @param x,y location where to draw the info - * @param engine_number the engine of which to draw the info of - */ -void DrawRoadVehPurchaseInfo(int x, int y, uint w, EngineID engine_number) -{ - const RoadVehicleInfo *rvi = RoadVehInfo(engine_number); - const Engine *e = GetEngine(engine_number); - bool refittable = (_engine_info[engine_number].refit_mask != 0); - YearMonthDay ymd; - ConvertDateToYMD(e->intro_date, &ymd); - - /* Purchase cost - Max speed */ - SetDParam(0, rvi->base_cost * (_price.roadveh_base>>3)>>5); - SetDParam(1, rvi->max_speed / 2); - DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0); - y += 10; - - /* Running cost */ - SetDParam(0, rvi->running_cost * _price.roadveh_running >> 8); - DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0); - y += 10; - - /* Cargo type + capacity */ - SetDParam(0, rvi->cargo_type); - SetDParam(1, rvi->capacity); - SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY); - DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0); - y += 10; - - /* Design date - Life length */ - SetDParam(0, ymd.year); - SetDParam(1, e->lifelength); - DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0); - y += 10; - - /* Reliability */ - SetDParam(0, e->reliability * 100 >> 16); - DrawString(x, y, STR_PURCHASE_INFO_RELIABILITY, 0); - y += 10; - - /* Additional text from NewGRF */ - y += ShowAdditionalText(x, y, w, engine_number); - y += ShowRefitOptionsList(x, y, w, engine_number); -} - void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection) { SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); @@ -396,48 +349,6 @@ void ShowRoadVehViewWindow(const Vehicle *v) } } - -static void DrawNewRoadVehWindow(Window *w) -{ - EngineID selected_id; - EngineID e; - uint count; - int pos; - int sel; - int y; - - SetWindowWidgetDisabledState(w, 5, w->window_number == 0); - - count = 0; - for (e = ROAD_ENGINES_INDEX; e < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; e++) { - if (HASBIT(GetEngine(e)->player_avail, _local_player)) count++; - } - SetVScrollCount(w, count); - - DrawWindowWidgets(w); - - y = 15; - sel = WP(w,buildvehicle_d).sel_index; - pos = w->vscroll.pos; - selected_id = INVALID_ENGINE; - for (e = ROAD_ENGINES_INDEX; e < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; e++) { - if (!HASBIT(GetEngine(e)->player_avail, _local_player)) continue; - if (sel == 0) selected_id = e; - if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) { - DrawString(60, y + 2, GetCustomEngineName(e), sel == 0 ? 0xC : 0x10); - DrawRoadVehEngine(30, y + 6, e, GetEnginePalette(e, _local_player)); - y += 14; - } - sel--; - } - - WP(w,buildvehicle_d).sel_engine = selected_id; - if (selected_id != INVALID_ENGINE) { - const Widget *wi = &w->widget[4]; - DrawRoadVehPurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, selected_id); - } -} - void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2) { const Vehicle *v; @@ -451,97 +362,3 @@ void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2) } ShowRoadVehViewWindow(v); } - -static void NewRoadVehWndProc(Window *w, WindowEvent *e) -{ - switch (e->event) { - case WE_PAINT: - DrawNewRoadVehWindow(w); - break; - - case WE_CLICK: - switch (e->we.click.widget) { - case 2: { /* listbox */ - uint i = (e->we.click.pt.y - 14) / 14; - if (i < w->vscroll.cap) { - WP(w,buildvehicle_d).sel_index = i + w->vscroll.pos; - SetWindowDirty(w); - } - } break; - - case 5: { /* build */ - EngineID sel_eng = WP(w,buildvehicle_d).sel_engine; - if (sel_eng != INVALID_ENGINE) - DoCommandP(w->window_number, sel_eng, 0, CcBuildRoadVeh, CMD_BUILD_ROAD_VEH | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE)); - } break; - - case 6: { /* rename */ - EngineID sel_eng = WP(w,buildvehicle_d).sel_engine; - if (sel_eng != INVALID_ENGINE) { - WP(w,buildvehicle_d).rename_engine = sel_eng; - ShowQueryString(GetCustomEngineName(sel_eng), STR_9036_RENAME_ROAD_VEHICLE_TYPE, 31, 160, w, CS_ALPHANUMERAL); - } - } break; - } - break; - - case WE_ON_EDIT_TEXT: - if (e->we.edittext.str[0] != '\0') { - _cmd_text = e->we.edittext.str; - DoCommandP(0, WP(w, buildvehicle_d).rename_engine, 0, NULL, - CMD_RENAME_ENGINE | CMD_MSG(STR_9037_CAN_T_RENAME_ROAD_VEHICLE)); - } - break; - - case WE_RESIZE: { - if (e->we.sizing.diff.y == 0) break; - - w->vscroll.cap += e->we.sizing.diff.y / 14; - w->widget[2].data = (w->vscroll.cap << 8) + 1; - } break; - - } -} - -static const Widget _new_road_veh_widgets[] = { -{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, -{ WWT_CAPTION, RESIZE_NONE, 14, 11, 247, 0, 13, STR_9006_NEW_ROAD_VEHICLES, STR_018C_WINDOW_TITLE_DRAG_THIS}, -{ WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 235, 14, 125, 0x801, STR_9026_ROAD_VEHICLE_SELECTION}, -{ WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 236, 247, 14, 125, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, -{ WWT_PANEL, RESIZE_TB, 14, 0, 247, 126, 217, 0x0, STR_NULL}, -{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 117, 218, 229, STR_9007_BUILD_VEHICLE, STR_9027_BUILD_THE_HIGHLIGHTED_ROAD}, -{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 118, 235, 218, 229, STR_9034_RENAME, STR_9035_RENAME_ROAD_VEHICLE_TYPE}, -{ WWT_RESIZEBOX, RESIZE_TB, 14, 236, 247, 218, 229, 0x0, STR_RESIZE_BUTTON}, -{ WIDGETS_END}, -}; - -static const WindowDesc _new_road_veh_desc = { - WDP_AUTO, WDP_AUTO, 248, 230, - WC_BUILD_VEHICLE,0, - WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, - _new_road_veh_widgets, - NewRoadVehWndProc -}; - -void ShowBuildRoadVehWindow(TileIndex tile) -{ - Window *w; - - DeleteWindowById(WC_BUILD_VEHICLE, tile); - - w = AllocateWindowDescFront(&_new_road_veh_desc, tile); - w->vscroll.cap = 8; - w->widget[2].data = (w->vscroll.cap << 8) + 1; - - w->resize.step_height = 14; - w->resize.height = w->height - 14 * 4; /* Minimum of 4 vehicles in the display */ - - if (tile != 0) { - w->caption_color = GetTileOwner(tile); - } else { - w->caption_color = _local_player; - } -} - - - diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index fa88841ff3..9a6db32673 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1045,19 +1045,6 @@ static void DrawEngineArrayInReplaceWindow(Window *w, int x, int y, int x2, int } } -static void DrawVehiclePurchaseInfoLocal(const int x, const int y, uint w, const EngineID engine_number) -{ - switch (GetEngine(engine_number)->type) { - case VEH_Road: DrawRoadVehPurchaseInfo(x, y, w, engine_number); break; - case VEH_Ship: - case VEH_Train: - case VEH_Aircraft: - DrawVehiclePurchaseInfo(x, y, w, engine_number); - break; - default: NOT_REACHED(); - } -} - static void ReplaceVehicleWndProc(Window *w, WindowEvent *e) { static const StringID _vehicle_type_names[] = { @@ -1141,7 +1128,7 @@ static void ReplaceVehicleWndProc(Window *w, WindowEvent *e) for (i = 0 ; i < 2 ; i++) { if (selected_id[i] != INVALID_ENGINE) { const Widget *wi = &w->widget[i == 0 ? 3 : 11]; - DrawVehiclePurchaseInfoLocal(wi->left + 2 , wi->top + 1, wi->right - wi->left - 2, selected_id[i]); + DrawVehiclePurchaseInfo(wi->left + 2 , wi->top + 1, wi->right - wi->left - 2, selected_id[i]); } } } break; // end of paint @@ -1737,12 +1724,7 @@ void PlayerVehWndProc(Window *w, WindowEvent *e) } break; case VLW_WIDGET_NEW_VEHICLES: - switch (vl->vehicle_type) { - case VEH_Road: ShowBuildRoadVehWindow(0); break; - case VEH_Ship: - case VEH_Train: - case VEH_Aircraft: ShowBuildVehicleWindow(0, vl->vehicle_type); break; - } + ShowBuildVehicleWindow(0, vl->vehicle_type); break; case VLW_WIDGET_MANAGE_VEHICLES: diff --git a/src/vehicle_gui.h b/src/vehicle_gui.h index 509435c925..0a7a9b0fe8 100644 --- a/src/vehicle_gui.h +++ b/src/vehicle_gui.h @@ -33,14 +33,12 @@ static inline bool ValidVLWFlags(uint16 flags) void PlayerVehWndProc(Window *w, WindowEvent *e); void DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number); -void DrawRoadVehPurchaseInfo(int x, int y, uint w, EngineID engine_number); void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection); void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection); void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection); void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection); -void ShowBuildRoadVehWindow(TileIndex tile); void ShowBuildVehicleWindow(TileIndex tile, byte type); void ChangeVehicleViewWindow(const Vehicle *from_v, const Vehicle *to_v);