mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-18 03:21:47 +02:00
commit
2902115141
@ -695,3 +695,12 @@ commands.add_command(
|
||||
unjail_player
|
||||
)
|
||||
commands.add_command('a', 'Admin chat. Messages all other admins (Admins only)', admin_chat)
|
||||
|
||||
local Report = require('report')
|
||||
commands.add_command('showreports', 'Shows user reports (Admins only)',
|
||||
function(event)
|
||||
if game.player and game.player.admin then
|
||||
Report.show_reports(game.players[event.player_index])
|
||||
end
|
||||
end
|
||||
)
|
||||
|
65
report.lua
65
report.lua
@ -14,16 +14,17 @@ global.player_report_data = {}
|
||||
|
||||
local function draw_report(parent, report_id)
|
||||
local report = global.reports[report_id]
|
||||
if report_id == 0 or not report then
|
||||
parent.add {type = "label", caption="No reports yet."}
|
||||
return
|
||||
end
|
||||
local reported_player_name = game.players[report.reported_player_index].name
|
||||
local reporting_player_name = game.players[report.reporting_player_index].name
|
||||
local time = Utils.format_time(report.tick)
|
||||
local time_ago = Utils.format_time(game.tick - report.tick)
|
||||
|
||||
local message = report.message
|
||||
for _,child in pairs(parent.children) do
|
||||
Gui.remove_data_recursivly(child)
|
||||
child.destroy()
|
||||
end
|
||||
Gui.clear(parent)
|
||||
|
||||
parent.add {type="label", caption="Offender: " .. reported_player_name}
|
||||
local msg_label_pane = parent.add {type="scroll-pane", vertical_scroll_policy = "auto-and-reserve-space", horizontal_scroll_policy="never"}
|
||||
@ -35,16 +36,17 @@ local function draw_report(parent, report_id)
|
||||
parent.add {type="label", caption="Reported by: " .. reporting_player_name}
|
||||
end
|
||||
|
||||
local function show_reports(player)
|
||||
Module.show_reports = function(player)
|
||||
local reports = global.reports or {}
|
||||
|
||||
local center = player.gui.center
|
||||
if player.opened then --Destroy whatever is open
|
||||
Gui.remove_data_recursivly(player.opened)
|
||||
player.opened.destroy()
|
||||
|
||||
local report_frame = center[report_frame_name]
|
||||
if report_frame and report_frame.valid then
|
||||
Gui.destroy(report_frame)
|
||||
end
|
||||
|
||||
local report_frame = center.add {
|
||||
|
||||
report_frame = center.add {
|
||||
type = 'frame',
|
||||
name = report_frame_name,
|
||||
direction = 'vertical',
|
||||
@ -61,13 +63,13 @@ local function show_reports(player)
|
||||
button_cell.add {
|
||||
type="button",
|
||||
name=report_tab_button_name,
|
||||
caption = game.players[report.reporting_player_index].name
|
||||
caption = game.players[report.reported_player_index].name
|
||||
}
|
||||
end
|
||||
end
|
||||
local report_body = report_frame.add {type = "scroll-pane", name = report_body_name, horizontal_scroll_policy = "never", vertical_scroll_policy="never"}
|
||||
report_frame.add {type = 'button', name = report_close_button_name, caption = 'Close'}
|
||||
|
||||
|
||||
draw_report(report_body, #reports)
|
||||
end
|
||||
|
||||
@ -77,14 +79,14 @@ local function report(reporting_player, reported_player, message)
|
||||
local notified = false
|
||||
for _,p in pairs(game.players) do
|
||||
if p.admin and p.connected then
|
||||
show_reports(p)
|
||||
Module.show_reports(p)
|
||||
if p.afk_time < 3600 then notified = true end
|
||||
end
|
||||
end
|
||||
if not notified then
|
||||
for _,p in pairs(game.players) do
|
||||
if p.admin then
|
||||
show_reports(p)
|
||||
Module.show_reports(p)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -93,16 +95,14 @@ end
|
||||
Gui.on_custom_close(
|
||||
report_frame_name,
|
||||
function(event)
|
||||
Gui.remove_data_recursivly(event.element)
|
||||
event.element.destroy()
|
||||
Gui.destroy(event.element)
|
||||
end
|
||||
)
|
||||
|
||||
Gui.on_click(
|
||||
report_close_button_name,
|
||||
function(event)
|
||||
Gui.remove_data_recursivly(event.element.parent)
|
||||
event.element.parent.destroy()
|
||||
Gui.destroy(event.element.parent)
|
||||
end
|
||||
)
|
||||
|
||||
@ -125,13 +125,13 @@ local reporting_input_name = Gui.uid_name()
|
||||
|
||||
Module.spawn_reporting_popup = function(player, reported_player)
|
||||
|
||||
local center = player.gui.center
|
||||
if player.opened then --Destroy whatever is open
|
||||
Gui.remove_data_recursivly(player.opened)
|
||||
player.opened.destroy()
|
||||
end
|
||||
local center = player.gui.center
|
||||
|
||||
local reporting_popup = center.add {
|
||||
local reporting_popup = center[reporting_popup_name]
|
||||
if reporting_popup and reporting_popup.valid then
|
||||
Gui.destroy(reporting_popup)
|
||||
end
|
||||
reporting_popup = center.add {
|
||||
type = 'frame',
|
||||
name = reporting_popup_name,
|
||||
direction = 'vertical',
|
||||
@ -157,8 +157,7 @@ end
|
||||
Gui.on_custom_close(
|
||||
reporting_popup_name,
|
||||
function(event)
|
||||
Gui.remove_data_recursivly(event.element)
|
||||
event.element.destroy()
|
||||
Gui.destroy(event.element)
|
||||
end
|
||||
)
|
||||
|
||||
@ -166,8 +165,7 @@ Gui.on_click(
|
||||
reporting_cancel_button_name,
|
||||
function(event)
|
||||
local frame = event.element.parent.parent
|
||||
Gui.remove_data_recursivly(frame)
|
||||
frame.destroy()
|
||||
Gui.destroy(frame)
|
||||
end
|
||||
)
|
||||
|
||||
@ -179,20 +177,11 @@ Gui.on_click(
|
||||
local data = Gui.get_data(frame)
|
||||
local reported_player_index = data["reported_player_index"]
|
||||
|
||||
Gui.remove_data_recursivly(frame)
|
||||
frame.destroy()
|
||||
Gui.destroy(frame)
|
||||
report(event.player, game.players[reported_player_index], msg)
|
||||
|
||||
event.player.print("Sucessfully reported " .. game.players[reported_player_index].name)
|
||||
end
|
||||
)
|
||||
|
||||
commands.add_command('showreports', 'Shows user reports (Admins only)',
|
||||
function(event)
|
||||
if game.player and game.player.admin then
|
||||
show_reports(game.players[event.player_index])
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
return Module
|
||||
|
Loading…
x
Reference in New Issue
Block a user