first commit

This commit is contained in:
Rainer 2025-08-22 02:33:02 +02:00
commit 31cd25f2a2
5 changed files with 112 additions and 0 deletions

21
README.txt Normal file
View file

@ -0,0 +1,21 @@
i3_extrabuttons
Dieses Mod erlaubt es beliebig viele "Zusatzbuttons" für das i3-Inventar anzulegen.
Andere Mods registrieren ihre Extra Buttons über
i3_extrabuttons.new_tab("name", {...})
Die Syntax ist identisch zu i3.new_tab, nur dass sie unter "Extras" gelistet werden.
Beispiel:
if minetest.global_exists("i3_extrabuttons") then
i3_extrabuttons.new_tab("pubinv", {
description = "Public Inventory",
image = "ui_icon_pubinv.png",
fields = function(player, data, fields)
-- Deins...
pubinv.open(player:get_player_name())
end,
})
end

87
init.lua Normal file
View file

@ -0,0 +1,87 @@
local S = minetest.get_translator(minetest.get_current_modname())
local extrabuttons = {}
i3_extrabuttons = {}
-- API-kompatibel: optionale priv/privs
function i3_extrabuttons.new_tab(name, def)
extrabuttons[#extrabuttons+1] = {
name = name,
def = def,
}
end
local function has_required_priv(player, def)
-- Einzelnes Privileg
if def.priv then
return minetest.check_player_privs(player, { [def.priv] = true })
end
-- Liste von Privs (alle müssen erfüllt sein)
if def.privs then
for _, priv in ipairs(def.privs) do
if not minetest.check_player_privs(player, { [priv] = true }) then
return false
end
end
return true
end
-- Kein Priv, immer anzeigen
return true
end
local function extras_formspec(player, data, fs)
-- Alphabetisch sortiert nach sichtbarer Beschriftung ("description" oder "name")
table.sort(extrabuttons, function(a, b)
local ad = a.def.description or a.name
local bd = b.def.description or b.name
return ad:lower() < bd:lower()
end)
local max_per_col = 10
local btn_width = 4
local btn_height = 0.8
local col_space = 7
local x_left = 1
local x_right = x_left + col_space
local btn_idx = 0
for _, tab in ipairs(extrabuttons) do
-- PRÜFUNG auf Rechte für diese Button-Definition:
if has_required_priv(player, tab.def) then
btn_idx = btn_idx + 1
local desc = tab.def.description or tab.name
local col = math.floor((btn_idx-1) / max_per_col)
local row = (btn_idx-1) % max_per_col
local x = (col == 0) and x_left or x_right
local y = 1 + row * (btn_height + 0.3)
fs(string.format(
'image_button[%.1f,%.1f;%.1f,%.1f;i3_extrabuttons_blank.png;extrabtn_%s;%s;;i3_extrabuttons_button_hover.png]',
x, y, btn_width, btn_height,
tab.name, minetest.formspec_escape(desc)
))
end
end
end
local function extras_fields(player, data, fields)
for _, tab in ipairs(extrabuttons) do
if fields["extrabtn_"..tab.name] and tab.def.fields then
return tab.def.fields(player, data, fields)
elseif fields["extrabtn_"..tab.name] and tab.def.formspec then
i3.set_tab(player, "inventory")
tab.def.formspec(player, data, function(...) end)
return
end
end
end
-- Tabs registrieren (wie gehabt)
if i3 then
i3.new_tab("i3_extrabuttons", {
description = S("Extras"),
formspec = extras_formspec,
fields = extras_fields,
})
end
_G.i3_extrabuttons = i3_extrabuttons

4
mod.conf Normal file
View file

@ -0,0 +1,4 @@
name = i3_extrabuttons
description = Mehr Tab-Buttons für i3, ohne das i3-Limit
depends = i3
author= Rage87

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B