Redesign UI and add some kind of API
This commit is contained in:
parent
04c955993f
commit
8e2a7c9f0e
2 changed files with 40 additions and 23 deletions
63
init.lua
63
init.lua
|
@ -1,40 +1,57 @@
|
||||||
local playerlist = {}
|
local playerlist = {
|
||||||
|
huds = {}
|
||||||
|
}
|
||||||
|
|
||||||
controls.register_on_press(function(player, key)
|
function playerlist.iterator()
|
||||||
|
return ipairs(minetest.get_connected_players())
|
||||||
|
end
|
||||||
|
|
||||||
|
function playerlist.count()
|
||||||
|
return #minetest.get_connected_players()
|
||||||
|
end
|
||||||
|
|
||||||
|
controls.register_on_press(function(user, key)
|
||||||
if key == "sneak" then
|
if key == "sneak" then
|
||||||
local name = player:get_player_name()
|
local user_name = user:get_player_name()
|
||||||
local list = {}
|
local huds = {user:hud_add({
|
||||||
local players = minetest.get_connected_players()
|
hud_elem_type = "image",
|
||||||
for i, p in pairs(players) do
|
position = {x = 0.5, y = 0},
|
||||||
local n = p:get_player_name()
|
offset = {x = 0, y = 20},
|
||||||
local ping = math.max(1, math.ceil(4 - minetest.get_player_information(n).avg_rtt * 4))
|
text = "playerlist_background.png",
|
||||||
list[#list + 1] = player:hud_add({
|
alignment = {x = 0, y = 1},
|
||||||
|
scale = {x = 400, y = playerlist.count() * 18 + 8},
|
||||||
|
number = 0xFFFFFF,
|
||||||
|
})}
|
||||||
|
for i, player, color, text in playerlist.iterator() do
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local ping = math.max(1, math.ceil(4 - minetest.get_player_information(name).avg_rtt * 50))
|
||||||
|
table.insert(huds, user:hud_add({
|
||||||
hud_elem_type = "text",
|
hud_elem_type = "text",
|
||||||
position = {x = 0.5, y = 0},
|
position = {x = 0.5, y = 0},
|
||||||
offset = {x = 20, y = 53 + (i - 1) * 18},
|
offset = {x = 0, y = 23 + (i - 1) * 18},
|
||||||
text = n,
|
text = text or name,
|
||||||
alignment = {x = 1, y = 1},
|
alignment = {x = 0, y = 1},
|
||||||
scale = {x = 100, y = 100},
|
scale = {x = 100, y = 100},
|
||||||
number = 0xFFFFFF,
|
number = color or 0xFFFFFF,
|
||||||
})
|
}))
|
||||||
list[#list + 1] = player:hud_add({
|
table.insert(huds, user:hud_add({
|
||||||
hud_elem_type = "image",
|
hud_elem_type = "image",
|
||||||
position = {x = 0.5, y = 0},
|
position = {x = 0.5, y = 0},
|
||||||
offset = {x = 0, y = 50 + (i - 1) * 18},
|
offset = {x = -195, y = 20 + (i - 1) * 18},
|
||||||
text = "server_ping_" .. ping .. ".png",
|
text = "server_ping_" .. ping .. ".png",
|
||||||
alignment = {x = -1, y = 1},
|
alignment = {x = 1, y = 1},
|
||||||
scale = {x = 1.5, y = 1.5},
|
scale = {x = 1.5, y = 1.5},
|
||||||
number = 0xFFFFFF,
|
number = 0xFFFFFF,
|
||||||
})
|
}))
|
||||||
end
|
end
|
||||||
playerlist[name] = list
|
playerlist.huds[user_name] = huds
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
controls.register_on_release(function(player, key)
|
controls.register_on_release(function(user, key)
|
||||||
if key == "sneak" and player then
|
if key == "sneak" and user then
|
||||||
for _, id in pairs(playerlist[player:get_player_name()]) do
|
for _, id in pairs(playerlist.huds[user:get_player_name()]) do
|
||||||
player:hud_remove(id)
|
user:hud_remove(id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
BIN
textures/playerlist_background.png
Normal file
BIN
textures/playerlist_background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 565 B |
Loading…
Reference in a new issue