Finish skins integration

This commit is contained in:
Alexander Weber 2017-02-13 22:26:43 +01:00
parent 3fb3a43311
commit 0d76ffa30c
5 changed files with 75 additions and 31 deletions

View File

@ -194,6 +194,7 @@ end
smart_inventory.register_page({ smart_inventory.register_page({
name = "crafting", name = "crafting",
tooltip = "Craft new items",
icon = "inventory_btn.png", icon = "inventory_btn.png",
smartfs_callback = crafting_callback, smartfs_callback = crafting_callback,
sequence = 10 sequence = 10

View File

@ -70,6 +70,7 @@ local inventory_form = smartfs.create("smart_inventory:main", function(state)
if def.icon then if def.icon then
tabdef.button:setImage(def.icon) tabdef.button:setImage(def.icon)
end end
tabdef.button:setTooltip(def.tooltip)
tabdef.button:onClick(function(self) tabdef.button:onClick(function(self)
tab_controller:set_active(def.name) tab_controller:set_active(def.name)
if def.on_button_click then if def.on_button_click then
@ -92,6 +93,7 @@ function smart_inventory.register_page(def)
--[[ API: --[[ API:
smart_inventory.register_page({ smart_inventory.register_page({
name = name name = name
tooltip = button tooltip
icon | label = *.png|text icon | label = *.png|text
check_active = (optional: function to check if active) (TODO) check_active = (optional: function to check if active) (TODO)
smartfs_callback = smartfs callback function smartfs_callback = smartfs callback function

View File

@ -57,6 +57,7 @@ local function update_selected_item(state, listentry)
local fire = listentry.itemdef.groups.armor_fire or 0 local fire = listentry.itemdef.groups.armor_fire or 0
local radiation = listentry.itemdef.groups.armor_radiation 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_level"):setText("Level: "..level)
state:get("item_heal"):setText("Heal: "..heal) state:get("item_heal"):setText("Heal: "..heal)
state:get("item_fire"):setText("Fire: "..fire) 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("fire"):setText("Fire: "..armor.def[name].fire)
state:get("radiation"):setText("Radiation: "..armor.def[name].radiation) state:get("radiation"):setText("Radiation: "..armor.def[name].radiation)
update_selected_item(state) 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.location.parentState:get("player_button"):setImage(skins.skins[name].."_preview.png")
state:get("preview"):setImage(skins.skins[name].."_preview.png") state:get("preview"):setImage(skins.skins[name].."_preview.png")
end end
if smart_inventory.skins_mod then 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
end end
@ -107,23 +118,27 @@ end
local function player_callback(state) local function player_callback(state)
local name = state.location.rootState.location.player 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,2.5,"level", "")
state:label(9,3.0,"heal","") state:label(9,3.0,"heal","")
state:label(9,3.5,"fire", "") state:label(9,3.5,"fire", "")
state:label(9,4.0, "radiation", "") 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(9,5.0,"skinname","")
state:label(0.1,3.0,"item_heal","") state:label(9,5.5,"skinauthor", "")
state:label(0.1,3.5,"item_fire", "") state:label(9,6.0, "skinlicense", "")
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:background(0, 0, 20, 1, "top_bg", "halo.png") state:background(0, 0, 20, 1, "top_bg", "halo.png")
state:background(0, 8, 20, 2, "bottom_bg", "halo.png") state:background(0, 8, 20, 2, "bottom_bg", "halo.png")
if smart_inventory.armor_mod then if smart_inventory.armor_mod then
local grid_armor = smart_inventory.smartfs_elements.buttons_grid(state, 0, 0, 8, 1, "armor_grid") 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 if smart_inventory.skins_mod then
-- Skins Grid -- Skins Grid
local grid_skins = smart_inventory.smartfs_elements.buttons_grid(state, 13, 1, 7 , 7, "skins_grid", false, 0.87, 1.30) local grid_skins = smart_inventory.smartfs_elements.buttons_grid(state, 13.1, 1.3, 7 , 7, "skins_grid", false, 0.87, 1.30)
grid_skins:setBackground("minimap_overlay_square.png") state:background(13, 1, 7 , 7, "bg_skins", "minimap_overlay_square.png")
grid_skins:onClick(function(self, state, index, player) 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.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 if smart_inventory.armor_mod then
armor.textures[name].skin = skins.list[index]..".png" armor.textures[name].skin = skin..".png"
armor:set_player_armor(minetest.get_player_by_name(name)) armor:set_player_armor(player_obj)
end end
update_page(state) update_page(state)
end) end)
@ -161,11 +178,12 @@ local function player_callback(state)
for idx, skin in pairs(skins.list) do for idx, skin in pairs(skins.list) do
table.insert(skins_grid_data, { table.insert(skins_grid_data, {
image = skin.."_preview.png", image = skin.."_preview.png",
tooltip = skins.meta[skin].name,
is_button = true, is_button = true,
size = { w = 0.87, h = 1.30 } size = { w = 0.87, h = 1.30 }
}) })
if skin == skins.skins[name] then 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
end end
grid_skins:setList(skins_grid_data) grid_skins:setList(skins_grid_data)
@ -176,6 +194,7 @@ end
smart_inventory.register_page({ smart_inventory.register_page({
name = "player", name = "player",
icon = "player.png", icon = "player.png",
tooltip = "Customize yourself",
smartfs_callback = player_callback, smartfs_callback = player_callback,
sequence = 20, sequence = 20,
on_button_click = update_page on_button_click = update_page

View File

@ -82,12 +82,20 @@ end
--- Pagable grid buttons --- Pagable grid buttons
----------------------------------------------------- -----------------------------------------------------
--[[ enhanced / prepared container --[[ enhanced / prepared container
Additional methods Additional methods
buttons_grid:setList(craft) buttons_grid:setList(craft)
buttons_grid:onClick(function(state, index, player)...end) buttons_grid:onClick(function(state, index, player)...end)
buttons_grid:setList(iconlist) buttons_grid:setList(iconlist)
buttons_grid:getFirstVisible() buttons_grid:getFirstVisible()
buttons_grid:setFirstVisible(index) 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) local buttons_grid = table.copy(smartfs._edef.container)
function buttons_grid:onCreate() function buttons_grid:onCreate()
@ -102,13 +110,13 @@ function buttons_grid:onCreate()
self.data.list = {} self.data.list = {}
for x = 1, self.data.grid_size.w do for x = 1, self.data.grid_size.w do
for y=1, self.data.grid_size.h 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, (x-1)*self.data.cell_size.w,
(y-1)*self.data.cell_size.h, (y-1)*self.data.cell_size.h,
self.data.cell_size.w, self.data.cell_size.w,
self.data.cell_size.h, self.data.cell_size.h,
tostring((y-1)*self.data.grid_size.w+x), tostring((y-1)*self.data.grid_size.w+x),
"text1","text2") "")
button:onClick(function(self, state, player) button:onClick(function(self, state, player)
local rel = tonumber(self.name) local rel = tonumber(self.name)
local parent_element = state.location.containerElement local parent_element = state.location.containerElement
@ -198,10 +206,12 @@ function buttons_grid:update()
button:setIsHidden(false) button:setIsHidden(false)
button:setItem(entry.item) button:setItem(entry.item)
button:setText("") button:setText("")
button:setTooltip(nil)
elseif entry.image and entry.is_button == true then elseif entry.image and entry.is_button == true then
button:setIsHidden(false) button:setIsHidden(false)
button:setImage(entry.image) button:setImage(entry.image)
button:setText("") button:setText("")
button:setTooltip(entry.tooltip)
-- TODO 1: entry.image to display *.png -- TODO 1: entry.image to display *.png
-- TODO 2: entry.text to display label on button -- TODO 2: entry.text to display label on button
-- TODO 3,4,5: is_button == false to get just pic or label without button -- TODO 3,4,5: is_button == false to get just pic or label without button

View File

@ -217,6 +217,7 @@ smartfs._ldef.inventory = {
player = name, player = name,
_show_ = function(state) _show_ = function(state)
local player = minetest.get_player_by_name(state.location.player) local player = minetest.get_player_by_name(state.location.player)
--print(state:_buildFormspec_(true))
player:set_inventory_formspec(state:_buildFormspec_(true)) player:set_inventory_formspec(state:_buildFormspec_(true))
end end
} }
@ -802,12 +803,12 @@ smartfs.element("button", {
assert(self.data.value, "button needs label") assert(self.data.value, "button needs label")
end, end,
build = function(self) build = function(self)
local specstring local specstring = self:getBackgroundString()
if self.data.image then if self.data.image then
if self.data.closes then if self.data.closes then
specstring = "image_button_exit[" specstring = specstring.."image_button_exit["
else else
specstring = "image_button[" specstring = specstring.."image_button["
end end
elseif self.data.item then elseif self.data.item then
if self.data.closes then if self.data.closes then
@ -826,14 +827,19 @@ smartfs.element("button", {
specstring = specstring .. specstring = specstring ..
self.data.pos.x..","..self.data.pos.y..";".. self.data.pos.x..","..self.data.pos.y..";"..
self.data.size.w..","..self.data.size.h..";" self.data.size.w..","..self.data.size.h..";"
if self.data.image then if self.data.image then
specstring = specstring..self.data.image..";" specstring = specstring..self.data.image..";"
elseif self.data.item then elseif self.data.item then
specstring = specstring..self.data.item..";" specstring = specstring..self.data.item..";"
end end
specstring = specstring..self:getAbsName()..";".. specstring = specstring..self:getAbsName()..";"..
minetest.formspec_escape(self.data.value).."]".. minetest.formspec_escape(self.data.value).."]"
self:getBackgroundString()
if self.data.tooltip then
specstring = specstring.."tooltip["..self:getAbsName()..";"..self.data.tooltip.."]"
end
return specstring return specstring
end, end,
submit = function(self, field, player) submit = function(self, field, player)
@ -872,6 +878,12 @@ smartfs.element("button", {
getItem = function(self) getItem = function(self)
return self.data.item return self.data.item
end, end,
setTooltip = function(self,text)
self.data.tooltip = text
end,
getTooltip = function(self)
return self.data.tooltip
end,
setClose = function(self,bool) setClose = function(self,bool)
self.data.closes = bool self.data.closes = bool
end end