private void HandleBuildingButton()
        {
            if (GuiManager.Cursor.WindowPushed is IBuildButton buildButton && buildButton.IsEnabled && buildButton.CanAfford)
            {
                if (selectedObject is StructurePlacement)
                {
                    var newBuilding = buildButton.BuildingFactory.CreateNew(WorldLayer) as BaseStructure;

                    newBuilding.Position = BuildMenuInstance.CurrentPlacement.Position;
                    newBuilding.Z        = 1;
                    newBuilding.StartWarpIn();

                    GuiManager.Cursor.WindowPushed = null;

                    BuildMenuInstance.Hide(didBuild: true);
                    PathingNodeNetwork.RemoveNodesForCollision(newBuilding.AxisAlignedRectangleInstance);

                    SpendSatoshis(newBuilding.SatoshiCost);


                    StructureBuildSound.Pan = newBuilding.X / (Camera.Main.OrthogonalWidth / 2);

                    SoundManager.PlaySoundEffect(StructureBuildSound);

                    //var towerBuiltData = new
                    //{
                    //    TowerType = buildButton.BuildingType.AssemblyQualifiedName,
                    //    NewTowerCount = AllStructuresList.Count,
                    //    AllTowersUnlocked = PlayerDataManager.GetAvailableTowers().Count == 6 ? "True" : "False"
                    //};
                    //AnalyticsManager.AddDeferredEvent("TowerBuilt", towerBuiltData);
                }
            }
        }
        void OnAfterCurrentSatoshisSet(object sender, EventArgs e)
        {
            var allowUpgrade = CurrentPlayerActionMode == PlayerActionMode.Building;

            BuildMenuInstance.UpdateAffordability(CurrentSatoshis);
            StructureInfoInstance.UpdateAffordability(CurrentSatoshis, allowUpgrade);
            LivesPointsDisplayInstance.SatoshiText = CurrentSatoshis.ToString();
        }
        private void AssignGumButtonEvents()
        {
            SetInfoBarControls();

            //Assign buildings to build buttons
            var listOfAllTowerTypes       = GameStateManager.GetAllTowers();
            var listOfAvailableTowerTypes = PlayerDataManager.GetAvailableTowers();

            var listOfAllInstantiatedTowers = new List <BaseStructure>();

            var listOfAvailableTowers         = new List <BaseStructure>();
            var listOfAvailableTowerFactories = new List <IEntityFactory>();

            foreach (var towerType in listOfAllTowerTypes)
            {
                var towerInstantiation = StructureFactories.GetNewObject(towerType) as BaseStructure;
                MachineLearningManager.LearnMaxTowerValues(towerInstantiation);
                _CheapestTowerCost = towerInstantiation.SatoshiCost < _CheapestTowerCost
                    ? towerInstantiation.SatoshiCost
                    : _CheapestTowerCost;
                listOfAllInstantiatedTowers.Add(towerInstantiation);

                if (listOfAvailableTowerTypes.Contains(towerType))
                {
                    listOfAvailableTowers.Add(towerInstantiation);
                    listOfAvailableTowerFactories.Add(StructureFactories.GetFactory(towerType.Name));
                }
            }

            BuildMenuInstance.AssociateTowers(listOfAvailableTowers, listOfAvailableTowerFactories, StructureInfoInstance, CurrentSatoshis);

            for (var i = listOfAllInstantiatedTowers.Count - 1; i >= 0; i--)
            {
                listOfAllInstantiatedTowers[i].Destroy();
            }

            ChatBoxInstance.ChatHistoryButtonClick += delegate(object sender, EventArgs args)
            {
                ChatHistoryInstance.PopulateWithRecentChatHistory();
                GameScreenGumInstance.ShowChatHistoryAnimation.Play();
            };

            ChatHistoryInstance.CloseButtonClick += delegate(object sender, EventArgs args)
            {
                if (GameScreenGumInstance.CurrentChatHistoryShowingState == GameScreenGumRuntime.ChatHistoryShowing.ChatHistoryShown)
                {
                    GameScreenGumInstance.HideChatHistoryAnimation.Play();
                }
            };
            GameScreenGumInstance.HideChatHistoryAnimation.AddAction("SetupResponseAvailability", ChatBoxInstance.SetupResponseAvailability);

            StructureInfoInstance.OnUpgradeAction = HandleUpgradeTower;

            ReadyButtonInstance.Click += OnStartButtonInstanceClick;
        }
        private void ChangeGameModeToNormal()
        {
            CurrentPlayerActionMode            = PlayerActionMode.Normal;
            CurrentLevel.IsReadyForNextWave    = true;
            StructurePlacementInstance.Visible = false;
            BuildMenuInstance.Hide();
            selectedObject = null;
            ReadyButtonInstance.PulseAnimation.Stop();
            ReadyButtonInstance.Visible = false;
            ReadyButtonInstance.Enabled = false;

            if (StructureInfoInstance.Visible)
            {
                StructureInfoInstance.UpdateAffordability(CurrentSatoshis, false);
            }
        }