Browse Source

feat: display a white border around the median grade.

master
Dominique Merle 2 years ago
parent
commit
89a18cd0b0
  1. 5
      addons/majority_judgment/MajorityJudgmentCandidateMeritProfile.gd
  2. 4
      addons/majority_judgment/nodes/MajorityJudgmentLinearGradeNode.gd
  3. 2
      addons/majority_judgment/nodes/MajorityJudgmentMeritProfileControl.gd
  4. 15
      addons/majority_judgment/shaders/linear_grade.shader

5
addons/majority_judgment/MajorityJudgmentCandidateMeritProfile.gd

@ -40,7 +40,7 @@ func count_grades_with_judgments() -> int:
func get_median() -> int:
"""
Returns the grade index, not a Grade instance.
0 = worst grade
0 = worst grade (most conservative?)
Returns -1 if there are no judgments.
"""
@ -69,6 +69,9 @@ func get_median() -> int:
func remove_one_judgment(grade_index:int) -> void:
"""
Used by the naive sorting algorithm, that works on a copy.
"""
assert(0 < self.grades[grade_index])
self.grades[grade_index] -= 1

4
addons/majority_judgment/nodes/MajorityJudgmentLinearGradeNode.gd

@ -1,5 +1,9 @@
extends ColorRect
func refresh_median_status(_is_median:bool):
get_material().set_shader_param("is_median", _is_median)
func set_grade_icon(_grade_icon:Texture):
get_material().set_shader_param("grade_icon", _grade_icon)

2
addons/majority_judgment/nodes/MajorityJudgmentMeritProfileControl.gd

@ -55,6 +55,7 @@ func refresh(merit_profile:MajorityJudgmentCandidateMeritProfile):
yield($Tween, "tree_entered")
$Tween.remove_all()
var median : int = merit_profile.get_median()
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()
@ -63,6 +64,7 @@ func refresh(merit_profile:MajorityJudgmentCandidateMeritProfile):
var cursor := 0
for grade_index in range(amount_of_grades):
var grade_node = _grades_nodes[grade_index]
grade_node.refresh_median_status(grade_index == median)
var amount_of_judgments_for_grade = merit_profile.grades[grade_index]
var width = (
(total_width - (amount_of_grades_with_judgments-1) * gap_size)

15
addons/majority_judgment/shaders/linear_grade.shader

@ -1,6 +1,7 @@
shader_type canvas_item;
uniform sampler2D grade_icon;
uniform bool is_median = false;
void fragment() {
vec4 final_color = COLOR;
@ -39,6 +40,20 @@ void fragment() {
texture_color_base.a
);
if (is_median) {
float border_size = 0.07;
if (
(UV.x > 1.0 - border_size)
||
(UV.x < border_size)
||
(UV.y > 1.0 - border_size)
||
(UV.y < border_size)
) {
final_color.rgb = vec3(1.0, 1.0, 1.0);
}
}
COLOR = final_color;

Loading…
Cancel
Save