ManaSign.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System;
  4. using System.Xml;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. public class Sign
  8. {
  9. #region 变量
  10. public int Coin;
  11. public int Diamond;
  12. public Text Lab1;
  13. public Text Lab2;
  14. public Image Icon;
  15. public Image Mark;
  16. public List<int> FlowerList = new List<int>();
  17. #endregion
  18. public Sign(int index, Transform tra, XmlAttributeCollection attribute)
  19. {
  20. Dictionary<string, Transform> dic = new Dictionary<string, Transform>();
  21. Auxiliary.CompileDic(tra, dic);
  22. Lab1 = dic["Lab1"].GetComponent<Text>();
  23. Lab2 = dic["Lab2"].GetComponent<Text>();
  24. Icon = dic["Icon1"].GetComponent<Image>();
  25. Mark = dic["Icon2"].GetComponent<Image>();
  26. Lab2.text = index.ToString();
  27. Coin = Auxiliary.IntParse(attribute[3].Value, 0);
  28. Diamond = Auxiliary.IntParse(attribute[2].Value, 0);
  29. FlowerList = Auxiliary.IntListParse(',', attribute[1].Value, new List<int>());
  30. SetUI();
  31. }
  32. public void Get()
  33. {
  34. Mark.SetActive(true);
  35. ManaSign.SignTime = ManaServer.Time;
  36. ManaSign.SignIndex++;
  37. ManaSign.SignIndex %= 22;
  38. if (FlowerList.Valid())
  39. {
  40. for (int i = 0; i < FlowerList.Count; i++)
  41. {
  42. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[FlowerList[i]];
  43. if (flowerInfo.Unlock == false)
  44. {
  45. flowerInfo.Unlock = true;
  46. return;
  47. }
  48. }
  49. }
  50. if (Diamond > 0)
  51. {
  52. ManaData.Diamond += Diamond;
  53. }
  54. else if (Coin > 0)
  55. {
  56. ManaData.Coin += Coin;
  57. }
  58. else
  59. {
  60. throw new Exception();
  61. }
  62. }
  63. public void SetUI()
  64. {
  65. if (FlowerList.Valid())
  66. {
  67. for (int i = 0; i < FlowerList.Count; i++)
  68. {
  69. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[FlowerList[i]];
  70. if (flowerInfo.Unlock == false)
  71. {
  72. ManaReso.SetText("Bb_InfoLabA", flowerInfo.Name);
  73. ManaReso.SetActive("Bb_IconA", true);
  74. ManaReso.SetSprite("Bb_IconA0", flowerInfo.Icon);
  75. ManaReso.Get<Image>("Bb_IconA0").Resize(0.65f, 0.65f);
  76. Icon.sprite = flowerInfo.Icon;
  77. Icon.Resize(0.2f, 0.2f);
  78. return;
  79. }
  80. }
  81. }
  82. if (Diamond > 0)
  83. {
  84. ManaReso.SetText("Bb_InfoLabB", Diamond.ToString());
  85. ManaReso.SetSprite("Bb_IconB", ManaReso.Load<Sprite>("钻石", Folder.UI));
  86. ManaReso.SetActive("Bb_IconB", true);
  87. Icon.sprite = ManaReso.Load<Sprite>("钻石", Folder.UI);
  88. Lab1.text = Diamond.ToString();
  89. }
  90. else if (Coin > 0)
  91. {
  92. ManaReso.SetText("Bb_InfoLabB", Coin.ToString());
  93. ManaReso.SetSprite("Bb_IconB", ManaReso.Load<Sprite>("金币", Folder.UI));
  94. ManaReso.SetActive("Bb_IconB", true);
  95. Icon.sprite = ManaReso.Load<Sprite>("金币", Folder.UI);
  96. Lab1.text = Coin.ToString();
  97. }
  98. else
  99. {
  100. throw new Exception();
  101. }
  102. }
  103. }
  104. public class ManaSign : Regist
  105. {
  106. #region 变量
  107. public static int SignIndex;
  108. public static DateTime SignTime;
  109. public static Dictionary<int, Sign> SignDic = new Dictionary<int, Sign>();
  110. #endregion
  111. public static void Get()
  112. {
  113. SignDic[SignIndex].Get();
  114. ManaData.SignAmt++;
  115. }
  116. public static void Reload()
  117. {
  118. SignTime = DateTime.Parse(Data.GetPlayerString("SignTime"));
  119. SignIndex = Data.GetPlayerInt("SignIndex");
  120. foreach (var kv in SignDic)
  121. {
  122. kv.Value.Mark.SetActive(false);
  123. }
  124. for (int i = 1; i < SignIndex; i++)
  125. {
  126. SignDic[i].Mark.SetActive(true);
  127. }
  128. }
  129. public override void RegistValueB()
  130. {
  131. SignTime = DateTime.Parse(Data.GetPlayerString("SignTime"));
  132. SignIndex = Data.GetPlayerInt("SignIndex");
  133. Transform par = ManaReso.Get("Bb_Grid");
  134. List<XmlAttributeCollection> attributeList = Data.GetSignConfig();
  135. for (int i = 0; i < attributeList.Count; i++)
  136. {
  137. Transform tra = ManaReso.Get<ObjRoot>("SignItem", Folder.UI, false, par, false, ObjType.SignItem);
  138. SignDic.Add(i + 1, new Sign(i + 1, tra, attributeList[i]));
  139. }
  140. for (int i = 1; i < SignIndex; i++)
  141. {
  142. SignDic[i].Mark.SetActive(true);
  143. }
  144. }
  145. }