mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-04 00:15:45 +02:00
spectator mode
This commit is contained in:
parent
e9dc451f6f
commit
6753ae3333
53
maps/biter_hatchery/gui.lua
Normal file
53
maps/biter_hatchery/gui.lua
Normal file
@ -0,0 +1,53 @@
|
||||
local Public = {}
|
||||
|
||||
function Public.spectate_button(player)
|
||||
if player.gui.top.spectate_button then return end
|
||||
local button = player.gui.top.add({type = "button", name = "spectate_button", caption = "Spectate"})
|
||||
button.style.font = "default-bold"
|
||||
button.style.font_color = {r = 0.0, g = 0.0, b = 0.0}
|
||||
button.style.minimal_height = 38
|
||||
button.style.minimal_width = 38
|
||||
button.style.top_padding = 2
|
||||
button.style.left_padding = 4
|
||||
button.style.right_padding = 4
|
||||
button.style.bottom_padding = 2
|
||||
end
|
||||
|
||||
local function create_spectate_confirmation(player)
|
||||
if player.gui.center.spectate_confirmation_frame then return end
|
||||
local frame = player.gui.center.add({type = "frame", name = "spectate_confirmation_frame", caption = "Are you sure you want to spectate this round?"})
|
||||
frame.style.font = "default"
|
||||
frame.style.font_color = {r = 0.3, g = 0.65, b = 0.3}
|
||||
frame.add({type = "button", name = "confirm_spectate", caption = "Spectate"})
|
||||
frame.add({type = "button", name = "cancel_spectate", caption = "Cancel"})
|
||||
end
|
||||
|
||||
local function on_gui_click(event)
|
||||
if not event then return end
|
||||
if not event.element then return end
|
||||
if not event.element.valid then return end
|
||||
local player = game.players[event.element.player_index]
|
||||
if event.element.name == "cancel_spectate" then player.gui.center["spectate_confirmation_frame"].destroy() return end
|
||||
if event.element.name == "confirm_spectate" then
|
||||
player.gui.center["spectate_confirmation_frame"].destroy()
|
||||
if player.character then player.character.die() end
|
||||
player.force = game.forces.player
|
||||
player.character = nil
|
||||
player.set_controller({type=defines.controllers.spectator})
|
||||
game.print(player.name .. " has turned into a spectator ghost.")
|
||||
return
|
||||
end
|
||||
if event.element.name == "spectate_button" then
|
||||
if player.gui.center["spectate_confirmation_frame"] then
|
||||
player.gui.center["spectate_confirmation_frame"].destroy()
|
||||
else
|
||||
create_spectate_confirmation(player)
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local event = require 'utils.event'
|
||||
event.add(defines.events.on_gui_click, on_gui_click)
|
||||
|
||||
return Public
|
@ -3,6 +3,7 @@ local RPG = require "modules.rpg"
|
||||
local unit_raffle = require "maps.biter_hatchery.raffle_tables"
|
||||
local map_functions = require "tools.map_functions"
|
||||
local Terrain = require "maps.biter_hatchery.terrain"
|
||||
local Gui = require "maps.biter_hatchery.gui"
|
||||
local Reset = require "functions.soft_reset"
|
||||
local Map = require "modules.map_info"
|
||||
local math_random = math.random
|
||||
@ -89,11 +90,13 @@ function Public.reset_map()
|
||||
end
|
||||
|
||||
local e = surface.create_entity({name = "biter-spawner", position = {-160, 0}, force = "west"})
|
||||
surface.create_entity({name = "small-worm-turret", position = {-148, 0}, force = "west"})
|
||||
e.active = false
|
||||
global.map_forces.west.hatchery = e
|
||||
global.map_forces.east.target = e
|
||||
|
||||
local e = surface.create_entity({name = "biter-spawner", position = {160, 0}, force = "east"})
|
||||
surface.create_entity({name = "small-worm-turret", position = {148, 0}, force = "east"})
|
||||
e.active = false
|
||||
global.map_forces.east.hatchery = e
|
||||
global.map_forces.west.target = e
|
||||
@ -242,6 +245,9 @@ local function on_entity_died(event)
|
||||
end
|
||||
end
|
||||
|
||||
for _, player in pairs(game.forces.player.connected_players) do
|
||||
player.play_sound{path="utility/game_won", volume_modifier=0.85}
|
||||
end
|
||||
global.game_reset_tick = game.tick + 1800
|
||||
|
||||
for _, player in pairs(game.connected_players) do
|
||||
@ -254,6 +260,8 @@ local function on_player_joined_game(event)
|
||||
local player = game.players[event.player_index]
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
|
||||
Gui.spectate_button(player)
|
||||
|
||||
if player.gui.left.biter_hatchery_game_won then player.gui.left.biter_hatchery_game_won.destroy() end
|
||||
|
||||
if player.surface.index ~= global.active_surface_index then
|
||||
@ -358,6 +366,14 @@ local function on_init()
|
||||
T.sub_caption_color = {r = 0, g = 250, b = 150}
|
||||
|
||||
for key, _ in pairs(global.map_forces) do game.create_force(key) end
|
||||
|
||||
game.forces.west.set_friend("player", true)
|
||||
game.forces.east.set_friend("player", true)
|
||||
game.forces.player.set_friend("west", true)
|
||||
game.forces.player.set_friend("east", true)
|
||||
game.forces.west.share_chart = true
|
||||
game.forces.east.share_chart = true
|
||||
|
||||
Public.reset_map()
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user