using System; using I2.Loc; using PlayerStatus; using UnityEngine; using wf; public class ShopItem : MonoBehaviour { public void Awake() { this.name_label_ = UTY.GetChildObject(base.gameObject, "ItemName", false).GetComponent(); this.price_label_ = UTY.GetChildObject(base.gameObject, "Price", false).GetComponent(); this.icon_sprite_ = UTY.GetChildObject(base.gameObject, "ItemIcon", false).GetComponent(); this.icon_button_ = UTY.GetChildObject(base.gameObject, "ItemIcon", false).GetComponent(); this.buy_button_ = UTY.GetChildObject(base.gameObject, "BuyButton", false).GetComponent(); this.frame_ = UTY.GetChildObject(base.gameObject, "ItemIcon/Frame", false); this.purchased_ = UTY.GetChildObject(base.gameObject, "Purchased", false); this.impossible_ = UTY.GetChildObject(base.gameObject, "Impossible", false); } public void OnDestroy() { if (this.icon_sprite_ != null && this.icon_sprite_.sprite2D != null && this.icon_sprite_.sprite2D.texture != null) { UnityEngine.Object.DestroyImmediate(this.icon_sprite_.sprite2D.texture); } } public void SetData(Shop.ItemDataBase item_data, ItemInfoWnd info_window, ShopItem.OnClickEvent icon_click_event, ShopItem.OnClickEvent click_event) { NDebug.AssertNull(item_data != null); this.item_data_ = item_data; this.info_window_ = info_window; this.icon_click_event_ = icon_click_event; this.click_event_ = click_event; this.buy_button_.onClick.Clear(); this.icon_button_.onClick.Clear(); EventDelegate.Add(this.buy_button_.onClick, new EventDelegate.Callback(this.OnClick)); EventDelegate.Add(this.icon_button_.onClick, new EventDelegate.Callback(this.OnIconClick)); UIEventTrigger component = this.icon_button_.GetComponent(); component.onHoverOver.Clear(); component.onHoverOut.Clear(); EventDelegate.Add(component.onHoverOver, new EventDelegate.Callback(this.OnHoverOver)); EventDelegate.Add(component.onHoverOut, new EventDelegate.Callback(this.OnHoverOut)); this.name_label_.text = this.item_data_.name; Utility.SetLocalizeTerm(this.name_label_, "SceneShop/" + this.item_data_.id + "/名前"); this.price_label_.text = Utility.ConvertMoneyText(this.item_data_.price); this.LoadIconImage(this.item_data_.icon_file); this.UpdateItemData(); } public void UpdateItemData() { bool is_have_item = this.item_data_.is_have_item; if (is_have_item) { this.buy_button_.gameObject.SetActive(false); this.purchased_.SetActive(true); this.price_label_.color = Color.white; if (this.impossible_ != null) { this.impossible_.SetActive(false); } } else { Status status = GameMain.Instance.CharacterMgr.status; bool flag = 0L <= status.money - (long)this.item_data_.price; if (this.item_data_.is_enabled_buy_item) { this.buy_button_.gameObject.SetActive(true); this.purchased_.SetActive(false); if (flag) { this.buy_button_.isEnabled = true; this.price_label_.color = Color.white; } else { this.buy_button_.isEnabled = false; this.price_label_.color = Color.red; } } else { this.buy_button_.gameObject.SetActive(false); this.purchased_.SetActive(false); this.impossible_.SetActive(true); this.price_label_.color = Color.red; } } } public void SetFlameVisible(bool value) { this.frame_.SetActive(value); } public void LoadIconImage(string icon_file_name) { if (!GameUty.FileSystem.IsExistentFile(icon_file_name)) { Debug.LogError("アイコンファイル[" + icon_file_name + "]が見つかりませんでした"); icon_file_name = "icon_none.tex"; } Texture2D texture2D = ImportCM.CreateTexture(icon_file_name); Sprite sprite = Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), default(Vector2)); sprite.name = icon_file_name; if (this.icon_sprite_.sprite2D != null && this.icon_sprite_.sprite2D.texture != null) { UnityEngine.Object.DestroyImmediate(this.icon_sprite_.sprite2D.texture); } this.icon_sprite_.sprite2D = sprite; if (texture2D.width < texture2D.height) { this.icon_sprite_.SetDimensions(72, 73); } else { this.icon_sprite_.SetDimensions(texture2D.width, texture2D.height); } } public Shop.ItemDataBase item_data { get { return this.item_data_; } } private void OnIconClick() { if (this.icon_click_event_ != null && this.item_data_.type == Shop.ItemDataBase.Type.Parts) { this.icon_click_event_(this); } } private void OnClick() { long num = GameMain.Instance.CharacterMgr.status.money - (long)this.item_data_.price; if (num < 0L) { GameMain.Instance.SysDlg.ShowFromLanguageTerm("Dialog/ショップ/資金が不足しています。", null, SystemDialog.TYPE.OK, null, null); return; } string text = Product.SPP ? LocalizationManager.GetTranslation("SceneShop/" + this.item_data_.id + "/名前", true, 0, true, false, null, null) : this.item_data_.name; string[] args = new string[] { text, Utility.ConvertMoneyText(this.item_data_.price) }; GameMain.Instance.SysDlg.ShowFromLanguageTerm("Dialog/ショップ/{0}を購入しますか?資金 -{1}CR", args, SystemDialog.TYPE.OK_CANCEL, new SystemDialog.OnClick(this.CallOnClickEvent), null); } private void CallOnClickEvent() { if (this.click_event_ != null) { this.click_event_(this); } string text = Product.SPP ? LocalizationManager.GetTranslation("SceneShop/" + this.item_data_.id + "/名前", true, 0, true, false, null, null) : this.item_data_.name; GameMain.Instance.SysDlg.ShowFromLanguageTerm("Dialog/ショップ/{0}を購入しました", new string[] { text }, SystemDialog.TYPE.OK, null, null); } private void OnHoverOver() { Vector3 position = base.transform.position; string f_strTitle = this.item_data_.name; string f_strInfo = this.item_data_.detail_text; if (Product.SPP) { f_strTitle = LocalizationManager.GetTranslation("SceneShop/" + this.item_data_.id + "/名前", true, 0, true, false, null, null); f_strInfo = LocalizationManager.GetTranslation("SceneShop/" + this.item_data_.id + "/説明", true, 0, true, false, null, null); } this.info_window_.Open(position, this.icon_sprite_.sprite2D.texture, f_strTitle, f_strInfo, 0); Transform transform = UTY.GetChildObject(this.info_window_.gameObject, "Base", false).transform; transform.position = position; float y = transform.localPosition.y; transform.localPosition = this.info_window_.m_vecOffsetPos + new Vector3(-337f, y, 0f); if (-412f > transform.localPosition.y - 90f) { Vector3 vecOffsetPos = this.info_window_.m_vecOffsetPos; vecOffsetPos.y *= -1f; transform.localPosition = vecOffsetPos + new Vector3(-337f, y, 0f); } } private void OnHoverOut() { this.info_window_.Close(); } private ItemInfoWnd info_window_; private UILabel name_label_; private UILabel price_label_; private UI2DSprite icon_sprite_; private UIButton icon_button_; private UIButton buy_button_; private GameObject frame_; private GameObject purchased_; private GameObject impossible_; private Shop.ItemDataBase item_data_; private ShopItem.OnClickEvent icon_click_event_; private ShopItem.OnClickEvent click_event_; public delegate void OnClickEvent(ShopItem click); }