Divergent/mods/Show All Faction Relations .../gamedata/scripts/dmg_safr_pda_mcm.script

163 lines
5.2 KiB
Plaintext

-- ======================================================================
--[[ Show All Faction Relations in PDA
-- ======================================================================
MCM initialization script
Author: dEmergence (dEmergence @ ModDB)
Source: https://www.moddb.com/mods/stalker-anomaly/addons/show-all-faction-relation-in-pda-except-monolith
Version: 6.2
Updated: 20231220
Credits for code that I found helpful and reused:
TheMrDemonized, DoctorX for MCM Preset Selection Code
As found in "[1.5.2/1.5.1] DYNAMIC ANOMALIES OVERHAUL (DAO)"
https://www.moddb.com/mods/stalker-anomaly/addons/dynamic-anomalies-overhaul-dao-read-description-please
ravenascendant for MCM table insert Code
As found in "REPUTATION EDITOR (ANOMALY 1.5.1/1.5.2)"
https://www.moddb.com/mods/stalker-anomaly/addons/reputation-editor
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
-- ===================================================================--]]
-- Reused Code from DAO
op_id = "dmg_safr_pda"
op_preset_id = "user_preset"
presets = {
[0] = {},
[1] = {},
[2] = {}
}
function Set(t,set_value)
local s = {}
for _,v in pairs(t) do s[v] = set_value end
return s
end
op = {id = "dmg_safr_pda", sh = true, gr = {}}
-- Reused Code from DAO
if ui_mcm and ui_mcm.UIMCM and ui_mcm.UIMCM.Callback_List then
MCM_Callback_List = ui_mcm.UIMCM.Callback_List
ui_mcm.UIMCM.Callback_List = function(self, ctrl, path, opt, v)
MCM_Callback_List(self, ctrl, path, opt, v)
if path ~= op_id then return end
if opt == op_preset_id then
local value = self:GetValue(path, opt, v)
set_preset(self, value)
end
end
end
function on_mcm_load()
-- Populate Presets
-- Anomaly Default Extended
-- Set 'Do not show' for all then overwrite with default values
presets[0] = Set(game_relations.factions_table,0)
presets[0]["stalker"] = 2
presets[0]["bandit"] = 2
presets[0]["csky"] = 2
presets[0]["dolg"] = 2
presets[0]["freedom"] = 2
presets[0]["killer"] = 2
presets[0]["army"] = 2
presets[0]["ecolog"] = 2
presets[0]["monolith"] = 2
if level.present and db.actor then
local actor_comm = string.gsub( character_community(db.actor), "actor_", "" )
printf("SAFR: Actor community = '"..actor_comm)
presets[0][actor_comm] = 2
end
presets[1] = Set(game_relations.factions_table,2)
presets[2] = Set(game_relations.factions_table,1)
-- mcm menu code
t = {
{id = "title", type = "slide", link = "ui_options_slider_player", text = "ui_mcm_dmg_safr_pda_title", size = { 512, 50 }, spacing = 20 },
{id = "show_eliminated", type = "check", val = 1, def = true},
{id = "disable_squad_count", type = "check", val = 1, def = true},
{id = "show_local_squad_count", type = "check", val = 1, def = false},
{id = "obscure_enemy_squad_count", type = "check", val = 1, def = true},
{id = "divider", type="line" },
{id = "use_encyclopedia_discovery", type = "check", val = 1, def = false},
{id = "debug_log", type = "check", val = 1, def = false},
{id = "show_mutant_faction", type = "check", val = 1, def = false},
{id = "divider", type="line" },
{id = "user_preset", type = "list", val = 2, def = 1,
content= {
{0,"SAFR_default_anomaly"},
{1,"SAFR_all_always"},
{2,"SAFR_all_when_discovered"},
{3,"SAFR_user_defined"}
}
},
{id = "user_defined_desc", type = "desc", text = "ui_mcm_dmg_safr_pda_user_defined_desc_text"}
}
for i=1, #game_relations.factions_table do
table.insert(t, {id = game_relations.factions_table[i], hint = "dcommontxt_factions_"..game_relations.factions_table[i], type = "radio_h", val = 2, def = 1, content = { { 0, "SAFR_Never_show_faction" }, { 1, "SAFR_Show_faction_by_progression" }, { 2, "SAFR_Always_show_faction" } }})
end
op.gr = t
return op
end
-- Reused Code from DAO
function set_preset(self, p)
if not presets[p] then
printf("DRX DA preset %s not found", p)
return
end
-- Pre-build available MCM values
local t = {}
for _, v in ipairs(op.gr) do
if v.def ~= nil then
t[v.id] = v.def
end
end
for k, value in pairs(presets[p]) do
if t[k] then
-- Validate option
local v = ui_mcm.get_opt_table(op_id .. "/" .. k)
if v and v.type then
-- Get proper value
if v.val == 0 then
-- Pass input value as is
elseif v.val == 1 then
value = (value == "true") and true or false
elseif v.val == 2 then
value = clamp(tonumber(value), v.min or 0, v.max or 100)
end
-- Extract path and opt
local t = ui_mcm.str_opt_explode(op_id .. "/" .. k)
local opt = t[#t]
local path = t[1]
for i=2,#t-1 do
path = ui_mcm.cc(path , t[i])
end
-- Cache changes
self:CacheValue(path, opt, value, v)
end
end
end
-- Update XML elements
self:Reset_opt(self.last_curr_tree, self.last_path)
-- Update state
self:UpdatePending()
end