From 850af80089b3415265c4b4b744448509f776a52d Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Thu, 4 Jun 2020 21:53:26 +0100 Subject: [PATCH] Add buttons to ContentDB in game bar and configure world (#9944) --- builtin/mainmenu/dlg_config_world.lua | 95 +++++++++++++++----------- builtin/mainmenu/dlg_contentstore.lua | 11 +++ builtin/mainmenu/tab_local.lua | 12 ++++ textures/base/pack/plus.png | Bin 0 -> 763 bytes 4 files changed, 79 insertions(+), 39 deletions(-) create mode 100644 textures/base/pack/plus.png diff --git a/builtin/mainmenu/dlg_config_world.lua b/builtin/mainmenu/dlg_config_world.lua index 97218df9c..2cf70c9c9 100644 --- a/builtin/mainmenu/dlg_config_world.lua +++ b/builtin/mainmenu/dlg_config_world.lua @@ -23,7 +23,49 @@ local function modname_valid(name) return not name:find("[^a-z0-9_]") end +local function init_data(data) + data.list = filterlist.create( + pkgmgr.preparemodlist, + pkgmgr.comparemod, + function(element, uid) + if element.name == uid then + return true + end + end, + function(element, criteria) + if criteria.hide_game and + element.is_game_content then + return false + end + + if criteria.hide_modpackcontents and + element.modpack ~= nil then + return false + end + return true + end, + { + worldpath = data.worldspec.path, + gameid = data.worldspec.gameid + }) + + if data.selected_mod > data.list:size() then + data.selected_mod = 0 + end + + data.list:set_filtercriteria({ + hide_game = data.hide_gamemods, + hide_modpackcontents = data.hide_modpackcontents + }) + data.list:add_sort_mechanism("alphabetic", sort_mod_list) + data.list:set_sortmode("alphabetic") +end + local function get_formspec(data) + if not data.list then + init_data(data) + end + local mod = data.list:get_list()[data.selected_mod] or {name = ""} local retval = @@ -85,11 +127,14 @@ local function get_formspec(data) end end end + retval = retval .. "button[3.25,7;2.5,0.5;btn_config_world_save;" .. fgettext("Save") .. "]" .. "button[5.75,7;2.5,0.5;btn_config_world_cancel;" .. - fgettext("Cancel") .. "]" + fgettext("Cancel") .. "]" .. + "button[9,7;2.5,0.5;btn_config_world_cdb;" .. + fgettext("Find More Mods") .. "]" if mod.name ~= "" and not mod.is_game_content then if mod.is_modpack then @@ -198,6 +243,16 @@ local function handle_buttons(this, fields) return true end + if fields.btn_config_world_cdb then + this.data.list = nil + + local dlg = create_store_dlg("mod") + dlg:set_parent(this) + this:hide() + dlg:show() + return true + end + if fields.btn_enable_all_mods then local list = this.data.list:get_raw_list() @@ -247,43 +302,5 @@ function create_configure_world_dlg(worldidx) return end - dlg.data.list = filterlist.create( - pkgmgr.preparemodlist, - pkgmgr.comparemod, - function(element, uid) - if element.name == uid then - return true - end - end, - function(element, criteria) - if criteria.hide_game and - element.is_game_content then - return false - end - - if criteria.hide_modpackcontents and - element.modpack ~= nil then - return false - end - return true - end, - { - worldpath = dlg.data.worldspec.path, - gameid = dlg.data.worldspec.gameid - } - ) - - - if dlg.data.selected_mod > dlg.data.list:size() then - dlg.data.selected_mod = 0 - end - - dlg.data.list:set_filtercriteria({ - hide_game = dlg.data.hide_gamemods, - hide_modpackcontents = dlg.data.hide_modpackcontents - }) - dlg.data.list:add_sort_mechanism("alphabetic", sort_mod_list) - dlg.data.list:set_sortmode("alphabetic") - return dlg end diff --git a/builtin/mainmenu/dlg_contentstore.lua b/builtin/mainmenu/dlg_contentstore.lua index 76c398f5a..8ac4dba68 100644 --- a/builtin/mainmenu/dlg_contentstore.lua +++ b/builtin/mainmenu/dlg_contentstore.lua @@ -513,6 +513,17 @@ function create_store_dlg(type) search_string = "" cur_page = 1 + + if type then + -- table.indexof does not work on tables that contain `nil` + for i, v in pairs(filter_types_type) do + if v == type then + filter_type = i + break + end + end + end + store.filter_packages(search_string) return dialog_create("store", diff --git a/builtin/mainmenu/tab_local.lua b/builtin/mainmenu/tab_local.lua index cd6cbea46..a21cf12b1 100644 --- a/builtin/mainmenu/tab_local.lua +++ b/builtin/mainmenu/tab_local.lua @@ -35,6 +35,15 @@ if enable_gamebar then end local function game_buttonbar_button_handler(fields) + if fields.game_open_cdb then + local maintab = ui.find_by_name("maintab") + local dlg = create_store_dlg("game") + dlg:set_parent(maintab) + maintab:hide() + dlg:show() + return true + end + for key,value in pairs(fields) do for j=1,#pkgmgr.games,1 do if ("game_btnbar_" .. pkgmgr.games[j].id == key) then @@ -87,6 +96,9 @@ if enable_gamebar then end btnbar:add_button(btn_name, text, image, tooltip) end + + local plus_image = core.formspec_escape(defaulttexturedir .. "plus.png") + btnbar:add_button("game_open_cdb", "", plus_image, fgettext("Install games from ContentDB")) end else function current_game() diff --git a/textures/base/pack/plus.png b/textures/base/pack/plus.png new file mode 100644 index 0000000000000000000000000000000000000000..64680b5698f487d5e2806ce6093297184f8f2526 GIT binary patch literal 763 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H3?#oinD`S&%?$7faRt)<2O9u8>0r%KO`zip zOM?7@85kIum|57^Id}!d#3iKU^h{m7e0&3AYnv9W+qh}-)?KGAK79K8#mje}zW@07 z>(AeR(ZzioKur%kT^vIyZoQp(a$1vtfNQXeqiYC@jKmQ}_YjMJ|BsgjG{${niz|;V zf2b5$a9;3poR^|RTOt%aJMYM~gW(`6hn_9?o!DB^DR^UfjIwr=RQCC?DW}}byoXF5)-(JUT2$Zmp_!vz|5@vAa%^Z| i;6@=5km5)FBkRHo#qO#MF(tr+!r