-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Mokuppo/persistent_hud
Persistent hud
- Loading branch information
Showing
3 changed files
with
1,138 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.