WittleWolfie / ModMenu

MIT License
19 stars 5 forks source link

OnPress event of bound key fires multiple times #7

Closed apocc closed 2 years ago

apocc commented 2 years ago

It seems the OnPress event of a bound key via ModMenu is fired multiple times (UMM log):

When I then exit to the main menu everything seems to be normal.

Tested with game v2.0.3i and ModMenu v1.2.5

Edit: RenewRegisteredBindings doesn't remove the callback binding in m_BindingCallbacks. Rebinding the key just adds the same callback to m_BindingCallbacks.

A DoUnbind before binding the key removes the callback.

if (Game.Instance.Keyboard.GetBindingByName(keyBinding.Entity.Key) != null)
{
  Main.Logger.Log($"Unbinding key: {keyBinding.Entity.Key}");
  Game.Instance.Keyboard.DoUnbind(keyBinding.Entity.Key, keyBinding.OnPress);
}

Game.Instance.Keyboard.Bind(keyBinding.Entity.Key, keyBinding.OnPress);
WittleWolfie commented 2 years ago

Thanks! I'll take a look this weekend.

WittleWolfie commented 2 years ago

BTW feel free to submit PRs if you've got a fix. Happy to have external contributions.