Skip to reading
Text & Sierra-Style Adventures

A4. Controller source: lines 106-140

Edition 0.86.3.4

Build a complete text or graphical parser adventure with typed commands, inventory puzzles and press-to-walk controls.

Download PDFView PDF page

Focus, reply dismissal and keyboard shortcuts.

Code example
    if pending_reply and code in [KEY_ENTER, KEY_ESCAPE]:
        dismiss_reply()
        get_viewport().set_input_as_handled()
        return
    var focused: Control = get_viewport().gui_get_focus_owner()
    var typing: bool = focused is LineEdit or focused is TextEdit
    if code == KEY_ESCAPE and typing:
        focused.release_focus()
        get_viewport().set_input_as_handled()
    elif code == KEY_SPACE and not typing and not pending_reply:
        focus_command()
        get_viewport().set_input_as_handled()
    elif code == KEY_F3 and not pending_reply:
        focus_command()
        var field: LineEdit = control(
            "text_command" if text_mode() else "graph_command")
        field.text = str(Runtime.variables.get("ta_last", ""))
        field.caret_column = field.text.length()
        get_viewport().set_input_as_handled()
    elif not typing and not pending_reply:
        var shortcuts: Dictionary = {
            KEY_F1:"help", KEY_F5:"save", KEY_F7:"restore",
            KEY_TAB:"inventory"
        }
        if shortcuts.has(code):
            get_viewport().set_input_as_handled()
            send(str(shortcuts[code]))
        elif key.unicode >= 32 and not text_mode():
            if key.ctrl_pressed or key.alt_pressed or key.meta_pressed:
                return
            focus_command()
            var field: LineEdit = control("graph_command")
            field.insert_text_at_caret(String.chr(key.unicode))
            get_viewport().set_input_as_handled()

Continue directly with the next source block.

Page 57 of 68Permalink
Go to page