Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unfocussing still gives sounds #16

Open
devedse opened this issue Jan 5, 2019 · 4 comments
Open

Unfocussing still gives sounds #16

devedse opened this issue Jan 5, 2019 · 4 comments

Comments

@devedse
Copy link

devedse commented Jan 5, 2019

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 = "";
            }
        }
@EmptyKeys
Copy link
Owner

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).

@devedse
Copy link
Author

devedse commented Jan 6, 2019

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?

@EmptyKeys EmptyKeys reopened this Jan 7, 2019
@EmptyKeys
Copy link
Owner

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

@devedse
Copy link
Author

devedse commented Feb 7, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants