2019-12-18 20:21:39 +01:00
|
|
|
local Public = {}
|
2021-01-25 02:26:09 +01:00
|
|
|
local Table = require "modules.towny.table"
|
2019-12-18 20:21:39 +01:00
|
|
|
|
2019-12-19 19:58:37 +01:00
|
|
|
function Public.toggle_button(player)
|
|
|
|
if player.gui.top["towny_map_intro_button"] then return end
|
2021-01-25 02:26:09 +01:00
|
|
|
local b = player.gui.top.add({type = "sprite-button", caption = {"modules_towny.towny"}, name = "towny_map_intro_button", tooltip = {"modules_towny.show_info"}})
|
2019-12-19 19:58:37 +01:00
|
|
|
b.style.font_color = {r=0.5, g=0.3, b=0.99}
|
|
|
|
b.style.font = "heading-1"
|
|
|
|
b.style.minimal_height = 38
|
2021-01-25 02:26:09 +01:00
|
|
|
b.style.maximal_height = 38
|
|
|
|
b.style.minimal_width = 100
|
2019-12-19 19:58:37 +01:00
|
|
|
b.style.top_padding = 1
|
|
|
|
b.style.left_padding = 1
|
|
|
|
b.style.right_padding = 1
|
|
|
|
b.style.bottom_padding = 1
|
|
|
|
end
|
|
|
|
|
2019-12-18 20:21:39 +01:00
|
|
|
function Public.show(player)
|
2021-01-25 02:26:09 +01:00
|
|
|
local townytable = Table.get_table()
|
2019-12-18 20:21:39 +01:00
|
|
|
if player.gui.center["towny_map_intro_frame"] then player.gui.center["towny_map_intro_frame"].destroy() end
|
2019-12-21 19:47:32 +01:00
|
|
|
local frame = player.gui.center.add {type = "frame", name = "towny_map_intro_frame"}
|
|
|
|
local frame = frame.add {type = "frame", direction = "vertical"}
|
2021-01-25 02:26:09 +01:00
|
|
|
|
2019-12-21 19:47:32 +01:00
|
|
|
local t = frame.add {type = "table", column_count = 2}
|
2021-01-25 02:26:09 +01:00
|
|
|
|
|
|
|
local label = t.add {type = "label", caption = {"modules_towny.active_factions"}}
|
2019-12-21 19:47:32 +01:00
|
|
|
label.style.font = "heading-1"
|
|
|
|
label.style.font_color = {r=0.85, g=0.85, b=0.85}
|
|
|
|
label.style.right_padding = 8
|
2021-01-25 02:26:09 +01:00
|
|
|
|
2019-12-21 19:47:32 +01:00
|
|
|
local t = t.add {type = "table", column_count = 4}
|
2021-01-25 02:26:09 +01:00
|
|
|
|
|
|
|
local label = t.add {type = "label", caption = {"modules_towny.outlander", #game.forces.player.connected_players}}
|
2019-12-21 19:47:32 +01:00
|
|
|
label.style.font_color = {170, 170, 170}
|
|
|
|
label.style.font = "heading-3"
|
|
|
|
label.style.minimal_width = 80
|
2021-01-25 02:26:09 +01:00
|
|
|
|
|
|
|
for _, town_center in pairs(townytable.town_centers) do
|
2019-12-21 19:47:32 +01:00
|
|
|
local force = town_center.market.force
|
2021-01-25 02:26:09 +01:00
|
|
|
local label = t.add {type = "label", caption = {"modules_towny.force", force.name, #force.connected_players}}
|
2019-12-21 19:47:32 +01:00
|
|
|
label.style.font = "heading-3"
|
|
|
|
label.style.minimal_width = 80
|
|
|
|
label.style.font_color = town_center.color
|
2021-01-25 02:26:09 +01:00
|
|
|
end
|
|
|
|
|
2019-12-21 19:47:32 +01:00
|
|
|
frame.add {type = "line"}
|
2021-01-25 02:26:09 +01:00
|
|
|
|
|
|
|
local l = frame.add {type = "label", caption = {"modules_towny.map_info_header"}}
|
2019-12-21 19:47:32 +01:00
|
|
|
l.style.font = "heading-1"
|
|
|
|
l.style.font_color = {r=0.85, g=0.85, b=0.85}
|
2021-01-25 02:26:09 +01:00
|
|
|
local caption = {"modules_towny.map_info", {"modules_towny.map_info1"}, {"modules_towny.map_info2"},{"modules_towny.map_info3"},{"modules_towny.map_info4"},{"modules_towny.map_info5"}}
|
|
|
|
|
|
|
|
local l = frame.add {type = "label", caption = caption}
|
2019-12-18 20:21:39 +01:00
|
|
|
l.style.single_line = false
|
|
|
|
l.style.font = "heading-2"
|
2021-01-25 02:26:09 +01:00
|
|
|
l.style.font_color = {r=0.8, g=0.7, b=0.99}
|
|
|
|
end
|
|
|
|
|
|
|
|
function Public.new_town_button(player)
|
|
|
|
if player.gui.top["towny_new_town_button"] then return end
|
|
|
|
local b = player.gui.top.add({type = "sprite-button", caption = "New Town", name = "towny_new_town_button", tooltip = {"modules_towny.new_town_caption", {"modules_towny.new_town_off"}}})
|
|
|
|
b.style.font_color = {r = 0.88, g = 0.02, b = 0.02}
|
|
|
|
b.style.font = "heading-1"
|
|
|
|
b.style.minimal_height = 38
|
|
|
|
b.style.maximal_height = 38
|
|
|
|
b.style.minimal_width = 100
|
|
|
|
b.style.top_padding = 1
|
|
|
|
b.style.left_padding = 1
|
|
|
|
b.style.right_padding = 1
|
|
|
|
b.style.bottom_padding = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
function Public.update_new_town_button(player)
|
|
|
|
local townytable = Table.get_table()
|
|
|
|
local button = player.gui.top["towny_new_town_button"]
|
|
|
|
if not button or not button.valid then return end
|
|
|
|
if player.force == game.forces.player then
|
|
|
|
button.visible = true
|
|
|
|
if townytable.town_buttons[player.index] == true then
|
|
|
|
button.tooltip = {"modules_towny.new_town_caption", {"modules_towny.new_town_on"}}
|
|
|
|
button.style.font_color = {r = 0.02, g = 0.88, b = 0.02}
|
|
|
|
else
|
|
|
|
button.tooltip = {"modules_towny.new_town_caption", {"modules_towny.new_town_off"}}
|
|
|
|
button.style.font_color = {r = 0.88, g = 0.02, b = 0.02}
|
|
|
|
end
|
|
|
|
else
|
|
|
|
button.visible = false
|
|
|
|
end
|
2019-12-18 20:21:39 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Public.close(event)
|
|
|
|
if not event.element then return end
|
2019-12-21 19:47:32 +01:00
|
|
|
if not event.element.valid then return end
|
|
|
|
local parent = event.element.parent
|
|
|
|
for _ = 1, 4, 1 do
|
|
|
|
if not parent then return end
|
2021-01-25 02:26:09 +01:00
|
|
|
if parent.name == "towny_map_intro_frame" then parent.destroy() return end
|
|
|
|
parent = parent.parent
|
2019-12-19 19:58:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Public.toggle(event)
|
|
|
|
if not event.element then return end
|
2021-01-25 02:26:09 +01:00
|
|
|
if not event.element.valid then return end
|
2019-12-19 19:58:37 +01:00
|
|
|
if event.element.name == "towny_map_intro_button" then
|
|
|
|
local player = game.players[event.player_index]
|
|
|
|
if player.gui.center["towny_map_intro_frame"] then
|
|
|
|
player.gui.center["towny_map_intro_frame"].destroy()
|
|
|
|
else
|
|
|
|
Public.show(player)
|
2021-01-25 02:26:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Public.toggle_town(event)
|
|
|
|
local townytable = Table.get_table()
|
|
|
|
if not event.element then return end
|
|
|
|
if not event.element.valid then return end
|
|
|
|
if event.element.name == "towny_new_town_button" then
|
|
|
|
local player = game.players[event.player_index]
|
|
|
|
if townytable.town_buttons[player.index] then
|
|
|
|
townytable.town_buttons[player.index] = false
|
|
|
|
else
|
|
|
|
townytable.town_buttons[player.index] = true
|
|
|
|
end
|
|
|
|
Public.update_new_town_button(player)
|
|
|
|
end
|
2019-12-18 20:21:39 +01:00
|
|
|
end
|
|
|
|
|
2019-12-19 19:58:37 +01:00
|
|
|
|
2021-01-25 02:26:09 +01:00
|
|
|
return Public
|