[Mod Options] Add current VT2 compatibility

It's gonna be removed once VT2 1.2 is out.
This commit is contained in:
Azumgi 2018-08-22 17:22:24 +03:00
parent 945c699beb
commit bfd467e0a2

View file

@ -4527,6 +4527,104 @@ local view_data = {
}
-- THIS BLOCK WILL BE DELETED AFTER VT2 1.2 IS OUT. IT'S HERE FOR TEMPORARY COMPATIBILITY
if not VT1 and (tonumber(script_data.settings.content_revision) <= 120239) then
if not VT1 and not IngameView.umoes_is_hooked then
local umoes_original_function = IngameView.update_menu_options_enabled_states
IngameView.update_menu_options_enabled_states = function(self)
umoes_original_function(self)
if self.active_button_data then
for _, menu_option in ipairs(self.active_button_data) do
if menu_option.transition == "vmf_options_view" then
menu_option.widget.content.button_hotspot.disable_button = menu_option.widget.content.button_hotspot.disabled
end
end
end
end
IngameView.umoes_is_hooked = true
end
-- disables/enables mods options buttons in the
local function change_mods_options_button_state(state)
local ingame_menu_buttons_exist, ingame_menu_buttons
if VT1 then
ingame_menu_buttons_exist, ingame_menu_buttons = pcall(function () return Managers.player.network_manager.matchmaking_manager.matchmaking_ui.ingame_ui.ingame_menu.active_button_data end)
else
ingame_menu_buttons_exist, ingame_menu_buttons = pcall(function () return Managers.player.network_manager.matchmaking_manager._ingame_ui.views.ingame_menu.active_button_data end)
end
if ingame_menu_buttons_exist and type(ingame_menu_buttons) == "table" then
for _, button_info in ipairs(ingame_menu_buttons) do
if button_info.transition == "vmf_options_view" then
-- it's enough to enable/disable buttons in V1, but it doesn't do anything in V2
-- there is special hook for V2 that updates button state every tick
-- and it uses this value to figure out if button is enabled
button_info.widget.content.disabled = (state == "disable")
button_info.widget.content.button_hotspot.disabled = (state == "disable")
end
end
end
end
vmf.initialize_vmf_options_view = function ()
vmf:register_new_view(view_data)
change_mods_options_button_state("enable")
end
vmf.disable_mods_options_button = function ()
change_mods_options_button_state("disable")
end
-- create mods options menu button in Esc-menu
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
if VT1 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
else
button_info.widget.style.title_text.localize = false
button_info.widget.style.title_text_disabled.localize = false
button_info.widget.style.title_text_shadow.localize = false
end
if not self.ingame_ui.views["vmf_options_view"] then
change_mods_options_button_state("disable")
end
end
end
end)
return
end
local _button_injection_data = vmf:persistent_table("button_injection_data")