Browse Source

自选礼包显示消耗数额 改成输入文本

heixaojie 2 years ago
parent
commit
d09e9da5d8

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

@@ -2,7 +2,7 @@
 <component size="172,241" overflow="hidden">
   <displayList>
     <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" vAlign="middle" autoSize="shrink" text="100"/>
+    <text id="n21_l6ko" name="txtSelNum" xy="56,184" size="60,53" fontSize="39" color="#915e15" align="center" vAlign="middle" autoSize="shrink" text="100" input="true" maxLength="3" keyboardType="4"/>
     <component id="n15_cu9w" name="btnReduce" src="cu9wtmf" fileName="components/BtnReduce.xml" xy="-1,188"/>
     <component id="n16_cu9w" name="btnAdd" src="cu9wtmg" fileName="components/BtnAdd.xml" xy="121,189"/>
     <image id="n0_v5no" name="n0" src="v5notm7" fileName="images/wpk_db_1_da.png" xy="0,1" group="n20_yjmk"/>

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

@@ -7,7 +7,7 @@ namespace UI.Bag
     public partial class UI_ListSelectorItem
     {
         public GComponent target;
-        public GTextField m_txtSelNum;
+        public GTextInput m_txtSelNum;
         public GButton m_btnReduce;
         public GButton m_btnAdd;
         public GLoader m_loaIcon;
@@ -59,7 +59,7 @@ namespace UI.Bag
 
         private void Init(GComponent comp)
         {
-            m_txtSelNum = (GTextField)comp.GetChild("txtSelNum");
+            m_txtSelNum = (GTextInput)comp.GetChild("txtSelNum");
             m_btnReduce = (GButton)comp.GetChild("btnReduce");
             m_btnAdd = (GButton)comp.GetChild("btnAdd");
             m_loaIcon = (GLoader)comp.GetChild("loaIcon");

+ 56 - 0
GameClient/Assets/Game/HotUpdate/Views/Bag/GiftBoxSelectorView.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using ET;
 using FairyGUI;
 using UI.Bag;
@@ -123,6 +124,7 @@ namespace GFGGame
             uiItemChild.m_loaIcon.onClick.Add(OnListSelectorItemClick);
             uiItemChild.m_txtNum.text = itemChildArr[1].ToString();
             uiItemChild.m_txtSelNum.text = "0";
+            uiItemChild.m_txtSelNum.onChanged.Add(OnChangedTxtSelNum);
             uiItemChild.m_btnAdd.onClick.Add(OnBtnAddClick);
             uiItemChild.m_btnReduce.onClick.Add(OnChildBtnReduceClick);
 
@@ -255,6 +257,60 @@ namespace GFGGame
             SetSelAllNum();
         }
 
+        //监控输入
+        private void OnChangedTxtSelNum(EventContext context)
+        {
+            GObject sender = context.sender as GObject;
+            GObject obj = sender.parent;
+            UI_ListSelectorItem listItem = UI_ListSelectorItem.Proxy(obj);
+
+            ItemCfg itemCfg = obj.data as ItemCfg;
+            UpdateSelNumSel(listItem, itemCfg);
+        }
+
+        private void UpdateSelNumSel(UI_ListSelectorItem listItem, ItemCfg itemCfg)
+        {
+            if (string.IsNullOrEmpty(listItem.m_txtSelNum.text))
+            {
+                listItem.m_txtSelNum.text = "0";
+            }
+
+            var txtSelNum = Convert.ToInt32(listItem.m_txtSelNum.text);
+            if (txtSelNum < 0)
+            {
+                if (_selDic.TryGetValue(itemCfg.id, out int numx))
+                {
+                    listItem.m_txtSelNum.text = numx.ToString();
+                }
+
+                return;
+            }
+
+            _selDic.TryGetValue(itemCfg.id, out var snumx);
+            var snum = _selCount - snumx + txtSelNum;
+
+            if (snum > _count)
+            {
+                _selDic.TryGetValue(itemCfg.id, out var numx);
+                listItem.m_txtSelNum.text = numx.ToString();
+
+                return;
+            }
+
+            if (_selDic.TryGetValue(itemCfg.id, out int num))
+            {
+                _selDic[itemCfg.id] = txtSelNum;
+                _selCount = _selDic.Values.Sum();
+            }
+            else
+            {
+                _selDic[itemCfg.id] = txtSelNum;
+                _selCount = _selDic.Values.Sum();
+            }
+
+            SetSelAllNum();
+        }
+
         private void SetSelAllNum()
         {
             _ui.m_txtSelRewardStr.text = $"已选奖励:{_selCount}/{_count}";

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