Skip to content

Commit 850af80

Browse files
authoredJun 4, 2020
Add buttons to ContentDB in game bar and configure world (#9944)
1 parent c1e01bc commit 850af80

File tree

4 files changed

+79
-39
lines changed

4 files changed

+79
-39
lines changed
 

Diff for: ‎builtin/mainmenu/dlg_config_world.lua

+56-39
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,49 @@ local function modname_valid(name)
2323
return not name:find("[^a-z0-9_]")
2424
end
2525

26+
local function init_data(data)
27+
data.list = filterlist.create(
28+
pkgmgr.preparemodlist,
29+
pkgmgr.comparemod,
30+
function(element, uid)
31+
if element.name == uid then
32+
return true
33+
end
34+
end,
35+
function(element, criteria)
36+
if criteria.hide_game and
37+
element.is_game_content then
38+
return false
39+
end
40+
41+
if criteria.hide_modpackcontents and
42+
element.modpack ~= nil then
43+
return false
44+
end
45+
return true
46+
end,
47+
{
48+
worldpath = data.worldspec.path,
49+
gameid = data.worldspec.gameid
50+
})
51+
52+
if data.selected_mod > data.list:size() then
53+
data.selected_mod = 0
54+
end
55+
56+
data.list:set_filtercriteria({
57+
hide_game = data.hide_gamemods,
58+
hide_modpackcontents = data.hide_modpackcontents
59+
})
60+
data.list:add_sort_mechanism("alphabetic", sort_mod_list)
61+
data.list:set_sortmode("alphabetic")
62+
end
63+
2664
local function get_formspec(data)
65+
if not data.list then
66+
init_data(data)
67+
end
68+
2769
local mod = data.list:get_list()[data.selected_mod] or {name = ""}
2870

2971
local retval =
@@ -85,11 +127,14 @@ local function get_formspec(data)
85127
end
86128
end
87129
end
130+
88131
retval = retval ..
89132
"button[3.25,7;2.5,0.5;btn_config_world_save;" ..
90133
fgettext("Save") .. "]" ..
91134
"button[5.75,7;2.5,0.5;btn_config_world_cancel;" ..
92-
fgettext("Cancel") .. "]"
135+
fgettext("Cancel") .. "]" ..
136+
"button[9,7;2.5,0.5;btn_config_world_cdb;" ..
137+
fgettext("Find More Mods") .. "]"
93138

94139
if mod.name ~= "" and not mod.is_game_content then
95140
if mod.is_modpack then
@@ -198,6 +243,16 @@ local function handle_buttons(this, fields)
198243
return true
199244
end
200245

246+
if fields.btn_config_world_cdb then
247+
this.data.list = nil
248+
249+
local dlg = create_store_dlg("mod")
250+
dlg:set_parent(this)
251+
this:hide()
252+
dlg:show()
253+
return true
254+
end
255+
201256
if fields.btn_enable_all_mods then
202257
local list = this.data.list:get_raw_list()
203258

@@ -247,43 +302,5 @@ function create_configure_world_dlg(worldidx)
247302
return
248303
end
249304

250-
dlg.data.list = filterlist.create(
251-
pkgmgr.preparemodlist,
252-
pkgmgr.comparemod,
253-
function(element, uid)
254-
if element.name == uid then
255-
return true
256-
end
257-
end,
258-
function(element, criteria)
259-
if criteria.hide_game and
260-
element.is_game_content then
261-
return false
262-
end
263-
264-
if criteria.hide_modpackcontents and
265-
element.modpack ~= nil then
266-
return false
267-
end
268-
return true
269-
end,
270-
{
271-
worldpath = dlg.data.worldspec.path,
272-
gameid = dlg.data.worldspec.gameid
273-
}
274-
)
275-
276-
277-
if dlg.data.selected_mod > dlg.data.list:size() then
278-
dlg.data.selected_mod = 0
279-
end
280-
281-
dlg.data.list:set_filtercriteria({
282-
hide_game = dlg.data.hide_gamemods,
283-
hide_modpackcontents = dlg.data.hide_modpackcontents
284-
})
285-
dlg.data.list:add_sort_mechanism("alphabetic", sort_mod_list)
286-
dlg.data.list:set_sortmode("alphabetic")
287-
288305
return dlg
289306
end

Diff for: ‎builtin/mainmenu/dlg_contentstore.lua

+11
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,17 @@ function create_store_dlg(type)
513513

514514
search_string = ""
515515
cur_page = 1
516+
517+
if type then
518+
-- table.indexof does not work on tables that contain `nil`
519+
for i, v in pairs(filter_types_type) do
520+
if v == type then
521+
filter_type = i
522+
break
523+
end
524+
end
525+
end
526+
516527
store.filter_packages(search_string)
517528

518529
return dialog_create("store",

Diff for: ‎builtin/mainmenu/tab_local.lua

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ if enable_gamebar then
3535
end
3636

3737
local function game_buttonbar_button_handler(fields)
38+
if fields.game_open_cdb then
39+
local maintab = ui.find_by_name("maintab")
40+
local dlg = create_store_dlg("game")
41+
dlg:set_parent(maintab)
42+
maintab:hide()
43+
dlg:show()
44+
return true
45+
end
46+
3847
for key,value in pairs(fields) do
3948
for j=1,#pkgmgr.games,1 do
4049
if ("game_btnbar_" .. pkgmgr.games[j].id == key) then
@@ -87,6 +96,9 @@ if enable_gamebar then
8796
end
8897
btnbar:add_button(btn_name, text, image, tooltip)
8998
end
99+
100+
local plus_image = core.formspec_escape(defaulttexturedir .. "plus.png")
101+
btnbar:add_button("game_open_cdb", "", plus_image, fgettext("Install games from ContentDB"))
90102
end
91103
else
92104
function current_game()

Diff for: ‎textures/base/pack/plus.png

763 Bytes
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.