mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-02-07 13:31:40 +02:00
added poll to comfy_panel
This commit is contained in:
parent
ba7c76b6b9
commit
e128bbd9ba
@ -19,7 +19,7 @@ local inv_tick_duration_step = 1 / tick_duration_step
|
||||
|
||||
local polls = {}
|
||||
local polls_counter = {0}
|
||||
local no_notify_players = {}
|
||||
local block_notify = {}
|
||||
local player_poll_index = {}
|
||||
local player_create_poll_data = {}
|
||||
|
||||
@ -27,14 +27,14 @@ Global.register(
|
||||
{
|
||||
polls = polls,
|
||||
polls_counter = polls_counter,
|
||||
no_notify_players = no_notify_players,
|
||||
block_notify = block_notify,
|
||||
player_poll_index = player_poll_index,
|
||||
player_create_poll_data = player_create_poll_data
|
||||
},
|
||||
function(tbl)
|
||||
polls = tbl.polls
|
||||
polls_counter = tbl.polls_counter
|
||||
no_notify_players = tbl.no_notify_players
|
||||
block_notify = tbl.block_notify
|
||||
player_poll_index = tbl.player_poll_index
|
||||
player_create_poll_data = tbl.player_create_poll_data
|
||||
end
|
||||
@ -152,7 +152,6 @@ local function send_poll_result_to_discord(poll)
|
||||
end
|
||||
|
||||
local function redraw_poll_viewer_content(data)
|
||||
local trusted = session.get_trusted_table()
|
||||
local poll_viewer_content = data.poll_viewer_content
|
||||
local remaining_time_label = data.remaining_time_label
|
||||
local poll_index = data.poll_index
|
||||
@ -222,20 +221,6 @@ local function redraw_poll_viewer_content(data)
|
||||
|
||||
local question_flow = poll_viewer_content.add {type = 'table', column_count = 2}
|
||||
|
||||
if trusted[player.name] or player.admin then
|
||||
local edit_button =
|
||||
question_flow.add {
|
||||
type = 'sprite-button',
|
||||
name = poll_view_edit_name,
|
||||
sprite = 'utility/rename_icon_normal',
|
||||
tooltip = 'Edit Poll.'
|
||||
}
|
||||
|
||||
local edit_button_style = edit_button.style
|
||||
edit_button_style.width = 26
|
||||
edit_button_style.height = 26
|
||||
end
|
||||
|
||||
local question_label = question_flow.add {type = 'label', caption = poll.question}
|
||||
question_label.style.minimal_height = 32
|
||||
question_label.style.single_line = false
|
||||
@ -324,9 +309,12 @@ local function update_poll_viewer(data)
|
||||
redraw_poll_viewer_content(data)
|
||||
end
|
||||
|
||||
local function draw_main_frame(left, player)
|
||||
local function draw_main_frame(player, left)
|
||||
local trusted = session.get_trusted_table()
|
||||
local frame = left.add {type = 'frame', name = main_frame_name, caption = 'Polls', direction = 'vertical'}
|
||||
|
||||
left.clear()
|
||||
|
||||
local frame = left.add {type = 'table', name = main_frame_name, direction = 'vertical', column_count = 1}
|
||||
--frame.style.maximal_width = 640
|
||||
|
||||
local poll_viewer_top_flow = frame.add {type = 'table', column_count = 5}
|
||||
@ -347,7 +335,7 @@ local function draw_main_frame(left, player)
|
||||
local remaining_time_label = poll_viewer_top_flow.add {type = 'label'}
|
||||
|
||||
local poll_viewer_content = frame.add {type = 'scroll-pane'}
|
||||
poll_viewer_content.style.maximal_height = 480
|
||||
poll_viewer_content.style.maximal_height = 300
|
||||
poll_viewer_content.style.width = 360
|
||||
--poll_viewer_content.style.minimal_height = 480
|
||||
--poll_viewer_content.style.minimal_width = 480
|
||||
@ -373,21 +361,22 @@ local function draw_main_frame(left, player)
|
||||
type = 'checkbox',
|
||||
name = notify_checkbox_name,
|
||||
caption = 'Notify me about polls.',
|
||||
state = not no_notify_players[player.index],
|
||||
state = not block_notify[player.index],
|
||||
tooltip = 'Receive a message when new polls are created and popup the poll.'
|
||||
}
|
||||
|
||||
local bottom_flow = frame.add {type = 'flow', direction = 'horizontal'}
|
||||
|
||||
local left_flow = bottom_flow.add {type = 'flow'}
|
||||
left_flow.style.horizontal_align = 'left'
|
||||
left_flow.style.horizontally_stretchable = true
|
||||
left_flow.style.vertical_align = 'bottom'
|
||||
|
||||
local close_button = left_flow.add {type = 'button', name = main_button_name, caption = 'Close'}
|
||||
apply_button_style(close_button)
|
||||
--local close_button = left_flow.add {type = 'button', name = main_button_name, caption = 'Close'}
|
||||
--apply_button_style(close_button)
|
||||
|
||||
local right_flow = bottom_flow.add {type = 'flow'}
|
||||
local right_flow = left.add {type = 'flow', directon = 'vertical'}
|
||||
right_flow.style.horizontal_align = 'right'
|
||||
right_flow.style.vertical_align = 'bottom'
|
||||
|
||||
if trusted[player.name] or player.admin then
|
||||
local create_poll_button =
|
||||
@ -430,13 +419,13 @@ local function remove_main_frame(main_frame, left, player)
|
||||
end
|
||||
|
||||
local function toggle(event)
|
||||
local left = event.player.gui.left
|
||||
local left = event.player.gui.left.comfy_panel.tabbed_pane.Polls
|
||||
local main_frame = left[main_frame_name]
|
||||
|
||||
if main_frame then
|
||||
remove_main_frame(main_frame, left, event.player)
|
||||
else
|
||||
draw_main_frame(left, event.player)
|
||||
comfy_panel_call_tab(p, "Polls")
|
||||
end
|
||||
end
|
||||
|
||||
@ -542,7 +531,7 @@ local function redraw_create_poll_content(data)
|
||||
end
|
||||
end
|
||||
|
||||
local function draw_create_poll_frame(parent, player, previous_data)
|
||||
local function draw_create_poll_frame(player, parent, previous_data)
|
||||
previous_data = previous_data or player_create_poll_data[player.index]
|
||||
|
||||
local edit_mode
|
||||
@ -645,23 +634,18 @@ local function show_new_poll(poll_data)
|
||||
table.concat {poll_data.created_by.name, ' has created a new Poll #', poll_data.id, ': ', poll_data.question}
|
||||
|
||||
for _, p in pairs(game.connected_players) do
|
||||
local left = p.gui.left
|
||||
local frame = left[main_frame_name]
|
||||
if no_notify_players[p.index] then
|
||||
if frame and frame.valid then
|
||||
local data = Gui.get_data(frame)
|
||||
update_poll_viewer(data)
|
||||
end
|
||||
if block_notify[p.index] then
|
||||
p.print(message)
|
||||
else
|
||||
p.print(message)
|
||||
|
||||
local frame = comfy_panel_call_tab(p, "Polls")
|
||||
p.print(message)
|
||||
if frame and frame.valid then
|
||||
local data = Gui.get_data(frame)
|
||||
data.poll_index = #polls
|
||||
update_poll_viewer(data)
|
||||
else
|
||||
player_poll_index[p.index] = nil
|
||||
draw_main_frame(left, p)
|
||||
comfy_panel_call_tab(p, "Polls")
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -722,7 +706,7 @@ local function create_poll(event)
|
||||
show_new_poll(poll_data)
|
||||
send_poll_result_to_discord(poll_data)
|
||||
|
||||
Gui.remove_data_recursively(frame)
|
||||
--Gui.remove_data_recursively(frame)
|
||||
frame.destroy()
|
||||
end
|
||||
|
||||
@ -772,7 +756,8 @@ local function vote(event)
|
||||
local vote_button_count, vote_button_tooltip = update_vote(voters, answer, 1)
|
||||
|
||||
for _, p in pairs(game.connected_players) do
|
||||
local frame = p.gui.left[main_frame_name]
|
||||
if p.gui.left.comfy_panel ~= nil then
|
||||
local frame = p.gui.left.comfy_panel.tabbed_pane.Polls[main_frame_name]
|
||||
if frame and frame.valid then
|
||||
local data = Gui.get_data(frame)
|
||||
|
||||
@ -793,13 +778,14 @@ local function vote(event)
|
||||
local vote_button = vote_buttons[vote_index]
|
||||
vote_button.caption = vote_button_count
|
||||
vote_button.tooltip = vote_button_tooltip
|
||||
-- if p.index == player_index then -- block commented to avoid desync risk
|
||||
-- local vote_button_style = vote_button.style
|
||||
-- vote_button_style.font_color = focus_color
|
||||
-- vote_button_style.disabled_font_color = focus_color
|
||||
-- if p.index == player_index then -- block commented to avoid desync risk
|
||||
-- local vote_button_style = vote_button.style
|
||||
-- vote_button_style.font_color = focus_color
|
||||
-- vote_button_style.disabled_font_color = focus_color
|
||||
-- end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -809,21 +795,13 @@ local function player_joined(event)
|
||||
return
|
||||
end
|
||||
|
||||
local gui = player.gui
|
||||
if gui.top[main_button_name] ~= nil then
|
||||
local frame = gui.left[main_frame_name]
|
||||
if frame and frame.valid then
|
||||
local data = Gui.get_data(frame)
|
||||
update_poll_viewer(data)
|
||||
end
|
||||
else
|
||||
gui.top.add {type = 'sprite-button', name = main_button_name, sprite = 'item/programmable-speaker'}
|
||||
end
|
||||
if not block_notify[player.index] then block_notify[player.index] = true end
|
||||
end
|
||||
|
||||
local function tick()
|
||||
for _, p in pairs(game.connected_players) do
|
||||
local frame = p.gui.left[main_frame_name]
|
||||
if p.gui.left.comfy_panel ~= nil then
|
||||
local frame = p.gui.left.comfy_panel.tabbed_pane.Polls[main_frame_name]
|
||||
if frame and frame.valid then
|
||||
local data = Gui.get_data(frame)
|
||||
local poll = polls[data.poll_index]
|
||||
@ -837,6 +815,7 @@ local function tick()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -854,7 +833,8 @@ Gui.on_click(
|
||||
if frame and frame.valid then
|
||||
remove_create_poll_frame(frame, player.index)
|
||||
else
|
||||
draw_create_poll_frame(left, player)
|
||||
if player.gui.left.comfy_panel then player.gui.left.comfy_panel.destroy() end
|
||||
draw_create_poll_frame(player, left)
|
||||
end
|
||||
end
|
||||
)
|
||||
@ -876,7 +856,7 @@ Gui.on_click(
|
||||
local poll = polls[frame_data.poll_index]
|
||||
|
||||
poll.edit_mode = true
|
||||
draw_create_poll_frame(left, player, poll)
|
||||
draw_create_poll_frame(player, left, poll)
|
||||
end
|
||||
)
|
||||
|
||||
@ -995,20 +975,20 @@ Gui.on_click(
|
||||
local message = table.concat {player.name, ' has deleted Poll #', poll.id, ': ', poll.question}
|
||||
|
||||
for _, p in pairs(game.connected_players) do
|
||||
if not no_notify_players[p.index] then
|
||||
if not block_notify[p.index] then
|
||||
p.print(message)
|
||||
end
|
||||
|
||||
local main_frame = p.gui.left[main_frame_name]
|
||||
if main_frame and main_frame.valid then
|
||||
local main_frame_data = Gui.get_data(main_frame)
|
||||
local poll_index = main_frame_data.poll_index
|
||||
local main_frame = p.gui.left.comfy_panel.tabbed_pane.Polls[main_frame_name]
|
||||
if main_frame and main_frame.valid then
|
||||
local main_frame_data = Gui.get_data(main_frame)
|
||||
local poll_index = main_frame_data.poll_index
|
||||
|
||||
if removed_index < poll_index then
|
||||
main_frame_data.poll_index = poll_index - 1
|
||||
if removed_index < poll_index then
|
||||
main_frame_data.poll_index = poll_index - 1
|
||||
end
|
||||
|
||||
update_poll_viewer(main_frame_data)
|
||||
end
|
||||
|
||||
update_poll_viewer(main_frame_data)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1103,13 +1083,10 @@ Gui.on_click(
|
||||
local message = table.concat {player.name, ' has edited Poll #', poll.id, ': ', poll.question}
|
||||
|
||||
for _, p in pairs(game.connected_players) do
|
||||
local main_frame = p.gui.left[main_frame_name]
|
||||
local main_frame = p.gui.left.comfy_panel.tabbed_pane.Polls[main_frame_name]
|
||||
|
||||
if no_notify_players[p.index] then
|
||||
if main_frame and main_frame.valid then
|
||||
local main_frame_data = Gui.get_data(main_frame)
|
||||
update_poll_viewer(main_frame_data)
|
||||
end
|
||||
if block_notify[p.index] then
|
||||
p.print(message)
|
||||
else
|
||||
p.print(message)
|
||||
if main_frame and main_frame.valid then
|
||||
@ -1117,7 +1094,7 @@ Gui.on_click(
|
||||
main_frame_data.poll_index = poll_index
|
||||
update_poll_viewer(main_frame_data)
|
||||
else
|
||||
draw_main_frame(p.gui.left, p)
|
||||
comfy_panel_call_tab(p, "Polls")
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1137,7 +1114,7 @@ Gui.on_checked_state_changed(
|
||||
new_state = true
|
||||
end
|
||||
|
||||
no_notify_players[player_index] = new_state
|
||||
block_notify[player_index] = new_state
|
||||
end
|
||||
)
|
||||
|
||||
@ -1314,4 +1291,6 @@ function Class.send_poll_result_to_discord(id)
|
||||
server_commands.to_discord_embed(message)
|
||||
end
|
||||
|
||||
comfy_panel_tabs["Polls"] = draw_main_frame
|
||||
|
||||
return Class
|
@ -16,12 +16,11 @@ require "player_modifiers"
|
||||
|
||||
require "comfy_panel.main"
|
||||
require "comfy_panel.player_list"
|
||||
require "comfy_panel.poll"
|
||||
require "comfy_panel.group"
|
||||
require "comfy_panel.score"
|
||||
require "comfy_panel.admin"
|
||||
|
||||
require "poll"
|
||||
|
||||
require "modules.autostash"
|
||||
require "modules.corpse_markers"
|
||||
require "modules.floaty_chat"
|
||||
|
Loading…
x
Reference in New Issue
Block a user