Browse Source

自选礼包完成

何晓捷 2 years ago
parent
commit
e472dad886

+ 1 - 1
FGUIProject/assets/Bag/GiftBoxSelectorUI.xml

@@ -24,7 +24,7 @@
     <group id="n21_v5no" name="n21" xy="43,422" size="875,313"/>
     <image id="n22_v5no" name="n22" src="v5notm3" fileName="images/lm_zhuangshixian_duan.png" xy="73,766" group="n27_v5no"/>
     <text id="n24_v5no" name="txtSelRewardStr" xy="357,783" size="247,44" group="n27_v5no" fontSize="28" color="#915e15" align="center" leading="1" autoSize="none" text="已选奖励:0/8"/>
-    <component id="n30_cu9w" name="n30" src="cu9wtme" fileName="components/BtnSub.xml" xy="348,845" group="n27_v5no"/>
+    <component id="n30_cu9w" name="btnSub" src="cu9wtme" fileName="components/BtnSub.xml" xy="348,845" group="n27_v5no"/>
     <group id="n27_v5no" name="n27" xy="73,766" size="816,161"/>
   </displayList>
 </component>

+ 22 - 0
FGUIProject/assets/Bag/components/BtnShowItemTips.xml

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<component size="172,172" extention="Button">
+  <Button/>
+  <controller name="button" pages="0,up,1,down,2,over,3,selectedOver"/>
+  <displayList>
+    <graph id="n0_cu9w" name="n0" xy="0,0" size="172,172" type="rect" lineSize="0" fillColor="#F0F0F0" touchable="false">
+      <gearDisplay controller="button" pages="0"/>
+      <relation target="" sidePair="width,height"/>
+    </graph>
+    <graph id="n1_cu9w" name="n1" xy="0,0" size="172,172" type="rect" lineSize="0" fillColor="#FAFAFA" touchable="false">
+      <gearDisplay controller="button" pages="2"/>
+      <relation target="" sidePair="width,height"/>
+    </graph>
+    <graph id="n2_cu9w" name="n2" xy="0,0" size="172,172" type="rect" lineSize="0" fillColor="#CCCCCC" touchable="false">
+      <gearDisplay controller="button" pages="1,3"/>
+      <relation target="" sidePair="width,height"/>
+    </graph>
+    <text id="n3_cu9w" name="title" xy="0,0" size="172,172" fontSize="30" autoSize="none" align="center" vAlign="middle" singleLine="true">
+      <relation target="" sidePair="width,height"/>
+    </text>
+  </displayList>
+</component>

+ 1 - 0
FGUIProject/assets/Bag/components/ListSelectorItem.xml

@@ -3,6 +3,7 @@
   <displayList>
     <image id="n0_v5no" name="n0" src="v5notm7" fileName="images/wpk_db_1_da.png" xy="0,1"/>
     <image id="n2_v5no" name="n2" src="v5notmc" fileName="images/db_jiajian_1.png" xy="23,189"/>
+    <text id="n17_cu9w" name="txtSelNum" xy="56,184" size="60,53" fontSize="39" color="#915e15" align="center" autoSize="none" text="0"/>
     <loader id="n11_v5no" name="loaIcon" xy="87,84" pivot="0.5,0.5" anchor="true" size="100,88" fill="scale"/>
     <component id="n12_v5no" name="comItemNumBag" src="v5notmd" fileName="components/ComItemNumBag.xml" xy="8,120" size="155,45"/>
     <component id="n15_cu9w" name="btnReduce" src="cu9wtmf" fileName="components/BtnReduce.xml" xy="-1,188"/>

+ 2 - 1
FGUIProject/assets/Bag/package.xml

@@ -28,6 +28,7 @@
     <component id="cu9wtmf" name="BtnReduce.xml" path="/components/" exported="true"/>
     <component id="cu9wtmg" name="BtnAdd.xml" path="/components/" exported="true"/>
     <component id="cu9wtmj" name="BtnCancel.xml" path="/components/" exported="true"/>
+    <component id="cu9wtmk" name="BtnShowItemTips.xml" path="/components/"/>
   </resources>
-  <publish name="" path="../GameClient/Assets/ResIn/UI/Bag" packageCount="2" genCode="true" extractAlpha="true"/>
+  <publish name="" path="..\GameClient\Assets\ResIn\UI\Bag" packageCount="2" genCode="true" extractAlpha="true"/>
 </packageDescription>

+ 4 - 0
GameClient/Assets/Game/HotUpdate/Data/ItemDataManager.cs

@@ -98,6 +98,10 @@ namespace GFGGame
                     {
                         BagDataManager.Instance.Remove(itemID);
                     }
+                    if (itemCfg.itemType == ConstItemType.GIFT_BAG)
+                    {
+                        BagDataManager.Instance.Remove(itemID);
+                    }
                     if (itemCfg.itemType == ConstItemType.HEAD)
                     {
                         RoleInfoManager.Instance.Remove(itemID);

+ 3 - 0
GameClient/Assets/Game/HotUpdate/FairyGUI/GenCode/Bag/UI_GiftBoxSelectorUI.cs

@@ -14,6 +14,7 @@ namespace UI.Bag
         public GLoader m_loaIcon;
         public GList m_list;
         public GTextField m_txtSelRewardStr;
+        public GButton m_btnSub;
         public const string URL = "ui://2bsz6nelu85qtlv";
         public const string PACKAGE_NAME = "Bag";
         public const string RES_NAME = "GiftBoxSelectorUI";
@@ -68,6 +69,7 @@ namespace UI.Bag
             m_loaIcon = (GLoader)comp.GetChild("loaIcon");
             m_list = (GList)comp.GetChild("list");
             m_txtSelRewardStr = (GTextField)comp.GetChild("txtSelRewardStr");
+            m_btnSub = (GButton)comp.GetChild("btnSub");
         }
         public void Dispose(bool disposeTarget = false)
         {
@@ -78,6 +80,7 @@ namespace UI.Bag
             m_loaIcon = null;
             m_list = null;
             m_txtSelRewardStr = null;
+            m_btnSub = null;
             if(disposeTarget && target != null)
             {
                 target.RemoveFromParent();

+ 3 - 0
GameClient/Assets/Game/HotUpdate/FairyGUI/GenCode/Bag/UI_ListSelectorItem.cs

@@ -7,6 +7,7 @@ namespace UI.Bag
     public partial class UI_ListSelectorItem
     {
         public GComponent target;
+        public GTextField m_txtSelNum;
         public GLoader m_loaIcon;
         public UI_ComItemNumBag m_comItemNumBag;
         public GButton m_btnReduce;
@@ -58,6 +59,7 @@ namespace UI.Bag
 
         private void Init(GComponent comp)
         {
+            m_txtSelNum = (GTextField)comp.GetChild("txtSelNum");
             m_loaIcon = (GLoader)comp.GetChild("loaIcon");
             m_comItemNumBag = (UI_ComItemNumBag)UI_ComItemNumBag.Create(comp.GetChild("comItemNumBag"));
             m_btnReduce = (GButton)comp.GetChild("btnReduce");
@@ -65,6 +67,7 @@ namespace UI.Bag
         }
         public void Dispose(bool disposeTarget = false)
         {
+            m_txtSelNum = null;
             m_loaIcon = null;
             m_comItemNumBag.Dispose();
             m_comItemNumBag = null;

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

@@ -90,5 +90,24 @@ namespace GFGGame
             }
             return false;
         }
+
+        //使用背包物品-自选礼包
+        public static async ETTask<bool> ReqUseGiftBoxSelItem(int itemID, List<GiftBoxSelChildItemProto> giftBoxSelChildItems)
+        {
+            M2C_GiftBoxSelConsumption response = null;
+            response = (M2C_GiftBoxSelConsumption)await MessageHelper.SendToServer(new C2M_GiftBoxSelConsumption()
+                { ItemId = itemID, GiftBoxSelChildItems = giftBoxSelChildItems });
+            if (response != null)
+            {
+                if (response.Error == ErrorCode.ERR_Success)
+                {
+                    List<ItemData> items = ItemUtil.CreateItemDataList(response.GotItemList);
+                    BonusController.TryShowBonusList(items);
+                    return true;
+                }
+            }
+
+            return false;
+        }
     }
 }

+ 135 - 8
GameClient/Assets/Game/HotUpdate/Views/Bag/GiftBoxSelectorView.cs

@@ -12,12 +12,20 @@ namespace GFGGame
     {
         private UI_GiftBoxSelectorUI _ui;
         private int _itemId;
-        private int _count;
+        private int _count; //物品数量
+        private int _selCount; //选择的数量
+        private Dictionary<int, int> _selDic; //选择礼包内的物品<物品id,数量>
 
         public override void Dispose()
         {
             base.Dispose();
 
+            if (_selDic != null)
+            {
+                _selDic.Clear();
+                _selDic = null;
+            }
+
             if (_ui != null)
             {
                 _ui.Dispose();
@@ -35,10 +43,11 @@ namespace GFGGame
             this.viewCom.Center();
             this.modal = true;
 
+            _selDic = new Dictionary<int, int>();
+
             _ui.m_btnCancel.onClick.Add(OnBtnCancelClick);
-            _ui.m_list.SetVirtual();
             _ui.m_list.itemRenderer = ListItemRender;
-            _ui.m_list.onClickItem.Add(OnListSelectorItemClick);
+            _ui.m_btnSub.onClick.Add(OnBtnSubClick);
         }
 
         protected override void AddEventListener()
@@ -52,8 +61,12 @@ namespace GFGGame
             _itemId = (int)this.viewData;
             _count = (int)ItemDataManager.GetItemNum(_itemId);
 
+            _selDic.Clear();
+            _selCount = 0;
+
             UpdateView();
             UpdateList();
+            SetSelAllNum();
         }
 
         protected override void OnHide()
@@ -64,6 +77,9 @@ namespace GFGGame
             }
 
             _ui.m_list.numItems = 0;
+            _selDic.Clear();
+            _selCount = 0;
+
             base.OnHide();
         }
 
@@ -83,7 +99,9 @@ namespace GFGGame
 
         private void UpdateList()
         {
-            _ui.m_list.numItems = _count;
+            ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId);
+            _ui.m_list.numItems = itemCfg.itemsArr.Length;
+            _ui.m_list.visible = true;
         }
 
         private void ListItemRender(int index, GObject obj)
@@ -94,21 +112,130 @@ namespace GFGGame
             int[] itemChildArr = itemCfg.itemsArr[index];
             ItemCfg itemCfgChild = ItemCfgArray.Instance.GetCfg(itemChildArr[0]);
             uiItemChild.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfgChild);
+            uiItemChild.m_loaIcon.onClick.Add(OnListSelectorItemClick);
             uiItemChild.m_comItemNumBag.m_txtNum.text = itemChildArr[1].ToString();
+            uiItemChild.m_txtSelNum.text = "0";
+            uiItemChild.m_btnAdd.onClick.Add(OnChildBtnAddClick);
+            uiItemChild.m_btnReduce.onClick.Add(OnChildBtnReduceClick);
+
             uiItemChild.target.data = itemCfgChild;
+            UI_ListSelectorItem.ProxyEnd();
         }
 
-        private void OnListSelectorItemClick(EventContext context)
+        private void OnChildBtnAddClick(EventContext context)
         {
-            GComponent comItem = (context.data as GComponent);
-            ItemCfg itemCfg = comItem.data as ItemCfg;
+            GObject sender = context.sender as GObject;
+            GObject obj = sender.parent;
+            UI_ListSelectorItem listItem = UI_ListSelectorItem.Proxy(obj);
 
-            //弹出物品详细描述框
+            if (_selCount == _count)
+            {
+                return;
+            }
+
+            if (listItem.m_txtSelNum.text == _count.ToString())
+            {
+                return;
+            }
+
+            ItemCfg itemCfg = obj.data as ItemCfg;
+
+            if (_selDic.TryGetValue(itemCfg.id, out int num))
+            {
+                if (num == _count)
+                {
+                    return;
+                }
+
+                _selCount += 1;
+                _selDic[itemCfg.id] = num + 1;
+                listItem.m_txtSelNum.text = Convert.ToString(Convert.ToInt32(listItem.m_txtSelNum.text) + 1);
+            }
+            else
+            {
+                _selDic.Add(itemCfg.id, 1);
+                _selCount += 1;
+                listItem.m_txtSelNum.text = Convert.ToString(1);
+            }
+
+            SetSelAllNum();
+        }
+
+        private void SetSelAllNum()
+        {
+            _ui.m_txtSelRewardStr.text = $"已选奖励:{_selCount}/{_count}";
+        }
+
+        private void OnChildBtnReduceClick(EventContext context)
+        {
+            GObject sender = context.sender as GObject;
+            GObject obj = sender.parent;
+            UI_ListSelectorItem listItem = UI_ListSelectorItem.Proxy(obj);
+
+            if (_selCount == 0)
+            {
+                return;
+            }
+
+            if (listItem.m_txtSelNum.text == "0")
+            {
+                return;
+            }
+
+
+            ItemCfg itemCfg = obj.data as ItemCfg;
+
+            if (_selDic.TryGetValue(itemCfg.id, out int num))
+            {
+                if (num == 0)
+                {
+                    return;
+                }
+
+                _selCount -= 1;
+                _selDic[itemCfg.id] = num - 1;
+                listItem.m_txtSelNum.text = Convert.ToString(Convert.ToInt32(listItem.m_txtSelNum.text) - 1);
+            }
+            else
+            {
+                _selCount -= 1;
+                _selDic.Add(itemCfg.id, 0);
+                listItem.m_txtSelNum.text = Convert.ToString(0);
+            }
+
+            SetSelAllNum();
+        }
+
+        //弹出物品详细描述框
+        private void OnListSelectorItemClick(EventContext context)
+        {
+            GObject sender = context.sender as GObject;
+            GObject obj = sender.parent;
+            ItemCfg itemCfg = obj.data as ItemCfg;
+            GoodsItemTipsController.ShowItemTips(itemCfg.id);
         }
 
         private void OnBtnCancelClick()
         {
             this.Hide();
         }
+
+        //确认按钮
+        private void OnBtnSubClick()
+        {
+            List<GiftBoxSelChildItemProto> reqItemList = new List<GiftBoxSelChildItemProto>();
+
+            foreach (var itemKv in _selDic)
+            {
+                reqItemList.Add(new GiftBoxSelChildItemProto
+                {
+                    ChildItemId = itemKv.Key,
+                    ChildItemCount = itemKv.Value
+                });
+            }
+
+            ItemProxy.ReqUseGiftBoxSelItem(_itemId, reqItemList).Coroutine();
+            this.Hide();
+        }
     }
 }

BIN
GameClient/Assets/ResIn/UI/Bag/Bag_fui.bytes