diff --git a/loc/US/strings_db.lua b/loc/US/strings_db.lua index 4b94cb9dcc9..ed582981161 100644 --- a/loc/US/strings_db.lua +++ b/loc/US/strings_db.lua @@ -4464,6 +4464,8 @@ key_desc_0405="Dock" key_desc_0407="Select all Bombers (Normal)" key_desc_0408="Select all Bombers (Torpedo)" +key_desc_quick_load="Load the game from the special quick save file" + keymap_category_0000="UI" keymap_category_0004="Selection" keymap_category_0025="Camera" diff --git a/lua/keymap/alternativeKeyMap.lua b/lua/keymap/alternativeKeyMap.lua index 81987cb0c48..0227ebb817a 100644 --- a/lua/keymap/alternativeKeyMap.lua +++ b/lua/keymap/alternativeKeyMap.lua @@ -35,6 +35,7 @@ defaultKeyMap = { ['F10'] = 'toggle_main_menu', ['F11'] = 'toggle_disconnect_screen', ['F12'] = 'show_objective_screen', + ['Shift-F9'] = 'quick_load', ['1'] = 'group1', ['2'] = 'group2', diff --git a/lua/keymap/defaultKeyMap.lua b/lua/keymap/defaultKeyMap.lua index 1c991163947..aa77eebe67c 100755 --- a/lua/keymap/defaultKeyMap.lua +++ b/lua/keymap/defaultKeyMap.lua @@ -32,6 +32,7 @@ defaultKeyMap = { ['F10'] = 'toggle_main_menu', ['F11'] = 'toggle_disconnect_screen', ['F12'] = 'show_objective_screen', + ['Shift-F9'] = 'quick_load', ['1'] = 'group1', ['2'] = 'group2', ['3'] = 'group3', diff --git a/lua/keymap/hotbuildKeyMap.lua b/lua/keymap/hotbuildKeyMap.lua index 681b09e3782..88fee8a967f 100644 --- a/lua/keymap/hotbuildKeyMap.lua +++ b/lua/keymap/hotbuildKeyMap.lua @@ -36,6 +36,7 @@ defaultKeyMap = { ['F10'] = 'toggle_main_menu', ['F11'] = 'toggle_disconnect_screen', ['F12'] = 'show_objective_screen', + ['Shift-F9'] = 'quick_load', ['1'] = 'group1', ['2'] = 'group2', diff --git a/lua/keymap/keyactions.lua b/lua/keymap/keyactions.lua index 77270012582..97ba446398f 100755 --- a/lua/keymap/keyactions.lua +++ b/lua/keymap/keyactions.lua @@ -1834,6 +1834,10 @@ local keyActionsGame = { action = 'UI_Lua import("/lua/ui/game/gamemain.lua").QuickSave(LOC("QuickSave"))', category = 'ui', }, + ['quick_load'] = { + action = 'UI_Lua import("/lua/ui/game/gamemain.lua").QuickLoad(LOC("QuickSave"))', + category = 'ui', + }, ['toggle_key_bindings'] = { action = 'UI_Lua import("/lua/ui/dialogs/keybindings.lua").CreateUI()', category = 'ui', diff --git a/lua/keymap/keydescriptions.lua b/lua/keymap/keydescriptions.lua index 7ff7890c52f..e27b828bafa 100755 --- a/lua/keymap/keydescriptions.lua +++ b/lua/keymap/keydescriptions.lua @@ -219,6 +219,7 @@ keyDescriptions = { ['cam_free'] = "Toggles camera free mode", ['quick_save'] = "Save the game to a special quick save file", + ['quick_load'] = "Load the game from the special quick save file", ['mouse_help'] = "Turn the mouse button help icon on/off", ['create_build_template'] = "Create a build template based on the current selection", diff --git a/lua/ui/game/gamemain.lua b/lua/ui/game/gamemain.lua index 84bb0c26fee..6f2ff023afa 100644 --- a/lua/ui/game/gamemain.lua +++ b/lua/ui/game/gamemain.lua @@ -28,6 +28,8 @@ local ordersControl = false local OnDestroyFuncs = {} + --- game's "Non-Interactive Sequence" state as synced from Sim + ---@type 'on' | 'off' | false local NISActive = false local isReplay = false local waitingDialog = false @@ -932,6 +934,9 @@ local rangePrefs = { } local preNISSettings = {} + +--- Called by user sync to set the NIS mode state and do callbacks for the states +---@param state 'on' | 'off' function NISMode(state) NISActive = state local worldView = import("/lua/ui/game/worldview.lua") @@ -1032,6 +1037,8 @@ function ShowNISBars() end end +--- Returns true if the game is in a "Non-Interactive Sequence" +---@return boolean function IsNISMode() if NISActive == 'on' then return true @@ -1117,6 +1124,55 @@ function QuickSave(filename) end end +--- Called by key action to load a special quick save file. +---@param filename string +function QuickLoad(filename) + if not SessionIsActive() + or not SessionIsMultiplayer() + then + --#region Duplicate code from QuickSave + local saveType + if import("/lua/ui/campaign/campaignmanager.lua").campaignMode then + saveType = "CampaignSave" + else + saveType = "SaveGame" + end + local path = GetSpecialFilePath(Prefs.GetCurrentProfile().Name, filename, saveType) + --#endregion + + local statusStr = "Loading Quick Save..." + local status = UIUtil.ShowInfoDialog(GetFrame(0), statusStr) + + --#region Duplicate of `/lua/ui/dialogs/saveload.lua` `CreateLoadDialog` `DoLoad` + SetFrontEndData('NextOpBriefing', nil) + local SaveErrors = { + WrongVersion = 'Wrong version for savegame "%s"', + CantOpen = 'Couldn\'t open savegame "%s"', + InvalidFormat = '"%s" is not a valid savegame', + InternalError = 'Internal error loading savegame "%s": %s', + } + local InternalErrors = { + ['eof'] = "EOF reached during serialization.", + ['noread'] = "Error reading file stream during serialization.", + ['nowrite'] = "Error writing data during serialization. Possibly out of disk space.", + } + + local worked, error, detail = LoadSavedGame(path) + if not worked then + UIUtil.ShowInfoDialog(GetFrame(0), + -- note - the 'Unknown error...' string below is intentionally not localized because + -- it should never show up. If it does, add the error string to SaveErrors. + LOCF(SaveErrors[error] or ('Unknown error ' .. repr(error) .. 'loading savegame %s: %s'), + Basename(path, true), + InternalErrors[detail] or detail), + "") + end + --#endregion + + status:Destroy() + end +end + defaultZoom = 1.4 function SimChangeCameraZoom(newMult) if SessionIsActive() and