1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-26 03:52:22 +02:00

Merge pull request #256 from ComfyFactory/issues

fix minor gui issues
This commit is contained in:
Gerkiz 2022-04-23 18:24:17 +02:00 committed by GitHub
commit 72e27238d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 114 additions and 22 deletions

92
modules/rpg/test.lua Normal file
View File

@ -0,0 +1,92 @@
local states = {
['attack'] = 'nuclear-smoke',
['support'] = 'poison-capsule-smoke'
}
local Task = require 'utils.task'
local Token = require 'utils.token'
local smokes = {
'artillery-smoke',
'car-smoke',
'fire-smoke',
'fire-smoke-on-adding-fuel',
'fire-smoke-without-glow',
'light-smoke',
'nuclear-smoke',
'poison-capsule-particle-smoke',
'poison-capsule-smoke',
'smoke',
'smoke-building',
'smoke-explosion-lower-particle-small',
'smoke-explosion-particle',
'smoke-explosion-particle-small',
'smoke-explosion-particle-stone-small',
'smoke-explosion-particle-tiny',
'smoke-fast',
'smoke-train-stop',
'soft-fire-smoke',
'tank-smoke',
'train-smoke',
'turbine-smoke'
}
local function get_area(pos, dist)
local area = {
left_top = {
x = pos.x - dist,
y = pos.y - dist
},
right_bottom = {
x = pos.x + dist,
y = pos.y + dist
}
}
return area
end
local do_something_token =
Token.register(
function(event)
local cs = event.cs
local smoke = event.smoke
local p = event.p
cs.create_trivial_smoke({name = smoke, position = p})
game.print(smoke)
end
)
local function area_of_effect(player, state, radius)
if not radius then
return
end
local cs = player.surface
local cp = player.position
if radius and radius > 256 then
radius = 256
end
local area = get_area(cp, radius)
if not states[state] then
return
end
for x = area.left_top.x, area.right_bottom.x, 1 do
for y = area.left_top.y, area.right_bottom.y, 1 do
local d = math.floor((cp.x - x) ^ 2 + (cp.y - y) ^ 2)
if d < radius then
local p = {x = x, y = y}
local c = 10
for _, smoke in pairs(smokes) do
c = c + 200
Task.set_timeout_in_ticks(c, do_something_token, {cs = cs, smoke = smoke, p = p})
end
end
end
end
end
area_of_effect(game.player, 'attack', 32)

View File

@ -54,13 +54,7 @@ local function validate_player(player)
if not player.valid then if not player.valid then
return false return false
end end
if not player.character then if player.admin then
return false
end
if not player.connected then
return false
end
if not game.players[player.index] then
return false return false
end end
return true return true
@ -77,30 +71,31 @@ local function validate_frame(frame)
return true return true
end end
local function create_mini_camera_gui(player, caption, position, surface) local function create_mini_camera_gui(player, target)
if not player or not player.valid then
return
end
if player.gui.center[locate_player_frame_name] then if player.gui.center[locate_player_frame_name] then
player.gui.center[locate_player_frame_name].destroy() player.gui.center[locate_player_frame_name].destroy()
remove_player_data(player) remove_player_data(player)
return return
end end
local target_player = game.players[caption] if validate_player(target) then
if validate_player(target_player) then
local player_data = create_player_data(player) local player_data = create_player_data(player)
player_data.target_player = target_player player_data.target = target
else else
remove_player_data(player) remove_player_data(player)
player.print('[Where] Please type a name of a player who is connected.', Color.warning)
return return
end end
local frame = player.gui.center[locate_player_frame_name] local frame = player.gui.center[locate_player_frame_name]
if not validate_frame(frame) then if not validate_frame(frame) then
frame = player.gui.center.add({type = 'frame', name = locate_player_frame_name, caption = caption}) frame = player.gui.center.add({type = 'frame', name = locate_player_frame_name, caption = target.name})
end end
surface = tonumber(surface) local surface = tonumber(target.surface.index)
if frame[player_frame_name] and frame[player_frame_name].valid then if frame[player_frame_name] and frame[player_frame_name].valid then
frame[player_frame_name].destroy() frame[player_frame_name].destroy()
@ -111,7 +106,7 @@ local function create_mini_camera_gui(player, caption, position, surface)
{ {
type = 'camera', type = 'camera',
name = player_frame_name, name = player_frame_name,
position = position, position = target.position,
zoom = 0.4, zoom = 0.4,
surface_index = surface surface_index = surface
} }
@ -132,12 +127,13 @@ commands.add_command(
if not cmd.parameter then if not cmd.parameter then
return return
end end
local target_player = game.players[cmd.parameter]
local target_player = game.get_player(cmd.parameter)
if validate_player(target_player) then if validate_player(target_player) then
local player_data = create_player_data(player) local player_data = create_player_data(player)
player_data.target_player = target_player player_data.target_player = target_player
create_mini_camera_gui(player, target_player.name, target_player.position, target_player.surface.index) create_mini_camera_gui(player, target_player)
else else
remove_player_data(player) remove_player_data(player)
player.print('[Where] Please type a name of a player who is connected.', Color.warning) player.print('[Where] Please type a name of a player who is connected.', Color.warning)

View File

@ -635,7 +635,7 @@ local function player_list_show(data)
if game.players[player_list[i].name].admin then if game.players[player_list[i].name].admin then
trusted = '[color=red][A][/color]' .. trusted trusted = '[color=red][A][/color]' .. trusted
tooltip = 'This player is an admin of this server.' .. minimap .. tooltip tooltip = 'This player is an admin of this server.' .. tooltip
elseif jailed[player_list[i].name] then elseif jailed[player_list[i].name] then
trusted = '[color=orange][J][/color]' .. trusted trusted = '[color=orange][J][/color]' .. trusted
tooltip = 'This player is currently jailed.' .. minimap .. tooltip tooltip = 'This player is currently jailed.' .. minimap .. tooltip
@ -857,16 +857,16 @@ local function on_gui_click(event)
end end
--Locate other players --Locate other players
local index = tonumber(element.name) local index = tonumber(element.name)
if index and game.players[index] and index == game.players[index].index then if index and game.get_player(index) and index == game.get_player(index).index then
local is_spamming = SpamProtection.is_spamming(player, nil, 'PlayerList Locate Player') local is_spamming = SpamProtection.is_spamming(player, nil, 'PlayerList Locate Player')
if is_spamming then if is_spamming then
return return
end end
local target = game.players[index] local target = game.get_player(index)
if not target or not target.valid then if not target or not target.valid then
return return
end end
Where.create_mini_camera_gui(player, target.name, target.position, target.surface.index) Where.create_mini_camera_gui(player, target)
end end
--Poke other players --Poke other players
if string.sub(element.name, 1, 11) == 'poke_player' then if string.sub(element.name, 1, 11) == 'poke_player' then

View File

@ -636,6 +636,10 @@ local function create_poll(event)
local player = event.player local player = event.player
local data = Gui.get_data(event.element) local data = Gui.get_data(event.element)
if not data then
return
end
local frame = data.frame local frame = data.frame
local question = data.question local question = data.question