Move hud text on new HUD API
parent
a66b108713
commit
9a7b7e2333
|
@ -37,11 +37,6 @@ function hud.register(name, def)
|
|||
return false
|
||||
end
|
||||
|
||||
--TODO: allow other elements
|
||||
if def.hud_elem_type ~= "statbar" then
|
||||
throw_error("The given HUD element is no statbar")
|
||||
return false
|
||||
end
|
||||
if items[name] ~= nil then
|
||||
throw_error("A statbar with that name already exists")
|
||||
return false
|
||||
|
@ -49,7 +44,7 @@ function hud.register(name, def)
|
|||
|
||||
-- actually register
|
||||
-- add background first since draworder is based on id :\
|
||||
if def.hud_elem_type == "statbar" and def.background ~= nil then
|
||||
if --[[def.hud_elem_type == "statbar" and]] def.background ~= nil then
|
||||
sb_bg[name] = table.copy(def)
|
||||
sb_bg[name].text = def.background
|
||||
if not def.autohide_bg and def.max then
|
||||
|
|
|
@ -6,27 +6,25 @@ local health_bar_definition = {}
|
|||
if enable_damage then
|
||||
hud.register("health", {
|
||||
hud_elem_type = "statbar",
|
||||
position = {x = 0.5, y = 1},
|
||||
text = "heart.png",
|
||||
number = 20,
|
||||
direction = 0,
|
||||
alignment = {x = -1, y = -1},
|
||||
size = {x = 24, y = 24},
|
||||
offset = {x = -249, y = -109},
|
||||
background = "heart_bg.png",
|
||||
position = {x = 0.5, y = 1},
|
||||
alignment = {x = -1, y = -1},
|
||||
offset = {x = -247, y = -108},
|
||||
size = {x = 24, y = 24},
|
||||
text = "heart.png",
|
||||
background = "heart_bg.png",
|
||||
number = 20,
|
||||
})
|
||||
end
|
||||
|
||||
local breath_bar_definition =
|
||||
{
|
||||
hud_elem_type = "statbar",
|
||||
position = {x = 0.5, y = 1},
|
||||
text = "bubble.png",
|
||||
number = 20,
|
||||
direction = 0,
|
||||
alignment = {x = -1, y = -1},
|
||||
size = {x = 24, y = 24},
|
||||
offset = {x = 8, y = -134},
|
||||
position = {x = 0.5, y = 1},
|
||||
alignment = {x = -1, y = -1},
|
||||
offset = {x = 10, y = -134},
|
||||
size = {x = 24, y = 24},
|
||||
text = "bubble.png",
|
||||
number = 20,
|
||||
}
|
||||
|
||||
local hud_ids = {}
|
||||
|
@ -171,23 +169,20 @@ core.register_playerevent(player_event_handler)
|
|||
|
||||
-- Hud Item name
|
||||
|
||||
local hud, timer, wield = {}, {}, {}
|
||||
local timer, wield = {}, {}
|
||||
local timeout = 2
|
||||
|
||||
local function add_text(player)
|
||||
local player_name = player:get_player_name()
|
||||
hud[player_name] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = {x = 0.5, y = 0.91},
|
||||
offset = {x = 0, y = -25},
|
||||
alignment = {x = 0, y = 0},
|
||||
number = 0xFFFFFF,
|
||||
})
|
||||
end
|
||||
hud.register("itemname", {
|
||||
hud_elem_type = "text",
|
||||
position = {x = 0.5, y = 1},
|
||||
alignment = {x = 0, y = -10},
|
||||
offset = {x = 0, y = -50},
|
||||
number = 0xFFFFFF,
|
||||
text = ""
|
||||
})
|
||||
|
||||
core.register_on_joinplayer(function(player)
|
||||
initialize_builtin_statbars(player)
|
||||
core.after(1, add_text, player)
|
||||
end)
|
||||
|
||||
core.register_globalstep(function(dtime)
|
||||
|
@ -202,13 +197,13 @@ core.register_globalstep(function(dtime)
|
|||
timer[player_name] = timer[player_name] and timer[player_name] + dtime or 0
|
||||
wield[player_name] = wield[player_name] or ""
|
||||
|
||||
if timer[player_name] > timeout and hud[player_name] then
|
||||
player:hud_change(hud[player_name], "text", "")
|
||||
if timer[player_name] > timeout and player then
|
||||
hud.change_item(player, "itemname", {text = ""})
|
||||
timer[player_name] = 0
|
||||
return
|
||||
end
|
||||
|
||||
if hud[player_name] and wielded_item_name ~= wield[player_name] then
|
||||
if player and wielded_item_name ~= wield[player_name] then
|
||||
wield[player_name] = wielded_item_name
|
||||
timer[player_name] = 0
|
||||
|
||||
|
@ -220,7 +215,7 @@ core.register_globalstep(function(dtime)
|
|||
local description = meta_desc ~= "" and meta_desc or
|
||||
(def and (def.description:match("(.-)\n") or def.description) or "")
|
||||
|
||||
player:hud_change(hud[player_name], "text", description)
|
||||
hud.change_item(player, "itemname", {text = description})
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
|
|
@ -26,14 +26,14 @@ if minetest.settings:get_bool("enable_damage") then
|
|||
|
||||
hud.register("armor", {
|
||||
hud_elem_type = "statbar",
|
||||
position = {x = 0.5, y = 1},
|
||||
size = {x = 24, y = 24},
|
||||
text = "3d_armor_statbar_fg.png",
|
||||
number = 0,
|
||||
alignment = {x = -1, y = -1},
|
||||
offset = {x = -249, y = -134},
|
||||
background = "3d_armor_statbar_bg.png",
|
||||
autohide_bg = true,
|
||||
max = 20,
|
||||
position = {x = 0.5, y = 1},
|
||||
alignment = {x = -1, y = -1},
|
||||
offset = {x = -247, y = -134},
|
||||
size = {x = 24, y = 24},
|
||||
text = "3d_armor_statbar_fg.png",
|
||||
background = "3d_armor_statbar_bg.png",
|
||||
number = 0,
|
||||
max = 20,
|
||||
autohide_bg = true,
|
||||
})
|
||||
end
|
|
@ -38,29 +38,39 @@ end
|
|||
|
||||
hud.register("xp_bar", {
|
||||
hud_elem_type = "statbar",
|
||||
position = {x = 0.5, y = 1},
|
||||
position = {x = 0.5, y = 1},
|
||||
alignment = {x = -1, y = -1},
|
||||
offset = {x = -184, y = -59},
|
||||
offset = {x = -246, y = -79},
|
||||
size = {x = 31, y = 14},
|
||||
text = "expbar_full.png",
|
||||
background = "expbar_empty.png",
|
||||
number = MAX_HUD_XP,
|
||||
number = 0,
|
||||
max = MAX_HUD_XP,
|
||||
})
|
||||
|
||||
hud.register("zlvl", {
|
||||
hud_elem_type = "text",
|
||||
position = {x = 0.5, y = 0.966},
|
||||
alignment = {x = 0, y = -1},
|
||||
offset = {x = 0, y = -50},
|
||||
number = 0x3cff00,
|
||||
text = "0",
|
||||
})
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
init_data(player)
|
||||
|
||||
_hud[name] = {
|
||||
_hud[name] = {}
|
||||
-- level number
|
||||
lvl = player:hud_add({
|
||||
--[[ lvl = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = {x = 0.5, y = 0.91},
|
||||
offset = {x = 0, y = -25},
|
||||
alignment = {x = 0, y = 0},
|
||||
number = 0x3cff00,
|
||||
text = "",
|
||||
})
|
||||
}
|
||||
}) ]]
|
||||
end)
|
||||
|
||||
function experience.add_orb(amount, pos)
|
||||
|
@ -147,9 +157,10 @@ minetest.register_globalstep(function(dtime)
|
|||
|
||||
hud.change_item(player, "xp_bar", {number = xp[name].xp_bar})
|
||||
|
||||
player:hud_change(_hud[name].lvl, "text", xp[name].level)
|
||||
--player:hud_change(_hud[name].lvl, "offset",
|
||||
-- {x = (xp[name].level >= 10 and 13 or 6), y = -202})
|
||||
-- player:hud_change(_hud[name].lvl, "text", xp[name].level)
|
||||
hud.change_item(player, "zlvl", {text = xp[name].level})
|
||||
-- player:hud_change(_hud[name].lvl, "offset",
|
||||
-- {x = (xp[name].level >= 10 and 13 or 6), y = -202})
|
||||
end
|
||||
end)
|
||||
|
||||
|
|
|
@ -23,14 +23,13 @@ if minetest.settings:get_bool("enable_damage") then
|
|||
|
||||
hud.register("hunger", {
|
||||
hud_elem_type = "statbar",
|
||||
position = {x = 0.5, y = 1},
|
||||
size = {x = 24, y = 24},
|
||||
text = "hunger_statbar_fg.png",
|
||||
number = 20,
|
||||
alignment = {x = -1, y = -1},
|
||||
offset = {x = 8, y = -109},
|
||||
background = "hunger_statbar_bg.png",
|
||||
max = 20,
|
||||
position = {x = 0.5, y = 1},
|
||||
alignment = {x = -1, y = -1},
|
||||
offset = {x = 8, y = -108},
|
||||
size = {x = 24, y = 24},
|
||||
text = "hunger_statbar_fg.png",
|
||||
background = "hunger_statbar_bg.png",
|
||||
number = 20,
|
||||
})
|
||||
|
||||
local modpath = minetest.get_modpath("hunger")
|
||||
|
|
Loading…
Reference in New Issue