From 31cd25f2a29a3783f0da3cb568b06cd6125d0eb9 Mon Sep 17 00:00:00 2001 From: rainer Date: Fri, 22 Aug 2025 02:33:02 +0200 Subject: [PATCH] first commit --- README.txt | 21 +++++++ init.lua | 87 +++++++++++++++++++++++++++++ mod.conf | 4 ++ textures/i3_extrabuttons_blank.png | Bin 0 -> 159 bytes textures/i3_extrabuttons_hover.png | Bin 0 -> 159 bytes 5 files changed, 112 insertions(+) create mode 100644 README.txt create mode 100644 init.lua create mode 100644 mod.conf create mode 100644 textures/i3_extrabuttons_blank.png create mode 100644 textures/i3_extrabuttons_hover.png 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 0000000000000000000000000000000000000000..43fc3db6dedcf534ef52ee786b72b74101b0f3e3 GIT binary patch literal 159 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jPK-BC>eK@{Ea{HEjtmSN z`?>!lvI6-E$sR$z3=CCj3=9n|3=F@3LJcn%7)lKo7+xhXFj&oCU=S~uvn$XBC?V_V z;uvCaI@zbEJ2znggMncHha0biX~LC;gGmewr@k@ndB1}FB2XcNr>mdKI;Vst0Q*xZ AAOHXW literal 0 HcmV?d00001 diff --git a/textures/i3_extrabuttons_hover.png b/textures/i3_extrabuttons_hover.png new file mode 100644 index 0000000000000000000000000000000000000000..f7fbb4e10a55a67dd46c58ea53414cbf93e8ff3e GIT binary patch literal 159 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jPK-BC>eK@{Ea{HEjtmSN z`?>!lvI6-E$sR$z3=CCj3=9n|3=F@3LJcn%7)lKo7+xhXFj&oCU=S~uvn$XBC?V_V z;uvCaI{DB4|MkqwtPP!wP6k;ARxmDR;}K(K$lSp^_mSLzopr04ani Ax&QzG literal 0 HcmV?d00001