|
@@ -0,0 +1,358 @@
|
|
|
+using UI.ClothingShop;
|
|
|
+using UI.CommonGame;
|
|
|
+using FairyGUI;
|
|
|
+using UnityEngine;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System;
|
|
|
+
|
|
|
+namespace GFGGame
|
|
|
+{
|
|
|
+ class GalleryShopTabType
|
|
|
+ {
|
|
|
+ public const int BG = 0;
|
|
|
+ public const int NPC = 1;
|
|
|
+ public const int ITEM = 2;
|
|
|
+ public const int BORDER = 3;
|
|
|
+ public const int EFFECT = 4;
|
|
|
+ }
|
|
|
+ public class GalleryShopView : BaseView
|
|
|
+ {
|
|
|
+
|
|
|
+ private UI_GalleryShopUI _ui;
|
|
|
+ private ValueBarController _valueBarController;
|
|
|
+ private List<ShopCfg> _dataList;
|
|
|
+ private ShopCfg _cfgSelected;
|
|
|
+ private const int MAX_COUNT = 99;
|
|
|
+ private const int INIT_COUNT = 1;
|
|
|
+ private int _scoreType;
|
|
|
+ private int _storeId = 1;
|
|
|
+ private GObject _selectedListItem;
|
|
|
+
|
|
|
+ private int _selectedItemId;//打开界面时选中的物品id
|
|
|
+ private int _selectedType = 0;//打开界面时选中的物品类型
|
|
|
+ private int _selectedItemCount;
|
|
|
+ private int _selectedItemClothingId;
|
|
|
+
|
|
|
+ public override void Dispose()
|
|
|
+ {
|
|
|
+ if (_valueBarController != null)
|
|
|
+ {
|
|
|
+ _valueBarController.Dispose();
|
|
|
+ _valueBarController = null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ _cfgSelected = null;
|
|
|
+
|
|
|
+ if (_ui != null)
|
|
|
+ {
|
|
|
+ _ui.Dispose();
|
|
|
+ _ui = null;
|
|
|
+ }
|
|
|
+ base.Dispose();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnInit()
|
|
|
+ {
|
|
|
+ base.OnInit();
|
|
|
+ packageName = UI_GalleryShopUI.PACKAGE_NAME;
|
|
|
+ _ui = UI_GalleryShopUI.Create();
|
|
|
+ this.viewCom = _ui.target;
|
|
|
+ isfullScreen = true;
|
|
|
+
|
|
|
+ _valueBarController = new ValueBarController(_ui.m_valueBar);
|
|
|
+
|
|
|
+
|
|
|
+ _ui.m_comItemList.m_list.itemRenderer = ListShopItemRender;
|
|
|
+ _ui.m_comItemList.m_list.onClickItem.Add(OnClickListShopItem);
|
|
|
+ _ui.m_comItemList.m_comBtnTab.m_c1.onChanged.Add(OnClickListTypeItem);
|
|
|
+
|
|
|
+ _ui.m_btnBack.onClick.Add(OnClickBtnBack);
|
|
|
+ _ui.m_btnBuy.onClick.Add(OnclickBtnBuy);
|
|
|
+
|
|
|
+ _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hz_bjbj");
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void AddEventListener()
|
|
|
+ {
|
|
|
+ base.AddEventListener();
|
|
|
+ EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateItemChange);
|
|
|
+ EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateSelectedItemInfo);
|
|
|
+ EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateItemChange);
|
|
|
+
|
|
|
+ }
|
|
|
+ protected override void OnShown()
|
|
|
+ {
|
|
|
+ base.OnShown();
|
|
|
+
|
|
|
+ _storeId = ConstStoreId.GALLERY_STORE_ID;
|
|
|
+ _scoreType = 0;
|
|
|
+ _selectedItemId = 0;
|
|
|
+ _selectedType = 0;
|
|
|
+ if (this.viewData != null)
|
|
|
+ {
|
|
|
+ //this.viewData[0]=storeId(商店Id)
|
|
|
+ //this.viewData[1]=_scoreType(服装属性:风花雪月)
|
|
|
+ //this.viewData[2]=_selectedItemId
|
|
|
+ //this.viewData[3]=_selectedItemCount
|
|
|
+ object[] objs = this.viewData as object[];
|
|
|
+ if (objs.Length > 0 && objs[0] != null)
|
|
|
+ {
|
|
|
+ _storeId = (int)objs[0];//从抽奖跳转到商店会区分商店Id
|
|
|
+ }
|
|
|
+ if (objs.Length > 1 && objs[1] != null)
|
|
|
+ {
|
|
|
+ _scoreType = (int)objs[1];//从战斗跳转到商店需要服装突出属性用来服装排序
|
|
|
+ }
|
|
|
+ if (objs.Length > 2 && objs[2] != null)
|
|
|
+ {
|
|
|
+ _selectedItemId = (int)objs[2];//从物品来源面板跳转到商店,需要物品id方便打开界面时做选中处理
|
|
|
+ _selectedItemCount = (int)objs[3];
|
|
|
+ ShopCfg[] dataArray = ClothingShopCfgManager.Instance.GetShopCfgs(_storeId);
|
|
|
+ for (int i = 0; i < dataArray.Length; i++)
|
|
|
+ {
|
|
|
+ if (dataArray[i].itemID == _selectedItemId)
|
|
|
+ {
|
|
|
+ _selectedType = dataArray[i].typeIndex;
|
|
|
+ _selectedItemClothingId = dataArray[i].id;
|
|
|
+ _ui.m_comItemList.m_comBtnTab.m_c1.selectedIndex = _selectedType;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ _ui.m_comItemList.m_comBtnTab.m_c1.selectedIndex = _selectedType;
|
|
|
+ // _ui.m_listType.ScrollToView(_selectedType);
|
|
|
+ UpdateList(false);
|
|
|
+
|
|
|
+ _valueBarController.OnShown();
|
|
|
+
|
|
|
+ if (_selectedItemId > 0 && _selectedItemCount > 0)
|
|
|
+ {
|
|
|
+ ShopDataManager.Instance.BuyItem(_cfgSelected.id, _selectedItemCount, _storeId, _cfgSelected);
|
|
|
+ }
|
|
|
+
|
|
|
+ Timers.inst.AddUpdate(CheckGuide);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnHide()
|
|
|
+ {
|
|
|
+ base.OnHide();
|
|
|
+ _valueBarController.OnHide();
|
|
|
+
|
|
|
+ _selectedItemId = 0;
|
|
|
+ Timers.inst.Remove(CheckGuide);
|
|
|
+
|
|
|
+ }
|
|
|
+ protected override void RemoveEventListener()
|
|
|
+ {
|
|
|
+ base.RemoveEventListener();
|
|
|
+ EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateSelectedItemInfo);
|
|
|
+ EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateItemChange);
|
|
|
+ EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateItemChange);
|
|
|
+
|
|
|
+ }
|
|
|
+ private void OnClickBtnBack()
|
|
|
+ {
|
|
|
+ ViewManager.GoBackFrom(ViewName.CLOTHING_SHOP_VIEW);
|
|
|
+ this.Hide();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnclickBtnBuy()
|
|
|
+ {
|
|
|
+ int count = _selectedItemId > 0 && _cfgSelected.itemID == _selectedItemId ? _selectedItemCount : INIT_COUNT;
|
|
|
+ // BuyItemConteoller.Show(_cfgSelected.itemID, _cfgSelected.costID, INIT_COUNT, _cfgSelected.costNum, count, null, true, false, MAX_COUNT);
|
|
|
+ count = Math.Max(1, count);
|
|
|
+ ShopDataManager.Instance.BuyItem(_cfgSelected.id, count, _storeId, _cfgSelected);
|
|
|
+ }
|
|
|
+ private void UpdateItemChange()
|
|
|
+ {
|
|
|
+ UpdateList(false);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void UpdateList(bool tween)
|
|
|
+ {
|
|
|
+
|
|
|
+ int typeIndex = _ui.m_comItemList.m_comBtnTab.m_c1.selectedIndex;
|
|
|
+ _dataList = ClothingShopCfgManager.Instance.GetList(_storeId, typeIndex, _scoreType);
|
|
|
+ _ui.m_comItemList.m_list.numItems = _dataList.Count;
|
|
|
+
|
|
|
+
|
|
|
+ if (_ui.m_comItemList.m_list.numItems > 0)
|
|
|
+ {
|
|
|
+ ShopCfg clothingShopCfg = ClothingShopCfgManager.Instance.GetShopCfg(_selectedItemClothingId, _storeId);
|
|
|
+ int itemIndex = 0;
|
|
|
+ if (_selectedItemId > 0 && clothingShopCfg != null)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < _dataList.Count; i++)
|
|
|
+ {
|
|
|
+ if (_dataList[i].id == _selectedItemClothingId)
|
|
|
+ {
|
|
|
+ itemIndex = i;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _ui.m_comItemList.m_list.ScrollToView(itemIndex < 0 ? 0 : itemIndex);
|
|
|
+ _ui.m_comItemList.m_list.selectedIndex = itemIndex;
|
|
|
+ }
|
|
|
+ UpdateSelectedItemInfo(_ui.m_comItemList.m_list.GetChildAt(itemIndex) as GComponent, tween);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void OnClickListTypeItem(EventContext context)
|
|
|
+ {
|
|
|
+ UpdateList(true);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void ListShopItemRender(int index, GObject item)
|
|
|
+ {
|
|
|
+ UI_ListGalleryShopItem listItem = UI_ListGalleryShopItem.Proxy(item);
|
|
|
+ ShopCfg cfg = _dataList[index];
|
|
|
+ listItem.target.data = cfg;
|
|
|
+ // listItem.m_grpSelect.visible = false;
|
|
|
+ ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.itemID);
|
|
|
+ listItem.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
|
|
|
+ string itemName = itemCfg.name;
|
|
|
+ listItem.m_txtName.text = itemName;
|
|
|
+ // RarityIconController.UpdateRarityIcon(listItem.m_rarity, cfg.itemID, false);
|
|
|
+ ItemCfg costItemCfg = ItemCfgArray.Instance.GetCfg(cfg.costID);
|
|
|
+ listItem.m_iconPrice.url = "ui://CommonGame/" + costItemCfg.res;
|
|
|
+ listItem.m_imgOwned.visible = ItemDataManager.GetItemNum(cfg.itemID) > 0;
|
|
|
+ // listItem.m_txtPrice.text = ItemDataManager.GetItemNum(cfg.costID) >= cfg.costNum ? StringUtil.GetColorText(cfg.costNum.ToString(), "#DD994A") : StringUtil.GetColorText(cfg.costNum.ToString(), "#F2989B");
|
|
|
+ listItem.m_txtPrice.text = cfg.costNum.ToString();
|
|
|
+ UI_ListGalleryShopItem.ProxyEnd();
|
|
|
+ }
|
|
|
+ private void OnClickListShopItem(EventContext context)
|
|
|
+ {
|
|
|
+ _selectedItemId = 0;
|
|
|
+
|
|
|
+ UpdateSelectedItemInfo(context.data as GComponent, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void UpdateSelectedItemInfo(GComponent listItem, bool tween)
|
|
|
+ {
|
|
|
+ _selectedListItem = listItem;
|
|
|
+
|
|
|
+ ShopCfg cfg = listItem.data as ShopCfg;
|
|
|
+ _cfgSelected = cfg;
|
|
|
+ UpdateRole(tween);
|
|
|
+ UpdateSelectedItemInfo();
|
|
|
+ }
|
|
|
+ private void UpdateRole(bool tween)
|
|
|
+ {
|
|
|
+ ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cfgSelected.itemID);
|
|
|
+ string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType);
|
|
|
+ _ui.m_loaBgRes.visible = false;
|
|
|
+ _ui.m_comRes.m_loaBg.visible = false;
|
|
|
+ _ui.m_comRes.m_c1.selectedIndex = _ui.m_comItemList.m_comBtnTab.m_c1.selectedIndex;
|
|
|
+ switch (_ui.m_comRes.m_c1.selectedIndex)
|
|
|
+ {
|
|
|
+ case GalleryShopTabType.BG:
|
|
|
+ _ui.m_comRes.m_loaBg.url = ResPathUtil.GetDressUpPath(itemCfg.res, ext);
|
|
|
+ // _ui.m_loaBgRes.visible = true;
|
|
|
+ _ui.m_comRes.m_loaBg.visible = true;
|
|
|
+ break;
|
|
|
+ case GalleryShopTabType.NPC:
|
|
|
+ _ui.m_comRes.m_loaNpc.url = ResPathUtil.GetNpcPicFPath(itemCfg.res);
|
|
|
+ break;
|
|
|
+ case GalleryShopTabType.ITEM:
|
|
|
+ ItemTypeCfg typeCfg = ItemTypeCfgArray.Instance.GetCfg(itemCfg.subType);
|
|
|
+ int sortingOrder = typeCfg.defaultLayer;
|
|
|
+
|
|
|
+ string res = itemCfg.res;
|
|
|
+ _ui.m_comRes.m_comItem.m_loaItem0.visible = false;
|
|
|
+ _ui.m_comRes.m_comItem.m_loaItem1.visible = false;
|
|
|
+ _ui.m_comRes.m_comItem.m_loaItem2.visible = false;
|
|
|
+ if (!string.IsNullOrEmpty(itemCfg.resLayer1))
|
|
|
+ {
|
|
|
+ res = itemCfg.resLayer1 == "n" ? res : string.Format("{0}_{1}", res, itemCfg.resLayer1);
|
|
|
+ string resPath = ResPathUtil.GetDressUpPath(res, ext);
|
|
|
+ // Texture2D texture2D = GFGAsset.Load<Texture2D>(resPath);
|
|
|
+ // _ui.m_comRes.m_loaItem0.texture = new NTexture(texture2D); ;
|
|
|
+ _ui.m_comRes.m_comItem.m_loaItem0.url = resPath;
|
|
|
+ float tx, ty;
|
|
|
+ DressUpUtil.LoadSpritePos(resPath, out tx, out ty);
|
|
|
+ _ui.m_comRes.m_comItem.m_loaItem0.SetXY(tx, ty);
|
|
|
+ _ui.m_comRes.m_comItem.m_loaItem0.visible = true;
|
|
|
+ _ui.m_comRes.m_comItem.m_loaItem0.sortingOrder = sortingOrder;
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty(itemCfg.resLayer2))
|
|
|
+ {
|
|
|
+ sortingOrder = typeCfg.specialLayer;
|
|
|
+ res = itemCfg.resLayer2 == "n" ? res : string.Format("{0}_{1}", res, itemCfg.resLayer2);
|
|
|
+ string resPath = ResPathUtil.GetDressUpPath(res, ext);
|
|
|
+ // Texture2D texture2D = GFGAsset.Load<Texture2D>(resPath);
|
|
|
+ // _ui.m_comRes.m_loaItem1.texture = new NTexture(texture2D); ;
|
|
|
+ _ui.m_comRes.m_comItem.m_loaItem1.url = resPath;
|
|
|
+ float tx, ty;
|
|
|
+ DressUpUtil.LoadSpritePos(resPath, out tx, out ty);
|
|
|
+ _ui.m_comRes.m_comItem.m_loaItem1.SetXY(tx, ty);
|
|
|
+ _ui.m_comRes.m_comItem.m_loaItem1.visible = true;
|
|
|
+ _ui.m_comRes.m_comItem.m_loaItem1.sortingOrder = sortingOrder;
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty(itemCfg.resLayer3))
|
|
|
+ {
|
|
|
+ sortingOrder = typeCfg.thirdlLayer;
|
|
|
+ res = itemCfg.resLayer3 == "n" ? res : string.Format("{0}_{1}", res, itemCfg.resLayer3);
|
|
|
+ string resPath = ResPathUtil.GetDressUpPath(res, ext);
|
|
|
+ // Texture2D texture2D = GFGAsset.Load<Texture2D>(res);
|
|
|
+ // _ui.m_comRes.m_loaItem2.texture = new NTexture(texture2D);
|
|
|
+ _ui.m_comRes.m_comItem.m_loaItem2.url = resPath;
|
|
|
+ float tx, ty;
|
|
|
+ DressUpUtil.LoadSpritePos(resPath, out tx, out ty);
|
|
|
+ _ui.m_comRes.m_comItem.m_loaItem2.SetXY(tx, ty);
|
|
|
+ _ui.m_comRes.m_comItem.m_loaItem2.visible = true;
|
|
|
+ _ui.m_comRes.m_comItem.m_loaItem2.sortingOrder = sortingOrder;
|
|
|
+ }
|
|
|
+ _ui.m_comRes.m_comItem.target.SetSize(_ui.m_comRes.m_comItem.m_grpItem.width, _ui.m_comRes.m_comItem.m_grpItem.height);
|
|
|
+ break;
|
|
|
+ case GalleryShopTabType.BORDER:
|
|
|
+ _ui.m_comRes.m_loaBorder.url = ResPathUtil.GetPhotographBorderPath(itemCfg.res);
|
|
|
+ break;
|
|
|
+ case GalleryShopTabType.EFFECT:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ private void UpdateSelectedItemInfo()
|
|
|
+ {
|
|
|
+ ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cfgSelected.itemID);
|
|
|
+ _ui.m_txtName.text = itemCfg.name;
|
|
|
+ _ui.m_txtDesc.text = itemCfg.desc;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CheckGuide(object param)
|
|
|
+ {
|
|
|
+ if (GuideDataManager.IsGuideFinish(ConstGuideId.BUY_CLOTHING) <= 0)
|
|
|
+ {
|
|
|
+ UpdateToCheckGuide(null);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Timers.inst.Remove(CheckGuide);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ protected override void UpdateToCheckGuide(object param)
|
|
|
+ {
|
|
|
+ if (!ViewManager.CheckIsTopView(this.viewCom)) return;
|
|
|
+
|
|
|
+ GuideController.TryGuide(_ui.m_btnBack, ConstGuideId.BUY_CLOTHING, 6, "回到换装。", -1, true, 140);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|