diff --git a/trview.app.tests/Windows/ViewerTests.cpp b/trview.app.tests/Windows/ViewerTests.cpp index c23b4c953..7f091815d 100644 --- a/trview.app.tests/Windows/ViewerTests.cpp +++ b/trview.app.tests/Windows/ViewerTests.cpp @@ -1083,6 +1083,35 @@ TEST(Viewer, SectorHighlightForwarded) ui.on_sector_hover(sector); } +TEST(Viewer, AlternateGroupForwarded) +{ + auto level = mock_shared(); + EXPECT_CALL(*level, set_alternate_group(6, true)).Times(1); + ON_CALL(*level, alternate_groups).WillByDefault(Return(std::set{ 6 })); + + auto [ui_ptr, ui] = create_mock(); + EXPECT_CALL(ui, set_alternate_group(6, true)).Times(1); + + auto viewer = register_test_module().with_ui(std::move(ui_ptr)).build(); + viewer->open(level, ILevel::OpenMode::Full); + + ui.on_alternate_group(6, true); +} + +TEST(Viewer, InvalidAlternateGroupNotForwarded) +{ + auto level = mock_shared(); + EXPECT_CALL(*level, set_alternate_group).Times(0); + + auto [ui_ptr, ui] = create_mock(); + EXPECT_CALL(ui, set_alternate_group).Times(0); + + auto viewer = register_test_module().with_ui(std::move(ui_ptr)).build(); + viewer->open(level, ILevel::OpenMode::Full); + + ui.on_alternate_group(6, true); +} + TEST(Viewer, FontForwarded) { auto [ui_ptr, ui] = create_mock(); diff --git a/trview.app/Windows/Viewer.cpp b/trview.app/Windows/Viewer.cpp index 4301c623a..5c7c00882 100644 --- a/trview.app/Windows/Viewer.cpp +++ b/trview.app/Windows/Viewer.cpp @@ -961,9 +961,12 @@ namespace trview { if (auto level = _level.lock()) { - _was_alternate_select = true; - level->set_alternate_group(group, enabled); - _ui->set_alternate_group(group, enabled); + if (std::ranges::contains(level->alternate_groups(), group)) + { + _was_alternate_select = true; + level->set_alternate_group(group, enabled); + _ui->set_alternate_group(group, enabled); + } } }