123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 |
- using System;
- using Prime31;
- using UnityEngine;
- using System.Collections;
- using TMPro;
- using ICTS.Localization;
- public class ObjectivesDialog : ScreenBase
- {
- public TextMeshProUGUI targetScore;
- public bool ScreenPaused;
- public LevelObjectiveUI targetObjective;
- public LevelObjectiveUI[] objectives;
- public TextMeshProUGUI Title;
- public StarsSummary starsSummary;
- private GameOverScreenTitle _gameOverScreenTitle;
- LevelMapping _level;
- Vector3[] _originalObjectivePositions;
- protected override void Awake()
- {
-
- base.Awake();
- _originalObjectivePositions = new Vector3[objectives.Length];
- for (int i = 0; i < objectives.Length; i++)
- {
- _originalObjectivePositions[i] = objectives[i].transform.localPosition;
- }
- }
- void OnEnable()
- {
- for (int i = 0; i < objectives.Length; i++)
- {
- objectives[i].transform.localPosition = _originalObjectivePositions[i];
- }
- if(!ScreenPaused)
- {
- Title.text = string.Format(Localization.instance.Get("scores.levelGlobalTitle"),
- LevelsManager.Instance.CurrentLevelIndex+1);
- }
-
- }
- void completionHandler(string error, object result)
- {
- if (error != null)
- Debug.LogError(error);
- else
- Prime31.Utils.logObject(result);
- }
- public void SetObjectives(LevelMapping level, bool showAmmoConstraint)
- {
- //position according to number of objectives, so they appear centered
- AVDebug.Assert(objectives.Length == 3, "Centering of objectives is assuming there will be max of 3 objectives");
- int numOfLevelObjectives = level.objectives.Length;
- //If we don't show the ammo constraint, then just reduce the number of level objectives being shown to the player, as that ammo is not really an objective.
- if (!showAmmoConstraint)
- {
- for (int i = 0; i < numOfLevelObjectives; i++)
- {
- if (level.objectives[i].type == LevelObjective.ObjectiveType.LimitedAmmo)
- {
- --numOfLevelObjectives;
- }
- }
- }
- if (numOfLevelObjectives == 1)
- {
- //put it in the center
- objectives[0].transform.localPosition = _originalObjectivePositions[1];
- } else
- if (numOfLevelObjectives == 2)
- {
- //find mid points, and move the first 2 objectives
- float x = (_originalObjectivePositions[0].x + _originalObjectivePositions[1].x)/2;
- objectives[0].transform.localPosition = new Vector3(x, _originalObjectivePositions[0].y, _originalObjectivePositions[0].z);
- x = (_originalObjectivePositions[1].x + _originalObjectivePositions[2].x)/2;
- objectives[1].transform.localPosition = new Vector3(x, _originalObjectivePositions[1].y, _originalObjectivePositions[1].z);
- }
- _level = level;
- char[] chars = level.star1Threshold.ToString().ToCharArray();
- Array.Reverse(chars);
- string newValue = "";
- var count = 1;
- for (int i = 0; i < chars.Length; i++)
- {
- if (count % 3 == 0 && chars.Length > 3)
- {
- //Debug.Log("DOT " + i + " " + chars.Length);
- newValue = newValue + chars[i] + ".";
- }
- else
- {
- newValue = newValue + chars[i];
- }
- count++;
- }
- chars = newValue.ToCharArray();
- Array.Reverse(chars);
- newValue = "";
- for (int i = 0; i < chars.Length; i++)
- {
- newValue = newValue + chars[i];
- }
- targetScore.text = Localization.instance.Get("scoreSummary.target.prefix") + " " + newValue + " " + Localization.instance.Get("scoreSummary.target.points");
- AVDebug.Assert(numOfLevelObjectives <= objectives.Length, "We don't have enough UI elements to show the level objects set for this level "+level.levelName);
- int objectiveUIIndex = 0;
- for (int i = 0; i < level.objectives.Length; i++)
- {
- //Skip limited ammo
- if (!showAmmoConstraint &&
- level.objectives[i].type == LevelObjective.ObjectiveType.LimitedAmmo)
- {
- continue;
- }
- objectives[objectiveUIIndex].gameObject.SetActive(true);
- objectives[objectiveUIIndex].SetObjective(level.objectives[i]);
- objectiveUIIndex++;
- }
- //disable the others
- for (int i = numOfLevelObjectives; i < objectives.Length; i++)
- {
- objectives[i].gameObject.SetActive(false);
- }
- }
- public void SetupForPreLevelObjectivesSummary()
- {
- for (int i = 0; i < _level.objectives.Length; i++)
- {
- objectives[i].SetTargetValue(objectives[i].Target);
- }
- }
- IEnumerator ResultSave()
- {
- yield return new WaitForSeconds(0.1f);
- CurrentResult();
- yield return new WaitForSeconds(4);
-
-
- }
- public bool CurrentResult()
- {
- int score = GameDataManager.Instance.Score;
- int curTargetFinish = 0;
- if (score >= _level.star1Threshold)
- {
- for (int i = 0; i < _level.objectives.Length; i++)
- {
- var currentTarget1 = _level.objectives[i].Actual;
- var target1 = _level.objectives[i].target;
- if (currentTarget1 == target1 )
- {
- Debug.Log(currentTarget1 == target1);
- curTargetFinish++;
- }
- }
- Debug.Log(PlayerPrefs.GetInt("Level"));
- if (curTargetFinish == _level.objectives.Length)
- {
- var curLEvel = PlayerPrefs.GetInt("Level");
- if (LevelsManager.Instance.CurrentLevelIndex + 1 == curLEvel)
- {
- if (curLEvel<=6)
- {
- Debug.Log("!!! curLEvel " + curLEvel);
- curLEvel = curLEvel + 1;
- var post = PlayerPrefs.GetInt("Post");
- if (curLEvel == 7 && post == 0)
- {
- //Debug.Log("Facebook.instance.postMessageWithLinkAndLinkToImage");
- //MenuManager._instance.FBShareDialog.Show();
- }
- PlayerPrefs.SetInt("Level", curLEvel);
- PlayerPrefs.Save();
- Debug.LogError(curLEvel);
- //if (curLEvel == 3)
- //{
- // MenuManager._instance.RescueMomentMessage.Show();
- //}
- if (curLEvel == 1 || curLEvel == 3 || curLEvel == 6 )
- {
- //Vungle.playAd();
- MenuManager._instance.CurState = MenuManager.StateAd.GameOver;
- }
- if (curLEvel == 2 || curLEvel == 5)
- {
- //MoPub.showBanner(true);
- }
- //if (curLEvel == 6)
- //{
- // MenuManager._instance.OnActionLevelSixStart();
- //}
- if (curLEvel == 6)
- {
- MenuManager._instance.OnActionLevelNineStart();
- }
-
- }
-
- }
- var curLevel1 = PlayerPrefs.GetInt("Level");
- //if (/*LevelsManager.Instance.CurrentLevelIndex <= curLevel1 - 1 &&*/ LevelsManager.Instance.CurrentLevelIndex + 1 <= 9)
- //{
- // LevelsManager.Instance.CurrentLevelIndex++;
- //}
- //if (LevelsManager.Instance.CurrentLevelIndex <= curLevel1 - 1 && LevelsManager.Instance.CurrentLevelIndex+1<=5)
- //{
- // LevelsManager.Instance.CurrentLevelIndex++;
- //}
- MenuManager._instance.Finish = true;
- GetComponent<GameOverScreenTitle>().OnActive(true);
-
- return true;
- }
- else
- {
- MenuManager._instance.Finish = false;
- GetComponent<GameOverScreenTitle>().OnActive(true);
-
- return false;
- }
- }
- else
- {
- MenuManager._instance.Finish = false;
- GetComponent<GameOverScreenTitle>().OnActive(true);
- return false;
- }
- }
- public void UpdateResult()
- {
- if(targetObjective.objectiveMarkMet.gameObject.activeSelf)
- {
- for (int i = 0; i < _level.objectives.Length; i++)
- {
- if(objectives[i].objectiveMarkMet.gameObject.activeSelf)
- {
- }
- else
- {
- //var curLevel = PlayerPrefs.GetInt("Level");
- //if (LevelsManager.Instance.CurrentLevelIndex <= curLevel - 1)
- //{
- // LevelsManager.Instance.CurrentLevelIndex++;
- //}
- return;
- }
- }
-
- }
- else
- {
- return;
- }
- var curLEvel = PlayerPrefs.GetInt("Level");
- if (LevelsManager.Instance.CurrentLevelIndex + 1 == curLEvel)
- {
- curLEvel = curLEvel + 1;
- Debug.Log(curLEvel);
- //PlayerPrefs.SetInt("Level", curLEvel);
- if (curLEvel == 1 || curLEvel == 3 || curLEvel == 6)
- {
- //Vungle.playAd();
- MenuManager._instance.CurState = MenuManager.StateAd.GameOver;
- }
- if (curLEvel == 2 || curLEvel == 5 || curLEvel == 4 )
- {
- //MoPub.showBanner(true);
- }
-
- }
- var curLevel1 = PlayerPrefs.GetInt("Level");
- //if (LevelsManager.Instance.CurrentLevelIndex <= curLevel1 - 1 && LevelsManager.Instance.CurrentLevelIndex<5)
- //{
- // LevelsManager.Instance.CurrentLevelIndex++;
- //
- //}
- }
- public void UpdateObjectivesStateForPauseScreen()
- {
- int score = GameDataManager.Instance.Score;
- int target = _level.star1Threshold;
- string targetPrefix = Localization.instance.Get("scoreSummary.target.prefix");
- string targetSuffix = Localization.instance.Get("scoreSummary.target.points");
- char[] chars =target.ToString().ToCharArray();
- Array.Reverse(chars);
- string newValue = "";
- var count = 1;
- for (int i = 0; i < chars.Length; i++)
- {
- if (count % 3 == 0 && chars.Length > 3)
- {
- newValue = newValue + chars[i] + ".";
- }
- else
- {
- newValue = newValue + chars[i];
- }
- count++;
- }
- chars = newValue.ToCharArray();
- Array.Reverse(chars);
- newValue = "";
- for (int i = 0; i < chars.Length; i++)
- {
- newValue = newValue + chars[i];
- }
- targetObjective.SetProgressValue(newValue, targetPrefix, targetSuffix);
- if (score >= target)
- {
- targetObjective.SetComplete(playSound:false);
- } else
- {
- targetObjective.SetNotComplete(playSound:false);
- }
- int objectiveUIIndex = 0;
- for (int i = 0; i < _level.objectives.Length; i++)
- {
- //Skip limited ammo for pause
- if (_level.objectives[i].type == LevelObjective.ObjectiveType.LimitedAmmo)
- {
- continue;
- }
- LevelObjectiveUI objective = objectives[objectiveUIIndex++];
- if (objective.title.text == "Timi" || objective.title.text == "Time")
- {
- objective.SetTargetValue(objective.Target);
- objective.UpdateStateForPauseScreen();
- }
- else
- {
- string objectivePrefix = string.Empty;
- string objectiveSuffix = "/" + objective.Target;
- objective.SetProgressValue(objective.Actual, objectivePrefix, objectiveSuffix);
- objective.UpdateStateForPauseScreen();
- }
-
- }
- }
- public void UpdateObjectivesStateForGameOverScreen()
- {
- StartCoroutine(UpdateObjectivesStateForGameOverScreenCoroutine());
- StartCoroutine(ResultSave());
- }
- IEnumerator UpdateObjectivesStateForGameOverScreenCoroutine()
- {
- yield return new WaitForSeconds(0.5f);
- //Start with introducing target score and objectives
- int score = GameDataManager.Instance.Score;
- string scorePrefix = Localization.instance.Get("scoreSummary.score.prefix");
- string scoreSuffix = string.Empty;
-
- targetObjective.AnimateValue(score, scorePrefix, scoreSuffix, () =>
- {
- IntroduceNextObjective(0);
- });
- }
- void IntroduceNextObjective(int i)
- {
- if (i < _level.objectives.Length)
- {
- //Skip limited ammo for game over
- if (_level.objectives[i].type == LevelObjective.ObjectiveType.LimitedAmmo)
- {
- IntroduceNextObjective(i+1);
- return;
- }
- LevelObjectiveUI objective = objectives[i];
- string objectivePrefix = "";
- string objectiveSuffix = "";
- if(objective.title.text == "Timi" || objective.title.text == "Time")
- {
- objectivePrefix = string.Empty;
- objectiveSuffix = objective.Target.ToString();
- }
- else
- {
- objectivePrefix = string.Empty;
- objectiveSuffix = "/" + objective.Target;
- }
-
- objective.AnimateValue(objective.Actual, objectivePrefix, objectiveSuffix, () =>
- {
- IntroduceNextObjective(i+1);
- });
- } else
- {
- StartCoroutine(ShowMarkingsCoroutine());
- }
- }
- IEnumerator ShowMarkingsCoroutine()
- {
- yield return new WaitForSeconds(0.3f);
- int score = GameDataManager.Instance.Score;
- if (score >= _level.star1Threshold)
- {
-
- targetObjective.SetComplete(playSound:true);
- } else
- {
- targetObjective.SetNotComplete(playSound:true);
- }
- yield return new WaitForSeconds(0.5f);
- for (int i = 0; i < _level.objectives.Length; i++)
- {
- LevelObjectiveUI objective = objectives[i];
- objective.UpdateStateForGameOverScreen();
- yield return new WaitForSeconds(0.5f);
- }
- yield return new WaitForSeconds(0.5f);
- starsSummary.AnimateStars();
-
- }
- }
|