From 187b0339bd9f70129043bccc2af64b4859061533 Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Thu, 19 Jan 2023 18:57:16 +0100 Subject: [PATCH] Minor changes to API --- API.md | 12 ++++++++---- src/api.lua | 17 ++++++++++++----- src/common.lua | 2 +- src/gui.lua | 8 ++++---- src/progressive.lua | 11 ++++++----- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/API.md b/API.md index 21c6238..3e5a789 100644 --- a/API.md +++ b/API.md @@ -192,14 +192,16 @@ Add a new minitab (limited to 6). Example: ```Lua -i3.new_minitab("Test", { +i3.new_minitab("test", { + description = "Test", + + -- Whether this tab is visible or not. Optional. access = function(player, data) - -- Whether this tab is visible or not. Optional. return player:get_player_name() == "singleplayer" end, + -- Whether a specific item is shown in the list or not. sorter = function(item, data) - -- Whether a specific item is shown in the list or not. return item:find"wood" end }) @@ -212,7 +214,9 @@ i3.new_minitab("Test", { #### `i3.remove_minitab(name)` -Remove a minitab. +Remove a minitab by name. + +- `name` is the name of the tab to remove. #### `i3.minimap` diff --git a/src/api.lua b/src/api.lua index aa41f6d..900d0db 100644 --- a/src/api.lua +++ b/src/api.lua @@ -440,13 +440,14 @@ function i3.new_minitab(name, def) return err "i3.new_minitab: definition missing" end - insert(i3.minitabs, {name = name, def = def}) + def.name = name + insert(i3.minitabs, def) end function i3.remove_minitab(name) if not true_str(name) then return err "i3.remove_minitab: name missing" - elseif name == "All" then + elseif name == "all" then return err "i3.remove_minitab: removing the 'All' tab is not allowed" end @@ -458,19 +459,25 @@ function i3.remove_minitab(name) end end -i3.new_minitab("All", { +i3.new_minitab("all", { + description = "All", + sorter = function() return true end }) -i3.new_minitab("Nodes", { +i3.new_minitab("nodes", { + description = "Nodes", + sorter = function(item) return core.registered_nodes[item] end }) -i3.new_minitab("Items", { +i3.new_minitab("items", { + description = "Items", + sorter = function(item) return core.registered_craftitems[item] or core.registered_tools[item] end diff --git a/src/common.lua b/src/common.lua index fcddb16..31a7952 100644 --- a/src/common.lua +++ b/src/common.lua @@ -361,7 +361,7 @@ local function sort_by_category(data) for i = 1, #items do local item = items[i] local tab = i3.minitabs[data.itab] - local to_add = tab.def.sorter(item, data) + local to_add = tab.sorter(item, data) if to_add then insert(new, item) diff --git a/src/gui.lua b/src/gui.lua index bbbf121..9bba00b 100644 --- a/src/gui.lua +++ b/src/gui.lua @@ -1469,10 +1469,10 @@ local function get_minitabs(fs, data, player, full_height) local minitabs = {} for i, v in ipairs(i3.minitabs) do - local access = v.def.access + local access = v.access if access == nil or access(player, data) then - minitabs[i] = v.name + minitabs[i] = v.description end end @@ -1480,10 +1480,10 @@ local function get_minitabs(fs, data, player, full_height) for id, title in pairs(minitabs) do i++ - local X = i > 3 and i - 3 or i + local top = i > 3 + local X = top and i - 3 or i local selected = id == data.itab local hover_texture = selected and PNG.tab_small_hover or PNG.tab_small - local top = i > 3 local flip = top and "^[transformFY" or "" fs([[ style_type[image_button;bgimg=%s%s;bgimg_hovered=%s%s; diff --git a/src/progressive.lua b/src/progressive.lua index a67a6c2..3b15292 100644 --- a/src/progressive.lua +++ b/src/progressive.lua @@ -2,14 +2,15 @@ local set_fs = i3.set_fs local hud_notif = i3.hud_notif local POLL_FREQ = 0.25 -IMPORT("reg_items", "reg_nodes") -IMPORT("fmt", "table_merge", "array_diff") +IMPORT("reg_items", "reg_nodes", "fmt", "table_merge", "array_diff") IMPORT("is_group", "extract_groups", "item_has_groups", "apply_recipe_filters", "sort_by_category") -i3.remove_minitab"Nodes" -i3.remove_minitab"Items" +i3.remove_minitab"nodes" +i3.remove_minitab"items" + +i3.new_minitab("unlocked", { + description = "Unlocked", -i3.new_minitab("Unlocked", { sorter = function(item, data) return data.items_progress[item] end