Minor changes to API
This commit is contained in:
parent
74e88acadf
commit
187b0339bd
12
API.md
12
API.md
|
@ -192,14 +192,16 @@ Add a new minitab (limited to 6).
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```Lua
|
```Lua
|
||||||
i3.new_minitab("Test", {
|
i3.new_minitab("test", {
|
||||||
access = function(player, data)
|
description = "Test",
|
||||||
|
|
||||||
-- Whether this tab is visible or not. Optional.
|
-- Whether this tab is visible or not. Optional.
|
||||||
|
access = function(player, data)
|
||||||
return player:get_player_name() == "singleplayer"
|
return player:get_player_name() == "singleplayer"
|
||||||
end,
|
end,
|
||||||
|
|
||||||
sorter = function(item, data)
|
|
||||||
-- Whether a specific item is shown in the list or not.
|
-- Whether a specific item is shown in the list or not.
|
||||||
|
sorter = function(item, data)
|
||||||
return item:find"wood"
|
return item:find"wood"
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -212,7 +214,9 @@ i3.new_minitab("Test", {
|
||||||
|
|
||||||
#### `i3.remove_minitab(name)`
|
#### `i3.remove_minitab(name)`
|
||||||
|
|
||||||
Remove a minitab.
|
Remove a minitab by name.
|
||||||
|
|
||||||
|
- `name` is the name of the tab to remove.
|
||||||
|
|
||||||
#### `i3.minimap`
|
#### `i3.minimap`
|
||||||
|
|
||||||
|
|
17
src/api.lua
17
src/api.lua
|
@ -440,13 +440,14 @@ function i3.new_minitab(name, def)
|
||||||
return err "i3.new_minitab: definition missing"
|
return err "i3.new_minitab: definition missing"
|
||||||
end
|
end
|
||||||
|
|
||||||
insert(i3.minitabs, {name = name, def = def})
|
def.name = name
|
||||||
|
insert(i3.minitabs, def)
|
||||||
end
|
end
|
||||||
|
|
||||||
function i3.remove_minitab(name)
|
function i3.remove_minitab(name)
|
||||||
if not true_str(name) then
|
if not true_str(name) then
|
||||||
return err "i3.remove_minitab: name missing"
|
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"
|
return err "i3.remove_minitab: removing the 'All' tab is not allowed"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -458,19 +459,25 @@ function i3.remove_minitab(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
i3.new_minitab("All", {
|
i3.new_minitab("all", {
|
||||||
|
description = "All",
|
||||||
|
|
||||||
sorter = function()
|
sorter = function()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
i3.new_minitab("Nodes", {
|
i3.new_minitab("nodes", {
|
||||||
|
description = "Nodes",
|
||||||
|
|
||||||
sorter = function(item)
|
sorter = function(item)
|
||||||
return core.registered_nodes[item]
|
return core.registered_nodes[item]
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
i3.new_minitab("Items", {
|
i3.new_minitab("items", {
|
||||||
|
description = "Items",
|
||||||
|
|
||||||
sorter = function(item)
|
sorter = function(item)
|
||||||
return core.registered_craftitems[item] or core.registered_tools[item]
|
return core.registered_craftitems[item] or core.registered_tools[item]
|
||||||
end
|
end
|
||||||
|
|
|
@ -361,7 +361,7 @@ local function sort_by_category(data)
|
||||||
for i = 1, #items do
|
for i = 1, #items do
|
||||||
local item = items[i]
|
local item = items[i]
|
||||||
local tab = i3.minitabs[data.itab]
|
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
|
if to_add then
|
||||||
insert(new, item)
|
insert(new, item)
|
||||||
|
|
|
@ -1469,10 +1469,10 @@ local function get_minitabs(fs, data, player, full_height)
|
||||||
local minitabs = {}
|
local minitabs = {}
|
||||||
|
|
||||||
for i, v in ipairs(i3.minitabs) do
|
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
|
if access == nil or access(player, data) then
|
||||||
minitabs[i] = v.name
|
minitabs[i] = v.description
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1480,10 +1480,10 @@ local function get_minitabs(fs, data, player, full_height)
|
||||||
|
|
||||||
for id, title in pairs(minitabs) do
|
for id, title in pairs(minitabs) do
|
||||||
i++
|
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 selected = id == data.itab
|
||||||
local hover_texture = selected and PNG.tab_small_hover or PNG.tab_small
|
local hover_texture = selected and PNG.tab_small_hover or PNG.tab_small
|
||||||
local top = i > 3
|
|
||||||
local flip = top and "^[transformFY" or ""
|
local flip = top and "^[transformFY" or ""
|
||||||
|
|
||||||
fs([[ style_type[image_button;bgimg=%s%s;bgimg_hovered=%s%s;
|
fs([[ style_type[image_button;bgimg=%s%s;bgimg_hovered=%s%s;
|
||||||
|
|
|
@ -2,14 +2,15 @@ local set_fs = i3.set_fs
|
||||||
local hud_notif = i3.hud_notif
|
local hud_notif = i3.hud_notif
|
||||||
local POLL_FREQ = 0.25
|
local POLL_FREQ = 0.25
|
||||||
|
|
||||||
IMPORT("reg_items", "reg_nodes")
|
IMPORT("reg_items", "reg_nodes", "fmt", "table_merge", "array_diff")
|
||||||
IMPORT("fmt", "table_merge", "array_diff")
|
|
||||||
IMPORT("is_group", "extract_groups", "item_has_groups", "apply_recipe_filters", "sort_by_category")
|
IMPORT("is_group", "extract_groups", "item_has_groups", "apply_recipe_filters", "sort_by_category")
|
||||||
|
|
||||||
i3.remove_minitab"Nodes"
|
i3.remove_minitab"nodes"
|
||||||
i3.remove_minitab"Items"
|
i3.remove_minitab"items"
|
||||||
|
|
||||||
|
i3.new_minitab("unlocked", {
|
||||||
|
description = "Unlocked",
|
||||||
|
|
||||||
i3.new_minitab("Unlocked", {
|
|
||||||
sorter = function(item, data)
|
sorter = function(item, data)
|
||||||
return data.items_progress[item]
|
return data.items_progress[item]
|
||||||
end
|
end
|
||||||
|
|
Ŝarĝante…
Reference in New Issue