2016-12-01 04:41:04 +02:00
|
|
|
-- separate_spawns_guis.lua
|
|
|
|
-- Nov 2016
|
|
|
|
|
|
|
|
-- I made a separate file for all the GUI related functions
|
|
|
|
|
|
|
|
require("separate_spawns")
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
local SPAWN_GUI_MAX_WIDTH = 450
|
2017-04-30 15:22:45 +02:00
|
|
|
local SPAWN_GUI_MAX_HEIGHT = 750
|
2016-12-02 23:26:49 +02:00
|
|
|
|
|
|
|
-- Use this for testing shared spawns...
|
2016-12-14 01:46:48 +02:00
|
|
|
-- local sharedSpawnExample1 = {openAccess=true,
|
|
|
|
-- position={x=50,y=50},
|
|
|
|
-- players={"ABC", "DEF"}}
|
|
|
|
-- local sharedSpawnExample2 = {openAccess=false,
|
|
|
|
-- position={x=200,y=200},
|
|
|
|
-- players={"ABC", "DEF"}}
|
|
|
|
-- local sharedSpawnExample3 = {openAccess=true,
|
|
|
|
-- owner="testName1",
|
|
|
|
-- players={"A", "B", "C", "D"}}
|
|
|
|
-- global.sharedSpawns = {testName1=sharedSpawnExample1,
|
|
|
|
-- testName2=sharedSpawnExample2,
|
|
|
|
-- testName3=sharedSpawnExample3}
|
|
|
|
|
2016-12-01 04:41:04 +02:00
|
|
|
|
|
|
|
-- A display gui message
|
|
|
|
-- Meant to be display the first time a player joins.
|
|
|
|
function DisplayWelcomeTextGui(player)
|
|
|
|
player.gui.center.add{name = "welcome_msg",
|
|
|
|
type = "frame",
|
|
|
|
direction = "vertical",
|
2017-01-06 04:17:58 +02:00
|
|
|
caption=global.welcome_msg_title}
|
2016-12-01 04:41:04 +02:00
|
|
|
local wGui = player.gui.center.welcome_msg
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
wGui.style.maximal_width = SPAWN_GUI_MAX_WIDTH
|
|
|
|
wGui.style.maximal_height = SPAWN_GUI_MAX_HEIGHT
|
2016-12-01 04:41:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wGui.add{name = "welcome_msg_lbl1", type = "label",
|
|
|
|
caption=WELCOME_MSG1}
|
|
|
|
wGui.add{name = "welcome_msg_lbl2", type = "label",
|
|
|
|
caption=WELCOME_MSG2}
|
|
|
|
wGui.add{name = "welcome_msg_spacer1", type = "label",
|
|
|
|
caption=" "}
|
|
|
|
|
|
|
|
ApplyStyle(wGui.welcome_msg_lbl1, my_label_style)
|
|
|
|
ApplyStyle(wGui.welcome_msg_lbl2, my_label_style)
|
2016-12-02 23:26:49 +02:00
|
|
|
ApplyStyle(wGui.welcome_msg_spacer1, my_spacer_style)
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2016-12-14 01:46:48 +02:00
|
|
|
wGui.add{name = "other_msg_lbl1", type = "label",
|
|
|
|
caption=OTHER_MSG1}
|
|
|
|
wGui.add{name = "other_msg_lbl2", type = "label",
|
|
|
|
caption=OTHER_MSG2}
|
2017-07-29 00:02:45 +02:00
|
|
|
if (OTHER_MSG3 ~= nil) then
|
|
|
|
wGui.add{name = "other_msg_lbl3", type = "label",
|
|
|
|
caption=OTHER_MSG3}
|
|
|
|
ApplyStyle(wGui.other_msg_lbl3, my_label_style)
|
|
|
|
end
|
|
|
|
if (OTHER_MSG4 ~= nil) then
|
|
|
|
wGui.add{name = "other_msg_lbl4", type = "label",
|
|
|
|
caption=OTHER_MSG4}
|
|
|
|
ApplyStyle(wGui.other_msg_lbl4, my_label_style)
|
|
|
|
end
|
|
|
|
if (OTHER_MSG5 ~= nil) then
|
|
|
|
wGui.add{name = "other_msg_lbl5", type = "label",
|
|
|
|
caption=OTHER_MSG5}
|
|
|
|
ApplyStyle(wGui.other_msg_lbl5, my_label_style)
|
|
|
|
end
|
2016-12-14 01:46:48 +02:00
|
|
|
wGui.add{name = "other_msg_spacer1", type = "label",
|
|
|
|
caption=" "}
|
|
|
|
|
|
|
|
ApplyStyle(wGui.other_msg_lbl1, my_label_style)
|
|
|
|
ApplyStyle(wGui.other_msg_lbl2, my_label_style)
|
|
|
|
ApplyStyle(wGui.other_msg_spacer1, my_spacer_style)
|
2016-12-01 04:41:04 +02:00
|
|
|
|
|
|
|
wGui.add{name = "welcome_msg_lbl3", type = "label",
|
|
|
|
caption=WELCOME_MSG3}
|
|
|
|
wGui.add{name = "welcome_msg_lbl4", type = "label",
|
|
|
|
caption=WELCOME_MSG4}
|
|
|
|
wGui.add{name = "welcome_msg_lbl5", type = "label",
|
|
|
|
caption=WELCOME_MSG5}
|
2016-12-02 23:26:49 +02:00
|
|
|
wGui.add{name = "welcome_msg_lbl6", type = "label",
|
|
|
|
caption=WELCOME_MSG6}
|
2016-12-01 04:41:04 +02:00
|
|
|
wGui.add{name = "welcome_msg_spacer2", type = "label",
|
|
|
|
caption=" "}
|
|
|
|
|
|
|
|
ApplyStyle(wGui.welcome_msg_lbl3, my_warning_style)
|
|
|
|
ApplyStyle(wGui.welcome_msg_lbl4, my_warning_style)
|
|
|
|
ApplyStyle(wGui.welcome_msg_lbl5, my_warning_style)
|
2016-12-02 23:26:49 +02:00
|
|
|
ApplyStyle(wGui.welcome_msg_lbl6, my_label_style)
|
|
|
|
ApplyStyle(wGui.welcome_msg_spacer2, my_spacer_style)
|
2016-12-01 04:41:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wGui.add{name = "welcome_okay_btn",
|
|
|
|
type = "button",
|
|
|
|
caption="I Understand"}
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- Handle the gui click of the welcome msg
|
|
|
|
function WelcomeTextGuiClick(event)
|
|
|
|
if not (event and event.element and event.element.valid) then return end
|
|
|
|
local player = game.players[event.player_index]
|
|
|
|
local buttonClicked = event.element.name
|
|
|
|
|
|
|
|
if (buttonClicked == "welcome_okay_btn") then
|
|
|
|
if (player.gui.center.welcome_msg ~= nil) then
|
|
|
|
player.gui.center.welcome_msg.destroy()
|
|
|
|
end
|
|
|
|
DisplaySpawnOptions(player)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- Display the spawn options and explanation
|
|
|
|
function DisplaySpawnOptions(player)
|
|
|
|
player.gui.center.add{name = "spawn_opts",
|
|
|
|
type = "frame",
|
|
|
|
direction = "vertical",
|
|
|
|
caption="Spawn Options"}
|
|
|
|
local sGui = player.gui.center.spawn_opts
|
2016-12-02 23:26:49 +02:00
|
|
|
sGui.style.maximal_width = SPAWN_GUI_MAX_WIDTH
|
|
|
|
sGui.style.maximal_height = SPAWN_GUI_MAX_HEIGHT
|
2016-12-01 04:41:04 +02:00
|
|
|
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
-- Warnings and explanations...
|
2016-12-01 04:41:04 +02:00
|
|
|
sGui.add{name = "warning_lbl1", type = "label",
|
2016-12-02 23:26:49 +02:00
|
|
|
caption="This is your ONLY chance to choose a spawn option. Choose carefully..."}
|
2016-12-01 04:41:04 +02:00
|
|
|
sGui.add{name = "warning_spacer", type = "label",
|
|
|
|
caption=" "}
|
|
|
|
ApplyStyle(sGui.warning_lbl1, my_warning_style)
|
2016-12-02 23:26:49 +02:00
|
|
|
ApplyStyle(sGui.warning_spacer, my_spacer_style)
|
2016-12-01 04:41:04 +02:00
|
|
|
|
|
|
|
sGui.add{name = "spawn_msg_lbl1", type = "label",
|
|
|
|
caption=SPAWN_MSG1}
|
|
|
|
sGui.add{name = "spawn_msg_lbl2", type = "label",
|
|
|
|
caption=SPAWN_MSG2}
|
|
|
|
sGui.add{name = "spawn_msg_lbl3", type = "label",
|
|
|
|
caption=SPAWN_MSG3}
|
|
|
|
sGui.add{name = "spawn_msg_spacer", type = "label",
|
2017-04-28 03:48:28 +02:00
|
|
|
caption="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"}
|
2016-12-01 04:41:04 +02:00
|
|
|
ApplyStyle(sGui.spawn_msg_lbl1, my_label_style)
|
|
|
|
ApplyStyle(sGui.spawn_msg_lbl2, my_label_style)
|
|
|
|
ApplyStyle(sGui.spawn_msg_lbl3, my_label_style)
|
2016-12-02 23:26:49 +02:00
|
|
|
ApplyStyle(sGui.spawn_msg_spacer, my_spacer_style)
|
|
|
|
|
|
|
|
|
|
|
|
if ENABLE_DEFAULT_SPAWN then
|
|
|
|
sGui.add{name = "default_spawn_btn",
|
|
|
|
type = "button",
|
|
|
|
caption="Default Spawn"}
|
|
|
|
sGui.add{name = "normal_spawn_lbl1", type = "label",
|
|
|
|
caption="This is the default spawn behavior of a vanilla game."}
|
|
|
|
sGui.add{name = "normal_spawn_lbl2", type = "label",
|
|
|
|
caption="You join the default team in the center of the map."}
|
|
|
|
sGui.add{name = "normal_spawn_lbl3", type = "label",
|
|
|
|
caption="(Back by popular request...)"}
|
|
|
|
ApplyStyle(sGui.normal_spawn_lbl1, my_label_style)
|
|
|
|
ApplyStyle(sGui.normal_spawn_lbl2, my_label_style)
|
|
|
|
ApplyStyle(sGui.normal_spawn_lbl3, my_label_style)
|
|
|
|
else
|
|
|
|
sGui.add{name = "normal_spawn_lbl1", type = "label",
|
|
|
|
caption="Default spawn is disabled in this mode."}
|
|
|
|
ApplyStyle(sGui.normal_spawn_lbl1, my_warning_style)
|
|
|
|
end
|
|
|
|
sGui.add{name = "normal_spawn_spacer", type = "label",
|
2017-04-28 03:48:28 +02:00
|
|
|
caption="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"}
|
2016-12-02 23:26:49 +02:00
|
|
|
ApplyStyle(sGui.normal_spawn_spacer, my_spacer_style)
|
2016-12-01 04:41:04 +02:00
|
|
|
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
-- The main spawning options. Solo near and solo far.
|
2017-04-30 15:22:45 +02:00
|
|
|
-- If enable, you can also choose to be on your own team.
|
|
|
|
local soloSpawnFlow = sGui.add{name = "spawn_solo_flow",
|
|
|
|
type = "flow",
|
|
|
|
direction="vertical"}
|
|
|
|
|
|
|
|
if (ENABLE_SEPARATE_TEAMS) then
|
|
|
|
soloSpawnFlow.add{name = "isolated_spawn_main_team_radio",
|
|
|
|
type = "radiobutton",
|
|
|
|
caption="Join Main Team (shared research)",
|
|
|
|
state=true}
|
|
|
|
soloSpawnFlow.add{name = "isolated_spawn_new_team_radio",
|
|
|
|
type = "radiobutton",
|
|
|
|
caption="Create Your Own Team (own research tree)",
|
|
|
|
state=false}
|
2017-07-26 02:20:35 +02:00
|
|
|
if (SPAWN_MOAT_CHOICE_ENABLED) then
|
|
|
|
soloSpawnFlow.add{name = "isolated_spawn_moat_option_checkbox",
|
|
|
|
type = "checkbox",
|
|
|
|
caption="Surround your spawn with a moat",
|
|
|
|
state=false}
|
|
|
|
end
|
2017-04-30 15:22:45 +02:00
|
|
|
soloSpawnFlow.add{name = "team_chat_warning_lbl1", type = "label",
|
|
|
|
caption="You must type '/s' before your msg to chat with other teams!!!"}
|
|
|
|
ApplyStyle(soloSpawnFlow.team_chat_warning_lbl1, my_warning_style)
|
|
|
|
soloSpawnFlow.add{name = "team_chat_warning_spacer", type = "label",
|
|
|
|
caption=" "}
|
|
|
|
ApplyStyle(soloSpawnFlow.team_chat_warning_spacer, my_spacer_style)
|
|
|
|
end
|
|
|
|
|
|
|
|
soloSpawnFlow.add{name = "isolated_spawn_near",
|
2016-12-01 04:41:04 +02:00
|
|
|
type = "button",
|
|
|
|
caption="Solo Spawn (Near)"}
|
2017-04-30 15:22:45 +02:00
|
|
|
soloSpawnFlow.add{name = "isolated_spawn_far",
|
2016-12-01 04:41:04 +02:00
|
|
|
type = "button",
|
|
|
|
caption="Solo Spawn (Far)"}
|
2017-04-30 15:22:45 +02:00
|
|
|
|
|
|
|
soloSpawnFlow.add{name = "isolated_spawn_lbl1", type = "label",
|
|
|
|
caption="You are spawned in a new area, with some starting resources."}
|
|
|
|
ApplyStyle(soloSpawnFlow.isolated_spawn_lbl1, my_label_style)
|
|
|
|
|
2016-12-01 04:41:04 +02:00
|
|
|
sGui.add{name = "isolated_spawn_spacer", type = "label",
|
2017-04-28 03:48:28 +02:00
|
|
|
caption="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"}
|
2016-12-02 23:26:49 +02:00
|
|
|
ApplyStyle(sGui.isolated_spawn_spacer, my_spacer_style)
|
|
|
|
|
|
|
|
|
|
|
|
-- Spawn options to join another player's base.
|
2016-12-14 01:46:48 +02:00
|
|
|
if ENABLE_SHARED_SPAWNS then
|
|
|
|
local numAvailSpawns = GetNumberOfAvailableSharedSpawns()
|
|
|
|
if (numAvailSpawns > 0) then
|
|
|
|
sGui.add{name = "join_other_spawn",
|
|
|
|
type = "button",
|
|
|
|
caption="Join Someone (" .. numAvailSpawns .. " available)"}
|
|
|
|
sGui.add{name = "join_other_spawn_lbl1", type = "label",
|
|
|
|
caption="You are spawned in someone else's base."}
|
|
|
|
sGui.add{name = "join_other_spawn_lbl2", type = "label",
|
|
|
|
caption="This requires at least 1 person to have allowed access to their base."}
|
|
|
|
sGui.add{name = "join_other_spawn_lbl3", type = "label",
|
|
|
|
caption="This choice is final and you will not be able to create your own spawn later."}
|
|
|
|
sGui.add{name = "join_other_spawn_spacer", type = "label",
|
|
|
|
caption=" "}
|
|
|
|
ApplyStyle(sGui.join_other_spawn_lbl1, my_label_style)
|
|
|
|
ApplyStyle(sGui.join_other_spawn_lbl2, my_label_style)
|
|
|
|
ApplyStyle(sGui.join_other_spawn_lbl3, my_label_style)
|
|
|
|
ApplyStyle(sGui.join_other_spawn_spacer, my_spacer_style)
|
|
|
|
else
|
|
|
|
sGui.add{name = "join_other_spawn_lbl1", type = "label",
|
|
|
|
caption="There are currently no shared bases availble to spawn at."}
|
|
|
|
sGui.add{name = "join_other_spawn_spacer", type = "label",
|
|
|
|
caption=" "}
|
|
|
|
ApplyStyle(sGui.join_other_spawn_lbl1, my_warning_style)
|
|
|
|
ApplyStyle(sGui.join_other_spawn_spacer, my_spacer_style)
|
|
|
|
sGui.add{name = "join_other_spawn_check",
|
|
|
|
type = "button",
|
|
|
|
caption="Check Again"}
|
|
|
|
end
|
2016-12-02 23:26:49 +02:00
|
|
|
else
|
|
|
|
sGui.add{name = "join_other_spawn_lbl1", type = "label",
|
2016-12-14 01:46:48 +02:00
|
|
|
caption="Shared spawns are disabled in this mode."}
|
2016-12-02 23:26:49 +02:00
|
|
|
ApplyStyle(sGui.join_other_spawn_lbl1, my_warning_style)
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
-- Some final notes
|
|
|
|
sGui.add{name = "note_spacer1", type = "label",
|
2017-04-28 03:48:28 +02:00
|
|
|
caption="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"}
|
2016-12-02 23:26:49 +02:00
|
|
|
sGui.add{name = "note_spacer2", type = "label",
|
|
|
|
caption=" "}
|
2016-12-14 01:46:48 +02:00
|
|
|
|
|
|
|
if MAX_ONLINE_PLAYERS_AT_SHARED_SPAWN then
|
|
|
|
sGui.add{name = "shared_spawn_note1", type = "label",
|
|
|
|
caption="If you create your own spawn point you can allow up to " .. MAX_ONLINE_PLAYERS_AT_SHARED_SPAWN-1 .. " other online players to join." }
|
|
|
|
ApplyStyle(sGui.shared_spawn_note1, my_note_style)
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
sGui.add{name = "note_lbl1", type = "label",
|
|
|
|
caption="Near spawn is between " .. NEAR_MIN_DIST*CHUNK_SIZE .. "-" .. NEAR_MAX_DIST*CHUNK_SIZE .. " tiles away from the center of the map."}
|
|
|
|
sGui.add{name = "note_lbl2", type = "label",
|
|
|
|
caption="Far spawn is between " .. FAR_MIN_DIST*CHUNK_SIZE .. "-" .. FAR_MAX_DIST*CHUNK_SIZE .. " tiles away from the center of the map."}
|
|
|
|
sGui.add{name = "note_lbl3", type = "label",
|
2016-12-02 23:26:49 +02:00
|
|
|
caption="Solo spawns are dangerous! Expect a fight to reach other players."}
|
|
|
|
sGui.add{name = "note_spacer3", type = "label",
|
2016-12-01 04:41:04 +02:00
|
|
|
caption=" "}
|
|
|
|
ApplyStyle(sGui.note_lbl1, my_note_style)
|
|
|
|
ApplyStyle(sGui.note_lbl2, my_note_style)
|
|
|
|
ApplyStyle(sGui.note_lbl3, my_note_style)
|
2016-12-02 23:26:49 +02:00
|
|
|
ApplyStyle(sGui.note_spacer1, my_spacer_style)
|
|
|
|
ApplyStyle(sGui.note_spacer2, my_spacer_style)
|
|
|
|
ApplyStyle(sGui.note_spacer3, my_spacer_style)
|
2016-12-01 04:41:04 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- Handle the gui click of the spawn options
|
|
|
|
function SpawnOptsGuiClick(event)
|
|
|
|
if not (event and event.element and event.element.valid) then return end
|
|
|
|
local player = game.players[event.player_index]
|
2017-04-30 15:22:45 +02:00
|
|
|
local elemName = event.element.name
|
|
|
|
|
|
|
|
if (player.gui.center.spawn_opts == nil) then
|
|
|
|
return -- Gui event unrelated to this gui.
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2017-07-26 02:20:35 +02:00
|
|
|
local joinMainTeamRadio, joinOwnTeamRadio, moatChoice = false
|
2016-12-01 04:41:04 +02:00
|
|
|
|
|
|
|
-- Check if a valid button on the gui was pressed
|
|
|
|
-- and delete the GUI
|
2017-04-30 15:22:45 +02:00
|
|
|
if ((elemName == "default_spawn_btn") or
|
|
|
|
(elemName == "isolated_spawn_near") or
|
|
|
|
(elemName == "isolated_spawn_far") or
|
|
|
|
(elemName == "join_other_spawn") or
|
|
|
|
(elemName == "join_other_spawn_check")) then
|
|
|
|
|
|
|
|
if (ENABLE_SEPARATE_TEAMS) then
|
|
|
|
joinMainTeamRadio =
|
|
|
|
player.gui.center.spawn_opts.spawn_solo_flow.isolated_spawn_main_team_radio.state
|
|
|
|
joinOwnTeamRadio =
|
|
|
|
player.gui.center.spawn_opts.spawn_solo_flow.isolated_spawn_new_team_radio.state
|
2017-07-26 02:20:35 +02:00
|
|
|
if (SPAWN_MOAT_CHOICE_ENABLED) then
|
|
|
|
moatChoice =
|
|
|
|
player.gui.center.spawn_opts.spawn_solo_flow.isolated_spawn_moat_option_checkbox.state
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
end
|
2017-04-30 15:22:45 +02:00
|
|
|
player.gui.center.spawn_opts.destroy()
|
|
|
|
|
|
|
|
-- This just updates the radio buttons.
|
|
|
|
elseif ((elemName == "isolated_spawn_main_team_radio") or
|
|
|
|
(elemName == "isolated_spawn_new_team_radio")) then
|
|
|
|
if (elemName == "isolated_spawn_main_team_radio") then
|
|
|
|
event.element.parent.isolated_spawn_new_team_radio.state=false
|
|
|
|
elseif (elemName == "isolated_spawn_new_team_radio") then
|
|
|
|
event.element.parent.isolated_spawn_main_team_radio.state=false
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
return -- Do nothing, no valid element item was clicked.
|
2016-12-01 04:41:04 +02:00
|
|
|
end
|
|
|
|
|
2017-04-30 15:22:45 +02:00
|
|
|
if (elemName == "default_spawn_btn") then
|
2016-12-02 23:26:49 +02:00
|
|
|
CreateSpawnCtrlGui(player)
|
|
|
|
GivePlayerStarterItems(player)
|
2017-04-27 02:59:48 +02:00
|
|
|
ChangePlayerSpawn(player, player.force.get_spawn_position(GAME_SURFACE_NAME))
|
2016-12-02 23:26:49 +02:00
|
|
|
SendBroadcastMsg(player.name .. " joined the main force!")
|
2017-04-27 02:59:48 +02:00
|
|
|
ChartArea(player.force, player.position, 4, player.surface)
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2017-04-30 15:22:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
elseif ((elemName == "isolated_spawn_near") or (elemName == "isolated_spawn_far")) then
|
2016-12-02 23:26:49 +02:00
|
|
|
CreateSpawnCtrlGui(player)
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
-- Create a new spawn point
|
|
|
|
local newSpawn = {x=0,y=0}
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2017-04-30 15:22:45 +02:00
|
|
|
-- Create a new force for player if they choose that radio button
|
|
|
|
if ENABLE_SEPARATE_TEAMS and joinOwnTeamRadio then
|
|
|
|
local newForce = CreatePlayerCustomForce(player)
|
|
|
|
|
|
|
|
if (FRONTIER_ROCKET_SILO_MODE and (newForce ~= nil)) then
|
|
|
|
ChartRocketSiloArea(newForce, game.surfaces[GAME_SURFACE_NAME])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
-- Re-used abandoned spawns...
|
|
|
|
if (#global.unusedSpawns >= 1) then
|
2017-07-26 02:20:35 +02:00
|
|
|
oldSpawn = table.remove(global.unusedSpawns)
|
|
|
|
global.uniqueSpawns[player.name] = oldSpawn
|
2016-12-02 23:26:49 +02:00
|
|
|
player.print("Sorry! You have been assigned to an abandoned base! This is done to keep map size small.")
|
2017-07-26 02:20:35 +02:00
|
|
|
ChangePlayerSpawn(player, oldSpawn.pos)
|
2016-12-02 23:26:49 +02:00
|
|
|
SendPlayerToSpawn(player)
|
|
|
|
GivePlayerStarterItems(player)
|
|
|
|
SendBroadcastMsg(player.name .. " joined an abandoned base!")
|
|
|
|
else
|
|
|
|
|
|
|
|
-- Find coordinates of a good place to spawn
|
2017-04-30 15:22:45 +02:00
|
|
|
if (elemName == "isolated_spawn_far") then
|
2017-04-27 02:59:48 +02:00
|
|
|
newSpawn = FindUngeneratedCoordinates(FAR_MIN_DIST,FAR_MAX_DIST, player.surface)
|
2017-04-30 15:22:45 +02:00
|
|
|
elseif (elemName == "isolated_spawn_near") then
|
2017-04-27 02:59:48 +02:00
|
|
|
newSpawn = FindUngeneratedCoordinates(NEAR_MIN_DIST,NEAR_MAX_DIST, player.surface)
|
2016-12-02 23:26:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- If that fails, find a random map edge in a rand direction.
|
|
|
|
if ((newSpawn.x == 0) and (newSpawn.x == 0)) then
|
2017-04-27 02:59:48 +02:00
|
|
|
newSpawn = FindMapEdge(GetRandomVector(), player.surface)
|
2016-12-02 23:26:49 +02:00
|
|
|
DebugPrint("Resorting to find map edge! x=" .. newSpawn.x .. ",y=" .. newSpawn.y)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Create that spawn in the global vars
|
|
|
|
ChangePlayerSpawn(player, newSpawn)
|
|
|
|
|
|
|
|
-- Send the player there
|
2017-07-26 02:20:35 +02:00
|
|
|
SendPlayerToNewSpawnAndCreateIt(player, newSpawn, moatChoice)
|
2017-04-30 15:22:45 +02:00
|
|
|
if (elemName == "isolated_spawn_near") then
|
|
|
|
SendBroadcastMsg(player.name .. " joined the game from a distance!")
|
|
|
|
elseif (elemName == "isolated_spawn_far") then
|
|
|
|
SendBroadcastMsg(player.name .. " joined the game from a great distance!")
|
2016-12-02 23:26:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
player.print("PLEASE WAIT WHILE YOUR SPAWN POINT IS GENERATED!")
|
|
|
|
player.print("PLEASE WAIT WHILE YOUR SPAWN POINT IS GENERATED!!")
|
|
|
|
player.print("PLEASE WAIT WHILE YOUR SPAWN POINT IS GENERATED!!!")
|
2016-12-01 04:41:04 +02:00
|
|
|
end
|
|
|
|
|
2017-04-30 15:22:45 +02:00
|
|
|
elseif (elemName == "join_other_spawn") then
|
2016-12-02 23:26:49 +02:00
|
|
|
DisplaySharedSpawnOptions(player)
|
|
|
|
|
|
|
|
-- Provide a way to refresh the gui to check if people have shared their
|
|
|
|
-- bases.
|
2017-04-30 15:22:45 +02:00
|
|
|
elseif (elemName == "join_other_spawn_check") then
|
2016-12-02 23:26:49 +02:00
|
|
|
DisplaySpawnOptions(player)
|
2016-12-01 04:41:04 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
-- Display the spawn options and explanation
|
|
|
|
function DisplaySharedSpawnOptions(player)
|
|
|
|
player.gui.center.add{name = "shared_spawn_opts",
|
|
|
|
type = "frame",
|
|
|
|
direction = "vertical",
|
|
|
|
caption="Available Bases to Join:"}
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
local shGuiFrame = player.gui.center.shared_spawn_opts
|
|
|
|
local shGui = shGuiFrame.add{type="scroll-pane", name="spawns_scroll_pane", caption=""}
|
|
|
|
ApplyStyle(shGui, my_fixed_width_style)
|
|
|
|
shGui.style.maximal_width = SPAWN_GUI_MAX_WIDTH
|
|
|
|
shGui.style.maximal_height = SPAWN_GUI_MAX_HEIGHT
|
|
|
|
shGui.horizontal_scroll_policy = "never"
|
2016-12-01 04:41:04 +02:00
|
|
|
|
|
|
|
|
2016-12-14 01:46:48 +02:00
|
|
|
for spawnName,sharedSpawn in pairs(global.sharedSpawns) do
|
|
|
|
if sharedSpawn.openAccess then
|
|
|
|
local spotsRemaining = MAX_ONLINE_PLAYERS_AT_SHARED_SPAWN - GetOnlinePlayersAtSharedSpawn(spawnName)
|
|
|
|
if (spotsRemaining > 0) then
|
|
|
|
shGui.add{type="button", caption=spawnName .. " (" .. spotsRemaining .. " spots remaining)", name=spawnName}
|
|
|
|
shGui.add{name = spawnName .. "spacer_lbl", type = "label", caption=" "}
|
|
|
|
ApplyStyle(shGui[spawnName], my_small_button_style)
|
|
|
|
ApplyStyle(shGui[spawnName .. "spacer_lbl"], my_spacer_style)
|
|
|
|
end
|
|
|
|
end
|
2016-12-02 23:26:49 +02:00
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
shGui.add{name = "shared_spawn_cancel",
|
|
|
|
type = "button",
|
|
|
|
caption="Cancel (Return to Previous Options)"}
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
-- Handle the gui click of the shared spawn options
|
|
|
|
function SharedSpwnOptsGuiClick(event)
|
|
|
|
if not (event and event.element and event.element.valid) then return end
|
|
|
|
local player = game.players[event.player_index]
|
|
|
|
local buttonClicked = event.element.name
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2017-04-29 03:19:08 +02:00
|
|
|
if (event.element.parent) then
|
|
|
|
if (event.element.parent.name ~= "spawns_scroll_pane") then
|
|
|
|
return
|
|
|
|
end
|
2017-04-28 03:48:28 +02:00
|
|
|
end
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
-- Check for cancel button, return to spawn options
|
|
|
|
if (buttonClicked == "shared_spawn_cancel") then
|
|
|
|
DisplaySpawnOptions(player)
|
|
|
|
if (player.gui.center.shared_spawn_opts ~= nil) then
|
|
|
|
player.gui.center.shared_spawn_opts.destroy()
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
-- Else check for which spawn was selected
|
|
|
|
-- If a spawn is removed during this time, the button will not do anything
|
|
|
|
else
|
2016-12-14 01:46:48 +02:00
|
|
|
for spawnName,sharedSpawn in pairs(global.sharedSpawns) do
|
2016-12-02 23:26:49 +02:00
|
|
|
if (buttonClicked == spawnName) then
|
|
|
|
CreateSpawnCtrlGui(player)
|
2016-12-14 01:46:48 +02:00
|
|
|
ChangePlayerSpawn(player,sharedSpawn.position)
|
2016-12-02 23:26:49 +02:00
|
|
|
SendPlayerToSpawn(player)
|
|
|
|
GivePlayerStarterItems(player)
|
2016-12-14 01:46:48 +02:00
|
|
|
table.insert(sharedSpawn.players, player.name)
|
2016-12-02 23:26:49 +02:00
|
|
|
SendBroadcastMsg(player.name .. " joined " .. spawnName .. "'s base!")
|
2017-04-30 15:22:45 +02:00
|
|
|
player.force = game.players[spawnName].force
|
2016-12-02 23:26:49 +02:00
|
|
|
if (player.gui.center.shared_spawn_opts ~= nil) then
|
|
|
|
player.gui.center.shared_spawn_opts.destroy()
|
|
|
|
end
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
function CreateSpawnCtrlGui(player)
|
|
|
|
if player.gui.top.spwn_ctrls == nil then
|
|
|
|
player.gui.top.add{name="spwn_ctrls", type="button", caption="Spawn Ctrl"}
|
|
|
|
end
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
local function IsSharedSpawnActive(player)
|
2016-12-14 01:46:48 +02:00
|
|
|
if ((global.sharedSpawns[player.name] == nil) or
|
|
|
|
(global.sharedSpawns[player.name].openAccess == false)) then
|
2016-12-02 23:26:49 +02:00
|
|
|
return false
|
|
|
|
else
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
-- Get a random warp point to go to
|
|
|
|
function GetRandomSpawnPoint()
|
|
|
|
local numSpawnPoints = TableLength(global.sharedSpawns)
|
|
|
|
if (numSpawnPoints > 0) then
|
|
|
|
local randSpawnNum = math.random(1,numSpawnPoints)
|
|
|
|
local counter = 1
|
2016-12-14 01:46:48 +02:00
|
|
|
for _,sharedSpawn in pairs(global.sharedSpawns) do
|
2016-12-02 23:26:49 +02:00
|
|
|
if (randSpawnNum == counter) then
|
2016-12-14 01:46:48 +02:00
|
|
|
return sharedSpawn.position
|
2016-12-02 23:26:49 +02:00
|
|
|
end
|
|
|
|
counter = counter + 1
|
|
|
|
end
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
return {x=0,y=0}
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
-- This is a toggle function, it either shows or hides the spawn controls
|
|
|
|
function ExpandSpawnCtrlGui(player, tick)
|
|
|
|
local spwnCtrlPanel = player.gui.left["spwn_ctrl_panel"]
|
|
|
|
if (spwnCtrlPanel) then
|
|
|
|
spwnCtrlPanel.destroy()
|
|
|
|
else
|
|
|
|
local spwnCtrlPanel = player.gui.left.add{type="frame",
|
|
|
|
name="spwn_ctrl_panel", caption="Spawn Controls:"}
|
|
|
|
local spwnCtrls = spwnCtrlPanel.add{type="scroll-pane",
|
|
|
|
name="spwn_ctrl_panel", caption=""}
|
|
|
|
ApplyStyle(spwnCtrls, my_fixed_width_style)
|
|
|
|
spwnCtrls.style.maximal_height = SPAWN_GUI_MAX_HEIGHT
|
|
|
|
spwnCtrls.horizontal_scroll_policy = "never"
|
|
|
|
|
2016-12-14 01:46:48 +02:00
|
|
|
if ENABLE_SHARED_SPAWNS then
|
|
|
|
if (global.uniqueSpawns[player.name] ~= nil) then
|
|
|
|
-- This checkbox allows people to join your base when they first
|
|
|
|
-- start the game.
|
|
|
|
spwnCtrls.add{type="checkbox", name="accessToggle",
|
|
|
|
caption="Allow others to join your base.",
|
|
|
|
state=IsSharedSpawnActive(player)}
|
|
|
|
spwnCtrls["accessToggle"].style.top_padding = 10
|
|
|
|
spwnCtrls["accessToggle"].style.bottom_padding = 10
|
|
|
|
ApplyStyle(spwnCtrls["accessToggle"], my_fixed_width_style)
|
|
|
|
end
|
2016-12-02 23:26:49 +02:00
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
-- Sets the player's custom spawn point to their current location
|
|
|
|
if ((tick - global.playerCooldowns[player.name].setRespawn) > RESPAWN_COOLDOWN_TICKS) then
|
|
|
|
spwnCtrls.add{type="button", name="setRespawnLocation", caption="Set New Respawn Location (1 hour cooldown)"}
|
|
|
|
spwnCtrls["setRespawnLocation"].style.font = "default-small-semibold"
|
|
|
|
spwnCtrls.add{name = "respawn_cooldown_note2", type = "label",
|
|
|
|
caption="This will set your respawn point to your current location."}
|
|
|
|
spwnCtrls.add{name = "respawn_cooldown_spacer1", type = "label",
|
|
|
|
caption=" "}
|
|
|
|
ApplyStyle(spwnCtrls.respawn_cooldown_note2, my_note_style)
|
|
|
|
ApplyStyle(spwnCtrls.respawn_cooldown_spacer1, my_spacer_style)
|
|
|
|
else
|
|
|
|
spwnCtrls.add{name = "respawn_cooldown_note1", type = "label",
|
|
|
|
caption="Set Respawn Cooldown Remaining: " .. formattime(RESPAWN_COOLDOWN_TICKS-(tick - global.playerCooldowns[player.name].setRespawn))}
|
|
|
|
spwnCtrls.add{name = "respawn_cooldown_note2", type = "label",
|
|
|
|
caption="This will set your respawn point to your current location."}
|
|
|
|
spwnCtrls.add{name = "respawn_cooldown_spacer1", type = "label",
|
|
|
|
caption=" "}
|
|
|
|
ApplyStyle(spwnCtrls.respawn_cooldown_note1, my_note_style)
|
|
|
|
ApplyStyle(spwnCtrls.respawn_cooldown_note2, my_note_style)
|
|
|
|
ApplyStyle(spwnCtrls.respawn_cooldown_spacer1, my_spacer_style)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
function SpawnCtrlGuiClick(event)
|
|
|
|
if not (event and event.element and event.element.valid) then return end
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
local player = game.players[event.element.player_index]
|
|
|
|
local name = event.element.name
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
if (name == "spwn_ctrls") then
|
|
|
|
ExpandSpawnCtrlGui(player, event.tick)
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2017-04-29 03:19:08 +02:00
|
|
|
if (event.element.parent) then
|
|
|
|
if (event.element.parent.name ~= "spwn_ctrl_panel") then
|
|
|
|
return
|
|
|
|
end
|
2017-04-28 03:48:28 +02:00
|
|
|
end
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
if (name == "accessToggle") then
|
|
|
|
if event.element.state then
|
|
|
|
if DoesPlayerHaveCustomSpawn(player) then
|
2016-12-14 01:46:48 +02:00
|
|
|
if (global.sharedSpawns[player.name] == nil) then
|
|
|
|
CreateNewSharedSpawn(player)
|
|
|
|
else
|
|
|
|
global.sharedSpawns[player.name].openAccess = true
|
|
|
|
end
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
SendBroadcastMsg("New players can now join " .. player.name .. "'s base!")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if (global.sharedSpawns[player.name] ~= nil) then
|
2016-12-14 01:46:48 +02:00
|
|
|
global.sharedSpawns[player.name].openAccess = false
|
2016-12-02 23:26:49 +02:00
|
|
|
SendBroadcastMsg("New players can no longer join " .. player.name .. "'s base!")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Sets a new respawn point and resets the cooldown.
|
|
|
|
if (name == "setRespawnLocation") then
|
|
|
|
if DoesPlayerHaveCustomSpawn(player) then
|
|
|
|
ChangePlayerSpawn(player, player.position)
|
|
|
|
ExpandSpawnCtrlGui(player, event.tick)
|
|
|
|
player.print("Re-spawn point updated!")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|