void Update() { if (!UIDialogMessage.IsShow() && Input.GetKeyDown(KeyCode.Escape)) { Hide(); } }
// start upgrade public bool Upgrade() { if (InUpgrade) { return(false); } if (bt.LevelMax <= Level) { return(false); } if (defNext == null) { return(false); } // check whether user has enough resources or not // decrease user's resource PayType payTypeReturn = PayforBuild(defNext); if (payTypeReturn != PayType.None) { if (payTypeReturn == PayType.Gold) { UIDialogMessage.Show("Insufficient Gold", "Ok", "Error"); } else if (payTypeReturn == PayType.Elixir) { UIDialogMessage.Show("Insufficient Elixir", "Ok", "Error"); } else if (payTypeReturn == PayType.Gem) { UIDialogMessage.Show("Insufficient Gem", "Ok", "Error"); } else { } return(false); } // prepare upgrade UpgradeCompleted = false; InUpgrade = true; // if upgrade time is zero(like wall) then upgrade immediately if (UpgradeTimeTotal > 0) { UpgradeTimeLeft = UpgradeTimeTotal; uiInfo.TimeLeft.text = BENumber.SecToString(Mathf.CeilToInt(UpgradeTimeLeft)); uiInfo.Progress.fillAmount = (UpgradeTimeTotal - UpgradeTimeLeft) / UpgradeTimeTotal; BETween.alpha(uiInfo.groupProgress.gameObject, 0.3f, 0.0f, 1.0f); uiInfo.groupProgress.gameObject.SetActive(true); } else { UpgradeEnd(); } return(true); }
void Update() { if (!UIDialogMessage.IsShow() && Input.GetKeyDown(KeyCode.Escape)) { _Hide(); } if (bdNext != null) { Available = bdNext.PriceInfoCheck(Price); } }
public void Clicked() { // if item is building if (bt != null) { //Debug.Log ("UIShopItem selected : "+bt.Name); //building creation is enabled if (CountAvailable && PriceAvailable && BEWorkerManager.instance.WorkerAvailable()) { // add building. if buildtime is zero, then create level1, else not, create o level and upgrade start Building script = BEGround.instance.BuildingAdd(bt.ID, (bd.BuildTime == 0) ? 1 : 0); if (script != null) { script.Move(Vector3.zero); BEGround.instance.MoveToVacantTilePos(script); script.CheckLandable(); SceneTown.instance.BuildingSelect(script); UIShop.instance.Hide(); } } else { // show message box if (!CountAvailable) { UIDialogMessage.Show("Upgrade town hall to enlarge max count", "Ok", "Reach to Max Count"); } else if (!PriceAvailable) { UIDialogMessage.Show("More Resource Required", "Ok", "Error"); } else { UIDialogMessage.Show("All workers are working now", "Ok", "Error"); } } } // if item is inapp if (ia != null) { //Debug.Log ("UIShopItem selected : "+ia.Name); // add gem SceneTown.Gem.ChangeDelta(ia.Gem); UIShop.instance.Hide(); SceneTown.instance.Save(); } }
// when user clicked upgrade button public void OnButtonOk() { // if upgrade is available, then upgrade if (Available && TownLevelOk) { if (building.Upgrade()) { // set this building to worker BEWorkerManager.instance.SetWorker(building); SceneTown.instance.BuildingSelect(null); } _Hide(); } else { UIDialogMessage.Show("More Resource Required", "Ok", "Error"); } }
void Update() { if (!UIDialogMessage.IsShow() && Input.GetKeyDown(KeyCode.Escape)) { _Hide(); } int GenCountTotal = 0; int GenTimeTotal = 0; for (int i = 0; i < building.queUnitGen.Count; ++i) { GenQueItem item = building.queUnitGen[i]; GenCountTotal += item.Count; GenTimeTotal += item.GetGenLeftTime(); } TrainingInfo.text = "Train Troops " + GenCountTotal.ToString() + "/" + bd.TrainingQueueMax.ToString(); CapacityInfo.text = "Troop capacity after training: 51 / 200"; TimeLeft.text = BENumber.SecToString(GenTimeTotal); GemCount.text = "10,000"; }
public void OnButtonInstant() { if (!TownLevelOk) { // upgrade not available return; } // checkuser has enough gem count if (SceneTown.Gem.Target() < GemCount) { // you need more gem UIDialogMessage.Show("More Gem Required", "Ok", "Error", TBDatabase.GetPayTypeIcon(PayType.Gem)); return; } // decrease gem count and upgrade immediately SceneTown.Gem.ChangeDelta(-GemCount); building.UpgradeEnd(); SceneTown.instance.BuildingSelect(null); _Hide(); }
// 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 { } } }
void Update() { // get delta time from BETime float deltaTime = BETime.deltaTime; // if user pressed escape key, show quit messagebox if (!UIDialogMessage.IsShow() && !isModalShow && Input.GetKeyDown(KeyCode.Escape)) { UIDialogMessage.Show("Do you want to quit this program?", "Yes,No", "Quit?", null, (result) => { MessageBoxResult(result); }); } // if in camera animation if (InFade) { //camera zoom in FadeAge += Time.deltaTime * 0.7f; if (FadeAge > 1.0f) { InFade = false; FadeAge = 1.0f; zoomCurrent = 64.0f; // 游戏开始时放大倍数(最终值) } goCameraRoot.transform.position = Vector3.Lerp(new Vector3(-5.5f, 0, -5), Vector3.zero, FadeAge); goCamera.transform.localPosition = Vector3.Lerp(new Vector3(0, 0, -128.0f), new Vector3(0, 0, -64.0f), FadeAge); // 游戏开始时放大倍数(中间值) } Exp.Update(); Gold.Update(); Elixir.Update(); Gem.Update(); Shield.ChangeTo(Shield.Target() - (double)deltaTime); Shield.Update(); HouseInfo.text = BEWorkerManager.instance.GetAvailableWorkerCount().ToString() + "/" + BEGround.instance.GetBuildingCount(1).ToString(); if (UIDialogMessage.IsShow() || isModalShow) { return; } //if(EventSystem.current.IsPointerOverGameObject()) return; if (Input.GetMouseButton(0)) { if (EventSystem.current.IsPointerOverGameObject()) { //Debug.Log("left-click over a GUI element!"); return; } //Click MouseButton if (!bInTouch) { bInTouch = true; ClickAfter = 0.0f; bTemporarySelect = false; Dragged = false; mousePosOld = Input.mousePosition; mousePosLast = Input.mousePosition; vCamRootPosOld = goCameraRoot.transform.position; //when a building was selected and user drag mouse on the map //check mouse drag start is over selected building or not //if not do not move selected building Ray ray = Camera.main.ScreenPointToRay(mousePosOld); RaycastHit hit; if (Physics.Raycast(ray, out hit) && (hit.collider.gameObject.tag == "Building")) { MouseClickedBuilding = BuildingFromObject(hit.collider.gameObject); } else { MouseClickedBuilding = null; } //Debug.Log ("Update buildingSelected:"+((buildingSelected != null) ? buildingSelected.name : "none")); } else { //Mouse Button is in pressed //if mouse move certain diatance if (Vector3.Distance(Input.mousePosition, mousePosLast) > 0.01f) { // set drag flag on if (!Dragged) { Dragged = true; // show tile grid 显示建筑物降落网格(亮度变0.3) if ((buildingSelected != null) && (MouseClickedBuilding == buildingSelected)) { BETween.alpha(ground.gameObject, 0.1f, 0.0f, 0.3f); //Debug.Log ("ground alpha to 0.1"); } } mousePosLast = Input.mousePosition; // if selected building exist if ((buildingSelected != null) && (MouseClickedBuilding == buildingSelected)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); float enter; xzPlane.Raycast(ray, out enter); Vector3 vTarget = ray.GetPoint(enter); // move selected building buildingSelected.Move(vTarget); } // else camera panning else { if (camPanningUse) { Vector3 vDelta = (Input.mousePosition - mousePosOld) * 0.008f; Vector3 vForward = goCameraRoot.transform.forward; vForward.y = 0.0f; vForward.Normalize(); Vector3 vRight = goCameraRoot.transform.right; vRight.y = 0.0f; vRight.Normalize(); Vector3 vMove = -vForward * vDelta.y + -vRight * vDelta.x; goCameraRoot.transform.position = vCamRootPosOld + vMove; } } } // Not Move else { if (!Dragged) { ClickAfter += Time.deltaTime; if (!bTemporarySelect && (ClickAfter > 0.5f)) { bTemporarySelect = true; //Debug.Log ("Update2 buildingSelected:"+((buildingSelected != null) ? buildingSelected.name : "none")); Pick(); } } } } } else { //Release MouseButton if (bInTouch) { bInTouch = false; // if in drag state if (Dragged) { // seleted building exist if (buildingSelected != null) { // hide tile grid if (MouseClickedBuilding == buildingSelected) { BETween.alpha(ground.gameObject, 0.1f, 0.3f, 0f); } if (buildingSelected.Landable && buildingSelected.OnceLanded) { BuildingLandUnselect(); } } } else { if (bTemporarySelect) { // land building if ((buildingSelected != null) && (MouseClickedBuilding != buildingSelected) && buildingSelected.OnceLanded) { BuildingLandUnselect(); } } else { // land building if ((buildingSelected != null) && (MouseClickedBuilding != buildingSelected) && buildingSelected.OnceLanded) { BuildingLandUnselect(); } //Debug.Log ("Update3 buildingSelected:"+((buildingSelected != null) ? buildingSelected.name : "none")); Pick(); } } } } //zoom if (!InFade) { zoomCurrent -= Input.GetAxis("Mouse ScrollWheel") * zoomSpeed; zoomCurrent = Mathf.Clamp(zoomCurrent, zoomMin, zoomMax); goCamera.transform.localPosition = new Vector3(0, 0, -zoomCurrent); } // pinch zoom for mobile touch input if (Input.touchCount == 2) { // Store both touches. Touch touchZero = Input.GetTouch(0); Touch touchOne = Input.GetTouch(1); // Find the position in the previous frame of each touch. Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition; Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition; // Find the magnitude of the vector (the distance) between the touches in each frame. float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude; float touchDeltaMag = (touchZero.position - touchOne.position).magnitude; // Find the difference in the distances between each frame. float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag; zoomCurrent += deltaMagnitudeDiff * perspectiveZoomSpeed; zoomCurrent = Mathf.Clamp(zoomCurrent, zoomMin, zoomMax); goCamera.transform.localPosition = new Vector3(0, 0, -zoomCurrent); } }
void Awake() { instance = this; SetModal = false; gameObject.SetActive(false); }