ShopItem.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. using System;
  2. using PlayerStatus;
  3. using UnityEngine;
  4. using wf;
  5. public class ShopItem : MonoBehaviour
  6. {
  7. public void Awake()
  8. {
  9. this.name_label_ = UTY.GetChildObject(base.gameObject, "ItemName", false).GetComponent<UILabel>();
  10. this.price_label_ = UTY.GetChildObject(base.gameObject, "Price", false).GetComponent<UILabel>();
  11. this.icon_sprite_ = UTY.GetChildObject(base.gameObject, "ItemIcon", false).GetComponent<UI2DSprite>();
  12. this.icon_button_ = UTY.GetChildObject(base.gameObject, "ItemIcon", false).GetComponent<UIButton>();
  13. this.buy_button_ = UTY.GetChildObject(base.gameObject, "BuyButton", false).GetComponent<UIButton>();
  14. this.frame_ = UTY.GetChildObject(base.gameObject, "ItemIcon/Frame", false);
  15. this.purchased_ = UTY.GetChildObject(base.gameObject, "Purchased", false);
  16. this.impossible_ = UTY.GetChildObject(base.gameObject, "Impossible", false);
  17. }
  18. public void OnDestroy()
  19. {
  20. if (this.icon_sprite_ != null && this.icon_sprite_.sprite2D != null && this.icon_sprite_.sprite2D.texture != null)
  21. {
  22. UnityEngine.Object.DestroyImmediate(this.icon_sprite_.sprite2D.texture);
  23. }
  24. }
  25. public void SetData(Shop.ItemDataBase item_data, ItemInfoWnd info_window, ShopItem.OnClickEvent icon_click_event, ShopItem.OnClickEvent click_event)
  26. {
  27. NDebug.AssertNull(item_data != null);
  28. this.item_data_ = item_data;
  29. this.info_window_ = info_window;
  30. this.icon_click_event_ = icon_click_event;
  31. this.click_event_ = click_event;
  32. this.buy_button_.onClick.Clear();
  33. this.icon_button_.onClick.Clear();
  34. EventDelegate.Add(this.buy_button_.onClick, new EventDelegate.Callback(this.OnClick));
  35. EventDelegate.Add(this.icon_button_.onClick, new EventDelegate.Callback(this.OnIconClick));
  36. UIEventTrigger component = this.icon_button_.GetComponent<UIEventTrigger>();
  37. component.onHoverOver.Clear();
  38. component.onHoverOut.Clear();
  39. EventDelegate.Add(component.onHoverOver, new EventDelegate.Callback(this.OnHoverOver));
  40. EventDelegate.Add(component.onHoverOut, new EventDelegate.Callback(this.OnHoverOut));
  41. this.name_label_.text = this.item_data_.name;
  42. this.price_label_.text = Utility.ConvertMoneyText(this.item_data_.price);
  43. this.LoadIconImage(this.item_data_.icon_file);
  44. this.UpdateItemData();
  45. }
  46. public void UpdateItemData()
  47. {
  48. bool is_have_item = this.item_data_.is_have_item;
  49. if (is_have_item)
  50. {
  51. this.buy_button_.gameObject.SetActive(false);
  52. this.purchased_.SetActive(true);
  53. this.price_label_.color = Color.white;
  54. if (this.impossible_ != null)
  55. {
  56. this.impossible_.SetActive(false);
  57. }
  58. }
  59. else
  60. {
  61. Status status = GameMain.Instance.CharacterMgr.status;
  62. bool flag = 0L <= status.money - (long)this.item_data_.price;
  63. if (this.item_data_.is_enabled_buy_item)
  64. {
  65. this.buy_button_.gameObject.SetActive(true);
  66. this.purchased_.SetActive(false);
  67. if (flag)
  68. {
  69. this.buy_button_.isEnabled = true;
  70. this.price_label_.color = Color.white;
  71. }
  72. else
  73. {
  74. this.buy_button_.isEnabled = false;
  75. this.price_label_.color = Color.red;
  76. }
  77. }
  78. else
  79. {
  80. this.buy_button_.gameObject.SetActive(false);
  81. this.purchased_.SetActive(false);
  82. this.impossible_.SetActive(true);
  83. this.price_label_.color = Color.red;
  84. }
  85. }
  86. }
  87. public void SetFlameVisible(bool value)
  88. {
  89. this.frame_.SetActive(value);
  90. }
  91. public void LoadIconImage(string icon_file_name)
  92. {
  93. if (!GameUty.FileSystem.IsExistentFile(icon_file_name))
  94. {
  95. Debug.LogError("アイコンファイル[" + icon_file_name + "]が見つかりませんでした");
  96. icon_file_name = "icon_none.tex";
  97. }
  98. Texture2D texture2D = ImportCM.CreateTexture(icon_file_name);
  99. Sprite sprite = Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), default(Vector2));
  100. sprite.name = icon_file_name;
  101. if (this.icon_sprite_.sprite2D != null && this.icon_sprite_.sprite2D.texture != null)
  102. {
  103. UnityEngine.Object.DestroyImmediate(this.icon_sprite_.sprite2D.texture);
  104. }
  105. this.icon_sprite_.sprite2D = sprite;
  106. if (texture2D.width < texture2D.height)
  107. {
  108. this.icon_sprite_.SetDimensions(72, 73);
  109. }
  110. else
  111. {
  112. this.icon_sprite_.SetDimensions(texture2D.width, texture2D.height);
  113. }
  114. }
  115. public Shop.ItemDataBase item_data
  116. {
  117. get
  118. {
  119. return this.item_data_;
  120. }
  121. }
  122. private void OnIconClick()
  123. {
  124. if (this.icon_click_event_ != null && this.item_data_.type == Shop.ItemDataBase.Type.Parts)
  125. {
  126. this.icon_click_event_(this);
  127. }
  128. }
  129. private void OnClick()
  130. {
  131. long num = GameMain.Instance.CharacterMgr.status.money - (long)this.item_data_.price;
  132. if (num < 0L)
  133. {
  134. GameMain.Instance.SysDlg.Show("資金が不足しています。", SystemDialog.TYPE.OK, null, null);
  135. return;
  136. }
  137. string f_strMsg = this.item_data_.name + "\nを購入しますか?\n資金 -" + Utility.ConvertMoneyText(this.item_data_.price) + "CR";
  138. GameMain.Instance.SysDlg.Show(f_strMsg, SystemDialog.TYPE.OK_CANCEL, new SystemDialog.OnClick(this.CallOnClickEvent), null);
  139. }
  140. private void CallOnClickEvent()
  141. {
  142. if (this.click_event_ != null)
  143. {
  144. this.click_event_(this);
  145. }
  146. GameMain.Instance.SysDlg.Show(this.item_data_.name + "を購入しました", SystemDialog.TYPE.OK, null, null);
  147. }
  148. private void OnHoverOver()
  149. {
  150. Vector3 position = base.transform.position;
  151. this.info_window_.Open(position, this.icon_sprite_.sprite2D.texture, this.item_data_.name, this.item_data_.detail_text, 0);
  152. Transform transform = UTY.GetChildObject(this.info_window_.gameObject, "Base", false).transform;
  153. transform.position = position;
  154. float y = transform.localPosition.y;
  155. transform.localPosition = this.info_window_.m_vecOffsetPos + new Vector3(-337f, y, 0f);
  156. if (-412f > transform.localPosition.y - 90f)
  157. {
  158. Vector3 vecOffsetPos = this.info_window_.m_vecOffsetPos;
  159. vecOffsetPos.y *= -1f;
  160. transform.localPosition = vecOffsetPos + new Vector3(-337f, y, 0f);
  161. }
  162. }
  163. private void OnHoverOut()
  164. {
  165. this.info_window_.Close();
  166. }
  167. private ItemInfoWnd info_window_;
  168. private UILabel name_label_;
  169. private UILabel price_label_;
  170. private UI2DSprite icon_sprite_;
  171. private UIButton icon_button_;
  172. private UIButton buy_button_;
  173. private GameObject frame_;
  174. private GameObject purchased_;
  175. private GameObject impossible_;
  176. private Shop.ItemDataBase item_data_;
  177. private ShopItem.OnClickEvent icon_click_event_;
  178. private ShopItem.OnClickEvent click_event_;
  179. public delegate void OnClickEvent(ShopItem click);
  180. }