123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527 |
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Events;
- using System;
- using System.Xml;
- using System.Text;
- using System.Collections;
- using System.Collections.Generic;
- using Object = UnityEngine.Object;
- public enum AchieveType
- {
- Elf,
- AD,
- Skill,
- Sign,
- Share,
- Flower,
- Person,
- Garden,
- TotalCoin,
- MiniGame,
- FlowerCoin,
- CurrentCoin,
- }
- public class Achieve
- {
- #region 变量
- public string Desc
- {
- get
- {
- return Language.GetStr("AchieveDesc", ID);
- }
- }
- public string Name
- {
- get
- {
- return Language.GetStr("AchieveName", ID);
- }
- }
- public int ID_;
- public string ID
- {
- get
- {
- return "Achieve" + ID_;
- }
- }
- public bool Regist
- {
- get { return Regist_; }
- set
- {
- Regist_ = value;
- if (Regist_)
- {
- AchieveItem = ManaReso.GetAchieveItem();
- RegistValue();
- }
- }
- }
- public bool Regist_;
- public string Icon_;
- public Sprite Icon
- {
- get { return ManaReso.Load<Sprite>(Icon_, Folder.UI); }
- }
- public int Index;
- public int Parent;
- public bool Valid;
- public bool Finish;
- public bool Delete;
- public float Person;
- public float CoinPerson;
- public float DiamondOnce;
- public double Value;
- public AchieveType Type;
- public List<Achieve> PostAchieveList = new List<Achieve>();
- public Text Tit;
- public Text Lab;
- public Text BtnLab;
- public Slider Slider;
- public Image Image;
- public Button Button;
- public Transform AchieveItem;
- #endregion
- public Achieve(XmlAttributeCollection attribute)
- {
- Valid = true;
- Icon_ = attribute[11].Value;
- Type = TypeParse(attribute[4].Value);
- Value = double.Parse(attribute[5].Value);
- Delete = BoolParse(attribute[7].Value);
- Parent = ParentParse(attribute[6].Value);
- ID_ = int.Parse(attribute[0].Value);
- Index = int.Parse(attribute[1].Value);
- Person = AwardParse(attribute[10].Value);
- CoinPerson = AwardParse(attribute[9].Value);
- DiamondOnce = AwardParse(attribute[8].Value);
- ManaAchieve.AchieveDic.Add(ID_, this);
-
- if (Parent != -1)
- {
- ManaAchieve.AchieveDic[Parent].PostAchieveList.Add(this);
- }
- }
- public void GetAward()
- {
- ManaDebug.Log(string.Format("获得钻石<color=red>{0}</color> 参观人次+<color=red>{1}</color> 每人次金币+<color=red>{2}</color>", DiamondOnce, Person, CoinPerson));
- Valid = false;
- ManaData.Diamond += DiamondOnce;
- ManaData.SkillPerson += Person;
- ManaData.SkillCoinPerson += CoinPerson;
- ManaAchieve.DeleDic[Type] = null;
- if (Delete)
- {
- ManaReso.Save(AchieveItem);
-
- if (PostAchieveList.Count > 0)
- {
- PostAchieveList[0].Regist = true;
-
- PostAchieveList.RemoveAt(0);
- }
- }
- else
- {
- UpdateStatus();
- }
- }
- public void RegistValue()
- {
- Dictionary<string, Transform> dic = new Dictionary<string, Transform>();
- Auxiliary.CompileDic(AchieveItem, dic);
- Tit = dic["Tit"].GetComponent<Text>();
- Lab = dic["Lab"].GetComponent<Text>();
- Slider = dic["Slider"].GetComponent<Slider>();
- Image = dic["Icon"].GetComponent<Image>();
- Button = dic["Btn"].GetComponent<Button>();
- BtnLab = dic["BtnLab"].GetComponent<Text>();
- ManaText.Add(Tit, new LanStr("AchieveName", ID));
- ManaText.Add(Lab, new LanStr("AchieveDesc", ID));
- ManaAchieve.DeleDic[Type] += UpdateValue;
- Image.sprite = Icon;
- AchieveItem.SetSiblingIndex(Index - 1);
- Button.onClick.RemoveAllListeners();
- Button.onClick.AddListener(GetAward);
- UpdateValue();
- UpdateStatus();
- }
- public void UpdateValue()
- {
- double value;
- if (Type == AchieveType.AD)
- {
- value = ManaData.AD;
- }
- else if (Type == AchieveType.Skill)
- {
- value = ManaData.Skill;
- }
- else if (Type == AchieveType.Sign)
- {
- value = ManaData.Sign;
- }
- else if (Type == AchieveType.Share)
- {
- value = ManaData.Share;
- }
- else if (Type == AchieveType.Flower)
- {
- value = ManaGarden.MyFlower;
- }
- else if (Type == AchieveType.Person)
- {
- value = ManaData.Person;
- }
- else if (Type == AchieveType.Elf)
- {
- value = ManaData.Elf;
- }
- else if (Type == AchieveType.TotalCoin)
- {
- value = ManaData.TotalCoin;
- }
- else if (Type == AchieveType.MiniGame)
- {
- value = ManaData.MiniGame;
- }
- else if (Type == AchieveType.FlowerCoin)
- {
- value = ManaData.FlowerCoin;
- }
- else if (Type == AchieveType.CurrentCoin)
- {
- value = ManaData.Coin;
- }
- else if (Type == AchieveType.Garden)
- {
- value = ManaData.Level;
- }
- else
- {
- throw new Exception();
- }
- Slider.value = (float)(value / Value);
- if (value >= Value)
- {
- Finish = true;
- }
- }
- public void UpdateValue(double value)
- {
- if (Valid == false)
- {
- return;
- }
- Slider.value = (float)(value/Value);
- if (value >= Value)
- {
- Finish = true;
- UpdateStatus();
- }
- }
- public void UpdateStatus()
- {
- if (Finish == false)
- {
- StatusProcess();
- }
- else
- {
- if (Valid)
- {
- StatusAvailible();
- }
- else
- {
- StausComplete();
- }
- }
- }
- public void StatusProcess()
- {
- List<object> objList = new List<object>();
-
- objList.Add(new LanStr("Object", "AchieveItem_BtnLab0"));
- objList.Add("\n");
- if (Math.Abs(DiamondOnce) > 0.0005f)
- {
- objList.Add("<(钻石)>" + DiamondOnce.ToString("0"));
- }
- if (Math.Abs(CoinPerson) > 0.0005f)
- {
- objList.Add(new LanStr("Common", "CoinPerson"));
- objList.Add("+");
- objList.Add(CoinPerson.ToString("0") + " ");
- }
- if (Math.Abs(Person) > 0.0005f)
- {
- objList.Add(new LanStr("Common", "Person"));
- objList.Add("+");
- objList.Add(Person.ToString("0") + " ");
- }
- Button.image.material = ManaReso.Load<Material>("GrayMat", Folder.Shader);
- Button.interactable = false;
- ManaText.Add(BtnLab, objList.ToArray());
- }
- public void StatusAvailible()
- {
- List<object> objList = new List<object>();
- objList.Add(new LanStr("Object", "AchieveItem_BtnLab1"));
- objList.Add("\n");
- if (Math.Abs(DiamondOnce) > 0.0005f)
- {
- objList.Add("<(钻石)>" + DiamondOnce.ToString("0"));
- }
- if (Math.Abs(CoinPerson) > 0.0005f)
- {
- objList.Add(new LanStr("Common", "CoinPerson"));
- objList.Add("+");
- objList.Add(CoinPerson.ToString("0") + " ");
- }
- if (Math.Abs(Person) > 0.0005f)
- {
- objList.Add(new LanStr("Common", "Person"));
- objList.Add("+");
- objList.Add(Person.ToString("0") + " ");
- }
- Button.image.material = null;
- Button.interactable = true;
- ManaText.Add(BtnLab, objList.ToArray());
- }
- public void StausComplete()
- {
- Button.image.material = null;
- Button.interactable = false;
- ManaText.Add(BtnLab, new LanStr("Object", "AchieveItem_BtnLab2"));
- }
- public int ParentParse(string str)
- {
- if (string.IsNullOrEmpty(str))
- {
- return -1;
- }
- else
- {
- return int.Parse(str);
- }
- }
- public bool BoolParse(string str)
- {
- return Convert.ToBoolean(int.Parse(str));
- }
- public float AwardParse(string str)
- {
- if (string.IsNullOrEmpty(str))
- {
- return 0;
- }
- else
- {
- return float.Parse(str);
- }
- }
- public AchieveType TypeParse(string str)
- {
- int integer = int.Parse(str);
- if (integer == 1)
- {
- return AchieveType.Garden;
- }
- else if (integer == 2)
- {
- return AchieveType.CurrentCoin;
- }
- else if (integer == 3)
- {
- return AchieveType.TotalCoin;
- }
- else if (integer == 4)
- {
- return AchieveType.Elf;
- }
- else if (integer == 5)
- {
- return AchieveType.Flower;
- }
- else if (integer == 6)
- {
- return AchieveType.Person;
- }
- else if (integer == 7)
- {
- return AchieveType.Skill;
- }
- else if (integer == 8)
- {
- return AchieveType.AD;
- }
- else if (integer == 9)
- {
- return AchieveType.Sign;
- }
- else if (integer == 10)
- {
- return AchieveType.Share;
- }
- else if (integer == 11)
- {
- return AchieveType.MiniGame;
- }
- else if (integer == 12)
- {
- return AchieveType.FlowerCoin;
- }
- else
- {
- throw new Exception();
- }
- }
- }
- public class ManaAchieve : Regist
- {
- #region 变量
- public static UnityAction<double> Elf;
- public static UnityAction<double> AD;
- public static UnityAction<double> Skill;
- public static UnityAction<double> Sign;
- public static UnityAction<double> Share;
- public static UnityAction<double> Flower;
- public static UnityAction<double> Person;
- public static UnityAction<double> Garden;
- public static UnityAction<double> TotalCoin;
- public static UnityAction<double> MiniGame;
- public static UnityAction<double> FlowerCoin;
- public static UnityAction<double> CurrentCoin;
- public static Dictionary<int, Achieve> AchieveDic = new Dictionary<int, Achieve>();
- public static Dictionary<AchieveType, UnityAction<double>> DeleDic = new Dictionary<AchieveType, UnityAction<double>>();
-
- #endregion
- public override void Instantiate()
- {
- List<XmlAttributeCollection> attributeList = Data.GetAchieveConfig();
- for (int i = 0; i < attributeList.Count; i++)
- {
- new Achieve(attributeList[i]);
- }
- }
- public override void RegistValueA()
- {
- DeleDic.Add(AchieveType.Elf, Elf);
- DeleDic.Add(AchieveType.AD, AD);
- DeleDic.Add(AchieveType.Skill, Skill);
- DeleDic.Add(AchieveType.Sign, Sign);
- DeleDic.Add(AchieveType.Share, Share);
- DeleDic.Add(AchieveType.Flower, Flower);
- DeleDic.Add(AchieveType.Person, Person);
- DeleDic.Add(AchieveType.Garden, Garden);
- DeleDic.Add(AchieveType.TotalCoin, TotalCoin);
- DeleDic.Add(AchieveType.MiniGame, MiniGame);
- DeleDic.Add(AchieveType.FlowerCoin, FlowerCoin);
- DeleDic.Add(AchieveType.CurrentCoin, CurrentCoin);
- List<int> achieveList = Data.GetAchieveList();
- for (int i = 0; i < achieveList.Count; i++)
- {
- AchieveDic[achieveList[i]].Valid = false;
- AchieveDic[achieveList[i]].Finish = true;
- }
- foreach (var kv in AchieveDic)
- {
- if (kv.Value.Valid)
- {
- if (kv.Value.Parent == -1 || !AchieveDic[kv.Value.Parent].Valid)
- {
- kv.Value.Regist = true;
- }
- }
- else
- {
- if (kv.Value.Delete == false)
- {
- kv.Value.Regist = true;
- kv.Value.Slider.value = 1;
- }
- }
- }
- }
- public static void UpdateStatus(AchieveType type, double value)
- {
- DeleDic[type].SafeInvoke(value);
- }
- }
|