MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / scrollDragEnd

Function scrollDragEnd

src/OpenLoco/src/Ui/Windows/Vehicle.cpp:2093–2147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2091 }
2092
2093 void scrollDragEnd(const Ui::Point& pos)
2094 {
2095 if (DragVehiclePart::getDragCarComponent() == nullptr)
2096 {
2097 return;
2098 }
2099
2100 auto vehicleWindow = getVehicleDetailsWindow(pos);
2101 if (vehicleWindow == nullptr)
2102 {
2103 return;
2104 }
2105
2106 auto targetWidget = vehicleWindow->findWidgetAt(pos.x, pos.y);
2107 switch (targetWidget)
2108 {
2109 case widx::remove:
2110 {
2111 GameCommands::VehicleSellArgs gcArgs{};
2112 gcArgs.car = DragVehiclePart::getDragCarComponent()->id;
2113
2114 if (Common::confirmComponentChange(gcArgs.car, StringIds::confirm_vehicle_component_sell_cargo_warning_title, StringIds::confirm_vehicle_component_sell_cargo_warning_message, StringIds::confirm_vehicle_component_sell_cargo_warning_confirm))
2115 {
2116 GameCommands::setErrorTitle(StringIds::cant_sell_vehicle);
2117 GameCommands::doCommand(gcArgs, GameCommands::Flags::apply);
2118 }
2119
2120 break;
2121 }
2122 case widx::carList:
2123 {
2124 auto car = getCarFromScrollViewPos(*vehicleWindow, pos);
2125 if (car != nullptr)
2126 {
2127 GameCommands::VehicleRearrangeArgs args{};
2128 args.source = DragVehiclePart::getDragCarComponent()->id;
2129 args.dest = car->id;
2130
2131 auto* srcVehicle = EntityManager::get<Vehicles::VehicleBase>(args.source);
2132 auto* destVehicle = EntityManager::get<Vehicles::VehicleBase>(args.dest);
2133
2134 bool sameHead = srcVehicle == nullptr || destVehicle == nullptr || srcVehicle->head == destVehicle->head;
2135
2136 const StringId warningMessage = sameHead ? StringIds::confirm_vehicle_component_move_cargo_warning_message : StringIds::confirm_vehicle_component_move_cargo_multiple_vehicles_warning_message;
2137
2138 if (Common::confirmComponentChange(args.source, args.dest, StringIds::confirm_vehicle_component_move_cargo_warning_title, warningMessage, StringIds::confirm_vehicle_component_move_cargo_warning_confirm))
2139 {
2140 GameCommands::setErrorTitle(StringIds::cant_move_vehicle);
2141 GameCommands::doCommand(args, GameCommands::Flags::apply);
2142 }
2143 }
2144 break;
2145 }
2146 }
2147 }
2148
2149 // copied and modified from VehicleDraw::getDrawItemsForVehicle
2150 static BodyItems getBodyItemsForVehicle(const VehicleObject& vehObject, const uint8_t yaw, const Vehicles::Car& car)

Callers 1

onMoveFunction · 0.85

Calls 7

getDragCarComponentFunction · 0.85
getVehicleDetailsWindowFunction · 0.85
confirmComponentChangeFunction · 0.85
setErrorTitleFunction · 0.85
getCarFromScrollViewPosFunction · 0.85
findWidgetAtMethod · 0.80
doCommandFunction · 0.50

Tested by

no test coverage detected