basic HUD for announcements implemented + practical implementation for queues
This commit is contained in:
parent
2e473d9b26
commit
d2e91486ca
5
api.lua
5
api.lua
@ -762,10 +762,13 @@ function arena_lib.remove_player_from_arena(p_name, is_eliminated)
|
||||
-- se l'arena era in coda e ora ci son troppi pochi giocatori, annullo la coda
|
||||
if arena.in_queue then
|
||||
local timer = minetest.get_node_timer(arena.sign)
|
||||
local players_in_arena = arena_lib.get_arena_players_count(arena)
|
||||
|
||||
if arena_lib.get_arena_players_count(arena) < arena.min_players then
|
||||
if players_in_arena < arena.min_players then
|
||||
timer:stop()
|
||||
arena.in_queue = false
|
||||
arena_lib.HUD_send_msg_all("hotbar", arena, arena.name .. " | " .. players_in_arena .. "/" .. arena.max_players ..
|
||||
" | in attesa di più giocatori... (" .. arena.min_players - players_in_arena .. ")")
|
||||
arena_lib.send_message_players_in_arena(arena, mod_ref.prefix .. S("The queue has been cancelled due to not enough players"))
|
||||
end
|
||||
|
||||
|
121
hud.lua
Normal file
121
hud.lua
Normal file
@ -0,0 +1,121 @@
|
||||
local player_huds = {} -- KEY: p_name, INDEX: {HUD_BG_ID, HUD_TXT_ID}
|
||||
|
||||
|
||||
|
||||
function arena_lib.HUD_add(player)
|
||||
|
||||
local HUD_BROADCAST_IMG = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = { x = 0.5, y = 0.2},
|
||||
text = "",
|
||||
scale = { x = 25, y = 2},
|
||||
number = 0xFFFFFF,
|
||||
})
|
||||
|
||||
local HUD_BROADCAST_TXT = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = { x = 0.5, y = 0.2},
|
||||
text = "",
|
||||
scale = { x = 1, y = 1},
|
||||
number = 0xFFFFFF,
|
||||
})
|
||||
|
||||
local HUD_HOTBAR_IMG = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = { x = 0.5, y = 0.89},
|
||||
text = "",
|
||||
scale = { x = 25, y = 1.5},
|
||||
number = 0xFFFFFF,
|
||||
})
|
||||
|
||||
local HUD_HOTBAR_TXT = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = { x = 0.5, y = 0.89},
|
||||
text = "",
|
||||
scale = { x = 1, y = 1},
|
||||
number = 0xFFFFFF,
|
||||
})
|
||||
|
||||
player_huds[player:get_player_name()] = {HUD_BROADCAST_IMG, HUD_BROADCAST_TXT, HUD_HOTBAR_IMG, HUD_HOTBAR_TXT}
|
||||
end
|
||||
|
||||
|
||||
|
||||
function arena_lib.HUD_send_msg(HUD_type, p_name, new_msg)
|
||||
|
||||
local player = minetest.get_player_by_name(p_name)
|
||||
local p_HUD = player_huds[p_name]
|
||||
|
||||
if HUD_type == "broadcast" then
|
||||
player:hud_change(p_HUD[1], "text", "arenalib_hud_bg.png")
|
||||
player:hud_change(p_HUD[2], "text", new_msg)
|
||||
elseif HUD_type == "hotbar" then
|
||||
player:hud_change(p_HUD[3], "text", "arenalib_hud_bg2.png")
|
||||
player:hud_change(p_HUD[4], "text", new_msg)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
function arena_lib.HUD_send_msg_all(HUD_type, arena, new_msg)
|
||||
for pl_name, _ in pairs(arena.players) do
|
||||
|
||||
local pl = minetest.get_player_by_name(pl_name)
|
||||
local pl_HUD = player_huds[pl_name]
|
||||
|
||||
if HUD_type == "broadcast" then
|
||||
pl:hud_change(pl_HUD[1], "text", "arenalib_hud_bg.png")
|
||||
pl:hud_change(pl_HUD[2], "text", new_msg)
|
||||
elseif HUD_type == "hotbar" then
|
||||
pl:hud_change(pl_HUD[3], "text", "arenalib_hud_bg2.png")
|
||||
pl:hud_change(pl_HUD[4], "text", new_msg)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
function arena_lib.HUD_hide(HUD_type, player_or_arena)
|
||||
|
||||
if type(player_or_arena) == "string" then
|
||||
|
||||
local player = minetest.get_player_by_name(player_or_arena)
|
||||
local p_HUD = player_huds[player_or_arena]
|
||||
|
||||
if HUD_type == "broadcast" then
|
||||
player:hud_change(p_HUD[1], "text", "")
|
||||
player:hud_change(p_HUD[2], "text", "")
|
||||
elseif HUD_type == "hotbar" then
|
||||
player:hud_change(p_HUD[3], "text", "")
|
||||
player:hud_change(p_HUD[4], "text", "")
|
||||
elseif HUD_type == "all" then
|
||||
player:hud_change(p_HUD[1], "text", "")
|
||||
player:hud_change(p_HUD[2], "text", "")
|
||||
player:hud_change(p_HUD[3], "text", "")
|
||||
player:hud_change(p_HUD[4], "text", "")
|
||||
end
|
||||
|
||||
elseif type(player_or_arena) == "table" then
|
||||
|
||||
for pl_name, _ in pairs(player_or_arena.players) do
|
||||
|
||||
local pl = minetest.get_player_by_name(pl_name)
|
||||
local pl_HUD = player_huds[pl_name]
|
||||
|
||||
if HUD_type == "broadcast" then
|
||||
pl:hud_change(pl_HUD[1], "text", "")
|
||||
pl:hud_change(pl_HUD[2], "text", "")
|
||||
elseif HUD_type == "hotbar" then
|
||||
pl:hud_change(pl_HUD[3], "text", "")
|
||||
pl:hud_change(pl_HUD[4], "text", "")
|
||||
elseif HUD_type == "all" then
|
||||
pl:hud_change(pl_HUD[1], "text", "")
|
||||
pl:hud_change(pl_HUD[2], "text", "")
|
||||
pl:hud_change(pl_HUD[3], "text", "")
|
||||
pl:hud_change(pl_HUD[4], "text", "")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
1
init.lua
1
init.lua
@ -1,6 +1,7 @@
|
||||
dofile(minetest.get_modpath("arena_lib") .. "/api.lua")
|
||||
dofile(minetest.get_modpath("arena_lib") .. "/callbacks.lua")
|
||||
dofile(minetest.get_modpath("arena_lib") .. "/debug_utilities.lua")
|
||||
dofile(minetest.get_modpath("arena_lib") .. "/hud.lua")
|
||||
dofile(minetest.get_modpath("arena_lib") .. "/items.lua")
|
||||
dofile(minetest.get_modpath("arena_lib") .. "/player_manager.lua")
|
||||
dofile(minetest.get_modpath("arena_lib") .. "/signs.lua")
|
||||
|
@ -1,6 +1,7 @@
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
|
||||
player:set_pos(arena_lib.get_hub_spawn_point())
|
||||
arena_lib.HUD_add(player)
|
||||
|
||||
end)
|
||||
|
||||
|
64
signs.lua
64
signs.lua
@ -4,6 +4,8 @@
|
||||
local S = minetest.get_translator("arena_lib")
|
||||
|
||||
local function in_game_txt(arena) end
|
||||
local function HUD_countdown(arena, seconds) end
|
||||
local function arena_display_format(arena, players_in_arena, msg) end
|
||||
|
||||
|
||||
|
||||
@ -52,14 +54,23 @@ minetest.override_item("default:sign_wall", {
|
||||
sign_arena.players[p_name] = nil
|
||||
arena_lib.update_sign(pos, sign_arena)
|
||||
arena_lib.remove_from_queue(p_name)
|
||||
arena_lib.HUD_hide("all", p_name)
|
||||
minetest.chat_send_player(p_name, mod_ref.prefix .. S("You have left the queue"))
|
||||
arena_lib.send_message_players_in_arena(sign_arena, mod_ref.prefix .. S("@1 has left the queue", p_name))
|
||||
|
||||
local players_in_arena = arena_lib.get_arena_players_count(sign_arena)
|
||||
|
||||
-- ...e la annullo se non ci sono più abbastanza persone
|
||||
if arena_lib.get_arena_players_count(sign_arena) < sign_arena.min_players and sign_arena.in_queue then
|
||||
if players_in_arena < sign_arena.min_players and sign_arena.in_queue then
|
||||
minetest.get_node_timer(pos):stop()
|
||||
arena_lib.HUD_hide("broadcast", sign_arena)
|
||||
arena_lib.HUD_send_msg_all("hotbar", sign_arena, arena_display_format(sign_arena, players_in_arena, "in attesa di più giocatori... ") ..
|
||||
"(" .. sign_arena.min_players - players_in_arena .. ")")
|
||||
arena_lib.send_message_players_in_arena(sign_arena, mod_ref.prefix .. S("The queue has been cancelled due to not enough players"))
|
||||
sign_arena.in_queue = false
|
||||
else
|
||||
-- (il numero giocatori è cambiato, per questo aggiorno)
|
||||
arena_lib.HUD_send_msg_all("hotbar", sign_arena, arena_display_format(sign_arena, players_in_arena,"Preparati!"))
|
||||
end
|
||||
|
||||
return
|
||||
@ -74,9 +85,14 @@ minetest.override_item("default:sign_wall", {
|
||||
arena_lib.update_sign(old_arena.sign, old_arena)
|
||||
arena_lib.send_message_players_in_arena(old_arena, old_mod_ref.prefix .. S("@1 has left the queue", p_name))
|
||||
|
||||
local players_in_arena = arena_lib.get_arena_players_count(old_arena)
|
||||
|
||||
-- annullando la coda della precedente se non ci sono più abbastanza giocatori
|
||||
if arena_lib.get_arena_players_count(old_arena) < old_arena.min_players and old_arena.in_queue then
|
||||
if players_in_arena < old_arena.min_players and old_arena.in_queue then
|
||||
minetest.get_node_timer(old_arena.sign):stop()
|
||||
arena_lib.HUD_hide("broadcast", old_arena)
|
||||
arena_lib.HUD_send_msg_all("hotbar", old_arena, arena_display_format(old_arena, players_in_arena, "in attesa di più giocatori... ") ..
|
||||
"(" .. old_arena.min_players - players_in_arena .. ")")
|
||||
arena_lib.send_message_players_in_arena(old_arena, old_mod_ref.prefix .. S("The queue has been cancelled due to not enough players"))
|
||||
old_arena.in_queue = false
|
||||
end
|
||||
@ -107,14 +123,23 @@ minetest.override_item("default:sign_wall", {
|
||||
local timer = minetest.get_node_timer(pos)
|
||||
|
||||
-- se ci sono abbastanza giocatori, parte il timer di attesa
|
||||
if arena_lib.get_arena_players_count(sign_arena) == sign_arena.min_players and not sign_arena.in_queue and not sign_arena.in_game then
|
||||
arena_lib.send_message_players_in_arena(sign_arena, mod_ref.prefix .. S("The game begins in @1 seconds!", mod_ref.queue_waiting_time))
|
||||
sign_arena.in_queue = true
|
||||
timer:start(mod_ref.queue_waiting_time)
|
||||
if not sign_arena.in_queue and not sign_arena.in_game then
|
||||
|
||||
local players_in_arena = arena_lib.get_arena_players_count(sign_arena)
|
||||
|
||||
if players_in_arena == sign_arena.min_players then
|
||||
sign_arena.in_queue = true
|
||||
timer:start(mod_ref.queue_waiting_time)
|
||||
HUD_countdown(sign_arena, players_in_arena, mod_ref.queue_waiting_time)
|
||||
elseif players_in_arena < sign_arena.min_players then
|
||||
arena_lib.HUD_send_msg("hotbar", p_name, arena_display_format(sign_arena, players_in_arena, " in attesa di più giocatori... ") ..
|
||||
"(" .. sign_arena.min_players - players_in_arena .. ")")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- se raggiungo i giocatori massimi e la partita non è iniziata, parte subito
|
||||
if arena_lib.get_arena_players_count(sign_arena) == sign_arena.max_players and sign_arena.in_queue then
|
||||
if players_in_arena == sign_arena.max_players and sign_arena.in_queue then
|
||||
timer:stop()
|
||||
timer:start(0.01)
|
||||
end
|
||||
@ -134,6 +159,7 @@ minetest.override_item("default:sign_wall", {
|
||||
sign_arena.in_game = true
|
||||
arena_lib.update_sign(pos, sign_arena)
|
||||
|
||||
arena_lib.HUD_hide("all", sign_arena)
|
||||
arena_lib.load_arena(mod, arena_ID)
|
||||
|
||||
return false
|
||||
@ -187,6 +213,30 @@ end
|
||||
---------------FUNZIONI LOCALI----------------
|
||||
----------------------------------------------
|
||||
|
||||
function HUD_countdown(arena, players_in_arena, seconds)
|
||||
if not arena.in_queue or seconds == 0 then return end
|
||||
|
||||
-- dai 3 secondi in giù il messaggio è stampato su broadcast
|
||||
if seconds <= 3 then
|
||||
arena_lib.HUD_send_msg_all("broadcast", arena, S("The game begins in @1 seconds!", seconds))
|
||||
arena_lib.HUD_send_msg_all("hotbar", arena, arena_display_format(arena, players_in_arena, "Preparati!"))
|
||||
else
|
||||
arena_lib.HUD_send_msg_all("hotbar", arena, arena_display_format(arena, players_in_arena, "" .. seconds .. " secondi all'inzio"))
|
||||
end
|
||||
|
||||
minetest.after(1, function()
|
||||
HUD_countdown(arena, players_in_arena, seconds-1)
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
-- es. Foresta | 3/4 | Il match inizierà a breve
|
||||
function arena_display_format(arena, players_in_arena, msg)
|
||||
return arena.name .. " | " .. players_in_arena .. "/" .. arena.max_players .. " | " .. msg
|
||||
end
|
||||
|
||||
|
||||
|
||||
function in_game_txt(arena)
|
||||
local txt
|
||||
|
||||
|
BIN
textures/arenalib_hud_bg.png
Normal file
BIN
textures/arenalib_hud_bg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 99 B |
BIN
textures/arenalib_hud_bg2.png
Normal file
BIN
textures/arenalib_hud_bg2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 99 B |
Loading…
x
Reference in New Issue
Block a user