snozbot / fungus

An easy to use Unity 3D library for creating illustrated Interactive Fiction games and more.
MIT License
1.59k stars 291 forks source link

When a Menu leads to a block that starts with Menu commands, you submit the next Menu with the same click #1057

Open TheEmbracedOne opened 2 years ago

TheEmbracedOne commented 2 years ago

Describe the bug I swear I had this issue in the past and I remember talking to people about it but I'm either amnesiac or imagined it or some other thing. I have a problem where if I have a set of Menu commands leading to a block that start with Menu commands, the mouseUp from the click that interacted with the first set of Menu commands will interact with the next Menus.

1) Current behaviour: Menu "AAAAA" appears, I click it, Menu "AAAAA" disappears, Menu "BBBBB" appears, and the same click "submits" it.

2) Same setup but with an added 0.5s Wait command at the start of each Block: there is now a minor delay before Menu "BBBBB" appears, so the same click, if the mouse wasnt held down after the click, will not "submit" the newly appearing "BBBBB" Menu, however:

3) Holding Mouse Down Problem: If I hold down the mouse after clicking a Menu then releasing it after "BBBBB" Menu appears, it will still "submit" the next menu, even with the 0.5s Wait before it.

To Reproduce Create a new Fungus Flowchart with just two blocks, each with at least one Menu dialogue, leading to the other block. Make sure the Menu commands display different text so it's easy to see the change. Enter play mode and click the menu appearing, and you'll observe the next set of menus will quickly appear, get clicked and disappear.

Expected behavior When a Menu is interacted with and the next Block starts with Menu commands, there should be a minor delay before they either A) appear B) become interactive (probably not ideal because the player would see greyed out options before they become interactive)

Versions & Platform (please complete the following information):

TheEmbracedOne commented 2 years ago

Upon further investigation I found that the culprit is button.onClick.AddListener(action);, because it, unbeknownst to me, circumvents my custom button event handler on every button in the game. I am using Rewired and I fire input events on button released, so it was very odd that upon further testing, Fungus Menu buttons kept submitting on mouse down, not up. Disabling my custom button event handler, the Menu buttons kept being interactive and submit-able, so I knew what I was looking for.

I replaced the button.onClick.AddListener(action); bit with a SendMessage that passes the UnityAction Fungus makes to my custom button event handler, so now the button successfully only submits on MouseUp (as I had intended) and the action goes through my custom button event handler.

I'm not sure if this is a problem for someone not using a custom event handler, so I'll leave my issue open for now in case anyone else with this problem stumbles upon it.