From e0bbb60de052fa9a896eded0683edd3fb99049fa Mon Sep 17 00:00:00 2001 From: "(Jip) Willem Wijnia" Date: Sun, 1 Dec 2024 12:27:22 +0100 Subject: [PATCH 01/10] Update camera documentation --- engine/User/CameraImpl.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/engine/User/CameraImpl.lua b/engine/User/CameraImpl.lua index 0ee6ed10cc..d314e879df 100644 --- a/engine/User/CameraImpl.lua +++ b/engine/User/CameraImpl.lua @@ -12,10 +12,14 @@ local CameraImpl = {} ---@alias UserCameraAccelerationModes 'Linear' | 'FastInSlowOut' | 'SlowInOut' ---- +--- Enables smooth transitions. function CameraImpl:EnableEaseInOut() end +--- Disables smooth transitions. +function CameraImpl:DisableEaseInOut() +end + --- Returns the focus point (on the terrain) of the center of the screen ---@return Vector function CameraImpl:GetFocusPosition() From 6e523e68214d606b860d72ef670baf7f36e0f4f2 Mon Sep 17 00:00:00 2001 From: "(Jip) Willem Wijnia" Date: Sun, 1 Dec 2024 12:27:37 +0100 Subject: [PATCH 02/10] Add cinematics key category --- lua/keymap/keycategories.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/keymap/keycategories.lua b/lua/keymap/keycategories.lua index b985136d01..70a2e0f788 100644 --- a/lua/keymap/keycategories.lua +++ b/lua/keymap/keycategories.lua @@ -7,6 +7,7 @@ keyCategories = { ['selectionControlGroups'] = "Selection - Control groups", ['selectionSubgroups'] = "Selection - Subgroups", ['camera'] = "Camera", + ['cinematics'] = "Cinematics", ['orders'] = "Orders", ['ordersAdvanced'] = "Orders - Advanced", ['ordersQueueBased'] = "Orders - Queue manipulation", @@ -42,6 +43,7 @@ keyCategoryOrder = { 'user', 'mods', 'debug', + 'cinematics', 'ai', 'none' } From 97e000c1fd3c4b3faeda29ab30b9969e14677145 Mon Sep 17 00:00:00 2001 From: "(Jip) Willem Wijnia" Date: Sun, 1 Dec 2024 12:27:48 +0100 Subject: [PATCH 03/10] Add setup for MoveTo --- lua/keymap/keyactions.lua | 53 ++++++ lua/keymap/keydescriptions.lua | 13 ++ lua/ui/game/cinematics/MoveTo.lua | 297 ++++++++++++++++++++++++++++++ 3 files changed, 363 insertions(+) create mode 100644 lua/ui/game/cinematics/MoveTo.lua diff --git a/lua/keymap/keyactions.lua b/lua/keymap/keyactions.lua index 4a4d52d8f1..e7bcc8830c 100755 --- a/lua/keymap/keyactions.lua +++ b/lua/keymap/keyactions.lua @@ -1945,6 +1945,58 @@ local keyActionsMisc = { } +---@type table +local keyActionsCinematics = { + ['cinematics_move_to_clear'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").Clear()', + category = 'cinematics', + }, + ['cinematics_move_to_add'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").Add()', + category = 'cinematics', + }, + ['cinematics_move_to_next'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").AnimateNext()', + category = 'cinematics', + }, + ['cinematics_move_to_prev'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").AnimatePrevious()', + category = 'cinematics', + }, + ['cinematics_move_to_jump_next'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").JumpAndAnimateNext()', + category = 'cinematics', + }, + ['cinematics_move_to_jump_prev'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").JumpAndAnimatePrevious()', + category = 'cinematics', + }, + ['cinematics_move_to_store_01'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").StoreToDisk("01")', + category = 'cinematics', + }, + ['cinematics_move_to_store_02'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").StoreToDisk("02")', + category = 'cinematics', + }, + ['cinematics_move_to_store_03'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").StoreToDisk("03")', + category = 'cinematics', + }, + ['cinematics_move_to_retrieve_01'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").RetrieveFromDisk("01")', + category = 'cinematics', + }, + ['cinematics_move_to_retrieve_02'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").RetrieveFromDisk("02")', + category = 'cinematics', + }, + ['cinematics_move_to_retrieve_03'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").RetrieveFromDisk("03")', + category = 'cinematics', + } +} + ---@type table keyActions = table.combine( keyActionsCamera, @@ -1962,5 +2014,6 @@ keyActions = table.combine( keyActionsGame, keyActionsChat, keyActionsUI, + keyActionsCinematics, keyActionsMisc ) diff --git a/lua/keymap/keydescriptions.lua b/lua/keymap/keydescriptions.lua index 0038d15413..652a07931e 100755 --- a/lua/keymap/keydescriptions.lua +++ b/lua/keymap/keydescriptions.lua @@ -560,4 +560,17 @@ keyDescriptions = { ['select_surface_bombers'] = 'Select all Bombers (Normal)', ['select_torpedo_bombers'] = 'Select all Bombers (Torpedo)', + + ['cinematics_move_to_clear'] = 'MoveTo - Clear the MoveTo sequence', + ['cinematics_move_to_add'] = 'MoveTo - Add current camera position to the MoveTo sequence', + ['cinematics_move_to_next'] = 'MoveTo - Animate to next position in the MoveTo sequence', + ['cinematics_move_to_prev'] = 'MoveTo - Animate to previous position in the MoveTo sequence', + ['cinematics_move_to_jump_next'] = 'MoveTo - Jump to next position and proceed to animate to the position after that', + ['cinematics_move_to_jump_prev'] = 'MoveTo - Jump to previous position and proceed to animate to the position before that', + ['cinematics_move_to_store_01'] = 'MoveTo - Save the 1st MoveTo sequence to the preference file', + ['cinematics_move_to_store_02'] = 'MoveTo - Save the 2nd MoveTo sequence to the preference file', + ['cinematics_move_to_store_03'] = 'MoveTo - Save the 3rd MoveTo sequence to the preference file', + ['cinematics_move_to_retrieve_01'] = 'MoveTo - Load the 1st MoveTo sequence from the preference file', + ['cinematics_move_to_retrieve_02'] = 'MoveTo - Load the 2nd MoveTo sequence from the preference file', + ['cinematics_move_to_retrieve_03'] = 'MoveTo - Load the 3rd MoveTo sequence from the preference file', } diff --git a/lua/ui/game/cinematics/MoveTo.lua b/lua/ui/game/cinematics/MoveTo.lua new file mode 100644 index 0000000000..f65c413a5e --- /dev/null +++ b/lua/ui/game/cinematics/MoveTo.lua @@ -0,0 +1,297 @@ +--******************************************************************************* +-- MIT License +-- +-- Copyright (c) 2024 (Jip) Willem Wijnia +-- +-- Permission is hereby granted, free of charge, to any person obtaining a copy +-- of this software and associated documentation files (the "Software"), to deal +-- in the Software without restriction, including without limitation the rights +-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +-- copies of the Software, and to permit persons to whom the Software is +-- furnished to do so, subject to the following conditions: +-- +-- The above copyright notice and this permission notice shall be included in all +-- copies or substantial portions of the Software. +-- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +-- SOFTWARE. +-- +--******************************************************************************* + +local PreferenceKey = "CinematicsMoveTo" +local DefaultCamera = "WorldCamera" + +---@type TrashBag +local ModuleTrash = TrashBag() + +---@type number +SequenceIndex = 1 + +---@type UserCameraSettings[] +Sequence = {} + +--- Moves the given camera to the specified settings. +---@param camera Camera +---@param settings UserCameraSettings +---@param duration? number +local MoveTo = function(camera, settings, duration) + duration = duration or 4 + + camera:MoveTo(settings.Focus, { settings.Heading, settings.Pitch, 0 }, settings.Zoom, duration) +end + +---@param index number +---@param count number +---@return number +local WrapSequenceIndex = function(index, count) + return math.mod(index - 1 + count, count) + 1 +end + +--- Clears the sequence. +Clear = function() + SequenceIndex = 1 + Sequence = {} + + print("Reset sequence for MoveTo") +end + +--- Stores the current sequence to the preference file. +---@param key any +StoreToDisk = function(key) + local prefs = import("/lua/user/prefs.lua") + + local stringifiedKey = tostring(key) + prefs.SetToCurrentProfile(PreferenceKey .. stringifiedKey, Sequence) + + -- inform user + print("Saved sequence for MoveTo to key '" .. stringifiedKey .. "'") + SavePreferences() +end + +--- Retrieves a sequence from the preference file. +---@param key any +RetrieveFromDisk = function(key) + local prefs = import("/lua/user/prefs.lua") + + local stringifiedKey = tostring(key) + local sequence = prefs.GetFromCurrentProfile(PreferenceKey .. stringifiedKey) + if not sequence then + print("No sequence found for key '" .. stringifiedKey .. "'") + end + + Sequence = sequence + SequenceIndex = 1 + + -- inform user + print("Loaded sequence for MoveTo to key '" .. stringifiedKey .. "' (" .. table.getn(Sequence) .. " steps)") +end + +--- Add a camera position to the sequence. +Add = function() + local camera = GetCamera(DefaultCamera) + table.insert(Sequence, camera:SaveSettings()) + + reprsl(camera) + reprsl(getmetatable(camera)) + print("Add to sequence (" .. table.getn(Sequence) .. " steps)") +end + +--- Inserts a camera position at the specified index. +---@param index number +Insert = function(index) + local camera = GetCamera(DefaultCamera) + table.insert(camera, index) + + print("Insert into sequence at index " .. index .. " (" .. table.getn(Sequence) .. " steps)") +end + +--- Overwrites the camera position at the specified index. +---@param index number +Overwrite = function(index) + local camera = GetCamera(DefaultCamera) + if Sequence[index] then + Sequence[index] = camera:SaveSettings() + print("Overwritten into sequence at index " .. index .. " (" .. table.getn(Sequence) .. " steps)") + end +end + +--- Move the camera to the last position in the sequence. +---@see `ToFirstState` +ToLastState = function() + local count = table.getn(Sequence) + if count == 0 then + print("No camera sequence defined") + return + end + + SequenceIndex = count + local state = Sequence[count] + local camera = GetCamera(DefaultCamera) + camera:RestoreSettings(state) +end + +--- Move the camera to the first position in the sequence. +---@see `ToLastState` +ToFirstState = function() + local count = table.getn(Sequence) + if count == 0 then + print("No camera sequence defined") + return + end + + SequenceIndex = count + local state = Sequence[count] + local camera = GetCamera(DefaultCamera) + camera:RestoreSettings(state) +end + +--- Immediately jump to the current position in the sequence. +---@param doPrint? boolean # defaults to false +JumpToCurrent = function(doPrint) + doPrint = doPrint or false + + local index = GetSequenceIndex() + if not index then + return + end + + local state = Sequence[index] + local camera = GetCamera(DefaultCamera) + camera:RestoreSettings(state) + + if doPrint then + print("Jumped to index " .. SequenceIndex .. " of " .. table.getn(Sequence)) + end +end + +--- Immediately jump to the next position in the sequence. +---@param doPrint? boolean # defaults to false +---@return Camera? +JumpToNext = function(doPrint) + doPrint = doPrint or false + + local sequenceCount = table.getn(Sequence) + if sequenceCount == 0 then + print("No camera sequence defined") + return nil + end + + -- update sequence index + SequenceIndex = WrapSequenceIndex(SequenceIndex + 1, sequenceCount) + + local state = Sequence[SequenceIndex] + local camera = GetCamera(DefaultCamera) + camera:RestoreSettings(state) + + if doPrint then + print("Jumped to index " .. SequenceIndex .. " of " .. table.getn(Sequence)) + end + + return camera +end + +--- Immediately jump to the previous position in the sequence. +---@param doPrint? boolean +---@return Camera? +JumpToPrevious = function(doPrint) + doPrint = doPrint or false + + local sequenceCount = table.getn(Sequence) + if sequenceCount == 0 then + print("No camera sequence defined") + return nil + end + + -- update sequence index + SequenceIndex = WrapSequenceIndex(SequenceIndex - 1, sequenceCount) + + local state = Sequence[SequenceIndex] + local camera = GetCamera(DefaultCamera) + camera:RestoreSettings(state) + + if doPrint then + print("Jumped to index " .. SequenceIndex .. " of " .. table.getn(Sequence)) + end + + return camera +end + +--- Animate the camera to the next position. +---@see `ToPreviousState` +---@return Camera? # Allows you to wait for the camera to finish +AnimateNext = function() + local index = GetSequenceIndex() + if not index then + return + end + + local state = Sequence[index] + local camera = GetCamera(DefaultCamera) + MoveTo(camera, state) + + -- push the sequence + SequenceIndex = SequenceIndex + 1 + + return camera +end + +--- Move the camera to the previous position in the sequence. +---@see `ToNextState` +---@return Camera? # Allows you to wait for the camera to finish +AnimatePrevious = function() + local index = GetSequenceIndex() + if not index then + return + end + + local state = Sequence[index] + local camera = GetCamera(DefaultCamera) + MoveTo(camera, state) + + -- push the sequence + SequenceIndex = SequenceIndex - 1 + + return camera +end + +--- Jump the camera to the next position and then proceed to animate to the position after that. +---@return Camera? # Allows you to wait for the camera to finish +JumpAndAnimateNext = function() + JumpToNext() + return AnimateNext() +end + +--- Jump the camera to the previous position and then proceed to animate to the position before that. +---@return Camera? # Allows you to wait for the camera to finish +JumpAndAnimatePrevious = function() + JumpToPrevious() + return AnimatePrevious() +end + +------------------------------------------------------------------------------- +--#region Debugging + +-- This section provides a hot-reload like functionality when debugging this +-- module. It requires the `/EnableDiskWatch` program argument. +-- +-- The code is not required for normal operation. + +--- Called by the module manager when this module is reloaded +---@param newModule any +function __moduleinfo.OnReload(newModule) + -- copy over state + newModule.SequenceIndex = SequenceIndex + newModule.Sequence = Sequence +end + +--- Called by the module manager when this module becomes dirty. +function __moduleinfo.OnDirty() + ModuleTrash:Destroy() +end + +--#endregion From f8127faeddeaa0cdb152cf9e94bf5671c7b8dda2 Mon Sep 17 00:00:00 2001 From: "(Jip) Willem Wijnia" Date: Sun, 1 Dec 2024 12:28:11 +0100 Subject: [PATCH 04/10] Rename camera class to `UserCamera` --- engine/Core.lua | 2 +- engine/User.lua | 2 +- engine/User/CUIWorldView.lua | 6 +++--- engine/User/CameraImpl.lua | 2 +- lua/ui/game/cinematics/MoveTo.lua | 14 +++++++------- lua/ui/game/cursor/depth.lua | 2 +- lua/ui/game/cursor/hover.lua | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/engine/Core.lua b/engine/Core.lua index 22177dd279..0d6c3e9c62 100644 --- a/engine/Core.lua +++ b/engine/Core.lua @@ -45,7 +45,7 @@ ---@alias Language "cn" | "cz" | "de" | "es" | "fr" | "it" | "pl" | "ru" | "tw" | "tzm" | "us" -- note that these object span both the sim and user states ----@alias GoalObject moho.manipulator_methods | EconomyEvent | Camera +---@alias GoalObject moho.manipulator_methods | EconomyEvent | UserCamera ---@unknown function AITarget() diff --git a/engine/User.lua b/engine/User.lua index e80673bc60..1c1a720f80 100644 --- a/engine/User.lua +++ b/engine/User.lua @@ -351,7 +351,7 @@ end --- ---@param name string ----@return Camera +---@return UserCamera function GetCamera(name) end diff --git a/engine/User/CUIWorldView.lua b/engine/User/CUIWorldView.lua index 6e24a8d33f..07c2921f2b 100644 --- a/engine/User/CUIWorldView.lua +++ b/engine/User/CUIWorldView.lua @@ -60,7 +60,7 @@ function CUIWorldView:IsCartographic() end --- ----@param camera Camera +---@param camera UserCamera function CUIWorldView:IsInputLocked(camera) end @@ -70,7 +70,7 @@ function CUIWorldView:IsResourceRenderingEnabled() end --- ----@param camera Camera +---@param camera UserCamera function CUIWorldView:LockInput(camera) end @@ -96,7 +96,7 @@ function CUIWorldView:ShowConvertToPatrolCursor() end --- ----@param camera Camera +---@param camera UserCamera function CUIWorldView:UnlockInput(camera) end diff --git a/engine/User/CameraImpl.lua b/engine/User/CameraImpl.lua index d314e879df..ed836fc05e 100644 --- a/engine/User/CameraImpl.lua +++ b/engine/User/CameraImpl.lua @@ -1,6 +1,6 @@ ---@meta ----@class Camera +---@class UserCamera local CameraImpl = {} diff --git a/lua/ui/game/cinematics/MoveTo.lua b/lua/ui/game/cinematics/MoveTo.lua index f65c413a5e..633d890a04 100644 --- a/lua/ui/game/cinematics/MoveTo.lua +++ b/lua/ui/game/cinematics/MoveTo.lua @@ -36,7 +36,7 @@ SequenceIndex = 1 Sequence = {} --- Moves the given camera to the specified settings. ----@param camera Camera +---@param camera UserCamera ---@param settings UserCameraSettings ---@param duration? number local MoveTo = function(camera, settings, duration) @@ -171,7 +171,7 @@ end --- Immediately jump to the next position in the sequence. ---@param doPrint? boolean # defaults to false ----@return Camera? +---@return UserCamera? JumpToNext = function(doPrint) doPrint = doPrint or false @@ -197,7 +197,7 @@ end --- Immediately jump to the previous position in the sequence. ---@param doPrint? boolean ----@return Camera? +---@return UserCamera? JumpToPrevious = function(doPrint) doPrint = doPrint or false @@ -223,7 +223,7 @@ end --- Animate the camera to the next position. ---@see `ToPreviousState` ----@return Camera? # Allows you to wait for the camera to finish +---@return UserCamera? # Allows you to wait for the camera to finish AnimateNext = function() local index = GetSequenceIndex() if not index then @@ -242,7 +242,7 @@ end --- Move the camera to the previous position in the sequence. ---@see `ToNextState` ----@return Camera? # Allows you to wait for the camera to finish +---@return UserCamera? # Allows you to wait for the camera to finish AnimatePrevious = function() local index = GetSequenceIndex() if not index then @@ -260,14 +260,14 @@ AnimatePrevious = function() end --- Jump the camera to the next position and then proceed to animate to the position after that. ----@return Camera? # Allows you to wait for the camera to finish +---@return UserCamera? # Allows you to wait for the camera to finish JumpAndAnimateNext = function() JumpToNext() return AnimateNext() end --- Jump the camera to the previous position and then proceed to animate to the position before that. ----@return Camera? # Allows you to wait for the camera to finish +---@return UserCamera? # Allows you to wait for the camera to finish JumpAndAnimatePrevious = function() JumpToPrevious() return AnimatePrevious() diff --git a/lua/ui/game/cursor/depth.lua b/lua/ui/game/cursor/depth.lua index b4d8d7da7b..870b63da8d 100644 --- a/lua/ui/game/cursor/depth.lua +++ b/lua/ui/game/cursor/depth.lua @@ -72,7 +72,7 @@ local function CheckConditions(CommandMode) end --- Defines the transparency curve ----@param camera Camera +---@param camera UserCamera ---@param distance number ---@param terrainHeight number ---@param surfaceHeight number diff --git a/lua/ui/game/cursor/hover.lua b/lua/ui/game/cursor/hover.lua index 145b988ec0..cef7813c5e 100644 --- a/lua/ui/game/cursor/hover.lua +++ b/lua/ui/game/cursor/hover.lua @@ -34,7 +34,7 @@ local function CheckConditions() end --- Defines the transparency curve ----@param camera Camera +---@param camera UserCamera ---@param distance number ---@param unitPosition Vector ---@param mousePosition Vector From 11c1448a996499da585a3a5e77348eed100112ee Mon Sep 17 00:00:00 2001 From: "(Jip) Willem Wijnia" Date: Sun, 1 Dec 2024 13:20:40 +0100 Subject: [PATCH 05/10] Finalize the implementation --- engine/User/CameraImpl.lua | 6 +- lua/keymap/keyactions.lua | 52 ++++++-- lua/keymap/keydescriptions.lua | 25 +++- lua/ui/game/cinematics/MoveTo.lua | 214 ++++++++++++++++++------------ 4 files changed, 195 insertions(+), 102 deletions(-) diff --git a/engine/User/CameraImpl.lua b/engine/User/CameraImpl.lua index ed836fc05e..c4ae16094a 100644 --- a/engine/User/CameraImpl.lua +++ b/engine/User/CameraImpl.lua @@ -113,9 +113,9 @@ function CameraImpl:SetZoom(zoom, seconds) end --- Snaps the camera to the given position, orientation and zoom ----@param position any ----@param orientationHPR any ----@param zoom any +---@param position Vector +---@param orientationHPR Vector +---@param zoom number function CameraImpl:SnapTo(position, orientationHPR, zoom) end diff --git a/lua/keymap/keyactions.lua b/lua/keymap/keyactions.lua index e7bcc8830c..004e8510e5 100755 --- a/lua/keymap/keyactions.lua +++ b/lua/keymap/keyactions.lua @@ -1947,30 +1947,62 @@ local keyActionsMisc = { ---@type table local keyActionsCinematics = { + -- CRUD-like operations ['cinematics_move_to_clear'] = { - action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").Clear()', + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").Clear(true)', category = 'cinematics', }, ['cinematics_move_to_add'] = { - action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").Add()', + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").Append(true)', category = 'cinematics', }, - ['cinematics_move_to_next'] = { - action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").AnimateNext()', + ['cinematics_move_to_insert'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").Insert(true)', category = 'cinematics', }, - ['cinematics_move_to_prev'] = { - action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").AnimatePrevious()', + ['cinematics_move_to_overwrite'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").Overwrite(true)', category = 'cinematics', }, - ['cinematics_move_to_jump_next'] = { - action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").JumpAndAnimateNext()', + ['cinematics_move_to_remove'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").Remove(true)', category = 'cinematics', }, - ['cinematics_move_to_jump_prev'] = { - action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").JumpAndAnimatePrevious()', + + -- Navigation + ['cinematics_move_to_jump_current'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").JumpToCurrent(true)', + category = 'cinematics', + }, + ['cinematics_move_to_jump_forward'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").JumpForward(true)', + category = 'cinematics', + }, + ['cinematics_move_to_jump_backward'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").JumpBackward(true)', + category = 'cinematics', + }, + + -- Animation + ['cinematics_move_to_animate_forward'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").AnimateForward(true)', category = 'cinematics', }, + ['cinematics_move_to_animate_backward'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").AnimateBackwards(true)', + category = 'cinematics', + }, + + ['cinematics_move_to_jump_and_animate_forward'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").JumpAndAnimateNext(true)', + category = 'cinematics', + }, + ['cinematics_move_to_jump_and_animate_backward'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").JumpAndAnimatePrevious(true)', + category = 'cinematics', + }, + + -- Preference file interactions ['cinematics_move_to_store_01'] = { action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").StoreToDisk("01")', category = 'cinematics', diff --git a/lua/keymap/keydescriptions.lua b/lua/keymap/keydescriptions.lua index 652a07931e..5927de74a4 100755 --- a/lua/keymap/keydescriptions.lua +++ b/lua/keymap/keydescriptions.lua @@ -561,12 +561,25 @@ keyDescriptions = { ['select_surface_bombers'] = 'Select all Bombers (Normal)', ['select_torpedo_bombers'] = 'Select all Bombers (Torpedo)', - ['cinematics_move_to_clear'] = 'MoveTo - Clear the MoveTo sequence', - ['cinematics_move_to_add'] = 'MoveTo - Add current camera position to the MoveTo sequence', - ['cinematics_move_to_next'] = 'MoveTo - Animate to next position in the MoveTo sequence', - ['cinematics_move_to_prev'] = 'MoveTo - Animate to previous position in the MoveTo sequence', - ['cinematics_move_to_jump_next'] = 'MoveTo - Jump to next position and proceed to animate to the position after that', - ['cinematics_move_to_jump_prev'] = 'MoveTo - Jump to previous position and proceed to animate to the position before that', + -- CRUD-like operations + ['cinematics_move_to_clear'] = 'MoveTo - Clear sequence', + ['cinematics_move_to_add'] = 'MoveTo - Append current camera position to the sequence', + ['cinematics_move_to_insert'] = 'MoveTo - Insert current camera position at the current index of the sequence', + ['cinematics_move_to_overwrite'] = 'MoveTo - Overwrite with current camera position at the current index of the sequence', + ['cinematics_move_to_remove'] = 'MoveTo - Remove camera position at the current index of the sequence', + + -- Navigation + ['cinematics_move_to_jump_current'] = 'MoveTo - Jump to the camera position at the current index of the sequence', + ['cinematics_move_to_jump_forward'] = 'MoveTo - Jump to the next camera position in the sequence', + ['cinematics_move_to_jump_backward'] = 'MoveTo - Jump to the previous camera position in the sequence', + + -- Animation + ['cinematics_move_to_animate_forward'] = 'MoveTo - Animate to the next camera position in the sequence', + ['cinematics_move_to_animate_backward'] = 'MoveTo - Animate to the previous camera position in the sequence', + ['cinematics_move_to_jump_and_animate_forward'] = 'MoveTo - Jump to the next camera position, then animate to the one after', + ['cinematics_move_to_jump_and_animate_backward'] = 'MoveTo - Jump to the previous camera position, then animate to the one before', + + -- Preference file interactions ['cinematics_move_to_store_01'] = 'MoveTo - Save the 1st MoveTo sequence to the preference file', ['cinematics_move_to_store_02'] = 'MoveTo - Save the 2nd MoveTo sequence to the preference file', ['cinematics_move_to_store_03'] = 'MoveTo - Save the 3rd MoveTo sequence to the preference file', diff --git a/lua/ui/game/cinematics/MoveTo.lua b/lua/ui/game/cinematics/MoveTo.lua index 633d890a04..d884d09aa8 100644 --- a/lua/ui/game/cinematics/MoveTo.lua +++ b/lua/ui/game/cinematics/MoveTo.lua @@ -41,10 +41,18 @@ Sequence = {} ---@param duration? number local MoveTo = function(camera, settings, duration) duration = duration or 4 - + camera:MoveTo(settings.Focus, { settings.Heading, settings.Pitch, 0 }, settings.Zoom, duration) end +--- Moves the given camera to the specified settings. +---@param camera UserCamera +---@param settings UserCameraSettings +local SnapTo = function(camera, settings) + camera:SnapTo(settings.Focus, { settings.Heading, settings.Pitch, 0 }, settings.Zoom) +end + +--- Wraps the given index so that it always fits within the sequence. ---@param index number ---@param count number ---@return number @@ -53,131 +61,159 @@ local WrapSequenceIndex = function(index, count) end --- Clears the sequence. -Clear = function() +---@param doPrint? boolean +Clear = function(doPrint) SequenceIndex = 1 Sequence = {} - print("Reset sequence for MoveTo") + if doPrint then + print("MoveTo - reset sequence") + end end --- Stores the current sequence to the preference file. ----@param key any -StoreToDisk = function(key) +---@param key string +---@param doPrint? boolean +StoreToDisk = function(key, doPrint) local prefs = import("/lua/user/prefs.lua") local stringifiedKey = tostring(key) prefs.SetToCurrentProfile(PreferenceKey .. stringifiedKey, Sequence) - - -- inform user - print("Saved sequence for MoveTo to key '" .. stringifiedKey .. "'") SavePreferences() + + if doPrint then + print("MoveTo - Saved sequence for MoveTo to key '" .. stringifiedKey .. "'") + end end --- Retrieves a sequence from the preference file. ----@param key any -RetrieveFromDisk = function(key) +---@param key string +---@param doPrint? boolean +RetrieveFromDisk = function(key, doPrint) local prefs = import("/lua/user/prefs.lua") local stringifiedKey = tostring(key) local sequence = prefs.GetFromCurrentProfile(PreferenceKey .. stringifiedKey) if not sequence then - print("No sequence found for key '" .. stringifiedKey .. "'") + if doPrint then + print("MoveTo - No sequence found for key '" .. stringifiedKey .. "'") + end end Sequence = sequence SequenceIndex = 1 -- inform user - print("Loaded sequence for MoveTo to key '" .. stringifiedKey .. "' (" .. table.getn(Sequence) .. " steps)") + if doPrint then + print("MoveTo - Loaded sequence for MoveTo to key '" .. + stringifiedKey .. "' (" .. table.getn(Sequence) .. " steps)") + end end ---- Add a camera position to the sequence. -Add = function() +--- Append a camera position to the end of the sequence. +---@param doPrint? boolean +Append = function(doPrint) local camera = GetCamera(DefaultCamera) table.insert(Sequence, camera:SaveSettings()) - reprsl(camera) - reprsl(getmetatable(camera)) - print("Add to sequence (" .. table.getn(Sequence) .. " steps)") + if doPrint then + print("MoveTo - Add to sequence (" .. table.getn(Sequence) .. " steps)") + end end --- Inserts a camera position at the specified index. ----@param index number -Insert = function(index) +---@param doPrint? boolean +Insert = function(doPrint) + local sequenceCount = table.getn(Sequence) + if sequenceCount == 0 then + SequenceIndex = 1 + else + SequenceIndex = WrapSequenceIndex(SequenceIndex, sequenceCount) + end + local camera = GetCamera(DefaultCamera) - table.insert(camera, index) + table.insert(camera, SequenceIndex, camera:SaveSettings()) - print("Insert into sequence at index " .. index .. " (" .. table.getn(Sequence) .. " steps)") -end + local t = { 1, 2, 3 } + table.insert(t, 2, 4) + reprsl(t) ---- Overwrites the camera position at the specified index. ----@param index number -Overwrite = function(index) - local camera = GetCamera(DefaultCamera) - if Sequence[index] then - Sequence[index] = camera:SaveSettings() - print("Overwritten into sequence at index " .. index .. " (" .. table.getn(Sequence) .. " steps)") + if doPrint then + print("MoveTo - Insert into sequence at index " .. SequenceIndex .. " (" .. sequenceCount .. " steps)") end end ---- Move the camera to the last position in the sequence. ----@see `ToFirstState` -ToLastState = function() - local count = table.getn(Sequence) - if count == 0 then - print("No camera sequence defined") - return +--- Overwrites the camera position at the specified index. +---@param doPrint? boolean +Overwrite = function(doPrint) + local sequenceCount = table.getn(Sequence) + if sequenceCount == 0 then + SequenceIndex = 1 + else + SequenceIndex = WrapSequenceIndex(SequenceIndex, sequenceCount) end - SequenceIndex = count - local state = Sequence[count] local camera = GetCamera(DefaultCamera) - camera:RestoreSettings(state) + if Sequence[SequenceIndex] then + Sequence[SequenceIndex] = camera:SaveSettings() + + if doPrint then + print("MoveTo - Overwritten into sequence at index " .. SequenceIndex .. " (" .. sequenceCount .. " steps)") + end + end end ---- Move the camera to the first position in the sequence. ----@see `ToLastState` -ToFirstState = function() - local count = table.getn(Sequence) - if count == 0 then +--- Removes the current camera position. +---@param doPrint? boolean +Remove = function(doPrint) + local sequenceCount = table.getn(Sequence) + if sequenceCount == 0 then print("No camera sequence defined") - return + return nil end - SequenceIndex = count - local state = Sequence[count] - local camera = GetCamera(DefaultCamera) - camera:RestoreSettings(state) + table.remove(Sequence, SequenceIndex) + + if doPrint then + print("MoveTo - Removed sequence " .. SequenceIndex .. " (" .. sequenceCount .. " steps)") + end end --- Immediately jump to the current position in the sequence. ---@param doPrint? boolean # defaults to false +---@return UserCamera? JumpToCurrent = function(doPrint) doPrint = doPrint or false - local index = GetSequenceIndex() - if not index then - return + local sequenceCount = table.getn(Sequence) + if sequenceCount == 0 then + print("No camera sequence defined") + return nil end - local state = Sequence[index] + -- update sequence index + SequenceIndex = WrapSequenceIndex(SequenceIndex, sequenceCount) + + local state = Sequence[SequenceIndex] local camera = GetCamera(DefaultCamera) - camera:RestoreSettings(state) + SnapTo(camera, state) if doPrint then - print("Jumped to index " .. SequenceIndex .. " of " .. table.getn(Sequence)) + print("MoveTo - jumped to (" .. SequenceIndex .. "/" .. sequenceCount .. ")") end + + return camera end --- Immediately jump to the next position in the sequence. ---@param doPrint? boolean # defaults to false ---@return UserCamera? -JumpToNext = function(doPrint) +JumpForward = function(doPrint) doPrint = doPrint or false local sequenceCount = table.getn(Sequence) if sequenceCount == 0 then - print("No camera sequence defined") + print("MoveTo - No camera sequence defined") return nil end @@ -186,10 +222,10 @@ JumpToNext = function(doPrint) local state = Sequence[SequenceIndex] local camera = GetCamera(DefaultCamera) - camera:RestoreSettings(state) + SnapTo(camera, state) if doPrint then - print("Jumped to index " .. SequenceIndex .. " of " .. table.getn(Sequence)) + print("MoveTo - jumped to (" .. SequenceIndex .. "/" .. sequenceCount .. ")") end return camera @@ -198,12 +234,12 @@ end --- Immediately jump to the previous position in the sequence. ---@param doPrint? boolean ---@return UserCamera? -JumpToPrevious = function(doPrint) +JumpBackward = function(doPrint) doPrint = doPrint or false local sequenceCount = table.getn(Sequence) if sequenceCount == 0 then - print("No camera sequence defined") + print("MoveTo - No camera sequence defined") return nil end @@ -212,10 +248,10 @@ JumpToPrevious = function(doPrint) local state = Sequence[SequenceIndex] local camera = GetCamera(DefaultCamera) - camera:RestoreSettings(state) + SnapTo(camera, state) if doPrint then - print("Jumped to index " .. SequenceIndex .. " of " .. table.getn(Sequence)) + print("MoveTo - jumped to (" .. SequenceIndex .. "/" .. sequenceCount .. ")") end return camera @@ -223,54 +259,66 @@ end --- Animate the camera to the next position. ---@see `ToPreviousState` +---@param doPrint? boolean ---@return UserCamera? # Allows you to wait for the camera to finish -AnimateNext = function() - local index = GetSequenceIndex() - if not index then - return +AnimateForward = function(doPrint) + local sequenceCount = table.getn(Sequence) + if sequenceCount == 0 then + print("MoveTo - No camera sequence defined") + return nil end - local state = Sequence[index] + -- update sequence index + SequenceIndex = WrapSequenceIndex(SequenceIndex + 1, sequenceCount) + + local state = Sequence[SequenceIndex] local camera = GetCamera(DefaultCamera) MoveTo(camera, state) - -- push the sequence - SequenceIndex = SequenceIndex + 1 + if doPrint then + print("MoveTo - animating to (" .. SequenceIndex .. "/" .. sequenceCount .. ")") + end return camera end --- Move the camera to the previous position in the sequence. ---@see `ToNextState` +---@param doPrint? boolean ---@return UserCamera? # Allows you to wait for the camera to finish -AnimatePrevious = function() - local index = GetSequenceIndex() - if not index then - return +AnimateBackwards = function(doPrint) + local sequenceCount = table.getn(Sequence) + if sequenceCount == 0 then + print("MoveTo - No camera sequence defined") + return nil end - local state = Sequence[index] + -- update sequence index + SequenceIndex = WrapSequenceIndex(SequenceIndex - 1, sequenceCount) + + local state = Sequence[SequenceIndex] local camera = GetCamera(DefaultCamera) MoveTo(camera, state) - -- push the sequence - SequenceIndex = SequenceIndex - 1 + if doPrint then + print("MoveTo - animating to (" .. SequenceIndex .. "/" .. sequenceCount .. ")") + end return camera end --- Jump the camera to the next position and then proceed to animate to the position after that. +---@param doPrint? boolean ---@return UserCamera? # Allows you to wait for the camera to finish -JumpAndAnimateNext = function() - JumpToNext() - return AnimateNext() +JumpAndAnimateNext = function(doPrint) + return JumpForward(doPrint) and AnimateForward(doPrint) end --- Jump the camera to the previous position and then proceed to animate to the position before that. +---@param doPrint? boolean ---@return UserCamera? # Allows you to wait for the camera to finish -JumpAndAnimatePrevious = function() - JumpToPrevious() - return AnimatePrevious() +JumpAndAnimatePrevious = function(doPrint) + return JumpBackward(doPrint) and AnimateBackwards(doPrint) end ------------------------------------------------------------------------------- From 4b40071dc9ee4a64fa230e6a7f86f7879281cbee Mon Sep 17 00:00:00 2001 From: "(Jip) Willem Wijnia" Date: Sun, 1 Dec 2024 13:23:35 +0100 Subject: [PATCH 06/10] Update insert operation --- lua/keymap/keydescriptions.lua | 2 +- lua/ui/game/cinematics/MoveTo.lua | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lua/keymap/keydescriptions.lua b/lua/keymap/keydescriptions.lua index 5927de74a4..d5c56216d8 100755 --- a/lua/keymap/keydescriptions.lua +++ b/lua/keymap/keydescriptions.lua @@ -564,7 +564,7 @@ keyDescriptions = { -- CRUD-like operations ['cinematics_move_to_clear'] = 'MoveTo - Clear sequence', ['cinematics_move_to_add'] = 'MoveTo - Append current camera position to the sequence', - ['cinematics_move_to_insert'] = 'MoveTo - Insert current camera position at the current index of the sequence', + ['cinematics_move_to_insert'] = 'MoveTo - Insert current camera position after the current index of the sequence', ['cinematics_move_to_overwrite'] = 'MoveTo - Overwrite with current camera position at the current index of the sequence', ['cinematics_move_to_remove'] = 'MoveTo - Remove camera position at the current index of the sequence', diff --git a/lua/ui/game/cinematics/MoveTo.lua b/lua/ui/game/cinematics/MoveTo.lua index d884d09aa8..64b27db3cd 100644 --- a/lua/ui/game/cinematics/MoveTo.lua +++ b/lua/ui/game/cinematics/MoveTo.lua @@ -132,11 +132,7 @@ Insert = function(doPrint) end local camera = GetCamera(DefaultCamera) - table.insert(camera, SequenceIndex, camera:SaveSettings()) - - local t = { 1, 2, 3 } - table.insert(t, 2, 4) - reprsl(t) + table.insert(camera, SequenceIndex + 1, camera:SaveSettings()) if doPrint then print("MoveTo - Insert into sequence at index " .. SequenceIndex .. " (" .. sequenceCount .. " steps)") From 637114f94fe3f14c5b39a7e7877a9939582f032e Mon Sep 17 00:00:00 2001 From: "(Jip) Willem Wijnia" Date: Sun, 1 Dec 2024 13:24:11 +0100 Subject: [PATCH 07/10] Remove un-used module trash --- lua/ui/game/cinematics/MoveTo.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lua/ui/game/cinematics/MoveTo.lua b/lua/ui/game/cinematics/MoveTo.lua index 64b27db3cd..c401e7fdb4 100644 --- a/lua/ui/game/cinematics/MoveTo.lua +++ b/lua/ui/game/cinematics/MoveTo.lua @@ -26,9 +26,6 @@ local PreferenceKey = "CinematicsMoveTo" local DefaultCamera = "WorldCamera" ----@type TrashBag -local ModuleTrash = TrashBag() - ---@type number SequenceIndex = 1 @@ -335,7 +332,7 @@ end --- Called by the module manager when this module becomes dirty. function __moduleinfo.OnDirty() - ModuleTrash:Destroy() + -- do nothing end --#endregion From b1bf5260a78f81ea1514fdc4792b85db329f063d Mon Sep 17 00:00:00 2001 From: "(Jip) Willem Wijnia" Date: Sun, 1 Dec 2024 16:22:13 +0100 Subject: [PATCH 08/10] Improve documentation --- engine/User.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/engine/User.lua b/engine/User.lua index 1c1a720f80..a52dc17a5c 100644 --- a/engine/User.lua +++ b/engine/User.lua @@ -124,6 +124,14 @@ --- | 'NUMPAD_DECIMAL' --- | 'NUMPAD_DIVIDE' +--- Represents a hotkey combination. The format is: [keycode]-[keycode]-[keycode]-[keycode]-(...) +--- A list of examples: +--- - `1` +--- - `CTRL-Q` +--- - `CTRL-SHIFT-ALT-ESCAPE` +---@alias Hotkey string + + --- No clue what this does ---@param entityId number ---@param onTime number @@ -634,8 +642,8 @@ end function HasCommandLineArg(option) end ---- Add a set of key mappings ----@param keyMapTable table +--- Add a set of key mappings. Does not overwrite existing hotkeys. +---@param keyMapTable table function IN_AddKeyMapTable(keyMapTable) end From 8b3b7d97484d40650bea897b42799e88a053554b Mon Sep 17 00:00:00 2001 From: "(Jip) Willem Wijnia" Date: Sun, 1 Dec 2024 16:22:28 +0100 Subject: [PATCH 09/10] Add default configuration --- lua/keymap/keyactions.lua | 6 ++- lua/ui/game/cinematics/Config.lua | 74 +++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 lua/ui/game/cinematics/Config.lua diff --git a/lua/keymap/keyactions.lua b/lua/keymap/keyactions.lua index 004e8510e5..0a37c815dc 100755 --- a/lua/keymap/keyactions.lua +++ b/lua/keymap/keyactions.lua @@ -1945,8 +1945,12 @@ local keyActionsMisc = { } ----@type table local keyActionsCinematics = { + ['cinematics_bind_keys'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/config.lua").ApplyDefaultKeyLayout()', + category = 'cinematics', + }, + -- CRUD-like operations ['cinematics_move_to_clear'] = { action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").Clear(true)', diff --git a/lua/ui/game/cinematics/Config.lua b/lua/ui/game/cinematics/Config.lua new file mode 100644 index 0000000000..fd0b6b7f1f --- /dev/null +++ b/lua/ui/game/cinematics/Config.lua @@ -0,0 +1,74 @@ +--******************************************************************************* +-- MIT License +-- +-- Copyright (c) 2024 (Jip) Willem Wijnia +-- +-- Permission is hereby granted, free of charge, to any person obtaining a copy +-- of this software and associated documentation files (the "Software"), to deal +-- in the Software without restriction, including without limitation the rights +-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +-- copies of the Software, and to permit persons to whom the Software is +-- furnished to do so, subject to the following conditions: +-- +-- The above copyright notice and this permission notice shall be included in all +-- copies or substantial portions of the Software. +-- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +-- SOFTWARE. +-- +--******************************************************************************* + +local function DefaultMoveToLayout() + local keyActions = import("/lua/keymap/keyactions.lua").keyActions + + return { + -- clear it out + ['CTRL-SHIFT-BACKSPACE'] = keyActions.cinematics_move_to_clear, + + -- navigate between sequences + ['Q'] = keyActions.cinematics_move_to_jump_backward, + ['W'] = keyActions.cinematics_move_to_jump_current, + ['E'] = keyActions.cinematics_move_to_jump_forward, + + -- add, insert, overwrite and remove camera orientations + ['A'] = keyActions.cinematics_move_to_add, + ['S'] = keyActions.cinematics_move_to_insert, + ['D'] = keyActions.cinematics_move_to_overwrite, + ['DELETE'] = keyActions.cinematics_move_to_remove, + + -- animation + ['Shift-Q'] = keyActions.cinematics_move_to_animate_forward, + ['Shift-W'] = keyActions.cinematics_move_to_animate_backward, + ['Shift-E'] = keyActions.cinematics_move_to_jump_and_animate_forward, + ['Shift-R'] = keyActions.cinematics_move_to_jump_and_animate_backward, + + -- store/retrieve from preference file + ['1'] = keyActions.cinematics_move_to_store_01, + ['2'] = keyActions.cinematics_move_to_store_02, + ['3'] = keyActions.cinematics_move_to_store_03, + + ['ALT-1'] = keyActions.cinematics_move_to_retrieve_01, + ['ALT-2'] = keyActions.cinematics_move_to_retrieve_02, + ['ALT-3'] = keyActions.cinematics_move_to_retrieve_03, + } +end + +function ApplyDefaultKeyLayout() + local userKeys = import("/lua/keymap/keymapper.lua").GetKeyMappings() + + -- cinematics-related keys + local moveToKeyMap = DefaultMoveToLayout() + + -- we overwrite existing user keys with our own key maps. This lasts for the entire session, + -- only restarting the game can undo this. It does not affect your preference file. + local combinedKeyMap = table.combine(userKeys, moveToKeyMap) + + -- apply the keys + IN_ClearKeyMap() + IN_AddKeyMapTable(combinedKeyMap) +end From 47763eb91fd4e1a44fca718a08aa7e37425796f3 Mon Sep 17 00:00:00 2001 From: "(Jip) Willem Wijnia" Date: Sun, 1 Dec 2024 18:58:15 +0100 Subject: [PATCH 10/10] Fix various small issues --- lua/keymap/keyactions.lua | 28 ++++++++++++++----------- lua/keymap/keydescriptions.lua | 15 +++++++------- lua/ui/game/cinematics/Config.lua | 9 +++++--- lua/ui/game/cinematics/MoveTo.lua | 34 +++++++++++++++++++++++-------- 4 files changed, 56 insertions(+), 30 deletions(-) diff --git a/lua/keymap/keyactions.lua b/lua/keymap/keyactions.lua index 0a37c815dc..9341a3e461 100755 --- a/lua/keymap/keyactions.lua +++ b/lua/keymap/keyactions.lua @@ -1960,16 +1960,20 @@ local keyActionsCinematics = { action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").Append(true)', category = 'cinematics', }, - ['cinematics_move_to_insert'] = { - action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").Insert(true)', + ['cinematics_move_to_remove'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").RemoveLast(true)', category = 'cinematics', }, - ['cinematics_move_to_overwrite'] = { - action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").Overwrite(true)', + ['cinematics_move_to_insert_at_index'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").InsertAfterIndex(true)', category = 'cinematics', }, - ['cinematics_move_to_remove'] = { - action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").Remove(true)', + ['cinematics_move_to_overwrite_at_index'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").OverwriteAtIndex(true)', + category = 'cinematics', + }, + ['cinematics_move_to_remove_at_index'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").RemoveAtIndex(true)', category = 'cinematics', }, @@ -2008,27 +2012,27 @@ local keyActionsCinematics = { -- Preference file interactions ['cinematics_move_to_store_01'] = { - action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").StoreToDisk("01")', + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").StoreToDisk("01", true)', category = 'cinematics', }, ['cinematics_move_to_store_02'] = { - action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").StoreToDisk("02")', + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").StoreToDisk("02", true)', category = 'cinematics', }, ['cinematics_move_to_store_03'] = { - action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").StoreToDisk("03")', + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").StoreToDisk("03", true)', category = 'cinematics', }, ['cinematics_move_to_retrieve_01'] = { - action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").RetrieveFromDisk("01")', + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").RetrieveFromDisk("01", true)', category = 'cinematics', }, ['cinematics_move_to_retrieve_02'] = { - action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").RetrieveFromDisk("02")', + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").RetrieveFromDisk("02", true)', category = 'cinematics', }, ['cinematics_move_to_retrieve_03'] = { - action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").RetrieveFromDisk("03")', + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").RetrieveFromDisk("03", true)', category = 'cinematics', } } diff --git a/lua/keymap/keydescriptions.lua b/lua/keymap/keydescriptions.lua index d5c56216d8..f1f489097e 100755 --- a/lua/keymap/keydescriptions.lua +++ b/lua/keymap/keydescriptions.lua @@ -561,29 +561,30 @@ keyDescriptions = { ['select_surface_bombers'] = 'Select all Bombers (Normal)', ['select_torpedo_bombers'] = 'Select all Bombers (Torpedo)', - -- CRUD-like operations + ['cinematics_bind_keys'] = 'Apply default key layout for cinematics. Applies until the game is restarted', + + --#region MoveTo ['cinematics_move_to_clear'] = 'MoveTo - Clear sequence', ['cinematics_move_to_add'] = 'MoveTo - Append current camera position to the sequence', - ['cinematics_move_to_insert'] = 'MoveTo - Insert current camera position after the current index of the sequence', - ['cinematics_move_to_overwrite'] = 'MoveTo - Overwrite with current camera position at the current index of the sequence', - ['cinematics_move_to_remove'] = 'MoveTo - Remove camera position at the current index of the sequence', + ['cinematics_move_to_remove'] = 'MoveTo - Remove the last camera position from sequence', + ['cinematics_move_to_insert_at_index'] = 'MoveTo - Insert current camera position at the current index of the sequence. Shifts the existing camera positions to the right.', + ['cinematics_move_to_overwrite_at_index'] = 'MoveTo - Overwrite with current camera position at the current index of the sequence', + ['cinematics_move_to_remove_at_index'] = 'MoveTo - Remove camera position at the current index of the sequence', - -- Navigation ['cinematics_move_to_jump_current'] = 'MoveTo - Jump to the camera position at the current index of the sequence', ['cinematics_move_to_jump_forward'] = 'MoveTo - Jump to the next camera position in the sequence', ['cinematics_move_to_jump_backward'] = 'MoveTo - Jump to the previous camera position in the sequence', - -- Animation ['cinematics_move_to_animate_forward'] = 'MoveTo - Animate to the next camera position in the sequence', ['cinematics_move_to_animate_backward'] = 'MoveTo - Animate to the previous camera position in the sequence', ['cinematics_move_to_jump_and_animate_forward'] = 'MoveTo - Jump to the next camera position, then animate to the one after', ['cinematics_move_to_jump_and_animate_backward'] = 'MoveTo - Jump to the previous camera position, then animate to the one before', - -- Preference file interactions ['cinematics_move_to_store_01'] = 'MoveTo - Save the 1st MoveTo sequence to the preference file', ['cinematics_move_to_store_02'] = 'MoveTo - Save the 2nd MoveTo sequence to the preference file', ['cinematics_move_to_store_03'] = 'MoveTo - Save the 3rd MoveTo sequence to the preference file', ['cinematics_move_to_retrieve_01'] = 'MoveTo - Load the 1st MoveTo sequence from the preference file', ['cinematics_move_to_retrieve_02'] = 'MoveTo - Load the 2nd MoveTo sequence from the preference file', ['cinematics_move_to_retrieve_03'] = 'MoveTo - Load the 3rd MoveTo sequence from the preference file', + --#endregion } diff --git a/lua/ui/game/cinematics/Config.lua b/lua/ui/game/cinematics/Config.lua index fd0b6b7f1f..7b8a3e7f63 100644 --- a/lua/ui/game/cinematics/Config.lua +++ b/lua/ui/game/cinematics/Config.lua @@ -37,9 +37,10 @@ local function DefaultMoveToLayout() -- add, insert, overwrite and remove camera orientations ['A'] = keyActions.cinematics_move_to_add, - ['S'] = keyActions.cinematics_move_to_insert, - ['D'] = keyActions.cinematics_move_to_overwrite, - ['DELETE'] = keyActions.cinematics_move_to_remove, + ['S'] = keyActions.cinematics_move_to_insert_at_index, + ['D'] = keyActions.cinematics_move_to_overwrite_at_index, + ['BACKSPACE'] = keyActions.cinematics_move_to_remove, + ['DELETE'] = keyActions.cinematics_move_to_remove_at_index, -- animation ['Shift-Q'] = keyActions.cinematics_move_to_animate_forward, @@ -71,4 +72,6 @@ function ApplyDefaultKeyLayout() -- apply the keys IN_ClearKeyMap() IN_AddKeyMapTable(combinedKeyMap) + + print("Applied hotkeys for cinematics") end diff --git a/lua/ui/game/cinematics/MoveTo.lua b/lua/ui/game/cinematics/MoveTo.lua index c401e7fdb4..4ee0995b5a 100644 --- a/lua/ui/game/cinematics/MoveTo.lua +++ b/lua/ui/game/cinematics/MoveTo.lua @@ -103,7 +103,7 @@ RetrieveFromDisk = function(key, doPrint) -- inform user if doPrint then print("MoveTo - Loaded sequence for MoveTo to key '" .. - stringifiedKey .. "' (" .. table.getn(Sequence) .. " steps)") + stringifiedKey .. "' (" .. table.getn(Sequence) .. " steps)") end end @@ -118,9 +118,9 @@ Append = function(doPrint) end end ---- Inserts a camera position at the specified index. +--- Inserts a camera position at the specified index, pushing back the other camera positions. ---@param doPrint? boolean -Insert = function(doPrint) +InsertAfterIndex = function(doPrint) local sequenceCount = table.getn(Sequence) if sequenceCount == 0 then SequenceIndex = 1 @@ -129,16 +129,16 @@ Insert = function(doPrint) end local camera = GetCamera(DefaultCamera) - table.insert(camera, SequenceIndex + 1, camera:SaveSettings()) + table.insert(Sequence, SequenceIndex, camera:SaveSettings()) if doPrint then - print("MoveTo - Insert into sequence at index " .. SequenceIndex .. " (" .. sequenceCount .. " steps)") + print("MoveTo - Insert into sequence at index " .. SequenceIndex .. " (" .. (sequenceCount + 1) .. " steps)") end end --- Overwrites the camera position at the specified index. ---@param doPrint? boolean -Overwrite = function(doPrint) +OverwriteAtIndex = function(doPrint) local sequenceCount = table.getn(Sequence) if sequenceCount == 0 then SequenceIndex = 1 @@ -158,7 +158,8 @@ end --- Removes the current camera position. ---@param doPrint? boolean -Remove = function(doPrint) +---@return nil +RemoveAtIndex = function(doPrint) local sequenceCount = table.getn(Sequence) if sequenceCount == 0 then print("No camera sequence defined") @@ -168,7 +169,24 @@ Remove = function(doPrint) table.remove(Sequence, SequenceIndex) if doPrint then - print("MoveTo - Removed sequence " .. SequenceIndex .. " (" .. sequenceCount .. " steps)") + print("MoveTo - Removed at " .. SequenceIndex .. " (" .. (sequenceCount - 1).. " steps)") + end +end + +--- Removes the last camera position. +---@param doPrint doPrint? boolean +---@return nil +RemoveLast = function(doPrint) + local sequenceCount = table.getn(Sequence) + if sequenceCount == 0 then + print("No camera sequence defined") + return nil + end + + table.remove(Sequence) + + if doPrint then + print("MoveTo - Removed last (" .. (sequenceCount - 1) .. " steps)") end end