All mod toggles in separate category (#16)
* mod toggle category * mods with no config appear in Toggle Mod list ---------
This commit is contained in:
parent
3b387c294d
commit
9633b29fed
3 changed files with 107 additions and 58 deletions
|
@ -32,13 +32,11 @@ return {
|
||||||
percent = {
|
percent = {
|
||||||
en = "%%",
|
en = "%%",
|
||||||
},
|
},
|
||||||
toggle_mod = {
|
toggle_mods = {
|
||||||
en = "Toggle Mod",
|
en = "Toggle Mods",
|
||||||
["zh-cn"] = "开关模组",
|
|
||||||
},
|
},
|
||||||
toggle_mod_description = {
|
toggle_mods_description = {
|
||||||
en = "Enable or disable the mod",
|
en = "Enable or disable your mods.",
|
||||||
["zh-cn"] = "启用或禁用模组",
|
|
||||||
},
|
},
|
||||||
ui_scaling = {
|
ui_scaling = {
|
||||||
en = "UI Scaling for FHD+ Resolutions",
|
en = "UI Scaling for FHD+ Resolutions",
|
||||||
|
|
|
@ -169,7 +169,7 @@ function dmf.initialize_mod_data(mod, mod_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Mod's options initialization
|
-- Mod's options initialization
|
||||||
if mod_data.options or ((mod_data.is_togglable and not mod_data.is_mutator) and not mod_data.options_widgets) then
|
if mod_data.options or (not mod_data.is_mutator and not mod_data.options_widgets) then
|
||||||
local success, error_message = pcall(dmf.initialize_mod_options, mod, mod_data.options)
|
local success, error_message = pcall(dmf.initialize_mod_options, mod, mod_data.options)
|
||||||
if not success then
|
if not success then
|
||||||
mod:error(ERRORS.REGULAR.mod_options_initializing_failed, error_message)
|
mod:error(ERRORS.REGULAR.mod_options_initializing_failed, error_message)
|
||||||
|
|
|
@ -185,9 +185,10 @@ local create_mod_toggle_template = function (self, params)
|
||||||
after = params.after,
|
after = params.after,
|
||||||
category = params.category,
|
category = params.category,
|
||||||
default_value = true,
|
default_value = true,
|
||||||
display_name = dmf:localize("toggle_mod"),
|
display_name = params.readable_mod_name or params.mod_name,
|
||||||
|
disabled = params.disabled,
|
||||||
indentation_level = 0,
|
indentation_level = 0,
|
||||||
tooltip_text = dmf:localize("toggle_mod_description"),
|
tooltip_text = params.description,
|
||||||
value_type = "boolean",
|
value_type = "boolean",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,6 +349,18 @@ local function widget_data_to_template(self, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Add a category for toggling mods
|
||||||
|
local function create_toggle_category(self, categories)
|
||||||
|
local category = {
|
||||||
|
can_be_reset = false,
|
||||||
|
display_name = dmf:localize("toggle_mods"),
|
||||||
|
custom = true
|
||||||
|
}
|
||||||
|
categories[#categories + 1] = category
|
||||||
|
return category
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Add a mod category to the options view categories
|
-- Add a mod category to the options view categories
|
||||||
local function create_mod_category(self, categories, widget_data)
|
local function create_mod_category(self, categories, widget_data)
|
||||||
local category = {
|
local category = {
|
||||||
|
@ -438,8 +451,61 @@ dmf.create_mod_options_settings = function (self, options_templates)
|
||||||
local categories = options_templates.categories
|
local categories = options_templates.categories
|
||||||
local settings = options_templates.settings
|
local settings = options_templates.settings
|
||||||
|
|
||||||
-- Create a category for every mod
|
-- Create the toggle category
|
||||||
|
local toggle_category = create_toggle_category(self, categories)
|
||||||
|
local toggle_index_offset = 0
|
||||||
|
|
||||||
|
-- Create the toggle category header
|
||||||
|
local toggle_header_data = {
|
||||||
|
type = "header",
|
||||||
|
category = toggle_category,
|
||||||
|
title = dmf:localize("toggle_mods"),
|
||||||
|
mod_name = "dmf",
|
||||||
|
tooltip = dmf:localize("toggle_mods"),
|
||||||
|
}
|
||||||
|
local toggle_header = create_option_template(self, toggle_header_data, toggle_category.display_name, toggle_index_offset)
|
||||||
|
if toggle_header then
|
||||||
|
settings[#settings + 1] = toggle_header
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Create the toggle category description
|
||||||
|
local desc_widget_data = {
|
||||||
|
mod_name = "dmf",
|
||||||
|
description = dmf:localize("toggle_mods_description"),
|
||||||
|
category = toggle_category.display_name,
|
||||||
|
display_name = toggle_category.display_name,
|
||||||
|
after = #settings,
|
||||||
|
type = "description"
|
||||||
|
}
|
||||||
|
local desc_template = create_option_template(self, desc_widget_data, toggle_category.display_name, toggle_index_offset)
|
||||||
|
|
||||||
|
if desc_template then
|
||||||
|
settings[#settings + 1] = desc_template
|
||||||
|
toggle_index_offset = toggle_index_offset + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Create a toggle for each mod; non-toggleable mods' toggles are disabled
|
||||||
for _, mod_data in ipairs(dmf.options_widgets_data) do
|
for _, mod_data in ipairs(dmf.options_widgets_data) do
|
||||||
|
local toggle_widget_data = {
|
||||||
|
mod_name = mod_data[1].mod_name,
|
||||||
|
readable_mod_name = mod_data[1].readable_mod_name or mod_data[1].title,
|
||||||
|
description = mod_data[1].description,
|
||||||
|
disabled = not mod_data[1].is_togglable,
|
||||||
|
category = toggle_category.display_name,
|
||||||
|
after = #settings,
|
||||||
|
type = "mod_toggle"
|
||||||
|
}
|
||||||
|
|
||||||
|
local toggle_template = create_option_template(self, toggle_widget_data, toggle_category.display_name, toggle_index_offset)
|
||||||
|
if toggle_template then
|
||||||
|
settings[#settings + 1] = toggle_template
|
||||||
|
toggle_index_offset = toggle_index_offset + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Create a category for every mod that has additional settings
|
||||||
|
for _, mod_data in ipairs(dmf.options_widgets_data) do
|
||||||
|
if #mod_data > 1 then
|
||||||
local category = create_mod_category(self, categories, mod_data[1])
|
local category = create_mod_category(self, categories, mod_data[1])
|
||||||
|
|
||||||
local index_offset = 0
|
local index_offset = 0
|
||||||
|
@ -468,22 +534,6 @@ dmf.create_mod_options_settings = function (self, options_templates)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Create a top-level toggle option if the mod is togglable
|
|
||||||
if mod_data[1].is_togglable then
|
|
||||||
local toggle_widget_data = {
|
|
||||||
mod_name = mod_data[1].mod_name,
|
|
||||||
category = category.display_name,
|
|
||||||
after = #settings,
|
|
||||||
type = "mod_toggle"
|
|
||||||
}
|
|
||||||
|
|
||||||
local toggle_template = create_option_template(self, toggle_widget_data, category.display_name, index_offset)
|
|
||||||
if toggle_template then
|
|
||||||
settings[#settings + 1] = toggle_template
|
|
||||||
index_offset = index_offset + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Populate the category with options taken from the remaining options data
|
-- Populate the category with options taken from the remaining options data
|
||||||
for i = 2, #mod_data do
|
for i = 2, #mod_data do
|
||||||
local widget_data = mod_data[i]
|
local widget_data = mod_data[i]
|
||||||
|
@ -498,6 +548,7 @@ dmf.create_mod_options_settings = function (self, options_templates)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return options_templates
|
return options_templates
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue