Skip to reading
Eight Adventure Interface Workshops

Select a coin action on mouse release

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page

Record ID: curse_release. Global Script: on. Keep Verb Direct configured for curse_coin and retain the three listed choice IDs.

Code example
extends "res://scripts/runtime/script_base.gd"
Code example
var tracking: bool = false
const CHOICES: Dictionary = {"curse_coin_look":"look",
    "curse_coin_use":"use", "curse_coin_talk":"talk"}
Code example
func on_global_ready(_context: Dictionary = {}) -> void:
    set_process(true)
Code example
func _process(_delta: float) -> void:
    if not is_instance_valid(Runtime):
        return
    var manager: Node = Runtime.get("authored_gui_manager")
    if not is_instance_valid(manager):
        return
    var visible_now: bool = bool(manager.call("is_gui_visible", "curse_coin"))
    var holding: bool = Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)
    if holding and visible_now and not str(Runtime.get("verb_direct_target")).is_empty():
        tracking = true
    if not tracking or holding:
        return
    tracking = false
    if not visible_now:
        return
    var nodes: Dictionary = manager.get("element_nodes")
    var pointer: Vector2 = get_viewport().get_mouse_position()
    for element_id: String in CHOICES:
        var control: Control = nodes.get(element_id) as Control
        if not is_instance_valid(control):
            continue
        var local: Vector2 = control.get_global_transform_with_canvas().affine_inverse() * pointer
        if Rect2(Vector2.ZERO, control.size).has_point(local):
            Runtime.call("choose_verb_from_gui", str(CHOICES[element_id]), false)
            return
    manager.call("hide_gui", "curse_coin")
    Runtime.set("verb_direct_target", "")

This adds a release gesture to a working target-first popup. It does not add a delayed hold threshold, an animated software cursor or automatic near-pointer positioning.

Page 107 of 119Permalink
Go to page