|
|
|
@ -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(
|
|
|
|
|