feat: provide a button to close a poll

That button can be hidden with F1.
master
Dominique Merle 4 years ago
parent 9cc7636793
commit 4e5e7c040f

@ -13,9 +13,12 @@ export(Resource) var poll setget set_poll, get_poll
export(int) var vertical_gap := 4 # pixels export(int) var vertical_gap := 4 # pixels
export(int) var candidates_labels_width := 200 # pixels export(int) var candidates_labels_width := 200 # pixels
export(bool) var align_with_bottom := false # pixels export(bool) var align_with_bottom := false # pixels
export(int) var padding_with_window := 20 # pixels export(int) var padding_with_window_top := 20 # pixels
export(int) var padding_with_window_bottom := 95 # pixels
onready var ClosePollButton = find_node("ClosePollButton", true)
onready var ClosePollDialog = find_node("ClosePollConfirmationDialog", true)
onready var ProfilesContainer = find_node("ProfilesContainer", true) onready var ProfilesContainer = find_node("ProfilesContainer", true)
@ -23,14 +26,27 @@ var providers:Array # of MajorityJudgmentAbstractJudgmentsProvider
#var provider:MajorityJudgmentAbstractJudgmentsProvider #var provider:MajorityJudgmentAbstractJudgmentsProvider
func _ready():
ClosePollDialog.connect("confirmed", self, "close_and_exit")
func _input(_event): func _input(_event):
if Input.is_action_just_pressed("ui_cancel"): if Input.is_action_just_pressed("ui_cancel"):
exit_scene() prompt_close_and_exit()
if Input.is_action_just_pressed("ui_toggle_elements"):
ClosePollButton.visible = not ClosePollButton.visible
func prompt_close_and_exit():
ClosePollDialog.popup_centered()
func close_and_exit():
close_poll()
exit_scene()
func exit_scene(): func exit_scene():
# Check if we want to save or discard?
# …
# Close things up # Close things up
# stop_providers() # stop_providers()
App.go_to_main_menu() App.go_to_main_menu()
@ -54,6 +70,10 @@ func set_poll(__poll:MajorityJudgmentPoll):
# start_provider(provider) # start_provider(provider)
func close_poll():
App.close_ongoing_poll()
var candidates_lines_nodes := Array() var candidates_lines_nodes := Array()
var profiles_nodes := Array() var profiles_nodes := Array()
func craft_nodes(): func craft_nodes():
@ -151,10 +171,10 @@ func update_scene():
- -
candidates_amount * (height + vertical_gap) candidates_amount * (height + vertical_gap)
- -
padding_with_window padding_with_window_bottom
) )
else: else:
cln_margin_top += padding_with_window cln_margin_top += padding_with_window_top
$Tween.interpolate_property( $Tween.interpolate_property(
@ -241,3 +261,6 @@ func __on_judgment_emitted(author_identifier, grade_index, candidate_index):
update_scene() update_scene()
func _on_ClosePollButton_pressed():
prompt_close_and_exit()

@ -1,6 +1,8 @@
[gd_scene load_steps=2 format=2] [gd_scene load_steps=4 format=2]
[ext_resource path="res://addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.gd" type="Script" id=1] [ext_resource path="res://addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.gd" type="Script" id=1]
[ext_resource path="res://gui/themes/AndroidAppTheme.tres" type="Theme" id=2]
[ext_resource path="res://gui/popups/ClosePollConfirmationDialog.tscn" type="PackedScene" id=3]
[node name="MajorityJudgmentLinearResultsControl" type="Control"] [node name="MajorityJudgmentLinearResultsControl" type="Control"]
anchor_right = 1.0 anchor_right = 1.0
@ -21,3 +23,26 @@ __meta__ = {
} }
[node name="Tween" type="Tween" parent="."] [node name="Tween" type="Tween" parent="."]
[node name="ClosePollButton" type="Button" parent="."]
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = -140.033
margin_top = -75.0443
margin_right = -20.0329
margin_bottom = -23.0443
hint_tooltip = "Press F1 to hide this button.
Your friend forever,
The Button Painter"
theme = ExtResource( 2 )
text = "CLOSE"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ClosePollConfirmationDialog" parent="." instance=ExtResource( 3 )]
visible = false
[connection signal="pressed" from="ClosePollButton" to="." method="_on_ClosePollButton_pressed"]

@ -1,6 +1,14 @@
extends Node extends Node
# Goal
# ====
#
# Set up Majority Judgment polls using a variety of providers,
# such a the Twitch Chat, SMS (Android only)…
#
# Unused (see Config.gd) # # Unused (see Config.gd) #
var config:ConfigResource var config:ConfigResource
var config_path := "user://settings.tres" var config_path := "user://settings.tres"
@ -13,9 +21,13 @@ var registered_providers = [
'MajorityJudgmentAndroidSmsProvider', 'MajorityJudgmentAndroidSmsProvider',
] ]
const ONGOING_POLL_FILEPATH = "user://ongoing_poll.tres"
var ongoing_poll:MajorityJudgmentPoll
func _ready(): func _ready():
load_config() load_config()
load_ongoing_poll()
func go_to_main_menu(): func go_to_main_menu():
@ -45,15 +57,56 @@ func save_config():
func start_poll(poll): func start_poll(poll):
prints("Starting poll", poll) prints("Starting poll", poll)
# Start listening to chat commands # Prepare timer for automatic closing of the poll?
# Prepare timer for automatic closing of the poll
# Move to poll results scene # Move to poll results scene
assert(null == self.ongoing_poll, "Cannot start another poll while one is ongoing.")
self.ongoing_poll = poll
var _done = get_tree().change_scene("res://addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.tscn") var _done = get_tree().change_scene("res://addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.tscn")
yield(get_tree(), "idle_frame") yield(get_tree(), "idle_frame")
get_tree().current_scene.align_with_bottom = Config.get_parameter("align_with_bottom", false) get_tree().current_scene.align_with_bottom = Config.get_parameter("align_with_bottom", false)
get_tree().current_scene.set_poll(poll) # last get_tree().current_scene.set_poll(poll) # last
func close_ongoing_poll():
assert(self.ongoing_poll, "No ongoing poll to close.")
var saved = ResourceSaver.save(
"user://poll_%d.tres" % [self.ongoing_poll.opened_at],
self.ongoing_poll,
ResourceSaver.FLAG_OMIT_EDITOR_PROPERTIES
)
if OK != saved:
printerr("Failed to save closing poll to disk: ERROR " + saved)
self.ongoing_poll = null
func save_ongoing_poll():
assert(self.ongoing_poll, "No ongoing poll to save.")
var saved = ResourceSaver.save(ONGOING_POLL_FILEPATH, self.ongoing_poll)
if OK != saved:
printerr("Failed to save ongoing poll to disk: ERROR " + saved)
func has_ongoing_poll():
if null != self.ongoing_poll:
return true
var file = File.new()
return file.file_exists(ONGOING_POLL_FILEPATH)
func load_ongoing_poll():
# assert(null == ongoing_poll, "There already is an ongoing poll.")
var file := File.new()
if file.file_exists(ONGOING_POLL_FILEPATH):
print("Loading ongoing poll…")
var _ongoing_poll = ResourceLoader.load(ONGOING_POLL_FILEPATH, "MajorityJudgmentPoll")
print("Ongoing poll loaded!")
start_poll(_ongoing_poll)
else:
print("No ongoing poll to load.")
func get_providers() -> Array: func get_providers() -> Array:
var providers = Array() var providers = Array()
for registered_provider in registered_providers: for registered_provider in registered_providers:
@ -75,12 +128,6 @@ func can_have_sms_provider() -> bool:
return Engine.has_singleton("AndroidSmsReceiver") return Engine.has_singleton("AndroidSmsReceiver")
#func get_android_sms_reader():
# if can_have_sms_provider():
# return Engine.get_singleton("AndroidSmsReader")
# return null
func get_now() -> int: func get_now() -> int:
return OS.get_unix_time() return OS.get_unix_time()

@ -28,9 +28,9 @@ __meta__ = {
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"] [node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
margin_left = 74.0 margin_left = 74.0
margin_top = 170.0 margin_top = 69.0
margin_right = 526.0 margin_right = 526.0
margin_bottom = 628.0 margin_bottom = 729.0
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
@ -59,13 +59,13 @@ placeholder_text = "Who should we raid?"
[node name="CandidatesContainer" type="MarginContainer" parent="CenterContainer/VBoxContainer"] [node name="CandidatesContainer" type="MarginContainer" parent="CenterContainer/VBoxContainer"]
margin_right = 452.0 margin_right = 452.0
margin_bottom = 250.0 margin_bottom = 452.0
rect_min_size = Vector2( 230, 250 ) rect_min_size = Vector2( 230, 452 )
size_flags_vertical = 3 size_flags_vertical = 3
[node name="CandidatesTree" type="Tree" parent="CenterContainer/VBoxContainer/CandidatesContainer"] [node name="CandidatesTree" type="Tree" parent="CenterContainer/VBoxContainer/CandidatesContainer"]
margin_right = 452.0 margin_right = 452.0
margin_bottom = 250.0 margin_bottom = 452.0
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
hide_folding = true hide_folding = true
@ -73,9 +73,9 @@ hide_root = true
script = ExtResource( 3 ) script = ExtResource( 3 )
[node name="GradingHBoxContainer" type="HBoxContainer" parent="CenterContainer/VBoxContainer"] [node name="GradingHBoxContainer" type="HBoxContainer" parent="CenterContainer/VBoxContainer"]
margin_top = 258.0 margin_top = 460.0
margin_right = 452.0 margin_right = 452.0
margin_bottom = 310.0 margin_bottom = 512.0
[node name="Label" type="Label" parent="CenterContainer/VBoxContainer/GradingHBoxContainer"] [node name="Label" type="Label" parent="CenterContainer/VBoxContainer/GradingHBoxContainer"]
self_modulate = Color( 1, 1, 1, 0.25098 ) self_modulate = Color( 1, 1, 1, 0.25098 )
@ -96,16 +96,16 @@ clip_text = true
items = [ "Quality (2 grades)", null, 2, true, false, 0, 0, null, "", false, "Quality (3 grades)", null, 2, false, false, 0, 0, null, "", false, "Quality (4 grades)", null, 2, false, false, 2, 0, null, "", false ] items = [ "Quality (2 grades)", null, 2, true, false, 0, 0, null, "", false, "Quality (3 grades)", null, 2, false, false, 0, 0, null, "", false, "Quality (4 grades)", null, 2, false, false, 2, 0, null, "", false ]
[node name="DelegationCheckButton" type="CheckButton" parent="CenterContainer/VBoxContainer"] [node name="DelegationCheckButton" type="CheckButton" parent="CenterContainer/VBoxContainer"]
margin_top = 318.0 margin_top = 520.0
margin_right = 452.0 margin_right = 452.0
margin_bottom = 398.0 margin_bottom = 600.0
disabled = true disabled = true
text = "Allow Delegations" text = "Allow Delegations"
[node name="ButtonsHBoxContainer" type="HBoxContainer" parent="CenterContainer/VBoxContainer"] [node name="ButtonsHBoxContainer" type="HBoxContainer" parent="CenterContainer/VBoxContainer"]
margin_top = 406.0 margin_top = 608.0
margin_right = 452.0 margin_right = 452.0
margin_bottom = 458.0 margin_bottom = 660.0
[node name="CancelButton" type="Button" parent="CenterContainer/VBoxContainer/ButtonsHBoxContainer"] [node name="CancelButton" type="Button" parent="CenterContainer/VBoxContainer/ButtonsHBoxContainer"]
margin_right = 214.0 margin_right = 214.0

@ -0,0 +1,13 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://gui/themes/AndroidAppTheme.tres" type="Theme" id=1]
[node name="ClosePollConfirmationDialog" type="ConfirmationDialog"]
margin_right = 278.0
margin_bottom = 110.0
theme = ExtResource( 1 )
popup_exclusive = true
window_title = "Close the poll?"
dialog_text = "The poll will be closed.
No more votes will be recorded."
dialog_autowrap = true

@ -282,6 +282,11 @@ theme/use_hidpi=true
[input] [input]
ui_toggle_elements={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777244,"unicode":0,"echo":false,"script":null)
]
}
run_tests={ run_tests={
"deadzone": 0.5, "deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":true,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":78,"unicode":0,"echo":false,"script":null) "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":true,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":78,"unicode":0,"echo":false,"script":null)

Loading…
Cancel
Save