-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement(lesson15): rethink color coding and box alignment
closes #430
- Loading branch information
1 parent
7a046a7
commit 766b821
Showing
8 changed files
with
232 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
[gd_resource type="Resource" load_steps=30 format=2] | ||
|
||
[ext_resource path="res://resources/Course.gd" type="Script" id=1] | ||
[ext_resource path="res://course/lesson-26-looping-over-dictionaries/lesson.tres" type="Resource" id=2] | ||
[ext_resource path="res://course/lesson-14-multiplying/lesson.tres" type="Resource" id=3] | ||
[ext_resource path="res://course/lesson-21-strings/lesson.tres" type="Resource" id=4] | ||
[ext_resource path="res://course/lesson-2-your-first-error/lesson.tres" type="Resource" id=5] | ||
[ext_resource path="res://course/lesson-11-time-delta/lesson.tres" type="Resource" id=6] | ||
[ext_resource path="res://course/lesson-17-while-loops/lesson.tres" type="Resource" id=7] | ||
[ext_resource path="res://course/lesson-6-multiple-function-parameters/lesson.tres" type="Resource" id=8] | ||
[ext_resource path="res://course/lesson-15-modulo/lesson.tres" type="Resource" id=9] | ||
[ext_resource path="res://course/lesson-13-conditions/lesson.tres" type="Resource" id=10] | ||
[ext_resource path="res://course/lesson-27-value-types/lesson.tres" type="Resource" id=11] | ||
[ext_resource path="res://course/lesson-22-functions-return-values/lesson.tres" type="Resource" id=12] | ||
[ext_resource path="res://course/lesson-18-for-loops/lesson.tres" type="Resource" id=13] | ||
[ext_resource path="res://course/lesson-3-standing-on-shoulders-of-giants/lesson.tres" type="Resource" id=14] | ||
[ext_resource path="res://course/lesson-28-specifying-types/lesson.tres" type="Resource" id=15] | ||
[ext_resource path="res://course/lesson-10-the-game-loop/lesson.tres" type="Resource" id=16] | ||
[ext_resource path="res://course/lesson-20-looping-over-arrays/lesson.tres" type="Resource" id=17] | ||
[ext_resource path="res://course/lesson-23-append-to-arrays/lesson.tres" type="Resource" id=18] | ||
[ext_resource path="res://course/lesson-4-drawing-a-rectangle/lesson.tres" type="Resource" id=19] | ||
[ext_resource path="res://course/lesson-24-access-array-indices/lesson.tres" type="Resource" id=20] | ||
[ext_resource path="res://course/lesson-19-creating-arrays/lesson.tres" type="Resource" id=21] | ||
[ext_resource path="res://course/lesson-9-adding-and-subtracting/lesson.tres" type="Resource" id=22] | ||
[ext_resource path="res://course/lesson-5-your-first-function/lesson.tres" type="Resource" id=23] | ||
[ext_resource path="res://course/lesson-16-2d-vectors/lesson.tres" type="Resource" id=24] | ||
[ext_resource path="res://course/lesson-8-defining-variables/lesson.tres" type="Resource" id=25] | ||
[ext_resource path="res://course/lesson-12-using-variables/lesson.tres" type="Resource" id=26] | ||
[ext_resource path="res://course/lesson-7-member-variables/lesson.tres" type="Resource" id=27] | ||
[ext_resource path="res://course/lesson-25-creating-dictionaries/lesson.tres" type="Resource" id=28] | ||
[ext_resource path="res://course/lesson-1-what-code-is-like/lesson.tres" type="Resource" id=29] | ||
[ext_resource path="res://course/lesson-11-time-delta/lesson.tres" type="Resource" id=2] | ||
[ext_resource path="res://course/lesson-7-member-variables/lesson.tres" type="Resource" id=3] | ||
[ext_resource path="res://course/lesson-25-creating-dictionaries/lesson.tres" type="Resource" id=4] | ||
[ext_resource path="res://course/lesson-1-what-code-is-like/lesson.tres" type="Resource" id=5] | ||
[ext_resource path="res://course/lesson-23-append-to-arrays/lesson.tres" type="Resource" id=6] | ||
[ext_resource path="res://course/lesson-13-conditions/lesson.tres" type="Resource" id=7] | ||
[ext_resource path="res://course/lesson-27-value-types/lesson.tres" type="Resource" id=8] | ||
[ext_resource path="res://course/lesson-2-your-first-error/lesson.tres" type="Resource" id=9] | ||
[ext_resource path="res://course/lesson-20-looping-over-arrays/lesson.tres" type="Resource" id=10] | ||
[ext_resource path="res://course/lesson-28-specifying-types/lesson.tres" type="Resource" id=11] | ||
[ext_resource path="res://course/lesson-4-drawing-a-rectangle/lesson.tres" type="Resource" id=12] | ||
[ext_resource path="res://course/lesson-24-access-array-indices/lesson.tres" type="Resource" id=13] | ||
[ext_resource path="res://course/lesson-21-strings/lesson.tres" type="Resource" id=14] | ||
[ext_resource path="res://course/lesson-19-creating-arrays/lesson.tres" type="Resource" id=15] | ||
[ext_resource path="res://course/lesson-9-adding-and-subtracting/lesson.tres" type="Resource" id=16] | ||
[ext_resource path="res://course/lesson-5-your-first-function/lesson.tres" type="Resource" id=17] | ||
[ext_resource path="res://course/lesson-16-2d-vectors/lesson.tres" type="Resource" id=18] | ||
[ext_resource path="res://course/lesson-8-defining-variables/lesson.tres" type="Resource" id=19] | ||
[ext_resource path="res://course/lesson-12-using-variables/lesson.tres" type="Resource" id=20] | ||
[ext_resource path="res://course/lesson-3-standing-on-shoulders-of-giants/lesson.tres" type="Resource" id=21] | ||
[ext_resource path="res://course/lesson-26-looping-over-dictionaries/lesson.tres" type="Resource" id=22] | ||
[ext_resource path="res://course/lesson-22-functions-return-values/lesson.tres" type="Resource" id=23] | ||
[ext_resource path="res://course/lesson-18-for-loops/lesson.tres" type="Resource" id=24] | ||
[ext_resource path="res://course/lesson-6-multiple-function-parameters/lesson.tres" type="Resource" id=25] | ||
[ext_resource path="res://course/lesson-10-the-game-loop/lesson.tres" type="Resource" id=26] | ||
[ext_resource path="res://course/lesson-17-while-loops/lesson.tres" type="Resource" id=27] | ||
[ext_resource path="res://course/lesson-14-multiplying/lesson.tres" type="Resource" id=28] | ||
[ext_resource path="res://course/lesson-15-modulo/lesson.tres" type="Resource" id=29] | ||
|
||
[resource] | ||
script = ExtResource( 1 ) | ||
title = "Learn GDScript From Zero" | ||
lessons = [ ExtResource( 29 ), ExtResource( 5 ), ExtResource( 14 ), ExtResource( 19 ), ExtResource( 23 ), ExtResource( 8 ), ExtResource( 27 ), ExtResource( 25 ), ExtResource( 22 ), ExtResource( 16 ), ExtResource( 6 ), ExtResource( 26 ), ExtResource( 10 ), ExtResource( 3 ), ExtResource( 9 ), ExtResource( 24 ), ExtResource( 7 ), ExtResource( 13 ), ExtResource( 21 ), ExtResource( 17 ), ExtResource( 4 ), ExtResource( 12 ), ExtResource( 18 ), ExtResource( 20 ), ExtResource( 28 ), ExtResource( 2 ), ExtResource( 11 ), ExtResource( 15 ) ] | ||
lessons = [ ExtResource( 5 ), ExtResource( 9 ), ExtResource( 21 ), ExtResource( 12 ), ExtResource( 17 ), ExtResource( 25 ), ExtResource( 3 ), ExtResource( 19 ), ExtResource( 16 ), ExtResource( 26 ), ExtResource( 2 ), ExtResource( 20 ), ExtResource( 7 ), ExtResource( 28 ), ExtResource( 29 ), ExtResource( 18 ), ExtResource( 27 ), ExtResource( 24 ), ExtResource( 15 ), ExtResource( 10 ), ExtResource( 14 ), ExtResource( 23 ), ExtResource( 6 ), ExtResource( 13 ), ExtResource( 4 ), ExtResource( 22 ), ExtResource( 8 ), ExtResource( 11 ) ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,60 @@ | ||
tool | ||
extends Node2D | ||
|
||
const COLOR_DEFAULT := Color("928fb8") | ||
const COLOR_NUMBER := Color("f5fafa") | ||
const COLOR_MODULO := Color("fff540") | ||
const COLOR_REMAINDER := Color("26c6f7") | ||
|
||
export var _offset := Vector2.ZERO | ||
export (int, 1, 7) var number := 5 setget _set_number, get_number | ||
export (int, 1, 7) var modulo := 3 setget _set_modulo, get_modulo | ||
const NORMAL_STYLEBOX := preload("res://course/lesson-15-modulo/visuals/Modulo/normal_stylebox.tres") | ||
const REMAINDER_STYLEBOX := preload("res://course/lesson-15-modulo/visuals/Modulo/remainder_stylebox.tres") | ||
const MODULO_SIZE_X := 48 | ||
const MODULO_GAP := 4 | ||
|
||
onready var _blocks := $Blocks as Node2D | ||
export (int, 1, 7) var number := 5 setget _set_number | ||
export (int, 1, 7) var modulo := 3 setget _set_modulo | ||
|
||
var number_color := Color.black | ||
var modulo_color := Color.black | ||
|
||
onready var _result := $Result as Control | ||
onready var _result_blocks := $Result/HBoxContainerBlocks as HBoxContainer | ||
onready var _result_modulo := $Result/HBoxContainerModulo as HBoxContainer | ||
onready var _string := $String as RichTextLabel | ||
onready var _remainder := $Remainder as Label | ||
|
||
|
||
func _ready() -> void: | ||
_remainder.add_color_override("font_color", COLOR_REMAINDER) | ||
for block in _blocks.get_children(): | ||
block.get_node("Shadow").self_modulate = COLOR_NUMBER | ||
_align_blocks() | ||
number_color = NORMAL_STYLEBOX.border_color | ||
modulo_color = _result_modulo.get_child(0).get_stylebox("panel").border_color | ||
_update_visual() | ||
|
||
|
||
func _align_blocks() -> void: | ||
for c in _blocks.get_children(): | ||
c.visible = false | ||
|
||
var row := 0 | ||
var column := 0 | ||
for i in range(max(number, modulo)): | ||
_blocks.get_child(i).position = Vector2(40 * column, row * 40) + _offset | ||
row += 1 | ||
if row % modulo == 0 and modulo < number: | ||
column += 1 | ||
row = 0 | ||
|
||
|
||
func _update_visual() -> void: | ||
if number >= modulo: | ||
for i in range(number): | ||
_blocks.get_child(i).visible = false | ||
_blocks.get_child(i).get_node("Shadow").self_modulate = COLOR_NUMBER | ||
if i < number - (number % modulo): | ||
_blocks.get_child(i).visible = true | ||
_blocks.get_child(i).self_modulate = COLOR_DEFAULT | ||
else: | ||
_blocks.get_child(i).visible = true | ||
_blocks.get_child(i).self_modulate = COLOR_REMAINDER | ||
else: | ||
for i in range(modulo): | ||
_blocks.get_child(i).visible = true | ||
_blocks.get_child(i).self_modulate = COLOR_REMAINDER | ||
_blocks.get_child(i).get_node("Shadow").self_modulate = COLOR_MODULO | ||
if i >= number: | ||
_blocks.get_child(i).self_modulate = COLOR_DEFAULT | ||
|
||
_string.bbcode_text = "[center][color=#%s]%s[/color] %% [color=#%s]%s[/color][/center]" % [COLOR_NUMBER.to_html(), number, COLOR_MODULO.to_html(), modulo] | ||
var remainder := number % modulo | ||
var cap := max(number, remainder) | ||
for i in range(_result_blocks.get_child_count()): | ||
var block: Panel = _result_blocks.get_child(i) | ||
block.visible = i < cap | ||
block.add_stylebox_override("panel", NORMAL_STYLEBOX if i < number - remainder else REMAINDER_STYLEBOX) | ||
|
||
var rest := int(number / modulo) | ||
for i in range(_result_modulo.get_child_count()): | ||
var modulo_highlight: Panel = _result_modulo.get_child(i) | ||
modulo_highlight.visible = i < rest | ||
modulo_highlight.rect_min_size.x = MODULO_SIZE_X * modulo + MODULO_GAP * (modulo - 1) | ||
|
||
_string.bbcode_text = ( | ||
"[center][color=#%s]%s[/color] %% [color=#%s]%s[/color][/center]" % | ||
[number_color.to_html(), number, modulo_color.to_html(), modulo] | ||
) | ||
_remainder.text = "Remainder: %s" % [number % modulo] | ||
|
||
|
||
func _set_number(value: int) -> void: | ||
number = value | ||
if not _blocks: | ||
if not _result: | ||
return | ||
_align_blocks() | ||
_update_visual() | ||
|
||
|
||
func _set_modulo(value: int) -> void: | ||
modulo = value | ||
if not _blocks: | ||
if not _result: | ||
return | ||
_align_blocks() | ||
_update_visual() | ||
|
||
|
||
func get_number() -> int: | ||
return number | ||
|
||
|
||
func get_modulo() -> int: | ||
return modulo |
Oops, something went wrong.