ShopItem.cs 7.2 KB

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