ShopItem.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. Localize component2 = this.name_label_.GetComponent<Localize>();
  44. if (GameUty.supportMultiLanguage && component2 != null)
  45. {
  46. component2.SetTerm("SceneShop/" + this.item_data_.id + "/名前");
  47. }
  48. this.price_label_.text = Utility.ConvertMoneyText(this.item_data_.price);
  49. this.LoadIconImage(this.item_data_.icon_file);
  50. this.UpdateItemData();
  51. }
  52. public void UpdateItemData()
  53. {
  54. bool is_have_item = this.item_data_.is_have_item;
  55. if (is_have_item)
  56. {
  57. this.buy_button_.gameObject.SetActive(false);
  58. this.purchased_.SetActive(true);
  59. this.price_label_.color = Color.white;
  60. if (this.impossible_ != null)
  61. {
  62. this.impossible_.SetActive(false);
  63. }
  64. }
  65. else
  66. {
  67. Status status = GameMain.Instance.CharacterMgr.status;
  68. bool flag = 0L <= status.money - (long)this.item_data_.price;
  69. if (this.item_data_.is_enabled_buy_item)
  70. {
  71. this.buy_button_.gameObject.SetActive(true);
  72. this.purchased_.SetActive(false);
  73. if (flag)
  74. {
  75. this.buy_button_.isEnabled = true;
  76. this.price_label_.color = Color.white;
  77. }
  78. else
  79. {
  80. this.buy_button_.isEnabled = false;
  81. this.price_label_.color = Color.red;
  82. }
  83. }
  84. else
  85. {
  86. this.buy_button_.gameObject.SetActive(false);
  87. this.purchased_.SetActive(false);
  88. this.impossible_.SetActive(true);
  89. this.price_label_.color = Color.red;
  90. }
  91. }
  92. }
  93. public void SetFlameVisible(bool value)
  94. {
  95. this.frame_.SetActive(value);
  96. }
  97. public void LoadIconImage(string icon_file_name)
  98. {
  99. if (!GameUty.FileSystem.IsExistentFile(icon_file_name))
  100. {
  101. Debug.LogError("アイコンファイル[" + icon_file_name + "]が見つかりませんでした");
  102. icon_file_name = "icon_none.tex";
  103. }
  104. Texture2D texture2D = ImportCM.CreateTexture(icon_file_name);
  105. Sprite sprite = Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), default(Vector2));
  106. sprite.name = icon_file_name;
  107. if (this.icon_sprite_.sprite2D != null && this.icon_sprite_.sprite2D.texture != null)
  108. {
  109. UnityEngine.Object.DestroyImmediate(this.icon_sprite_.sprite2D.texture);
  110. }
  111. this.icon_sprite_.sprite2D = sprite;
  112. if (texture2D.width < texture2D.height)
  113. {
  114. this.icon_sprite_.SetDimensions(72, 73);
  115. }
  116. else
  117. {
  118. this.icon_sprite_.SetDimensions(texture2D.width, texture2D.height);
  119. }
  120. }
  121. public Shop.ItemDataBase item_data
  122. {
  123. get
  124. {
  125. return this.item_data_;
  126. }
  127. }
  128. private void OnIconClick()
  129. {
  130. if (this.icon_click_event_ != null && this.item_data_.type == Shop.ItemDataBase.Type.Parts)
  131. {
  132. this.icon_click_event_(this);
  133. }
  134. }
  135. private void OnClick()
  136. {
  137. long num = GameMain.Instance.CharacterMgr.status.money - (long)this.item_data_.price;
  138. if (num < 0L)
  139. {
  140. GameMain.Instance.SysDlg.ShowFromLanguageTerm("Dialog/ショップ/資金が不足しています。", null, SystemDialog.TYPE.OK, null, null);
  141. return;
  142. }
  143. string text = GameUty.supportMultiLanguage ? LocalizationManager.GetTranslation("SceneShop/" + this.item_data_.id + "/名前", true, 0, true, false, null, null) : this.item_data_.name;
  144. string[] args = new string[]
  145. {
  146. text,
  147. Utility.ConvertMoneyText(this.item_data_.price)
  148. };
  149. GameMain.Instance.SysDlg.ShowFromLanguageTerm("Dialog/ショップ/{0}を購入しますか?資金 -{1}CR", args, SystemDialog.TYPE.OK_CANCEL, new SystemDialog.OnClick(this.CallOnClickEvent), null);
  150. }
  151. private void CallOnClickEvent()
  152. {
  153. if (this.click_event_ != null)
  154. {
  155. this.click_event_(this);
  156. }
  157. string text = GameUty.supportMultiLanguage ? LocalizationManager.GetTranslation("SceneShop/" + this.item_data_.id + "/名前", true, 0, true, false, null, null) : this.item_data_.name;
  158. GameMain.Instance.SysDlg.ShowFromLanguageTerm("Dialog/ショップ/{0}を購入しました", new string[]
  159. {
  160. text
  161. }, SystemDialog.TYPE.OK, null, null);
  162. }
  163. private void OnHoverOver()
  164. {
  165. Vector3 position = base.transform.position;
  166. string f_strTitle = this.item_data_.name;
  167. string f_strInfo = this.item_data_.detail_text;
  168. if (GameUty.supportMultiLanguage)
  169. {
  170. f_strTitle = LocalizationManager.GetTranslation("SceneShop/" + this.item_data_.id + "/名前", true, 0, true, false, null, null);
  171. f_strInfo = LocalizationManager.GetTranslation("SceneShop/" + this.item_data_.id + "/説明", true, 0, true, false, null, null);
  172. }
  173. this.info_window_.Open(position, this.icon_sprite_.sprite2D.texture, f_strTitle, f_strInfo, 0);
  174. Transform transform = UTY.GetChildObject(this.info_window_.gameObject, "Base", false).transform;
  175. transform.position = position;
  176. float y = transform.localPosition.y;
  177. transform.localPosition = this.info_window_.m_vecOffsetPos + new Vector3(-337f, y, 0f);
  178. if (-412f > transform.localPosition.y - 90f)
  179. {
  180. Vector3 vecOffsetPos = this.info_window_.m_vecOffsetPos;
  181. vecOffsetPos.y *= -1f;
  182. transform.localPosition = vecOffsetPos + new Vector3(-337f, y, 0f);
  183. }
  184. }
  185. private void OnHoverOut()
  186. {
  187. this.info_window_.Close();
  188. }
  189. private ItemInfoWnd info_window_;
  190. private UILabel name_label_;
  191. private UILabel price_label_;
  192. private UI2DSprite icon_sprite_;
  193. private UIButton icon_button_;
  194. private UIButton buy_button_;
  195. private GameObject frame_;
  196. private GameObject purchased_;
  197. private GameObject impossible_;
  198. private Shop.ItemDataBase item_data_;
  199. private ShopItem.OnClickEvent icon_click_event_;
  200. private ShopItem.OnClickEvent click_event_;
  201. public delegate void OnClickEvent(ShopItem click);
  202. }