carenalgas / popochiu

Godot plugin to make point-and-click adventure games, inspired by tools like Adventure Game Studio and PowerQuest.
https://carenalgas.github.io/popochiu/
MIT License
205 stars 19 forks source link

Inventory bar close animation plays twice with fast clicks #350

Closed balloonpopper closed 1 day ago

balloonpopper commented 4 days ago

Bug description

I have an "_on_click" on a prop where I add an item to the inventory, hide the prop and show some system text.

I click on the prop and pick it up, the inventory opens and the item appears in it. If I quickly click while the text is showing (i.e. < 2 seconds) the inventory will close. When the 2 seconds has elapsed, the inventory appears and closes again.

Steps to reproduce

  1. Create a prop with code similar to this
    func _on_click() -> void:
    I.Bullets.add()
    R.get_prop("Bullets").hide()
    await G.show_system_text("You take a speed loader with six rounds of .357-magnum, hollow point, silver-jacketed bullets.")
  2. Run the scene. Click the prop to pick it up.
  3. Immediately click to see the text disappear and the inventory close.
  4. See the inventory close again ~2 seconds later.

Expected vs observed behavior

The inventory should only close once

Environment information (please complete):

Additional context

I have tracked down the cause - in inventory_bar.gd : _add_item has this code:

        _open()
        await get_tree().create_timer(2.0).timeout

        _close()
        await get_tree().create_timer(0.5).timeout

This will close the inventory automatically 2 seconds after you pick up an item.

_input in the same file has this code

func _input(event: InputEvent) -> void:
        <...>
    if _is_hidden and rect.has_point(get_global_mouse_position()):
        _open()
    elif not _is_hidden and not rect.has_point(get_global_mouse_position()):
        _close()

The last 2 lines (check that the mouse is not in the inventory panel) close the window immediately once the click to close the text box reenables input processing.

So _add_item opens the window, _input closes it, then _add_item re-closes it.