Skip to content

Commit

Permalink
Merge pull request #1 from Mokuppo/persistent_hud
Browse files Browse the repository at this point in the history
Persistent hud
  • Loading branch information
shmerl authored Dec 31, 2023
2 parents 5e394b8 + 8059d76 commit 2977f66
Show file tree
Hide file tree
Showing 3 changed files with 1,138 additions and 9 deletions.
57 changes: 49 additions & 8 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,51 @@
local GameSettings = require('GameSettings')
local GameSettings = require('modules/GameSettings')
local GameSession = require('modules/GameSession')

registerHotkey('ToggleHUD', 'Toggle HUD', function()
GameSettings.ToggleGroup('/interface/hud')

end)
local ToggleHud = {
hud_group_path = '/interface/hud',
crosshair_path = '/interface/hud/crosshairs',
hud_hidden = false,
hud_settings = {}
}

registerHotkey('ToggleCrosshair', 'Toggle Crosshair', function()
GameSettings.Toggle('/interface/hud/crosshairs')
end)
function ToggleHud:hideHud()
local hud_group = Game.GetSettingsSystem():GetGroup(self.hud_group_path)

-- save HUD settings
self.hud_settings = GameSettings.ExportVars(nil, hud_group)
-- hide HUD
GameSettings.SetGroupBool(self.hud_group_path, false)
end

function ToggleHud:restoreHud()
GameSettings.ImportVars(self.hud_settings)
end

function ToggleHud:new()
registerForEvent('onInit', function()
-- restore hud on exit in case it was hidden
GameSession.OnEnd(function()
if self.hud_hidden then
self:restoreHud()
end
end)
end)

registerHotkey('ToggleHUD', 'Toggle HUD', function()
if not self.hud_hidden then
self:hideHud()
else
self:restoreHud()
end

self.hud_hidden = not self.hud_hidden
end)

registerHotkey('ToggleCrosshair', 'Toggle Crosshair', function()
GameSettings.Toggle(self.crosshair_path)
end)

return self
end

return ToggleHud:new()
Loading

0 comments on commit 2977f66

Please sign in to comment.