Author Topic: UIImageButton Disabled state in 2.6.0  (Read 12558 times)

jmclaren

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
UIImageButton Disabled state in 2.6.0
« on: April 24, 2013, 08:06:04 AM »
Settting the disabled state for a UIImageButton  in editor mode changes the pressed state image instead, and the disabled state remains blank. Also, if you disable a button, it uses a random image for the disabled state

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIImageButton Disabled state in 2.6.0
« Reply #1 on: April 24, 2013, 11:09:08 AM »
Are the names you put in valid in the same atlas?

jmclaren

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: UIImageButton Disabled state in 2.6.0
« Reply #2 on: April 29, 2013, 05:35:56 AM »
yes, just picking them from the popup screen

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIImageButton Disabled state in 2.6.0
« Reply #3 on: April 29, 2013, 10:43:53 AM »
There was a bug in this script caused by yours truly. I think it may have been fixed already in the newest version of the pro version, and should be pushed out to standard as soon as 1.6.1 gets done.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIImageButton Disabled state in 2.6.0
« Reply #4 on: April 29, 2013, 06:02:25 PM »
1.6.1, Nicki? :)

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIImageButton Disabled state in 2.6.0
« Reply #5 on: May 02, 2013, 11:10:17 AM »

maoguo.zhang

  • Guest
Re: UIImageButton Pressed state in 2.6.1
« Reply #6 on: May 06, 2013, 12:08:52 AM »
It seems that UIImageButton.pressedSprite is never used in NGUI, so there is no pressed state when I press the image button.
« Last Edit: May 06, 2013, 12:34:03 AM by maoguo.zhang »

jarjin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: UIImageButton Pressed state in 2.6.1
« Reply #7 on: May 06, 2013, 09:04:33 PM »
It seems that UIImageButton.pressedSprite is never used in NGUI, so there is no pressed state when I press the image button.
+1
Me too~

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIImageButton Disabled state in 2.6.0
« Reply #8 on: May 06, 2013, 09:06:30 PM »
Get 2.6.1b.

maoguo.zhang

  • Guest
Re: UIImageButton Pressed state in 2.6.1c
« Reply #9 on: May 07, 2013, 04:00:59 AM »
Get 2.6.1b.

I got 2.6.1c. But the problem still exists. UIImageButton.pressedSprite which is set in inspector isn't used when pressing image button.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIImageButton Disabled state in 2.6.0
« Reply #10 on: May 07, 2013, 05:09:42 AM »
How is it not used? Here's the full UIImageButton script from 2.6.1c
  1. public class UIImageButton : MonoBehaviour
  2. {
  3.         public UISprite target;
  4.         public string normalSprite;
  5.         public string hoverSprite;
  6.         public string pressedSprite;
  7.         public string disabledSprite;
  8.        
  9.         public bool isEnabled
  10.         {
  11.                 get
  12.                 {
  13.                         Collider col = collider;
  14.                         return col && col.enabled;
  15.                 }
  16.                 set
  17.                 {
  18.                         Collider col = collider;
  19.                         if (!col) return;
  20.  
  21.                         if (col.enabled != value)
  22.                         {
  23.                                 col.enabled = value;
  24.                                 UpdateImage();
  25.                         }
  26.                 }
  27.         }
  28.  
  29.         void Awake () { if (target == null) target = GetComponentInChildren<UISprite>(); }
  30.         void OnEnable () { UpdateImage(); }
  31.         void OnHover (bool isOver) { if (enabled) UpdateImage(); }
  32.         void OnPress (bool pressed) { if (enabled) UpdateImage(); }
  33.        
  34.         void UpdateImage()
  35.         {
  36.                 if (target != null)
  37.                 {
  38.                         if (isEnabled)
  39.                         {
  40.                                 target.spriteName = UICamera.IsHighlighted(gameObject) ? hoverSprite : normalSprite;
  41.                         }
  42.                         else
  43.                         {
  44.                                 target.spriteName = disabledSprite;
  45.                         }      
  46.                         target.MakePixelPerfect();
  47.                 }
  48.         }
  49. }
It's clearly used in UpdateImage(), which is called when you set isEnabled.

maoguo.zhang

  • Guest
Re: UIImageButton Disabled state in 2.6.0
« Reply #11 on: May 07, 2013, 05:20:45 AM »
There are hoverSprite, normalSprite and disableSprite in UpdateImage, but pressedSprite is not used.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIImageButton Disabled state in 2.6.0
« Reply #12 on: May 07, 2013, 05:24:20 AM »
Hmm you're right, I was looking at the disabled sprite.

Looks like Nicki took the liberty of removing something rather important... I'm just going to revert the whole thing and start over.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIImageButton Disabled state in 2.6.0
« Reply #13 on: May 07, 2013, 05:29:28 AM »
Try this one.
  1. public class UIImageButton : MonoBehaviour
  2. {
  3.         public UISprite target;
  4.         public string normalSprite;
  5.         public string hoverSprite;
  6.         public string pressedSprite;
  7.         public string disabledSprite;
  8.        
  9.         public bool isEnabled
  10.         {
  11.                 get
  12.                 {
  13.                         Collider col = collider;
  14.                         return col && col.enabled;
  15.                 }
  16.                 set
  17.                 {
  18.                         Collider col = collider;
  19.                         if (!col) return;
  20.  
  21.                         if (col.enabled != value)
  22.                         {
  23.                                 col.enabled = value;
  24.                                 UpdateImage();
  25.                         }
  26.                 }
  27.         }
  28.  
  29.         void Awake () { if (target == null) target = GetComponentInChildren<UISprite>(); }
  30.         void OnEnable () { UpdateImage(); }
  31.        
  32.         void UpdateImage()
  33.         {
  34.                 if (target != null)
  35.                 {
  36.                         if (isEnabled)
  37.                         {
  38.                                 target.spriteName = UICamera.IsHighlighted(gameObject) ? hoverSprite : normalSprite;
  39.                         }
  40.                         else
  41.                         {
  42.                                 target.spriteName = disabledSprite;
  43.                         }      
  44.                         target.MakePixelPerfect();
  45.                 }
  46.         }
  47.  
  48.         void OnHover (bool isOver)
  49.         {
  50.                 if (enabled && target != null)
  51.                 {
  52.                         target.spriteName = isOver ? hoverSprite : normalSprite;
  53.                         target.MakePixelPerfect();
  54.                 }
  55.         }
  56.  
  57.         void OnPress (bool pressed)
  58.         {
  59.                 if (pressed)
  60.                 {
  61.                         target.spriteName = pressedSprite;
  62.                         target.MakePixelPerfect();
  63.                 }
  64.                 else UpdateImage();
  65.         }
  66. }

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIImageButton Disabled state in 2.6.0
« Reply #14 on: May 07, 2013, 07:51:24 AM »
Argh, did I fuck it all up? Damnation!