56 lines
1.8 KiB
GDScript
56 lines
1.8 KiB
GDScript
extends Control
|
|
class_name BaseUI
|
|
|
|
onready var hover_effect = preload("res://ui/text_hover_effect.tscn").instance()
|
|
var ui_parent: Node
|
|
|
|
func _input(event):
|
|
if Globals.process_3d_inputs:
|
|
return
|
|
if Input.is_action_just_pressed("ui_cancel"):
|
|
close()
|
|
|
|
func connect_children(elem, event: String, method: String):
|
|
for control in elem.get_children():
|
|
if control is Button:
|
|
control.connect(event, self, method, [control])
|
|
connect_children(control, event, method)
|
|
|
|
func close():
|
|
if ui_parent:
|
|
ui_parent.visible = true
|
|
queue_free()
|
|
|
|
func enter_ui(ui: PackedScene):
|
|
var ui_scene = ui.instance()
|
|
ui_scene.ui_parent = self
|
|
visible = false
|
|
get_parent().add_child(ui_scene)
|
|
|
|
func _ready():
|
|
add_child(hover_effect)
|
|
hover_effect.visible = false
|
|
move_child(hover_effect, 1)
|
|
connect_children(self, "mouse_entered", "button_hover")
|
|
connect_children(self, "pressed", "button_click_sound")
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_CONFINED)
|
|
Input.set_custom_mouse_cursor(preload("res://assets/all_gbs/textures/cursor.tga"))
|
|
|
|
func button_hover(elem: Button):
|
|
if elem.disabled:
|
|
return
|
|
hover_effect.visible = true
|
|
var stream = preload("res://assets/audio/Sounds/MM_MINOR.xx_permanentaliens.gzp.wav")
|
|
Globals.play_sound(stream, Globals.Bus.Sounds)
|
|
var position = elem.rect_global_position
|
|
hover_effect.global_position = position + Vector2(elem.rect_size.x /2 - 10, elem.rect_size.y /2)
|
|
hover_effect.visible = true
|
|
var material: ParticlesMaterial
|
|
material = hover_effect.process_material
|
|
material.emission_box_extents = Vector3(elem.rect_size.x/2, 0, 0)
|
|
hover_effect.amount = pow(elem.rect_size.x/40, 2) + 10
|
|
|
|
func button_click_sound(_elem: Button):
|
|
var stream = preload("res://assets/audio/Sounds/MM_MAJOR.xx_permanentaliens.gzp.wav")
|
|
Globals.play_sound(stream, Globals.Bus.Sounds)
|