From 7b7ee4134638910f32b77456ca912e3c356af9e6 Mon Sep 17 00:00:00 2001 From: Daretmavi Date: Tue, 6 Jul 2021 11:50:32 +0200 Subject: [PATCH] Test skinsdb tab --- i3_mods_tabs.lua | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ init.lua | 4 ++++ 2 files changed, 55 insertions(+) create mode 100644 i3_mods_tabs.lua diff --git a/i3_mods_tabs.lua b/i3_mods_tabs.lua new file mode 100644 index 0000000..51baba8 --- /dev/null +++ b/i3_mods_tabs.lua @@ -0,0 +1,51 @@ +local modpath = core.get_modpath "i3" + +local maxn, sort, concat, copy, insert, remove, indexof = + table.maxn, table.sort, table.concat, table.copy, + table.insert, table.remove, table.indexof + +local sprintf, find, gmatch, match, sub, split, upper, lower = + string.format, string.find, string.gmatch, string.match, + string.sub, string.split, string.upper, string.lower + +local PNG, styles, fs_elements = loadfile(modpath .. "/etc/styles.lua")() + +local ESC = core.formspec_escape +local S = core.get_translator "i3" + +local ES = function(...) + return ESC(S(...)) +end + +local function fmt(elem, ...) + if not fs_elements[elem] then + return sprintf(elem, ...) + end + + return sprintf(fs_elements[elem], ...) +end + +i3.new_tab { + name = "Skins", + description = "Skins", + image = "i3_skin.png", + + formspec = function(player, data, fs) + --fs("label[3,1;Test 1]") + local name = player:get_player_name() + local _skins = skins.get_skinlist_for_player(name) + local sks = {} + local yextra = 1 + + for _, skin in ipairs(_skins) do + sks[#sks + 1] = skin.name + end + + sks = concat(sks, ","):gsub(";", "") + + fs("label", 1, yextra + 0.85, fmt("%s:", ES"Select a skin")) + fs(fmt("dropdown[1,%f;4,0.6;skins;%s;%u;true]", yextra + 1.1, sks, data.skin_id or 1)) + --core.log("skin: ", dump(skins.get_player_skin(player).name)) + end, +} + diff --git a/init.lua b/init.lua index c9ded8c..23d4197 100644 --- a/init.lua +++ b/init.lua @@ -3428,3 +3428,7 @@ end --dofile(modpath .. "/tests/test_tabs.lua") --dofile(modpath .. "/tests/test_custom_recipes.lua") + +if __skinsdb then + dofile(modpath .. "/i3_mods_tabs.lua") +end \ No newline at end of file