Files
Cinderwild/scripts/ui/hint_card.gd

65 lines
2.1 KiB
GDScript

extends Control
## Old Tam's tips in normal worlds (scripts/core/hints.gd): a card top right,
## under the clock, for 14 seconds. H puts it away early.
const UITheme = preload("res://scripts/ui/theme.gd")
const SHOW_FOR := 14.0
var _box: PanelContainer
var _title: Label
var _text: Label
var _tween: Tween
func setup() -> void:
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
mouse_filter = Control.MOUSE_FILTER_IGNORE
_box = UITheme.panel()
_box.set_anchors_and_offsets_preset(Control.PRESET_TOP_RIGHT)
_box.grow_horizontal = Control.GROW_DIRECTION_BEGIN
_box.offset_right = -22
_box.offset_top = 48
_box.custom_minimum_size = Vector2(340, 0)
_box.mouse_filter = Control.MOUSE_FILTER_IGNORE
_box.modulate.a = 0.0
_box.visible = false
add_child(_box)
var v := VBoxContainer.new()
v.add_theme_constant_override("separation", 4)
v.custom_minimum_size = Vector2(320, 0)
_box.add_child(v)
v.add_child(UITheme.label("%s's tip (H hides · tips can be turned off in the menu)" % Hints.guide_name if not Hints.guide_name.is_empty() else "Tip (H hides)", 13, UITheme.TEXT_DIM))
_title = UITheme.label("", 19)
v.add_child(_title)
_text = UITheme.label("", 15, UITheme.TEXT_DIM)
_text.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
_text.custom_minimum_size = Vector2(320, 0)
v.add_child(_text)
Hints.shown.connect(show_hint)
func show_hint(h: Dictionary) -> void:
Sfx.ui("ui_tip")
_title.text = String(h.title)
_text.text = ("\"%s\"" % String(h.text)) if not Hints.guide_name.is_empty() else String(h.text)
_box.visible = true
if _tween != null:
_tween.kill()
_tween = create_tween()
_tween.tween_property(_box, "modulate:a", 1.0, 0.4)
_tween.tween_interval(SHOW_FOR)
_tween.tween_property(_box, "modulate:a", 0.0, 0.8)
_tween.tween_callback(func(): _box.visible = false)
func is_showing() -> bool:
return _box.visible
func hide_hint() -> void:
if _tween != null:
_tween.kill()
_box.visible = false
_box.modulate.a = 0.0
func _unhandled_input(event: InputEvent) -> void:
if _box.visible and event is InputEventKey and event.pressed and not event.echo and event.keycode == KEY_H:
hide_hint()
get_viewport().set_input_as_handled()