Author Topic: UIKey Binding - keyboard+mouse selection problem  (Read 12664 times)

Kval

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
UIKey Binding - keyboard+mouse selection problem
« on: December 08, 2014, 08:07:05 AM »
Hey, I've been searching for this and could not find anything. Sorry if it's already answered somewhere.

I have a button that pops a typical settings meny, either by clicking said button or hitting escape using the UIKey Binding script. The method used is UIFlipActive/FlipActive. I'm also using UIKey Navigation to control the menu with the keyboard. So far so good, it works.

The issues I've run into are these:
- I do not get a selection controllable by the keyboard if I call the menu with the mouse.
- The keyboard selection is also controlled by the mouse by just dragging the mouse anywhere on the screen.
- I get both a keyboard selection and a mouse selection at the same time if I call the menu with UIKey Binding.
- I lose the keyboard selection if I hover it with the mouse. It is still there and can interact with its currently selected menu option and reappears if I try to move it though.

I'm not the coder on the project but is there any way I can fix these things?
Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIKey Binding - keyboard+mouse selection problem
« Reply #1 on: December 09, 2014, 01:37:16 PM »
There is only one type of selection -- you get an OnSelect(bool isSelected) event. What you seem to be talking about are hover events, which are completely different. To select something, you need to actually press on it, or give it selection via UICamera.selectedObject. UIKeyBinding has an option to select something when a key gets pressed. Once selection is given, nothing will remove it for you unless you do it using key navigation, hitting escape, or by doing it via code (UICamera.selectedObject = null).
« Last Edit: December 11, 2014, 08:55:43 AM by ArenMook »

Kval

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: UIKey Binding - keyboard+mouse selection problem
« Reply #2 on: December 10, 2014, 10:17:04 AM »
Actually I was talking about both the hover event and the selection, I just wasn't sure how they were separate things. It makes a lot more sense now. However, I'm still unable to get these two to play nicely with each other.

For example, it is confusing that the menu behaves differently depending on if it's called with UIKeyBinding or a mouse click (one creates a selection, the other does not). I can see the logic behind it though.

Am I correct to assume that the selection piggybacks on the hover event for displaying what its current selection is? If that is the case I think that's where most of my confusion comes from. In part because it looks like there's "sometimes" two hovers/selections at the same time, but also because the mouse can hide the selection by hovering it and leaving (making the button enter the "Normal" state, despite still being selected).

My ideas for solving my previously mentioned problems would be to:
- Create a selection both when clicking and using UIKeyBinding to call the menu.
- Have the selection snap to the button the mouse is currently hovering.
- Not have the UIButton enter its Normal state if the button is selected but the mouse leaves.

Quick edit: also make the selection not accept mouse input to move itself (it jumps to new buttons when the mouse have moved X distance anywhere on the screen).

Is this possible with the provided scripts or should I just bite the bullet and get familiar with the code side of things?

Again, thanks for your time.
« Last Edit: December 10, 2014, 10:22:47 AM by Kval »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIKey Binding - keyboard+mouse selection problem
« Reply #3 on: December 11, 2014, 08:58:31 AM »
Yes, the highlighting is done by having selection tie into the hover logic, which is why when you do an actual hover afterwards it overwrites the state. This is why you would ideally be using either keyboard or mouse navigation, not both. For both, you would need some custom logic to determine what was used last -- was it keyboard/joystick? Or was it the mouse? -- and go from there. You'll need to make a custom button class basically. It's not difficult -- just use that deterministic logic to figure out what type of input was used last, and change the color of the sprite accordingly.

codejoy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: UIKey Binding - keyboard+mouse selection problem
« Reply #4 on: February 14, 2015, 04:55:25 AM »
I am trying to get the third example working with the example scene 3 where that window goes back and forth.   It works but I want the UIKey Navigation script to work too.  Strange thing is all the animations are triggered on an OnClick it seems and I cannot figure out how to make that options window in the demo pop up when enter/ or a button a controller is pressed..it acts like it presses it does button animation and the sound but the options panel never comes in.
And as an aside, how can I make that options panel visible so I can edit on it too?



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIKey Binding - keyboard+mouse selection problem
« Reply #5 on: February 14, 2015, 09:48:00 AM »
Key navigation only works if the target object is actually enabled. You can see what it's doing just by examining the code -- it's a pretty short script. If you're opening another window you should stick to "starts enabled" instead. To quickly hide/show panels, use the panel tool that comes with NGUI.

codejoy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: UIKey Binding - keyboard+mouse selection problem
« Reply #6 on: February 15, 2015, 02:44:19 AM »
Okay I am still new to this,when you say target object (using the example 3) i am trying to make it where clicking A button on 360 wired controller goes to options panel.

I have "starts selected"  selected for the options button (but I think i want the first button to have that)....I am not sure where this starts enabled is... it seems like the "Select on Click" really does just that, selects the ui component as if it was hovered over or the controller was moved to it, but it doesnt push a OnClick to the system (so again all the components in the example 3 pick it up and change out to the options window).  Am I close to right?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIKey Binding - keyboard+mouse selection problem
« Reply #7 on: February 15, 2015, 01:59:53 PM »
Starts selected should be on some button inside the options window. The button that actually opens the options doesn't have to have that option. What I do in Windward, is I have a button on the screen in the top left corner that opens the options window. This button has UIKeyBinding on it that's set to some button. When I press this key, it also presses the button (as that's what key binding does). This opens my window.

codejoy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: UIKey Binding - keyboard+mouse selection problem
« Reply #8 on: February 15, 2015, 08:17:00 PM »
Ahhhh I think I was only using key navigation.   Sounds like I also need key binding too.   Maybe that's my missing piece

codejoy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: UIKey Binding - keyboard+mouse selection problem
« Reply #9 on: February 16, 2015, 12:28:04 AM »
Nope I really cannot believe I am making this so hard sorry.  I added a UIKey Binding to the Options Button in the Example 3 of the NGUI.  I thought with the UIKey Navigation Script plust the UIKey Binding Script I could make it where moving the arrow keys up and down (or joystick) would select buttons (it does that) but pressing enter (or JoyStickButton0) does not select the button and go onto the next window like at all.  The first button in that menu in the UIKey Navigation is set to "Starts Selected"
 The constraints on all buttons are set in the UIKey Navigation.  I simply want it to work just like as if you had clicked with the mouse the options button.  I noticed I thought that was part of what Example 4 in the NGUI examples is telling one to do, and that does not work and I didn't touch it... It spoke of in example four the override , for what to do the on click?   Is there something I am totally missing, is it because most the logic seems to be done in Example 3 through the UIPlay Animations ??? which respond to an OnClick which does not seem to be emulated when the button is selected and the enter or joystickbutton 0 is pressed?

apparently very lost.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIKey Binding - keyboard+mouse selection problem
« Reply #10 on: February 17, 2015, 09:23:35 PM »
UIPlayAnimation is set to enable the target game object's window before doing the tween. Do you actually enable it? If you don't, there is nothing to select as disabled objects can't be selected.

codejoy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: UIKey Binding - keyboard+mouse selection problem
« Reply #11 on: February 18, 2015, 01:19:33 AM »
I am confused as to what I am trying to have enabled... Is it through the UIKey Navigation or the UIKey Binding somewhere that I have to enable the options window I want to goto from hitting enter on the options button on the main window?

Actually I am making some progress, I changed the On Trigger condition for the animations that make that window fly in and out...I didn't realize there were so many conditions (On Click I don't want ditching mouse) I am going purely gamepad/keyboard navigation.  I thought "On Select" true... but that triggers just by moving the arrow keys or the joystick to select that button, it doesn't wait for enter key or button press before flying the windows in and out...  So it is closer, I mean I really am not changing anything in the Example 3 that I know of, just trying to get keyboard navigation with enter key or gamepad navigation with button press to actually goto the next window or come back depending upon the options button highlighted when they hit enter or a joystick button, or if the done button on the other window is highlighted when they hit enter or press a button on the gamepad.

« Last Edit: February 18, 2015, 01:29:24 AM by codejoy »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIKey Binding - keyboard+mouse selection problem
« Reply #12 on: February 18, 2015, 05:03:13 PM »
In the menu example that comes with NGUi there are two panels. One of them is disabled while the other one is active. Navigation between panels is facilitated by tweening one panel in and the other one out. Play tween or play animation scripts both have an option to first enable the target game object before playing the tween/animation. They also have an option to disable the game object after the animation completes. That's how the menu transitioning is set up in that example and that's what I was talking about. Transitioning from one menu to another is only possible if the target menu is actually enabled first.

codejoy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: UIKey Binding - keyboard+mouse selection problem
« Reply #13 on: February 19, 2015, 06:13:27 PM »
Okay.  I am trying to step back and evaluate what I am doing.

I originally opened up that Example 3, it had the nice window you click options it flies to the other window, you click done it flies back.  Does this all day.

I just wanted it to do this when the enter key or joystick was pressed and the options button was highlighted.

So I added to the Options Button in Panel - Main (which is enabled) two scripts:

I added a UIKey Navigation script (Added this to all the buttons on Panel - Main).  So great, I can move the keyboard up down and even hit enter and it makes the sound like it was clicked (as each button in this demo has a sound but the options button sounds different when clicked).  All this still happens.  It just never goes to the next window?  So i thought "a-ha I need a UIKey binding to intercept the enter/joystickbutton press"  So the UIKey binding on the options button is:
Key Code: Return
Modifier: None
Action: PressAndClick

I thought this would act as if a click was pressed on that button, which to me should set off the animations and the tweens.  But this never happens, it clicks, makse the noise, the animation of the clicking.

Now I discover if the UIKey binding is and attached to t hat options button, then pressing enter on any selection  always makes that one click too.  So i disabled the UIKey binding.

So I can select with the UIKey navigation script and arrow keys any button (and if I goto all their animations that do the hover animation, and change that to selected) the animations work as I press up and down on the arrow keys.  But pressing enter: does the click animation, plays the selected click sound but never goes to the other window.   Which the other window is ultimately disabled.  The thing that confuses me is why does it act like its clicking just never execute the fly to the other window, is it because the UIPlay Animation and UIPlay tween scripts are all looking for a trigger even of "OnClick" which if that was the case, and pressing enter on a button with UIKey Navigation on it means it should NOT make the clicking noise or anything, but it is, which sure enough the UIPlay sound looks for OnClick.

To me the Pressing enter while a key is selected (like options key) mimics an OnClick as the sound plays, and the other clicking animation plays, but the other things that trigger to onclick (Play animations to fly windows in and out) never play.  So I am not sure what I am missing, the UIPlay Animations all have if disabled on start enable the play (the two animations for the window no the one for the button selection, that was previous on hover

Since this is to me a simple case of attaching the UIKey Navigation to the options button from that demo so that pressing enter (or the A button on a 360 game pad) makes that options button press and goto the other window seemed pretty straight forward I am not sure where the disconnect of my understanding of this process is.






ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIKey Binding - keyboard+mouse selection problem
« Reply #14 on: February 21, 2015, 08:00:09 AM »
UIKeyBinding should be used to activate a button via any keyboard or controller press. For example in Windward I have keybindings on all the hotbar buttons, letting users rebind them at will. So they can click the visible button, or they can press a key on the keyboard, the effect will be the same.

What I don't understand is why you're using example 3 as your starting point. Wouldn't example 4 be the better choice? It's the same menu, but navigates with a keyboard / controller. Everything you're trying to do is already done there as you want it to be done.