Author Topic: Changing text in box then tweening size causes text to not update size  (Read 5946 times)

harrisonpink

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Hey guys,

I've got a panel I'm using as a pop up window in my mobile app. I'm trying to use it as an all-purpose pop up and just change the text to match the reason the pop up appeared (confirmation to return to main menu, error messages, etc.). The pop up tweens from super tiny and alpha of 0 to regular size and alpha of 1. The problem is, if I change the text in the boxes as it tweens in, the text still assumes it's super tiny and doesn't show up correctly once the box has finished appearing.

Here's the code I'm using:
  1. public void ShowPopUp (string reasonString)
  2.         {
  3.                 popupPanelPopped = true;
  4.                
  5.                 // Make the popup visible
  6.                 popupPanelTween.PlayForward();
  7.                 popupBackgroundTween.PlayForward();
  8.                 fadeTween.PlayForward();
  9.                
  10.                 // Customize text based on what called the pop up
  11.                 if (reasonString == "xButtonPressed")
  12.                 {
  13.                         popupText.text = "End quiz and return to the Main Menu?";
  14.                        
  15.                         popupButton1Sprite.enabled = true;
  16.                         popupButton2Sprite.enabled = true;
  17.                         popupButton1Label.text = "Main Menu";
  18.                         popupButton2Label.text = "Cancel";
  19.                        
  20.                         popupButton1Sprite.leftAnchor.relative = 0; // 0 = left, 1 = right
  21.                         popupButton1Sprite.leftAnchor.absolute = 15;
  22.                        
  23.                         popupButton1Sprite.rightAnchor.relative = 0.5f;
  24.                         popupButton1Sprite.rightAnchor.absolute = -10;
  25.  
  26.                         popupButton1Sprite.ResetAndUpdateAnchors();
  27.                 }
  28.                 else if (reasonString == "quizInvalid")
  29.                 {
  30.                         popupText.text = "There are no cards that match the quiz options! Change options and try again.";
  31.                        
  32.                         popupButton1Label.text = "Okay";
  33.                        
  34.                         popupButton1Sprite.enabled = true;
  35.                         popupButton2Sprite.enabled = false;
  36.                         popupButton2Label.text = "";
  37.                        
  38.                         popupButton1Sprite.leftAnchor.relative = 0; // 0 = left, 1 = right
  39.                         popupButton1Sprite.leftAnchor.absolute = 89;
  40.                        
  41.                         popupButton1Sprite.rightAnchor.relative = 1;
  42.                         popupButton1Sprite.rightAnchor.absolute = -89;
  43.  
  44.                         popupButton1Sprite.ResetAndUpdateAnchors();
  45.                 }
  46.         }

This code works fine as long as the text isn't changed, but if the pop up is called for one reason and then a different reason later, the text gets all screwed up. The moment I edit the text in the Inspector, it suddenly pops into the right size. In fact, even re-sizing the Game window fixes it, but that isn't really a solution :P

After some experimentation, adding a "ResetAndUpdateAnchors();" line for the buttons seems to fix this problem, however adding one for popupText.text does not help.

Any thoughts?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Changing text in box then tweening size causes text to not update size
« Reply #1 on: August 17, 2014, 09:18:27 AM »
Assuming the content of the popup is only anchored to some root widget that's still inside the popup, and the root widget is not anchored to anything, it should work fine. However if you anchored to the panel instead, and the panel has no clipping, then I can see you having issues as doing so will anchor to the screen.

Make sure you have a plain invisible widget as the root widget just below the panel you're fading in, and anchor everything to it.

Also make sure your TweenScale doesn't use a zero scale, as it's invalid.

harrisonpink

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Changing text in box then tweening size causes text to not update size
« Reply #2 on: August 17, 2014, 10:23:04 PM »
Still having problems. Attached is an image of my hierarchy.

The Popup Widget has an alpha tween on it and the Popup Background has a Tween Scale. They both fire at the same time to have the popup fade in as it grows in size.

If I anchor all the buttons and labels to the Popup Widget, when it scales up everying scales up independently instead of uniformly, making it look strange and unorganized.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Changing text in box then tweening size causes text to not update size
« Reply #3 on: August 18, 2014, 11:50:04 AM »
You anchor to a widget, then tween scale its child? If I understood you correctly, then this is what your issue is. You should be tweening the root object, and most certainly not anchoring anything to something above the tween.

harrisonpink

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Changing text in box then tweening size causes text to not update size
« Reply #4 on: August 21, 2014, 12:26:55 AM »
Alright, attached is a picture of the new hierarchy.

I've put both the TweenAlpha and the TweenScale on the popupWidget. However, I still have the exact same problem when I cause the popup to show, then close it, change the text on the buttons and cause it to re-open. The text isn't updating in size. If I so much as resize the game window, it updates, but otherwise it doesn't. I've also attached a picture of what it looks like when it won't update the text.

harrisonpink

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Changing text in box then tweening size causes text to not update size
« Reply #5 on: August 22, 2014, 01:29:03 AM »
Any ideas?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Changing text in box then tweening size causes text to not update size
« Reply #6 on: August 22, 2014, 04:04:05 AM »
What code are you using to show/hide them, and what's the full order of how you're enabling them and changing the content?

The only thing I can think of that will break this, is tween scale from scale of 0, since zero scale is invalid.

harrisonpink

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Changing text in box then tweening size causes text to not update size
« Reply #7 on: August 23, 2014, 09:25:53 PM »
Yep, it was the zero scale tween. Setting it to 0.1 fixed my problem. You mentioned that as being an issue above but I didn't understand, so I apologise.

Thank you for your help!