Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.isartdigital.diamant.ui.hud.wireframes;
- import com.isartdigital.diamant.game.controllers.buildings.generic.TileController;
- import com.isartdigital.diamant.game.controllers.buildings.generic.UpgradableController;
- import com.isartdigital.diamant.game.pooling.PoolManager;
- import com.isartdigital.diamant.game.server.ServerActionManager;
- import com.isartdigital.diamant.game.sprites.tiles.GraphicTile;
- import com.isartdigital.diamant.game.sprites.tiles.UpgradableTile;
- import com.isartdigital.diamant.tools.ButtonUtils;
- import com.isartdigital.diamant.tools.JsonHelper;
- import com.isartdigital.diamant.tools.SFXManager;
- import com.isartdigital.diamant.ui.hud.buttons.BuildingButtonShop;
- import com.isartdigital.diamant.ui.hud.FreezingPopin;
- import com.isartdigital.utils.ui.smart.SmartButton;
- import com.isartdigital.utils.ui.smart.SmartComponent;
- import com.isartdigital.utils.ui.smart.TextSprite;
- import com.isartdigital.utils.ui.smart.UISprite;
- import haxe.Constraints.Function;
- import pixi.core.text.Text;
- import pixi.interaction.EventTarget;
- /**
- * ...
- * @author Etienne HECK
- */
- class Management extends FreezingPopin
- {
- /**
- * instance unique de la classe Management
- */
- private static var instance: Management;
- public var doAction:Function;
- private var logo:SmartComponent;
- private static var LAYER_TEXT_TITLE:String = "ManagementUpgrades_Title";
- //private static var LAYER_TEXT_TITLE_BACKGROUND:String = "ManagementUpgrades_Title_Background";
- private static var LAYER_TEXT_DESCRIPTION:String = "ManagementUpgrades_Description";
- private static var LAYER_MANAGEMENT_UPGRADE_DESCRIPTION:String = "ManagementUpgrades_Description";
- private static var LAYER_MANAGEMENT_UPGRADE:String = "Management_Upgrade";
- private static var LAYER_MANAGEMENT_UPGRADE_DESCRIPTION_BACKGROUND:String = "ManagementUpgrades_Description_Background";
- //title
- private static var LAYER_UPGRADE_SELL_TEXT:String = "ManagementUpgrades_Sell_Text";
- private static var LAYER_UPGRADE_CARD_NEXT_TITLE:String = "ManagementUpgrades_Upgrade_next";
- private static var LAYER_UPGRADE_CARD_CURRENT_TITLE:String = "ManagementUpgrades_Upgrade_actual";
- private static var LAYER_UPGRADE_CARD_MAX_TITLE:String = "ManagementUpgrades_Upgrade_max";
- //description
- private static var LAYER_UPGRADE_CARD_MAX_DESCRIPTION:String = "UpgradeMax_Text_Description";
- private static var LAYER_UPGRADE_CARD_NEXT_DESCRIPTION:String = "UpgradeNext_Text_Description";
- private static var LAYER_UPGRADE_CARD_CURRENT_DESCRIPTION:String = "UpgradeActual_Text_Description";
- //windows
- private static var WINDOWS_ACTUAL:String = "Window_actual";
- private static var WINDOWS_MAX:String = "Window_max";
- private static var WINDOWS_NEXT:String = "Window_next";
- private static var LAYER_UPGRADE_DESCRIPTION_LEVEL:String = "Upgrades_Description";
- private static var LAYER_LOGO:String = "ShopBuilding_Item_Logo";
- private static var LAYER_MANAGEMENT_BTNSELL:String = "ManagementUpgrades_Sell_Button";
- private static var LAYER_MANAGEMENT_BACKGROUND:String = "ManagementUpgrades_Background";
- private var hudSpecial:SmartComponent;
- private var hudUpgrade:SmartComponent;
- //windows
- private var windowsActual:UISprite;
- private var windowsMax:UISprite;
- private var windowsNext:UISprite;
- //title
- private var upgradeCardNext:TextSprite;
- private var upgradeCardCurrent:TextSprite;
- private var upgradeCardMax:TextSprite;
- //description
- private var upgradeCardNextDescription:TextSprite;
- private var upgradeCardCurrentDescription:TextSprite;
- private var upgradeCardMaxDescription:TextSprite;
- public var btnSell:SmartButton;
- private var btnTabUpgrade:SmartButton;
- private var textBtnTabUpgrade:Text;
- /**
- * Retourne l'instance unique de la classe, et la crée si elle n'existait pas au préalable
- * @return instance unique
- */
- public static function getInstance (): Management {
- if (instance == null) instance = new Management();
- return instance;
- }
- /**
- * constructeur privé pour éviter qu'une instance soit créée directement
- */
- private function new(pID:String=null)
- {
- super("MCP_Management");
- shouldEndSelection = false;
- hudUpgrade = cast(getChildByName(LAYER_MANAGEMENT_UPGRADE), SmartComponent);
- modal = true;
- btnSell = ButtonUtils.createButton(btnSell, hudUpgrade, LAYER_MANAGEMENT_BTNSELL, onSell);
- btnSell.visible = false;
- //title
- upgradeCardNext = cast(hudUpgrade.getChildByName(LAYER_UPGRADE_CARD_NEXT_TITLE), TextSprite);
- upgradeCardCurrent = cast(hudUpgrade.getChildByName(LAYER_UPGRADE_CARD_CURRENT_TITLE), TextSprite);
- upgradeCardMax = cast(hudUpgrade.getChildByName(LAYER_UPGRADE_CARD_MAX_TITLE), TextSprite);
- upgradeCardMax.visible = false;
- //windows
- windowsActual = cast(hudUpgrade.getChildByName(WINDOWS_ACTUAL), UISprite);
- windowsMax = cast(hudUpgrade.getChildByName(WINDOWS_MAX), UISprite);
- windowsNext = cast(hudUpgrade.getChildByName(WINDOWS_NEXT), UISprite);
- windowsMax.visible = false;
- //description
- upgradeCardCurrentDescription = cast(hudUpgrade.getChildByName(LAYER_UPGRADE_CARD_CURRENT_DESCRIPTION), TextSprite);
- upgradeCardNextDescription = cast(hudUpgrade.getChildByName(LAYER_UPGRADE_CARD_NEXT_DESCRIPTION), TextSprite);
- upgradeCardMaxDescription = cast(hudUpgrade.getChildByName(LAYER_UPGRADE_CARD_MAX_DESCRIPTION), TextSprite);
- upgradeCardMaxDescription.text = ServerActionManager.getInstance().getDescription(TileController.selectedController.controlledSet.model.name,TileController.selectedController.controlledSet.model.level).flavour;
- }
- private function displayMaxBuilding():Void {
- var levelActual:Int = TileController.selectedController.controlledSet.model.level ;
- var levelMax:Int = JsonHelper.getBuildingMaxLevel(TileController.selectedController.controlledSet.model.assetType)[0];
- if (levelActual >= levelMax) {
- upgradeCardMax.visible = true;
- windowsMax.visible = true;
- upgradeCardMaxDescription.visible = true;
- windowsActual.visible = false;
- windowsNext.visible = false;
- upgradeCardNext.visible = false;
- upgradeCardCurrent.visible = false;
- upgradeCardCurrentDescription.visible = false;
- upgradeCardNextDescription.visible = false;
- }
- }
- public function onSell(pEvent:EventTarget) {
- SFXManager.getInstance().playSound('sell');
- var data = { name: TileController.selectedController.controlledSet.model.name,assetType:TileController.selectedController.controlledSet.model.assetType};
- if(Main.getInstance().activateServer)ServerActionManager.getInstance().deleteBuilding(data);
- TileController.selectedController.remove();
- UIManager.getInstance().closeCurrentPopin();
- }
- private function onTabUpgrade(pEvent:EventTarget) {
- setModeUpgrade();
- }
- /*--------------------VOID-------------------*/
- public function setModeVoid():Void {
- doAction = doActionVoid;
- }
- private function doActionVoid():Void {
- }
- /*-----------------UPGRADE-------------------*/
- public function setModeUpgrade():Void {
- hudUpgrade.visible = true;
- setHudUpgrade();
- }
- public function setModeDecoration():Void {
- upgradeCardNext.visible = false;
- upgradeCardCurrent.visible = false;
- upgradeCardMax.visible = false;
- hudSpecial.visible = false;
- }
- override public function open():Void
- {
- super.open();
- fillInfos();
- displayMaxBuilding();
- setModeUpgrade();
- updateLogo();
- }
- private function fillInfos():Void
- {
- var lBuildingInfo:Dynamic = JsonHelper.getBuildingDatas( TileController.selectedController.controlledSet.model.assetType);
- var buildingName:TextSprite = cast(hudUpgrade.getChildByName(LAYER_TEXT_TITLE), TextSprite);
- buildingName.text = Reflect.field(lBuildingInfo, "usedName");
- //building description
- var buildingDescription:TextSprite = cast(hudUpgrade.getChildByName(LAYER_TEXT_DESCRIPTION), TextSprite);
- /*METTRE LES FLAVOUR TEXT*/
- buildingDescription.visible = false;
- }
- public function updateLogo():Void
- {
- logo = cast(getChildByName(LAYER_LOGO), SmartComponent);
- var lBuildingInfo:Dynamic = JsonHelper.getBuildingDatas(TileController.selectedController.controlledSet.model.assetType);
- if (lBuildingInfo != null && TileController.selectedController.controlledSet.model.assetType != "SocialBuilding") {
- var lBuilding:GraphicTile = cast(PoolManager.getFromPool(TileController.selectedController.controlledSet.model.assetType), GraphicTile);
- lBuilding.start();
- if (Std.is(TileController.selectedController, UpgradableController))
- {
- cast(lBuilding, UpgradableTile).setLevel(TileController.selectedController.controlledSet.model.level);
- }
- BuildingButtonShop.changeLogo(lBuilding, lBuildingInfo, logo,1.3);
- }
- }
- private function setHudUpgrade():Void {
- //description
- //upgradeCardMaxDescription.text=ServerActionManager.getInstance().getDescription( TileController.selectedController.controlledSet.model.assetType,TileController.selectedController.controlledSet.model.level) ;
- //upgradeCardNextDescription.text=ServerActionManager.getInstance().getDescription( TileController.selectedController.controlledSet.model.assetType,TileController.selectedController.controlledSet.model.level) ;
- if (ServerActionManager.getInstance().isBuildingDescriptRestored == true) {
- upgradeCardMaxDescription.text= upgradeCardMaxDescription.text=ServerActionManager.getInstance().getDescription( TileController.selectedController.controlledSet.model.assetType,TileController.selectedController.controlledSet.model.level).description ;
- if (upgradeCardNextDescription.visible) upgradeCardNextDescription.text = ServerActionManager.getInstance().getDescription( TileController.selectedController.controlledSet.model.assetType, TileController.selectedController.controlledSet.model.level + 1).description;
- }
- }
- /**
- * détruit l'instance unique et met sa référence interne à null
- */
- override public function destroy (): Void {
- super.destroy();
- instance = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement