The data is a dummy, waiting to be connected to a provider like Twitch. We also need to sort the profiles, and animate the sort ;) The GUI elements will probably need more work as well (like clipping, etc.)master
parent
323a5fc345
commit
4e05835e81
@ -0,0 +1,8 @@
|
|||||||
|
[gd_scene format=2]
|
||||||
|
|
||||||
|
[node name="MajorityJudgmentLinearGradeNode" type="ColorRect"]
|
||||||
|
margin_right = 40.0
|
||||||
|
margin_bottom = 40.0
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
@ -0,0 +1,180 @@
|
|||||||
|
extends Control
|
||||||
|
|
||||||
|
|
||||||
|
const MeritProfileScene = preload("res://addons/majority_judgment/nodes/MajorityJudgmentMeritProfileControl.tscn")
|
||||||
|
|
||||||
|
|
||||||
|
export(Resource) var poll setget set_poll, get_poll
|
||||||
|
|
||||||
|
|
||||||
|
#func _ready():
|
||||||
|
# set_poll(load("res://test_poll.tres"))
|
||||||
|
|
||||||
|
|
||||||
|
func get_poll() -> MajorityJudgmentPoll:
|
||||||
|
return poll
|
||||||
|
|
||||||
|
|
||||||
|
func set_poll(__poll:MajorityJudgmentPoll):
|
||||||
|
poll = __poll
|
||||||
|
craft_nodes()
|
||||||
|
update_nodes()
|
||||||
|
|
||||||
|
yield(get_tree().create_timer(3), "timeout")
|
||||||
|
|
||||||
|
var j = MajorityJudgmentJudgment.new()
|
||||||
|
j.set_participant(MajorityJudgmentParticipant.make("Plume"))
|
||||||
|
j.set_grade(poll.grading.grades[2])
|
||||||
|
j.set_candidate(poll.candidates[0])
|
||||||
|
poll.add_judgment(j)
|
||||||
|
|
||||||
|
var sylvain = MajorityJudgmentParticipant.make("Sylvain")
|
||||||
|
j = MajorityJudgmentJudgment.new()
|
||||||
|
j.set_participant(sylvain)
|
||||||
|
j.set_grade(poll.grading.grades[3])
|
||||||
|
j.set_candidate(poll.candidates[0])
|
||||||
|
poll.add_judgment(j)
|
||||||
|
j = MajorityJudgmentJudgment.new()
|
||||||
|
j.set_participant(sylvain)
|
||||||
|
j.set_grade(poll.grading.grades[3])
|
||||||
|
j.set_candidate(poll.candidates[1])
|
||||||
|
poll.add_judgment(j)
|
||||||
|
j = MajorityJudgmentJudgment.new()
|
||||||
|
j.set_participant(sylvain)
|
||||||
|
j.set_grade(poll.grading.grades[4])
|
||||||
|
j.set_candidate(poll.candidates[2])
|
||||||
|
poll.add_judgment(j)
|
||||||
|
|
||||||
|
j = MajorityJudgmentJudgment.new()
|
||||||
|
j.set_participant(MajorityJudgmentParticipant.make("Sabre"))
|
||||||
|
j.set_grade(poll.grading.grades[5])
|
||||||
|
j.set_candidate(poll.candidates[0])
|
||||||
|
poll.add_judgment(j)
|
||||||
|
|
||||||
|
update_nodes()
|
||||||
|
|
||||||
|
yield(get_tree().create_timer(2), "timeout")
|
||||||
|
|
||||||
|
var tiger = MajorityJudgmentParticipant.make("Tiger")
|
||||||
|
j = MajorityJudgmentJudgment.new()
|
||||||
|
j.set_participant(tiger)
|
||||||
|
j.set_grade(poll.grading.grades[4])
|
||||||
|
j.set_candidate(poll.candidates[0])
|
||||||
|
poll.add_judgment(j)
|
||||||
|
update_nodes()
|
||||||
|
|
||||||
|
yield(get_tree().create_timer(2), "timeout")
|
||||||
|
|
||||||
|
j = MajorityJudgmentJudgment.new()
|
||||||
|
j.set_participant(tiger)
|
||||||
|
j.set_grade(poll.grading.grades[1])
|
||||||
|
j.set_candidate(poll.candidates[2])
|
||||||
|
poll.add_judgment(j)
|
||||||
|
update_nodes()
|
||||||
|
|
||||||
|
var profiles_nodes := Array()
|
||||||
|
func craft_nodes():
|
||||||
|
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 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()
|
||||||
|
var candidate_label = Label.new()
|
||||||
|
candidate_label.text = candidate.get_name()
|
||||||
|
candidate_label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||||
|
# candidate_label.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||||
|
candidate_label.rect_min_size = Vector2(70, height)
|
||||||
|
candidate_label.valign = Label.VALIGN_CENTER
|
||||||
|
candidate_label.align = Label.ALIGN_RIGHT
|
||||||
|
wrapper.add_child(candidate_label)
|
||||||
|
wrapper.add_child(profile)
|
||||||
|
container.add_child(wrapper)
|
||||||
|
|
||||||
|
|
||||||
|
profiles_nodes.append(profile)
|
||||||
|
|
||||||
|
candidate_index += 1
|
||||||
|
|
||||||
|
|
||||||
|
func update_nodes():
|
||||||
|
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 candidate_tally := tally.get_tally_of_candidate(candidate)
|
||||||
|
# var merit_profile = candidate_tally.merit_profile
|
||||||
|
var profile = profiles_nodes[candidate_index]
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
#func test():
|
||||||
|
# var poll : MajorityJudgmentPoll = MajorityJudgmentPoll.make(
|
||||||
|
# "Test",
|
||||||
|
# MajorityJudgmentGrading.make_quality_6(),
|
||||||
|
# [
|
||||||
|
# MajorityJudgmentCandidate.make("Candidate A"),
|
||||||
|
# MajorityJudgmentCandidate.make("Candidate B"),
|
||||||
|
# MajorityJudgmentCandidate.make("Candidate C"),
|
||||||
|
# ]
|
||||||
|
# )
|
||||||
|
#
|
||||||
|
# var poll_tally = MajorityJudgmentPollTally.new()
|
||||||
|
# poll_tally.poll = poll
|
||||||
|
# var candidate_tallies = Array()
|
||||||
|
# var candidate_tally := MajorityJudgmentCandidateTally.new()
|
||||||
|
# candidate_tally.poll = poll
|
||||||
|
# candidate_tally.merit_profile = MajorityJudgmentCandidateMeritProfile.new()
|
||||||
|
# candidate_tally.merit_profile.grades = [
|
||||||
|
# 10,
|
||||||
|
# 2,
|
||||||
|
# 5,
|
||||||
|
# 7,
|
||||||
|
# 1,
|
||||||
|
# 11,
|
||||||
|
# ]
|
||||||
|
# candidate_tally.merit_profile.candidate_tally = candidate_tally
|
||||||
|
# candidate_tallies.append(candidate_tally)
|
||||||
|
# create_merit_profile_scene(candidate_tally.merit_profile)
|
||||||
|
#
|
||||||
|
## candidate_tally = MajorityJudgmentCandidateTally.new()
|
||||||
|
## candidate_tally.merit_profile = MajorityJudgmentCandidateMeritProfile.new()
|
||||||
|
## candidate_tally.merit_profile.grades = [
|
||||||
|
## 2,
|
||||||
|
## 7,
|
||||||
|
## 10,
|
||||||
|
## 11,
|
||||||
|
## 1,
|
||||||
|
## 5,
|
||||||
|
## ]
|
||||||
|
## candidate_tallies.append(candidate_tally)
|
||||||
|
## create_merit_profile_scene(candidate_tally.merit_profile)
|
||||||
|
#
|
||||||
|
# poll_tally.candidates_tallies = candidate_tallies
|
||||||
|
|
||||||
|
|
||||||
|
func create_merit_profile_scene(gradation_size:int):
|
||||||
|
var mps = MeritProfileScene.instance()
|
||||||
|
mps.set_poll(get_poll())
|
||||||
|
mps.craft_nodes(gradation_size)
|
||||||
|
return mps
|
After Width: | Height: | Size: 2.5 KiB |
@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/MajorityJudgmentLinearResultsControl.svg-fa6c8a91c72c88a932e738e8ceee0654.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.svg"
|
||||||
|
dest_files=[ "res://.import/MajorityJudgmentLinearResultsControl.svg-fa6c8a91c72c88a932e738e8ceee0654.stex" ]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_mode=0
|
||||||
|
compress/bptc_ldr=0
|
||||||
|
compress/normal_map=0
|
||||||
|
flags/repeat=0
|
||||||
|
flags/filter=true
|
||||||
|
flags/mipmaps=false
|
||||||
|
flags/anisotropic=false
|
||||||
|
flags/srgb=2
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/HDR_as_SRGB=false
|
||||||
|
process/invert_color=false
|
||||||
|
stream=false
|
||||||
|
size_limit=0
|
||||||
|
detect_3d=true
|
||||||
|
svg/scale=1.0
|
@ -0,0 +1,22 @@
|
|||||||
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.gd" type="Script" id=1]
|
||||||
|
|
||||||
|
[node name="MajorityJudgmentLinearResultsControl" type="Control"]
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="CenterContainer" type="CenterContainer" parent="."]
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
|
||||||
|
[node name="ProfilesContainer" type="VBoxContainer" parent="CenterContainer"]
|
||||||
|
margin_left = 312.0
|
||||||
|
margin_top = 99.0
|
||||||
|
margin_right = 712.0
|
||||||
|
margin_bottom = 499.0
|
||||||
|
rect_min_size = Vector2( 400, 400 )
|
@ -0,0 +1,113 @@
|
|||||||
|
extends Control
|
||||||
|
|
||||||
|
|
||||||
|
const GradeNode = preload("res://addons/majority_judgment/nodes/MajorityJudgmentLinearGradeNode.tscn")
|
||||||
|
|
||||||
|
|
||||||
|
export(Resource) var poll setget set_poll, get_poll # MajorityJudgmentPoll
|
||||||
|
#export(Resource) var merit_profile # MajorityJudgmentCandidateMeritProfile
|
||||||
|
|
||||||
|
|
||||||
|
export var gap_size := 4 # pixels
|
||||||
|
export var total_width := 300 # pixels
|
||||||
|
|
||||||
|
|
||||||
|
var _grades_nodes := Array()
|
||||||
|
|
||||||
|
|
||||||
|
#func _ready():
|
||||||
|
# assert(self.merit_profile, "Inject a merit profile first")
|
||||||
|
# craft_nodes()
|
||||||
|
# refresh()
|
||||||
|
|
||||||
|
|
||||||
|
func set_poll(__poll:MajorityJudgmentPoll) -> void:
|
||||||
|
poll = __poll
|
||||||
|
|
||||||
|
|
||||||
|
func get_poll() -> MajorityJudgmentPoll:
|
||||||
|
return poll
|
||||||
|
|
||||||
|
|
||||||
|
func craft_nodes(grading_size):
|
||||||
|
assert(0 == _grades_nodes.size())
|
||||||
|
# or queue_free() them
|
||||||
|
|
||||||
|
for grade_index in range(grading_size):
|
||||||
|
var grade_node = GradeNode.instance()
|
||||||
|
grade_node.name = "GradeNode%d" % [grade_index]
|
||||||
|
grade_node.color = get_poll().get_grading().get_color_of_grade(grade_index)
|
||||||
|
add_child(grade_node)
|
||||||
|
_grades_nodes.append(grade_node)
|
||||||
|
|
||||||
|
|
||||||
|
func compute_height():
|
||||||
|
var gold = 2.0 / (sqrt(5.0) + 1.0)
|
||||||
|
assert(1.0/gold == 1.0+gold)
|
||||||
|
var amount_of_grades : int = poll.grading.grades.size()
|
||||||
|
|
||||||
|
return int(round(total_width / float(amount_of_grades)) * gold)
|
||||||
|
|
||||||
|
|
||||||
|
func refresh(merit_profile:MajorityJudgmentCandidateMeritProfile):
|
||||||
|
$Tween.remove_all()
|
||||||
|
|
||||||
|
var total_amount_of_judgments : int = merit_profile.count_judgments()
|
||||||
|
var amount_of_grades_with_judgments : int = merit_profile.count_grades_with_judgments()
|
||||||
|
var amount_of_grades : int = merit_profile.grades.size()
|
||||||
|
var height : int = compute_height()
|
||||||
|
var cursor := 0
|
||||||
|
for grade_index in range(amount_of_grades):
|
||||||
|
var grade_node = _grades_nodes[grade_index]
|
||||||
|
var amount_of_judgments_for_grade = merit_profile.grades[grade_index]
|
||||||
|
var width = (
|
||||||
|
(total_width - (amount_of_grades_with_judgments-1) * gap_size)
|
||||||
|
*
|
||||||
|
amount_of_judgments_for_grade
|
||||||
|
/
|
||||||
|
total_amount_of_judgments
|
||||||
|
)
|
||||||
|
var grade_margin_right = stepify(cursor + width, total_width / total_amount_of_judgments)
|
||||||
|
if 0 == width:
|
||||||
|
grade_margin_right = cursor
|
||||||
|
var tween_transition = Tween.TRANS_SINE
|
||||||
|
var tween_ease = Tween.EASE_IN_OUT
|
||||||
|
var tween_duration = 0.9
|
||||||
|
var tween_delay = 0
|
||||||
|
|
||||||
|
$Tween.interpolate_property(
|
||||||
|
grade_node,
|
||||||
|
"margin_left",
|
||||||
|
grade_node.margin_left,
|
||||||
|
cursor,
|
||||||
|
tween_duration,
|
||||||
|
tween_transition,
|
||||||
|
tween_ease,
|
||||||
|
tween_delay
|
||||||
|
)
|
||||||
|
$Tween.interpolate_property(
|
||||||
|
grade_node,
|
||||||
|
"margin_right",
|
||||||
|
grade_node.margin_right,
|
||||||
|
# cursor + width,
|
||||||
|
grade_margin_right,
|
||||||
|
tween_duration,
|
||||||
|
tween_transition,
|
||||||
|
tween_ease,
|
||||||
|
tween_delay
|
||||||
|
)
|
||||||
|
$Tween.start()
|
||||||
|
|
||||||
|
grade_node.margin_top = 0
|
||||||
|
grade_node.margin_bottom = height
|
||||||
|
# grade_node.margin_left = cursor
|
||||||
|
# grade_node.margin_right = cursor + width
|
||||||
|
if width:
|
||||||
|
# cursor = width + gap_size
|
||||||
|
cursor = grade_margin_right + gap_size
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
|||||||
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://addons/majority_judgment/nodes/MajorityJudgmentMeritProfileControl.gd" type="Script" id=1]
|
||||||
|
|
||||||
|
[node name="MajorityJudgmentMeritProfileControl" type="Control"]
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Tween" type="Tween" parent="."]
|
Loading…
Reference in new issue