Divergent/mods/DynaHUD/gamedata/scripts/zzz_dynahud_hud.script

156 lines
5.6 KiB
Plaintext

-- hud_style
-- INHERIT | -4 Aydin | -3 BHS | -2 EFP | -1 GAMMA | ======= | MAIN | 0 S2 | 1 minimalistic | 2 minimalistic no ammo counter
-- S2
HUD = dynahud_hud_binder.HUD
local restore_firemodecheck_hidegui = nil
local restore_firemodecheck_displaymode = nil
local restore_ammocheck_hidecounter = nil
local restore_ammocheck_hideicon = nil
local restore_hud_configurator_background = nil
local restore_hud_configurator_fire_mode = nil
local restore_hud_configurator_health_bar = nil
local restore_hud_configurator_psy_bar = nil
local restore_hud_configurator_stamina_bar = nil
local function toboolean(str)
if str == "true" then
return true
elseif str == "false" then
return false
else return str end
end
local function configure_setting(setting_key)
local pref_setting_value = ui_mcm.get("dynahud/hud_init_pref/".. (dynahud_hud_binder.HUD.style) .. "/" .. setting_key)
if pref_setting_value ~= nil then
printf("[dynahud_hud] setting %s to %s (init_pref)",setting_key, pref_setting_value)
ui_mcm.set(setting_key, toboolean(pref_setting_value))
else
printf("[dynahud_hud] setting %s to %s",setting_key, HUD.mcm_config[setting_key])
ui_mcm.set(setting_key, HUD.mcm_config[setting_key])
end
end
local function restore_setting(setting_key, value)
printf("[dynahud_hud] restoring %s to %s",setting_key, value)
ui_mcm.set(setting_key, value)
end
function init_ui_components(HUD)
printf("[dynahud_hud] initializing ammo counter (%s)", HUD.ui_config["ui/show_ammo_counter_hud"])
local pref_setting_value = ui_mcm.get("dynahud/hud_init_pref/ui/show_ammo_counter_hud")
if pref_setting_value ~= nil then
zzzz_dynahud.ui_show_cur_ammo(toboolean(pref_setting_value))
else
zzzz_dynahud.ui_show_cur_ammo(HUD.ui_config["ui/show_ammo_counter_hud"])
end
printf("[dynahud_hud] initializing ammo icon hud (%s)", HUD.ui_config["ui/show_ammo_icon_hud"])
pref_setting_value = ui_mcm.get("dynahud/hud_init_pref/ui/show_ammo_icon_hud")
if pref_setting_value ~= nil then
zzzz_dynahud.ui_show_weapon_icon(toboolean(pref_setting_value))
else
zzzz_dynahud.ui_show_weapon_icon(HUD.ui_config["ui/show_ammo_icon_hud"])
end
end
function init_hud_style()
printf("[dynahud_hud] initializing the hud style %s", HUD.style)
init_ui_components(HUD)
if ish_firemode then
restore_firemodecheck_hidegui = ui_mcm.get("fireModeCheck/hideGui")
restore_firemodecheck_displaymode = ui_mcm.get("fireModeCheck/displayMode")
end
if ammo_check_mcm then
restore_ammocheck_hidecounter = ui_mcm.get("rax_ammo_check/hidecounter")
restore_ammocheck_hideicon = ui_mcm.get("rax_ammo_check/hideicon")
end
if ish_firemode then
printf("[dynahud_hud] ish_firemode detected, configuring mcm")
configure_setting("fireModeCheck/hideGui")
configure_setting("fireModeCheck/displayMode")
ish_firemode.on_option_change()
end
if ammo_check_mcm and ammo_check_mcm.on_option_change then
printf("[dynahud_hud] ammocheck detected, configuring mcm")
configure_setting("rax_ammo_check/hidecounter")
configure_setting("rax_ammo_check/hideicon")
ammo_check_mcm.on_option_change()
end
-- 0 no patch | 1 BHS | 2 BHS_GAMMA - | 3 BHS_EFP
local patch_type = dynahud_patch_binder.patch_type
if patch_type == 3 then
printf("[dynahud_hud] initializing hud according to patch type %s", patch_type)
if hud_configurator_mcm then
printf("[dynahud_hud] hud_configurator_mcm detected, configuring mcm")
restore_hud_configurator_background = ui_mcm.get("hud_configurator/background")
restore_hud_configurator_fire_mode = ui_mcm.get("hud_configurator/fire_mode")
restore_hud_configurator_health_bar = ui_mcm.get("hud_configurator/health_bar")
restore_hud_configurator_psy_bar = ui_mcm.get("hud_configurator/psy_bar")
restore_hud_configurator_stamina_bar = ui_mcm.get("hud_configurator/background")
configure_setting("hud_configurator/background")
configure_setting("hud_configurator/fire_mode")
configure_setting("hud_configurator/health_bar")
configure_setting("hud_configurator/psy_bar")
configure_setting("hud_configurator/stamina_bar")
hud_configurator_mcm.on_option_change()
end
end
end
local function restore_mcm_settings()
printf("[dynahud_hud] restore mcm settings")
if ish_firemode then
restore_setting("fireModeCheck/displayMode", restore_firemodecheck_displaymode)
restore_setting("fireModeCheck/hideGui", restore_firemodecheck_hidegui)
end
if ammo_check_mcm then
restore_setting("rax_ammo_check/hidecounter", restore_ammocheck_hidecounter)
restore_setting("rax_ammo_check/hideicon", restore_ammocheck_hideicon)
end
-- 0 no patch | 1 BHS | 2 BHS_GAMMA - | 3 BHS_EFP
local patch_type = dynahud_patch_binder.patch_type
if patch_type == 3 then
if hud_configurator_mcm then
restore_setting("hud_configurator/background", restore_hud_configurator_background)
restore_setting("hud_configurator/fire_mode", restore_hud_configurator_fire_mode)
restore_setting("hud_configurator/health_bar", restore_hud_configurator_health_bar)
restore_setting("hud_configurator/psy_bar", restore_hud_configurator_psy_bar)
restore_setting("hud_configurator/stamina_bar", restore_hud_configurator_stamina_bar)
end
end
end
function destroy_init_style()
restore_mcm_settings()
end
function on_game_start()
end