From ff032a0d727eee13399e29391e1437bea912337c Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期六, 06 十二月 2025 16:42:46 +0800
Subject: [PATCH] 121 【武将】武将系统 - 生效武将版本,同步属性计算,更改新筛选模式

---
 Main/System/HeroUI/HeroSelectBehaviour.cs |  211 +++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 165 insertions(+), 46 deletions(-)

diff --git a/Main/System/HeroUI/HeroSelectBehaviour.cs b/Main/System/HeroUI/HeroSelectBehaviour.cs
index da85036..61b2213 100644
--- a/Main/System/HeroUI/HeroSelectBehaviour.cs
+++ b/Main/System/HeroUI/HeroSelectBehaviour.cs
@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using Cysharp.Threading.Tasks;
 using UnityEngine;
 using UnityEngine.UI;
 
@@ -10,17 +11,25 @@
     [SerializeField] Button foldBtn;    //鏀惰捣鎸夐挳
     [SerializeField] Transform foldForm;    //鏀惰捣瀹瑰櫒
     [SerializeField] Button unFoldBtn;  //灞曞紑鎸夐挳
-    [SerializeField] GroupButtonEx[] jobsBtn;
-    [SerializeField] GroupButtonEx[] countrysBtn;
-    [SerializeField] GroupButtonExManager jobManager;
-    [SerializeField] GroupButtonExManager countryManager;
+    [SerializeField] Toggle[] jobsBtn;
+    [SerializeField] Toggle[] countrysBtn;
+    [SerializeField] Toggle[] hurtTypeBtn;
+    [SerializeField] Toggle[] specialType6Btn;
+    [SerializeField] Transform specialTypeMoreRect;
+    [SerializeField] ClickScreenOtherSpaceEvent clickScreenOtherSpaceEvent;
+    [SerializeField] Button resetBtn;
 
-    int m_Job = 0;
-    int m_Country = 0;
+    Toggle[] specialTypeMoreBtn;
+
+    int m_Job = 0;  //鑱屼笟 澶氶�夐」鎸変綅瀛樺偍
+    int m_Country = 0;  //鍥藉 澶氶�夐」浣嶆寜瀛樺偍
+    int m_HurtType = 0;  //浼ゅ绫诲瀷 澶氶�夐」浣嶆寜瀛樺偍
+    int m_SpecialType6 = 0;  //6澶ф垬鏂楀睘鎬� 澶氶�夐」浣嶆寜瀛樺偍
+    int m_SpecialTypeMore = 0;  //鐗规畩灞炴�� 澶氶�夐」浣嶆寜瀛樺偍
     int foldState = 0;  //0 鏀惰捣锛�1 灞曞紑
 
     //鐐瑰嚮鎸夐挳闇�閫氱煡鍝嶅簲澶栭儴浜嬩欢
-    private Action<int, int> selectAction;
+    private Action<List<int>> selectAction;
 
 
 
@@ -38,80 +47,190 @@
             RefreshFolState();
         });
 
+        specialTypeMoreBtn = specialTypeMoreRect.GetComponentsInChildren<Toggle>();
+
+        // 鍒濆鍖栫壒娈婂睘鎬ф寜閽殑鏄剧ず鍜屾枃鏈�
+        for (int i = 0; i < specialTypeMoreBtn.Length; i++)
+        {
+            if (i < HeroUIManager.Instance.heroSpecialAttrsForSelect.Count)
+            {
+                int index = HeroUIManager.Instance.heroSpecialAttrsForSelect[i];
+                specialTypeMoreBtn[i].SetActive(true);
+                specialTypeMoreBtn[i].GetComponentInChildren<Text>().text = Language.Get($"HeroSpecialty2_{index}");
+            }
+            else
+            {
+                specialTypeMoreBtn[i].SetActive(false);
+            }
+        }
+
+        // 娣诲姞鎵�鏈塗oggle鐩戝惉鍣�
+        AddAllListeners();
+
+        clickScreenOtherSpaceEvent.AddListener(() =>
+        {
+            if (foldState == 0)
+                return;
+            foldBtn.onClick.Invoke();
+        });
+
+        resetBtn.AddListener(Reset);
+
+    }
+
+    // 绉婚櫎鎵�鏈塗oggle鐩戝惉鍣�
+    void RemoveAllListeners()
+    {
         for (int i = 0; i < jobsBtn.Length; i++)
         {
-            int index = i;
-            jobsBtn[i].AddListener(() =>
+            jobsBtn[i].onValueChanged.RemoveAllListeners();
+        }
+        for (int i = 0; i < countrysBtn.Length; i++)
+        {
+            countrysBtn[i].onValueChanged.RemoveAllListeners();
+        }
+        for (int i = 0; i < hurtTypeBtn.Length; i++)
+        {
+            hurtTypeBtn[i].onValueChanged.RemoveAllListeners();
+        }
+        for (int i = 0; i < specialType6Btn.Length; i++)
+        {
+            specialType6Btn[i].onValueChanged.RemoveAllListeners();
+        }
+        for (int i = 0; i < specialTypeMoreBtn.Length; i++)
+        {
+            specialTypeMoreBtn[i].onValueChanged.RemoveAllListeners();
+        }
+    }
+
+    // 娣诲姞鎵�鏈塗oggle鐩戝惉鍣�
+    void AddAllListeners()
+    {
+        for (int i = 0; i < jobsBtn.Length; i++)
+        {
+            int index = i + 1;
+            jobsBtn[i].onValueChanged.AddListener((bool value) =>
             {
-                m_Job = index;
-                RefreshJobsBtn();
-                selectAction?.Invoke(m_Job, m_Country);
+                m_Job = value ? m_Job | (1 << index) : m_Job & ~(1 << index);
+                selectAction?.Invoke(new List<int>() { m_Job, m_Country, m_HurtType, m_SpecialType6, m_SpecialTypeMore });
             });
         }
 
         for (int i = 0; i < countrysBtn.Length; i++)
         {
-            int index = i;
-            countrysBtn[i].AddListener(() =>
+            int index = i + 1;
+            countrysBtn[i].onValueChanged.AddListener((bool value) =>
             {
-                m_Country = index;
-                RefreshCountryBtn();
-                selectAction?.Invoke(m_Job, m_Country);
+                m_Country = value ? m_Country | (1 << index) : m_Country & ~(1 << index);
+                selectAction?.Invoke(new List<int>() { m_Job, m_Country, m_HurtType, m_SpecialType6, m_SpecialTypeMore });
             });
         }
 
+        for (int i = 0; i < hurtTypeBtn.Length; i++)
+        {
+            int index = i + 1;
+            hurtTypeBtn[i].onValueChanged.AddListener((bool value) =>
+            {
+                m_HurtType = value ? m_HurtType | (1 << index) : m_HurtType & ~(1 << index);
+                selectAction?.Invoke(new List<int>() { m_Job, m_Country, m_HurtType, m_SpecialType6, m_SpecialTypeMore });
+            });
+        }
+
+        for (int i = 0; i < specialType6Btn.Length; i++)
+        {
+            int index = i + 1;
+            specialType6Btn[i].onValueChanged.AddListener((bool value) =>
+            {
+                m_SpecialType6 = value ? m_SpecialType6 | (1 << index) : m_SpecialType6 & ~(1 << index);
+                selectAction?.Invoke(new List<int>() { m_Job, m_Country, m_HurtType, m_SpecialType6, m_SpecialTypeMore });
+            });
+        }
+
+        for (int i = 0; i < specialTypeMoreBtn.Length; i++)
+        {
+            if (i < HeroUIManager.Instance.heroSpecialAttrsForSelect.Count)
+            {
+                int index = HeroUIManager.Instance.heroSpecialAttrsForSelect[i];
+                specialTypeMoreBtn[i].onValueChanged.AddListener((bool value) =>
+                {
+                    m_SpecialTypeMore = value ? m_SpecialTypeMore | (1 << index) : m_SpecialTypeMore & ~(1 << index);
+                    selectAction?.Invoke(new List<int>() { m_Job, m_Country, m_HurtType, m_SpecialType6, m_SpecialTypeMore });
+                });
+            }
+        }
     }
 
     /// <summary>
     /// 鍥藉鑱屼笟绛涢��
     /// </summary>
     /// <param name="state"> 0鏀惰捣锛�1灞曞紑</param>
-    /// <param name="job"></param>
-    /// <param name="country"></param>
     /// <param name="onRefresh"> 鐐瑰嚮鎸夐挳闇�閫氱煡鍝嶅簲澶栭儴浜嬩欢</param>
-    public void Display(int state, int job, int country, Action<int, int> onRefresh)
+    /// 鍥炶皟鍙傛暟锛� 鑱屼笟锛屽浗瀹讹紝浼ゅ绫诲瀷锛�6澶ф垬鏂楀睘鎬э紝鐗规畩灞炴��
+    public void Display(int state, Action<List<int>> onRefresh)
     {
         foldState = state;
-        m_Job = job;
-        m_Country = country;
 
         RefreshFolState();
-        RefreshJobsBtn();
-        RefreshCountryBtn();
         selectAction = onRefresh;
+        Reset();
 
     }
 
 
-    //鍒锋柊鍏ㄩ儴鍒嗙被 
-    void RefreshJobsBtn()
-    {
-        jobManager.SelectButton(jobsBtn[m_Job]);
-    }
-    //鍒锋柊鍏ㄩ儴鍒嗙被
-    void RefreshCountryBtn()
-    {
-        countryManager.SelectButton(countrysBtn[m_Country]);
-    }
+
     //鍒锋柊灞曞紑鏀惰捣鐘舵��
     void RefreshFolState()
     {
         unFoldForm.SetActive(foldState == 1);
         foldForm.SetActive(foldState == 0);
-    }
-    
-
-    private void LateUpdate()
-    {
-        if (foldState == 0)
-            return;
-        if (Input.GetMouseButtonDown(0))
+        if (foldState == 1)
         {
-            if (!RectTransformUtility.RectangleContainsScreenPoint(this.transform as RectTransform, Input.mousePosition, CameraManager.uiCamera))
-            {
-                foldBtn.onClick.Invoke();
-            }
+            UIHelper.ForceRefreshLayout(unFoldForm).Forget();
         }
     }
+
+    public static HeroSelectBehaviour Create(Transform heroSelectBehaviour)
+    {
+        var instanceGO = UIUtility.CreateWidget("HeroSelectBehaviour", "HeroSelectBehaviour");
+        instanceGO.transform.SetParentEx(heroSelectBehaviour, Vector3.zero, Quaternion.identity, Vector3.one);
+        return instanceGO.GetComponent<HeroSelectBehaviour>();
+    }
+
+    void Reset()
+    {
+        // 鏆傛椂绉婚櫎鎵�鏈夌洃鍚櫒閬垮厤閲嶇疆鏃跺娆¤Е鍙�
+        RemoveAllListeners();
+        
+        m_Job = 0;
+        m_Country = 0;
+        m_HurtType = 0;
+        m_SpecialType6 = 0;
+        m_SpecialTypeMore = 0;
+
+        for (int i = 0; i < jobsBtn.Length; i++)
+        {
+            jobsBtn[i].isOn = false;
+        }
+        for (int i = 0; i < countrysBtn.Length; i++)
+        {
+            countrysBtn[i].isOn = false;
+        }
+        for (int i = 0; i < hurtTypeBtn.Length; i++)
+        {
+            hurtTypeBtn[i].isOn = false;
+        }
+        for (int i = 0; i < specialType6Btn.Length; i++)
+        {
+            specialType6Btn[i].isOn = false;
+        }
+        for (int i = 0; i < specialTypeMoreBtn.Length; i++)
+        {
+            specialTypeMoreBtn[i].isOn = false;
+        }
+
+        // 閲嶆柊娣诲姞鐩戝惉鍣�
+        AddAllListeners();
+        selectAction?.Invoke(new List<int>() { m_Job, m_Country, m_HurtType, m_SpecialType6, m_SpecialTypeMore });
+    }
 }
 

--
Gitblit v1.8.0