ManaSign.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. ManaReso.SetText("Bb_InfoLabA", flowerInfo.Name);
  46. ManaReso.SetActive("Bb_IconA", true);
  47. ManaReso.SetSprite("Bb_IconA0", flowerInfo.Icon);
  48. ManaReso.Get<Image>("Bb_IconA0").Resize(0.65f, 0.65f);
  49. flowerInfo.Unlock = true;
  50. return;
  51. }
  52. }
  53. }
  54. if (Diamond > 0)
  55. {
  56. ManaReso.SetText("Bb_InfoLabB", Diamond.ToString());
  57. ManaReso.SetSprite("Bb_IconB", ManaReso.Load<Sprite>("钻石", Folder.UI));
  58. ManaReso.SetActive("Bb_IconB", true);
  59. ManaData.Diamond += Diamond;
  60. }
  61. else if (Coin > 0)
  62. {
  63. ManaReso.SetText("Bb_InfoLabB", Coin.ToString());
  64. ManaReso.SetSprite("Bb_IconB", ManaReso.Load<Sprite>("金币", Folder.UI));
  65. ManaReso.SetActive("Bb_IconB", true);
  66. ManaData.Coin += Coin;
  67. }
  68. else
  69. {
  70. throw new Exception();
  71. }
  72. }
  73. public void SetUI()
  74. {
  75. if (FlowerList.Valid())
  76. {
  77. for (int i = 0; i < FlowerList.Count; i++)
  78. {
  79. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[FlowerList[i]];
  80. if (flowerInfo.Unlock == false)
  81. {
  82. Icon.sprite = flowerInfo.Icon;
  83. Icon.Resize(0.2f, 0.2f);
  84. return;
  85. }
  86. }
  87. }
  88. if (Diamond > 0)
  89. {
  90. Icon.sprite = ManaReso.Load<Sprite>("钻石", Folder.UI);
  91. Lab1.text = Diamond.ToString();
  92. }
  93. else if (Coin > 0)
  94. {
  95. Icon.sprite = ManaReso.Load<Sprite>("金币", Folder.UI);
  96. Lab1.text = Coin.ToString();
  97. }
  98. }
  99. }
  100. public class ManaSign : Regist
  101. {
  102. #region 变量
  103. public static int SignIndex;
  104. public static DateTime SignTime;
  105. public static Dictionary<int, Sign> SignDic = new Dictionary<int, Sign>();
  106. #endregion
  107. public static void Get()
  108. {
  109. SignDic[SignIndex].Get();
  110. ManaData.SignAmt++;
  111. }
  112. public static void Reload()
  113. {
  114. SignTime = DateTime.Parse(Data.GetPlayerString("SignTime"));
  115. SignIndex = Data.GetPlayerInt("SignIndex");
  116. foreach (var kv in SignDic)
  117. {
  118. kv.Value.Mark.SetActive(false);
  119. }
  120. for (int i = 1; i < SignIndex; i++)
  121. {
  122. SignDic[i].Mark.SetActive(true);
  123. }
  124. }
  125. public override void RegistValueB()
  126. {
  127. SignTime = DateTime.Parse(Data.GetPlayerString("SignTime"));
  128. SignIndex = Data.GetPlayerInt("SignIndex");
  129. Transform par = ManaReso.Get("Bb_Grid");
  130. List<XmlAttributeCollection> attributeList = Data.GetSignConfig();
  131. for (int i = 0; i < attributeList.Count; i++)
  132. {
  133. Transform tra = ManaReso.Get<ObjRoot>("SignItem", Folder.UI, false, par, false, ObjType.SignItem);
  134. SignDic.Add(i + 1, new Sign(i + 1, tra, attributeList[i]));
  135. }
  136. for (int i = 1; i < SignIndex; i++)
  137. {
  138. SignDic[i].Mark.SetActive(true);
  139. }
  140. }
  141. }