diff options
author | bjarni <bjarni@openttd.org> | 2007-01-22 00:26:46 +0000 |
---|---|---|
committer | bjarni <bjarni@openttd.org> | 2007-01-22 00:26:46 +0000 |
commit | 14b29980230f2862329bb3228e1051c0a316f62b (patch) | |
tree | 641962eb406e6ac06b8fac492379680153a55843 | |
parent | 1f32ce7e8932208993ef8bfc5c4124606f4ae6c3 (diff) | |
download | openttd-14b29980230f2862329bb3228e1051c0a316f62b.tar.xz |
(svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
-Codechange: the build ship window is merged into build_vehicle_gui.cpp
-rw-r--r-- | src/build_vehicle_gui.cpp | 108 | ||||
-rw-r--r-- | src/depot_gui.cpp | 2 | ||||
-rw-r--r-- | src/ship.h | 1 | ||||
-rw-r--r-- | src/ship_gui.cpp | 182 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 4 | ||||
-rw-r--r-- | src/vehicle_gui.h | 2 |
6 files changed, 110 insertions, 189 deletions
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 9ab3d4d0e..e957e9698 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 "ship.h" #include "aircraft.h" #include "debug.h" #include "functions.h" @@ -74,6 +75,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_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; + w->widget[BUILD_VEHICLE_WIDGET_BUILD].data = STR_9809_BUILD_SHIP; + w->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips = STR_9826_BUILD_THE_HIGHLIGHTED_SHIP; + w->widget[BUILD_VEHICLE_WIDGET_RENAME].data = STR_9836_RENAME; + w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_9837_RENAME_SHIP_TYPE; + break; case VEH_Aircraft: w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data = STR_A005_NEW_AIRCRAFT; w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips = STR_A025_AIRCRAFT_SELECTION_LIST; @@ -89,6 +98,9 @@ static bool _internal_sort_order; // descending/ascending static byte _last_sort_criteria_train = 0; static bool _last_sort_order_train = false; +static byte _last_sort_criteria_ship = 0; +static bool _last_sort_order_ship = false; + static byte _last_sort_criteria_aircraft = 0; static bool _last_sort_order_aircraft = false; @@ -305,6 +317,21 @@ static const StringID _train_sort_listing[] = { INVALID_STRING_ID }; +static EngList_SortTypeFunction * const _ship_sorter[] = { + &EngineNumberSorter, + &EngineIntroDateSorter, + &EngineNameSorter, + &EngineReliabilitySorter, +}; + +static const StringID _ship_sort_listing[] = { + STR_ENGINE_SORT_ENGINE_ID, + STR_ENGINE_SORT_INTRO_DATE, + STR_SORT_BY_DROPDOWN_NAME, + STR_SORT_BY_RELIABILITY, + INVALID_STRING_ID +}; + static EngList_SortTypeFunction * const _aircraft_sorter[] = { &EngineNumberSorter, &AircraftEngineCostSorter, @@ -392,6 +419,30 @@ static int DrawVehiclePurchaseInfo(int x, int y, EngineID engine_number, const R return y; } +/* Draw ship specific details */ +static int DrawVehiclePurchaseInfo(int x, int y, EngineID engine_number, const ShipVehicleInfo *svi) +{ + /* Purchase cost - Max speed */ + SetDParam(0, svi->base_cost * (_price.ship_base>>3)>>5); + SetDParam(1, svi->max_speed / 2); + DrawString(x,y, STR_PURCHASE_INFO_COST_SPEED, 0); + y += 10; + + /* Cargo type + capacity */ + SetDParam(0, svi->cargo_type); + SetDParam(1, svi->capacity); + SetDParam(2, svi->refittable ? STR_9842_REFITTABLE : STR_EMPTY); + DrawString(x,y, STR_PURCHASE_INFO_CAPACITY, 0); + y += 10; + + /* Running cost */ + SetDParam(0, svi->running_cost * _price.ship_running >> 8); + DrawString(x,y, STR_PURCHASE_INFO_RUNNINGCOST, 0); + y += 10; + + return y; +} + /* Draw aircraft specific details */ static int DrawVehiclePurchaseInfo(int x, int y, EngineID engine_number, const AircraftVehicleInfo *avi) { @@ -463,6 +514,9 @@ void DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number) y += 10; } 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; @@ -490,6 +544,10 @@ void DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number) const RailVehicleInfo *rvi = RailVehInfo(engine_number); if (rvi->capacity > 0) y += ShowRefitOptionsList(x, y, w, engine_number); } break; + case VEH_Ship: { + const ShipVehicleInfo *svi = ShipVehInfo(engine_number); + if (svi->refittable) y += ShowRefitOptionsList(x, y, w, engine_number); + } break; case VEH_Aircraft: y += ShowRefitOptionsList(x, y, w, engine_number); break; @@ -544,6 +602,25 @@ static void GenerateBuildTrainList(Window *w) } /* Figure out what aircraft EngineIDs to put in the list */ +static void GenerateBuildShipList(Window *w) +{ + EngineID eid, sel_id; + buildvehicle_d *bv = &WP(w, buildvehicle_d); + + EngList_RemoveAll(&bv->eng_list); + + sel_id = INVALID_ENGINE; + + for (eid = SHIP_ENGINES_INDEX; eid < SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES; eid++) { + if (!IsEngineBuildable(eid, VEH_Ship, _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 aircraft EngineIDs to put in the list */ static void GenerateBuildAircraftList(Window *w) { EngineID eid, sel_id; @@ -590,6 +667,11 @@ static void GenerateBuildList(Window *w) case VEH_Train: GenerateBuildTrainList(w); break; + case VEH_Ship: + GenerateBuildShipList(w); + _internal_sort_order = bv->descending_sort_order; + EngList_Sort(&bv->eng_list, _ship_sorter[bv->sort_criteria]); + break; case VEH_Aircraft: GenerateBuildAircraftList(w); _internal_sort_order = bv->descending_sort_order; @@ -624,6 +706,14 @@ static void DrawBuildVehicleWindow(Window *w) DrawTrainEngine(x + 29, y + 6, engine, GetEnginePalette(engine, _local_player)); } break; + case VEH_Ship: + for (; position < max; position++, y += 24) { + const EngineID engine = bv->eng_list[position]; + + DrawString(x + 75, y + 7, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10); + DrawShipEngine(x + 35, y + 10, engine, GetEnginePalette(engine, _local_player)); + } + break; case VEH_Aircraft: for (; position < max; position++, y += 24) { const EngineID engine = bv->eng_list[position]; @@ -643,6 +733,7 @@ static void DrawBuildVehicleWindow(Window *w) StringID str = STR_NULL; switch (bv->vehicle_type) { case VEH_Train: str = _train_sort_listing[bv->sort_criteria]; break; + case VEH_Ship: str = _ship_sort_listing[bv->sort_criteria]; break; case VEH_Aircraft: str = _aircraft_sort_listing[bv->sort_criteria]; break; } @@ -679,6 +770,9 @@ static void BuildVehicleClickEvent(Window *w, WindowEvent *e) case VEH_Train: ShowDropDownMenu(w, _train_sort_listing, bv->sort_criteria, BUILD_VEHICLE_WIDGET_SORT_DROPDOWN, 0, 0); break; + case VEH_Ship: + ShowDropDownMenu(w, _ship_sort_listing, bv->sort_criteria, BUILD_VEHICLE_WIDGET_SORT_DROPDOWN, 0, 0); + break; case VEH_Aircraft: ShowDropDownMenu(w, _aircraft_sort_listing, bv->sort_criteria, BUILD_VEHICLE_WIDGET_SORT_DROPDOWN, 0, 0); break; @@ -693,6 +787,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_Ship: + DoCommandP(w->window_number, sel_eng, 0, CcBuildShip, CMD_BUILD_SHIP | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP)); + break; case VEH_Aircraft: DoCommandP(w->window_number, sel_eng, 0, CcBuildAircraft, CMD_BUILD_AIRCRAFT | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT)); break; @@ -709,6 +806,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_Ship: str = STR_9838_RENAME_SHIP_TYPE; break; case VEH_Aircraft: str = STR_A039_RENAME_AIRCRAFT_TYPE; break; } ShowQueryString(GetCustomEngineName(sel_eng), str, 31, 160, w, CS_ALPHANUMERAL); @@ -750,6 +848,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_Ship: str = STR_9839_CAN_T_RENAME_SHIP_TYPE; break; case VEH_Aircraft: str = STR_A03A_CAN_T_RENAME_AIRCRAFT_TYPE; break; } DoCommandP(0, bv->rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(str)); @@ -762,6 +861,7 @@ static void NewVehicleWndProc(Window *w, WindowEvent *e) bv->sort_criteria = e->we.dropdown.index; switch (bv->vehicle_type) { case VEH_Train: _last_sort_criteria_train = bv->sort_criteria; break; + case VEH_Ship: _last_sort_criteria_ship = bv->sort_criteria; break; case VEH_Aircraft: _last_sort_criteria_aircraft = bv->sort_criteria; break; } bv->regenerate_list = true; @@ -819,14 +919,18 @@ void ShowBuildVehicleWindow(TileIndex tile, byte type) bv->sort_criteria = _last_sort_criteria_train; bv->descending_sort_order = _last_sort_order_train; break; - case VEH_Aircraft: { + case VEH_Ship: + ResizeWindow(w, 27, 0); + bv->sort_criteria = _last_sort_criteria_ship; + bv->descending_sort_order = _last_sort_order_ship; + break; + case VEH_Aircraft: AcceptPlanes acc_planes = (tile == 0) ? ALL : GetAirport(GetStationByTile(tile)->airport_type)->acc_planes; bv->filter.acc_planes = acc_planes; ResizeWindow(w, 12, 0); bv->sort_criteria = _last_sort_criteria_aircraft; bv->descending_sort_order = _last_sort_order_aircraft; break; - } } SetupWindowStrings(w, type); ResizeButtons(w); diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 1e21af514..bae5637fe 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -737,7 +737,7 @@ static void DepotWndProc(Window *w, WindowEvent *e) ResetObjectToPlace(); switch (WP(w, depot_d).type) { case VEH_Road: ShowBuildRoadVehWindow(w->window_number); break; - case VEH_Ship: ShowBuildShipWindow(w->window_number); break; + case VEH_Ship: case VEH_Train: case VEH_Aircraft: ShowBuildVehicleWindow(w->window_number, WP(w, depot_d).type); diff --git a/src/ship.h b/src/ship.h index 4f91276ef..4d9dc5131 100644 --- a/src/ship.h +++ b/src/ship.h @@ -5,6 +5,7 @@ #include "vehicle.h" +void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2); void CcCloneShip(bool success, TileIndex tile, uint32 p1, uint32 p2); void RecalcShipStuff(Vehicle *v); diff --git a/src/ship_gui.cpp b/src/ship_gui.cpp index 07bdc3acc..2bd300eff 100644 --- a/src/ship_gui.cpp +++ b/src/ship_gui.cpp @@ -7,67 +7,13 @@ #include "ship.h" #include "table/strings.h" #include "table/sprites.h" -#include "map.h" -#include "window.h" #include "gui.h" -#include "gfx.h" #include "vehicle.h" #include "viewport.h" -#include "station.h" #include "command.h" -#include "player.h" -#include "engine.h" #include "depot.h" #include "vehicle_gui.h" #include "newgrf_engine.h" -#include "date.h" - -/** - * Draw the purchase info details of a ship 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 DrawShipPurchaseInfo(int x, int y, uint w, EngineID engine_number) -{ - YearMonthDay ymd; - const ShipVehicleInfo *svi = ShipVehInfo(engine_number); - const Engine *e; - - /* Purchase cost - Max speed */ - SetDParam(0, svi->base_cost * (_price.ship_base>>3)>>5); - SetDParam(1, svi->max_speed / 2); - DrawString(x,y, STR_PURCHASE_INFO_COST_SPEED, 0); - y += 10; - - /* Cargo type + capacity */ - SetDParam(0, svi->cargo_type); - SetDParam(1, svi->capacity); - SetDParam(2, svi->refittable ? STR_9842_REFITTABLE : STR_EMPTY); - DrawString(x,y, STR_PURCHASE_INFO_CAPACITY, 0); - y += 10; - - /* Running cost */ - SetDParam(0, svi->running_cost * _price.ship_running >> 8); - DrawString(x,y, STR_PURCHASE_INFO_RUNNINGCOST, 0); - y += 10; - - /* Design date - Life length */ - e = GetEngine(engine_number); - ConvertDateToYMD(e->intro_date, &ymd); - 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); - if (svi->refittable) y += ShowRefitOptionsList(x, y, w, engine_number); -} void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection) { @@ -239,134 +185,6 @@ void CcCloneShip(bool success, TileIndex tile, uint32 p1, uint32 p2) if (success) ShowShipViewWindow(GetVehicle(_new_vehicle_id)); } -static void NewShipWndProc(Window *w, WindowEvent *e) -{ - switch (e->event) { - case WE_PAINT: { - EngineID selected_id; - EngineID eid; - int count; - int pos; - int sel; - int y; - - SetWindowWidgetDisabledState(w, 5, w->window_number == 0); - - count = 0; - for (eid = SHIP_ENGINES_INDEX; eid < SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES; eid++) { - if (HASBIT(GetEngine(eid)->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 (eid = SHIP_ENGINES_INDEX; eid < SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES; eid++) { - if (!HASBIT(GetEngine(eid)->player_avail, _local_player)) continue; - if (sel == 0) selected_id = eid; - if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) { - DrawString(77, y + 7, GetCustomEngineName(eid), sel == 0 ? 0xC : 0x10); - DrawShipEngine(37, y + 10, eid, GetEnginePalette(eid, _local_player)); - y += 24; - } - sel--; - } - - WP(w,buildvehicle_d).sel_engine = selected_id; - - if (selected_id != INVALID_ENGINE) { - const Widget *wi = &w->widget[4]; - DrawShipPurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, selected_id); - } - break; - } - - case WE_CLICK: - switch (e->we.click.widget) { - case 2: { /* listbox */ - uint i = (e->we.click.pt.y - 14) / 24; - 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, CcBuildShip, CMD_BUILD_SHIP | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP)); - } 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_9838_RENAME_SHIP_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_9839_CAN_T_RENAME_SHIP_TYPE)); - } - break; - - case WE_RESIZE: - w->vscroll.cap += e->we.sizing.diff.y / 24; - w->widget[2].data = (w->vscroll.cap << 8) + 1; - break; - - } -} - -static const Widget _new_ship_widgets[] = { -{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, -{ WWT_CAPTION, RESIZE_NONE, 14, 11, 254, 0, 13, STR_9808_NEW_SHIPS, STR_018C_WINDOW_TITLE_DRAG_THIS}, -{ WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 242, 14, 109, 0x401, STR_9825_SHIP_SELECTION_LIST_CLICK}, -{ WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 243, 254, 14, 109, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, -{ WWT_PANEL, RESIZE_TB, 14, 0, 254, 110, 201, 0x0, STR_NULL}, -{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 121, 202, 213, STR_9809_BUILD_SHIP, STR_9826_BUILD_THE_HIGHLIGHTED_SHIP}, -{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 122, 242, 202, 213, STR_9836_RENAME, STR_9837_RENAME_SHIP_TYPE}, -{ WWT_RESIZEBOX, RESIZE_TB, 14, 243, 254, 202, 213, 0x0, STR_RESIZE_BUTTON}, -{ WIDGETS_END}, -}; - -static const WindowDesc _new_ship_desc = { - WDP_AUTO, WDP_AUTO, 255, 214, - WC_BUILD_VEHICLE,0, - WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, - _new_ship_widgets, - NewShipWndProc -}; - - -void ShowBuildShipWindow(TileIndex tile) -{ - Window *w; - - DeleteWindowById(WC_BUILD_VEHICLE, tile); - - w = AllocateWindowDescFront(&_new_ship_desc, tile); - w->vscroll.cap = 4; - w->widget[2].data = (w->vscroll.cap << 8) + 1; - - w->resize.step_height = 24; - - if (tile != 0) { - w->caption_color = GetTileOwner(tile); - } else { - w->caption_color = _local_player; - } - -} - - static void ShipViewWndProc(Window *w, WindowEvent *e) { switch (e->event) { diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 9b6c3c725..fa88841ff 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1049,7 +1049,7 @@ static void DrawVehiclePurchaseInfoLocal(const int x, const int y, uint w, const { switch (GetEngine(engine_number)->type) { case VEH_Road: DrawRoadVehPurchaseInfo(x, y, w, engine_number); break; - case VEH_Ship: DrawShipPurchaseInfo(x, y, w, engine_number); break; + case VEH_Ship: case VEH_Train: case VEH_Aircraft: DrawVehiclePurchaseInfo(x, y, w, engine_number); @@ -1739,7 +1739,7 @@ void PlayerVehWndProc(Window *w, WindowEvent *e) case VLW_WIDGET_NEW_VEHICLES: switch (vl->vehicle_type) { case VEH_Road: ShowBuildRoadVehWindow(0); break; - case VEH_Ship: ShowBuildShipWindow(0); break; + case VEH_Ship: case VEH_Train: case VEH_Aircraft: ShowBuildVehicleWindow(0, vl->vehicle_type); break; } diff --git a/src/vehicle_gui.h b/src/vehicle_gui.h index 77d067db1..509435c92 100644 --- a/src/vehicle_gui.h +++ b/src/vehicle_gui.h @@ -34,7 +34,6 @@ 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 DrawShipPurchaseInfo(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); @@ -42,7 +41,6 @@ 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 ShowBuildShipWindow(TileIndex tile); void ShowBuildVehicleWindow(TileIndex tile, byte type); void ChangeVehicleViewWindow(const Vehicle *from_v, const Vehicle *to_v); |