Advertisement
dunc001

Widget animation woes

Aug 5th, 2018
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function prepareForPreselectAnimation(): Void
  2.     {
  3.         //This function checks if the preselect icons are to the left or right of their main icon and sets the animate out direction to the opposite side. It also stores current main icon x/y as the target values for the preselect icons to animate to. Finally it gets and stores all necessary current scale and alpha values to ensure everything returns to the exact state it was in prior to starting the animation
  4.        
  5.         var leftIconLTG:Object = {x:(leftIcon._height * 0.5), y:(leftIcon._width * 0.5)};
  6.         var leftPreselectIconLTG:Object = {x:(leftPreselectIcon._height * 0.5), y:(leftPreselectIcon._width * 0.5)};
  7.         var rightIconLTG:Object = {x:(rightIcon._height * 0.5), y:(rightIcon._width * 0.5)};
  8.         var rightPreselectIconLTG:Object = {x:(rightPreselectIcon._height * 0.5), y:(rightPreselectIcon._width * 0.5)};
  9.         var shoutIconLTG:Object = {x:(shoutIcon._height * 0.5), y:(shoutIcon._width * 0.5)};
  10.         var shoutPreselectIconLTG:Object = {x:(shoutPreselectIcon._height * 0.5), y:(shoutPreselectIcon._width * 0.5)};
  11.  
  12.         leftIcon.localToGlobal(leftIconLTG);
  13.         leftPreselectIcon.localToGlobal(leftPreselectIconLTG);
  14.         rightIcon.localToGlobal(rightIconLTG);
  15.         rightPreselectIcon.localToGlobal(rightPreselectIconLTG);
  16.         shoutIcon.localToGlobal(shoutIconLTG);
  17.         shoutPreselectIcon.localToGlobal(shoutPreselectIconLTG);
  18.  
  19.         skyui.util.Debug.log("leftIconLTG - x: " + leftIconLTG.x + ", y: " + leftIconLTG.y)
  20.         skyui.util.Debug.log("leftPreselectIconLTG - x: " + leftPreselectIconLTG.x + ", y: " + leftPreselectIconLTG.y)
  21.  
  22.         if (leftIconLTG.x > leftPreselectIconLTG.x){
  23.             leftTargetX = (leftIcon_mc._width) //If preselect icon is to the left of the main widget animate main widget out to right
  24.             //leftPTargetX = (leftIconLTG.x - leftPreselectIconLTG.x) + (leftIcon._width / 2)
  25.         } else {
  26.             leftTargetX = -(leftIcon_mc._width) //If preselect icon is to the right of the main widget animate main widget out to left
  27.             //leftPTargetX = (leftIconLTG.x - leftPreselectIconLTG.x) - (leftIcon._width)
  28.         }
  29.         leftPTargetX = (leftIconLTG.x - leftPreselectIconLTG.x)
  30.         skyui.util.Debug.log("leftTargetX: " + leftTargetX + ", leftPTargetX: " + leftPTargetX)
  31.         if (rightIconLTG.x > rightPreselectIconLTG.x){
  32.             rightTargetX = (rightIcon_mc._width)
  33.             //rightPTargetX = (rightIconLTG.x - rightPreselectIconLTG.x) + (rightIcon._width / 2)
  34.         } else {
  35.             rightTargetX = -(rightIcon_mc._width)
  36.             //rightPTargetX = (rightIconLTG.x - rightPreselectIconLTG.x) - (rightIcon._width)
  37.         }
  38.         rightPTargetX = (rightIconLTG.x - rightPreselectIconLTG.x)
  39.         if (shoutIconLTG.x > shoutPreselectIconLTG.x){
  40.             shoutTargetX = (shoutIcon_mc._width)
  41.             //shoutPTargetX = (shoutIconLTG.x - shoutPreselectIconLTG.x) + (shoutIcon._width / 2)
  42.         } else {
  43.             shoutTargetX = -(shoutIcon_mc._width)
  44.             //shoutPTargetX = (shoutIconLTG.x - shoutPreselectIconLTG.x) - (shoutIcon._width)
  45.         }
  46.         shoutPTargetX = (shoutIconLTG.x - shoutPreselectIconLTG.x)
  47.        
  48.         leftPTargetY = leftIconLTG.y - leftPreselectIconLTG.y;
  49.         skyui.util.Debug.log("leftPTargetY: " + leftPTargetY)
  50.         rightPTargetY = rightIconLTG.y - rightPreselectIconLTG.y;
  51.         shoutPTargetY = shoutIconLTG.y - shoutPreselectIconLTG.y;
  52.  
  53.         //Store current alpha and scale values ready to reapply
  54.         leftIconAlpha = leftIcon_mc._alpha;
  55.         leftTargetScale = ((leftIcon_mc._xscale / leftPreselectIcon_mc._xscale) * 100);
  56.         //leftPTargetX = ((leftIconLTG.x - leftPreselectIconLTG.x) * (leftIcon_mc._xscale / leftPreselectIcon_mc._xscale));
  57.         leftPIconAlpha = leftPreselectIcon_mc._alpha;
  58.         leftPIconScale = leftPreselectIcon._xscale;
  59.         rightIconAlpha = rightIcon_mc._alpha;
  60.         rightTargetScale = ((rightIcon_mc._xscale / rightPreselectIcon_mc._xscale) * 100);
  61.         rightPIconAlpha = rightPreselectIcon_mc._alpha;
  62.         rightPIconScale = rightPreselectIcon._xscale;
  63.         shoutIconAlpha = shoutIcon_mc._alpha;
  64.         shoutTargetScale = ((shoutIcon_mc._xscale / shoutPreselectIcon_mc._xscale) * 100);
  65.         shoutPIconAlpha = shoutPreselectIcon_mc._alpha;
  66.         shoutPIconScale = shoutPreselectIcon._xscale;
  67.         leftNameAlpha = leftName_mc._alpha;
  68.         leftPNameAlpha = leftPreselectName_mc._alpha;
  69.         rightNameAlpha = rightName_mc._alpha;
  70.         rightPNameAlpha = rightPreselectName_mc._alpha;
  71.         shoutNameAlpha = shoutName_mc._alpha;
  72.         shoutPNameAlpha = shoutPreselectName_mc._alpha;
  73.  
  74.         skse.SendModEvent("iEquip_ReadyForPreselectAnimation", null);
  75.  
  76.     }
  77.  
  78.     public function equipPreselectedItem(iSlot: Number, currIcon: String, newIcon: String, newName: String, currPIcon: String, newPIcon: String, newPName: String): Void
  79.     {
  80.        
  81.         var iconClip: MovieClip;
  82.         var iconClip_mc: MovieClip;
  83.         var currIcon: String;
  84.         var pIconClip: MovieClip;
  85.         var pIconClip_mc: MovieClip;
  86.         var currPIcon: String;
  87.         var itemName_mc: MovieClip;
  88.         var preselectName_mc: MovieClip;
  89.         var targetX: Number;
  90.         var pTargetX: Number;
  91.         var pTargetY: Number;
  92.         var pIconAlpha: Number;
  93.         var pIconScale: Number;
  94.         var pIconTargetScale: Number
  95.         var iconAlpha: Number;
  96.         var itemNameAlpha: Number;
  97.         var preselectNameAlpha: Number;
  98.        
  99.         switch(iSlot) {
  100.             case 0:
  101.                 iconClip = leftIcon;
  102.                 iconClip_mc = leftIcon_mc;
  103.                 pIconClip = leftPreselectIcon;
  104.                 pIconClip_mc = leftPreselectIcon_mc;
  105.                 itemName_mc = leftName_mc;
  106.                 preselectName_mc = leftPreselectName_mc;
  107.                 targetX = leftTargetX;
  108.                 pTargetX = leftPTargetX;
  109.                 pTargetY = leftPTargetY;
  110.                 pIconAlpha = leftPIconAlpha;
  111.                 pIconScale = leftPIconScale;
  112.                 iconAlpha = leftIconAlpha;
  113.                 pIconTargetScale = leftTargetScale;
  114.                 itemNameAlpha = leftNameAlpha;
  115.                 preselectNameAlpha = leftPNameAlpha;
  116.                 break
  117.             case 1:
  118.                 iconClip = rightIcon;
  119.                 iconClip_mc = rightIcon_mc;
  120.                 pIconClip = rightPreselectIcon;
  121.                 pIconClip_mc = rightPreselectIcon_mc;
  122.                 itemName_mc = rightName_mc;
  123.                 preselectName_mc = rightPreselectName_mc;
  124.                 targetX = rightTargetX;
  125.                 pTargetX = rightPTargetX;
  126.                 pTargetY = rightPTargetY;
  127.                 pIconAlpha = rightPIconAlpha;
  128.                 pIconScale = rightPIconScale;
  129.                 iconAlpha = rightIconAlpha;
  130.                 pIconTargetScale = rightTargetScale;
  131.                 itemNameAlpha = rightNameAlpha;
  132.                 preselectNameAlpha = rightPNameAlpha;
  133.                 break
  134.             case 2:
  135.                 iconClip = shoutIcon;
  136.                 iconClip_mc = shoutIcon_mc;
  137.                 pIconClip = shoutPreselectIcon;
  138.                 pIconClip_mc = shoutPreselectIcon_mc;
  139.                 itemName_mc = shoutName_mc;
  140.                 preselectName_mc = shoutPreselectName_mc;
  141.                 targetX = shoutTargetX;
  142.                 pTargetX = shoutPTargetX;
  143.                 pTargetY = shoutPTargetY;
  144.                 pIconAlpha = shoutPIconAlpha;
  145.                 pIconScale = shoutPIconScale;
  146.                 iconAlpha = shoutIconAlpha;
  147.                 pIconTargetScale = shoutTargetScale;
  148.                 itemNameAlpha = shoutNameAlpha;
  149.                 preselectNameAlpha = shoutPNameAlpha;
  150.                 break
  151.             }
  152.            
  153.         var tempIcon: MovieClip = iconClip.duplicateMovieClip("tempIcon", this.getNextHighestDepth());
  154.         tempIcon.gotoAndStop(currIcon);
  155.         iconClip._alpha = 0;
  156.         iconClip.gotoAndStop(newIcon);
  157.         var tempPIcon: MovieClip = pIconClip.duplicateMovieClip("tempPIcon", this.getNextHighestDepth());
  158.         //var iconLTG: Object = {x:(iconClip._width * 0.5), y:(iconClip._height * 0.5)}
  159.         //iconClip.localToGlobal(iconLTG);
  160.         //var tempPIconLTG: Object = {x:(tempPIcon._width * 0.5), y:(tempPIcon._height * 0.5)}
  161.         //tempPIcon.localToGlobal(tempPIconLTG);
  162.         //pTargetX = ((iconLTG.x - tempPIconLTG.x) * (iconClip_mc._xscale / pIconClip_mc._xscale));
  163.        
  164.         //skyui.util.Debug.log("iconLTG.x: " + iconLTG.x + ", iconLTG.y: " + iconLTG.y + "tempPIconLTG.x: " + tempPIconLTG.x + ", tempPIconLTG.y: " + tempPIconLTG.y + ", pTargetX: " + pTargetX)
  165.  
  166.         tempPIcon._xscale = pIconClip_mc._xscale;
  167.         tempPIcon._yscale = pIconClip_mc._yscale;
  168.         tempPIcon.gotoAndStop(currPIcon);
  169.         pIconClip._alpha = 0;
  170.         pIconClip._xscale = 25;
  171.         pIconClip._yscale = 25;
  172.         pIconClip.gotoAndStop(newPIcon);
  173.         var tl = new TimelineLite({paused:true, autoRemoveChildren:true, onComplete:equipPreselectedItemComplete});
  174.         tl.to(itemName_mc, 0.3, {_alpha:0, ease:Quad.easeOut}, 0)
  175.         .to(preselectName_mc, 0.3, {_alpha:0, ease:Quad.easeOut}, 0)
  176.         .call(updateNamesForEquipPreselect, [iSlot, newName, newPName, this]);
  177.         tl.to(tempIcon, 0.6, {_x:targetX, _y:((tempIcon._height) / 2), _rotation:"+=90", _alpha:0, _xscale:25, _yscale:25, ease:Quad.easeOut}, 0);
  178.         tl.to(tempPIcon, 0.6, {_x:pTargetX, _y:pTargetY, _alpha:iconAlpha, _xscale:pIconTargetScale, _yscale:pIconTargetScale, ease:Quad.easeOut}, 0)
  179.         .to(iconClip, 0, {_alpha:iconAlpha, ease:Linear.easeNone})
  180.         //.to(tempPIcon, 0, {_alpha:0, ease:Linear.easeNone})
  181.         .to(pIconClip, 0.4, {_alpha:pIconAlpha, _xscale:pIconScale, _yscale:pIconScale, ease:Elastic.easeOut}, 0.5)
  182.         .to(itemName_mc, 0.3, {_alpha:itemNameAlpha, ease:Quad.easeOut}, 0.6)
  183.         .to(preselectName_mc, 0.3, {_alpha:preselectNameAlpha, ease:Quad.easeOut}, 0.6)
  184.  
  185.         tl.play();
  186.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement