Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 7.43 KB | None | 0 0
  1. package com.isartdigital.perle.ui.popin.levelUp;
  2.  
  3. import com.isartdigital.perle.game.AssetName;
  4. import com.isartdigital.perle.game.BuildingName;
  5. import com.isartdigital.perle.game.GameConfig;
  6. import com.isartdigital.perle.game.managers.DialogueManager;
  7. import com.isartdigital.perle.game.managers.FakeTraduction;
  8. import com.isartdigital.perle.game.managers.ResourcesManager;
  9. import com.isartdigital.perle.game.managers.TweenManager;
  10. import com.isartdigital.perle.game.managers.UnlockManager;
  11. import com.isartdigital.perle.game.sprites.FlumpStateGraphic;
  12. import com.isartdigital.perle.ui.hud.Hud;
  13. import com.isartdigital.perle.ui.hud.dialogue.FocusManager;
  14. import com.isartdigital.perle.utils.Interactive;
  15. import com.isartdigital.utils.events.MouseEventType;
  16. import com.isartdigital.utils.game.GameStage;
  17. import com.isartdigital.utils.localisation.Localisation;
  18. import com.isartdigital.utils.sounds.SoundManager;
  19. import com.isartdigital.utils.ui.smart.SmartButton;
  20. import com.isartdigital.utils.ui.smart.SmartComponent;
  21. import com.isartdigital.utils.ui.smart.SmartPopin;
  22. import com.isartdigital.utils.ui.smart.TextSprite;
  23. import com.isartdigital.utils.ui.smart.UIMovie;
  24. import com.isartdigital.utils.ui.smart.UISprite;
  25. import haxe.Timer;
  26. import pixi.core.math.Point;
  27.  
  28.    
  29. /**
  30.  * ...
  31.  * @author Alexis
  32.  */
  33. class LevelUpPoppin extends SmartPopinExtended
  34. {
  35.    
  36.     /**
  37.      * instance unique de la classe LevelUpPoppin
  38.      */
  39.     private static var instance: LevelUpPoppin;
  40.    
  41.     private static var level:TextSprite;
  42.     //private static var typeUnlock:TextSprite;
  43.     private static var txtNew:TextSprite;
  44.     private static var nameUnlock:TextSprite;
  45.     //private static var description:TextSprite;
  46.     //private static var congrats:TextSprite;
  47.     private static var txtNext:TextSprite;
  48.     private static var img:UISprite;
  49.     private static var imgImage:FlumpStateGraphic;
  50.     private var btnNext:SmartButton;
  51.     private var bgLvl:SmartComponent;
  52.     private var unlock:SmartComponent;
  53.     private var currentImage:UIMovie;
  54.    
  55.     private static var imgArray:Array<UIMovie>;
  56.     private var shopGraphic:UISprite;
  57.    
  58.     private var allRewardsTook:Bool = false;
  59.     private var canDoJuicyWithTheseElement:Bool = false;
  60.     /**
  61.      * Retourne l'instance unique de la classe, et la crée si elle n'existait pas au préalable
  62.      * @return instance unique
  63.      */
  64.     public static function getInstance (): LevelUpPoppin {
  65.         if (instance == null) instance = new LevelUpPoppin();
  66.         return instance;
  67.     }
  68.    
  69.     private function setPopin(pName:String, pLevel:Int):Void {
  70.         //todo : rajouter la description, level type du batiment
  71.         level.text = "" + ResourcesManager.getLevel();
  72.        
  73.         currentImage = SmartPopinExtended.setImage(img, BuildingName.getAssetName(pName, pLevel));
  74.         imgArray.push(currentImage);
  75.         //txtNew.text = Localisation.allTraductions["LABEL_LEVEL_UP_NEW"];
  76.         txtNext.text = Localisation.allTraductions["LABEL_LEVEL_UP_NEXT"];
  77.         //congrats.text = Localisation.allTraductions["LABEL_LEVEL_UP_CONGRATS"];
  78.        
  79.         //setImage(BuildingName.getAssetName(UnlockManager.unlockedItem[0].name, UnlockManager.unlockedItem[0].level));
  80.         //setImage(BuildingName.getAssetName(UnlockManager.unlockedItem[0].name));
  81.         //todo @Ambroise : setImage en fonction du level comme la ligne 56 commentée (elle ne marche pas car elle detecte les decoration au level 1)
  82.        
  83.         nameUnlock.text = pName;
  84.         canDoJuicyWithTheseElement = true;
  85.         //typeUnlock.text = "";
  86.         //description.text = UnlockManager.itemUnlockedForPoppin[0][0][4];
  87.     }
  88.    
  89.     public function getImgCenter():Point {
  90.         return img.position;
  91.     }
  92.    
  93.     private function onClickNext():Void {
  94.         juicyEffect();
  95.         shopGraphic.visible = true;
  96.         if (UnlockManager.unlockedItem.length != 0) {
  97.             var lUnlockedItem:TableTypeBuilding = UnlockManager.unlockedItem.shift();
  98.                
  99.             setPopin(
  100.                 FakeTraduction.assetNameNameToTrad(lUnlockedItem.name),
  101.                 lUnlockedItem.level
  102.             );
  103.         }
  104.         else if (!allRewardsTook) {
  105.             shopGraphic.visible = false;
  106.             setGoldsIcon();
  107.         }
  108.         else
  109.             closeLevelUpPoppin();
  110.     }
  111.    
  112.     private function setGoldsIcon() {
  113.         allRewardsTook = true;
  114.        
  115.         canDoJuicyWithTheseElement = false;
  116.         level.text = "" + ResourcesManager.getLevel();
  117.         var lLevel:Float = ResourcesManager.getLevel();
  118.         var level:Int = cast(lLevel - 2, Int);
  119.         //destroyAfterEffect();
  120.         var lSprite:UISprite = SmartPopinExtended.setImageUiSprite(img, "_goldPack5_portrait");
  121.         nameUnlock.text = "" + GameConfig.getLevelRewardsConfig()[level].gold;
  122.         UnlockManager.giveLevelReward();
  123.     }
  124.    
  125.     private function closeLevelUpPoppin() {
  126.         if (DialogueManager.ftueCloseUnlockedItem)
  127.             DialogueManager.endOfaDialogue();
  128.         Hud.getInstance().btnShop.interactive = true;
  129.         Hud.getInstance().show();
  130.         UIManager.getInstance().closePopin(this);
  131.         UnlockManager.checkIfNeedToCreateDialogue();
  132.     }
  133.    
  134.     private function juicyEffect():Void {
  135.         if (!canDoJuicyWithTheseElement)
  136.             return;
  137.         TweenManager.positionAndRescal(
  138.             currentImage,
  139.             shopGraphic.position,
  140.             this,
  141.             destroyAfterEffect,
  142.             shopGraphic
  143.         );
  144.     }
  145.    
  146.     private function destroyAfterEffect():Void {
  147.     /*  if (imgArray.length != 0) {
  148.             var lImg:UIMovie = imgArray[0];
  149.             imgArray.splice(0, 1);
  150.             lImg.parent.removeChild(lImg);
  151.             lImg.destroy();
  152.             //if (imgArray.length == 0)
  153.         }*/
  154.        
  155.         SoundManager.getSound("SOUND_NEUTRAL").play();
  156.     }
  157.    
  158.     /**
  159.      * constructeur privé pour éviter qu'une instance soit créée directement
  160.      */
  161.     private function new()
  162.     {
  163.         super(AssetName.LEVELUP_POPPIN);
  164.         setWireframe();
  165.         imgArray = [];
  166.         if (UnlockManager.unlockedItem[0] != null) {
  167.            
  168.             canDoJuicyWithTheseElement = true;
  169.             setPopin(
  170.                 FakeTraduction.assetNameNameToTrad(UnlockManager.unlockedItem[0].name),
  171.                 UnlockManager.unlockedItem[0].level
  172.             );
  173.             UnlockManager.unlockedItem.splice(0,1);
  174.         }
  175.         else {
  176.             allRewardsTook = true;
  177.             setGoldsIcon();
  178.         }
  179.        
  180.         shopGraphic = new UISprite("_shopButton_HUD_up");
  181.         shopGraphic.position = Hud.getInstance().getShopIconPos();
  182.         addChild(shopGraphic);
  183.         shopGraphic.visible = false;
  184.         allRewardsTook = false;
  185.         SoundManager.getSound("SOUND_LEVELUP").play();
  186.     }
  187.    
  188.     /**
  189.      * Set all the variables to the wireframe
  190.      */
  191.     private function setWireframe():Void {
  192.         bgLvl = cast(getChildByName(AssetName.LEVELUP_POPPIN_LEVELBG), SmartComponent);
  193.         unlock = cast(getChildByName(AssetName.LEVELUP_POPPIN_UNLOCK), SmartComponent);
  194.        
  195.         level = cast(SmartCheck.getChildByName(bgLvl, AssetName.LEVELUP_POPPIN_LEVEL), TextSprite);
  196.         nameUnlock = cast(SmartCheck.getChildByName(unlock, AssetName.LEVELUP_POPPIN_NAME), TextSprite);
  197.         //description = cast(SmartCheck.getChildByName(unlock, AssetName.LEVELUP_POPPIN_DESCRIPTION), TextSprite);
  198.         //typeUnlock = cast(getChildByName(AssetName.LEVELUP_POPPIN_TYPE), TextSprite);
  199.        
  200.         //congrats = cast(getChildByName(AssetName.LEVELUP_POPPIN_CONGRATS), TextSprite);
  201.         //txtNew = cast(getChildByName(AssetName.LEVELUP_POPPIN_TEXT_NEW), TextSprite);
  202.        
  203.         img = cast(SmartCheck.getChildByName(unlock, AssetName.LEVELUP_POPPIN_IMG), UISprite);
  204.        
  205.         btnNext = cast(getChildByName(AssetName.LEVELUP_POPPIN_BUTTON), SmartButton);
  206.        
  207.         txtNext = cast(SmartCheck.getChildByName(btnNext, AssetName.LEVELUP_POPPIN_NEXT_TEXT), TextSprite);
  208.         Interactive.addListenerClick(btnNext, onClickNext);
  209.         //SmartCheck.traceChildrens(btnNext);
  210.     }
  211.    
  212.     /**
  213.      * détruit l'instance unique et met sa référence interne à null
  214.      */
  215.     override public function destroy (): Void {
  216.         Interactive.removeListenerClick(btnNext, onClickNext);
  217.        
  218.         instance = null;
  219.     }
  220.  
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement