From e2db1fef2986d0354ac61e6d665a7929ea0a248e Mon Sep 17 00:00:00 2001 From: CactiChameleon9 Date: Sun, 17 Jul 2022 14:25:56 +0100 Subject: [PATCH] Add selection shader to show selected dice --- .gitignore | 3 ++ Scenes/BattleScene.gd | 10 ++++-- UI/Dice.gd | 13 ++++++++ UI/DiceView.gd | 13 ++++++-- UI/RainbowOutline.tres | 75 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 UI/RainbowOutline.tres diff --git a/.gitignore b/.gitignore index 822b784..04cce45 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,6 @@ export_presets.cfg .mono/ data_*/ +# Krita +*.png~ +*.kra~ diff --git a/Scenes/BattleScene.gd b/Scenes/BattleScene.gd index 122dd6b..bb32111 100644 --- a/Scenes/BattleScene.gd +++ b/Scenes/BattleScene.gd @@ -9,9 +9,13 @@ var player_movement_range = 5 func _ready(): # start with the DiceView being selected - $Diceiew.selected = true - $CardView.selected = false - self.selected = false + $UI/DiceView.selected = true + $UI/CardView.selected = false + self.player_to_move = false + + $UI/DiceView.roll_dice() + $UI/DiceView.roll_dice() + $UI/DiceView.roll_dice() func set_player_to_move(movement_range : int = 0): diff --git a/UI/Dice.gd b/UI/Dice.gd index 4510659..9c72a47 100644 --- a/UI/Dice.gd +++ b/UI/Dice.gd @@ -2,8 +2,19 @@ tool extends Control const dice_image_string = "res://Assets/Dice/Dice%s.png" +const selected_shader = preload("res://UI/RainbowOutline.tres") export (int, 1, 6) var dice_value : int setget _set_dice_value +export var selected : bool setget _set_selected + + +func _set_selected(new_value): + selected = new_value + if selected: + self.material = selected_shader + else: + self.material = null + func _set_dice_value(new_value): dice_value = new_value @@ -14,3 +25,5 @@ func _ready(): randomize() self.dice_value = int(round(rand_range(0.5, 6.49999999))) + + diff --git a/UI/DiceView.gd b/UI/DiceView.gd index 08f101e..73aeb5a 100644 --- a/UI/DiceView.gd +++ b/UI/DiceView.gd @@ -23,17 +23,24 @@ func _physics_process(delta): # move the selection forward or backward the list depending on input if (Input.is_action_just_pressed("ui_up") or Input.is_action_just_pressed("ui_left")): + + current_dice[selected_dice].selected = false + selected_dice += 1 - if selected_dice <= len(current_dice): + if selected_dice >= len(current_dice): selected_dice = 0 if (Input.is_action_just_pressed("ui_down") or Input.is_action_just_pressed("ui_right")): + + current_dice[selected_dice].selected = false + selected_dice -= 1 - if selected_dice > 0: + if selected_dice < 0: selected_dice = len(current_dice) -1 - + # enable the selected shader + current_dice[selected_dice].selected = true func roll_dice(specific_value : int = 0): diff --git a/UI/RainbowOutline.tres b/UI/RainbowOutline.tres new file mode 100644 index 0000000..760f676 --- /dev/null +++ b/UI/RainbowOutline.tres @@ -0,0 +1,75 @@ +[gd_resource type="ShaderMaterial" load_steps=2 format=2] + +[sub_resource type="Shader" id=1] +code = "shader_type canvas_item; + +uniform vec4 line_color : hint_color = vec4(1); +uniform float line_thickness : hint_range(0, 50) = 1.0; + +uniform bool rainbow = false; //Activate the rainbow or select you color +uniform float line_scale : hint_range(0, 20) = 1.2; // thickness of the line +uniform float frequency : hint_range(0.0, 2.0) = 0.5; // frequency of the rainbow +uniform float light_offset : hint_range(0.00001, 1.0) = 0.5; // this offsets all color channels; +uniform float alpha : hint_range(0.0, 1.0) = 1.0; + + +void fragment() { + vec2 size = TEXTURE_PIXEL_SIZE * line_thickness; + + float outline = texture(TEXTURE, UV + vec2(-size.x, 0)).a; + outline += texture(TEXTURE, UV + vec2(0, size.y)).a; + + outline += texture(TEXTURE, UV + vec2(size.x, 0)).a; + + outline += texture(TEXTURE, UV + vec2(0, -size.y)).a; + + + outline += texture(TEXTURE, UV + vec2(-size.x, size.y)).a; + + outline += texture(TEXTURE, UV + vec2(-size.x, size.y * 0.5)).a; + + + + outline += texture(TEXTURE, UV + vec2(size.x, size.y)).a; + outline += texture(TEXTURE, UV + vec2(size.x, size.y * 0.5)).a; + + + outline += texture(TEXTURE, UV + vec2(-size.x, -size.y)).a; + outline += texture(TEXTURE, UV + vec2(-size.x, -size.y * 0.5)).a; + + + + outline += texture(TEXTURE, UV + vec2(size.x, -size.y)).a; + outline += texture(TEXTURE, UV + vec2(size.x, -size.y * 0.5)).a; + + + outline = min(outline, 1.0); + + + vec4 color = texture(TEXTURE, UV); + + vec4 animated_line_color = vec4(light_offset + sin(2.0*3.14*frequency*TIME), + light_offset + sin(2.0*3.14*frequency*TIME + radians(120.0)), + light_offset + sin(2.0*3.14*frequency*TIME + radians(240.0)), + alpha); + + + if (rainbow == true){//if rainbow is activated + COLOR = mix(color, animated_line_color, outline - color.a); + } + if (rainbow == false){//if rainbow not is activated and you pick a color + COLOR = mix(color, line_color , outline - color.a); + } + +// COLOR = mix(color, line_color, outline - color.a); +}" + +[resource] +shader = SubResource( 1 ) +shader_param/line_color = Color( 1, 1, 1, 1 ) +shader_param/line_thickness = 35.0 +shader_param/rainbow = true +shader_param/line_scale = 1.2 +shader_param/frequency = 0.25 +shader_param/light_offset = 0.5 +shader_param/alpha = 1.0