From cce7a7dafc184434e9dd80bd13203c98ccbba986 Mon Sep 17 00:00:00 2001 From: "(Jip) Willem Wijnia" Date: Wed, 25 Dec 2024 08:42:25 +0100 Subject: [PATCH] Preserve the world camera when switching to/from split view (#6576) --- .vscode/settings.json | 3 +++ changelog/snippets/features.6576.md | 3 +++ lua/ui/game/worldview.lua | 23 +++++++++++++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 changelog/snippets/features.6576.md diff --git a/.vscode/settings.json b/.vscode/settings.json index 8bdda3b316..230bddec7f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -24,6 +24,9 @@ "Lua.runtime.exportEnvDefault": true, "Lua.completion.autoRequire": false, "Lua.diagnostics.globals": ["ScenarioInfo"], + "Lua.format.defaultConfig": { + "max_line_length": "unset", + }, // used for grammar checks of changelog "grammarly.files.include": [ diff --git a/changelog/snippets/features.6576.md b/changelog/snippets/features.6576.md new file mode 100644 index 0000000000..7d5e86629b --- /dev/null +++ b/changelog/snippets/features.6576.md @@ -0,0 +1,3 @@ +- (#6576) Preserve the world camera when switching to/from split view + + When you switch to/from split view the primary camera (the left camera) is now preserved. This makes it less disorientating for a player (or caster) to switch to/from split view. \ No newline at end of file diff --git a/lua/ui/game/worldview.lua b/lua/ui/game/worldview.lua index 9a3fdd49d8..ac7d4abe5a 100644 --- a/lua/ui/game/worldview.lua +++ b/lua/ui/game/worldview.lua @@ -47,7 +47,7 @@ local function CreatePositionMarker(army, worldView) marker.frame.Depth:Set(marker:Depth() - 1) marker.name = UIUtil.CreateText(marker, data.name, 12, UIUtil.bodyFont) - marker.name:DisableHitTest() + marker.name:DisableHitTest() marker.name:SetColor('white') if Factions[data.faction] then @@ -120,7 +120,7 @@ function MarkStartPositions(startPositions) local faction = armyData.faction + 1 local color = armyData.color - positionMarkers[armyId] = {army = armyId, pos = pos, name = name, faction = faction, color = color, views = 0} + positionMarkers[armyId] = { army = armyId, pos = pos, name = name, faction = faction, color = color, views = 0 } for viewName, view in MapControls do if viewName ~= 'MiniMap' then @@ -132,6 +132,16 @@ function MarkStartPositions(startPositions) end function CreateMainWorldView(parent, mapGroup, mapGroupRight) + -- feature: preserve the world camera when changing views + ---@type UserCamera + local worldCamera = GetCamera('WorldCamera') + + ---@type UserCameraSettings | nil + local worldCameraSettings = nil + if worldCamera then + worldCameraSettings = worldCamera:SaveSettings() + end + if viewLeft then viewLeft:Destroy() viewLeft = false @@ -176,6 +186,15 @@ function CreateMainWorldView(parent, mapGroup, mapGroupRight) view:DisableHitTest() LayoutHelpers.FillParent(view, viewLeft) end + + -- feature: preserve the world camera when changing views + if worldCameraSettings then + local newWorldCamera = GetCamera('WorldCamera') + if newWorldCamera then + newWorldCamera:RestoreSettings(worldCameraSettings) + end + end + import("/lua/ui/game/multifunction.lua").RefreshMapDialog() end