145 lines
3.2 KiB
Lua
145 lines
3.2 KiB
Lua
local saved_huds = {} -- pl_name = {hud_name = id}
|
|
|
|
|
|
function fbrawl.generate_HUD(arena, pl_name)
|
|
local player = minetest.get_player_by_name(pl_name)
|
|
|
|
local stats_bg
|
|
local kills
|
|
local deaths
|
|
local status_pointer
|
|
local waypoint
|
|
|
|
stats_bg = player:hud_add({
|
|
hud_elem_type = "image",
|
|
position = {x = 1, y = 0.5},
|
|
offset = {x = -25*3 + -25*2/3, y = 0},
|
|
text = "fbrawl_hud_stats.png",
|
|
alignment = { x = 1, y=0.5},
|
|
scale = { x = 3, y = 3},
|
|
number = 0xFFFFFF,
|
|
})
|
|
|
|
kills = player:hud_add({
|
|
hud_elem_type = "text",
|
|
position = {x = 1, y = 0.5},
|
|
offset = {x = -53, y = 27},
|
|
text = 0,
|
|
number = 0xFFFFFF,
|
|
})
|
|
|
|
deaths = player:hud_add({
|
|
hud_elem_type = "text",
|
|
position = {x = 1, y = 0.5},
|
|
offset = {x = -53, y = 107.5},
|
|
text = 0,
|
|
number = 0xFFFFFF,
|
|
})
|
|
|
|
status_pointer = player:hud_add({
|
|
name = "pointer_status",
|
|
hud_elem_type = "image",
|
|
text = "fbrawl_transparent.png",
|
|
position = {x=0.5, y=0.5},
|
|
offset = {x=-18.75, y = 0},
|
|
scale = {x=2.5, y=2.5},
|
|
alignment = {x=0.5, y=0.5},
|
|
})
|
|
|
|
waypoint = player:hud_add({
|
|
name = "waypoint",
|
|
hud_elem_type = "image_waypoint",
|
|
text = "fbrawl_smash_item.png",
|
|
scale = {x=0, y=0},
|
|
size = {x=1, y=1},
|
|
})
|
|
|
|
saved_huds[pl_name] = {
|
|
stats_bg = stats_bg,
|
|
kills = kills,
|
|
deaths = deaths,
|
|
status_pointer = status_pointer,
|
|
waypoint = waypoint
|
|
}
|
|
end
|
|
|
|
|
|
|
|
function fbrawl.update_hud(pl_name, field, new_value)
|
|
if saved_huds[pl_name] and saved_huds[pl_name][field] then
|
|
local player = minetest.get_player_by_name(pl_name)
|
|
player:hud_change(saved_huds[pl_name][field], "text", new_value)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
function fbrawl.remove_huds(pl_name)
|
|
minetest.after(1, function()
|
|
local player = minetest.get_player_by_name(pl_name)
|
|
|
|
if not player or not saved_huds[pl_name] then return end
|
|
|
|
for name, id in pairs(saved_huds[pl_name]) do
|
|
player:hud_remove(id)
|
|
end
|
|
|
|
saved_huds[pl_name] = {}
|
|
end)
|
|
end
|
|
|
|
|
|
|
|
function fbrawl.add_temp_hud(pl_name, hud, time)
|
|
local player = minetest.get_player_by_name(pl_name)
|
|
|
|
hud = player:hud_add(hud)
|
|
saved_huds[pl_name] = saved_huds[pl_name] or {}
|
|
saved_huds[pl_name][tostring(hud)] = hud
|
|
|
|
minetest.after(time, function()
|
|
-- Removing the hud if the player still has it.
|
|
if saved_huds[pl_name] and saved_huds[pl_name][tostring(hud)] then
|
|
player:hud_remove(hud)
|
|
saved_huds[pl_name][tostring(hud)] = nil
|
|
end
|
|
end)
|
|
|
|
return hud
|
|
end
|
|
|
|
|
|
|
|
function fbrawl.add_hud(pl_name, name, def)
|
|
local player = minetest.get_player_by_name(pl_name)
|
|
|
|
if not player then return end
|
|
|
|
local hud = player:hud_add(def)
|
|
saved_huds[pl_name] = saved_huds[pl_name] or {}
|
|
saved_huds[pl_name][name] = hud
|
|
|
|
return hud
|
|
end
|
|
|
|
|
|
|
|
function fbrawl.remove_hud(pl_name, name)
|
|
local player = minetest.get_player_by_name(pl_name)
|
|
|
|
if not player or not saved_huds[pl_name] or not saved_huds[pl_name][name] then return end
|
|
|
|
player:hud_remove(saved_huds[pl_name][name])
|
|
|
|
saved_huds[pl_name][name] = nil
|
|
end
|
|
|
|
|
|
|
|
function fbrawl.get_hud(pl_name, name)
|
|
local player = minetest.get_player_by_name(pl_name)
|
|
|
|
if not player or not saved_huds[pl_name] or not saved_huds[pl_name][name] then return end
|
|
|
|
return saved_huds[pl_name][name]
|
|
end |