UI_Engines icon indicating copy to clipboard operation
UI_Engines copied to clipboard

Unfocussing still gives sounds

Open devedse opened this issue 5 years ago • 4 comments

I'm currently working on a 2d multiplayer game with chat functionality. I just used this stackoverflow post to create an IsFocussed extension: https://stackoverflow.com/a/7972361/1149816

However I'm now trying to implement something that if you click out of the chat box that no commands are being sent to the UI anymore. I keep hearing all kinds of pops and sound effects and also the UI is still responding to arrow presses. This also happens when I use the InputManager.Current.ClearFocus() method. For some reason the next update loop the GamePlayUI is set as the focussed element again.

Is there any way to completely clear the focus of the EmptyKeys library?

I've created a video of this problem: https://youtu.be/J001tU1ZucI

Incase you're wondering, the code that executes when you press enter or the Send button:

        private void OnChatEnterClick(object obj)
        {
            if (gameplayUIViewModel.ChatBoxFocussed == false)
            {
                gameplayUIViewModel.ChatBoxFocussed = true;
            }
            else if (string.IsNullOrEmpty(gameplayUIViewModel.ChatTextBoxText))
            {
                InputManager.Current.ClearFocus();
            }
            else
            {
                SendChat(gameplayUIViewModel.ChatTextBoxText);
                gameplayUIViewModel.ChatTextBoxText = "";
            }
        }

devedse avatar Jan 05 '19 18:01 devedse

Hi, in my game I have simple function which tells me if mouse is over UI or not. If it's not over UI i Clear Focus every frame (after UpdateInput of ui root).

EmptyKeys avatar Jan 06 '19 14:01 EmptyKeys

Isn't that something we'd rather have EmptyKeys handle itself? I think it should do something that if you click outside of the UI and it unfocusses everything untill you click in the UI again.

Could we build something like that inside EmptyKeys?

devedse avatar Jan 06 '19 23:01 devedse

I will write it down and think about it, if there is a good way to do it.

EmptyKeys avatar Jan 07 '19 19:01 EmptyKeys

If you have an update for this let me know :).

Maybe something like this would work:

  1. If you click the UI then that specific component gets focussed (Should be detectable by EmptyKeys).
  2. If you click outside of the UI then the UI gets unfocussed (Should be detectable by EmptyKeys).
  3. There should probably be a method to focus a specific UI component (e.g. pressing enter in game focusses the chatbox).
  4. There should probably be a method to unfocus the UI untill either the user clicks on it again or that specific UIComponent.Focus method is called again.

I think doing something like this makes the whole UI stuff very intuïtive and wouldn't need custom work from consumers of the library.

devedse avatar Feb 07 '19 20:02 devedse