commit 31cd25f2a29a3783f0da3cb568b06cd6125d0eb9 Author: rainer Date: Fri Aug 22 02:33:02 2025 +0200 first commit diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..cacd289 --- /dev/null +++ b/README.txt @@ -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 diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..9270d2a --- /dev/null +++ b/init.lua @@ -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 diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..9678c03 --- /dev/null +++ b/mod.conf @@ -0,0 +1,4 @@ +name = i3_extrabuttons +description = Mehr Tab-Buttons für i3, ohne das i3-Limit +depends = i3 +author= Rage87 diff --git a/textures/i3_extrabuttons_blank.png b/textures/i3_extrabuttons_blank.png new file mode 100644 index 0000000..43fc3db Binary files /dev/null and b/textures/i3_extrabuttons_blank.png differ diff --git a/textures/i3_extrabuttons_hover.png b/textures/i3_extrabuttons_hover.png new file mode 100644 index 0000000..f7fbb4e Binary files /dev/null and b/textures/i3_extrabuttons_hover.png differ