From 12c9a591fb96d382cedc932b541fd2b5c7176594 Mon Sep 17 00:00:00 2001 From: "(Jip) Willem Wijnia" Date: Thu, 5 Dec 2024 19:18:24 +0100 Subject: [PATCH 1/6] Preserve the world camera when switching to/from split view --- lua/ui/game/worldview.lua | 40 ++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/lua/ui/game/worldview.lua b/lua/ui/game/worldview.lua index 9a3fdd49d8..dc704e8738 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 @@ -78,7 +78,8 @@ local function CreatePositionMarker(army, worldView) -- That often happens even if the cursor is nowhere near the marker, so it's unusable. This way isn't pretty, but at least it works correctly. local oldWVHandleEvent = worldView.HandleEvent worldView.HandleEvent = function(self, event) - if marker and event.Type == 'ButtonPress' and not event.Modifiers.Middle and marker.frame:HitTest(event.MouseX, event.MouseY) then + if marker and event.Type == 'ButtonPress' and not event.Modifiers.Middle and + marker.frame:HitTest(event.MouseX, event.MouseY) then if positionMarkers[marker.army].views == 1 then positionMarkers[marker.army] = nil end @@ -92,9 +93,12 @@ local function CreatePositionMarker(army, worldView) marker.OnFrame = function(self, delta) if not worldView:IsHidden() then local pos = worldView:Project(self.pos) - LayoutHelpers.AtLeftTopIn(self, worldView, (pos.x - self.Width() / 2) / LayoutHelpers.GetPixelScaleFactor(), (pos.y - self.Height() / 2) / LayoutHelpers.GetPixelScaleFactor()) + LayoutHelpers.AtLeftTopIn(self, worldView, (pos.x - self.Width() / 2) / LayoutHelpers.GetPixelScaleFactor(), + (pos.y - self.Height() / 2) / LayoutHelpers.GetPixelScaleFactor()) - if (self:Left() < worldView:Left() or self:Top() < worldView:Top() or self:Right() > worldView:Right() or self:Bottom() > worldView:Bottom()) then + if ( + self:Left() < worldView:Left() or self:Top() < worldView:Top() or self:Right() > worldView:Right() or + self:Bottom() > worldView:Bottom()) then if not self:IsHidden() then self:Hide() end @@ -120,7 +124,8 @@ 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 +137,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 +191,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 @@ -200,11 +224,13 @@ function Expand() viewLeft.Top:Set(gameViewTemp.Top) viewLeft.Left:Set(gameViewTemp.Left) - viewLeft.Right:Set(function() return (gameViewTemp.Left() - 2) + ((gameViewTemp.Right() - gameViewTemp.Left()) / 2) end) + viewLeft.Right:Set(function() return (gameViewTemp.Left() - 2) + + ((gameViewTemp.Right() - gameViewTemp.Left()) / 2) end) viewLeft.Bottom:Set(gameViewTemp.Bottom) viewRight.Top:Set(gameViewTemp.Top) - viewRight.Left:Set(function() return (gameViewTemp.Left() + 2) + ((gameViewTemp.Right() - gameViewTemp.Left()) / 2) end) + viewRight.Left:Set(function() return (gameViewTemp.Left() + 2) + + ((gameViewTemp.Right() - gameViewTemp.Left()) / 2) end) viewRight.Right:Set(gameViewTemp.Right) viewRight.Bottom:Set(gameViewTemp.Bottom) else From 5ddd57db456ba3b1cfa3092c63a189e3c2d96553 Mon Sep 17 00:00:00 2001 From: "(Jip) Willem Wijnia" Date: Thu, 5 Dec 2024 19:21:58 +0100 Subject: [PATCH 2/6] Add a snippet --- changelog/snippets/features.6576.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/snippets/features.6576.md diff --git a/changelog/snippets/features.6576.md b/changelog/snippets/features.6576.md new file mode 100644 index 0000000000..63b1bae8b8 --- /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 From 5474cbd71ec98a90e5ba2844ae025ade4ba1c09a Mon Sep 17 00:00:00 2001 From: "(Jip) Willem Wijnia" Date: Mon, 9 Dec 2024 07:11:13 +0100 Subject: [PATCH 3/6] Update changelog/snippets/features.6576.md Co-authored-by: lL1l1 <82986251+lL1l1@users.noreply.github.com> --- changelog/snippets/features.6576.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/snippets/features.6576.md b/changelog/snippets/features.6576.md index 63b1bae8b8..7d5e86629b 100644 --- a/changelog/snippets/features.6576.md +++ b/changelog/snippets/features.6576.md @@ -1,3 +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 + 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 From 16e12f4c324c36aa7c6ddd3854815fc6dfdc2d94 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Tue, 24 Dec 2024 18:44:57 -0800 Subject: [PATCH 4/6] Undo line breaks --- lua/ui/game/worldview.lua | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/lua/ui/game/worldview.lua b/lua/ui/game/worldview.lua index dc704e8738..4904bae671 100644 --- a/lua/ui/game/worldview.lua +++ b/lua/ui/game/worldview.lua @@ -78,8 +78,7 @@ local function CreatePositionMarker(army, worldView) -- That often happens even if the cursor is nowhere near the marker, so it's unusable. This way isn't pretty, but at least it works correctly. local oldWVHandleEvent = worldView.HandleEvent worldView.HandleEvent = function(self, event) - if marker and event.Type == 'ButtonPress' and not event.Modifiers.Middle and - marker.frame:HitTest(event.MouseX, event.MouseY) then + if marker and event.Type == 'ButtonPress' and not event.Modifiers.Middle and marker.frame:HitTest(event.MouseX, event.MouseY) then if positionMarkers[marker.army].views == 1 then positionMarkers[marker.army] = nil end @@ -93,12 +92,8 @@ local function CreatePositionMarker(army, worldView) marker.OnFrame = function(self, delta) if not worldView:IsHidden() then local pos = worldView:Project(self.pos) - LayoutHelpers.AtLeftTopIn(self, worldView, (pos.x - self.Width() / 2) / LayoutHelpers.GetPixelScaleFactor(), - (pos.y - self.Height() / 2) / LayoutHelpers.GetPixelScaleFactor()) - - if ( - self:Left() < worldView:Left() or self:Top() < worldView:Top() or self:Right() > worldView:Right() or - self:Bottom() > worldView:Bottom()) then + LayoutHelpers.AtLeftTopIn(self, worldView, (pos.x - self.Width() / 2) / LayoutHelpers.GetPixelScaleFactor(), (pos.y - self.Height() / 2) / LayoutHelpers.GetPixelScaleFactor()) + if (self:Left() < worldView:Left() or self:Top() < worldView:Top() or self:Right() > worldView:Right() or self:Bottom() > worldView:Bottom()) then if not self:IsHidden() then self:Hide() end @@ -124,8 +119,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 @@ -224,13 +218,11 @@ function Expand() viewLeft.Top:Set(gameViewTemp.Top) viewLeft.Left:Set(gameViewTemp.Left) - viewLeft.Right:Set(function() return (gameViewTemp.Left() - 2) + - ((gameViewTemp.Right() - gameViewTemp.Left()) / 2) end) + viewLeft.Right:Set(function() return (gameViewTemp.Left() - 2) + ((gameViewTemp.Right() - gameViewTemp.Left()) / 2) end) viewLeft.Bottom:Set(gameViewTemp.Bottom) viewRight.Top:Set(gameViewTemp.Top) - viewRight.Left:Set(function() return (gameViewTemp.Left() + 2) + - ((gameViewTemp.Right() - gameViewTemp.Left()) / 2) end) + viewRight.Left:Set(function() return (gameViewTemp.Left() + 2) + ((gameViewTemp.Right() - gameViewTemp.Left()) / 2) end) viewRight.Right:Set(gameViewTemp.Right) viewRight.Bottom:Set(gameViewTemp.Bottom) else From c071a4e2e144bd813a5734755455eb016f864725 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Tue, 24 Dec 2024 19:11:02 -0800 Subject: [PATCH 5/6] Unset lua formatter max line length --- .vscode/settings.json | 3 +++ 1 file changed, 3 insertions(+) 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": [ From 401077d1dbaea09a738cc462ca2d90f2620d9174 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Tue, 24 Dec 2024 19:12:00 -0800 Subject: [PATCH 6/6] Re-add a line break --- lua/ui/game/worldview.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/ui/game/worldview.lua b/lua/ui/game/worldview.lua index 4904bae671..ac7d4abe5a 100644 --- a/lua/ui/game/worldview.lua +++ b/lua/ui/game/worldview.lua @@ -93,6 +93,7 @@ local function CreatePositionMarker(army, worldView) if not worldView:IsHidden() then local pos = worldView:Project(self.pos) LayoutHelpers.AtLeftTopIn(self, worldView, (pos.x - self.Width() / 2) / LayoutHelpers.GetPixelScaleFactor(), (pos.y - self.Height() / 2) / LayoutHelpers.GetPixelScaleFactor()) + if (self:Left() < worldView:Left() or self:Top() < worldView:Top() or self:Right() > worldView:Right() or self:Bottom() > worldView:Bottom()) then if not self:IsHidden() then self:Hide()