godot-psd-training/UI/station_keys/outlined_key.gd

43 lines
898 B
GDScript3
Raw Normal View History

2024-04-12 11:06:25 +08:00
extends VBoxContainer
## 外轮廓线凸显shader材质
@export var outline_material: ShaderMaterial
## 鼠标进入范围外轮廓线颜色
static var ENTERED_COLOR = Vector4(0, 1.0, 1.0, 0.5)
## 聚焦时外轮廓线颜色
static var FOCUS_COLOR = Vector4(0, 1.0, 1.0, 1)
signal on_focus
var focus: bool = false
## 鼠标进入检测范围
func _on_area_2d_mouse_entered():
if not focus:
outline_material.set_shader_parameter("color", ENTERED_COLOR)
%Key.material = outline_material
## 鼠标离开检测范围
func _on_area_2d_mouse_exited():
if not focus:
%Key.material = null
func _on_focus_entered():
focus = true
on_focus.emit(self)
outline_material.set_shader_parameter("color", FOCUS_COLOR)
%Key.material = outline_material
func _on_focus_exited():
focus = false
%Key.material = null
func hide_key():
%Key.modulate.a = 0
func show_key():
%Key.modulate.a = 255