Author Topic: Using DPAD with UIScrollBar  (Read 3889 times)

PompeyBlue

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 8
    • View Profile
Using DPAD with UIScrollBar
« on: October 27, 2016, 09:17:56 AM »
I am almost complete with porting my game over to DPAD with NGUI. Just one last thing.

The game uses UIScrollBar and has prefabs inside which are selectable buttons. If I move the controller up or down, the selected button moves fine. However it also moves the scroll bar too (I have Pan set to horizonta as well). Is it possible to adjust UIScrollBar so that it keeps whatever is hovered over, central inside the UIScrollBar in view? Obviously if it's the first, or last item, then it should still be at the top / bottom of the UIScrollBar.

Essentially I need to decouble pan as it's being used by whatever has hover in the window.

That way, in controller mode, I could select the different objects and the scroll bar would auto scroll as I went through them

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Using DPAD with UIScrollBar
« Reply #1 on: October 30, 2016, 12:15:30 PM »
I'm not sure I understand your question properly... Scroll bar needs to be outside your scroll view. Sounds like you have it inside of it? Or did you mean something else by moving the scroll bar? And why mention "pan"? Do you have the scroll view set to move both horizontally and vertically? If so, that's a mistake, as it should be set to move only on one dimension.

The scroll bar always represents the current position of what's visible against the actual dimensions of the content.

PompeyBlue

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Using DPAD with UIScrollBar
« Reply #2 on: December 13, 2016, 02:54:50 PM »
Hello

Sorry in the time to get back. We have been crazy with the PS4 port. When it's complete I'll send a full list of mods I've made to NGUI. There's only a couple, and they may be rejected, but they were what was needed to fully convert a touch game to dpad.

So with the problem I have right now - the pan control & dpad up / down are the same control.

I have a UIScrollView which has a UIGrid underneath. Inside that UIGrid I have a selection of UIButtons which all have UIKeyNavigation items on them and I can select the buttons up and down. What I want is, as I select the buttons I want the UIScrollView to always show the highlighted button.

However I am detecting OnPan messages coming to my UIScrollView which is then sent to the vertical scroll bar which then pans all of the content so my highlighted buttons scroll out of view. I'm wondering if there's a way I can ensure that the UIScrollView always displays the highlighted button?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Using DPAD with UIScrollBar
« Reply #3 on: December 15, 2016, 09:10:32 AM »
UICenterOnChild / UICenterOnClick scripts can be used to center the scroll view on a target object. If you want to check whether some object is visible, use UIPanel.IsVisible(widget) or UIPanel.IsVisible(position). Keeping a selection visible would be a bit more complicated as you'll need to do some math. You know the dimensions of the scroll view (UIPanel.finalClipRegion) and all widgets have UIRect.localCorners / worldCorners, giving you all you need to do a rect check. NGUI also has the NGUITools.FitOnScreen extension, but it's for keeping stuff visible on the screen, not within a scroll view. May help you figure out the math though.