tron@2186: /* $Id$ */ tron@2186: belugas@6117: /** @file autoreplace_gui.cpp */ belugas@6117: darkvater@164: #include "stdafx.h" Darkvater@1891: #include "openttd.h" tron@1299: #include "debug.h" tron@2163: #include "functions.h" tron@1363: #include "table/sprites.h" tron@507: #include "table/strings.h" tron@588: #include "window.h" bjarni@842: #include "gui.h" bjarni@842: #include "command.h" tron@2159: #include "variables.h" tron@2159: #include "vehicle_gui.h" peter1138@2962: #include "newgrf_engine.h" rubidium@6643: #include "group.h" bjarni@5808: bjarni@5808: bjarni@5809: static RailType _railtype_selected_in_replace_gui; tron@505: bjarni@5944: static bool _rebuild_left_list; bjarni@5944: static bool _rebuild_right_list; bjarni@5944: bjarni@5808: static const StringID _rail_types_list[] = { bjarni@5808: STR_RAIL_VEHICLES, bjarni@5808: STR_ELRAIL_VEHICLES, bjarni@5808: STR_MONORAIL_VEHICLES, bjarni@5808: STR_MAGLEV_VEHICLES, bjarni@5808: INVALID_STRING_ID bjarni@5808: }; bjarni@5808: bjarni@5808: /* General Vehicle GUI based procedures that are independent of vehicle types */ rubidium@6247: void InitializeVehiclesGuiList() bjarni@5808: { bjarni@5808: _railtype_selected_in_replace_gui = RAILTYPE_RAIL; bjarni@5808: } bjarni@5808: bjarni@5944: /** Rebuild the left autoreplace list if an engine is removed or added bjarni@5944: * @param e Engine to check if it is removed or added peter1138@7096: * @param id_g The group the engine belongs to bjarni@5944: * Note: this function only works if it is called either bjarni@5944: * - when a new vehicle is build, but before it's counted in num_engines bjarni@5944: * - when a vehicle is deleted and after it's substracted from num_engines bjarni@5944: * - when not changing the count (used when changing replace orders) bjarni@5808: */ peter1138@7096: void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g) bjarni@5808: { bjarni@5944: Player *p = GetPlayer(_local_player); bjarni@5944: byte type = GetEngine(e)->type; peter1138@7096: uint num_engines = IsDefaultGroupID(id_g) ? p->num_engines[e] : GetGroup(id_g)->num_engines[e]; bjarni@5808: peter1138@7096: if (num_engines == 0 || p->num_engines[e] == 0) { bjarni@5944: /* We don't have any of this engine type. bjarni@5944: * Either we just sold the last one, we build a new one or we stopped replacing it. bjarni@5944: * In all cases, we need to update the left list */ bjarni@5944: _rebuild_left_list = true; bjarni@5944: } else { bjarni@5944: _rebuild_left_list = false; bjarni@5944: } bjarni@5944: _rebuild_right_list = false; bjarni@5944: InvalidateWindowData(WC_REPLACE_VEHICLE, type); bjarni@5944: } bjarni@5808: bjarni@5944: /** When an engine is made buildable or is removed from being buildable, add/remove it from the build/autoreplace lists bjarni@5944: * @param type The type of engine bjarni@5944: */ rubidium@6638: void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type) bjarni@5944: { bjarni@5944: _rebuild_left_list = false; // left list is only for the vehicles the player owns and is not related to being buildable bjarni@5944: _rebuild_right_list = true; bjarni@5944: InvalidateWindowData(WC_REPLACE_VEHICLE, type); // Update the autoreplace window bjarni@5944: InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well bjarni@5944: } bjarni@5944: bjarni@5944: /** Get the default cargo type for an engine bjarni@5944: * @param engine the EngineID to get the cargo for bjarni@5944: * @return the cargo type carried by the engine (CT_INVALID if engine got no cargo capacity) bjarni@5944: */ bjarni@5944: static CargoID EngineCargo(EngineID engine) bjarni@5944: { bjarni@5944: if (engine == INVALID_ENGINE) return CT_INVALID; // surely INVALID_ENGINE can't carry anything but CT_INVALID bjarni@5944: bjarni@5944: switch (GetEngine(engine)->type) { bjarni@5944: default: NOT_REACHED(); rubidium@6259: case VEH_TRAIN: bjarni@5944: if (RailVehInfo(engine)->capacity == 0) return CT_INVALID; // no capacity -> can't carry cargo bjarni@5944: return RailVehInfo(engine)->cargo_type; rubidium@6259: case VEH_ROAD: return RoadVehInfo(engine)->cargo_type; rubidium@6259: case VEH_SHIP: return ShipVehInfo(engine)->cargo_type; rubidium@6259: case VEH_AIRCRAFT: return CT_PASSENGERS; // all planes are build with passengers by default bjarni@5944: } bjarni@5944: } bjarni@5944: bjarni@5944: /** Figure out if an engine should be added to a list bjarni@5944: * @param e The EngineID bjarni@5944: * @param draw_left If true, then the left list is drawn (the engines specific to the railtype you selected) bjarni@5944: * @param show_engines if truem then locomotives are drawn, else wagons (never both) bjarni@5944: * @return true if the engine should be in the list (based on this check) bjarni@5944: */ bjarni@5944: static bool GenerateReplaceRailList(EngineID e, bool draw_left, bool show_engines) bjarni@5944: { bjarni@5944: const RailVehicleInfo *rvi = RailVehInfo(e); bjarni@5944: bjarni@5944: /* Ensure that the wagon/engine selection fits the engine. */ bjarni@5944: if ((rvi->railveh_type == RAILVEH_WAGON) == show_engines) return false; bjarni@5944: bjarni@5944: if (draw_left && show_engines) { bjarni@5944: /* Ensure that the railtype is specific to the selected one */ bjarni@5944: if (rvi->railtype != _railtype_selected_in_replace_gui) return false; bjarni@5944: } else { bjarni@5944: /* Ensure that it's a compatible railtype to the selected one (like electric <-> diesel) bjarni@5944: * The vehicle do not have to have power on the railtype in question, only able to drive (pulled if needed) */ bjarni@5944: if (!IsCompatibleRail(rvi->railtype, _railtype_selected_in_replace_gui)) return false; bjarni@5944: } bjarni@5944: return true; bjarni@5944: } bjarni@5944: bjarni@5944: /** Figure out if two engines got at least one type of cargo in common (refitting if needed) bjarni@5944: * @param engine_a one of the EngineIDs bjarni@5944: * @param engine_b the other EngineID bjarni@5944: * @return true if they can both carry the same type of cargo (or at least one of them got no capacity at all) bjarni@5944: */ bjarni@5944: static bool EnginesGotCargoInCommon(EngineID engine_a, EngineID engine_b) bjarni@5944: { bjarni@5944: CargoID a = EngineCargo(engine_a); bjarni@5944: CargoID b = EngineCargo(engine_b); bjarni@5944: bjarni@5944: /* we should always be able to refit to/from locomotives without capacity bjarni@5944: * Because of that, CT_INVALID shoudl always return true */ bjarni@5944: if (a == CT_INVALID || b == CT_INVALID || a == b) return true; // they carry no ro the same type by default bjarni@5944: if (EngInfo(engine_a)->refit_mask & EngInfo(engine_b)->refit_mask) return true; // both can refit to the same bjarni@5944: if (CanRefitTo(engine_a, b) || CanRefitTo(engine_b, a)) return true; // one can refit to what the other one carries bjarni@5944: return false; bjarni@5944: } bjarni@5944: bjarni@5944: /** Generate a list bjarni@5944: * @param w Window, that contains the list bjarni@5944: * @param draw_left true if generating the left list, otherwise false bjarni@5944: */ bjarni@5944: static void GenerateReplaceVehList(Window *w, bool draw_left) bjarni@5944: { bjarni@5944: Player *p = GetPlayer(_local_player); bjarni@5944: EngineID e; bjarni@5944: EngineID selected_engine = INVALID_ENGINE; bjarni@5944: byte type = w->window_number; bjarni@5944: byte i = draw_left ? 0 : 1; bjarni@5944: bjarni@5944: EngineList *list = &WP(w, replaceveh_d).list[i]; bjarni@5944: EngList_RemoveAll(list); bjarni@5944: bjarni@5944: FOR_ALL_ENGINEIDS_OF_TYPE(e, type) { rubidium@6259: if (type == VEH_TRAIN && !GenerateReplaceRailList(e, draw_left, WP(w, replaceveh_d).wagon_btnstate)) continue; // special rules for trains bjarni@5944: bjarni@5944: if (draw_left) { rubidium@6643: const GroupID selected_group = WP(w, replaceveh_d).sel_group; rubidium@6643: const uint num_engines = IsDefaultGroupID(selected_group) ? p->num_engines[e] : GetGroup(selected_group)->num_engines[e]; rubidium@6643: bjarni@5944: /* Skip drawing the engines we don't have any of and haven't set for replacement */ rubidium@6643: if (num_engines == 0 && EngineReplacementForPlayer(GetPlayer(_local_player), e, selected_group) == INVALID_ENGINE) continue; bjarni@5808: } else { bjarni@5944: /* This is for engines we can replace to and they should depend on what we selected to replace from */ bjarni@5944: if (!IsEngineBuildable(e, type, _local_player)) continue; // we need to be able to build the engine bjarni@5944: if (!EnginesGotCargoInCommon(e, WP(w, replaceveh_d).sel_engine[0])) continue; // the engines needs to be able to carry the same cargo rubidium@6687: rubidium@6687: /* Road vehicles can't be replaced by trams and vice-versa */ rubidium@6687: if (type == VEH_ROAD && HASBIT(EngInfo(WP(w, replaceveh_d).sel_engine[0])->misc_flags, EF_ROAD_TRAM) != HASBIT(EngInfo(e)->misc_flags, EF_ROAD_TRAM)) continue; bjarni@5944: if (e == WP(w, replaceveh_d).sel_engine[0]) continue; // we can't replace an engine into itself (that would be autorenew) bjarni@5808: } bjarni@5808: bjarni@5944: EngList_Add(list, e); bjarni@5944: if (e == WP(w, replaceveh_d).sel_engine[i]) selected_engine = e; // The selected engine is still in the list bjarni@5944: } bjarni@5944: WP(w, replaceveh_d).sel_engine[i] = selected_engine; // update which engine we selected (the same or none, if it's not in the list anymore) bjarni@5944: } bjarni@5944: bjarni@5944: /** Generate the lists bjarni@5944: * @param w Window containing the lists bjarni@5944: */ bjarni@5944: static void GenerateLists(Window *w) bjarni@5944: { bjarni@5944: EngineID e = WP(w, replaceveh_d).sel_engine[0]; bjarni@5944: bjarni@5944: if (WP(w, replaceveh_d).update_left == true) { bjarni@5944: /* We need to rebuild the left list */ bjarni@5944: GenerateReplaceVehList(w, true); bjarni@5944: SetVScrollCount(w, EngList_Count(&WP(w, replaceveh_d).list[0])); bjarni@5944: if (WP(w, replaceveh_d).init_lists && WP(w, replaceveh_d).sel_engine[0] == INVALID_ENGINE && EngList_Count(&WP(w, replaceveh_d).list[0]) != 0) { bjarni@5944: WP(w, replaceveh_d).sel_engine[0] = WP(w, replaceveh_d).list[0][0]; bjarni@5944: } bjarni@5944: } bjarni@5944: bjarni@5944: if (WP(w, replaceveh_d).update_right || e != WP(w, replaceveh_d).sel_engine[0]) { bjarni@5944: /* Either we got a request to rebuild the right list or the left list selected a different engine */ bjarni@5944: if (WP(w, replaceveh_d).sel_engine[0] == INVALID_ENGINE) { bjarni@5944: /* Always empty the right list when nothing is selected in the left list */ bjarni@5944: EngList_RemoveAll(&WP(w, replaceveh_d).list[1]); bjarni@5944: WP(w, replaceveh_d).sel_engine[1] = INVALID_ENGINE; bjarni@5944: } else { bjarni@5944: GenerateReplaceVehList(w, false); bjarni@5944: SetVScroll2Count(w, EngList_Count(&WP(w, replaceveh_d).list[1])); bjarni@5944: if (WP(w, replaceveh_d).init_lists && WP(w, replaceveh_d).sel_engine[1] == INVALID_ENGINE && EngList_Count(&WP(w, replaceveh_d).list[1]) != 0) { bjarni@5944: WP(w, replaceveh_d).sel_engine[1] = WP(w, replaceveh_d).list[1][0]; bjarni@5808: } bjarni@5808: } bjarni@5808: } bjarni@5944: /* Reset the flags about needed updates */ bjarni@5944: WP(w, replaceveh_d).update_left = false; bjarni@5944: WP(w, replaceveh_d).update_right = false; bjarni@5944: WP(w, replaceveh_d).init_lists = false; bjarni@5808: } bjarni@5808: bjarni@5808: rubidium@6643: void DrawEngineList(VehicleType type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group); bjarni@5808: bjarni@5808: static void ReplaceVehicleWndProc(Window *w, WindowEvent *e) bjarni@5808: { bjarni@5944: /* Strings for the pulldown menu */ bjarni@5808: static const StringID _vehicle_type_names[] = { bjarni@5808: STR_019F_TRAIN, bjarni@5808: STR_019C_ROAD_VEHICLE, bjarni@5808: STR_019E_SHIP, bjarni@5808: STR_019D_AIRCRAFT bjarni@5808: }; bjarni@5808: bjarni@5808: switch (e->event) { bjarni@5944: case WE_CREATE: bjarni@5944: WP(w, replaceveh_d).wagon_btnstate = true; // start with locomotives (all other vehicles will not read this bool) bjarni@5944: EngList_Create(&WP(w, replaceveh_d).list[0]); bjarni@5944: EngList_Create(&WP(w, replaceveh_d).list[1]); bjarni@5944: WP(w, replaceveh_d).update_left = true; bjarni@5944: WP(w, replaceveh_d).update_right = true; bjarni@5944: WP(w, replaceveh_d).init_lists = true; bjarni@5944: WP(w, replaceveh_d).sel_engine[0] = INVALID_ENGINE; bjarni@5944: WP(w, replaceveh_d).sel_engine[1] = INVALID_ENGINE; bjarni@5944: break; bjarni@5808: bjarni@5944: case WE_PAINT: { bjarni@5944: if (WP(w, replaceveh_d).update_left || WP(w, replaceveh_d).update_right) GenerateLists(w); bjarni@5808: bjarni@5944: Player *p = GetPlayer(_local_player); bjarni@5944: EngineID selected_id[2]; rubidium@6643: const GroupID selected_group = WP(w,replaceveh_d).sel_group; bjarni@5808: bjarni@5944: selected_id[0] = WP(w, replaceveh_d).sel_engine[0]; bjarni@5944: selected_id[1] = WP(w, replaceveh_d).sel_engine[1]; bjarni@5808: bjarni@5944: /* Disable the "Start Replacing" button if: bjarni@5944: * Either list is empty bjarni@5944: * or The selected replacement engine has a replacement (to prevent loops) bjarni@5944: * or The right list (new replacement) has the existing replacement vehicle selected */ bjarni@5944: SetWindowWidgetDisabledState(w, 4, bjarni@5944: selected_id[0] == INVALID_ENGINE || bjarni@5944: selected_id[1] == INVALID_ENGINE || rubidium@6643: EngineReplacementForPlayer(p, selected_id[1], selected_group) != INVALID_ENGINE || rubidium@6643: EngineReplacementForPlayer(p, selected_id[0], selected_group) == selected_id[1]); bjarni@5944: bjarni@5944: /* Disable the "Stop Replacing" button if: bjarni@5944: * The left list (existing vehicle) is empty bjarni@5944: * or The selected vehicle has no replacement set up */ bjarni@5944: SetWindowWidgetDisabledState(w, 6, bjarni@5944: selected_id[0] == INVALID_ENGINE || rubidium@6643: !EngineHasReplacementForPlayer(p, selected_id[0], selected_group)); bjarni@5944: bjarni@5944: /* now the actual drawing of the window itself takes place */ bjarni@5955: SetDParam(0, _vehicle_type_names[w->window_number]); bjarni@5944: rubidium@6259: if (w->window_number == VEH_TRAIN) { bjarni@5944: /* set on/off for renew_keep_length */ bjarni@5944: SetDParam(1, p->renew_keep_length ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF); bjarni@5944: bjarni@5944: /* set wagon/engine button */ bjarni@5944: SetDParam(2, WP(w, replaceveh_d).wagon_btnstate ? STR_ENGINES : STR_WAGONS); glx@6398: glx@6398: /* sets the colour of that art thing */ glx@6398: w->widget[13].color = _player_colors[_local_player]; glx@6398: w->widget[16].color = _player_colors[_local_player]; bjarni@5944: } bjarni@5944: bjarni@5944: DrawWindowWidgets(w); bjarni@5944: rubidium@6259: if (w->window_number == VEH_TRAIN) { bjarni@5944: /* Draw the selected railtype in the pulldown menu */ bjarni@5944: RailType railtype = _railtype_selected_in_replace_gui; bjarni@5944: DrawString(157, w->widget[14].top + 1, _rail_types_list[railtype], 0x10); bjarni@5944: } bjarni@5944: bjarni@5944: /* sets up the string for the vehicle that is being replaced to */ bjarni@5944: if (selected_id[0] != INVALID_ENGINE) { rubidium@6643: if (!EngineHasReplacementForPlayer(p, selected_id[0], selected_group)) { bjarni@5944: SetDParam(0, STR_NOT_REPLACING); bjarni@5944: } else { peter1138@7059: SetDParam(0, STR_ENGINE_NAME); peter1138@7059: SetDParam(1, EngineReplacementForPlayer(p, selected_id[0], selected_group)); bjarni@5808: } bjarni@5944: } else { bjarni@5944: SetDParam(0, STR_NOT_REPLACING_VEHICLE_SELECTED); bjarni@5944: } bjarni@5944: bjarni@5944: DrawString(145, w->widget[5].top + 1, STR_02BD, 0x10); bjarni@5944: bjarni@5944: /* Draw the lists */ bjarni@5944: for(byte i = 0; i < 2; i++) { bjarni@5944: uint16 x = i == 0 ? 2 : 230; // at what X offset bjarni@5944: EngineList list = WP(w, replaceveh_d).list[i]; // which list to draw bjarni@5944: EngineID start = i == 0 ? w->vscroll.pos : w->vscroll2.pos; // what is the offset for the start (scrolling) bjarni@5944: EngineID end = min((i == 0 ? w->vscroll.cap : w->vscroll2.cap) + start, EngList_Count(&list)); bjarni@5944: bjarni@5944: /* Do the actual drawing */ rubidium@6643: DrawEngineList((VehicleType)w->window_number, x, 15, list, start, end, WP(w, replaceveh_d).sel_engine[i], i == 0, selected_group); bjarni@5944: bjarni@5944: /* Also draw the details if an engine is selected */ bjarni@5944: if (WP(w, replaceveh_d).sel_engine[i] != INVALID_ENGINE) { bjarni@5944: const Widget *wi = &w->widget[i == 0 ? 3 : 11]; bjarni@5944: DrawVehiclePurchaseInfo(wi->left + 2, wi->top + 1, wi->right - wi->left - 2, WP(w, replaceveh_d).sel_engine[i]); bjarni@5944: } bjarni@5944: } bjarni@5944: bjarni@5944: } break; // end of paint bjarni@5808: bjarni@5808: case WE_CLICK: { bjarni@5808: switch (e->we.click.widget) { bjarni@5808: case 12: bjarni@5808: WP(w, replaceveh_d).wagon_btnstate = !(WP(w, replaceveh_d).wagon_btnstate); bjarni@5944: WP(w, replaceveh_d).update_left = true; bjarni@5944: WP(w, replaceveh_d).init_lists = true; bjarni@5808: SetWindowDirty(w); bjarni@5808: break; bjarni@5808: bjarni@5808: case 14: bjarni@5808: case 15: /* Railtype selection dropdown menu */ bjarni@5808: ShowDropDownMenu(w, _rail_types_list, _railtype_selected_in_replace_gui, 15, 0, ~GetPlayer(_local_player)->avail_railtypes); bjarni@5808: break; bjarni@5808: bjarni@5808: case 17: /* toggle renew_keep_length */ bjarni@5808: DoCommandP(0, 5, GetPlayer(_local_player)->renew_keep_length ? 0 : 1, NULL, CMD_SET_AUTOREPLACE); bjarni@5808: break; bjarni@5808: bjarni@5808: case 4: { /* Start replacing */ bjarni@5808: EngineID veh_from = WP(w, replaceveh_d).sel_engine[0]; bjarni@5808: EngineID veh_to = WP(w, replaceveh_d).sel_engine[1]; rubidium@6643: DoCommandP(0, 3 + (WP(w, replaceveh_d).sel_group << 16) , veh_from + (veh_to << 16), NULL, CMD_SET_AUTOREPLACE); bjarni@5944: } break; bjarni@5808: bjarni@5808: case 6: { /* Stop replacing */ bjarni@5808: EngineID veh_from = WP(w, replaceveh_d).sel_engine[0]; rubidium@6643: DoCommandP(0, 3 + (WP(w, replaceveh_d).sel_group << 16), veh_from + (INVALID_ENGINE << 16), NULL, CMD_SET_AUTOREPLACE); bjarni@5944: } break; bjarni@5808: bjarni@5808: case 7: bjarni@5808: case 9: { bjarni@5808: uint i = (e->we.click.pt.y - 14) / w->resize.step_height; bjarni@5944: uint16 click_scroll_pos = e->we.click.widget == 7 ? w->vscroll.pos : w->vscroll2.pos; bjarni@5944: uint16 click_scroll_cap = e->we.click.widget == 7 ? w->vscroll.cap : w->vscroll2.cap; bjarni@5944: byte click_side = e->we.click.widget == 7 ? 0 : 1; bjarni@5944: uint16 engine_count = EngList_Count(&WP(w, replaceveh_d).list[click_side]); bjarni@5944: bjarni@5808: if (i < click_scroll_cap) { bjarni@5944: i += click_scroll_pos; bjarni@5944: EngineID e = engine_count > i ? WP(w, replaceveh_d).list[click_side][i] : INVALID_ENGINE; bjarni@5944: if (e == WP(w, replaceveh_d).sel_engine[click_side]) break; // we clicked the one we already selected bjarni@5944: WP(w, replaceveh_d).sel_engine[click_side] = e; bjarni@5944: if (click_side == 0) { bjarni@5944: WP(w, replaceveh_d).update_right = true; bjarni@5944: WP(w, replaceveh_d).init_lists = true; bjarni@5944: } bjarni@5808: SetWindowDirty(w); bjarni@5944: } bjarni@5944: break; bjarni@5808: } bjarni@5808: } bjarni@5808: break; bjarni@5808: } bjarni@5808: bjarni@5944: case WE_DROPDOWN_SELECT: { /* we have selected a dropdown item in the list */ bjarni@5944: RailType temp = (RailType)e->we.dropdown.index; bjarni@5944: if (temp == _railtype_selected_in_replace_gui) break; // we didn't select a new one. No need to change anything bjarni@5944: _railtype_selected_in_replace_gui = temp; bjarni@5808: /* Reset scrollbar positions */ bjarni@5808: w->vscroll.pos = 0; bjarni@5808: w->vscroll2.pos = 0; bjarni@5944: /* Rebuild the lists */ bjarni@5944: WP(w, replaceveh_d).update_left = true; bjarni@5944: WP(w, replaceveh_d).update_right = true; bjarni@5944: WP(w, replaceveh_d).init_lists = true; bjarni@5808: SetWindowDirty(w); bjarni@5944: } break; bjarni@5808: bjarni@5808: case WE_RESIZE: bjarni@5808: w->vscroll.cap += e->we.sizing.diff.y / (int)w->resize.step_height; bjarni@5808: w->vscroll2.cap += e->we.sizing.diff.y / (int)w->resize.step_height; bjarni@5808: bjarni@5808: w->widget[7].data = (w->vscroll.cap << 8) + 1; bjarni@5808: w->widget[9].data = (w->vscroll2.cap << 8) + 1; bjarni@5808: break; bjarni@5944: bjarni@5944: case WE_INVALIDATE_DATA: bjarni@5944: if (_rebuild_left_list) WP(w, replaceveh_d).update_left = true; bjarni@5944: if (_rebuild_right_list) WP(w, replaceveh_d).update_right = true; bjarni@5944: SetWindowDirty(w); bjarni@5944: break; bjarni@5944: bjarni@5944: case WE_DESTROY: bjarni@5944: EngList_RemoveAll(&WP(w, replaceveh_d).list[0]); bjarni@5944: EngList_RemoveAll(&WP(w, replaceveh_d).list[1]); bjarni@5944: break; bjarni@5808: } bjarni@5808: } bjarni@5808: bjarni@5808: static const Widget _replace_rail_vehicle_widgets[] = { bjarni@5808: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, bjarni@5808: { WWT_CAPTION, RESIZE_NONE, 14, 11, 443, 0, 13, STR_REPLACE_VEHICLES_WHITE, STR_018C_WINDOW_TITLE_DRAG_THIS}, bjarni@5808: { WWT_STICKYBOX, RESIZE_NONE, 14, 444, 455, 0, 13, STR_NULL, STR_STICKY_BUTTON}, bjarni@5808: { WWT_PANEL, RESIZE_TB, 14, 0, 227, 126, 227, 0x0, STR_NULL}, bjarni@5808: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 138, 240, 251, STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON}, bjarni@5808: { WWT_PANEL, RESIZE_TB, 14, 139, 316, 228, 239, 0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB}, bjarni@5808: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 306, 443, 240, 251, STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON}, bjarni@5808: { WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 215, 14, 125, 0x801, STR_REPLACE_HELP_LEFT_ARRAY}, bjarni@5808: { WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 216, 227, 14, 125, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST}, bjarni@5808: { WWT_MATRIX, RESIZE_BOTTOM, 14, 228, 443, 14, 125, 0x801, STR_REPLACE_HELP_RIGHT_ARRAY}, bjarni@5808: { WWT_SCROLL2BAR, RESIZE_BOTTOM, 14, 444, 455, 14, 125, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST}, bjarni@5808: { WWT_PANEL, RESIZE_TB, 14, 228, 455, 126, 227, 0x0, STR_NULL}, bjarni@5808: // train specific stuff bjarni@5808: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 138, 228, 239, STR_REPLACE_ENGINE_WAGON_SELECT, STR_REPLACE_ENGINE_WAGON_SELECT_HELP}, // widget 12 bjarni@5808: { WWT_PANEL, RESIZE_TB, 14, 139, 153, 240, 251, 0x0, STR_NULL}, bjarni@5808: { WWT_PANEL, RESIZE_TB, 14, 154, 277, 240, 251, 0x0, STR_REPLACE_HELP_RAILTYPE}, bjarni@5808: { WWT_TEXTBTN, RESIZE_TB, 14, 278, 289, 240, 251, STR_0225, STR_REPLACE_HELP_RAILTYPE}, bjarni@5808: { WWT_PANEL, RESIZE_TB, 14, 290, 305, 240, 251, 0x0, STR_NULL}, bjarni@5808: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 317, 455, 228, 239, STR_REPLACE_REMOVE_WAGON, STR_REPLACE_REMOVE_WAGON_HELP}, bjarni@5808: // end of train specific stuff bjarni@5808: { WWT_RESIZEBOX, RESIZE_TB, 14, 444, 455, 240, 251, STR_NULL, STR_RESIZE_BUTTON}, bjarni@5808: { WIDGETS_END}, bjarni@5808: }; bjarni@5808: bjarni@5808: static const Widget _replace_road_vehicle_widgets[] = { bjarni@5808: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, bjarni@5808: { WWT_CAPTION, RESIZE_NONE, 14, 11, 443, 0, 13, STR_REPLACE_VEHICLES_WHITE, STR_018C_WINDOW_TITLE_DRAG_THIS}, bjarni@5808: { WWT_STICKYBOX, RESIZE_NONE, 14, 444, 455, 0, 13, STR_NULL, STR_STICKY_BUTTON}, bjarni@5808: { WWT_PANEL, RESIZE_TB, 14, 0, 227, 126, 217, 0x0, STR_NULL}, bjarni@5808: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 138, 218, 229, STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON}, bjarni@5808: { WWT_PANEL, RESIZE_TB, 14, 139, 305, 218, 229, 0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB}, bjarni@5808: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 306, 443, 218, 229, STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON}, bjarni@5808: { WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 215, 14, 125, 0x801, STR_REPLACE_HELP_LEFT_ARRAY}, bjarni@5808: { WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 216, 227, 14, 125, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST}, bjarni@5808: { WWT_MATRIX, RESIZE_BOTTOM, 14, 228, 443, 14, 125, 0x801, STR_REPLACE_HELP_RIGHT_ARRAY}, bjarni@5808: { WWT_SCROLL2BAR, RESIZE_BOTTOM, 14, 444, 455, 14, 125, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST}, bjarni@5808: { WWT_PANEL, RESIZE_TB, 14, 228, 455, 126, 217, 0x0, STR_NULL}, bjarni@5808: { WWT_RESIZEBOX, RESIZE_TB, 14, 444, 455, 218, 229, STR_NULL, STR_RESIZE_BUTTON}, bjarni@5808: { WIDGETS_END}, bjarni@5808: }; bjarni@5808: bjarni@5808: static const Widget _replace_ship_aircraft_vehicle_widgets[] = { bjarni@5808: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, bjarni@5808: { WWT_CAPTION, RESIZE_NONE, 14, 11, 443, 0, 13, STR_REPLACE_VEHICLES_WHITE, STR_018C_WINDOW_TITLE_DRAG_THIS}, bjarni@5808: { WWT_STICKYBOX, RESIZE_NONE, 14, 444, 455, 0, 13, STR_NULL, STR_STICKY_BUTTON}, bjarni@5808: { WWT_PANEL, RESIZE_TB, 14, 0, 227, 110, 201, 0x0, STR_NULL}, bjarni@5808: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 138, 202, 213, STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON}, bjarni@5808: { WWT_PANEL, RESIZE_TB, 14, 139, 305, 202, 213, 0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB}, bjarni@5808: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 306, 443, 202, 213, STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON}, bjarni@5808: { WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 215, 14, 109, 0x401, STR_REPLACE_HELP_LEFT_ARRAY}, bjarni@5808: { WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 216, 227, 14, 109, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST}, bjarni@5808: { WWT_MATRIX, RESIZE_BOTTOM, 14, 228, 443, 14, 109, 0x401, STR_REPLACE_HELP_RIGHT_ARRAY}, bjarni@5808: { WWT_SCROLL2BAR, RESIZE_BOTTOM, 14, 444, 455, 14, 109, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST}, bjarni@5808: { WWT_PANEL, RESIZE_TB, 14, 228, 455, 110, 201, 0x0, STR_NULL}, bjarni@5808: { WWT_RESIZEBOX, RESIZE_TB, 14, 444, 455, 202, 213, STR_NULL, STR_RESIZE_BUTTON}, bjarni@5808: { WIDGETS_END}, bjarni@5808: }; bjarni@5808: bjarni@5808: static const WindowDesc _replace_rail_vehicle_desc = { bjarni@5808: WDP_AUTO, WDP_AUTO, 456, 252, rubidium@5893: WC_REPLACE_VEHICLE, WC_NONE, bjarni@5808: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, bjarni@5808: _replace_rail_vehicle_widgets, bjarni@5808: ReplaceVehicleWndProc bjarni@5808: }; bjarni@5808: bjarni@5808: static const WindowDesc _replace_road_vehicle_desc = { bjarni@5808: WDP_AUTO, WDP_AUTO, 456, 230, rubidium@5893: WC_REPLACE_VEHICLE, WC_NONE, bjarni@5808: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, bjarni@5808: _replace_road_vehicle_widgets, bjarni@5808: ReplaceVehicleWndProc bjarni@5808: }; bjarni@5808: bjarni@5808: static const WindowDesc _replace_ship_aircraft_vehicle_desc = { bjarni@5808: WDP_AUTO, WDP_AUTO, 456, 214, rubidium@5893: WC_REPLACE_VEHICLE, WC_NONE, bjarni@5808: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, bjarni@5808: _replace_ship_aircraft_vehicle_widgets, bjarni@5808: ReplaceVehicleWndProc bjarni@5808: }; bjarni@5808: bjarni@5808: rubidium@6638: void ShowReplaceVehicleWindow(VehicleType vehicletype) bjarni@5808: { bjarni@5808: Window *w; bjarni@5808: bjarni@5808: DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype); bjarni@5808: bjarni@5808: switch (vehicletype) { rubidium@6259: case VEH_TRAIN: bjarni@5808: w = AllocateWindowDescFront(&_replace_rail_vehicle_desc, vehicletype); bjarni@5808: w->vscroll.cap = 8; bjarni@5808: w->resize.step_height = 14; bjarni@5808: WP(w, replaceveh_d).wagon_btnstate = true; bjarni@5808: break; rubidium@6259: case VEH_ROAD: bjarni@5808: w = AllocateWindowDescFront(&_replace_road_vehicle_desc, vehicletype); bjarni@5808: w->vscroll.cap = 8; bjarni@5808: w->resize.step_height = 14; bjarni@5808: break; rubidium@6259: case VEH_SHIP: rubidium@6259: case VEH_AIRCRAFT: bjarni@5808: w = AllocateWindowDescFront(&_replace_ship_aircraft_vehicle_desc, vehicletype); bjarni@5808: w->vscroll.cap = 4; bjarni@5808: w->resize.step_height = 24; bjarni@5808: break; bjarni@5808: default: return; bjarni@5808: } bjarni@5808: bjarni@5808: w->caption_color = _local_player; bjarni@5808: w->vscroll2.cap = w->vscroll.cap; // these two are always the same rubidium@6643: WP(w, replaceveh_d).sel_group = DEFAULT_GROUP; rubidium@6643: } rubidium@6643: rubidium@6643: void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype) rubidium@6643: { rubidium@6643: Window *w; rubidium@6643: rubidium@6643: DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype); rubidium@6643: rubidium@6643: switch (vehicletype) { rubidium@6643: default: NOT_REACHED(); rubidium@6643: case VEH_TRAIN: rubidium@6643: w = AllocateWindowDescFront(&_replace_rail_vehicle_desc, vehicletype); rubidium@6643: w->vscroll.cap = 8; rubidium@6643: w->resize.step_height = 14; rubidium@6643: WP(w, replaceveh_d).wagon_btnstate = true; rubidium@6643: break; rubidium@6643: case VEH_ROAD: rubidium@6643: w = AllocateWindowDescFront(&_replace_road_vehicle_desc, vehicletype); rubidium@6643: w->vscroll.cap = 8; rubidium@6643: w->resize.step_height = 14; rubidium@6643: break; rubidium@6643: case VEH_SHIP: rubidium@6643: case VEH_AIRCRAFT: rubidium@6643: w = AllocateWindowDescFront(&_replace_ship_aircraft_vehicle_desc, vehicletype); rubidium@6643: w->vscroll.cap = 4; rubidium@6643: w->resize.step_height = 24; rubidium@6643: break; rubidium@6643: } rubidium@6643: rubidium@6643: w->caption_color = _local_player; rubidium@6643: WP(w, replaceveh_d).sel_group = id_g; rubidium@6643: w->vscroll2.cap = w->vscroll.cap; // these two are always the same bjarni@5808: }