Browse Source

feat: animate the order of candidates in the linear results scene

master
Dominique Merle 2 years ago
parent
commit
7f136aa91d
  1. 17
      addons/majority_judgment/MajorityJudgmentPollTally.gd
  2. 79
      addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.gd
  3. 17
      addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.tscn
  4. 8
      gui/forms/SettingsForm.tscn

17
addons/majority_judgment/MajorityJudgmentPollTally.gd

@ -26,3 +26,20 @@ func get_tally_of_candidate(candidate:MajorityJudgmentCandidate) -> MajorityJudg
return candidate_tally
assert(false, "Candidate tally not found.")
return MajorityJudgmentCandidateTally.new() # urgh
func get_position_of_candidate(candidate:MajorityJudgmentCandidate, unique=false) -> int:
if unique:
var position := 0
for candidate_tally in self.candidates_tallies:
if candidate_tally.candidate == candidate:
return position
position += 1
else:
for candidate_tally in self.candidates_tallies:
if candidate_tally.candidate == candidate:
return candidate_tally.position
assert(false, "Candidate cannot be found.")
return -1

79
addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.gd

@ -1,14 +1,18 @@
extends Control
# A scene displaying the poll results as linear merit profiles.
# This scene is updated dynamically as the poll receives new judgments.
const MeritProfileScene = preload("res://addons/majority_judgment/nodes/MajorityJudgmentMeritProfileControl.tscn")
export(Resource) var poll setget set_poll, get_poll
export(int) var vertical_gap := 4 # pixels
#func _ready():
# set_poll(load("res://test_poll.tres"))
var provider:MajorityJudgmentAbstractJudgmentsProvider
func get_poll() -> MajorityJudgmentPoll:
@ -25,6 +29,7 @@ func set_poll(__poll:MajorityJudgmentPoll):
start_provider(provider)
var candidates_lines_nodes := Array()
var profiles_nodes := Array()
func craft_nodes():
var tally : MajorityJudgmentPollTally = get_poll().tally()
@ -32,22 +37,28 @@ func craft_nodes():
var candidate_index = 0 # as they were initially written, before the sort
for candidate in get_poll().get_candidates():
# var candidate_tally := tally.get_tally_of_candidate(candidate)
# var merit_profile = candidate_tally.merit_profile
var profile = create_merit_profile_scene(6)
if tally:
profile.refresh(tally.get_tally_of_candidate(candidate).merit_profile)
var height = profile.compute_height()
# profile.margin_top = candidate_index * 50
# profile.margin_left = 0
# profile.margin_right = 0
# profile.margin_bottom = candidate_index * 50 + 42
profile.rect_min_size = Vector2(400, height)
var container = $CenterContainer/ProfilesContainer
var wrapper = HBoxContainer.new()
wrapper.name = "Candidate%sLine" % char(candidate_index+65)
wrapper.anchor_right = 1.0
# wrapper.rect_min_size = Vector2(400, height)
var position = candidate_index
if tally:
position = tally.get_position_of_candidate(candidate, true)
wrapper.margin_top = position * (height + vertical_gap)
wrapper.margin_bottom = wrapper.margin_top + height
self.candidates_lines_nodes.append(wrapper)
var candidate_label = Label.new()
candidate_label.name = "CandidateLabel"
candidate_label.text = candidate.get_name()
candidate_label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
# candidate_label.size_flags_vertical = Control.SIZE_EXPAND_FILL
@ -58,24 +69,70 @@ func craft_nodes():
wrapper.add_child(profile)
container.add_child(wrapper)
# wrapper.margin_top = position * height
# wrapper.margin_bottom = wrapper.margin_top + height
profiles_nodes.append(profile)
# separator.owner = self
candidate_label.owner = self
profile.owner = self
wrapper.owner = self
self.profiles_nodes.append(profile)
candidate_index += 1
# perhaps update_scene()?
func update_nodes():
$Tween.remove_all()
var tally : MajorityJudgmentPollTally = get_poll().tally()
var candidate_index = 0 # as they were initially written, before the sort
for candidate in get_poll().get_candidates():
var profile = profiles_nodes[candidate_index]
var candidate_line_node = self.candidates_lines_nodes[candidate_index]
var position = candidate_index
var height = profile.compute_height()
if tally:
position = tally.get_position_of_candidate(candidate, true)
var tween_transition = Tween.TRANS_SINE
var tween_ease = Tween.EASE_IN_OUT
var tween_duration = 0.818
var tween_delay = 0
var cln_margin_top = position * (height + vertical_gap)
$Tween.interpolate_property(
candidate_line_node,
"margin_top",
candidate_line_node.margin_top,
cln_margin_top,
tween_duration,
tween_transition,
tween_ease,
tween_delay
)
$Tween.interpolate_property(
candidate_line_node,
"margin_bottom",
candidate_line_node.margin_bottom,
cln_margin_top + height,
tween_duration,
tween_transition,
tween_ease,
tween_delay
)
$Tween.start()
# candidate_line_node.margin_top = position * (height + vertical_gap)
# candidate_line_node.margin_bottom = wrapper.margin_top + height
if tally:
var merit = tally.get_tally_of_candidate(candidate).merit_profile
profile.refresh(merit)
else:
var merit = poll.get_dummy_merit_profile(candidate)
profile.refresh(merit)
candidate_index += 1
@ -86,8 +143,6 @@ func create_merit_profile_scene(gradation_size:int):
return mps
var provider:MajorityJudgmentAbstractJudgmentsProvider
func start_provider(__provider):
self.provider = __provider
var connected = self.provider.connect(

17
addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.tscn

@ -13,10 +13,15 @@ __meta__ = {
[node name="CenterContainer" type="CenterContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ProfilesContainer" type="Control" parent="CenterContainer"]
margin_left = 212.0
margin_top = 99.0
margin_right = 812.0
margin_bottom = 499.0
rect_min_size = Vector2( 600, 400 )
[node name="ProfilesContainer" type="VBoxContainer" parent="CenterContainer"]
margin_left = 312.0
margin_top = 100.0
margin_right = 712.0
margin_bottom = 500.0
rect_min_size = Vector2( 400, 400 )
[node name="Tween" type="Tween" parent="."]

8
gui/forms/SettingsForm.tscn

@ -77,10 +77,10 @@ __meta__ = {
[node name="ColorPicker" type="ColorPicker" parent="CenterContainer/VBoxContainer/TabContainer/General"]
visible = false
margin_left = 16.0
margin_top = 16.0
margin_right = 324.0
margin_bottom = 478.0
margin_left = 24.0
margin_top = 24.0
margin_right = 332.0
margin_bottom = 486.0
color = Color( 0.341176, 0.133333, 0.133333, 1 )
__meta__ = {
"_edit_use_anchors_": false

Loading…
Cancel
Save