Skip to content

Commit

Permalink
Preserve the world camera when switching to/from split view (#6576)
Browse files Browse the repository at this point in the history
  • Loading branch information
Garanas authored Dec 25, 2024
1 parent 9142736 commit cce7a7d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
3 changes: 3 additions & 0 deletions changelog/snippets/features.6576.md
Original file line number Diff line number Diff line change
@@ -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.
23 changes: 21 additions & 2 deletions lua/ui/game/worldview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit cce7a7d

Please sign in to comment.