Create ctf_colors, clean up hud

master
rubenwardy 2015-09-07 10:31:09 +01:00
parent 8f1b6c7abd
commit 4d00a8cf1d
8 changed files with 166 additions and 141 deletions

View File

@ -1 +1,2 @@
chatplus?
chatplus?
hudkit

View File

@ -199,29 +199,6 @@ ctf.gui.register_tab("diplo", "Diplomacy", function(name, team)
)
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)
for name, tab in pairs(ctf.gui.tabs) do
if fsname == "ctf:" .. name then
@ -261,28 +238,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
ctf.gui.show(name, "news")
return true
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)
minetest.register_on_player_receive_fields(function(player, formname, fields)

View File

@ -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.parts = {}
function ctf.hud.register_part(func)
table.insert(ctf.hud.parts, func)
end
minetest.register_on_leaveplayer(function(player)
ctf.hud.players[player:get_player_name()] = nil
@ -79,29 +21,27 @@ function ctf.hud.update(player)
end
-- Team Identifier
local color = ctf.flag_colors[ctf.team(tplayer.team).data.color]
if not color then
color = "0x000000"
for i = 1, #ctf.hud.parts do
ctf.hud.parts[i](player, name, tplayer)
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
return ctf.hud:add(player, "ctf:hud_team", {
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,
number = "0x000000",
offset = {x=-100, y = 20}
})
else
ctf.hud:change(player, "ctf:hud_team", "text", tplayer.team)
ctf.hud:change(player, "ctf:hud_team", "number", color)
end
end
end)
local count = 0
function ctf.hud.updateAll()
count = 0
if not ctf.setting("hud") then
return
end
@ -112,10 +52,8 @@ function ctf.hud.updateAll()
end
end
minetest.register_globalstep(function(delta)
count = count + delta
if count > 10 then
ctf.hud.updateAll()
end
end)
local function tick()
ctf.hud.updateAll()
minetest.after(10, tick)
end
minetest.after(1, tick)

View File

@ -21,22 +21,6 @@ minetest.register_privilege("ctf_admin", {
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
dofile(minetest.get_modpath("ctf") .. "/core.lua")
dofile(minetest.get_modpath("ctf") .. "/teams.lua")

1
ctf_colors/depends.txt Normal file
View File

@ -0,0 +1 @@
ctf

84
ctf_colors/init.lua Normal file
View 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)

View File

@ -1 +1,2 @@
ctf
ctf_colors

61
hudkit/init.lua Normal file
View 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