diff --git a/doc/mod_api.txt b/doc/mod_api.txt index 0d100a0..ff52792 100644 --- a/doc/mod_api.txt +++ b/doc/mod_api.txt @@ -101,3 +101,72 @@ Register a non-standard craft recipe: -- ^ Same as `minetest.register_recipe` }) + +Categories +---------- + +Register a new category: + The config table (second argument) is optional, and all its members are optional + See the unified_inventory.set_category_* functions for more details on the members of the config table + + unified_inventory.register_category("category_name", { + symbol = "mod_name:item_name" or "texture.png", + label = "Human Readable Label", + index = 5, + items = { + "mod_name:item_name", + "another_mod:different_item" + } + }) + +Add / override the symbol for a category: + The category does not need to exist first + The symbol can be an item name or a texture image + If unset this will default to "default:stick" + + unified_inventory.set_category_symbol("category_name", "mod_name:item_name" or "texture.png") + +Add / override the human readable label for a category: + If unset this will default to the category name + + unified_inventory.set_category_label("category_name", "Human Readable Label") + +Add / override the sorting index of the category: + Must be a number, can also be negative (-5) or fractional (2.345) + This determines the position the category appears in the list of categories + The "all" meta-category has index -2, the "misc"/"uncategorized" meta-category has index -1, use a negative number smaller than these to make a category appear before these in the list + By default categories are sorted alphabetically with an index between 0.0101(AA) and 0.2626(ZZ) + + unified_inventory.set_category_index("category_name", 5) + +Add a single item to a category: + + unified_inventory.add_category_item("category_name", "mod_name:item_name") + +Add multiple items to a category: + + unified_inventory.add_category_items("category_name", { + "mod_name:item_name", + "another_mod:different_item" + }) + +Remove an item from a category: + + unified_inventory.remove_category_item("category_name", "mod_name:item_name") + +Remove a category entirely: + + unified_inventory.remove_category("category_name") + +Finding existing items in categories: + This will find the first category an item exists in + It should be used for checking if an item is catgorised + Returns "category_name" or nil + + unified_inventory.find_category("mod_name:item_name") + + + This will find all the categories an item exists in + Returns a number indexed table (list) of category names + + unified_inventory.find_categories("mod_name:item_name") diff --git a/internal.lua b/internal.lua index 85aecf1..5f28987 100644 --- a/internal.lua +++ b/internal.lua @@ -36,7 +36,7 @@ local function formspec_button(ui_peruser, name, image, offset, pos, scale, labe (offset.x or offset[1]) + ( ui_peruser.btn_spc * (pos.x or pos[1]) ) + spc, (offset.y or offset[2]) + ( ui_peruser.btn_spc * (pos.y or pos[2]) ) + spc, size, size, image, name) .. - string.format("tooltip[%s;%s]", name, F(S(label))) + string.format("tooltip[%s;%s]", name, F(S(label or name))) end function ui.get_formspec(player, page) @@ -157,12 +157,12 @@ function ui.get_formspec(player, page) end if category_count > ui_peruser.pagecols and scroll_offset > 0 then -- prev - formspec[n] = formspec_button(ui_peruser, "prev_category", "ui_left_icon.png", categories_scroll_pos, {ui_peruser.pagecols - 2, 0}, 0.8, "Scroll Categories Left") + formspec[n] = formspec_button(ui_peruser, "prev_category", "ui_left_icon.png", categories_scroll_pos, {ui_peruser.pagecols - 2, 0}, 0.8, "Scroll categories left") n = n + 1 end if category_count > ui_peruser.pagecols and category_count - scroll_offset > ui_peruser.pagecols then -- next - formspec[n] = formspec_button(ui_peruser, "next_category", "ui_right_icon.png", categories_scroll_pos, {ui_peruser.pagecols - 1, 0}, 0.8, "Scroll Categories Right") + formspec[n] = formspec_button(ui_peruser, "next_category", "ui_right_icon.png", categories_scroll_pos, {ui_peruser.pagecols - 1, 0}, 0.8, "Scroll categories right") n = n + 1 end diff --git a/textures/ui_category_all.png b/textures/ui_category_all.png index a18571f..0af7a53 100644 Binary files a/textures/ui_category_all.png and b/textures/ui_category_all.png differ diff --git a/textures/ui_category_none.png b/textures/ui_category_none.png index 631d022..8976fb0 100644 Binary files a/textures/ui_category_none.png and b/textures/ui_category_none.png differ diff --git a/textures/ui_smallbg_9_sliced.png b/textures/ui_smallbg_9_sliced.png index 1a08d68..865e0c9 100644 Binary files a/textures/ui_smallbg_9_sliced.png and b/textures/ui_smallbg_9_sliced.png differ