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

Function tryCloseWindow

src/OpenLoco/src/Ui/Windows/ObjectSelectionWindow.cpp:1287–1332  ·  view source on GitHub ↗

0x00473A13

Source from the content-addressed store, hash-verified

1285
1286 // 0x00473A13
1287 bool tryCloseWindow()
1288 {
1289 auto& selection = ObjectManager::getCurrentSelectionList();
1290 const auto res = ObjectManager::validateObjectSelection(selection.objectFlags);
1291 if (!res.has_value())
1292 {
1293 // All okay selection is good!
1294 auto* w = WindowManager::find(WindowType::objectSelection);
1295 if (w != nullptr)
1296 {
1297 WindowManager::close(w);
1298 }
1299 return true;
1300 }
1301 else
1302 {
1303 // Selection was bad so throw up an error message
1304 // and switch tabs to the bad type
1305
1306 Windows::Error::open(StringIds::invalid_selection_of_objects, GameCommands::getErrorText());
1307
1308 auto* w = WindowManager::find(WindowType::objectSelection);
1309 if (w != nullptr)
1310 {
1311 // TODO: switch modes as needed?
1312 auto objectType = res.value();
1313 switchTabByObjectType(*w, objectType);
1314
1315 w->rowHover = -1;
1316 w->object = nullptr;
1317 w->scrollAreas[0].contentWidth = 0;
1318 ObjectManager::freeTemporaryObject();
1319 w->invalidate();
1320
1321 auto objIndex = getFirstAvailableSelectedObject(selection);
1322 if (objIndex.index != ObjectManager::kNullObjectIndex)
1323 {
1324 w->rowHover = objIndex.index;
1325 w->object = reinterpret_cast<std::byte*>(&objIndex.object._header);
1326
1327 ObjectManager::loadTemporaryObject(objIndex.object._header);
1328 }
1329 }
1330 return false;
1331 }
1332 }
1333
1334 static void switchPrimaryTab(Window& self, uint8_t tabIndex)
1335 {

Callers 3

goToNextStepFunction · 0.85
onMouseUpFunction · 0.85
loadsaveMenuDropdownFunction · 0.85

Calls 11

validateObjectSelectionFunction · 0.85
findFunction · 0.85
getErrorTextFunction · 0.85
switchTabByObjectTypeFunction · 0.85
freeTemporaryObjectFunction · 0.85
loadTemporaryObjectFunction · 0.85
valueMethod · 0.80
closeFunction · 0.70
openFunction · 0.70
invalidateMethod · 0.45

Tested by

no test coverage detected