Skip to content

gui/mod-manager improvements #1481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jul 26, 2025
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions gui/mod-manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,30 @@ local widgets = require('gui.widgets')
local presets_file = json.open("dfhack-config/mod-manager.json")
local GLOBAL_KEY = 'mod-manager'

-- get_newregion_viewscreen and get_modlist_fields are declared as global functions
-- so external tools can call them to get the DF mod list
function get_newregion_viewscreen()
-- Shamelessly taken from hack/library/lua/script-manager.lua
function vanilla(dir)
dir = dir.value
dir = dir -- better safe than sorry i guess
return dir:startswith('data/vanilla')
end

-- get_moddable_viewscreen(), get_any_moddable_viewscreen() and get_modlist_fields are declared
-- as global functions so external tools can call them to get the DF mod list
function get_moddable_viewscreen(type)
local vs = nil
if type == 'region' then
vs = dfhack.gui.getViewscreenByType(df.viewscreen_new_regionst, 0)
elseif type == 'arena' then
vs = dfhack.gui.getViewscreenByType(df.viewscreen_new_arenast, 0)
end
return vs
end

function get_any_moddable_viewscreen()
local vs = dfhack.gui.getViewscreenByType(df.viewscreen_new_regionst, 0)
if not vs then
vs = dfhack.gui.getViewscreenByType(df.viewscreen_new_arenast, 0)
end
return vs
end

Expand Down Expand Up @@ -62,7 +82,9 @@ local function move_mod_entry(viewscreen, to, from, mod_id, mod_version)
local mod_index = nil
for i, v in ipairs(from_fields.id) do
local version = from_fields.numeric_version[i]
if v.value == mod_id and version == mod_version then
local src_dir = from_fields.src_dir[i]
-- assumes that vanilla mods will not have multiple possible indices.
if v.value == mod_id and (vanilla(src_dir) or version == mod_version) then
mod_index = i
break
end
Expand Down Expand Up @@ -137,7 +159,7 @@ ModmanageMenu.ATTRS {
}

local function save_new_preset(preset_name)
local viewscreen = get_newregion_viewscreen()
local viewscreen = get_any_moddable_viewscreen()
local modlist = get_active_modlist(viewscreen)
table.insert(presets_file.data, { name = preset_name, modlist = modlist })
presets_file:write()
Expand All @@ -157,7 +179,7 @@ local function overwrite_preset(idx)
return
end

local viewscreen = get_newregion_viewscreen()
local viewscreen = get_any_moddable_viewscreen()
local modlist = get_active_modlist(viewscreen)
presets_file.data[idx].modlist = modlist
presets_file:write()
Expand All @@ -168,7 +190,7 @@ local function load_preset(idx, unset_default_on_failure)
return
end

local viewscreen = get_newregion_viewscreen()
local viewscreen = get_any_moddable_viewscreen()
local modlist = presets_file.data[idx].modlist
local failures = swap_modlist(viewscreen, modlist)

Expand Down Expand Up @@ -205,7 +227,7 @@ local function load_preset(idx, unset_default_on_failure)
table.insert(text, NEWLINE)
end
dialogs.showMessage("Warning", text)
end
end
end

local function find_preset_by_name(name)
Expand Down Expand Up @@ -573,7 +595,7 @@ ModmanageOverlay.ATTRS {
desc = "Adds a link to the mod selection screen for accessing the mod manager.",
default_pos = { x=5, y=-6 },
version = 2,
viewscreens = { "new_region/Mods" },
viewscreens = { "new_region/Mods", "new_arena/Mods" },
default_enabled=true,
}

Expand Down Expand Up @@ -636,7 +658,7 @@ notification_timer_fn()
local default_applied = false
dfhack.onStateChange[GLOBAL_KEY] = function(sc)
if sc == SC_VIEWSCREEN_CHANGED then
local vs = get_newregion_viewscreen()
local vs = get_any_moddable_viewscreen()
if vs and not default_applied then
default_applied = true
for i, v in ipairs(presets_file.data) do
Expand Down