[Mod Options] Move options view to separate file
This commit is contained in:
parent
2decd8d2e0
commit
e940f59fd3
4 changed files with 130 additions and 134 deletions
126
vmf/scripts/mods/vmf/modules/ui/options/mod_options.lua
Normal file
126
vmf/scripts/mods/vmf/modules/ui/options/mod_options.lua
Normal file
|
@ -0,0 +1,126 @@
|
|||
local vmf = get_mod("VMF")
|
||||
|
||||
local _button_injection_data = vmf:persistent_table("button_injection_data")
|
||||
|
||||
|
||||
if VT1 then
|
||||
|
||||
|
||||
-- Disable Mod Options button during mods reloading
|
||||
vmf:hook_safe(IngameView, "update_menu_options", function (self)
|
||||
for _, button_info in ipairs(self.active_button_data) do
|
||||
if button_info.transition == "vmf_options_view" then
|
||||
button_info.widget.content.disabled = _button_injection_data.mod_options_button_disabled
|
||||
button_info.widget.content.button_hotspot.disabled = _button_injection_data.mod_options_button_disabled
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
-- Inject Mod Options button in current ESC-menu layout
|
||||
-- Disable localization for button widget
|
||||
vmf:hook(IngameView, "setup_button_layout", function (func, self, layout_data, ...)
|
||||
local mods_options_button = {
|
||||
display_name = vmf:localize("mods_options"),
|
||||
transition = "vmf_options_view",
|
||||
fade = false
|
||||
}
|
||||
for i = 1, #layout_data do
|
||||
if layout_data[i].transition == "options_menu" and layout_data[i + 1].transition ~= "vmf_options_view" then
|
||||
table.insert(layout_data, i + 1, mods_options_button)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
func(self, layout_data, ...)
|
||||
|
||||
for _, button_info in ipairs(self.active_button_data) do
|
||||
if button_info.transition == "vmf_options_view" then
|
||||
button_info.widget.style.text.localize = false
|
||||
button_info.widget.style.text_disabled.localize = false
|
||||
button_info.widget.style.text_click.localize = false
|
||||
button_info.widget.style.text_hover.localize = false
|
||||
button_info.widget.style.text_selected.localize = false
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
else
|
||||
|
||||
|
||||
local function get_mod_options_button_index(layout_logic)
|
||||
for button_index, button_data in ipairs(layout_logic.active_button_data) do
|
||||
if button_data.transition == "vmf_options_view" then
|
||||
return button_index
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Disable localization for Mod Options button widget for pc version of ESC-menu
|
||||
-- Widget definition: ingame_view_definitions.lua -> UIWidgets.create_default_button
|
||||
vmf:hook_safe(IngameView, "on_enter", function (self)
|
||||
self.layout_logic._ingame_view = self
|
||||
end)
|
||||
vmf:hook_safe(IngameViewLayoutLogic, "setup_button_layout", function (self)
|
||||
if self._ingame_view then
|
||||
local mod_options_button_index = get_mod_options_button_index(self)
|
||||
local button_widget = self._ingame_view.stored_buttons[mod_options_button_index]
|
||||
button_widget.style.title_text.localize = false
|
||||
button_widget.style.title_text_shadow.localize = false
|
||||
button_widget.style.title_text_disabled.localize = false
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
-- Disable localization for Mod Options button widget for console version of ESC-menu
|
||||
-- Widget definition: hero_window_ingame_view_definitions.lua -> create_title_button
|
||||
vmf:hook_safe(HeroWindowIngameView, "on_enter", function (self)
|
||||
local button_widget = self._title_button_widgets[get_mod_options_button_index(self.layout_logic)]
|
||||
button_widget.style.text.localize = false
|
||||
button_widget.style.text_hover.localize = false
|
||||
button_widget.style.text_shadow.localize = false
|
||||
button_widget.style.text_disabled.localize = false
|
||||
end)
|
||||
|
||||
|
||||
-- Disable Mod Options button during mods reloading
|
||||
vmf:hook_safe(IngameViewLayoutLogic, "_update_menu_options_enabled_states", function (self)
|
||||
local mod_options_button_index = get_mod_options_button_index(self)
|
||||
local mod_options_button_data = self.active_button_data[mod_options_button_index]
|
||||
mod_options_button_data.disabled = _button_injection_data.mod_options_button_disabled
|
||||
end)
|
||||
|
||||
|
||||
-- Inject Mod Options button in all possible ESC-menu layouts (except for developer's one, because it will increase
|
||||
-- the number of buttons to 10, when the hard limit is 9, which will crash the game)
|
||||
vmf:hook_safe(IngameViewLayoutLogic, "init", function (self)
|
||||
local mod_options_button = {
|
||||
display_name = vmf:localize("mods_options"),
|
||||
transition = "vmf_options_view",
|
||||
fade = false
|
||||
}
|
||||
for _, layout in pairs(self.layout_list) do
|
||||
for i = 1, #layout do
|
||||
if layout[i].transition == "options_menu" and layout[i + 1].transition ~= "vmf_options_view" then
|
||||
table.insert(layout, i + 1, mod_options_button)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
vmf.initialize_vmf_options_view = function ()
|
||||
vmf:register_view("scripts/mods/vmf/modules/ui/options/vmf_options_view")
|
||||
_button_injection_data.mod_options_button_disabled = false
|
||||
end
|
||||
|
||||
|
||||
vmf.disable_mods_options_button = function ()
|
||||
_button_injection_data.mod_options_button_disabled = true
|
||||
end
|
|
@ -4276,7 +4276,7 @@ vmf.load_vmf_options_view_settings()
|
|||
|
||||
|
||||
|
||||
local view_data = {
|
||||
return {
|
||||
view_name = "vmf_options_view",
|
||||
view_settings = {
|
||||
init_view_function = function (ingame_ui_context)
|
||||
|
@ -4286,10 +4286,6 @@ local view_data = {
|
|||
inn = true,
|
||||
ingame = true
|
||||
},
|
||||
blocked_transitions = {
|
||||
inn = {},
|
||||
ingame = {}
|
||||
},
|
||||
keybind_transitions = {
|
||||
open_view_transition = "vmf_options_view",
|
||||
close_view_transition = "exit_menu",
|
||||
|
@ -4301,130 +4297,4 @@ local view_data = {
|
|||
self.menu_active = true
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
local _button_injection_data = vmf:persistent_table("button_injection_data")
|
||||
|
||||
|
||||
if VT1 then
|
||||
|
||||
|
||||
-- Disable Mod Options button during mods reloading
|
||||
vmf:hook_safe(IngameView, "update_menu_options", function (self)
|
||||
for _, button_info in ipairs(self.active_button_data) do
|
||||
if button_info.transition == "vmf_options_view" then
|
||||
button_info.widget.content.disabled = _button_injection_data.mod_options_button_disabled
|
||||
button_info.widget.content.button_hotspot.disabled = _button_injection_data.mod_options_button_disabled
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
-- Inject Mod Options button in current ESC-menu layout
|
||||
-- Disable localization for button widget
|
||||
vmf:hook(IngameView, "setup_button_layout", function (func, self, layout_data, ...)
|
||||
local mods_options_button = {
|
||||
display_name = vmf:localize("mods_options"),
|
||||
transition = "vmf_options_view",
|
||||
fade = false
|
||||
}
|
||||
for i = 1, #layout_data do
|
||||
if layout_data[i].transition == "options_menu" and layout_data[i + 1].transition ~= "vmf_options_view" then
|
||||
table.insert(layout_data, i + 1, mods_options_button)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
func(self, layout_data, ...)
|
||||
|
||||
for _, button_info in ipairs(self.active_button_data) do
|
||||
if button_info.transition == "vmf_options_view" then
|
||||
button_info.widget.style.text.localize = false
|
||||
button_info.widget.style.text_disabled.localize = false
|
||||
button_info.widget.style.text_click.localize = false
|
||||
button_info.widget.style.text_hover.localize = false
|
||||
button_info.widget.style.text_selected.localize = false
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
else
|
||||
|
||||
|
||||
local function get_mod_options_button_index(layout_logic)
|
||||
for button_index, button_data in ipairs(layout_logic.active_button_data) do
|
||||
if button_data.transition == "vmf_options_view" then
|
||||
return button_index
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Disable localization for Mod Options button widget for pc version of ESC-menu
|
||||
-- Widget definition: ingame_view_definitions.lua -> UIWidgets.create_default_button
|
||||
vmf:hook_safe(IngameView, "on_enter", function (self)
|
||||
self.layout_logic._ingame_view = self
|
||||
end)
|
||||
vmf:hook_safe(IngameViewLayoutLogic, "setup_button_layout", function (self)
|
||||
if self._ingame_view then
|
||||
local mod_options_button_index = get_mod_options_button_index(self)
|
||||
local button_widget = self._ingame_view.stored_buttons[mod_options_button_index]
|
||||
button_widget.style.title_text.localize = false
|
||||
button_widget.style.title_text_shadow.localize = false
|
||||
button_widget.style.title_text_disabled.localize = false
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
-- Disable localization for Mod Options button widget for console version of ESC-menu
|
||||
-- Widget definition: hero_window_ingame_view_definitions.lua -> create_title_button
|
||||
vmf:hook_safe(HeroWindowIngameView, "on_enter", function (self)
|
||||
local button_widget = self._title_button_widgets[get_mod_options_button_index(self.layout_logic)]
|
||||
button_widget.style.text.localize = false
|
||||
button_widget.style.text_hover.localize = false
|
||||
button_widget.style.text_shadow.localize = false
|
||||
button_widget.style.text_disabled.localize = false
|
||||
end)
|
||||
|
||||
|
||||
-- Disable Mod Options button during mods reloading
|
||||
vmf:hook_safe(IngameViewLayoutLogic, "_update_menu_options_enabled_states", function (self)
|
||||
local mod_options_button_index = get_mod_options_button_index(self)
|
||||
local mod_options_button_data = self.active_button_data[mod_options_button_index]
|
||||
mod_options_button_data.disabled = _button_injection_data.mod_options_button_disabled
|
||||
end)
|
||||
|
||||
|
||||
-- Inject Mod Options button in all possible ESC-menu layouts (except for developer's one, because it will increase
|
||||
-- the number of buttons to 10, when the hard limit is 9, which will crash the game)
|
||||
vmf:hook_safe(IngameViewLayoutLogic, "init", function (self)
|
||||
local mod_options_button = {
|
||||
display_name = vmf:localize("mods_options"),
|
||||
transition = "vmf_options_view",
|
||||
fade = false
|
||||
}
|
||||
for _, layout in pairs(self.layout_list) do
|
||||
for i = 1, #layout do
|
||||
if layout[i].transition == "options_menu" and layout[i + 1].transition ~= "vmf_options_view" then
|
||||
table.insert(layout, i + 1, mod_options_button)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
vmf.initialize_vmf_options_view = function ()
|
||||
vmf:register_view(view_data)
|
||||
_button_injection_data.mod_options_button_disabled = false
|
||||
end
|
||||
|
||||
|
||||
vmf.disable_mods_options_button = function ()
|
||||
_button_injection_data.mod_options_button_disabled = true
|
||||
end
|
||||
}
|
|
@ -240,7 +240,7 @@ if not vmf:get("vmf_initialized") then
|
|||
vmf.load_dev_console_settings()
|
||||
vmf.load_chat_history_settings()
|
||||
vmf.load_ui_scaling_settings()
|
||||
vmf.load_vmf_options_view_settings()
|
||||
--vmf.load_vmf_options_view_settings()
|
||||
|
||||
vmf:set("vmf_initialized", true)
|
||||
end
|
|
@ -34,7 +34,7 @@ function vmf_mod_object:init()
|
|||
dofile("scripts/mods/vmf/modules/gui/custom_views")
|
||||
dofile("scripts/mods/vmf/modules/gui/ui_scaling")
|
||||
dofile("scripts/mods/vmf/modules/ui/chat/chat_actions")
|
||||
dofile("scripts/mods/vmf/modules/ui/options/vmf_options_view")
|
||||
dofile("scripts/mods/vmf/modules/ui/options/mod_options")
|
||||
dofile("scripts/mods/vmf/modules/vmf_options")
|
||||
|
||||
if VT1 then
|
||||
|
|
Loading…
Add table
Reference in a new issue