Author Topic: Long Popup List  (Read 23768 times)

adam718

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 60
    • View Profile
Re: Long Popup List
« Reply #15 on: December 26, 2012, 12:16:03 PM »
But I should do click, click & drag, of the item.
Then parent gets lost focus and would destroy panel.

I am sorry I couldn't understand your intension.
Could you explain me in more detail?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Long Popup List
« Reply #16 on: December 26, 2012, 12:17:41 PM »
Sounds like what you need then is to have just one collider -- for the background, instead of individual items. Then in OnClick you'd actually determine which label you clicked over and do the selection.

adam718

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 60
    • View Profile
Re: Long Popup List
« Reply #17 on: December 26, 2012, 12:19:01 PM »
Oh! I understand now.
Thank you Aren.
I will update it right now.

Thank you very much. ;D

adam718

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 60
    • View Profile
Re: Long Popup List
« Reply #18 on: December 26, 2012, 10:43:43 PM »
Hi Aren.
I changed my code.
But I have a problem to determine which label is selected.
I made parent panel and OnPanelClick().
in OnPanelClick, I try to get mouse pos by UICamera.lastHit.point and determine which label is selected.
But now i am wondering how to get real(localposition) from UICamera.lastHit.point.

Could you tell me the easy way how to determine which label is selected.

Thank you.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Long Popup List
« Reply #19 on: December 27, 2012, 12:42:52 AM »
You should know how tall each line is as you're the one who positions the labels. Knowing this, calculating which label you are currently on should be trivial.

adam718

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 60
    • View Profile
Re: Long Popup List
« Reply #20 on: December 27, 2012, 02:18:42 AM »
You should know how tall each line is as you're the one who positions the labels. Knowing this, calculating which label you are currently on should be trivial.
I could know easily the first, just the height of label.
But calculating is my problem how to do it.

adam718

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 60
    • View Profile
Re: Long Popup List
« Reply #21 on: December 27, 2012, 02:49:27 AM »
Hi Aren.
I resolve my problem.
Before upload my files, I want you to see this code snippet.
This is the code to determine which item is selected.

    void OnPanelClick(GameObject go)
    {
        UILabel lbl = GetSelectedItem();
        Select(lbl, true);
    }

    UILabel GetSelectedItem()
    {
        //. determine which label will be selected
        //. mChildPanel : draggable panel of popup list
        Vector3 panelPos = UICamera.currentCamera.WorldToScreenPoint(mChildPanel.transform.position);
        float fDelta = panelPos.y - UICamera.currentTouch.pos.y;
        int nItem = (int)(fDelta / (font.size * textScale + padding.y));

        return mLabelList[nItem];
    }

Thank you.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Long Popup List
« Reply #22 on: December 27, 2012, 11:58:32 AM »
I can see there being issues with this code when running with a non-automatic UIRoot, as the UI will not be in pixels but in virtual units.

The mChildPanel.transform.localPosition already tells you the value in virtual units. No need to WorldToScreenPoint anything.

adam718

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 60
    • View Profile
Re: Long Popup List
« Reply #23 on: December 27, 2012, 12:05:54 PM »
Thank you Aren.
mChildPanel is not a child of UIRoot.
It's a child of other gameobject, and I should get a absolute position rather than relative position (local position)
So I did WorldToScreenPoint.

Thanks again, I will upload my files right away.

Robon

  • Guest
Re: Long Popup List
« Reply #24 on: April 19, 2013, 02:48:44 PM »
Was this ever finished? It looks very interesting.

adam718

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 60
    • View Profile
Re: Long Popup List
« Reply #25 on: April 19, 2013, 10:45:21 PM »
it works with 2.5.1. and may have some problems.

Russel

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: Long Popup List
« Reply #26 on: June 11, 2013, 04:10:20 AM »
What do I need to change in GetSelectedItem(), so that it works with "FixedSizeOnMobiles"? It works correctly only with "Pixel Perfect" in the UIRoot. I am grateful for any tips.

    UILabel GetSelectedItem()
    {
        //. determine which label will be selected
        Vector3 panelPos = UICamera.currentCamera.WorldToScreenPoint(mChildPanel.transform.position);
        float fDelta = panelPos.y - UICamera.currentTouch.pos.y;
        int nItem = (int)(fDelta / (font.size * textScale + padding.y));
       
        if (nItem < 0 || nItem >= mLabelList.Count)
            return null;

        return mLabelList[nItem];
    }


Russel

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: Long Popup List
« Reply #27 on: June 12, 2013, 03:32:58 AM »
Nobody can help me?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Long Popup List
« Reply #28 on: June 12, 2013, 04:08:46 AM »
Adjust by UIAtlas.pixelSize I'm guessing.

Russel

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: Long Popup List
« Reply #29 on: June 13, 2013, 09:13:44 AM »
Thank you!

I found this:

"You can read the actual screen size in Screen.height and compare that with the value UIRoot has calculated, to figure out your widget's actual pixel size on the screen." (http://www.tasharen.com/forum/index.php?topic=3162.0)

I have now tried it so:

int nItem = (int)((fDelta / (font.size * textScale + padding.y))*(transform.root.GetComponent<UIRoot>().manualHeight/Screen.height));

It seems to work with:

UIRoot.manualHeight=960
Screen.Height=480

Pixel Size is 2

but not with:

UIRoot.manualHeight=1136
Screen.Height=854

Pixel Size is 1.3302...

Is this the right way? Maybe you have a solution?