Added reason entry

This commit is contained in:
Cooldude2606
2019-05-26 20:38:51 +01:00
parent 42de74fa4f
commit e7353e331f
2 changed files with 99 additions and 10 deletions

View File

@@ -4,8 +4,10 @@ local Store = require 'expcore.store'
local Game = require 'utils.game' local Game = require 'utils.game'
local Reports = require 'modules.addons.reports-control' local Reports = require 'modules.addons.reports-control'
local Jail = require 'modules.addons.jail-control' local Jail = require 'modules.addons.jail-control'
local format_chat_player_name = ext_require('expcore.common','format_chat_player_name')
local action_player_store = 'gui.left.player-list.action-player' local action_player_store = 'gui.left.player-list.action-player'
local action_name_store = 'gui.left.player-list.action-name'
local function tool_button_style(style) local function tool_button_style(style)
Gui.set_padding_style(style,-1,-1,-1,-1) Gui.set_padding_style(style,-1,-1,-1,-1)
@@ -24,7 +26,8 @@ end
local function get_action_player(player) local function get_action_player(player)
local action_player_name = Store.get_child(action_player_store,player.name) local action_player_name = Store.get_child(action_player_store,player.name)
local action_player = Game.get_player_from_any(action_player_name) local action_player = Game.get_player_from_any(action_player_name)
return action_player local action_player_name_color = format_chat_player_name(action_player)
return action_player,action_player_name_color
end end
local function teleport(from_player,to_player) local function teleport(from_player,to_player)
@@ -74,29 +77,46 @@ Gui.new_button()
:set_tooltip('Report player') :set_tooltip('Report player')
:set_style('tool_button',tool_button_style) :set_style('tool_button',tool_button_style)
:on_click(function(player,element) :on_click(function(player,element)
local action_player = get_action_player(player) Store.set_child(action_name_store,player.name,'command/report')
Reports.report_player(action_player,reason,player.name)
end) end)
local function report_player_callback(player,reason)
local action_player,action_player_name_color = get_action_player(player)
local by_player_name_color = format_chat_player_name(player)
game.print{'expcom-report.non-admin',action_player_name_color,reason}
Roles.print_to_roles_higher('Trainee',{'expcom-report.admin',action_player_name_color,by_player_name_color,reason})
Reports.report_player(action_player,reason,player.name)
end
local jail_player = local jail_player =
Gui.new_button() Gui.new_button()
:set_sprites('utility/item_editor_icon') :set_sprites('utility/item_editor_icon')
:set_tooltip('Jail player') :set_tooltip('Jail player')
:set_style('tool_button',tool_button_style) :set_style('tool_button',tool_button_style)
:on_click(function(player,element) :on_click(function(player,element)
local action_player = get_action_player(player) Store.set_child(action_name_store,player.name,'command/jail')
Jail.jail_player(action_player,player.name)
end) end)
local function jail_player_callback(player,reason)
local action_player,action_player_name_color = get_action_player(player)
local by_player_name_color = format_chat_player_name(player)
game.print{'expcom-jail.give',action_player_name_color,by_player_name_color,reason}
Jail.jail_player(action_player,player.name)
end
local temp_ban_player = local temp_ban_player =
Gui.new_button() Gui.new_button()
:set_sprites('utility/clock') :set_sprites('utility/clock')
:set_tooltip('Temp ban player') :set_tooltip('Temp ban player')
:set_style('tool_button',tool_button_style) :set_style('tool_button',tool_button_style)
:on_click(function(player,element) :on_click(function(player,element)
Store.set_child(action_name_store,player.name,'command/temp-ban')
end)
local function temp_ban_player_callback(player,reason)
local action_player = get_action_player(player) local action_player = get_action_player(player)
Jail.temp_ban_player(action_player,player.name,reason) Jail.temp_ban_player(action_player,player.name,reason)
end) end
local kick_player = local kick_player =
Gui.new_button() Gui.new_button()
@@ -104,9 +124,13 @@ Gui.new_button()
:set_tooltip('Kick player') :set_tooltip('Kick player')
:set_style('tool_button',tool_button_style) :set_style('tool_button',tool_button_style)
:on_click(function(player,element) :on_click(function(player,element)
Store.set_child(action_name_store,player.name,'command/kick')
end)
local function kick_player_callback(player,reason)
local action_player = get_action_player(player) local action_player = get_action_player(player)
game.kick_player(action_player,reason) game.kick_player(action_player,reason)
end) end
local ban_player = local ban_player =
Gui.new_button() Gui.new_button()
@@ -114,9 +138,13 @@ Gui.new_button()
:set_tooltip('Ban player') :set_tooltip('Ban player')
:set_style('tool_button',tool_button_style) :set_style('tool_button',tool_button_style)
:on_click(function(player,element) :on_click(function(player,element)
Store.set_child(action_name_store,player.name,'command/ban')
end)
local function ban_player_callback(player,reason)
local action_player = get_action_player(player) local action_player = get_action_player(player)
game.ban_player(action_player,reason) game.ban_player(action_player,reason)
end) end
return { return {
['command/teleport'] = { ['command/teleport'] = {
@@ -129,22 +157,27 @@ return {
}, },
['command/report'] = { ['command/report'] = {
auth=auth_lower_role, auth=auth_lower_role,
reason_callback=report_player_callback,
report_player report_player
}, },
['command/jail'] = { ['command/jail'] = {
auth=auth_lower_role, auth=auth_lower_role,
reason_callback=jail_player_callback,
jail_player jail_player
}, },
['command/temp-ban'] = { ['command/temp-ban'] = {
auth=auth_lower_role, auth=auth_lower_role,
reason_callback=temp_ban_player_callback,
temp_ban_player temp_ban_player
}, },
['command/kick'] = { ['command/kick'] = {
auth=auth_lower_role, auth=auth_lower_role,
reason_callback=kick_player_callback,
kick_player kick_player
}, },
['command/ban'] = { ['command/ban'] = {
auth=auth_lower_role, auth=auth_lower_role,
reason_callback=ban_player_callback,
ban_player ban_player
} }
} }

View File

@@ -9,6 +9,7 @@ local config = require 'config.action_buttons'
local Colors = require 'resources.color_presets' local Colors = require 'resources.color_presets'
local action_player_store = 'gui.left.player-list.action-player' local action_player_store = 'gui.left.player-list.action-player'
local action_name_store = 'gui.left.player-list.action-name'
--- Button used to open the action bar --- Button used to open the action bar
local open_action_bar = local open_action_bar =
@@ -39,6 +40,26 @@ Gui.new_button()
end) end)
:on_click(function(player,element) :on_click(function(player,element)
Store.set_child(action_player_store,player.name,nil) Store.set_child(action_player_store,player.name,nil)
Store.set_child(action_name_store,player.name,nil)
end)
--- Button used to confirm a reason
local reason_confrim =
Gui.new_button()
:set_sprites('utility/confirm_slot')
:set_tooltip('Confirm Reason')
:set_style('tool_button',function(style)
Gui.set_padding_style(style,-1,-1,-1,-1)
style.height = 28
style.width = 28
end)
:on_click(function(player,element)
local reason = element.parent.entry.text or 'Non Given'
local action_name = Store.get_child(action_name_store,player.name)
local reason_callback = config[action_name].reason_callback
reason_callback(player,reason)
Store.set_child(action_player_store,player.name,nil)
Store.set_child(action_name_store,player.name,nil)
end) end)
--[[ Creates the main gui areas for the player list --[[ Creates the main gui areas for the player list
@@ -48,7 +69,7 @@ end)
>>> table >>> table
>> action_bar >> action_bar
]] ]]
local function generate_container(element) local function generate_container(player,element)
Gui.set_padding(element,2,2,2,2) Gui.set_padding(element,2,2,2,2)
element.style.minimal_width = 200 element.style.minimal_width = 200
@@ -98,6 +119,33 @@ local function generate_container(element)
action_bar.style.horizontally_stretchable = true action_bar.style.horizontally_stretchable = true
action_bar.style.height = 35 action_bar.style.height = 35
-- reason bar which contains the reason text field and confirm button
local reason_bar =
container.add{
name='reason_bar',
type='frame',
style='subfooter_frame'
}
Gui.set_padding(reason_bar,-1,-1,3,3)
reason_bar.style.horizontally_stretchable = true
reason_bar.style.height = 35
local action_name = Store.get_child(action_name_store,player.name)
reason_bar.visible = action_name ~= nil
-- text entry for the reason bar
local reason_field =
reason_bar.add{
name='entry',
type='textfield',
style='stretchable_textfield',
tooltip='Enter reason'
}
Gui.set_padding(reason_field)
reason_field.style.height = 28
reason_field.style.minimal_width = 160
reason_confrim(reason_bar)
return list_table, action_bar return list_table, action_bar
end end
@@ -202,7 +250,7 @@ Gui.new_left_frame('gui/player-list')
:set_open_by_default() :set_open_by_default()
:set_direction('vertical') :set_direction('vertical')
:on_draw(function(player,element) :on_draw(function(player,element)
local list_table,action_bar = generate_container(element) local list_table,action_bar = generate_container(player,element)
generate_action_bar(player,action_bar) generate_action_bar(player,action_bar)
local players = {} local players = {}
@@ -233,6 +281,14 @@ Store.register(action_player_store,function(value,category)
update_action_bar(player) update_action_bar(player)
end) end)
--- When the action name is changed the reason input will update
Store.register(action_name_store,function(value,category)
local player = Game.get_player_from_any(category)
local frame = Gui.classes.left_frames.get_frame(player_list_name,player)
local element = frame.container.reason_bar
element.visible = value ~= nil
end)
--- Many events which trigger the gui to be re drawn --- Many events which trigger the gui to be re drawn
Event.add(defines.events.on_player_joined_game,player_list 'redraw_all') Event.add(defines.events.on_player_joined_game,player_list 'redraw_all')
Event.add(defines.events.on_player_left_game,player_list 'redraw_all') Event.add(defines.events.on_player_left_game,player_list 'redraw_all')