Add selection shader to show selected dice
This commit is contained in:
parent
c4b483b2a1
commit
e2db1fef29
3
.gitignore
vendored
3
.gitignore
vendored
@ -11,3 +11,6 @@ export_presets.cfg
|
||||
.mono/
|
||||
data_*/
|
||||
|
||||
# Krita
|
||||
*.png~
|
||||
*.kra~
|
||||
|
@ -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):
|
||||
|
13
UI/Dice.gd
13
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)))
|
||||
|
||||
|
||||
|
@ -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):
|
||||
|
75
UI/RainbowOutline.tres
Normal file
75
UI/RainbowOutline.tres
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user