Up and down buttons added to diplomacy tab.

This commit is contained in:
Coder12a 2017-09-26 16:57:29 -07:00 committed by GitHub
parent 578c3222a5
commit 336712b3dd

View File

@ -131,6 +131,8 @@ ctf.gui.register_tab("news", "News", function(name, tname)
result) result)
end) end)
local scroll_diplomacy = 0
local scroll_max = 0
-- Team interface -- Team interface
ctf.gui.register_tab("diplo", "Diplomacy", function(name, tname) ctf.gui.register_tab("diplo", "Diplomacy", function(name, tname)
local result = "" local result = ""
@ -151,6 +153,18 @@ ctf.gui.register_tab("diplo", "Diplomacy", function(name, tname)
result = result .. "label[1,1;Diplomacy from the perspective of " .. tname .. "]" result = result .. "label[1,1;Diplomacy from the perspective of " .. tname .. "]"
scroll_max = 0
for i = 1, #data do
scroll_max = i
end
scroll_max = scroll_max - 5
if scroll_diplomacy > 0 then
result = result .. "button[9.2,0.44;1,3;scroll_up;Up]"
end
if scroll_diplomacy <= scroll_max then
result = result .. "button[9.2,3.8;1,3;scroll_down;Down]"
end
for i = 1, #data do for i = 1, #data do
amount = i amount = i
local height = (i*1)+0.5 local height = (i*1)+0.5
@ -159,35 +173,37 @@ ctf.gui.register_tab("diplo", "Diplomacy", function(name, tname)
break break
end end
local L = i + scroll_diplomacy
result = result .. "background[1," .. height .. ";8.2,1;diplo_" .. result = result .. "background[1," .. height .. ";8.2,1;diplo_" ..
data[i].state .. ".png]" data[L].state .. ".png]"
result = result .. "button[1.25," .. height .. ";2,1;team_" .. result = result .. "button[1.25," .. height .. ";2,1;team_" ..
data[i].team .. ";" .. data[i].team .. "]" data[L].team .. ";" .. data[L].team .. "]"
result = result .. "label[3.75," .. height .. ";" .. data[i].state result = result .. "label[3.75," .. height .. ";" .. data[L].state
.. "]" .. "]"
if ctf.can_mod(name, tname) and ctf.player(name).team == tname then if ctf.can_mod(name, tname) and ctf.player(name).team == tname then
if not data[i].from and not data[i].to then if not data[L].from and not data[L].to then
if data[i].state == "war" then if data[L].state == "war" then
result = result .. "button[7.5," .. height .. result = result .. "button[7.5," .. height ..
";1.5,1;peace_" .. data[i].team .. ";Peace]" ";1.5,1;peace_" .. data[L].team .. ";Peace]"
elseif data[i].state == "peace" then elseif data[L].state == "peace" then
result = result .. "button[6," .. height .. result = result .. "button[6," .. height ..
";1.5,1;war_" .. data[i].team .. ";War]" ";1.5,1;war_" .. data[L].team .. ";War]"
result = result .. "button[7.5," .. height .. result = result .. "button[7.5," .. height ..
";1.5,1;alli_" .. data[i].team .. ";Alliance]" ";1.5,1;alli_" .. data[L].team .. ";Alliance]"
elseif data[i].state == "alliance" then elseif data[L].state == "alliance" then
result = result .. "button[6," .. height .. result = result .. "button[6," .. height ..
";1.5,1;peace_" .. data[i].team .. ";Peace]" ";1.5,1;peace_" .. data[L].team .. ";Peace]"
end end
elseif data[i].from ~= nil then elseif data[L].from ~= nil then
result = result .. "label[6," .. height .. result = result .. "label[6," .. height ..
";request recieved]" ";request recieved]"
elseif data[i].to ~= nil then elseif data[L].to ~= nil then
result = result .. "label[5.5," .. height .. result = result .. "label[5.5," .. height ..
";request sent]" ";request sent]"
result = result .. "button[7.5," .. height .. result = result .. "button[7.5," .. height ..
";1.5,1;cancel_" .. data[i].team .. ";Cancel]" ";1.5,1;cancel_" .. data[L].team .. ";Cancel]"
end end
end end
end end
@ -280,6 +296,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
end) end)
local cur_team = nil
minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.register_on_player_receive_fields(function(player, formname, fields)
local name = player:get_player_name() local name = player:get_player_name()
local tplayer = ctf.player(name) local tplayer = ctf.player(name)
@ -287,13 +304,33 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local team = ctf.team(tname) local team = ctf.team(tname)
if not team or formname ~= "ctf:diplo" then if not team or formname ~= "ctf:diplo" then
cur_team = nil
return false return false
end end
if cur_team == nil then
cur_team = tname
end
if fields.scroll_up then
scroll_diplomacy = scroll_diplomacy - 1
if scroll_diplomacy < 0 then
scroll_diplomacy = 0
end
ctf.gui.show(name, "diplo", cur_team)
end
if fields.scroll_down then
scroll_diplomacy = scroll_diplomacy + 1
if scroll_diplomacy > (scroll_max+5) then
scroll_diplomacy = scroll_max
end
ctf.gui.show(name, "diplo", cur_team)
end
for key, field in pairs(fields) do for key, field in pairs(fields) do
local tname2 = string.match(key, "team_(.+)") local tname2 = string.match(key, "team_(.+)")
if tname2 and ctf.team(tname2) then if tname2 and ctf.team(tname2) then
ctf.gui.show(name, "diplo", tname2) ctf.gui.show(name, "diplo", tname2)
cur_team = tname2
return true return true
end end