From 1385ad34bbf0910616c8615b8497b9c06bd7f039 Mon Sep 17 00:00:00 2001 From: LeMagnesium Date: Wed, 13 Jul 2016 20:20:55 +0200 Subject: [PATCH] [pclasses] Add information menus (informations not yet written) - For #473 --- mods/pclasses/api.lua | 4 ++ mods/pclasses/depends.txt | 1 + mods/pclasses/inventory.lua | 62 ++++++++++++++++++++++++ mods/pclasses/textures/pclasses_inv.png | Bin 0 -> 598 bytes 4 files changed, 67 insertions(+) create mode 100644 mods/pclasses/textures/pclasses_inv.png diff --git a/mods/pclasses/api.lua b/mods/pclasses/api.lua index 8f091927..ff9caac9 100755 --- a/mods/pclasses/api.lua +++ b/mods/pclasses/api.lua @@ -14,6 +14,10 @@ function pclasses.api.register_class(cname, def) cname .. ". Reason : no definition table.") return end + if cname == "infos" then + minetest.log("error", "[PClasses] Error registering class with reserved name : infos") + return + end pclasses.register_class_switch(cname, def.switch_params) pclasses.classes[cname] = def diff --git a/mods/pclasses/depends.txt b/mods/pclasses/depends.txt index 00881d35..86d6f14f 100755 --- a/mods/pclasses/depends.txt +++ b/mods/pclasses/depends.txt @@ -1,2 +1,3 @@ 3d_armor sprint +unified_inventory diff --git a/mods/pclasses/inventory.lua b/mods/pclasses/inventory.lua index f8cd0929..4028ff71 100755 --- a/mods/pclasses/inventory.lua +++ b/mods/pclasses/inventory.lua @@ -85,3 +85,65 @@ function pclasses.api.vacuum_graveyard(player) end end end + +-- Inventory description buttons +local pbutton_form = "size[10,10]" .. + "button_exit[4.5,9.5;1,0.5;pmenu_leave;Leave]" .. + "tabheader[0,0;pmenu_header;infos" + +function textify(text) + return "textarea[0.5,0.2;9.6,10;pmenu_data;;" .. text .. "]" +end + +local pbuttons = {} +local pforms = {} +local pinfo = textify( + "PClasses (Player Classes) allows you to become a member of specific classes implemented with abilities, advantages, and reserved items. " .. + "Each one of the classes defined grants the right to carry items, called reserved items, tied to the abilities of a class. A hunter will be " .. + "able to use arrows, whereas a warrior can own powerful weapons. Each time you switch classes, you will lose your stats and items, the latter " .. + "being transfered into a special part of your inventory, the graveyard. Once you return to a class that allows you to use those items, they will " .. + "return in your main inventory.\n" .. + "You can use this menu to navigate between classes and read informations about what abilities come with specific classes." +) + + +minetest.after(0, function() + for cname, cdef in pairs(pclasses.classes) do + if cname ~= pclasses.conf.superuser_class then + pbutton_form = pbutton_form .. ',' .. cname + table.insert(pbuttons, cname) + end + end + pbutton_form = pbutton_form .. ";1]" + minetest.log("action", pbutton_form) +end) + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= "" then return end + + if fields.pmenu_header then + minetest.log(fields.pmenu_header) + if fields.pmenu_header + 0 == 1 then + player:set_inventory_formspec(pbutton_form .. pinfo) + else + player:set_inventory_formspec(string.sub(pbutton_form, 1, -3) .. fields.pmenu_header .. "]" .. textify(pclasses.classes[pbuttons[fields.pmenu_header-1]].informations or "No informations available")) + end + return + + elseif fields.pmenu_leave then + player:set_inventory_formspec(pforms[player:get_player_name()]) + pforms[player:get_player_name()] = nil + end +end) + +unified_inventory.register_button("pclasses", { + type = "image", + image = "pclasses_inv.png", + tooltip = "Player Classes Descriptions", + action = function(player) + if not pforms[player:get_player_name()] then + pforms[player:get_player_name()] = player:get_inventory_formspec() + player:set_inventory_formspec(pbutton_form .. pinfo) + end + end +}) diff --git a/mods/pclasses/textures/pclasses_inv.png b/mods/pclasses/textures/pclasses_inv.png new file mode 100644 index 0000000000000000000000000000000000000000..1de55e50e108eb2d1f01069be5f3a633047f72da GIT binary patch literal 598 zcmV-c0;&CpP)1QxR}3}0^Gr7XGK5EqMo3}x}F;+g8qj9IOQ^R!T5qW0jT+Db{ERw6^&h=g=SGt zX@|fpx{&~YT9U~cQJ}1aGpct409+q8tcy#K=f(*;ejXnw?OKu)1Aa#A*@DBZ=8yV)ZkE8;?rUrB>ws20fJ8Lb_6r9ILx}gC?Wu#zK@8IV1 zk)2$W4n6FE8I3}KvJjj(CwWz{05tcbddIqm4&iIgDdb_~geWVe0K4sp^UjsLT%p^Z zC~W``DYNh;-~Tg~`vygTno}LV?HheIb6sAyVopzk80f1IUuUblUAZ*R5vjU+K#M@~ za^>|*e;UMWza9yZ{{Cz-UPxqKZQ-_=QwSLeE(#ogcOe#;QwWi+jD9`*08@mvH29iR z2p@S}1)TZ1-^`DfLvyz}1h;#@@jf6^p_^0V>UfI1MN0uVxHWga9ImWBg;if2PxG2s z_nWAWr^@)=qNSS|5H5hi6s-HrKYb6l%mL3E5rOc2LoPCw3f-NM=g8F16#SUxbG9L$ k2>kDd$+lGn;9sNg4R#LB;UTR;{{R3007*qoM6N<$g7PvAMF0Q* literal 0 HcmV?d00001