Пример #1
0
 void Update()
 {
     // change price text color by checking resources
     if (bd != null)
     {
         PriceAvailable = bd.PriceInfoCheck(Price);
     }
 }
Пример #2
0
        void Update()
        {
            if (!UIDialogMessage.IsShow() && Input.GetKeyDown(KeyCode.Escape))
            {
                _Hide();
            }

            if (bdNext != null)
            {
                Available = bdNext.PriceInfoCheck(Price);
            }
        }
Пример #3
0
        // when button clicked
        public void ButtonClicked(CommandType ct)
        {
            //Debug.Log ("ButtonClicked "+ct.ToString());
            BEAudioManager.SoundPlay(6);

            // if newly created building is selected
            // only perform create and cancel
            if (building.OnceLanded == false)
            {
                // if user clicked 'create' button
                if (ct == CommandType.Create)
                {
                    // building can land
                    if (building.Landable)
                    {
                        // hide command dialog
                        Hide();
                        // land building and unselect
                        SceneTown.instance.BuildingLandUnselect();

                        // decrease build price of the building
                        BuildingDef bd = TBDatabase.GetBuildingDef(building.Type, (building.Level == 0) ? 1 : building.Level);
                        building.PayforBuild(bd);
                        // if building level is 0(need buildtime), upgrade to level 1 start
                        // if not, check resource capacity
                        if (building.Level == 0)
                        {
                            building.Upgrade();
                        }
                        else
                        {
                            SceneTown.instance.CapacityCheck();
                        }
                    }

                    // if house is created add worker
                    if (building.Type == 1)
                    {
                        BEWorkerManager.instance.AddWorker();
                    }

                    // if wall is created,automatically next wall create for convenience
                    if (building.Type == 2)
                    {
                        // check if user has enough gold and wall count is not max count
                        BuildingDef bd        = TBDatabase.GetBuildingDef(building.Type, 1);
                        bool        Available = bd.PriceInfoCheck(null);
                        int         CountMax  = BEGround.instance.GetBuildingCountMax(building.Type);
                        int         Count     = BEGround.instance.GetBuildingCount(building.Type);
                        if (Available && (Count < CountMax))
                        {
                            //Debug.Log ("wall tilePos:"+building.tilePos.ToString ());
                            // add another wall automatically
                            Building script = BEGround.instance.BuildingAdd(2, 1);
                            if (script != null)
                            {
                                // choose whicj direction
                                Building buildingNeighbor = null;
                                Vector2  tilePos          = Vector2.zero;
                                int      NeighborX        = 0;
                                int      NeighborZ        = 0;
                                bool     bFind            = false;
                                // check prev and next tile in x,z coordination
                                for (int dir = 0; dir < 2; ++dir)
                                {
                                    for (int value = 0; value < 2; ++value)
                                    {
                                        if (dir == 0)
                                        {
                                            NeighborX = 0;
                                            NeighborZ = ((value == 0) ? -1 : 1);
                                        }
                                        else
                                        {
                                            NeighborX = ((value == 0) ? -1 : 1);
                                            NeighborZ = 0;
                                        }
                                        buildingNeighbor = BEGround.instance.GetBuilding((int)building.tilePos.x + NeighborX, (int)building.tilePos.y + NeighborZ);

                                        // if wall finded
                                        if ((buildingNeighbor != null) && (buildingNeighbor.Type == 2))
                                        {
                                            bFind = true;
                                            break;
                                        }
                                    }

                                    if (bFind)
                                    {
                                        break;
                                    }
                                }
                                //Debug.Log ("wall NeighborX:"+NeighborX.ToString ()+ "NeighborZ:"+NeighborZ.ToString ());

                                // set inverse direction
                                tilePos = building.tilePos;
                                if (NeighborX == 0)
                                {
                                    tilePos.y -= (float)NeighborZ;
                                }
                                else
                                {
                                    tilePos.x -= (float)NeighborX;
                                }

                                //Debug.Log ("wall tilePos New:"+tilePos.ToString ());
                                script.Move((int)tilePos.x, (int)tilePos.y);
                                script.CheckLandable();
                                SceneTown.instance.BuildingSelect(script);
                            }
                        }
                    }

                    SceneTown.instance.Save();
                    BEWorkerManager.instance.SetWorker(building);
                }
                // if user clicked 'cancel' button
                else if (ct == CommandType.CreateCancel)
                {
                    // hide command dialog
                    Hide();
                    // delete temporary created building
                    SceneTown.instance.BuildingDelete();
                }
                else
                {
                }
            }
            else
            {
                if (ct == CommandType.Info)
                {
                    Hide();
                    UIDialogInfo.Show(building);
                }
                else if (ct == CommandType.Upgrade)
                {
                    // check if worker available
                    if (BEWorkerManager.instance.WorkerAvailable())
                    {
                        Hide();
                        UIDialogUpgradeAsk.Show(building);
                    }
                    else
                    {
                        UIDialogMessage.Show("All workers are working now", "Ok", "No Worker Available");
                    }
                }
                else if (ct == CommandType.UpgradeCancel)
                {
                    UIDialogMessage.Show("Cancel current upgrade?", "Yes,No", "Cancel Upgrade ?", null, (result) => { MessageBoxResultUpgradeCancel(result); });
                }
                else if (ct == CommandType.UpgradeFinish)
                {
                    // if instant finish button was clicked
                    int FinishGemCount = building.GetFinishGemCount();
                    // user has enough gem to finish
                    if (SceneTown.Gem.Target() >= FinishGemCount)
                    {
                        // decrease gem
                        SceneTown.Gem.ChangeDelta(-FinishGemCount);
                        // complete upgrade
                        building.UpgradeCompleted = true;
                        Hide();
                    }
                    else
                    {
                        UIDialogMessage.Show("You need more gems to finish this work immediately", "Ok", "Need More Gems");
                    }
                }
                else if (ct == CommandType.Training)
                {
                    Hide();
                    UIDialogTraining.Show(building);
                }
                else
                {
                }
            }
        }