Attempt to create "fancy" hotbar.
Seems this doesn't actually work. The hotbar image MUST be a physical file, and cannot use any texture modifiers, so sayeth the engine.
@ -12,8 +12,8 @@ local irradiated = modname .. ":irradiated"
|
||||
minetest.register_craftitem(irradiated, {
|
||||
description = "Burn",
|
||||
stack_max = 1,
|
||||
inventory_image = modname .. "_base.png^[mask:"
|
||||
.. modname .. "_icon_mask.png",
|
||||
inventory_image = "[combine:1x1",
|
||||
hotbar_type = "burn",
|
||||
wield_image = hand.wield_image,
|
||||
wield_scale = hand.wield_scale,
|
||||
on_drop = function(stack) return stack end,
|
||||
|
@ -10,7 +10,8 @@ local injured = modname .. ":injured"
|
||||
minetest.register_craftitem(injured, {
|
||||
description = "Injury",
|
||||
stack_max = 1,
|
||||
inventory_image = modname .. "_injured.png",
|
||||
inventory_image = "[combine:1x1",
|
||||
hotbar_type = "injury",
|
||||
wield_image = hand.wield_image,
|
||||
wield_scale = hand.wield_scale,
|
||||
on_drop = function(stack) return stack end,
|
||||
|
@ -1,10 +1,12 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local math, minetest, nodecore, pairs
|
||||
= math, minetest, nodecore, pairs
|
||||
local math, minetest, nodecore
|
||||
= math, minetest, nodecore
|
||||
local math_floor
|
||||
= math.floor
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local hotbar_slots = 8
|
||||
|
||||
local function breathimg(br)
|
||||
local o = 255 * (1 - br / 11)
|
||||
if o == 0 then return "" end
|
||||
@ -34,11 +36,51 @@ end
|
||||
minetest.register_on_priv_grant(grantrevoke)
|
||||
minetest.register_on_priv_revoke(grantrevoke)
|
||||
|
||||
local hotbars = {}
|
||||
|
||||
local bar_scale = 32
|
||||
local function sethotbar(player)
|
||||
local bar = "[combine:" .. (hotbar_slots * bar_scale) .. "x" .. bar_scale
|
||||
local sel = "nc_player_hud_sel"
|
||||
local inv = player:get_inventory()
|
||||
for i = 1, hotbar_slots do
|
||||
local img = "nc_player_hud_bar"
|
||||
local stack = inv:get_stack("main", i)
|
||||
local def = stack and (not stack:is_empty()) and stack:get_definition()
|
||||
if def and def.hotbar_type then
|
||||
img = img .. "_" .. def.hotbar_type
|
||||
if i == player:get_wield_index() then
|
||||
sel = sel .. "_" .. def.hotbar_type
|
||||
end
|
||||
end
|
||||
bar = bar .. ":" .. (i * bar_scale - bar_scale) .. ",0=" .. img
|
||||
.. ".png"--\\^[resize\\:" .. bar_scale .. "x" .. bar_scale
|
||||
end
|
||||
sel = sel .. ".png^[resize:" .. bar_scale .. "x" .. bar_scale
|
||||
|
||||
local pname = player:get_player_name()
|
||||
local old = hotbars[pname]
|
||||
if not old then
|
||||
old = {}
|
||||
hotbars[pname] = old
|
||||
end
|
||||
if old.bar ~= bar then
|
||||
player:hud_set_hotbar_image(bar)
|
||||
old.bar = bar
|
||||
end
|
||||
if old.sel ~= sel then
|
||||
player:hud_set_hotbar_selected_image(sel)
|
||||
old.sel = sel
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
hotbars[player:get_player_name()] = nil
|
||||
end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
sethudflags(player)
|
||||
player:hud_set_hotbar_itemcount(8)
|
||||
player:hud_set_hotbar_image("nc_player_hud_bar.png")
|
||||
player:hud_set_hotbar_selected_image("nc_player_hud_sel.png")
|
||||
sethotbar(player)
|
||||
|
||||
if not minetest.settings:get_bool("enable_damage") then
|
||||
player:set_breath(11)
|
||||
@ -61,5 +103,6 @@ minetest.register_globalstep(function()
|
||||
label = "breath",
|
||||
text = breathimg(player:get_breath())
|
||||
})
|
||||
sethotbar(player)
|
||||
end
|
||||
end)
|
||||
|
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 1.3 KiB |
BIN
mods/nc_player_hud/textures/nc_player_hud_bar_burn.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
mods/nc_player_hud/textures/nc_player_hud_bar_injury.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.6 KiB |
BIN
mods/nc_player_hud/textures/nc_player_hud_sel_burn.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
mods/nc_player_hud/textures/nc_player_hud_sel_injury.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 90 KiB After Width: | Height: | Size: 58 KiB |