refactor with ColorRect

This commit is contained in:
Fabien Freling 2019-11-27 00:50:35 +01:00
parent d98ad5fd23
commit 8a720717e4
4 changed files with 73 additions and 11 deletions

View file

@ -5,11 +5,13 @@ tool
export var size: int = 64
var number: int = 0
func _draw() -> void:
draw_rect(Rect2(0, 0, size, size), Color.yellow)
#func _draw() -> void:
# draw_rect(Rect2(0, 0, size, size), Color.yellow)
func set_number(num: int) -> void:
number = num
func _ready() -> void:
$Label.text = str(number)
$ColorRect.rect_size.x = size
$ColorRect.rect_size.y = size
$ColorRect/Label.text = str(number)

View file

@ -1,12 +1,64 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=5 format=2]
[ext_resource path="res://src/Piece.gd" type="Script" id=1]
[sub_resource type="VisualShaderNodeColorConstant" id=1]
constant = Color( 0.73997, 0.960938, 0.446686, 1 )
[sub_resource type="VisualShader" id=2]
code = "shader_type canvas_item;
void vertex() {
// Output:0
}
void fragment() {
// Color:2
vec3 n_out2p0;
float n_out2p1;
n_out2p0 = vec3(0.739970,0.960938,0.446686);
n_out2p1 = 1.000000;
// Output:0
COLOR.rgb = n_out2p0;
}
void light() {
// Output:0
}
"
mode = 1
flags/light_only = false
nodes/fragment/0/position = Vector2( 380, 80 )
nodes/fragment/2/node = SubResource( 1 )
nodes/fragment/2/position = Vector2( 140, 80 )
nodes/fragment/connections = PoolIntArray( 2, 0, 0, 0 )
[sub_resource type="ShaderMaterial" id=3]
shader = SubResource( 2 )
[node name="Piece" type="Node2D"]
script = ExtResource( 1 )
[node name="Label" type="Label" parent="."]
margin_right = 40.0
margin_bottom = 14.0
[node name="ColorRect" type="ColorRect" parent="."]
material = SubResource( 3 )
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = 128.0
margin_bottom = 128.0
[node name="Label" type="Label" parent="ColorRect"]
margin_left = 10.0
margin_top = 10.0
margin_right = 50.0
margin_bottom = 50.0
rect_scale = Vector2( 3, 3 )
rect_clip_content = true
size_flags_vertical = 1
custom_colors/font_color = Color( 0, 0, 0, 1 )
text = "!"
text = "0"

View file

@ -19,8 +19,8 @@ var pieces: Array = []
var missing_piece: Vector2
var rng = RandomNumberGenerator.new()
func _draw() -> void:
draw_rect(Rect2(0, 0, width, height), Color.blue)
#func _draw() -> void:
# draw_rect(Rect2(0, 0, width, height), Color.blue)
func position_for_index(index: Vector2, size: int) -> Vector2:
var padding_w = (width - (size * columns)) / (columns + 1)
@ -29,6 +29,9 @@ func position_for_index(index: Vector2, size: int) -> Vector2:
func _ready() -> void:
$ColorRect.rect_size.x = width
$ColorRect.rect_size.y = height
rng.randomize()
var piece_size: int = compute_piece_size()
@ -46,7 +49,7 @@ func _ready() -> void:
missing_piece.x = c
missing_piece.y = r
add_child(piece)
$ColorRect.add_child(piece)
pieces_row.append(piece)
pieces.append(pieces_row)

View file

@ -4,3 +4,8 @@
[node name="Taquin" type="Node2D"]
script = ExtResource( 1 )
[node name="ColorRect" type="ColorRect" parent="."]
margin_right = 512.0
margin_bottom = 512.0
color = Color( 0.254902, 0.329412, 0.45098, 1 )