ManaSign.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. }
  31. public void Get()
  32. {
  33. SetUI();
  34. ManaSign.SignTime = ManaServer.Time;
  35. ManaSign.SignIndex++;
  36. ManaSign.SignIndex %= 22;
  37. if (FlowerList.Valid())
  38. {
  39. for (int i = 0; i < FlowerList.Count; i++)
  40. {
  41. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[FlowerList[i]];
  42. if (flowerInfo.Unlock == false)
  43. {
  44. flowerInfo.Unlock = true;
  45. return;
  46. }
  47. }
  48. }
  49. if (Diamond > 0)
  50. {
  51. ManaData.Diamond += Diamond;
  52. }
  53. else if (Coin > 0)
  54. {
  55. ManaData.Coin += Coin;
  56. }
  57. else
  58. {
  59. throw new Exception();
  60. }
  61. }
  62. public void SetUI()
  63. {
  64. Mark.SetActive(true);
  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. Icon.SetActive(true);
  79. return;
  80. }
  81. }
  82. }
  83. if (Diamond > 0)
  84. {
  85. ManaReso.SetText("Bb_InfoLabB", Diamond.ToString());
  86. ManaReso.SetSprite("Bb_IconB", ManaReso.Load<Sprite>("钻石", Folder.UI));
  87. ManaReso.SetActive("Bb_IconB", true);
  88. Icon.sprite = ManaReso.Load<Sprite>("钻石", Folder.UI);
  89. Icon.SetActive(true);
  90. Lab1.text = Diamond.ToString();
  91. Lab1.SetActive(true);
  92. }
  93. else if (Coin > 0)
  94. {
  95. ManaReso.SetText("Bb_InfoLabB", Coin.ToString());
  96. ManaReso.SetSprite("Bb_IconB", ManaReso.Load<Sprite>("金币", Folder.UI));
  97. ManaReso.SetActive("Bb_IconB", true);
  98. Icon.sprite = ManaReso.Load<Sprite>("金币", Folder.UI);
  99. Icon.SetActive(true);
  100. Lab1.text = Coin.ToString();
  101. Lab1.SetActive(true);
  102. }
  103. else
  104. {
  105. throw new Exception();
  106. }
  107. }
  108. }
  109. public class ManaSign : Regist
  110. {
  111. #region 变量
  112. public static int SignIndex;
  113. public static DateTime SignTime;
  114. public static Dictionary<int, Sign> SignDic = new Dictionary<int, Sign>();
  115. #endregion
  116. public static void Get()
  117. {
  118. SignDic[SignIndex].Get();
  119. ManaData.SignAmt++;
  120. }
  121. public static void Reload()
  122. {
  123. SignTime = DateTime.Parse(Data.GetPlayerString("SignTime"));
  124. SignIndex = Data.GetPlayerInt("SignIndex");
  125. foreach (var kv in SignDic)
  126. {
  127. kv.Value.Icon.SetActive(false);
  128. kv.Value.Mark.SetActive(false);
  129. }
  130. for (int i = 1; i < SignIndex; i++)
  131. {
  132. SignDic[i].SetUI();
  133. }
  134. }
  135. public override void RegistValueB()
  136. {
  137. SignTime = DateTime.Parse(Data.GetPlayerString("SignTime"));
  138. SignIndex = Data.GetPlayerInt("SignIndex");
  139. Transform par = ManaReso.Get("Bb_Grid");
  140. List<XmlAttributeCollection> attributeList = Data.GetSignConfig();
  141. for (int i = 0; i < attributeList.Count; i++)
  142. {
  143. Transform tra = ManaReso.Get<ObjRoot>("SignItem", Folder.UI, false, par, false, ObjType.SignItem);
  144. SignDic.Add(i + 1, new Sign(i + 1, tra, attributeList[i]));
  145. }
  146. for (int i = 1; i < SignIndex; i++)
  147. {
  148. SignDic[i].SetUI();
  149. }
  150. }
  151. }