Finish skins integration
This commit is contained in:
parent
3fb3a43311
commit
0d76ffa30c
@ -194,6 +194,7 @@ end
|
||||
|
||||
smart_inventory.register_page({
|
||||
name = "crafting",
|
||||
tooltip = "Craft new items",
|
||||
icon = "inventory_btn.png",
|
||||
smartfs_callback = crafting_callback,
|
||||
sequence = 10
|
||||
|
2
init.lua
2
init.lua
@ -70,6 +70,7 @@ local inventory_form = smartfs.create("smart_inventory:main", function(state)
|
||||
if def.icon then
|
||||
tabdef.button:setImage(def.icon)
|
||||
end
|
||||
tabdef.button:setTooltip(def.tooltip)
|
||||
tabdef.button:onClick(function(self)
|
||||
tab_controller:set_active(def.name)
|
||||
if def.on_button_click then
|
||||
@ -92,6 +93,7 @@ function smart_inventory.register_page(def)
|
||||
--[[ API:
|
||||
smart_inventory.register_page({
|
||||
name = name
|
||||
tooltip = button tooltip
|
||||
icon | label = *.png|text
|
||||
check_active = (optional: function to check if active) (TODO)
|
||||
smartfs_callback = smartfs callback function
|
||||
|
55
player.lua
55
player.lua
@ -57,6 +57,7 @@ local function update_selected_item(state, listentry)
|
||||
local fire = listentry.itemdef.groups.armor_fire or 0
|
||||
local radiation = listentry.itemdef.groups.armor_radiation or 0
|
||||
|
||||
state:get("item_name"):setText(listentry.itemdef.description)
|
||||
state:get("item_level"):setText("Level: "..level)
|
||||
state:get("item_heal"):setText("Heal: "..heal)
|
||||
state:get("item_fire"):setText("Fire: "..fire)
|
||||
@ -77,13 +78,23 @@ local function update_page(state)
|
||||
state:get("fire"):setText("Fire: "..armor.def[name].fire)
|
||||
state:get("radiation"):setText("Radiation: "..armor.def[name].radiation)
|
||||
update_selected_item(state)
|
||||
elseif smart_inventory.skins_mod then
|
||||
elseif smart_inventory.skins_mod then
|
||||
state.location.parentState:get("player_button"):setImage(skins.skins[name].."_preview.png")
|
||||
state:get("preview"):setImage(skins.skins[name].."_preview.png")
|
||||
end
|
||||
|
||||
if smart_inventory.skins_mod then
|
||||
|
||||
local skin = skins.skins[name]
|
||||
print("skin:", skin, skins.meta[skin])
|
||||
if skin and skins.meta[skin] then
|
||||
state:get("skinname"):setText("Skin name: "..(skins.meta[skin].name or ""))
|
||||
state:get("skinauthor"):setText("Author: "..(skins.meta[skin].author or ""))
|
||||
state:get("skinlicense"):setText("License: "..(skins.meta[skin].license or ""))
|
||||
else
|
||||
state:get("skinname"):setText("")
|
||||
state:get("skinauthor"):setText("")
|
||||
state:get("skinlicense"):setText("")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -107,23 +118,27 @@ end
|
||||
|
||||
local function player_callback(state)
|
||||
local name = state.location.rootState.location.player
|
||||
state:image(7,2.5,2,4,"preview","")
|
||||
state:background(0, 2.3, 6, 4.6, "it_bg", "minimap_overlay_square.png")
|
||||
state:label(0.1,2.5,"item_name", "")
|
||||
state:label(0.1,3.0,"item_level", "")
|
||||
state:label(0.1,3.5,"item_heal","")
|
||||
state:label(0.1,4.0,"item_fire", "")
|
||||
state:label(0.1,4.5, "item_radiation", "")
|
||||
state:item_image(0,5.0,2,2,"item_image","")
|
||||
|
||||
state:background(6.7, 2.3, 6, 4.6, "pl_bg", "minimap_overlay_square.png")
|
||||
state:image(7,3.0,2,4,"preview","")
|
||||
state:label(9,2.5,"level", "")
|
||||
state:label(9,3.0,"heal","")
|
||||
state:label(9,3.5,"fire", "")
|
||||
state:label(9,4.0, "radiation", "")
|
||||
state:background(6.7, 2.3, 6, 4.6, "pl_bg", "minimap_overlay_square.png")
|
||||
|
||||
state:label(0.1,2.5,"item_level", "")
|
||||
state:label(0.1,3.0,"item_heal","")
|
||||
state:label(0.1,3.5,"item_fire", "")
|
||||
state:label(0.1,4.0, "item_radiation", "")
|
||||
state:item_image(0,4.5,2,2,"item_image","")
|
||||
state:background(0, 2.3, 6, 4.6, "it_bg", "minimap_overlay_square.png")
|
||||
state:label(9,5.0,"skinname","")
|
||||
state:label(9,5.5,"skinauthor", "")
|
||||
state:label(9,6.0, "skinlicense", "")
|
||||
|
||||
state:background(0, 0, 20, 1, "top_bg", "halo.png")
|
||||
state:background(0, 8, 20, 2, "bottom_bg", "halo.png")
|
||||
|
||||
if smart_inventory.armor_mod then
|
||||
local grid_armor = smart_inventory.smartfs_elements.buttons_grid(state, 0, 0, 8, 1, "armor_grid")
|
||||
|
||||
@ -144,15 +159,17 @@ local function player_callback(state)
|
||||
|
||||
if smart_inventory.skins_mod then
|
||||
-- Skins Grid
|
||||
local grid_skins = smart_inventory.smartfs_elements.buttons_grid(state, 13, 1, 7 , 7, "skins_grid", false, 0.87, 1.30)
|
||||
grid_skins:setBackground("minimap_overlay_square.png")
|
||||
local grid_skins = smart_inventory.smartfs_elements.buttons_grid(state, 13.1, 1.3, 7 , 7, "skins_grid", false, 0.87, 1.30)
|
||||
state:background(13, 1, 7 , 7, "bg_skins", "minimap_overlay_square.png")
|
||||
grid_skins:onClick(function(self, state, index, player)
|
||||
skins.skins[player] = skins.list[index]
|
||||
local skin = skins.list[index]
|
||||
local player_obj = minetest.get_player_by_name(name)
|
||||
skins.skins[player] = skin
|
||||
skins.file_save = true
|
||||
skins.update_player_skin(minetest.get_player_by_name(name))
|
||||
skins.update_player_skin(player_obj)
|
||||
if smart_inventory.armor_mod then
|
||||
armor.textures[name].skin = skins.list[index]..".png"
|
||||
armor:set_player_armor(minetest.get_player_by_name(name))
|
||||
armor.textures[name].skin = skin..".png"
|
||||
armor:set_player_armor(player_obj)
|
||||
end
|
||||
update_page(state)
|
||||
end)
|
||||
@ -161,11 +178,12 @@ local function player_callback(state)
|
||||
for idx, skin in pairs(skins.list) do
|
||||
table.insert(skins_grid_data, {
|
||||
image = skin.."_preview.png",
|
||||
tooltip = skins.meta[skin].name,
|
||||
is_button = true,
|
||||
size = { w = 0.87, h = 1.30 }
|
||||
})
|
||||
if skin == skins.skins[name] then
|
||||
grid_skins:setFirstVisible(idx - 20) --8x5 (grid size) / 2
|
||||
grid_skins:setFirstVisible(idx - 19) --8x5 (grid size) / 2 -1
|
||||
end
|
||||
end
|
||||
grid_skins:setList(skins_grid_data)
|
||||
@ -176,6 +194,7 @@ end
|
||||
smart_inventory.register_page({
|
||||
name = "player",
|
||||
icon = "player.png",
|
||||
tooltip = "Customize yourself",
|
||||
smartfs_callback = player_callback,
|
||||
sequence = 20,
|
||||
on_button_click = update_page
|
||||
|
@ -82,12 +82,20 @@ end
|
||||
--- Pagable grid buttons
|
||||
-----------------------------------------------------
|
||||
--[[ enhanced / prepared container
|
||||
Additional methods
|
||||
buttons_grid:setList(craft)
|
||||
buttons_grid:onClick(function(state, index, player)...end)
|
||||
buttons_grid:setList(iconlist)
|
||||
buttons_grid:getFirstVisible()
|
||||
buttons_grid:setFirstVisible(index)
|
||||
Additional methods
|
||||
buttons_grid:setList(craft)
|
||||
buttons_grid:onClick(function(state, index, player)...end)
|
||||
buttons_grid:setList(iconlist)
|
||||
buttons_grid:getFirstVisible()
|
||||
buttons_grid:setFirstVisible(index)
|
||||
|
||||
iconslist is a list of next entries:
|
||||
entry = {
|
||||
image | item =
|
||||
tooltip=
|
||||
is_button = true,
|
||||
size = {w=,h=}
|
||||
}
|
||||
]]
|
||||
local buttons_grid = table.copy(smartfs._edef.container)
|
||||
function buttons_grid:onCreate()
|
||||
@ -102,13 +110,13 @@ function buttons_grid:onCreate()
|
||||
self.data.list = {}
|
||||
for x = 1, self.data.grid_size.w do
|
||||
for y=1, self.data.grid_size.h do
|
||||
local button = self._state:image_button(
|
||||
local button = self._state:button(
|
||||
(x-1)*self.data.cell_size.w,
|
||||
(y-1)*self.data.cell_size.h,
|
||||
self.data.cell_size.w,
|
||||
self.data.cell_size.h,
|
||||
tostring((y-1)*self.data.grid_size.w+x),
|
||||
"text1","text2")
|
||||
"")
|
||||
button:onClick(function(self, state, player)
|
||||
local rel = tonumber(self.name)
|
||||
local parent_element = state.location.containerElement
|
||||
@ -198,10 +206,12 @@ function buttons_grid:update()
|
||||
button:setIsHidden(false)
|
||||
button:setItem(entry.item)
|
||||
button:setText("")
|
||||
button:setTooltip(nil)
|
||||
elseif entry.image and entry.is_button == true then
|
||||
button:setIsHidden(false)
|
||||
button:setImage(entry.image)
|
||||
button:setText("")
|
||||
button:setTooltip(entry.tooltip)
|
||||
-- TODO 1: entry.image to display *.png
|
||||
-- TODO 2: entry.text to display label on button
|
||||
-- TODO 3,4,5: is_button == false to get just pic or label without button
|
||||
|
22
smartfs.lua
22
smartfs.lua
@ -217,6 +217,7 @@ smartfs._ldef.inventory = {
|
||||
player = name,
|
||||
_show_ = function(state)
|
||||
local player = minetest.get_player_by_name(state.location.player)
|
||||
--print(state:_buildFormspec_(true))
|
||||
player:set_inventory_formspec(state:_buildFormspec_(true))
|
||||
end
|
||||
}
|
||||
@ -802,12 +803,12 @@ smartfs.element("button", {
|
||||
assert(self.data.value, "button needs label")
|
||||
end,
|
||||
build = function(self)
|
||||
local specstring
|
||||
local specstring = self:getBackgroundString()
|
||||
if self.data.image then
|
||||
if self.data.closes then
|
||||
specstring = "image_button_exit["
|
||||
specstring = specstring.."image_button_exit["
|
||||
else
|
||||
specstring = "image_button["
|
||||
specstring = specstring.."image_button["
|
||||
end
|
||||
elseif self.data.item then
|
||||
if self.data.closes then
|
||||
@ -826,14 +827,19 @@ smartfs.element("button", {
|
||||
specstring = specstring ..
|
||||
self.data.pos.x..","..self.data.pos.y..";"..
|
||||
self.data.size.w..","..self.data.size.h..";"
|
||||
|
||||
if self.data.image then
|
||||
specstring = specstring..self.data.image..";"
|
||||
elseif self.data.item then
|
||||
specstring = specstring..self.data.item..";"
|
||||
end
|
||||
|
||||
specstring = specstring..self:getAbsName()..";"..
|
||||
minetest.formspec_escape(self.data.value).."]"..
|
||||
self:getBackgroundString()
|
||||
minetest.formspec_escape(self.data.value).."]"
|
||||
|
||||
if self.data.tooltip then
|
||||
specstring = specstring.."tooltip["..self:getAbsName()..";"..self.data.tooltip.."]"
|
||||
end
|
||||
return specstring
|
||||
end,
|
||||
submit = function(self, field, player)
|
||||
@ -872,6 +878,12 @@ smartfs.element("button", {
|
||||
getItem = function(self)
|
||||
return self.data.item
|
||||
end,
|
||||
setTooltip = function(self,text)
|
||||
self.data.tooltip = text
|
||||
end,
|
||||
getTooltip = function(self)
|
||||
return self.data.tooltip
|
||||
end,
|
||||
setClose = function(self,bool)
|
||||
self.data.closes = bool
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user