mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-08 00:39:30 +02:00
where module
clicking a player name in the player list now follows that player.
This commit is contained in:
parent
507ad4e65e
commit
12aa64706e
@ -2,9 +2,35 @@
|
||||
|
||||
local Color = require 'utils.color_presets'
|
||||
local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
|
||||
local this = {
|
||||
players = {}
|
||||
}
|
||||
|
||||
Global.register(
|
||||
this,
|
||||
function(t)
|
||||
this = t
|
||||
end
|
||||
)
|
||||
|
||||
local Public = {}
|
||||
|
||||
local function get_player_data(player, remove)
|
||||
local player_data = this.players[player.index]
|
||||
if player_data then
|
||||
if not remove then
|
||||
return player_data
|
||||
else
|
||||
this.players[player.index] = nil
|
||||
end
|
||||
end
|
||||
|
||||
this.players[player.index] = {}
|
||||
return this.players[player.index]
|
||||
end
|
||||
|
||||
local function validate_player(player)
|
||||
if not player then
|
||||
return false
|
||||
@ -24,12 +50,33 @@ local function validate_player(player)
|
||||
return true
|
||||
end
|
||||
|
||||
local function create_mini_camera_gui(player, caption, position, surface)
|
||||
if player.gui.center['where_camera'] then
|
||||
local function create_mini_camera_gui(player, caption, position, surface, refresh)
|
||||
local target_player = game.players[caption]
|
||||
|
||||
if validate_player(target_player) then
|
||||
local player_data = get_player_data(player)
|
||||
player_data.target_player = target_player
|
||||
else
|
||||
get_player_data(player, true)
|
||||
player.print('Please type a name of a player who is connected.', Color.warning)
|
||||
return
|
||||
end
|
||||
|
||||
if player.gui.center['where_camera'] and not refresh then
|
||||
player.gui.center['where_camera'].destroy()
|
||||
end
|
||||
local frame = player.gui.center.add({type = 'frame', name = 'where_camera', caption = caption})
|
||||
|
||||
local frame = player.gui.center.where_camera
|
||||
if not frame then
|
||||
frame = player.gui.center.add({type = 'frame', name = 'where_camera', caption = caption})
|
||||
end
|
||||
|
||||
surface = tonumber(surface)
|
||||
|
||||
if frame.where_camera then
|
||||
frame.where_camera.destroy()
|
||||
end
|
||||
|
||||
local camera =
|
||||
frame.add(
|
||||
{
|
||||
@ -57,8 +104,11 @@ commands.add_command(
|
||||
local target_player = game.players[cmd.parameter]
|
||||
|
||||
if validate_player(target_player) then
|
||||
local player_data = get_player_data(player)
|
||||
player_data.target_player = target_player
|
||||
create_mini_camera_gui(player, target_player.name, target_player.position, target_player.surface.index)
|
||||
else
|
||||
get_player_data(player, true)
|
||||
player.print('Please type a name of a player who is connected.', Color.warning)
|
||||
end
|
||||
else
|
||||
@ -78,12 +128,35 @@ local function on_gui_click(event)
|
||||
|
||||
if name == 'where_camera' then
|
||||
player.gui.center['where_camera'].destroy()
|
||||
get_player_data(player, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local function on_nth_tick()
|
||||
local players = game.connected_players
|
||||
for i = 1, #players do
|
||||
local player = players[i]
|
||||
|
||||
local player_data = get_player_data(player)
|
||||
if player_data and player_data.target_player then
|
||||
local target_player = player_data.target_player
|
||||
|
||||
if not validate_player(target_player) then
|
||||
get_player_data(player, true)
|
||||
goto continue
|
||||
end
|
||||
|
||||
create_mini_camera_gui(player, target_player.name, target_player.position, target_player.surface.index, true)
|
||||
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Public.create_mini_camera_gui = create_mini_camera_gui
|
||||
|
||||
Event.add(defines.events.on_gui_click, on_gui_click)
|
||||
Event.on_nth_tick(2, on_nth_tick)
|
||||
|
||||
return Public
|
||||
|
Loading…
Reference in New Issue
Block a user