From fd3750546d81c6ec7e9aa9177b92b1fa46e8f944 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Fri, 16 Aug 2019 15:29:00 +0200 Subject: [PATCH] Add shader for making phase icons change color --- Scenes/Board/UI/PhaseColor.shader | 19 +++++++++++ Scenes/BoardUI.tscn | 55 +++++++++++++++++++++++++++++-- Scenes/Scripts/BoardUI.gd | 6 ++-- 3 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 Scenes/Board/UI/PhaseColor.shader diff --git a/Scenes/Board/UI/PhaseColor.shader b/Scenes/Board/UI/PhaseColor.shader new file mode 100644 index 0000000..e2ead32 --- /dev/null +++ b/Scenes/Board/UI/PhaseColor.shader @@ -0,0 +1,19 @@ +shader_type canvas_item; +render_mode unshaded; + +uniform vec4 fillColor: hint_color; +uniform vec4 baseColor: hint_color; +uniform float fillRatio: hint_range(0.0, 1.0); +uniform float fillAngle: hint_range(0.0, 6.28); + +void fragment() { + vec4 col = texture(TEXTURE, UV); + vec3 mask = col.xyz * -1.0 + 1.0; + if (UV.y+fillAngle*UV.x > (1.0 - fillRatio)*1.2) { + mask *= fillColor.xyz; + col.xyz += mask.xyz; + } else { + col.xyz += baseColor.xyz; + } + COLOR = col; +} \ No newline at end of file diff --git a/Scenes/BoardUI.tscn b/Scenes/BoardUI.tscn index 8bb1019..32e4828 100644 --- a/Scenes/BoardUI.tscn +++ b/Scenes/BoardUI.tscn @@ -1,9 +1,53 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=10 format=2] [ext_resource path="res://Scenes/Scripts/BoardUI.gd" type="Script" id=1] [ext_resource path="res://Scenes/Board/UI/PhaseIcon.tscn" type="PackedScene" id=2] [ext_resource path="res://MLPAssets/Placeholders/unknowncard.jpg" type="Texture" id=3] +[sub_resource type="Shader" id=2] +code = "shader_type canvas_item; +render_mode unshaded; + +uniform vec4 fillColor: hint_color; +uniform vec4 baseColor: hint_color; +uniform float fillRatio: hint_range(0.0, 1.0); + +void fragment() { + vec4 col = texture(TEXTURE, UV); + vec3 mask = col.xyz * -1.0 + 1.0; + if (UV.y > 1.0 - fillRatio) { + mask *= fillColor.xyz; + col.xyz += mask.xyz; + } else { + col.xyz += baseColor.xyz; + } + COLOR = col; +}" + +[sub_resource type="ShaderMaterial" id=3] +shader = SubResource( 2 ) +shader_param/fillColor = Color( 1, 0.298039, 0.137255, 1 ) +shader_param/baseColor = Color( 0, 0, 0, 1 ) +shader_param/fillRatio = 0.0 + +[sub_resource type="ShaderMaterial" id=4] +shader = SubResource( 2 ) +shader_param/fillColor = Color( 1, 0.298039, 0.137255, 1 ) +shader_param/baseColor = Color( 0, 0, 0, 1 ) +shader_param/fillRatio = 0.0 + +[sub_resource type="ShaderMaterial" id=5] +shader = SubResource( 2 ) +shader_param/fillColor = Color( 1, 0.298039, 0.137255, 1 ) +shader_param/baseColor = Color( 0, 0, 0, 1 ) +shader_param/fillRatio = 0.0 + +[sub_resource type="ShaderMaterial" id=6] +shader = SubResource( 2 ) +shader_param/fillColor = Color( 1, 0.298039, 0.137255, 1 ) +shader_param/baseColor = Color( 0, 0, 0, 1 ) +shader_param/fillRatio = 0.0 + [sub_resource type="Animation" id=1] resource_name = "fade ui card" length = 0.1 @@ -85,6 +129,7 @@ size_flags_vertical = 3 alignment = 1 [node name="ReadyPhase" parent="Panel/HBoxContainer" instance=ExtResource( 2 )] +material = SubResource( 3 ) margin_left = 819.0 margin_top = 0.0 margin_right = 899.0 @@ -93,6 +138,7 @@ rect_scale = Vector2( 1, 1 ) mouse_filter = 2 [node name="TroublePhase" parent="Panel/HBoxContainer" instance=ExtResource( 2 )] +material = SubResource( 4 ) margin_left = 903.0 margin_top = 0.0 margin_right = 983.0 @@ -102,6 +148,7 @@ mouse_filter = 2 phaseID = 1 [node name="MainPhase" parent="Panel/HBoxContainer" instance=ExtResource( 2 )] +material = SubResource( 5 ) margin_left = 987.0 margin_top = 0.0 margin_right = 1067.0 @@ -111,6 +158,7 @@ mouse_filter = 2 phaseID = 2 [node name="ScorePhase" parent="Panel/HBoxContainer" instance=ExtResource( 2 )] +material = SubResource( 6 ) margin_left = 1071.0 margin_top = 0.0 margin_right = 1151.0 @@ -121,7 +169,6 @@ phaseID = 3 [node name="CardZoom" type="TextureRect" parent="."] visible = false -modulate = Color( 1, 1, 1, 0 ) anchor_bottom = 1.0 margin_left = 40.0 margin_top = 20.0 @@ -135,5 +182,7 @@ texture = ExtResource( 3 ) expand = true stretch_mode = 5 -[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +[node name="PhaseAnimations" type="AnimationPlayer" parent="."] + +[node name="CardAnimations" type="AnimationPlayer" parent="."] "anims/fade ui card" = SubResource( 1 ) diff --git a/Scenes/Scripts/BoardUI.gd b/Scenes/Scripts/BoardUI.gd index 15b42e6..826fecc 100644 --- a/Scenes/Scripts/BoardUI.gd +++ b/Scenes/Scripts/BoardUI.gd @@ -1,6 +1,6 @@ extends Control -onready var animation = $AnimationPlayer +onready var cardanim = $CardAnimations onready var cardPic = $CardZoom var menu: PopupMenu = null @@ -8,10 +8,10 @@ var menu: PopupMenu = null func _card_selected(card: Card): # TODO Hide card if it shouldn't be visible cardPic.texture = card.texture - animation.play("fade ui card") + cardanim.play("fade ui card") func _card_unselected(card: Card): - animation.play_backwards("fade ui card") + cardanim.play_backwards("fade ui card") func show_card_menu(card: Card, cbobj: Object, cbfn): # Close any open menus