123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- using UnityEngine;
- using System.Collections;
- using System;
- using TMPro;
- using UnityEngine.UI;
- using ICTS.Localization;
- using DG.Tweening;
- using System.Collections.Generic;
- public class LevelObjectiveUI : MonoBehaviour
- {
- public TextMeshProUGUI title;
- public TextMeshProUGUI label;
- public Image[] icons;
- public Image objectiveMarkMet;
- public Image objectiveMarkNotMet;
- public SoundEvent objectiveMetSound;
- public SoundEvent objectiveNotMetSound;
- Vector3 _originalScaleMarkMet;
- Vector3 _originalScaleMarkNotMet;
- LevelObjective _levelObjective;
- const float VALUE_ANIM_TIME = 0.5f;
- void Awake()
- {
- _originalScaleMarkMet = objectiveMarkMet.transform.localScale;
- _originalScaleMarkNotMet = objectiveMarkNotMet.transform.localScale;
- }
- void OnEnable()
- {
- objectiveMarkMet.gameObject.SetActive(false);
- objectiveMarkNotMet.gameObject.SetActive(false);
- label.text = "";
- }
- public void SetObjective(LevelObjective objective)
- {
- _levelObjective = objective;
- int nextIcon = 0;
- for (int i = 0; i < icons.Length; i++)
- {
- icons[i].gameObject.SetActive(false);
- }
- //label.text = objective.target.ToString();
- switch (objective.type)
- {
- case LevelObjective.ObjectiveType.SurviveForXTime:
- title.text = Localization.instance.Get("objectives.surviveForXTime.title");
- objectiveMetSound = SoundEvent.scoreSummary_surviveMet;
- objectiveNotMetSound = SoundEvent.scoreSummary_surviveNotMet;
- break;
- case LevelObjective.ObjectiveType.CaptureXEnemies:
- title.text = Localization.instance.Get("objectives.captureXEnemies.title");
- //AVDebug.Assert(objective.enemyType != EnemyType.anyVirus, "We don't have an icon for this yet: "+objective.enemyType);
- //AVDebug.Assert(objective.enemyType != EnemyType.bronzeSperm, "We don't have an icon for this yet: "+objective.enemyType);
- //AVDebug.Assert(objective.enemyType != EnemyType.goldSperm, "We don't have an icon for this yet: "+objective.enemyType);
- //AVDebug.Assert(objective.enemyType != EnemyType.silverSperm, "We don't have an icon for this yet: "+objective.enemyType);
- SetNextIcon(ref nextIcon, "icon_"+objective.enemyType.ToString());
- if (objective.weaponType != PickupType.AnyWeapon)
- {
- SetNextIcon(ref nextIcon, "pickup"+objective.weaponType.ToString());
- }
- objectiveMetSound = SoundEvent.scoreSummary_captureMet;
- objectiveNotMetSound = SoundEvent.scoreSummary_captureNotMet;
- break;
- case LevelObjective.ObjectiveType.LimitedAmmo:
- title.text = Localization.instance.Get("objectives.limitedAmmo.title");
- //Not really required for limited ammo, since it's more of a restriction
- objectiveMetSound = SoundEvent.scoreSummary_targetMet;
- objectiveNotMetSound = SoundEvent.scoreSummary_targetNotMet;
- break;
- default:
- AVDebug.LogError("Objective type not being handled in UI: "+objective.type);
- break;
- }
- }
- void SetNextIcon(ref int nextIcon, string spriteName)
- {
- Image icon = icons[nextIcon];
- var list = MenuManager._instance.IconSprites;
- Debug.Log(spriteName);
- for (int i = 0; i < list.Count; i++)
- {
- if(spriteName == list[i].Texture.name)
- {
- icon.sprite = list[i].Texture;
- }
- }
-
- icon.gameObject.SetActive(true);
- icon.SetNativeSize();
- //Limit the size (especially done for pickups, since we are re-using the same graphics, which are too big for this
- int maxWidth = 67;
- if (icon.transform.localScale.x > maxWidth)
- {
- float factor = maxWidth / icon.transform.localScale.x;
- icon.transform.localScale *= factor;
- }
- ++nextIcon;
- }
- public void SetComplete(bool playSound)
- {
- if (playSound)
- {
- SoundManager.Play(objectiveMetSound);
- }
- objectiveMarkMet.gameObject.SetActive(true);
- objectiveMarkMet.transform.localScale = _originalScaleMarkMet*2;
- objectiveMarkMet.color = new Color(objectiveMarkMet.color.r, objectiveMarkMet.color.g, objectiveMarkMet.color.b, 0);
- objectiveMarkMet.DOFade(1,1);
- objectiveMarkMet.ScaleTo(_originalScaleMarkMet, 0.5f, ease:MyTween.Ease.easeOutBack);
- }
- public void SetNotComplete(bool playSound)
- {
- if (playSound)
- {
- SoundManager.Play(objectiveNotMetSound);
- }
- objectiveMarkNotMet.gameObject.SetActive(true);
- objectiveMarkNotMet.transform.localScale = _originalScaleMarkNotMet*2;
- objectiveMarkMet.color = new Color(objectiveMarkMet.color.r, objectiveMarkMet.color.g, objectiveMarkMet.color.b, 0);
- objectiveMarkMet.DOFade(1, 1);
- objectiveMarkNotMet.ScaleTo(_originalScaleMarkNotMet, 0.5f, ease:MyTween.Ease.easeOutBack);
- }
- public void UpdateStateForPauseScreen()
- {
- if (_levelObjective != null)
- {
- if (_levelObjective.IsMet)
- {
- SetComplete(playSound:false);
- } else
- {
- SetNotComplete(playSound:false);
- }
- }
- }
- public void UpdateStateForGameOverScreen()
- {
- if (_levelObjective == null)
- {
- return;
- }
- //don't do anything for limited ammo, as such it is just a restriction rather an objective
- if (_levelObjective.type == LevelObjective.ObjectiveType.LimitedAmmo)
- {
- return;
- }
- if (_levelObjective.IsMet)
- {
- SetComplete(playSound:true);
- } else
- {
- SetNotComplete(playSound:true);
- }
- }
- public int Target
- {
- get
- {
- if (_levelObjective != null)
- {
- return _levelObjective.target;
- }
- else
- {
- return 0;
- }
- }
- }
- public int Actual
- {
- get
- {
- if (_levelObjective != null)
- {
- return _levelObjective.Actual;
-
- }
- else
- {
- return 0;
- }
- }
- }
- public void SetTargetValue(int targetValue)
- {
- //Debug.Log("SetTargetValue");
- gameObject.SetActive(true);
- if (title.text == "Timi" || title.text == "Time")
- {
- UpdateLabelTimi(targetValue.ToString());
- }
- else
- {
- UpdateLabel(targetValue);
- }
-
- }
- public void SetProgressValue(int actualValue, string prefix, string suffix)
- {
- //Debug.Log("SetProgressValue");
- gameObject.SetActive(true);
- //Debug.Log(suffix);
- UpdateLabel(actualValue, prefix, suffix);
- }
- public void SetProgressValue(string actualValue, string prefix, string suffix)
- {
- //Debug.Log("SetProgressValue");
- gameObject.SetActive(true);
- //Debug.Log(suffix);
- UpdateLabel(actualValue, prefix, suffix);
- }
- public void AnimateValue(int actualValue, string prefix, string suffix, Action onComplete)
- {
- //Debug.Log("AnimateValue");
- gameObject.SetActive(true);
- if (title!= null)
- {
- if (title.text == "Timi" || title.text == "Time")
- {
- UpdateLabelTimi(suffix);
- }
- else
- {
- UpdateLabel(0, prefix, suffix);
- }
- }
- else
- {
-
- UpdateLabel(0, prefix, suffix);
-
- }
- AVDebug.LogWarning("Sound Active" + gameObject.name + " " + gameObject.transform.parent.parent.gameObject.name);
- if (gameObject.transform.parent.parent.gameObject.activeSelf)
- {
- SoundManager.Play(SoundEvent.scoreSummary_pointCounter);
- //MenuManager._instance.audioLoop.loop = false;
- }
- this.ValueTo(0, actualValue, VALUE_ANIM_TIME, (f) =>
- {
- if(prefix.Contains("Stig"))
- {
- char[] chars = ((int)f).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];
- }
- UpdateLabel(newValue, prefix, suffix);
- }
- else
- {
- if (title != null)
- {
- if (title.text == "Timi" || title.text == "Time")
- {
- UpdateLabelTimi(suffix);
- }
- else
- {
- UpdateLabel((int)f, prefix, suffix);
- }
- }
- else
- {
-
- UpdateLabel((int)f, prefix, suffix);
-
- }
-
- }
-
- }, OnComplete: () =>
- {
- AVDebug.LogWarning("Sound OFF");
- //SoundManager.StopLoop(SoundEvent.scoreSummary_pointCounter);
- //MenuManager._instance.audioLoop.loop = false;
- if (onComplete != null)
- {
- onComplete();
- }
- });
- }
- void UpdateLabel(int value, string prefix = "", string suffix = "")
- {
-
- label.text = prefix + " " +value + " " +suffix;
- //Debug.Log("suffix " + suffix + " " + value);
- }
- void UpdateLabel(string value, string prefix = "", string suffix = "")
- {
- //Debug.Log(value + " " + prefix + " " + suffix);
- label.text = prefix + " " + value + " " + suffix;
- //Debug.Log("suffix " + suffix + " " + value);
- }
- void UpdateLabelTimi(string suffix = "")
- {
- //Debug.Log(suffix + " sekúndur");
- label.text = string.Format(Localization.instance.Get("time.text"), suffix);
- //Debug.Log("suffix " + suffix + " " + value);
- }
-
- }
|