zhaoyang 2 năm trước cách đây
mục cha
commit
20611e57e4

+ 1 - 0
GameClient/Assets/Game/HotUpdate/Controller/GameController.cs

@@ -164,6 +164,7 @@ namespace GFGGame
             GetSuitItemController.Clear();
             FriendDataManager.Instance.Clear();
             RedDotController.Instance.Clear();
+            BagDataManager.Instance.Clear();
             GameGlobal.zoneScene.GetComponent<SessionComponent>()?.Disconnect();
             GameGlobal.zoneScene.GetComponent<ServerInfosComponent>()?.ServerInfoList?.Clear();
             GameGlobal.zoneScene.GetComponent<AccountInfoComponent>()?.Clear();

+ 12 - 9
GameClient/Assets/Game/HotUpdate/Data/BagDataManager.cs

@@ -15,6 +15,11 @@ namespace GFGGame
                 return _bagDatas;
             }
         }
+        public void Clear()
+        {
+            _bagDatas.Clear();
+            _bagDataDic.Clear();
+        }
         public void Add(ItemData itemData)
         {
             if (!_bagDataDic.ContainsKey(itemData.id))
@@ -42,15 +47,13 @@ namespace GFGGame
             {
                 ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a.id);
                 ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b.id);
-                if (itemCfgB.subType > itemCfgA.subType)
-                {
-                    return -1;
-                }
-                else if (itemCfgB.rarity > itemCfgA.rarity)
-                {
-                    return -1;
-                }
-                return itemCfgB.id - itemCfgA.id;
+                if (itemCfgA.subType > itemCfgB.subType) return -1;
+                if (itemCfgA.subType < itemCfgB.subType) return 1;
+
+                if (itemCfgA.rarity > itemCfgB.rarity) return -1;
+                if (itemCfgA.rarity < itemCfgB.rarity) return 1;
+
+                return itemCfgA.id - itemCfgB.id;
             });
         }
 

+ 19 - 2
GameClient/Assets/Game/HotUpdate/ServerProxy/ItemProxy.cs

@@ -1,4 +1,5 @@
-using ET;
+using System.Collections.Generic;
+using ET;
 
 namespace GFGGame
 {
@@ -40,7 +41,7 @@ namespace GFGGame
 
         }
 
-        //赠送
+        //设置物品已读
         public static async ETTask<bool> ReqSetItemRead(int itemID)
         {
             S2C_SetItemRead response = null;
@@ -56,5 +57,21 @@ namespace GFGGame
             }
             return false;
         }
+        //使用背包物品
+        public static async ETTask<bool> ReqUseItem(int itemID, int count)
+        {
+            S2C_UseItem response = null;
+            response = (S2C_UseItem)await MessageHelper.SendToServer(new C2S_UseItem() { ItemId = itemID, itemNum = count });
+            if (response != null)
+            {
+                if (response.Error == ErrorCode.ERR_Success)
+                {
+                    List<ItemData> items = ItemUtil.CreateItemDataList(response.GotItemList);
+                    BonusController.TryShowBonusList(items);
+                    return true;
+                }
+            }
+            return false;
+        }
     }
 }

+ 2 - 1
GameClient/Assets/Game/HotUpdate/Views/Bag/BagExchangeView.cs

@@ -115,7 +115,8 @@ namespace GFGGame
         }
         private void OnBtnConfirmClick()
         {
-
+            ItemProxy.ReqUseItem(_itemId, _count).Coroutine();
+            this.Hide();
         }
         private void OnBtnCancleClick()
         {

+ 7 - 19
GameClient/Assets/Game/HotUpdate/Views/Bag/BagView.cs

@@ -47,6 +47,7 @@ namespace GFGGame
             _valueBarController = new ValueBarController(_ui.m_comValueBar);
 
             _ui.m_btnback.onClick.Add(OnBtnBackClick);
+            _ui.m_list.SetVirtual();
             _ui.m_list.itemRenderer = ListItemRender;
             _ui.m_list.onClickItem.Add(OnListItemClick);
 
@@ -62,14 +63,19 @@ namespace GFGGame
         {
             base.OnShown();
             _valueBarController.OnShown();
-
             UpdateList();
         }
 
         protected override void OnHide()
         {
             _valueBarController.OnHide();
+
+            if (_ui.m_list.numItems > 0)
+            {
+                _ui.m_list.ScrollToView(0);
+            }
             _ui.m_list.numItems = 0;
+
             base.OnHide();
         }
         protected override void RemoveEventListener()
@@ -80,14 +86,6 @@ namespace GFGGame
         private void UpdateList()
         {
             _ui.m_list.numItems = BagDataManager.Instance.BagDatas.Count;
-            int index = BagDataManager.Instance.GetItemIndex(_curItemId, _ui.m_list.selectedIndex);
-
-            if (index >= 0)
-            {
-                _ui.m_list.selectedIndex = index;
-                int childIndex = _ui.m_list.ItemIndexToChildIndex(index);
-                GComponent comItem = _ui.m_list.GetChildAt(childIndex).asCom;
-            }
         }
 
         private void ListItemRender(int index, GObject obj)
@@ -98,16 +96,6 @@ namespace GFGGame
             item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
             item.m_txtCount.SetVar("count", itemData.num.ToString()).FlushVars();
             item.target.data = itemCfg;
-            // if (obj.data == null)
-            // {
-            //     ItemView itemView = new ItemView(obj as GComponent);
-            //     obj.data = itemView;
-            //     _listItemViews.Add(itemView);
-            // }
-            // (obj.data as ItemView).SetData(itemData);
-            // (obj.data as ItemView).ShowName = false;
-            // (obj.data as ItemView).ShowHasCount = false;
-            // (obj.data as ItemView).ShowTips = false;
         }
 
         private void OnListItemClick(EventContext context)