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