T4: Old Tam's tips in normal worlds, with a setting
This commit is contained in:
63
scripts/ui/hint_card.gd
Normal file
63
scripts/ui/hint_card.gd
Normal file
@@ -0,0 +1,63 @@
|
||||
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:
|
||||
_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()
|
||||
@@ -179,6 +179,11 @@ func _build_stats(root: Control) -> void:
|
||||
guide.name = "Guide"
|
||||
root.add_child(guide)
|
||||
guide.setup(player)
|
||||
# Old Tam's tips in normal worlds (T4), in the same place.
|
||||
var tips := preload("res://scripts/ui/hint_card.gd").new()
|
||||
tips.name = "HintCard"
|
||||
root.add_child(tips)
|
||||
tips.setup()
|
||||
|
||||
func _process(_d: float) -> void:
|
||||
_fade_chat()
|
||||
|
||||
@@ -80,6 +80,26 @@ func bind(p: CharacterBody3D) -> void:
|
||||
sens_row.add_child(sens)
|
||||
_main.add_child(sens_row)
|
||||
|
||||
# Old Tam's tips in normal worlds (T4): on or off, or all of them again.
|
||||
if not Guide.active:
|
||||
var tips_row := HBoxContainer.new()
|
||||
var tips := CheckButton.new()
|
||||
tips.text = "Old Tam's tips"
|
||||
tips.focus_mode = Control.FOCUS_NONE
|
||||
tips.button_pressed = Hints.enabled
|
||||
tips.add_theme_font_size_override("font_size", 18)
|
||||
tips.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
tips.toggled.connect(Hints.set_enabled)
|
||||
tips_row.add_child(tips)
|
||||
var again := Button.new()
|
||||
again.text = "Show again"
|
||||
again.focus_mode = Control.FOCUS_NONE
|
||||
again.add_theme_font_size_override("font_size", 15)
|
||||
again.tooltip_text = "Every tip shows once more, when it next fits"
|
||||
again.pressed.connect(func(): Hints.reset_seen(); again.text = "Done")
|
||||
tips_row.add_child(again)
|
||||
_main.add_child(tips_row)
|
||||
|
||||
# The tutorial: skip a step, or leave it (saved, to carry on later).
|
||||
if Guide.active:
|
||||
_main.add_child(_button("Skip this tutorial step", func(): Guide.skip(); close()))
|
||||
|
||||
Reference in New Issue
Block a user