Author Topic: Swapping Panels doesn't set the focus  (Read 4265 times)

cygnus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Swapping Panels doesn't set the focus
« on: March 29, 2014, 07:33:13 AM »
Hi,

I'm pulling out my hairs here as I don't seem to find a solution to my problem. Note we are using a Gamepad to navigate the UI.
When the user presses the back key an ingame pause menu is shown (this is done by using NGUITools.AddChild) and the first menu choice is selected (buttons are set up normal and do all have the UIButtonKeys assigned and properly setted up).
When the user select his choice a new panel is added to this menu (again using NGUITools.AddChild) and everything works as expected.
However when the user pressed the B key to go back to the previous menu it is displayed properly but there is no focus assigned to the first choice (which has the selected on start flagged). I already tried to set the focus myself using UICamera.selectedObject but to no avail. Second try was to remove the menu using DestroyImmediate and instantiate it back with NGUITools.AddChild but again no luck (although this works the first time the menu is loaded  :-\)

Do I miss something or did I find a bug?

PS: I'm on NGUI 3.5.4.

cygnus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: Swapping Panels doesn't set the focus
« Reply #1 on: March 30, 2014, 04:58:33 AM »
Converted to NGUI 3.5.5 and replaced all UIButtonKeys to UIKeyNavigation. But still no luck, after looking into the new example I notice the workflow there is rather different then what I'm trying to achieve.
In your example you have a Done button in the options screen that relays back to the main menu. However what I'm trying to achieve is that when the user presses the B button the submenu is closed and the user gets back to the previous menu, so I can't set any OnClick on my buttons. Any possible way to achieve what I'm trying to do?
It drills down to that I want a Input.GetButton("B") to handle the swap of the panels.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Swapping Panels doesn't set the focus
« Reply #2 on: March 30, 2014, 07:40:04 AM »
"Select on start" isn't it. You need to set the "select on click". Whenever you press any button to open another window, you need to "pass" the focus to something inside that window. It's done via "select on click".

That's assuming that you set it up properly where you have an actual "Go Back" button (as in, a clickable control widget!), and you set UIKeyBinding to react to the "B" key.

If you don't, and you have your own code logic to detect the "B" key and react to it, then that's where you will need to do your selection transfer (manually).