Skip to content

Commit bb4db84

Browse files
rubenwardyparamat
authored andcommittedFeb 10, 2017
Use tree to list mods rather than textlist
1 parent 7760948 commit bb4db84

File tree

3 files changed

+59
-112
lines changed

3 files changed

+59
-112
lines changed
 

Diff for: ‎builtin/mainmenu/dlg_config_world.lua

+30-80
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,26 @@
1717

1818
--------------------------------------------------------------------------------
1919

20-
local enabled_all = false
20+
local enabled_all = false
2121

2222
local function modname_valid(name)
2323
return not name:find("[^a-z0-9_]")
2424
end
2525

2626
local function get_formspec(data)
27-
2827
local mod = data.list:get_list()[data.selected_mod]
2928

3029
local retval =
3130
"size[11.5,7.5,true]" ..
3231
"label[0.5,0;" .. fgettext("World:") .. "]" ..
3332
"label[1.75,0;" .. data.worldspec.name .. "]"
3433

35-
if data.hide_gamemods then
36-
retval = retval .. "checkbox[1,6;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";true]"
37-
else
38-
retval = retval .. "checkbox[1,6;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";false]"
39-
end
40-
41-
if data.hide_modpackcontents then
42-
retval = retval .. "checkbox[6,6;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";true]"
43-
else
44-
retval = retval .. "checkbox[6,6;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";false]"
45-
end
46-
4734
if mod == nil then
4835
mod = {name=""}
4936
end
5037

5138
local hard_deps, soft_deps = modmgr.get_dependencies(mod.path)
52-
39+
5340
retval = retval ..
5441
"label[0,0.7;" .. fgettext("Mod:") .. "]" ..
5542
"label[0.75,0.7;" .. mod.name .. "]" ..
@@ -62,41 +49,45 @@ local function get_formspec(data)
6249
"button[3.25,7;2.5,0.5;btn_config_world_save;" .. fgettext("Save") .. "]" ..
6350
"button[5.75,7;2.5,0.5;btn_config_world_cancel;" .. fgettext("Cancel") .. "]"
6451

65-
if mod ~= nil and mod.name ~= "" and mod.typ ~= "game_mod" then
52+
if mod and mod.name ~= "" and mod.typ ~= "game_mod" then
6653
if mod.is_modpack then
6754
local rawlist = data.list:get_raw_list()
6855

6956
local all_enabled = true
70-
for j=1,#rawlist,1 do
71-
if rawlist[j].modpack == mod.name and
72-
rawlist[j].enabled ~= true then
73-
all_enabled = false
74-
break
57+
for j = 1, #rawlist, 1 do
58+
if rawlist[j].modpack == mod.name and not rawlist[j].enabled then
59+
all_enabled = false
60+
break
7561
end
7662
end
7763

78-
if all_enabled == false then
79-
retval = retval .. "button[5.5,0.125;2.5,0.5;btn_mp_enable;" .. fgettext("Enable MP") .. "]"
64+
if all_enabled then
65+
retval = retval .. "button[5.5,0.125;2.5,0.5;btn_mp_disable;" ..
66+
fgettext("Disable MP") .. "]"
8067
else
81-
retval = retval .. "button[5.5,0.125;2.5,0.5;btn_mp_disable;" .. fgettext("Disable MP") .. "]"
68+
retval = retval .. "button[5.5,0.125;2.5,0.5;btn_mp_enable;" ..
69+
fgettext("Enable MP") .. "]"
8270
end
8371
else
8472
if mod.enabled then
85-
retval = retval .. "checkbox[5.5,-0.125;cb_mod_enable;" .. fgettext("enabled") .. ";true]"
73+
retval = retval .. "checkbox[5.5,-0.125;cb_mod_enable;" ..
74+
fgettext("enabled") .. ";true]"
8675
else
87-
retval = retval .. "checkbox[5.5,-0.125;cb_mod_enable;" .. fgettext("enabled") .. ";false]"
76+
retval = retval .. "checkbox[5.5,-0.125;cb_mod_enable;" ..
77+
fgettext("enabled") .. ";false]"
8878
end
8979
end
9080
end
91-
if enabled_all then
81+
if enabled_all then
9282
retval = retval ..
93-
"button[8.75,0.125;2.5,0.5;btn_disable_all_mods;" .. fgettext("Disable all") .. "]" ..
94-
"textlist[5.5,0.75;5.75,5.4;world_config_modlist;"
83+
"button[8.75,0.125;2.5,0.5;btn_disable_all_mods;" .. fgettext("Disable all") .. "]"
9584
else
9685
retval = retval ..
97-
"button[8.75,0.125;2.5,0.5;btn_enable_all_mods;" .. fgettext("Enable all") .. "]" ..
98-
"textlist[5.5,0.75;5.75,5.4;world_config_modlist;"
86+
"button[8.75,0.125;2.5,0.5;btn_enable_all_mods;" .. fgettext("Enable all") .. "]"
9987
end
88+
retval = retval ..
89+
"tablecolumns[color;tree;text]" ..
90+
"table[5.5,0.75;5.75,6;world_config_modlist;"
10091
retval = retval .. modmgr.render_modlist(data.list)
10192
retval = retval .. ";" .. data.selected_mod .."]"
10293

@@ -129,16 +120,15 @@ end
129120

130121

131122
local function handle_buttons(this, fields)
132-
133123
if fields["world_config_modlist"] ~= nil then
134-
local event = core.explode_textlist_event(fields["world_config_modlist"])
135-
this.data.selected_mod = event.index
136-
core.setting_set("world_config_selected_mod", event.index)
124+
local event = core.explode_table_event(fields["world_config_modlist"])
125+
this.data.selected_mod = event.row
126+
core.setting_set("world_config_selected_mod", event.row)
137127

138128
if event.type == "DCL" then
139129
enable_mod(this)
140130
end
141-
131+
142132
return true
143133
end
144134

@@ -160,44 +150,7 @@ local function handle_buttons(this, fields)
160150
return true
161151
end
162152

163-
if fields["cb_hide_gamemods"] ~= nil or
164-
fields["cb_hide_mpcontent"] ~= nil then
165-
local current = this.data.list:get_filtercriteria()
166-
167-
if current == nil then
168-
current = {}
169-
end
170-
171-
if fields["cb_hide_gamemods"] ~= nil then
172-
if core.is_yes(fields["cb_hide_gamemods"]) then
173-
current.hide_game = true
174-
this.data.hide_gamemods = true
175-
core.setting_set("world_config_hide_gamemods", "true")
176-
else
177-
current.hide_game = false
178-
this.data.hide_gamemods = false
179-
core.setting_set("world_config_hide_gamemods", "false")
180-
end
181-
end
182-
183-
if fields["cb_hide_mpcontent"] ~= nil then
184-
if core.is_yes(fields["cb_hide_mpcontent"]) then
185-
current.hide_modpackcontents = true
186-
this.data.hide_modpackcontents = true
187-
core.setting_set("world_config_hide_modpackcontents", "true")
188-
else
189-
current.hide_modpackcontents = false
190-
this.data.hide_modpackcontents = false
191-
core.setting_set("world_config_hide_modpackcontents", "false")
192-
end
193-
end
194-
195-
this.data.list:set_filtercriteria(current)
196-
return true
197-
end
198-
199153
if fields["btn_config_world_save"] then
200-
201154
local filename = this.data.worldspec.path ..
202155
DIR_DELIM .. "world.mt"
203156

@@ -231,7 +184,7 @@ local function handle_buttons(this, fields)
231184
if not worldfile:write() then
232185
core.log("error", "Failed to write world config file")
233186
end
234-
187+
235188
this:delete()
236189
return true
237190
end
@@ -252,7 +205,7 @@ local function handle_buttons(this, fields)
252205
enabled_all = true
253206
return true
254207
end
255-
208+
256209
if fields.btn_disable_all_mods then
257210
local list = this.data.list:get_raw_list()
258211

@@ -269,14 +222,11 @@ local function handle_buttons(this, fields)
269222
end
270223

271224
function create_configure_world_dlg(worldidx)
272-
273225
local dlg = dialog_create("sp_config_world",
274226
get_formspec,
275227
handle_buttons,
276228
nil)
277229

278-
dlg.data.hide_gamemods = core.setting_getbool("world_config_hide_gamemods")
279-
dlg.data.hide_modpackcontents = core.setting_getbool("world_config_hide_modpackcontents")
280230
dlg.data.selected_mod = tonumber(core.setting_get("world_config_selected_mod"))
281231
if dlg.data.selected_mod == nil then
282232
dlg.data.selected_mod = 0
@@ -286,14 +236,14 @@ function create_configure_world_dlg(worldidx)
286236
if dlg.data.worldspec == nil then dlg:delete() return nil end
287237

288238
dlg.data.worldconfig = modmgr.get_worldconfig(dlg.data.worldspec.path)
289-
239+
290240
if dlg.data.worldconfig == nil or dlg.data.worldconfig.id == nil or
291241
dlg.data.worldconfig.id == "" then
292242

293243
dlg:delete()
294244
return nil
295245
end
296-
246+
297247
dlg.data.list = filterlist.create(
298248
modmgr.preparemodlist, --refresh
299249
modmgr.comparemod, --compare

Diff for: ‎builtin/mainmenu/modmgr.lua

+25-29
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
--------------------------------------------------------------------------------
1919
function get_mods(path,retval,modpack)
2020
local mods = core.get_dir_list(path, true)
21-
21+
2222
for _, name in ipairs(mods) do
2323
if name:sub(1, 1) ~= "." then
2424
local prefix = path .. DIR_DELIM .. name .. DIR_DELIM
@@ -237,49 +237,45 @@ function modmgr.render_modlist(render_list)
237237

238238
local list = render_list:get_list()
239239
local last_modpack = nil
240-
241-
for i,v in ipairs(list) do
242-
if retval ~= "" then
243-
retval = retval ..","
240+
local retval = {}
241+
local in_game_mods = false
242+
for i, v in ipairs(list) do
243+
if v.typ == "game_mod" and not in_game_mods then
244+
in_game_mods = true
245+
retval[#retval + 1] = mt_color_blue
246+
retval[#retval + 1] = "0"
247+
retval[#retval + 1] = fgettext("Subgame Mods")
244248
end
245249

246250
local color = ""
247-
248251
if v.is_modpack then
249252
local rawlist = render_list:get_raw_list()
253+
color = mt_color_dark_green
250254

251-
local all_enabled = true
252-
for j=1,#rawlist,1 do
255+
for j = 1, #rawlist, 1 do
253256
if rawlist[j].modpack == list[i].name and
254-
rawlist[j].enabled ~= true then
255-
all_enabled = false
256-
break
257+
rawlist[j].enabled ~= true then
258+
-- Modpack not entirely enabled so showing as grey
259+
color = mt_color_grey
260+
break
257261
end
258262
end
259-
260-
if all_enabled == false then
261-
color = mt_color_grey
262-
else
263-
color = mt_color_dark_green
264-
end
265-
end
266-
267-
if v.typ == "game_mod" then
263+
elseif v.typ == "game_mod" then
268264
color = mt_color_blue
269-
else
270-
if v.enabled then
271-
color = mt_color_green
272-
end
265+
elseif v.enabled then
266+
color = mt_color_green
273267
end
274268

275-
retval = retval .. color
276-
if v.modpack ~= nil then
277-
retval = retval .. " "
269+
retval[#retval + 1] = color
270+
if v.modpack ~= nil or v.typ == "game_mod" then
271+
retval[#retval + 1] = "1"
272+
else
273+
retval[#retval + 1] = "0"
278274
end
279-
retval = retval .. v.name
275+
retval[#retval + 1] = core.formspec_escape(v.name)
280276
end
281277

282-
return retval
278+
return table.concat(retval, ",")
283279
end
284280

285281
--------------------------------------------------------------------------------

Diff for: ‎builtin/mainmenu/tab_mods.lua

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ local function get_formspec(tabview, name, tabdata)
2828

2929
local retval =
3030
"label[0.05,-0.25;".. fgettext("Installed Mods:") .. "]" ..
31-
"textlist[0,0.25;5.1,5;modlist;" ..
31+
"tablecolumns[color;tree;text]" ..
32+
"table[0,0.25;5.1,5;modlist;" ..
3233
modmgr.render_modlist(modmgr.global_mods) ..
3334
";" .. tabdata.selected_mod .. "]"
3435

@@ -127,8 +128,8 @@ end
127128
--------------------------------------------------------------------------------
128129
local function handle_buttons(tabview, fields, tabname, tabdata)
129130
if fields["modlist"] ~= nil then
130-
local event = core.explode_textlist_event(fields["modlist"])
131-
tabdata.selected_mod = event.index
131+
local event = core.explode_table_event(fields["modlist"])
132+
tabdata.selected_mod = event.row
132133
return true
133134
end
134135

0 commit comments

Comments
 (0)
Please sign in to comment.