Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: kittikun on February 11, 2014, 10:50:13 PM

Title: Progresss bar at zero still shows sprite
Post by: kittikun on February 11, 2014, 10:50:13 PM
Hi,

It doesn't seem possible to have a "true" 0% with the progress bar since the sprite is still showing. You can see the picture taken from "Example 0 - Control Widgets"

Is there any workaround this ?

Thank you

Title: Re: Progresss bar at zero still shows sprite
Post by: BehindTheStone on February 12, 2014, 04:24:15 AM
Well, you could do it by code.
Something like this

  1. if(bar.value <= 0)
  2. {
  3.    // deactivate sprite
  4. }
Title: Re: Progresss bar at zero still shows sprite
Post by: kittikun on February 13, 2014, 04:47:06 AM
Yes, I know..

I guess this was more like a feature request, it would have been nice to have a checkbox for this
Title: Re: Progresss bar at zero still shows sprite
Post by: Agent_007 on February 13, 2014, 05:31:32 AM
If you want to use Spliced sprite as progress indicator (with direct cuts), you actually might want three filled progress bars (UISprites) that create a one bar. It requires some extra work (you need three sprites instead of one, and you cannot use texture compression for the atlas), but it is doable
  1. public static void SetValueForThreePartBar(UISprite[] parts, float value)
  2.         {
  3.                 int totalWidth = parts[0].width + parts[1].width + parts[2].width;
  4.                 int valueWidth = Mathf.RoundToInt(value * totalWidth);
  5.                 if (valueWidth > totalWidth)
  6.                 {
  7.                         valueWidth = totalWidth;
  8.                 }
  9.  
  10.                 if (valueWidth < 1)
  11.                 {
  12.                         // Don't show anything
  13.                         parts[0].fillAmount = 0.0f;
  14.                         parts[1].fillAmount = 0.0f;
  15.                         parts[2].fillAmount = 0.0f;
  16.                 }
  17.                 else if (valueWidth <= parts[0].width)
  18.                 {
  19.                         // Show only first part
  20.                         parts[0].fillAmount = (float)(valueWidth) / (float)parts[0].width;
  21.                         parts[1].fillAmount = 0.0f;
  22.                         parts[2].fillAmount = 0.0f;
  23.                 }
  24.                 else if (valueWidth <= (parts[0].width + parts[1].width))
  25.                 {
  26.                         // Show first and second part
  27.                         parts[0].fillAmount = 1.0f;
  28.                         parts[1].fillAmount = (float)(valueWidth - parts[0].width) / (float)(parts[1].width);
  29.                         parts[2].fillAmount = 0.0f;
  30.                 }
  31.                 else
  32.                 {
  33.                         // Show all three parts
  34.                         parts[0].fillAmount = 1.0f;
  35.                         parts[1].fillAmount = 1.0f;
  36.                         parts[2].fillAmount = (float)(valueWidth - parts[0].width - parts[1].width) / (float)(parts[2].width);
  37.                 }
  38.         }