Esempio n. 1
0
    /// <summary>Initializes the panel for a given upgrade.</summary>
    /// <param name="upgradeIndex">The upgrade (as an index).</param>
    public void Initialize(int upgradeIndex)
    {
        Assert.IsFalse(PlayerManager.instance.HasBoughtUpgrade(upgradeIndex));

        //get a reference to the upgrade's data
        UpgradeData data = GameData.instance.GetDataForUpgrade(upgradeIndex);

        //and upgrade the UI
        image.sprite        = data.image;
        nameText.text       = data.name;
        descripionText.text = data.description;
        costText.text       = NumberFormatter.ToString(number: data.cost, showDecimalPlaces: false);
        bool canAffordManager = PlayerManager.instance.cash >= data.cost;

        buyButton.SetInteractableAndColor(canAffordManager);
        if (canAffordManager)
        {
            //if the player can afford the upgrade, then add a callback
            buyButton.onClick.AddListener(() => {
                //firstly disable the button
                buyButton.interactable = false;
                //next process the purchase
                PlayerManager.instance.BoughtUpgrade(upgradeIndex);
                PlayerManager.instance.DecrementCashBy(data.cost);
                int businessIndex = (int)data.business; PlayerManager.instance.GetBusiness(businessIndex).UpdateUpgradeProfitMultiplier(data.profitMultiplier);
                //finally destroy the panel
                Destroy(gameObject);
            });
        }
    }
Esempio n. 2
0
    /// <summary>Refreshes the panel.</summary>
    public void Refresh()
    {
        //firstly update the levelFill and levelText
        levelFill.fillAmount = business.nextMilestonePercentage;
        levelText.text       = business.level.ToString();

        //if the business can be updated to a higher level, determine the cost for the selected bulkLeveUpIndex and set the button's interactibility and text
        if (business.upgradeLevelExists)
        {
            float costToUpgradeForBulkLevelUpIndex = (GameManager.instance.bulkLevelUpIndex < Constants.NUMBER_BULK_UPGRADE_OPTIONS - 1 ?
                                                      business.UpgradeXLevelsCost(GameManager.instance.bulkLevelUpAmount) : business.UpgradeMaxLevelsCost());
            bool canAffordUpgrade = PlayerManager.instance.cash >= costToUpgradeForBulkLevelUpIndex;
            upgradeButton.SetInteractableAndColor(canAffordUpgrade);
            upgradeCostText.text = NumberFormatter.ToString(costToUpgradeForBulkLevelUpIndex, showDecimalPlaces: true);
        }
        else         //otherwise display maxed out
        {
            upgradeButton.SetInteractableAndColor(false);
            upgradeCostText.text = LocalizationManager.instance.StringForKey(LocalizationManagerKeys.Max);
        }

        //determine what to present in the profitText, profit per unit (black) or cash per second (green)
        if (business.shouldShowCashPerSecond)
        {
            progressBarFill.fillAmount = 1;             //no fill
            profitText.text            = string.Format("${0} /{1}", NumberFormatter.ToString(number: business.profit, showDecimalPlaces: true, showDollarSign: false),
                                                       LocalizationManager.instance.StringForKey(LocalizationManagerKeys.Sec));
        }
        else
        {
            progressBarFill.fillAmount = (business.timeToProduce >= Constants.MINIMUM_TIME_TO_UPDATE_PRODUCTION_FILL ? business.unitCompletePercentage : 1);
            profitText.text            = NumberFormatter.ToString(number: business.profit, showDecimalPlaces: true);
        }

        //finally update the time to produce current unit (no unit in production returns 00:00:00)
        timeText.text = business.timeDisplayString;
    }
Esempio n. 3
0
    /// <summary>Initializes the panel for a given manager.</summary>
    /// <param name="managerIndex">The manager (as an index).</param>
    public void Initialize(int managerIndex)
    {
        Assert.IsFalse(PlayerManager.instance.HasBoughtManager(managerIndex));

        //get a reference to the upgrade's data
        ManagerData data = GameData.instance.GetDataForManager(managerIndex);

        //and upgrade the UI
        image.sprite        = data.image;
        nameText.text       = data.name;
        descripionText.text = data.description;
        costText.text       = NumberFormatter.ToString(number: data.cost, showDecimalPlaces: false);
        bool canAffordManager = PlayerManager.instance.cash >= data.cost;

        buyButton.SetInteractableAndColor(canAffordManager);
        if (canAffordManager)
        {
            //if the player can afford the upgrade, then add a callback
            buyButton.onClick.AddListener(() => {
                //firstly disable the button
                buyButton.interactable = false;
                //next process the purchase
                PlayerManager.instance.BoughtManager(managerIndex);
                PlayerManager.instance.DecrementCashBy(data.cost);
                int businessIndex = (int)data.business;
                if (data.type == ManagerData.ManagerType.Standard)                //manager starts running the business
                {
                    Assert.IsFalse(PlayerManager.instance.GetBusiness(businessIndex).hasManager);
                    PlayerManager.instance.GetBusiness(businessIndex).AssignManager(Business.ManagerType.RunsBusiness);
                }
                else if (data.type == ManagerData.ManagerType.Efficient)                //manager reduces costs, shows cash per second
                {
                    PlayerManager.instance.GetBusiness(businessIndex).AssignManager(Business.ManagerType.ReducesCost);
                    PlayerManager.instance.GetBusiness(businessIndex).SetCostReductionMultiplier(data.costReductionMultiplier);
                    if (data.showCashPerSecond)
                    {
                        PlayerManager.instance.GetBusiness(businessIndex).SetShouldShowCashPerSecond(true);
                    }
                }
                //finally destroy the panel
                Destroy(gameObject);
            });
        }
    }