2024-08-21 20:46:29 -04:00
|
|
|
-- Spawn control tab in the Oarc GUI, for things like sharing your base with others.
|
|
|
|
|
2024-10-24 09:54:05 -04:00
|
|
|
local RESET_GUI_MAX_WIDTH = 500
|
|
|
|
local RESET_GUI_MAX_HEIGHT = 1000
|
|
|
|
|
2024-08-21 20:46:29 -04:00
|
|
|
---Provides the content of the spawn control tab in the Oarc GUI.
|
|
|
|
---@param tab_container LuaGuiElement
|
|
|
|
---@param player LuaPlayer
|
|
|
|
---@return nil
|
|
|
|
function CreateSpawnControlsTab(tab_container, player)
|
|
|
|
local spwnCtrls = tab_container.add {
|
|
|
|
type = "scroll-pane",
|
2024-10-21 23:11:20 -04:00
|
|
|
vertical_scroll_policy = "auto",
|
2024-09-05 21:15:56 -04:00
|
|
|
}
|
2024-10-21 23:11:20 -04:00
|
|
|
-- ApplyStyle(spwnCtrls, my_fixed_width_style)
|
|
|
|
spwnCtrls.style.maximal_height = GENERIC_GUI_MAX_HEIGHT
|
|
|
|
spwnCtrls.style.padding = 5
|
|
|
|
|
2024-10-24 09:54:05 -04:00
|
|
|
-- Don't show anything WHILE they are still generating a spawn:
|
|
|
|
if PlayerHasDelayedSpawn(player.name--[[@as string]]) then
|
|
|
|
AddLabel(spwnCtrls, nil, { "oarc-spawn-controls-disabled-delayed" }, my_warning_style)
|
|
|
|
return
|
|
|
|
end
|
2024-08-21 20:46:29 -04:00
|
|
|
|
2024-09-19 14:05:29 -04:00
|
|
|
CreatePrimarySpawnInfo(player, spwnCtrls)
|
|
|
|
CreateSecondarySpawnInfo(player, spwnCtrls)
|
2024-09-10 11:40:19 -04:00
|
|
|
CreateSetRespawnLocationButton(player, spwnCtrls)
|
2024-09-12 20:58:19 -04:00
|
|
|
|
2024-10-19 20:48:20 -04:00
|
|
|
if storage.ocfg.gameplay.enable_shared_spawns then
|
2024-09-12 20:58:19 -04:00
|
|
|
CreateSharedSpawnControls(player, spwnCtrls)
|
|
|
|
CreateJoinQueueControls(player, spwnCtrls)
|
|
|
|
end
|
2024-10-24 09:54:05 -04:00
|
|
|
|
|
|
|
CreatePlayerResetControls(spwnCtrls)
|
2024-09-12 20:58:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
---Display some general info about the player's home base (different from respawn point).
|
|
|
|
---There should ONLY be one of these per player? Or maybe there are one per surface
|
|
|
|
---@param player LuaPlayer
|
|
|
|
---@param container LuaGuiElement
|
|
|
|
---@return nil
|
2024-09-19 14:05:29 -04:00
|
|
|
function CreatePrimarySpawnInfo(player, container)
|
2024-09-14 13:59:28 -04:00
|
|
|
local primary_spawn = FindPrimaryUniqueSpawn(player.name)
|
|
|
|
if (primary_spawn == nil) then return end
|
2024-09-12 20:58:19 -04:00
|
|
|
|
2024-09-19 14:05:29 -04:00
|
|
|
AddLabel(container, nil, { "oarc-primary-spawn-info-header" }, "caption_label")
|
|
|
|
AddLabel(container, nil, { "oarc-primary-spawn-info-note" }, my_label_style)
|
2024-09-12 20:58:19 -04:00
|
|
|
|
|
|
|
local horizontal_flow = container.add { type = "flow", direction = "horizontal"}
|
|
|
|
horizontal_flow.style.vertical_align = "center"
|
2024-09-19 14:05:29 -04:00
|
|
|
AddLabel(horizontal_flow, nil, { "oarc-primary-spawn-info-surface-label",
|
2024-09-14 13:59:28 -04:00
|
|
|
primary_spawn.surface_name,
|
|
|
|
primary_spawn.position.x,
|
|
|
|
primary_spawn.position.y}, my_label_style)
|
2024-09-12 20:58:19 -04:00
|
|
|
|
|
|
|
--Add empty widget
|
|
|
|
local dragger = horizontal_flow.add {
|
|
|
|
type = "empty-widget",
|
|
|
|
style = "draggable_space_header"
|
|
|
|
}
|
|
|
|
dragger.style.horizontally_stretchable = true
|
|
|
|
|
2024-09-19 14:05:29 -04:00
|
|
|
CreateGPSButton(horizontal_flow, primary_spawn.surface_name, primary_spawn.position)
|
|
|
|
end
|
|
|
|
|
|
|
|
---Display some general info about the player's secondary spawn points.
|
|
|
|
---@param player LuaPlayer
|
|
|
|
---@param container LuaGuiElement
|
|
|
|
---@return nil
|
|
|
|
function CreateSecondarySpawnInfo(player, container)
|
|
|
|
local secondary_spawns = FindSecondaryUniqueSpawns(player.name)
|
|
|
|
if (secondary_spawns == nil) or (table_size(secondary_spawns) == 0) then return end
|
|
|
|
|
2024-10-24 09:54:05 -04:00
|
|
|
AddSpacerLine(container)
|
2024-09-19 14:05:29 -04:00
|
|
|
AddLabel(container, nil, { "oarc-secondary-spawn-info-header" }, "caption_label")
|
|
|
|
AddLabel(container, nil, { "oarc-secondary-spawn-info-note" }, my_label_style)
|
|
|
|
|
|
|
|
for _,secondary_spawn in pairs(secondary_spawns) do
|
|
|
|
local horizontal_flow = container.add { type = "flow", direction = "horizontal"}
|
|
|
|
horizontal_flow.style.vertical_align = "center"
|
|
|
|
AddLabel(horizontal_flow, nil, { "oarc-secondary-spawn-info-surface-label",
|
|
|
|
secondary_spawn.surface_name,
|
|
|
|
secondary_spawn.position.x,
|
|
|
|
secondary_spawn.position.y}, my_label_style)
|
|
|
|
|
|
|
|
--Add empty widget
|
|
|
|
local dragger = horizontal_flow.add {
|
|
|
|
type = "empty-widget",
|
|
|
|
style = "draggable_space_header"
|
|
|
|
}
|
|
|
|
dragger.style.horizontally_stretchable = true
|
|
|
|
|
|
|
|
CreateGPSButton(horizontal_flow, secondary_spawn.surface_name, secondary_spawn.position)
|
|
|
|
end
|
2024-09-10 11:40:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
---Display the shared spawn controls
|
|
|
|
---@param player LuaPlayer
|
|
|
|
---@param container LuaGuiElement
|
|
|
|
---@return nil
|
|
|
|
function CreateSharedSpawnControls(player, container)
|
2024-09-14 13:59:28 -04:00
|
|
|
local primary_spawn = FindPrimaryUniqueSpawn(player.name)
|
|
|
|
if (primary_spawn == nil) then return end
|
|
|
|
|
2024-10-24 09:54:05 -04:00
|
|
|
AddSpacerLine(container)
|
2024-09-14 13:59:28 -04:00
|
|
|
AddLabel(container, nil, { "oarc-shared-spawn-controls" }, "caption_label")
|
|
|
|
|
|
|
|
local shared_spawn_open = IsSharedSpawnOpen(primary_spawn.surface_name, player.name)
|
|
|
|
local shared_spawn_full = IsSharedSpawnFull(primary_spawn.surface_name, player.name)
|
|
|
|
|
|
|
|
-- This checkbox allows people to join your base when they first start the game.
|
|
|
|
local toggle = container.add {
|
|
|
|
type = "checkbox",
|
|
|
|
name = "accessToggle",
|
|
|
|
tags = { action = "oarc_spawn_ctrl_tab", setting = "shared_access_toggle" },
|
|
|
|
caption = { "oarc-shared-spawn-allow-joiners" },
|
|
|
|
state = shared_spawn_open,
|
|
|
|
enabled = not shared_spawn_full -- Disable if the shared spawn is full
|
|
|
|
}
|
2024-09-12 20:58:19 -04:00
|
|
|
|
2024-09-14 13:59:28 -04:00
|
|
|
if shared_spawn_open and shared_spawn_full then
|
|
|
|
AddLabel(container, nil, { "oarc-shared-spawn-full" }, my_note_style)
|
2024-08-21 20:46:29 -04:00
|
|
|
end
|
2024-09-14 13:59:28 -04:00
|
|
|
|
|
|
|
ApplyStyle(toggle, my_fixed_width_style)
|
2024-09-10 11:40:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
---Display the set respawn location button in the spawn control tab.
|
|
|
|
---@param player LuaPlayer
|
|
|
|
---@param container LuaGuiElement
|
|
|
|
---@return nil
|
|
|
|
function CreateSetRespawnLocationButton(player, container)
|
2024-10-24 09:54:05 -04:00
|
|
|
|
|
|
|
AddSpacerLine(container)
|
2024-09-10 11:40:19 -04:00
|
|
|
AddLabel(container, nil, { "oarc-set-respawn-loc-header" }, "caption_label")
|
2024-08-21 20:46:29 -04:00
|
|
|
|
2024-09-12 20:58:19 -04:00
|
|
|
--[[@type OarcPlayerSpawn]]
|
2024-10-19 20:48:20 -04:00
|
|
|
local respawn_info = storage.player_respawns[player.name][player.surface.name]
|
2024-09-20 21:39:01 -04:00
|
|
|
|
|
|
|
if (respawn_info == nil) then
|
2024-10-23 09:20:01 -04:00
|
|
|
AddLabel(container, nil, { "oarc-no-respawn-this-surface" }, my_warning_style)
|
2024-09-20 21:39:01 -04:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2024-09-19 14:05:29 -04:00
|
|
|
local respawn_surface_name = respawn_info.surface
|
|
|
|
local respawn_position = respawn_info.position
|
2024-09-12 20:58:19 -04:00
|
|
|
|
|
|
|
-- Display the current respawn location
|
2024-09-19 14:05:29 -04:00
|
|
|
local horizontal_flow = container.add { type = "flow", direction = "horizontal"}
|
|
|
|
horizontal_flow.style.vertical_align = "center"
|
|
|
|
AddLabel(horizontal_flow, nil, { "oarc-set-respawn-loc-info-surface-label",
|
|
|
|
respawn_surface_name,
|
|
|
|
respawn_position.x,
|
|
|
|
respawn_position.y }, my_label_style)
|
|
|
|
|
|
|
|
--Add empty widget
|
|
|
|
local dragger = horizontal_flow.add {
|
|
|
|
type = "empty-widget",
|
|
|
|
style = "draggable_space_header"
|
|
|
|
}
|
|
|
|
dragger.style.horizontally_stretchable = true
|
|
|
|
|
2024-10-21 23:11:20 -04:00
|
|
|
local teleport_button = horizontal_flow.add {
|
|
|
|
type = "button",
|
|
|
|
tags = { action = "oarc_spawn_ctrl_tab", setting = "teleport_home", surface = respawn_surface_name, position = respawn_position },
|
|
|
|
caption = { "oarc-teleport-home" },
|
|
|
|
tooltip = { "oarc-teleport-home-tooltip" },
|
|
|
|
style = "green_button"
|
|
|
|
}
|
|
|
|
teleport_button.style.height = 26
|
2024-09-19 14:05:29 -04:00
|
|
|
CreateGPSButton(horizontal_flow, respawn_surface_name, respawn_position)
|
2024-09-12 20:58:19 -04:00
|
|
|
|
2024-08-21 20:46:29 -04:00
|
|
|
-- Sets the player's custom spawn point to their current location
|
2024-10-19 20:48:20 -04:00
|
|
|
if ((game.tick - storage.player_cooldowns[player.name].setRespawn) >
|
|
|
|
(storage.ocfg.gameplay.respawn_cooldown_min * TICKS_PER_MINUTE)) then
|
2024-09-10 11:40:19 -04:00
|
|
|
local change_respawn_button = container.add {
|
2024-09-05 21:15:56 -04:00
|
|
|
type = "button",
|
|
|
|
tags = { action = "oarc_spawn_ctrl_tab", setting = "set_respawn_location" },
|
|
|
|
name = "setRespawnLocation",
|
2024-09-10 11:40:19 -04:00
|
|
|
caption = { "oarc-set-respawn-loc" },
|
|
|
|
tooltip = { "oarc-set-respawn-loc-tooltip" },
|
|
|
|
style = "red_button"
|
2024-09-05 21:15:56 -04:00
|
|
|
}
|
|
|
|
change_respawn_button.style.font = "default-small-semibold"
|
2024-08-21 20:46:29 -04:00
|
|
|
else
|
2024-09-10 11:40:19 -04:00
|
|
|
AddLabel(container, nil,
|
2024-10-19 20:48:20 -04:00
|
|
|
{ "oarc-set-respawn-loc-cooldown", FormatTime((storage.ocfg.gameplay.respawn_cooldown_min * TICKS_PER_MINUTE) -
|
|
|
|
(game.tick - storage.player_cooldowns[player.name].setRespawn)) }, my_note_style)
|
2024-08-21 20:46:29 -04:00
|
|
|
end
|
2024-09-12 20:58:19 -04:00
|
|
|
AddLabel(container, nil, { "oarc-set-respawn-note" }, my_label_style)
|
2024-09-10 11:40:19 -04:00
|
|
|
end
|
2024-08-21 20:46:29 -04:00
|
|
|
|
2024-09-10 11:40:19 -04:00
|
|
|
---Display a list of people in the join queue for a shared spawn.
|
|
|
|
---@param player LuaPlayer
|
|
|
|
---@param container LuaGuiElement
|
|
|
|
---@return nil
|
|
|
|
function CreateJoinQueueControls(player, container)
|
2024-09-14 13:59:28 -04:00
|
|
|
local primary_spawn = FindPrimaryUniqueSpawn(player.name)
|
|
|
|
if (primary_spawn == nil) then return end
|
|
|
|
|
|
|
|
local shared_spawn_open = IsSharedSpawnOpen(primary_spawn.surface_name, player.name)
|
|
|
|
local shared_spawn_full = IsSharedSpawnFull(primary_spawn.surface_name, player.name)
|
|
|
|
|
2024-09-12 20:58:19 -04:00
|
|
|
-- Only show this if the player has an open and not full shared spawn
|
2024-09-14 13:59:28 -04:00
|
|
|
if (not shared_spawn_open or shared_spawn_full) then return end
|
2024-09-12 20:58:19 -04:00
|
|
|
|
2024-09-22 22:18:22 -04:00
|
|
|
if (table_size(primary_spawn.join_queue) > 0) then
|
2024-09-12 20:58:19 -04:00
|
|
|
AddLabel(container, nil, { "oarc-join-queue-header" }, "caption_label")
|
|
|
|
AddLabel(container, "drop_down_msg_lbl1", { "oarc-select-player-join-queue" }, my_label_style)
|
|
|
|
|
|
|
|
local horizontal_flow = container.add { type = "flow", direction = "horizontal" }
|
|
|
|
horizontal_flow.style.horizontally_stretchable = true
|
|
|
|
|
|
|
|
horizontal_flow.add {
|
|
|
|
name = "join_queue_dropdown",
|
|
|
|
type = "drop-down",
|
2024-09-14 13:59:28 -04:00
|
|
|
items = primary_spawn.join_queue
|
2024-09-12 20:58:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
local dragger = horizontal_flow.add {
|
|
|
|
type = "empty-widget",
|
|
|
|
style = "draggable_space_header"
|
|
|
|
}
|
|
|
|
dragger.style.horizontally_stretchable = true
|
|
|
|
|
|
|
|
horizontal_flow.add {
|
|
|
|
name = "accept_player_request",
|
|
|
|
tags = { action = "oarc_spawn_ctrl_tab", setting = "accept_player_request" },
|
|
|
|
type = "button",
|
|
|
|
style = "green_button",
|
|
|
|
caption = { "oarc-accept" }
|
|
|
|
}
|
|
|
|
horizontal_flow.add {
|
|
|
|
name = "reject_player_request",
|
|
|
|
tags = { action = "oarc_spawn_ctrl_tab", setting = "reject_player_request" },
|
|
|
|
type = "button",
|
|
|
|
style = "red_button",
|
|
|
|
caption = { "oarc-reject" }
|
|
|
|
}
|
|
|
|
else
|
|
|
|
AddLabel(container, "empty_join_queue_note1", { "oarc-no-player-join-reqs" }, my_note_style)
|
2024-08-21 20:46:29 -04:00
|
|
|
end
|
2024-09-12 20:58:19 -04:00
|
|
|
|
2024-08-21 20:46:29 -04:00
|
|
|
end
|
|
|
|
|
2024-09-10 11:40:19 -04:00
|
|
|
|
2024-09-19 14:05:29 -04:00
|
|
|
---Display a GPS button for a specific location.
|
|
|
|
---@param container LuaGuiElement
|
|
|
|
---@param surface_name string
|
|
|
|
---@param position MapPosition
|
|
|
|
---@return nil
|
|
|
|
function CreateGPSButton(container, surface_name, position)
|
|
|
|
local gps_button = container.add {
|
|
|
|
type = "sprite-button",
|
|
|
|
sprite = "utility/gps_map_icon",
|
|
|
|
tags = {
|
|
|
|
action = "oarc_spawn_ctrl_tab",
|
|
|
|
setting = "show_location",
|
|
|
|
surface = surface_name,
|
|
|
|
position = position
|
|
|
|
},
|
|
|
|
style = "slot_button",
|
|
|
|
tooltip = { "oarc-spawn-info-location-button-tooltip" },
|
|
|
|
}
|
|
|
|
gps_button.style.width = 28
|
|
|
|
gps_button.style.height = 28
|
|
|
|
end
|
|
|
|
|
2024-10-24 09:54:05 -04:00
|
|
|
---Create the GUI controls for self-resetting the player.
|
|
|
|
---@param container LuaGuiElement
|
|
|
|
---@return nil
|
|
|
|
function CreatePlayerResetControls(container)
|
|
|
|
if not storage.ocfg.gameplay.enable_player_self_reset then return end
|
|
|
|
|
|
|
|
AddSpacerLine(container)
|
|
|
|
AddLabel(container, nil, { "oarc-player-reset-header" }, "caption_label")
|
|
|
|
AddLabel(container, nil, { "oarc-player-reset-note" }, my_longer_label_style)
|
|
|
|
|
|
|
|
local horizontal_flow = container.add { type = "flow", direction = "horizontal" }
|
|
|
|
|
|
|
|
local dragger = horizontal_flow.add {
|
|
|
|
type = "empty-widget",
|
|
|
|
style = "draggable_space_header"
|
|
|
|
}
|
|
|
|
dragger.style.horizontally_stretchable = true
|
|
|
|
|
|
|
|
local reset_button = horizontal_flow.add {
|
|
|
|
type = "button",
|
|
|
|
tags = { action = "oarc_spawn_ctrl_tab", setting = "player_reset" },
|
|
|
|
caption = { "oarc-player-reset" },
|
|
|
|
tooltip = { "oarc-player-reset-tooltip" },
|
|
|
|
style = "red_button"
|
|
|
|
}
|
|
|
|
reset_button.style.font = "default-small-semibold"
|
|
|
|
end
|
|
|
|
|
|
|
|
---Display a confirmation GUI for the player to reset themselves.
|
|
|
|
---@param player LuaPlayer
|
|
|
|
---@return nil
|
|
|
|
function DisplayPlayerResetConfirmationGUI(player)
|
|
|
|
local self_reset_gui = player.gui.screen.add {
|
|
|
|
name = "self_reset_confirm",
|
|
|
|
type = "frame",
|
|
|
|
direction = "vertical",
|
|
|
|
caption = { "oarc-player-reset" }
|
|
|
|
}
|
|
|
|
self_reset_gui.auto_center = true
|
|
|
|
self_reset_gui.style.maximal_width = RESET_GUI_MAX_WIDTH
|
|
|
|
self_reset_gui.style.maximal_height = RESET_GUI_MAX_HEIGHT
|
|
|
|
self_reset_gui.style.padding = 5
|
|
|
|
|
|
|
|
local self_reset_gui_if = self_reset_gui.add {
|
|
|
|
type = "frame",
|
|
|
|
style = "inside_shallow_frame_with_padding",
|
|
|
|
direction = "vertical"
|
|
|
|
}
|
|
|
|
|
|
|
|
AddLabel(self_reset_gui_if, nil, { "oarc-player-reset-are-you-sure" }, my_warning_style)
|
|
|
|
AddSpacer(self_reset_gui_if)
|
|
|
|
|
|
|
|
local horizontal_flow = self_reset_gui_if.add { type = "flow", direction = "horizontal" }
|
|
|
|
horizontal_flow.style.horizontally_stretchable = true
|
|
|
|
|
|
|
|
local cancel_button = horizontal_flow.add {
|
|
|
|
type = "button",
|
|
|
|
tags = { action = "oarc_spawn_ctrl_tab", setting = "player_reset_cancel" },
|
|
|
|
caption = { "oarc-cancel-button-caption" },
|
|
|
|
style = "back_button"
|
|
|
|
}
|
|
|
|
|
|
|
|
local dragger = horizontal_flow.add {
|
|
|
|
type = "empty-widget",
|
|
|
|
style = "draggable_space_header"
|
|
|
|
}
|
|
|
|
dragger.style.horizontally_stretchable = true
|
|
|
|
|
|
|
|
local reset_button = horizontal_flow.add {
|
|
|
|
type = "button",
|
|
|
|
tags = { action = "oarc_spawn_ctrl_tab", setting = "player_reset_confirm" },
|
|
|
|
caption = { "oarc-confirm-button-caption" },
|
|
|
|
tooltip = { "oarc-player-reset" },
|
|
|
|
style = "confirm_button"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2024-08-21 20:46:29 -04:00
|
|
|
---Handle the gui checkboxes & radio buttons of the spawn control tab in the Oarc GUI.
|
|
|
|
---@param event EventData.on_gui_checked_state_changed
|
|
|
|
---@return nil
|
2024-10-06 15:28:16 -04:00
|
|
|
function SpawnCtrlGuiOptionsCheckedStateChanged(event)
|
2024-09-05 21:15:56 -04:00
|
|
|
if not event.element.valid then return end
|
2024-08-21 20:46:29 -04:00
|
|
|
local player = game.players[event.player_index]
|
2024-09-05 21:15:56 -04:00
|
|
|
local tags = event.element.tags
|
2024-08-21 20:46:29 -04:00
|
|
|
|
2024-09-05 21:15:56 -04:00
|
|
|
if (tags.action ~= "oarc_spawn_ctrl_tab") then
|
2024-08-21 20:46:29 -04:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Handle changes to spawn sharing.
|
2024-09-05 21:15:56 -04:00
|
|
|
if (tags.setting == "shared_access_toggle") then
|
2024-08-21 20:46:29 -04:00
|
|
|
if event.element.state then
|
2024-09-12 20:58:19 -04:00
|
|
|
SendBroadcastMsg({ "oarc-start-shared-base", player.name })
|
2024-08-21 20:46:29 -04:00
|
|
|
else
|
2024-09-12 20:58:19 -04:00
|
|
|
SendBroadcastMsg({ "oarc-stop-shared-base", player.name })
|
2024-08-21 20:46:29 -04:00
|
|
|
end
|
2024-09-14 13:59:28 -04:00
|
|
|
local primary_spawn = FindPrimaryUniqueSpawn(player.name)
|
2024-10-19 20:48:20 -04:00
|
|
|
storage.unique_spawns[primary_spawn.surface_name][player.name].open_access = event.element.state
|
2024-09-04 22:21:43 -04:00
|
|
|
OarcGuiRefreshContent(player)
|
2024-08-28 01:36:02 -04:00
|
|
|
|
|
|
|
-- Refresh the shared spawn spawn gui for all players
|
|
|
|
for _,p in pairs(game.connected_players) do
|
|
|
|
RefreshSharedSpawnFrameIfExist(p)
|
|
|
|
end
|
2024-08-21 20:46:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
---Handle the gui click of the spawn control tab in the Oarc GUI.
|
|
|
|
---@param event EventData.on_gui_click
|
|
|
|
---@return nil
|
2024-10-06 15:28:16 -04:00
|
|
|
function SpawnCtrlTabGuiClick(event)
|
2024-09-05 21:15:56 -04:00
|
|
|
if not event.element.valid then return end
|
2024-08-21 20:46:29 -04:00
|
|
|
local player = game.players[event.player_index]
|
2024-09-05 21:15:56 -04:00
|
|
|
local tags = event.element.tags
|
2024-08-21 20:46:29 -04:00
|
|
|
|
2024-09-05 21:15:56 -04:00
|
|
|
if (tags.action ~= "oarc_spawn_ctrl_tab") then
|
2024-08-21 20:46:29 -04:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Sets a new respawn point and resets the cooldown.
|
2024-09-05 21:15:56 -04:00
|
|
|
if (tags.setting == "set_respawn_location") then
|
2024-10-21 23:11:20 -04:00
|
|
|
|
|
|
|
-- Check if the surface is blacklisted
|
|
|
|
local surface_name = player.surface.name
|
|
|
|
if IsSurfaceBlacklisted(surface_name) then
|
|
|
|
player.print("Can't set a respawn point on this surface!")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
SetPlayerRespawn(player.name, surface_name, player.position, true)
|
2024-09-12 20:58:19 -04:00
|
|
|
OarcGuiRefreshContent(player)
|
|
|
|
player.print({ "oarc-spawn-point-updated" })
|
2024-09-05 21:15:56 -04:00
|
|
|
|
2024-09-12 20:58:19 -04:00
|
|
|
-- Shows the spawn location on the map
|
2024-09-19 14:05:29 -04:00
|
|
|
elseif (tags.setting == "show_location") then
|
|
|
|
local surface_name = tags.surface --[[@as string]]
|
|
|
|
local position = tags.position --[[@as MapPosition]]
|
2024-10-21 13:48:42 -04:00
|
|
|
|
|
|
|
player.set_controller{type = defines.controllers.remote, position = position, surface = surface_name}
|
2024-10-21 23:11:20 -04:00
|
|
|
player.print({"", { "oarc-spawn-gps-location" }, GetGPStext(surface_name, position)})
|
|
|
|
|
|
|
|
-- Teleports the player to their home base
|
|
|
|
elseif (tags.setting == "teleport_home") then
|
|
|
|
local surface_name = tags.surface --[[@as string]]
|
|
|
|
local position = tags.position --[[@as MapPosition]]
|
2024-10-23 09:20:01 -04:00
|
|
|
|
|
|
|
--TODO Verify player is still on the same surface, if they leave the GUI open, they can teleport back from any surface.
|
|
|
|
|
2024-10-21 23:11:20 -04:00
|
|
|
SafeTeleport(player, game.surfaces[surface_name], position)
|
2024-08-21 20:46:29 -04:00
|
|
|
|
2024-10-24 09:54:05 -04:00
|
|
|
-- Self reset the player
|
|
|
|
elseif (tags.setting == "player_reset") then
|
|
|
|
DisplayPlayerResetConfirmationGUI(player)
|
|
|
|
|
|
|
|
-- Cancel the self reset
|
|
|
|
elseif (tags.setting == "player_reset_cancel") then
|
|
|
|
if (player.gui.screen.self_reset_confirm) then
|
|
|
|
player.gui.screen.self_reset_confirm.destroy()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Confirm the self reset
|
|
|
|
elseif (tags.setting == "player_reset_confirm") then
|
|
|
|
if (player.gui.screen.self_reset_confirm) then
|
|
|
|
player.gui.screen.self_reset_confirm.destroy()
|
|
|
|
end
|
|
|
|
RemoveOrResetPlayer(player, false)
|
|
|
|
|
2024-08-21 20:46:29 -04:00
|
|
|
-- Accept or reject pending player join requests to a shared base
|
2024-09-05 21:15:56 -04:00
|
|
|
elseif ((tags.setting == "accept_player_request") or (tags.setting == "reject_player_request")) then
|
2024-09-12 20:58:19 -04:00
|
|
|
|
2024-08-21 20:46:29 -04:00
|
|
|
if ((event.element.parent.join_queue_dropdown == nil) or
|
|
|
|
(event.element.parent.join_queue_dropdown.selected_index == 0)) then
|
2024-09-05 21:15:56 -04:00
|
|
|
player.print({ "oarc-selected-player-not-valid" })
|
2024-09-04 22:21:43 -04:00
|
|
|
OarcGuiRefreshContent(player)
|
2024-08-21 20:46:29 -04:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2024-09-14 13:59:28 -04:00
|
|
|
local join_queue_index = event.element.parent.join_queue_dropdown.selected_index
|
|
|
|
local join_queue_player_choice = event.element.parent.join_queue_dropdown.get_item(join_queue_index) --[[@as string]]
|
2024-08-21 20:46:29 -04:00
|
|
|
|
2024-09-05 21:15:56 -04:00
|
|
|
-- Shouldn't be able to hit this since we force a GUI refresh when they leave?
|
2024-09-14 13:59:28 -04:00
|
|
|
if ((game.players[join_queue_player_choice] == nil) or (not game.players[join_queue_player_choice].connected)) then
|
2024-08-21 20:46:29 -04:00
|
|
|
player.print({ "oarc-selected-player-not-wait" })
|
2024-09-04 22:21:43 -04:00
|
|
|
OarcGuiRefreshContent(player)
|
2024-08-21 20:46:29 -04:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2024-09-14 13:59:28 -04:00
|
|
|
local primary_spawn = FindPrimaryUniqueSpawn(player.name)
|
2024-08-21 20:46:29 -04:00
|
|
|
|
2024-09-05 21:15:56 -04:00
|
|
|
if (tags.setting == "reject_player_request") then
|
|
|
|
|
2024-09-14 13:59:28 -04:00
|
|
|
RemovePlayerFromJoinQueue(join_queue_player_choice) -- This also refreshes the host gui
|
2024-09-04 22:21:43 -04:00
|
|
|
|
|
|
|
-- Inform the host that the player was rejected
|
2024-09-14 13:59:28 -04:00
|
|
|
player.print({ "oarc-reject-joiner", join_queue_player_choice })
|
2024-09-04 22:21:43 -04:00
|
|
|
-- Inform the player that their request was rejected
|
2024-09-14 13:59:28 -04:00
|
|
|
SendMsg(join_queue_player_choice, { "oarc-your-request-rejected" })
|
2024-08-21 20:46:29 -04:00
|
|
|
|
|
|
|
-- Close the waiting players menu
|
2024-09-14 13:59:28 -04:00
|
|
|
if (game.players[join_queue_player_choice].gui.screen.join_shared_spawn_wait_menu) then
|
|
|
|
game.players[join_queue_player_choice].gui.screen.join_shared_spawn_wait_menu.destroy()
|
|
|
|
DisplaySpawnOptions(game.players[join_queue_player_choice])
|
2024-08-21 20:46:29 -04:00
|
|
|
end
|
|
|
|
|
2024-09-05 21:15:56 -04:00
|
|
|
elseif (tags.setting == "accept_player_request") then
|
|
|
|
|
2024-09-11 21:20:00 -04:00
|
|
|
-- Check if there is space first
|
2024-10-19 20:48:20 -04:00
|
|
|
if (table_size(primary_spawn.joiners) >= storage.ocfg.gameplay.number_of_players_per_shared_spawn - 1) then
|
2024-09-11 12:49:23 -04:00
|
|
|
player.print({ "oarc-shared-spawn-full" })
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2024-09-05 21:15:56 -04:00
|
|
|
-- Send an announcement
|
2024-09-14 13:59:28 -04:00
|
|
|
SendBroadcastMsg({ "oarc-player-joining-base", join_queue_player_choice, player.name })
|
2024-09-04 22:21:43 -04:00
|
|
|
|
2024-09-05 21:15:56 -04:00
|
|
|
-- Close the waiting players menu
|
2024-09-14 13:59:28 -04:00
|
|
|
if (game.players[join_queue_player_choice].gui.screen.join_shared_spawn_wait_menu) then
|
|
|
|
game.players[join_queue_player_choice].gui.screen.join_shared_spawn_wait_menu.destroy()
|
2024-08-21 20:46:29 -04:00
|
|
|
end
|
|
|
|
|
2024-09-05 21:15:56 -04:00
|
|
|
-- Spawn the player
|
2024-09-14 13:59:28 -04:00
|
|
|
local joining_player = game.players[join_queue_player_choice]
|
2024-09-19 13:19:57 -04:00
|
|
|
SetPlayerRespawn(joining_player.name, primary_spawn.surface_name, primary_spawn.position, true)
|
2024-09-14 13:59:28 -04:00
|
|
|
SendPlayerToSpawn(primary_spawn.surface_name, joining_player)
|
|
|
|
GivePlayerStarterItems(joining_player)
|
2024-10-19 20:48:20 -04:00
|
|
|
table.insert(storage.unique_spawns[primary_spawn.surface_name][player.name].joiners, joining_player.name)
|
2024-09-14 13:59:28 -04:00
|
|
|
joining_player.force = game.players[player.name].force
|
2024-08-21 20:46:29 -04:00
|
|
|
|
2024-09-05 21:15:56 -04:00
|
|
|
-- Render some welcoming text...
|
2024-09-14 13:59:28 -04:00
|
|
|
DisplayWelcomeGroundTextAtSpawn(joining_player, primary_spawn.surface_name, primary_spawn.position)
|
2024-09-04 22:21:43 -04:00
|
|
|
|
2024-09-05 21:15:56 -04:00
|
|
|
-- Unlock spawn control gui tab
|
2024-09-14 13:59:28 -04:00
|
|
|
SetOarcGuiTabEnabled(joining_player, OARC_SPAWN_CTRL_TAB_NAME, true)
|
2024-09-12 20:58:19 -04:00
|
|
|
|
2024-09-14 13:59:28 -04:00
|
|
|
RemovePlayerFromJoinQueue(join_queue_player_choice) -- This also refreshes the host gui
|
2024-08-21 20:46:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|