Merge pull request #4 from danreeves/inject-mod-options
Inject Mod Options button into Esc menu
This commit is contained in:
commit
24502d9957
2 changed files with 55 additions and 4 deletions
|
@ -91,13 +91,12 @@ end
|
|||
-- ##### DMF internal functions and variables #########################################################################
|
||||
-- ####################################################################################################################
|
||||
|
||||
-- Handles the return of global localize text_ids
|
||||
dmf:hook(_G, "Localize", function (func, text_id, ...)
|
||||
dmf:hook(LocalizationManager, "localize", function (func, self, text_id, ...)
|
||||
|
||||
local text_translations = text_id and _global_localization_database[text_id]
|
||||
local message = get_translated_or_english_message(nil, text_translations, ...)
|
||||
|
||||
return message or func(text_id, ...)
|
||||
return message or func(self, text_id, ...)
|
||||
end)
|
||||
|
||||
-- ####################################################################################################################
|
||||
|
|
|
@ -350,10 +350,62 @@ local function create_option_template(self, widget_data, category_name, index_of
|
|||
end
|
||||
end
|
||||
|
||||
-- Insert a new item into a table before any items that pass the item_tester function
|
||||
local function insert_before(tbl, item_tester, new_item)
|
||||
local copy = {}
|
||||
for _, item in ipairs(tbl) do
|
||||
if item_tester(item) then
|
||||
table.insert(copy, new_item)
|
||||
end
|
||||
table.insert(copy, item)
|
||||
end
|
||||
return copy
|
||||
end
|
||||
|
||||
|
||||
-- ####################################################################################################################
|
||||
-- ##### Hooks ########################################################################################################
|
||||
-- ####################################################################################################################
|
||||
|
||||
-- Add Mods Options title to global localization table
|
||||
-- so that the SystemView options menu can localize it
|
||||
dmf:add_global_localize_strings({
|
||||
-- TODO: copied from dmf/localization/dmf.lua, figure out a better way
|
||||
mods_options = {
|
||||
en = "Mod Options",
|
||||
es = "Configuración de mods",
|
||||
ru = "Настройки модов",
|
||||
}
|
||||
})
|
||||
|
||||
local dmf_option_definition = {
|
||||
text = "mods_options",
|
||||
type = "button",
|
||||
icon = "content/ui/materials/icons/system/escape/settings",
|
||||
trigger_function = function()
|
||||
local context = {
|
||||
can_exit = true,
|
||||
}
|
||||
local view_name = "dmf_options_view"
|
||||
Managers.ui:open_view(view_name, nil, nil, nil, nil, context)
|
||||
end,
|
||||
}
|
||||
|
||||
local function is_options_button(item)
|
||||
return item.text == "loc_options_view_display_name"
|
||||
end
|
||||
|
||||
-- Inject DMF Options button into the Esc menu
|
||||
dmf:hook_require("scripts/ui/views/system_view/system_view_content_list", function(instance)
|
||||
-- Don't re-inject if it's already there
|
||||
if table.find_by_key(instance.default, "text", dmf_option_definition.text) then
|
||||
return
|
||||
end
|
||||
|
||||
instance.default = insert_before(instance.default, is_options_button, dmf_option_definition)
|
||||
instance.StateMainMenu = insert_before(instance.StateMainMenu, is_options_button, dmf_option_definition)
|
||||
end)
|
||||
|
||||
-- ####################################################################################################################
|
||||
-- ##### DMF internal functions and variables #########################################################################
|
||||
-- ####################################################################################################################
|
||||
|
|
Loading…
Add table
Reference in a new issue