112 lines
3.5 KiB
GDScript
112 lines
3.5 KiB
GDScript
extends PanelContainer
|
|
|
|
const res_action = preload("res://scenes/osd_action.tscn")
|
|
|
|
enum ICON_POSITION {
|
|
LEFT,
|
|
CENTER,
|
|
RIGHT
|
|
}
|
|
|
|
@onready var gui_tagline := $"OSDTagline"
|
|
@onready var gui_title := $"OSDTitle"
|
|
@onready var gui_actionbar := $"OSDActionBar"
|
|
|
|
@onready var tagline:
|
|
get: gui_tagline.text
|
|
set(value):
|
|
gui_tagline.text = value
|
|
@onready var title:
|
|
get: gui_title.text
|
|
set(value):
|
|
gui_title.text = value
|
|
var last_shown = -(GlobalConfig.osd_dwell_time + GlobalConfig.osd_fade_time)
|
|
|
|
func show_osd(a_tagline: String, a_title: String, a_actions: Array):
|
|
# Clear actions
|
|
for n in gui_actionbar.get_children():
|
|
gui_actionbar.remove_child(n)
|
|
n.queue_free()
|
|
|
|
tagline = a_tagline
|
|
title = a_title
|
|
for action in a_actions:
|
|
var button = res_action.instantiate()
|
|
var title: Label = button.get_node("Title")
|
|
var icon: Label = button.get_node("Icon")
|
|
|
|
title.text = action.title
|
|
|
|
if action.icon != null:
|
|
icon.text = action.icon
|
|
if action.icon_pos == ICON_POSITION.LEFT:
|
|
icon.set_anchors_preset(Control.PRESET_LEFT_WIDE)
|
|
icon.set_position(Vector2(0,-12))
|
|
elif action.icon_pos == ICON_POSITION.CENTER:
|
|
icon.set_anchors_preset(Control.PRESET_VCENTER_WIDE)
|
|
icon.set_position(Vector2(-12,-12))
|
|
else:
|
|
icon.set_anchors_preset(Control.PRESET_RIGHT_WIDE)
|
|
icon.set_position(Vector2(-24,-12))
|
|
|
|
if action.toggles:
|
|
button.toggle_mode = true
|
|
button.toggled.connect(action.action)
|
|
else:
|
|
button.pressed.connect(action.action)
|
|
|
|
gui_actionbar.add_child(button)
|
|
|
|
last_shown = Time.get_ticks_msec()
|
|
visible = true
|
|
modulate.a = GlobalConfig.osd_opacity
|
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
|
for n in gui_actionbar.get_children():
|
|
gui_actionbar.mouse_filter = Control.MOUSE_FILTER_STOP
|
|
|
|
func hide_osd():
|
|
last_shown = -(GlobalConfig.osd_dwell_time + GlobalConfig.osd_fade_time)
|
|
visible = false
|
|
modulate.a = GlobalConfig.osd_opacity
|
|
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
for n in gui_actionbar.get_children():
|
|
gui_actionbar.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
|
|
var mouse_inside = false
|
|
var mouse_just_inside = false
|
|
|
|
func _ready() -> void:
|
|
mouse_entered.connect(func(): mouse_inside = true; mouse_just_inside = true)
|
|
mouse_exited.connect(func(): mouse_inside = false)
|
|
|
|
func _process(delta: float) -> void:
|
|
var ft = GlobalConfig.osd_dwell_time + GlobalConfig.osd_fade_time
|
|
var time_since_shown = Time.get_ticks_msec() - last_shown
|
|
|
|
if mouse_inside and time_since_shown >= GlobalConfig.osd_dwell_time and time_since_shown < ft:
|
|
if mouse_just_inside:
|
|
mouse_just_inside = false
|
|
visible = true
|
|
modulate.a = GlobalConfig.osd_opacity
|
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
|
for n in gui_actionbar.get_children():
|
|
gui_actionbar.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
last_shown = Time.get_ticks_msec()
|
|
time_since_shown = 0
|
|
|
|
if time_since_shown >= ft and visible:
|
|
modulate.a = GlobalConfig.osd_opacity
|
|
visible = false
|
|
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
for n in gui_actionbar.get_children():
|
|
gui_actionbar.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
elif time_since_shown >= GlobalConfig.osd_dwell_time and time_since_shown < ft:
|
|
var percentage = min(1, float(time_since_shown - GlobalConfig.osd_dwell_time) / GlobalConfig.osd_fade_time)
|
|
modulate.a = (1 - percentage) * GlobalConfig.osd_opacity
|
|
visible = true
|
|
elif time_since_shown < GlobalConfig.osd_dwell_time and not visible:
|
|
modulate.a = GlobalConfig.osd_opacity
|
|
visible = true
|
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
|
for n in gui_actionbar.get_children():
|
|
gui_actionbar.mouse_filter = Control.MOUSE_FILTER_STOP
|