1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-10-30 23:47:41 +02:00

Add new tab to admin panel - scenario history

This commit is contained in:
Gerkiz
2023-09-17 16:28:11 +02:00
parent aa6da86e70
commit 305dae5277
5 changed files with 67 additions and 10 deletions

View File

@@ -35,6 +35,7 @@ local this = {
message_history = {},
cancel_crafting_history = {},
deconstruct_history = {},
scenario_history = {},
whitelist_types = {},
permission_group_editing = {},
players_warned = {},
@@ -1167,6 +1168,28 @@ function Public.damage_entity_threshold(value)
return this.damage_entity_threshold
end
--- Appends a new message to the scenario history tab in the admin panel.
---@param message string
function Public.append_scenario_history(player, entity, message)
if not this.scenario_history then
this.scenario_history = {}
end
if #this.scenario_history > this.limit + 8000 then
this.scenario_history = {}
end
local t = abs(floor((game.tick) / 60))
t = FancyTime.short_fancy_time(t)
local str = '[' .. t .. '] '
str = str .. '[color=yellow]' .. message .. '[/color]'
str = str .. ' at X:'
str = str .. floor(entity.position.x)
str = str .. ' Y:'
str = str .. floor(entity.position.y)
str = str .. ' '
str = str .. 'surface:' .. player.surface.index
increment(this.scenario_history, str)
end
--- Returns the table.
---@param key string|nil
function Public.get(key)

View File

@@ -42,13 +42,17 @@ local function remove_player_data(player)
end
local player_data = this.players[player.index]
if player_data then
if player_data.render_object then
rendering.destroy(player_data.render_object)
end
this.players[player.index] = nil
end
end
local function remove_camera_frame(player)
if player.gui.center[locate_player_frame_name] then
player.gui.center[locate_player_frame_name].destroy()
if player.gui.screen[locate_player_frame_name] then
player.gui.screen[locate_player_frame_name].destroy()
remove_player_data(player)
return
end
@@ -78,43 +82,65 @@ local function validate_frame(frame)
return true
end
local function create_mini_camera_gui(player, target)
local function create_mini_camera_gui(player, target, zoom, render)
if not player or not player.valid then
return
end
if player.gui.center[locate_player_frame_name] then
player.gui.center[locate_player_frame_name].destroy()
if player.gui.screen[locate_player_frame_name] then
player.gui.screen[locate_player_frame_name].destroy()
remove_player_data(player)
return
end
local player_data
if validate_player(target) then
local player_data = create_player_data(player)
player_data = create_player_data(player)
player_data.target = target
else
remove_player_data(player)
return
end
local frame = player.gui.center[locate_player_frame_name]
local frame = player.gui.screen[locate_player_frame_name]
if not validate_frame(frame) then
frame = player.gui.center.add({type = 'frame', name = locate_player_frame_name, caption = target.name})
frame = player.gui.screen.add({type = 'frame', name = locate_player_frame_name, caption = target.name})
end
frame.force_auto_center()
local surface = tonumber(target.surface.index)
if frame[player_frame_name] and frame[player_frame_name].valid then
frame[player_frame_name].destroy()
end
if render then
local render_object =
rendering.draw_text {
text = '',
surface = target.surface,
target = {target.position.x, target.position.y - 3},
color = {r = 0.98, g = 0.66, b = 0.22},
scale = 3,
players = {player.index},
font = 'heading-1',
alignment = 'center',
scale_with_zoom = false
}
if player_data then
player_data.render_object = render_object
end
end
local camera =
frame.add(
{
type = 'camera',
name = player_frame_name,
position = target.position,
zoom = 0.4,
zoom = zoom or 0.4,
surface_index = surface
}
)

View File

@@ -4,6 +4,7 @@ return {
-- See features.server.to_discord_named
channel_names = {
mtn_channel = 'mount-fortress',
scenario_notifications = 'scenario-notifications',
bb_channel = 'biter_battles',
bot_quarters = 'bot-quarters',
announcements = 'announcements',

View File

@@ -58,6 +58,9 @@ local main_frame_name = Public.uid_name()
local main_button_name = Public.uid_name()
local close_button_name = Public.uid_name()
Public.button_style = 'mod_gui_button'
Public.frame_style = 'non_draggable_frame'
Public.top_main_gui_button = main_button_name
Public.main_frame_name = main_frame_name

View File

@@ -248,7 +248,8 @@ local function draw_events(data)
['Landfill History'] = antigrief.landfill_history,
['Corpse Looting History'] = antigrief.corpse_history,
['Cancel Crafting History'] = antigrief.cancel_crafting_history,
['Deconstruct History'] = antigrief.deconstruct_history
['Deconstruct History'] = antigrief.deconstruct_history,
['Scenario History'] = antigrief.scenario_history
}
local scroll_pane
@@ -516,6 +517,9 @@ local function create_admin_panel(data)
if antigrief.deconstruct_history then
table.insert(histories, 'Deconstruct History')
end
if antigrief.scenario_history then
table.insert(histories, 'Scenario History')
end
if #histories == 0 then
return