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 ef83854aaf..d3d2eb41fe 100644 --- a/engine/User.lua +++ b/engine/User.lua @@ -124,6 +124,13 @@ --- | '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 + --- Repeatedly the selection box of the unit to the hovered-over state to create a blinking effect ---@param entityId EntityId ---@param onTime number @@ -351,7 +358,7 @@ end --- ---@param name string ----@return Camera +---@return UserCamera function GetCamera(name) end @@ -634,8 +641,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 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 0ee6ed10cc..c4ae16094a 100644 --- a/engine/User/CameraImpl.lua +++ b/engine/User/CameraImpl.lua @@ -1,6 +1,6 @@ ---@meta ----@class Camera +---@class UserCamera local CameraImpl = {} @@ -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() @@ -109,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 4a4d52d8f1..9341a3e461 100755 --- a/lua/keymap/keyactions.lua +++ b/lua/keymap/keyactions.lua @@ -1945,6 +1945,98 @@ local keyActionsMisc = { } +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)', + category = 'cinematics', + }, + ['cinematics_move_to_add'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").Append(true)', + category = 'cinematics', + }, + ['cinematics_move_to_remove'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").RemoveLast(true)', + category = 'cinematics', + }, + ['cinematics_move_to_insert_at_index'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").InsertAfterIndex(true)', + category = 'cinematics', + }, + ['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', + }, + + -- 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", true)', + category = 'cinematics', + }, + ['cinematics_move_to_store_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", true)', + category = 'cinematics', + }, + ['cinematics_move_to_retrieve_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", true)', + category = 'cinematics', + }, + ['cinematics_move_to_retrieve_03'] = { + action = 'UI_Lua import("/lua/ui/game/cinematics/moveto.lua").RetrieveFromDisk("03", true)', + category = 'cinematics', + } +} + ---@type table keyActions = table.combine( keyActionsCamera, @@ -1962,5 +2054,6 @@ keyActions = table.combine( keyActionsGame, keyActionsChat, keyActionsUI, + keyActionsCinematics, keyActionsMisc ) 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' } diff --git a/lua/keymap/keydescriptions.lua b/lua/keymap/keydescriptions.lua index 0038d15413..f1f489097e 100755 --- a/lua/keymap/keydescriptions.lua +++ b/lua/keymap/keydescriptions.lua @@ -560,4 +560,31 @@ keyDescriptions = { ['select_surface_bombers'] = 'Select all Bombers (Normal)', ['select_torpedo_bombers'] = 'Select all Bombers (Torpedo)', + + ['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_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', + + ['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', + + ['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', + + ['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 new file mode 100644 index 0000000000..7b8a3e7f63 --- /dev/null +++ b/lua/ui/game/cinematics/Config.lua @@ -0,0 +1,77 @@ +--******************************************************************************* +-- 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_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, + ['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) + + print("Applied hotkeys for cinematics") +end diff --git a/lua/ui/game/cinematics/MoveTo.lua b/lua/ui/game/cinematics/MoveTo.lua new file mode 100644 index 0000000000..4ee0995b5a --- /dev/null +++ b/lua/ui/game/cinematics/MoveTo.lua @@ -0,0 +1,356 @@ +--******************************************************************************* +-- 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 number +SequenceIndex = 1 + +---@type UserCameraSettings[] +Sequence = {} + +--- Moves the given camera to the specified settings. +---@param camera UserCamera +---@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 + +--- 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 +local WrapSequenceIndex = function(index, count) + return math.mod(index - 1 + count, count) + 1 +end + +--- Clears the sequence. +---@param doPrint? boolean +Clear = function(doPrint) + SequenceIndex = 1 + Sequence = {} + + if doPrint then + print("MoveTo - reset sequence") + end +end + +--- Stores the current sequence to the preference file. +---@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) + SavePreferences() + + if doPrint then + print("MoveTo - Saved sequence for MoveTo to key '" .. stringifiedKey .. "'") + end +end + +--- Retrieves a sequence from the preference file. +---@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 + if doPrint then + print("MoveTo - No sequence found for key '" .. stringifiedKey .. "'") + end + end + + Sequence = sequence + SequenceIndex = 1 + + -- inform user + if doPrint then + print("MoveTo - Loaded sequence for MoveTo to key '" .. + stringifiedKey .. "' (" .. table.getn(Sequence) .. " steps)") + end +end + +--- 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()) + + if doPrint then + print("MoveTo - Add to sequence (" .. table.getn(Sequence) .. " steps)") + end +end + +--- Inserts a camera position at the specified index, pushing back the other camera positions. +---@param doPrint? boolean +InsertAfterIndex = 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(Sequence, SequenceIndex, camera:SaveSettings()) + + if doPrint then + print("MoveTo - Insert into sequence at index " .. SequenceIndex .. " (" .. (sequenceCount + 1) .. " steps)") + end +end + +--- Overwrites the camera position at the specified index. +---@param doPrint? boolean +OverwriteAtIndex = function(doPrint) + local sequenceCount = table.getn(Sequence) + if sequenceCount == 0 then + SequenceIndex = 1 + else + SequenceIndex = WrapSequenceIndex(SequenceIndex, sequenceCount) + end + + local camera = GetCamera(DefaultCamera) + if Sequence[SequenceIndex] then + Sequence[SequenceIndex] = camera:SaveSettings() + + if doPrint then + print("MoveTo - Overwritten into sequence at index " .. SequenceIndex .. " (" .. sequenceCount .. " steps)") + end + end +end + +--- Removes the current camera position. +---@param doPrint? boolean +---@return nil +RemoveAtIndex = function(doPrint) + local sequenceCount = table.getn(Sequence) + if sequenceCount == 0 then + print("No camera sequence defined") + return nil + end + + table.remove(Sequence, SequenceIndex) + + if doPrint then + 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 + +--- 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 sequenceCount = table.getn(Sequence) + if sequenceCount == 0 then + print("No camera sequence defined") + return nil + end + + -- update sequence index + SequenceIndex = WrapSequenceIndex(SequenceIndex, sequenceCount) + + local state = Sequence[SequenceIndex] + local camera = GetCamera(DefaultCamera) + SnapTo(camera, state) + + if doPrint then + 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? +JumpForward = function(doPrint) + doPrint = doPrint or false + + local sequenceCount = table.getn(Sequence) + if sequenceCount == 0 then + print("MoveTo - No camera sequence defined") + return nil + end + + -- update sequence index + SequenceIndex = WrapSequenceIndex(SequenceIndex + 1, sequenceCount) + + local state = Sequence[SequenceIndex] + local camera = GetCamera(DefaultCamera) + SnapTo(camera, state) + + if doPrint then + print("MoveTo - jumped to (" .. SequenceIndex .. "/" .. sequenceCount .. ")") + end + + return camera +end + +--- Immediately jump to the previous position in the sequence. +---@param doPrint? boolean +---@return UserCamera? +JumpBackward = function(doPrint) + doPrint = doPrint or false + + local sequenceCount = table.getn(Sequence) + if sequenceCount == 0 then + print("MoveTo - No camera sequence defined") + return nil + end + + -- update sequence index + SequenceIndex = WrapSequenceIndex(SequenceIndex - 1, sequenceCount) + + local state = Sequence[SequenceIndex] + local camera = GetCamera(DefaultCamera) + SnapTo(camera, state) + + if doPrint then + print("MoveTo - jumped to (" .. SequenceIndex .. "/" .. sequenceCount .. ")") + end + + return camera +end + +--- Animate the camera to the next position. +---@see `ToPreviousState` +---@param doPrint? boolean +---@return UserCamera? # Allows you to wait for the camera to finish +AnimateForward = function(doPrint) + local sequenceCount = table.getn(Sequence) + if sequenceCount == 0 then + print("MoveTo - No camera sequence defined") + return nil + end + + -- update sequence index + SequenceIndex = WrapSequenceIndex(SequenceIndex + 1, sequenceCount) + + local state = Sequence[SequenceIndex] + local camera = GetCamera(DefaultCamera) + MoveTo(camera, state) + + 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 +AnimateBackwards = function(doPrint) + local sequenceCount = table.getn(Sequence) + if sequenceCount == 0 then + print("MoveTo - No camera sequence defined") + return nil + end + + -- update sequence index + SequenceIndex = WrapSequenceIndex(SequenceIndex - 1, sequenceCount) + + local state = Sequence[SequenceIndex] + local camera = GetCamera(DefaultCamera) + MoveTo(camera, state) + + 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(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(doPrint) + return JumpBackward(doPrint) and AnimateBackwards(doPrint) +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() + -- do nothing +end + +--#endregion 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