forked from Mirrorlandia_minetest/minetest
DevTest: Refactor testhud features
This commit is contained in:
parent
c761aa268d
commit
0152d39215
@ -1,6 +1,6 @@
|
|||||||
local player_huds = {}
|
local player_font_huds = {}
|
||||||
|
|
||||||
local states = {
|
local font_states = {
|
||||||
{0, "Normal font"},
|
{0, "Normal font"},
|
||||||
{1, "Bold font"},
|
{1, "Bold font"},
|
||||||
{2, "Italic font"},
|
{2, "Italic font"},
|
||||||
@ -11,79 +11,75 @@ local states = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
local default_def = {
|
local font_default_def = {
|
||||||
hud_elem_type = "text",
|
hud_elem_type = "text",
|
||||||
position = {x = 0.5, y = 0.5},
|
position = {x = 0.5, y = 0.5},
|
||||||
scale = {x = 2, y = 2},
|
scale = {x = 2, y = 2},
|
||||||
alignment = { x = 0, y = 0 },
|
alignment = { x = 0, y = 0 },
|
||||||
|
number = 0xFFFFFF,
|
||||||
}
|
}
|
||||||
|
|
||||||
local function add_hud(player, state)
|
local function add_font_hud(player, state)
|
||||||
local def = table.copy(default_def)
|
local def = table.copy(font_default_def)
|
||||||
local statetbl = states[state]
|
local statetbl = font_states[state]
|
||||||
def.offset = {x = 0, y = 32 * state}
|
def.offset = {x = 0, y = 32 * state}
|
||||||
def.style = statetbl[1]
|
def.style = statetbl[1]
|
||||||
def.text = statetbl[2]
|
def.text = statetbl[2]
|
||||||
return player:hud_add(def)
|
return player:hud_add(def)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
local font_etime = 0
|
||||||
player_huds[player:get_player_name()] = nil
|
local font_state = 0
|
||||||
player_waypoints[player:get_player_name()] = nil
|
|
||||||
end)
|
|
||||||
|
|
||||||
local etime = 0
|
|
||||||
local state = 0
|
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
etime = etime + dtime
|
font_etime = font_etime + dtime
|
||||||
if etime < 1 then
|
if font_etime < 1 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
etime = 0
|
font_etime = 0
|
||||||
for _, player in ipairs(minetest.get_connected_players()) do
|
for _, player in ipairs(minetest.get_connected_players()) do
|
||||||
local huds = player_huds[player:get_player_name()]
|
local huds = player_font_huds[player:get_player_name()]
|
||||||
if huds then
|
if huds then
|
||||||
for i, hud_id in ipairs(huds) do
|
for i, hud_id in ipairs(huds) do
|
||||||
local statetbl = states[(state + i) % #states + 1]
|
local statetbl = font_states[(font_state + i) % #font_states + 1]
|
||||||
player:hud_change(hud_id, "style", statetbl[1])
|
player:hud_change(hud_id, "style", statetbl[1])
|
||||||
player:hud_change(hud_id, "text", statetbl[2])
|
player:hud_change(hud_id, "text", statetbl[2])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
state = state + 1
|
font_state = font_state + 1
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_chatcommand("hudfonts", {
|
minetest.register_chatcommand("hudfonts", {
|
||||||
params = "",
|
params = "[<HUD elements>]",
|
||||||
description = "Show/Hide some text on the HUD with various font options",
|
description = "Show/Hide some text on the HUD with various font options",
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
local param = tonumber(param) or 0
|
local param = tonumber(param) or 0
|
||||||
param = math.min(math.max(param, 1), #states)
|
param = math.min(math.max(param, 1), #font_states)
|
||||||
if player_huds[name] == nil then
|
if player_font_huds[name] == nil then
|
||||||
player_huds[name] = {}
|
player_font_huds[name] = {}
|
||||||
for i = 1, param do
|
for i = 1, param do
|
||||||
table.insert(player_huds[name], add_hud(player, i))
|
table.insert(player_font_huds[name], add_font_hud(player, i))
|
||||||
end
|
end
|
||||||
minetest.chat_send_player(name, ("%d HUD element(s) added."):format(param))
|
minetest.chat_send_player(name, ("%d text HUD element(s) added."):format(param))
|
||||||
else
|
else
|
||||||
local huds = player_huds[name]
|
local huds = player_font_huds[name]
|
||||||
if huds then
|
if huds then
|
||||||
for _, hud_id in ipairs(huds) do
|
for _, hud_id in ipairs(huds) do
|
||||||
player:hud_remove(hud_id)
|
player:hud_remove(hud_id)
|
||||||
end
|
end
|
||||||
minetest.chat_send_player(name, "All HUD elements removed.")
|
minetest.chat_send_player(name, "All text HUD elements removed.")
|
||||||
end
|
end
|
||||||
player_huds[name] = nil
|
player_font_huds[name] = nil
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
local player_waypoints = {}
|
-- Testing waypoint capabilities
|
||||||
|
|
||||||
-- Use this to test waypoint capabilities
|
local player_waypoints = {}
|
||||||
minetest.register_chatcommand("hudwaypoints", {
|
minetest.register_chatcommand("hudwaypoints", {
|
||||||
params = "[ add | add_change | remove ]",
|
params = "[ add | add_change | remove ]",
|
||||||
description = "Create HUD waypoints at your position for testing (add: Add waypoints and change them after 0.5s (default). add_change: Add waypoints and change immediately. remove: Remove all waypoints)",
|
description = "Create HUD waypoints at your position for testing (add: Add waypoints and change them after 0.5s (default). add_change: Add waypoints and change immediately. remove: Remove all waypoints)",
|
||||||
@ -99,7 +95,7 @@ minetest.register_chatcommand("hudwaypoints", {
|
|||||||
end
|
end
|
||||||
player_waypoints[name] = {}
|
player_waypoints[name] = {}
|
||||||
end
|
end
|
||||||
return true, "Waypoints removed."
|
return true, "All waypoint HUD elements removed."
|
||||||
end
|
end
|
||||||
if not (params == "add_change" or params == "add" or params == "") then
|
if not (params == "add_change" or params == "add" or params == "") then
|
||||||
-- Incorrect syntax
|
-- Incorrect syntax
|
||||||
@ -183,9 +179,6 @@ minetest.register_chatcommand("hudwaypoints", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
|
||||||
end)
|
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
player:set_properties({zoom_fov = 15})
|
player:set_properties({zoom_fov = 15})
|
||||||
end)
|
end)
|
||||||
@ -211,3 +204,8 @@ minetest.register_chatcommand("zoomfov", {
|
|||||||
return true, "zoom_fov = "..tostring(fov)
|
return true, "zoom_fov = "..tostring(fov)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
player_font_huds[player:get_player_name()] = nil
|
||||||
|
player_waypoints[player:get_player_name()] = nil
|
||||||
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user