Create ctf_colors, clean up hud
This commit is contained in:
parent
8f1b6c7abd
commit
4d00a8cf1d
@ -1 +1,2 @@
|
|||||||
chatplus?
|
chatplus?
|
||||||
|
hudkit
|
||||||
|
45
ctf/gui.lua
45
ctf/gui.lua
@ -199,29 +199,6 @@ ctf.gui.register_tab("diplo", "Diplomacy", function(name, team)
|
|||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Team interface
|
|
||||||
ctf.gui.register_tab("settings", "Settings", function(name, team)
|
|
||||||
local color = ""
|
|
||||||
|
|
||||||
if ctf.team(team).data.color then
|
|
||||||
color = ctf.team(team).data.color
|
|
||||||
end
|
|
||||||
|
|
||||||
local result = "field[3,2;4,1;color;Team Color;" .. color .. "]" ..
|
|
||||||
"button[4,6;2,1;save;Save]"
|
|
||||||
|
|
||||||
|
|
||||||
if not ctf.can_mod(name,team) then
|
|
||||||
result = "label[0.5,1;You do not own this team!"
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.show_formspec(name, "ctf:settings",
|
|
||||||
"size[10,7]" ..
|
|
||||||
ctf.gui.get_tabs(name, team) ..
|
|
||||||
result
|
|
||||||
)
|
|
||||||
end)
|
|
||||||
|
|
||||||
local function formspec_is_ctf_tab(fsname)
|
local function formspec_is_ctf_tab(fsname)
|
||||||
for name, tab in pairs(ctf.gui.tabs) do
|
for name, tab in pairs(ctf.gui.tabs) do
|
||||||
if fsname == "ctf:" .. name then
|
if fsname == "ctf:" .. name then
|
||||||
@ -261,28 +238,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
ctf.gui.show(name, "news")
|
ctf.gui.show(name, "news")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Settings page
|
|
||||||
if fields.save and formname == "ctf:settings" then
|
|
||||||
ctf.gui.show(name, "settings")
|
|
||||||
|
|
||||||
if ctf.flag_colors[fields.color] then
|
|
||||||
team.data.color = fields.color
|
|
||||||
ctf.needs_save = true
|
|
||||||
else
|
|
||||||
local colors = ""
|
|
||||||
for color, code in pairs(ctf.flag_colors) do
|
|
||||||
if colors ~= "" then
|
|
||||||
colors = colors .. ", "
|
|
||||||
end
|
|
||||||
colors = colors .. color
|
|
||||||
end
|
|
||||||
minetest.chat_send_player(name, "Color " .. fields.color ..
|
|
||||||
" does not exist! Available: " .. colors)
|
|
||||||
end
|
|
||||||
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
94
ctf/hud.lua
94
ctf/hud.lua
@ -1,66 +1,8 @@
|
|||||||
local function hudkit()
|
|
||||||
return {
|
|
||||||
players = {},
|
|
||||||
|
|
||||||
add = function(self, player, id, def)
|
|
||||||
local name = player:get_player_name()
|
|
||||||
local elements = self.players[name]
|
|
||||||
|
|
||||||
if not elements then
|
|
||||||
self.players[name] = {}
|
|
||||||
elements = self.players[name]
|
|
||||||
end
|
|
||||||
|
|
||||||
elements[id] = player:hud_add(def)
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
|
|
||||||
exists = function(self, player, id)
|
|
||||||
if not player then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
local name = player:get_player_name()
|
|
||||||
local elements = self.players[name]
|
|
||||||
|
|
||||||
if not elements or not elements[id] then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
|
|
||||||
change = function(self, player, id, stat, value)
|
|
||||||
if not player then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
local name = player:get_player_name()
|
|
||||||
local elements = self.players[name]
|
|
||||||
|
|
||||||
if not elements or not elements[id] then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
player:hud_change(elements[id], stat, value)
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
|
|
||||||
remove = function(self, player, id)
|
|
||||||
local name = player:get_player_name()
|
|
||||||
local elements = self.players[name]
|
|
||||||
|
|
||||||
if not elements or not elements[id] then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
player:hud_remove(elements[id])
|
|
||||||
elements[id] = nil
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
ctf.hud = hudkit()
|
ctf.hud = hudkit()
|
||||||
|
ctf.hud.parts = {}
|
||||||
|
function ctf.hud.register_part(func)
|
||||||
|
table.insert(ctf.hud.parts, func)
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
ctf.hud.players[player:get_player_name()] = nil
|
ctf.hud.players[player:get_player_name()] = nil
|
||||||
@ -79,29 +21,27 @@ function ctf.hud.update(player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Team Identifier
|
-- Team Identifier
|
||||||
local color = ctf.flag_colors[ctf.team(tplayer.team).data.color]
|
for i = 1, #ctf.hud.parts do
|
||||||
if not color then
|
ctf.hud.parts[i](player, name, tplayer)
|
||||||
color = "0x000000"
|
|
||||||
end
|
end
|
||||||
player:set_nametag_attributes({ color = "0xFF" .. string.sub(color, 3) })
|
end
|
||||||
|
|
||||||
|
ctf.hud.register_part(function(player, name, tplayer)
|
||||||
if not ctf.hud:exists(player, "ctf:hud_team") then
|
if not ctf.hud:exists(player, "ctf:hud_team") then
|
||||||
return ctf.hud:add(player, "ctf:hud_team", {
|
ctf.hud:add(player, "ctf:hud_team", {
|
||||||
hud_elem_type = "text",
|
hud_elem_type = "text",
|
||||||
position = {x = 1, y = 0},
|
position = {x = 1, y = 0},
|
||||||
scale = {x = 100, y = 100},
|
scale = {x = 100, y = 100},
|
||||||
text = tplayer.team,
|
text = tplayer.team,
|
||||||
number = color,
|
number = "0x000000",
|
||||||
offset = {x=-100, y = 20}
|
offset = {x=-100, y = 20}
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
ctf.hud:change(player, "ctf:hud_team", "text", tplayer.team)
|
ctf.hud:change(player, "ctf:hud_team", "text", tplayer.team)
|
||||||
ctf.hud:change(player, "ctf:hud_team", "number", color)
|
|
||||||
end
|
end
|
||||||
end
|
end)
|
||||||
|
|
||||||
local count = 0
|
|
||||||
function ctf.hud.updateAll()
|
function ctf.hud.updateAll()
|
||||||
count = 0
|
|
||||||
if not ctf.setting("hud") then
|
if not ctf.setting("hud") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -112,10 +52,8 @@ function ctf.hud.updateAll()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_globalstep(function(delta)
|
local function tick()
|
||||||
count = count + delta
|
|
||||||
|
|
||||||
if count > 10 then
|
|
||||||
ctf.hud.updateAll()
|
ctf.hud.updateAll()
|
||||||
end
|
minetest.after(10, tick)
|
||||||
end)
|
end
|
||||||
|
minetest.after(1, tick)
|
||||||
|
16
ctf/init.lua
16
ctf/init.lua
@ -21,22 +21,6 @@ minetest.register_privilege("ctf_admin", {
|
|||||||
description = "Can create teams, manage players, assign team owners.",
|
description = "Can create teams, manage players, assign team owners.",
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Colors
|
|
||||||
ctf.flag_colors = {
|
|
||||||
red = "0xFF4444",
|
|
||||||
cyan = "0x00FFFF",
|
|
||||||
blue = "0x4466FF",
|
|
||||||
purple = "0x800080",
|
|
||||||
yellow = "0xFFFF00",
|
|
||||||
green = "0x00FF00",
|
|
||||||
pink = "0xFF00FF",
|
|
||||||
silver = "0xC0C0C0",
|
|
||||||
gray = "0x808080",
|
|
||||||
black = "0x000000",
|
|
||||||
orange = "0xFFA500",
|
|
||||||
gold = "0x808000"
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Modules
|
-- Modules
|
||||||
dofile(minetest.get_modpath("ctf") .. "/core.lua")
|
dofile(minetest.get_modpath("ctf") .. "/core.lua")
|
||||||
dofile(minetest.get_modpath("ctf") .. "/teams.lua")
|
dofile(minetest.get_modpath("ctf") .. "/teams.lua")
|
||||||
|
1
ctf_colors/depends.txt
Normal file
1
ctf_colors/depends.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
ctf
|
84
ctf_colors/init.lua
Normal file
84
ctf_colors/init.lua
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
ctf.flag_colors = {
|
||||||
|
red = "0xFF4444",
|
||||||
|
cyan = "0x00FFFF",
|
||||||
|
blue = "0x4466FF",
|
||||||
|
purple = "0x800080",
|
||||||
|
yellow = "0xFFFF00",
|
||||||
|
green = "0x00FF00",
|
||||||
|
pink = "0xFF00FF",
|
||||||
|
silver = "0xC0C0C0",
|
||||||
|
gray = "0x808080",
|
||||||
|
black = "0x000000",
|
||||||
|
orange = "0xFFA500",
|
||||||
|
gold = "0x808000"
|
||||||
|
}
|
||||||
|
|
||||||
|
ctf.hud.register_part(function(player, name, tplayer)
|
||||||
|
local color = ctf.flag_colors[ctf.team(tplayer.team).data.color]
|
||||||
|
if not color then
|
||||||
|
color = "0x000000"
|
||||||
|
end
|
||||||
|
player:set_nametag_attributes({ color = "0xFF" .. string.sub(color, 3) })
|
||||||
|
|
||||||
|
if not ctf.hud:exists(player, "ctf:hud_team") then
|
||||||
|
ctf.hud:add(player, "ctf:hud_team", {
|
||||||
|
hud_elem_type = "text",
|
||||||
|
position = {x = 1, y = 0},
|
||||||
|
scale = {x = 100, y = 100},
|
||||||
|
text = tplayer.team,
|
||||||
|
number = color,
|
||||||
|
offset = {x=-100, y = 20}
|
||||||
|
})
|
||||||
|
else
|
||||||
|
ctf.hud:change(player, "ctf:hud_team", "number", color)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
ctf.gui.register_tab("settings", "Settings", function(name, team)
|
||||||
|
local color = ""
|
||||||
|
if ctf.team(team).data.color then
|
||||||
|
color = ctf.team(team).data.color
|
||||||
|
end
|
||||||
|
|
||||||
|
local result = "field[3,2;4,1;color;Team Color;" .. color .. "]" ..
|
||||||
|
"button[4,6;2,1;save;Save]"
|
||||||
|
|
||||||
|
|
||||||
|
if not ctf.can_mod(name,team) then
|
||||||
|
result = "label[0.5,1;You do not own this team!"
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.show_formspec(name, "ctf:settings",
|
||||||
|
"size[10,7]" ..
|
||||||
|
ctf.gui.get_tabs(name, team) ..
|
||||||
|
result
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
if formname ~= "ctf:settings" then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Settings page
|
||||||
|
if fields.save then
|
||||||
|
ctf.gui.show(name, "settings")
|
||||||
|
|
||||||
|
if ctf.flag_colors[fields.color] then
|
||||||
|
team.data.color = fields.color
|
||||||
|
ctf.needs_save = true
|
||||||
|
else
|
||||||
|
local colors = ""
|
||||||
|
for color, code in pairs(ctf.flag_colors) do
|
||||||
|
if colors ~= "" then
|
||||||
|
colors = colors .. ", "
|
||||||
|
end
|
||||||
|
colors = colors .. color
|
||||||
|
end
|
||||||
|
minetest.chat_send_player(name, "Color " .. fields.color ..
|
||||||
|
" does not exist! Available: " .. colors)
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end)
|
@ -1 +1,2 @@
|
|||||||
ctf
|
ctf
|
||||||
|
ctf_colors
|
||||||
|
61
hudkit/init.lua
Normal file
61
hudkit/init.lua
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
function hudkit()
|
||||||
|
return {
|
||||||
|
players = {},
|
||||||
|
|
||||||
|
add = function(self, player, id, def)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local elements = self.players[name]
|
||||||
|
|
||||||
|
if not elements then
|
||||||
|
self.players[name] = {}
|
||||||
|
elements = self.players[name]
|
||||||
|
end
|
||||||
|
|
||||||
|
elements[id] = player:hud_add(def)
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
|
||||||
|
exists = function(self, player, id)
|
||||||
|
if not player then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local elements = self.players[name]
|
||||||
|
|
||||||
|
if not elements or not elements[id] then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
|
||||||
|
change = function(self, player, id, stat, value)
|
||||||
|
if not player then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local elements = self.players[name]
|
||||||
|
|
||||||
|
if not elements or not elements[id] then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
player:hud_change(elements[id], stat, value)
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
|
||||||
|
remove = function(self, player, id)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local elements = self.players[name]
|
||||||
|
|
||||||
|
if not elements or not elements[id] then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
player:hud_remove(elements[id])
|
||||||
|
elements[id] = nil
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user