mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 12:31:41 +09:00
Working Poll System
This commit is contained in:
@@ -42,6 +42,7 @@ local send_popup = Gui.inputs.add{
|
|||||||
for power,__rank in pairs(Ranking._ranks()) do
|
for power,__rank in pairs(Ranking._ranks()) do
|
||||||
if power <= _rank.power then
|
if power <= _rank.power then
|
||||||
Gui.popup.open('announcements',{sent_by=sent_by,sent_to=sent_to,message=message},__rank:get_players(true))
|
Gui.popup.open('announcements',{sent_by=sent_by,sent_to=sent_to,message=message},__rank:get_players(true))
|
||||||
|
event.element.parent.parent.message.text = ''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -17,18 +17,24 @@ local function _polls(reset)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function _poll_end(uuid)
|
local function _poll_end(uuid)
|
||||||
local poll = _polls().active[poll.uuid]
|
local poll = _polls().active[uuid]
|
||||||
if not poll then return end
|
if not poll then return end
|
||||||
|
local highest = {nil,-1}
|
||||||
|
local _votes = {}
|
||||||
for index,answer in pairs(poll.answers) do
|
for index,answer in pairs(poll.answers) do
|
||||||
local _result = #poll.votes[index] or 0
|
local _result = poll.votes[index] or 0
|
||||||
poll.votes[index] = _result
|
if _result > highest[2] then highest = {answer,_result} end
|
||||||
|
_votes[answer] = _result
|
||||||
end
|
end
|
||||||
local uuid = poll.uuid
|
local uuid = poll.uuid
|
||||||
poll.uuid = nil
|
poll.uuid = nil
|
||||||
|
poll.votes = _votes
|
||||||
poll.answers = nil
|
poll.answers = nil
|
||||||
poll.voted = nil
|
poll.voted = nil
|
||||||
table.insert(_polls().old,poll)
|
table.insert(_polls().old,poll)
|
||||||
_polls().active[uuid] = nil
|
_polls().active[uuid] = nil
|
||||||
|
game.print({'polls.end',poll.question},defines.text_color.info)
|
||||||
|
game.print({'polls.winner',highest[1]},defines.text_color.info)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function _poll_data(question,answers)
|
local function _poll_data(question,answers)
|
||||||
@@ -45,11 +51,34 @@ local function _poll_data(question,answers)
|
|||||||
}:on_event('timeout',function(self)
|
}:on_event('timeout',function(self)
|
||||||
local uuid = self.data.poll_uuid
|
local uuid = self.data.poll_uuid
|
||||||
_poll_end(uuid)
|
_poll_end(uuid)
|
||||||
end)
|
end):open()
|
||||||
_polls().active[poll.uuid]=poll
|
_polls().active[poll.uuid]=poll
|
||||||
return poll.uuid
|
return poll.uuid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function draw_poll(frame)
|
||||||
|
frame.clear()
|
||||||
|
local index = tonumber(frame.parent.current_index.caption)
|
||||||
|
local poll = _polls().old[index]
|
||||||
|
if not poll then
|
||||||
|
frame.add{
|
||||||
|
type='label',
|
||||||
|
caption={'polls.no-poll'}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
end
|
||||||
|
frame.add{
|
||||||
|
type='label',
|
||||||
|
caption='Question: '..poll.question
|
||||||
|
}
|
||||||
|
for answer,votes in pairs(poll.votes) do
|
||||||
|
frame.add{
|
||||||
|
type='label',
|
||||||
|
caption=answer..') '..votes
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function _opptions(player,root_frame)
|
local function _opptions(player,root_frame)
|
||||||
local opptions = {'Please Select An Opption'}
|
local opptions = {'Please Select An Opption'}
|
||||||
local uuid = root_frame.name
|
local uuid = root_frame.name
|
||||||
@@ -67,10 +96,10 @@ local opption_drop_down = Gui.inputs.add_drop_down('opption-drop-down-polls',_op
|
|||||||
if not poll then return end
|
if not poll then return end
|
||||||
if poll.voted[player.index] and poll.voted[player.index] > 1 then
|
if poll.voted[player.index] and poll.voted[player.index] > 1 then
|
||||||
local old_vote = poll.voted[player.index]
|
local old_vote = poll.voted[player.index]
|
||||||
poll.votes[old_vote] = poll.votes[old_vote]-1
|
poll.votes[old_vote-1] = poll.votes[old_vote-1] and poll.votes[old_vote-1]-1 or 0
|
||||||
end
|
end
|
||||||
if element.selected_index > 1 then
|
if element.selected_index > 1 then
|
||||||
poll.votes[element.selected_index-1] = poll.votes[element.selected_index-1] + 1
|
poll.votes[element.selected_index-1] = poll.votes[element.selected_index-1] and poll.votes[element.selected_index-1]+1 or 1
|
||||||
end
|
end
|
||||||
poll.voted[player.index]=element.selected_index
|
poll.voted[player.index]=element.selected_index
|
||||||
element.parent.answer.caption = 'Your Answer: '..selected
|
element.parent.answer.caption = 'Your Answer: '..selected
|
||||||
@@ -79,26 +108,28 @@ end)
|
|||||||
local prev = Gui.inputs.add{
|
local prev = Gui.inputs.add{
|
||||||
type='button',
|
type='button',
|
||||||
name='prev-poll',
|
name='prev-poll',
|
||||||
caption='utility/hint_arrow_right'
|
caption='utility/hint_arrow_left'
|
||||||
}:on_event('click',function(event)
|
}:on_event('click',function(event)
|
||||||
local parent = event.element.parent
|
local parent = event.element.parent
|
||||||
local index = parent.parent.current_index.caption
|
local index = parent.parent.current_index.caption
|
||||||
local _index = tonumber(index)-1
|
local _index = tonumber(index)-1
|
||||||
if _index < 1 then _index = #_polls().old end
|
if _index < 1 then _index = #_polls().old end
|
||||||
parent.parent.current_index.caption = _index
|
parent.parent.current_index.caption = _index
|
||||||
|
parent.parent.title.title.caption = 'Viewing Poll: '.._index
|
||||||
draw_poll(parent.parent.poll_area)
|
draw_poll(parent.parent.poll_area)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local next = Gui.inputs.add{
|
local next = Gui.inputs.add{
|
||||||
type='button',
|
type='button',
|
||||||
name='next-poll',
|
name='next-poll',
|
||||||
caption='utility/hint_arrow_left'
|
caption='utility/hint_arrow_right'
|
||||||
}:on_event('click',function(event)
|
}:on_event('click',function(event)
|
||||||
local parent = event.element.parent
|
local parent = event.element.parent
|
||||||
local index = parent.parent.current_index.caption
|
local index = parent.parent.current_index.caption
|
||||||
local _index = tonumber(index)+1
|
local _index = tonumber(index)+1
|
||||||
if _index > #_polls().old then _index = 1 end
|
if _index > #_polls().old then _index = 1 end
|
||||||
parent.parent.current_index.caption = _index
|
parent.parent.current_index.caption = _index
|
||||||
|
parent.parent.title.title.caption = 'Viewing Poll: '.._index
|
||||||
draw_poll(parent.parent.poll_area)
|
draw_poll(parent.parent.poll_area)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -108,11 +139,11 @@ local function poll_assembler(frame)
|
|||||||
local frame_table = frame.add { type = 'table', name = 'table_poll_assembler', column_count = 2 }
|
local frame_table = frame.add { type = 'table', name = 'table_poll_assembler', column_count = 2 }
|
||||||
frame_table.add { type = 'label', caption = 'Question:' }
|
frame_table.add { type = 'label', caption = 'Question:' }
|
||||||
frame_table.add { type = 'textfield', name = 'textfield_question', text = '' }
|
frame_table.add { type = 'textfield', name = 'textfield_question', text = '' }
|
||||||
frame_table.add { type = 'label', caption = 'Answer #1:' }
|
frame_table.add { type = 'label', caption = 'Option #1:' }
|
||||||
frame_table.add { type = 'textfield', name = 'textfield_answer_1', text = '' }
|
frame_table.add { type = 'textfield', name = 'textfield_answer_1', text = '' }
|
||||||
frame_table.add { type = 'label', caption = 'Answer #2:' }
|
frame_table.add { type = 'label', caption = 'Option #2:' }
|
||||||
frame_table.add { type = 'textfield', name = 'textfield_answer_2', text = '' }
|
frame_table.add { type = 'textfield', name = 'textfield_answer_2', text = '' }
|
||||||
frame_table.add { type = 'label', caption = 'Answer #3:' }
|
frame_table.add { type = 'label', caption = 'Option #3:' }
|
||||||
frame_table.add { type = 'textfield', name = 'textfield_answer_3', text = '' }
|
frame_table.add { type = 'textfield', name = 'textfield_answer_3', text = '' }
|
||||||
frame_table.add { type = 'label', caption = '' }
|
frame_table.add { type = 'label', caption = '' }
|
||||||
end
|
end
|
||||||
@@ -123,43 +154,27 @@ local create_poll = Gui.inputs.add{
|
|||||||
caption='utility/add'
|
caption='utility/add'
|
||||||
}:on_event('click',function(event)
|
}:on_event('click',function(event)
|
||||||
local parent = event.element.parent
|
local parent = event.element.parent
|
||||||
if event.element.caption == 'utility/enter' then
|
if event.element.sprite == 'utility/enter' then
|
||||||
local inputs = parent.pool_area.table_poll_assembler
|
local inputs = parent.parent.poll_area.table_poll_assembler
|
||||||
local uuid = _poll_data(inputs.textfield_question,{
|
if not inputs then
|
||||||
inputs.textfield_answer_1,
|
event.element.sprite = 'utility/add'
|
||||||
inputs.textfield_answer_2,
|
draw_poll(parent.parent.poll_area)
|
||||||
inputs.textfield_answer_3
|
return
|
||||||
|
end
|
||||||
|
local uuid = _poll_data(inputs.textfield_question.text,{
|
||||||
|
inputs.textfield_answer_1.text,
|
||||||
|
inputs.textfield_answer_2.text,
|
||||||
|
inputs.textfield_answer_3.text
|
||||||
})
|
})
|
||||||
Gui.popup.open('polls',{uuid=uuid})
|
Gui.popup.open('polls',{uuid=uuid})
|
||||||
|
event.element.sprite = 'utility/add'
|
||||||
|
draw_poll(parent.parent.poll_area)
|
||||||
else
|
else
|
||||||
event.element.caption = 'utility/enter'
|
event.element.sprite = 'utility/enter'
|
||||||
poll_assembler(parent.parent.poll_area)
|
poll_assembler(parent.parent.poll_area)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function draw_poll(frame)
|
|
||||||
frame.clear()
|
|
||||||
local index = frame.parent.current_index.caption
|
|
||||||
local poll = _polls().old[index]
|
|
||||||
if not poll then
|
|
||||||
frame.add{
|
|
||||||
type='label',
|
|
||||||
caption={'polls.no-poll'}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
end
|
|
||||||
frame.add{
|
|
||||||
type='label',
|
|
||||||
caption='Question: '..poll.question
|
|
||||||
}
|
|
||||||
for answer,votes in pairs(poll.answers) do
|
|
||||||
frame.add{
|
|
||||||
type='label',
|
|
||||||
caption=answer..') '..votes
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Gui.popup.add{
|
Gui.popup.add{
|
||||||
name='polls',
|
name='polls',
|
||||||
caption={'polls.name'},
|
caption={'polls.name'},
|
||||||
@@ -177,36 +192,38 @@ Gui.popup.add{
|
|||||||
flow.add{type='label',caption='Question: '..poll.question}
|
flow.add{type='label',caption='Question: '..poll.question}
|
||||||
flow.add{type='label',name='answer',caption='Your Answer: None'}
|
flow.add{type='label',name='answer',caption='Your Answer: None'}
|
||||||
opption_drop_down:draw(flow)
|
opption_drop_down:draw(flow)
|
||||||
flow.add{type='lable',caption={'polls.auto-update'}}.style.font_size = 8
|
flow.add{type='label',caption={'polls.time-left',poll_time_out}}
|
||||||
end
|
end
|
||||||
}:add_left{
|
}:add_left{
|
||||||
caption='utility/item_editor_icon',
|
caption='utility/item_editor_icon',
|
||||||
tooltip={'polls.tooltip'},
|
tooltip={'polls.tooltip'},
|
||||||
draw=function(frame)
|
draw=function(frame)
|
||||||
|
frame.caption={'polls.name'}
|
||||||
frame.add{
|
frame.add{
|
||||||
type='lable',
|
type='label',
|
||||||
name='current_index',
|
name='current_index',
|
||||||
cpation=1
|
caption=1
|
||||||
}.style.visible = false
|
}.style.visible = false
|
||||||
local title = frame.add{
|
local title = frame.add{
|
||||||
type='flow',
|
type='flow',
|
||||||
name='title'
|
name='title'
|
||||||
}
|
}
|
||||||
local btn = prev:draw(title)
|
local btn = prev:draw(title)
|
||||||
btn.style.width = 30
|
btn.style.width = 20
|
||||||
btn.style.height = 30
|
btn.style.height = 20
|
||||||
title.add{
|
title.add{
|
||||||
type='label',
|
type='label',
|
||||||
|
name='title',
|
||||||
caption='Viewing Poll: 1',
|
caption='Viewing Poll: 1',
|
||||||
style='caption_label'
|
style='caption_label'
|
||||||
}
|
}
|
||||||
local btn = next:draw(title)
|
local btn = next:draw(title)
|
||||||
btn.style.width = 30
|
btn.style.width = 20
|
||||||
btn.style.height = 30
|
btn.style.height = 20
|
||||||
if Ranking.get_rank(frame.player_index):allowed('create-poll') then
|
if Ranking.get_rank(frame.player_index):allowed('create-poll') then
|
||||||
local btn = create_poll:draw(title)
|
local btn = create_poll:draw(title)
|
||||||
btn.style.width = 30
|
btn.style.width = 20
|
||||||
btn.style.height = 30
|
btn.style.height = 20
|
||||||
end
|
end
|
||||||
local flow = frame.add{
|
local flow = frame.add{
|
||||||
type='flow',
|
type='flow',
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ groups['Root']:edit('allow',false,{
|
|||||||
['clear-reports']=true,
|
['clear-reports']=true,
|
||||||
['clear-player']=true,
|
['clear-player']=true,
|
||||||
['announcements']=true,
|
['announcements']=true,
|
||||||
['warp-list']=true
|
['warp-list']=true,
|
||||||
|
['polls']=true
|
||||||
})
|
})
|
||||||
groups['Admin']:edit('allow',false,{
|
groups['Admin']:edit('allow',false,{
|
||||||
['player-list']=true,
|
['player-list']=true,
|
||||||
@@ -68,7 +69,8 @@ groups['Admin']:edit('allow',false,{
|
|||||||
['clear-reports']=true,
|
['clear-reports']=true,
|
||||||
['clear-player']=true,
|
['clear-player']=true,
|
||||||
['announcements']=true,
|
['announcements']=true,
|
||||||
['warp-list']=true
|
['warp-list']=true,
|
||||||
|
['polls']=true
|
||||||
})
|
})
|
||||||
groups['User']:edit('allow',false,{
|
groups['User']:edit('allow',false,{
|
||||||
['player-list']=true,
|
['player-list']=true,
|
||||||
@@ -77,7 +79,8 @@ groups['User']:edit('allow',false,{
|
|||||||
['science']=true,
|
['science']=true,
|
||||||
['tasklist']=true,
|
['tasklist']=true,
|
||||||
['report']=true,
|
['report']=true,
|
||||||
['warp-list']=true
|
['warp-list']=true,
|
||||||
|
['polls']=true
|
||||||
})
|
})
|
||||||
groups['Jail']:edit('allow',false,{
|
groups['Jail']:edit('allow',false,{
|
||||||
|
|
||||||
|
|||||||
7
locale/en/polls.cfg
Normal file
7
locale/en/polls.cfg
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[polls]
|
||||||
|
name=Polls
|
||||||
|
tooltip=View Old Polls
|
||||||
|
no-poll=No Old Polls
|
||||||
|
end=Poll Just Ended: __1__
|
||||||
|
winner=__1__ had the most votes.
|
||||||
|
time-left=You will have __1__s to pick.
|
||||||
Reference in New Issue
Block a user