UI HUGE UPDATE
This commit is contained in:
@@ -58,6 +58,11 @@ public class CharacterCardView : MonoBehaviour, IBeginDragHandler, IDragHandler,
|
||||
/// Documentation text normalized.
|
||||
public void beSelected()
|
||||
{
|
||||
if (!IsCharacterUnlocked(characterID))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isSelected)
|
||||
{
|
||||
isSelected = true;
|
||||
@@ -79,6 +84,7 @@ public class CharacterCardView : MonoBehaviour, IBeginDragHandler, IDragHandler,
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
Debug.Log($"CharacterCardView OnBeginDrag: {gameObject.name}");
|
||||
if (!IsCharacterUnlocked(characterID)) return;
|
||||
if (characterImage == null || characterImage.sprite == null) return;
|
||||
if (rootCanvas == null) rootCanvas = GetComponentInParent<Canvas>();
|
||||
if (rootCanvas == null) return;
|
||||
@@ -147,6 +153,26 @@ public class CharacterCardView : MonoBehaviour, IBeginDragHandler, IDragHandler,
|
||||
dragGhost.transform.localPosition = localPoint;
|
||||
}
|
||||
|
||||
private bool IsCharacterUnlocked(int id)
|
||||
{
|
||||
if (id <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AllyHero_SO[] heroes = Resources.LoadAll<AllyHero_SO>("");
|
||||
for (int i = 0; i < heroes.Length; i++)
|
||||
{
|
||||
AllyHero_SO hero = heroes[i];
|
||||
if (hero != null && hero.ally_heroID == id)
|
||||
{
|
||||
return hero.isUnlocked;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (!enableHoverAnim || isDragging) return;
|
||||
|
||||
@@ -0,0 +1,270 @@
|
||||
using System.Text;
|
||||
using Bansonic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class TeamShareApplyPanel : MonoBehaviour
|
||||
{
|
||||
[Header("Inputs")]
|
||||
[SerializeField] private InputField schemeNameInputField;
|
||||
[SerializeField] private InputField shareCodeInputField;
|
||||
|
||||
[Header("Buttons")]
|
||||
[SerializeField] private Button copyButton;
|
||||
[SerializeField] private Button applyButton;
|
||||
|
||||
[Header("Config")]
|
||||
[SerializeField] private bool autoRefreshShareCode = true;
|
||||
|
||||
private string lockedVisibleSchemeName;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
BindUiEvents();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
RefreshShareCodeDisplay();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
UnbindUiEvents();
|
||||
}
|
||||
|
||||
public void RefreshShareCodeDisplay()
|
||||
{
|
||||
if (!autoRefreshShareCode || shareCodeInputField == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string shareCode;
|
||||
string errorMessage;
|
||||
if (!TeamShareCodec.TryExportCurrentTeam(GetSchemeNameOrDefault(), out shareCode, out errorMessage))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(errorMessage))
|
||||
{
|
||||
gNotice.error.display(errorMessage);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
EnsureLockedVisibleSchemeName();
|
||||
shareCodeInputField.text = ReplaceVisibleSchemeName(shareCode, lockedVisibleSchemeName);
|
||||
}
|
||||
|
||||
public void HandleCopyClicked()
|
||||
{
|
||||
if (shareCodeInputField == null)
|
||||
{
|
||||
gNotice.error.display("\u672a\u914d\u7f6e\u7f16\u961f\u7801\u8f93\u5165\u6846");
|
||||
return;
|
||||
}
|
||||
|
||||
string content = string.IsNullOrWhiteSpace(shareCodeInputField.text) ? string.Empty : shareCodeInputField.text.Trim();
|
||||
if (string.IsNullOrEmpty(content))
|
||||
{
|
||||
RefreshShareCodeDisplay();
|
||||
content = string.IsNullOrWhiteSpace(shareCodeInputField.text) ? string.Empty : shareCodeInputField.text.Trim();
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(content))
|
||||
{
|
||||
gNotice.error.display("\u5f53\u524d\u6ca1\u6709\u53ef\u590d\u5236\u7684\u7f16\u961f\u7801");
|
||||
return;
|
||||
}
|
||||
|
||||
GUIUtility.systemCopyBuffer = content;
|
||||
gNotice.recommendation.display("\u5df2\u590d\u5236\u7f16\u961f\u5206\u4eab\u7801");
|
||||
}
|
||||
|
||||
public void HandleApplyClicked()
|
||||
{
|
||||
if (shareCodeInputField == null)
|
||||
{
|
||||
gNotice.error.display("\u672a\u914d\u7f6e\u7f16\u961f\u7801\u8f93\u5165\u6846");
|
||||
return;
|
||||
}
|
||||
|
||||
string content = string.IsNullOrWhiteSpace(shareCodeInputField.text) ? string.Empty : shareCodeInputField.text.Trim();
|
||||
if (string.IsNullOrEmpty(content))
|
||||
{
|
||||
gNotice.error.display("\u8bf7\u8f93\u5165\u7f16\u961f\u5206\u4eab\u7801");
|
||||
return;
|
||||
}
|
||||
|
||||
TeamShareApplyReport report;
|
||||
string errorMessage;
|
||||
if (!TeamShareCodec.TryApplyToCurrentTeam(content, out report, out errorMessage))
|
||||
{
|
||||
gNotice.error.display(string.IsNullOrWhiteSpace(errorMessage) ? "\u7f16\u961f\u7801\u5e94\u7528\u5931\u8d25" : errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
lockedVisibleSchemeName = ExtractVisibleSchemeName(content);
|
||||
if (schemeNameInputField != null && !string.IsNullOrWhiteSpace(report.schemeName))
|
||||
{
|
||||
schemeNameInputField.text = report.schemeName;
|
||||
}
|
||||
|
||||
RefreshShareCodeDisplay();
|
||||
|
||||
if (report != null && report.messages != null && report.messages.Count > 0)
|
||||
{
|
||||
gNotice.error.display(BuildSkipReasonText(report));
|
||||
return;
|
||||
}
|
||||
|
||||
gNotice.recommendation.display("\u5df2\u5e94\u7528\u7f16\u961f\u5206\u4eab\u7801");
|
||||
}
|
||||
|
||||
private void HandleSchemeNameChanged(string _)
|
||||
{
|
||||
RefreshShareCodeDisplay();
|
||||
}
|
||||
|
||||
private void BindUiEvents()
|
||||
{
|
||||
UnbindUiEvents();
|
||||
|
||||
if (copyButton != null)
|
||||
{
|
||||
copyButton.onClick.AddListener(HandleCopyClicked);
|
||||
}
|
||||
|
||||
if (applyButton != null)
|
||||
{
|
||||
applyButton.onClick.AddListener(HandleApplyClicked);
|
||||
}
|
||||
|
||||
if (schemeNameInputField != null)
|
||||
{
|
||||
schemeNameInputField.onValueChanged.AddListener(HandleSchemeNameChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private void UnbindUiEvents()
|
||||
{
|
||||
if (copyButton != null)
|
||||
{
|
||||
copyButton.onClick.RemoveListener(HandleCopyClicked);
|
||||
}
|
||||
|
||||
if (applyButton != null)
|
||||
{
|
||||
applyButton.onClick.RemoveListener(HandleApplyClicked);
|
||||
}
|
||||
|
||||
if (schemeNameInputField != null)
|
||||
{
|
||||
schemeNameInputField.onValueChanged.RemoveListener(HandleSchemeNameChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private string GetSchemeNameOrDefault()
|
||||
{
|
||||
if (schemeNameInputField == null || string.IsNullOrWhiteSpace(schemeNameInputField.text))
|
||||
{
|
||||
return TeamShareSnapshot.DefaultSchemeName;
|
||||
}
|
||||
|
||||
return schemeNameInputField.text;
|
||||
}
|
||||
|
||||
private void EnsureLockedVisibleSchemeName()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(lockedVisibleSchemeName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (shareCodeInputField != null && !string.IsNullOrWhiteSpace(shareCodeInputField.text))
|
||||
{
|
||||
lockedVisibleSchemeName = ExtractVisibleSchemeName(shareCodeInputField.text);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(lockedVisibleSchemeName))
|
||||
{
|
||||
lockedVisibleSchemeName = GetSchemeNameOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
private static string ReplaceVisibleSchemeName(string shareCode, string visibleSchemeName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(shareCode))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
int splitIndex = FindPrefixSplitIndex(shareCode);
|
||||
if (splitIndex < 0)
|
||||
{
|
||||
return shareCode;
|
||||
}
|
||||
|
||||
string safeVisibleName = string.IsNullOrWhiteSpace(visibleSchemeName) ? TeamShareSnapshot.DefaultSchemeName : visibleSchemeName.Trim();
|
||||
return safeVisibleName + shareCode.Substring(splitIndex);
|
||||
}
|
||||
|
||||
private static string ExtractVisibleSchemeName(string shareCode)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(shareCode))
|
||||
{
|
||||
return TeamShareSnapshot.DefaultSchemeName;
|
||||
}
|
||||
|
||||
int splitIndex = FindPrefixSplitIndex(shareCode);
|
||||
if (splitIndex <= 0)
|
||||
{
|
||||
return TeamShareSnapshot.DefaultSchemeName;
|
||||
}
|
||||
|
||||
return shareCode.Substring(0, splitIndex);
|
||||
}
|
||||
|
||||
private static int FindPrefixSplitIndex(string shareCode)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(shareCode))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int index = shareCode.IndexOf("-T3", System.StringComparison.Ordinal);
|
||||
if (index >= 0)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
index = shareCode.IndexOf("-TS3", System.StringComparison.Ordinal);
|
||||
if (index >= 0)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
index = shareCode.IndexOf("-BT2", System.StringComparison.Ordinal);
|
||||
if (index >= 0)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
index = shareCode.IndexOf("-BT1", System.StringComparison.Ordinal);
|
||||
return index;
|
||||
}
|
||||
|
||||
private static string BuildSkipReasonText(TeamShareApplyReport report)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.Append("\u7f16\u961f\u7801\u5df2\u90e8\u5206\u5e94\u7528\uff0c\u4ee5\u4e0b\u5185\u5bb9\u88ab\u8df3\u8fc7\uff1a");
|
||||
|
||||
for (int i = 0; i < report.messages.Count; i++)
|
||||
{
|
||||
builder.Append('\n');
|
||||
builder.Append(report.messages[i]);
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 509f30be3d4e6d14e8dd0f6a612583ae
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94ebb2cfccd43df4fa08b450637a22f9
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class newTeamSelector : MonoBehaviour
|
||||
{
|
||||
@@ -32,11 +32,17 @@ public class newTeamSelector : MonoBehaviour
|
||||
[Tooltip("Optional override colors used for header images per slot. If not set, prefab's headerImage_colors will be used.")]
|
||||
public Color[] overrideHeaderColors;
|
||||
|
||||
[Tooltip("Per-slot default images used when the slot is empty. Index 0-4 maps to slot 1-5.")]
|
||||
public Sprite[] slotDefaultImage;
|
||||
|
||||
[Tooltip("If true, create slots automatically on Start")]
|
||||
public bool instantiateOnStart = true;
|
||||
[Tooltip("Delay skill list rebuild until after slot enter animation to reduce hitching.")]
|
||||
public float delayedSkillRefreshSeconds = 0.75f;
|
||||
|
||||
[Header("Team Share")]
|
||||
public TeamShareApplyPanel teamShareApplyPanel;
|
||||
|
||||
private readonly List<slots_heroSlots> createdSlots = new List<slots_heroSlots>();
|
||||
private static AllyHero_SO[] cachedHeroes;
|
||||
private static Dictionary<int, AllyHero_SO> cachedHeroesById;
|
||||
@@ -57,6 +63,7 @@ public class newTeamSelector : MonoBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
RefreshTeamShareCodeDisplay();
|
||||
if (instantiateOnStart)
|
||||
CreateSlots();
|
||||
StartCoroutine(LoadSelectedHeroesNextFrame());
|
||||
@@ -172,31 +179,38 @@ public class newTeamSelector : MonoBehaviour
|
||||
|
||||
public void UpdateAndSaveSelectedHeroes()
|
||||
{
|
||||
if (createdSlots.Count > 0) selected_heroSlot01_heroID = createdSlots[0].heroSlot_heroID;
|
||||
if (createdSlots.Count > 1) selected_heroSlot02_heroID = createdSlots[1].heroSlot_heroID;
|
||||
if (createdSlots.Count > 2) selected_heroSlot03_heroID = createdSlots[2].heroSlot_heroID;
|
||||
if (createdSlots.Count > 3) selected_heroSlot04_heroID = createdSlots[3].heroSlot_heroID;
|
||||
if (createdSlots.Count > 4) selected_heroSlot05_heroID = createdSlots[4].heroSlot_heroID;
|
||||
int[] ids = new int[slotCount > 0 ? slotCount : 5];
|
||||
for (int i = 0; i < ids.Length; i++)
|
||||
{
|
||||
ids[i] = i < createdSlots.Count && createdSlots[i] != null ? Mathf.Max(0, createdSlots[i].heroSlot_heroID) : 0;
|
||||
}
|
||||
|
||||
PlayerPrefs.SetInt("selected_heroSlot01_heroID", selected_heroSlot01_heroID);
|
||||
PlayerPrefs.SetInt("selected_heroSlot02_heroID", selected_heroSlot02_heroID);
|
||||
PlayerPrefs.SetInt("selected_heroSlot03_heroID", selected_heroSlot03_heroID);
|
||||
PlayerPrefs.SetInt("selected_heroSlot04_heroID", selected_heroSlot04_heroID);
|
||||
PlayerPrefs.SetInt("selected_heroSlot05_heroID", selected_heroSlot05_heroID);
|
||||
ApplySelectedHeroIdsToFields(ids);
|
||||
SyncCurrentTeamFromIds(ids);
|
||||
SaveSelectedHeroIdsToPlayerPrefs(ids);
|
||||
PlayerPrefs.Save();
|
||||
|
||||
Debug.Log("已保存当前英雄到 PlayerPrefs");
|
||||
RefreshTeamShareCodeDisplay();
|
||||
}
|
||||
|
||||
public void LoadSelectedHeroes()
|
||||
{
|
||||
if (createdSlots.Count == 0) return;
|
||||
|
||||
selected_heroSlot01_heroID = PlayerPrefs.GetInt("selected_heroSlot01_heroID", 0);
|
||||
selected_heroSlot02_heroID = PlayerPrefs.GetInt("selected_heroSlot02_heroID", 0);
|
||||
selected_heroSlot03_heroID = PlayerPrefs.GetInt("selected_heroSlot03_heroID", 0);
|
||||
selected_heroSlot04_heroID = PlayerPrefs.GetInt("selected_heroSlot04_heroID", 0);
|
||||
selected_heroSlot05_heroID = PlayerPrefs.GetInt("selected_heroSlot05_heroID", 0);
|
||||
int[] selectedIds;
|
||||
bool loadedFromCurrentTeam = TryGetCurrentTeamHeroIds(out selectedIds);
|
||||
if (!loadedFromCurrentTeam)
|
||||
{
|
||||
selectedIds = ReadSelectedHeroIdsFromPlayerPrefs();
|
||||
SyncCurrentTeamFromIds(selectedIds);
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveSelectedHeroIdsToPlayerPrefs(selectedIds);
|
||||
}
|
||||
|
||||
ApplySelectedHeroIdsToFields(selectedIds);
|
||||
|
||||
// Set the slots
|
||||
if (createdSlots.Count > 0) createdSlots[0].heroSlot_heroID = selected_heroSlot01_heroID;
|
||||
@@ -205,52 +219,225 @@ public class newTeamSelector : MonoBehaviour
|
||||
if (createdSlots.Count > 3) createdSlots[3].heroSlot_heroID = selected_heroSlot04_heroID;
|
||||
if (createdSlots.Count > 4) createdSlots[4].heroSlot_heroID = selected_heroSlot05_heroID;
|
||||
|
||||
bool changed = false;
|
||||
|
||||
// Update each slot's UI
|
||||
for (int i = 0; i < createdSlots.Count; i++)
|
||||
{
|
||||
var slot = createdSlots[i];
|
||||
if (slot == null)
|
||||
continue;
|
||||
|
||||
if (slot.heroSlot_heroID != 0)
|
||||
{
|
||||
// Find the hero SO
|
||||
AllyHero_SO hero = FindHeroById(slot.heroSlot_heroID);
|
||||
if (hero != null)
|
||||
if (hero != null && hero.isUnlocked)
|
||||
{
|
||||
// Delay expensive skill UI refresh to avoid slot-enter stutters.
|
||||
slot.SetSlot(slot.heroSlot_heroID, hero.ally_heroName, hero.ally_heroPoster, false);
|
||||
slot.RefreshSlotVisualsFromCurrentHero(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.heroSlot_heroID = 0;
|
||||
slot.RefreshSlotVisualsFromCurrentHero(false);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Clear slot logic
|
||||
slot.heroSlot_heroID = 0;
|
||||
if (slot.heroSlot_heroName != null) slot.heroSlot_heroName.text = "未选择";
|
||||
if (slot.heroImage != null)
|
||||
{
|
||||
// revert to default sprite if provided, otherwise keep transparent
|
||||
if (slot.defaultHeroSprite != null)
|
||||
{
|
||||
slot.heroImage.sprite = slot.defaultHeroSprite;
|
||||
slot.heroImage.color = new Color(slot.heroImage.color.r, slot.heroImage.color.g, slot.heroImage.color.b, 1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.heroImage.sprite = null;
|
||||
slot.heroImage.color = new Color(slot.heroImage.color.r, slot.heroImage.color.g, slot.heroImage.color.b, 0f);
|
||||
}
|
||||
}
|
||||
if (slot.heroLevelImage != null)
|
||||
{
|
||||
slot.heroLevelImage.sprite = null;
|
||||
slot.heroLevelImage.color = new Color(1f, 1f, 1f, 0f);
|
||||
}
|
||||
// Update skill list
|
||||
slot.UpdateSkillList(false);
|
||||
slot.RefreshSlotVisualsFromCurrentHero(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
UpdateAndSaveSelectedHeroes();
|
||||
}
|
||||
|
||||
if (refreshSkillsRoutine != null)
|
||||
StopCoroutine(refreshSkillsRoutine);
|
||||
refreshSkillsRoutine = StartCoroutine(RefreshSkillsGradually());
|
||||
StartCoroutine(ForceRefreshSlotNamesNextFrame());
|
||||
RefreshTeamShareCodeDisplay();
|
||||
}
|
||||
|
||||
private IEnumerator ForceRefreshSlotNamesNextFrame()
|
||||
{
|
||||
yield return null;
|
||||
|
||||
for (int i = 0; i < createdSlots.Count; i++)
|
||||
{
|
||||
var slot = createdSlots[i];
|
||||
if (slot == null)
|
||||
continue;
|
||||
|
||||
slot.RefreshSlotVisualsFromCurrentHero(false);
|
||||
}
|
||||
}
|
||||
|
||||
private int[] ReadSelectedHeroIdsFromPlayerPrefs()
|
||||
{
|
||||
int[] ids = new int[Mathf.Max(5, slotCount)];
|
||||
if (ids.Length > 0) ids[0] = Mathf.Max(0, PlayerPrefs.GetInt("selected_heroSlot01_heroID", 0));
|
||||
if (ids.Length > 1) ids[1] = Mathf.Max(0, PlayerPrefs.GetInt("selected_heroSlot02_heroID", 0));
|
||||
if (ids.Length > 2) ids[2] = Mathf.Max(0, PlayerPrefs.GetInt("selected_heroSlot03_heroID", 0));
|
||||
if (ids.Length > 3) ids[3] = Mathf.Max(0, PlayerPrefs.GetInt("selected_heroSlot04_heroID", 0));
|
||||
if (ids.Length > 4) ids[4] = Mathf.Max(0, PlayerPrefs.GetInt("selected_heroSlot05_heroID", 0));
|
||||
return ids;
|
||||
}
|
||||
|
||||
private void SaveSelectedHeroIdsToPlayerPrefs(int[] ids)
|
||||
{
|
||||
PlayerPrefs.SetInt("selected_heroSlot01_heroID", GetIdAt(ids, 0));
|
||||
PlayerPrefs.SetInt("selected_heroSlot02_heroID", GetIdAt(ids, 1));
|
||||
PlayerPrefs.SetInt("selected_heroSlot03_heroID", GetIdAt(ids, 2));
|
||||
PlayerPrefs.SetInt("selected_heroSlot04_heroID", GetIdAt(ids, 3));
|
||||
PlayerPrefs.SetInt("selected_heroSlot05_heroID", GetIdAt(ids, 4));
|
||||
}
|
||||
|
||||
private void ApplySelectedHeroIdsToFields(int[] ids)
|
||||
{
|
||||
selected_heroSlot01_heroID = GetIdAt(ids, 0);
|
||||
selected_heroSlot02_heroID = GetIdAt(ids, 1);
|
||||
selected_heroSlot03_heroID = GetIdAt(ids, 2);
|
||||
selected_heroSlot04_heroID = GetIdAt(ids, 3);
|
||||
selected_heroSlot05_heroID = GetIdAt(ids, 4);
|
||||
}
|
||||
|
||||
private bool TryGetCurrentTeamHeroIds(out int[] ids)
|
||||
{
|
||||
ids = new int[Mathf.Max(5, slotCount)];
|
||||
|
||||
TeamManager teamManager = TeamManager.Instance;
|
||||
if (teamManager == null)
|
||||
return false;
|
||||
|
||||
TeamSetting currentTeam = null;
|
||||
try
|
||||
{
|
||||
currentTeam = teamManager.getCurrentSelectedTeam();
|
||||
}
|
||||
catch
|
||||
{
|
||||
currentTeam = null;
|
||||
}
|
||||
|
||||
if (currentTeam == null || currentTeam.teamIdList == null)
|
||||
return false;
|
||||
|
||||
bool hasAnyHero = false;
|
||||
for (int i = 0; i < ids.Length && i < currentTeam.teamIdList.Count; i++)
|
||||
{
|
||||
CharacterView slot = currentTeam.teamIdList[i];
|
||||
ids[i] = slot != null ? Mathf.Max(0, slot.characterId) : 0;
|
||||
if (ids[i] > 0)
|
||||
hasAnyHero = true;
|
||||
}
|
||||
|
||||
return hasAnyHero;
|
||||
}
|
||||
|
||||
private void SyncCurrentTeamFromIds(int[] ids)
|
||||
{
|
||||
TeamManager teamManager = TeamManager.Instance;
|
||||
if (teamManager == null)
|
||||
return;
|
||||
|
||||
TeamSetting currentTeam = null;
|
||||
try
|
||||
{
|
||||
currentTeam = teamManager.getCurrentSelectedTeam();
|
||||
}
|
||||
catch
|
||||
{
|
||||
currentTeam = null;
|
||||
}
|
||||
|
||||
if (currentTeam == null)
|
||||
{
|
||||
currentTeam = new TeamSetting(new List<CharacterView>(), -1);
|
||||
}
|
||||
|
||||
if (currentTeam.teamIdList == null)
|
||||
{
|
||||
currentTeam.teamIdList = new List<CharacterView>();
|
||||
}
|
||||
|
||||
int targetCount = Mathf.Max(5, ids != null ? ids.Length : 0);
|
||||
while (currentTeam.teamIdList.Count < targetCount)
|
||||
{
|
||||
currentTeam.teamIdList.Add(new CharacterView(0, null));
|
||||
}
|
||||
|
||||
for (int i = 0; i < targetCount; i++)
|
||||
{
|
||||
int heroId = GetIdAt(ids, i);
|
||||
string boundaryLevel = ResolveBoundaryLevel(heroId);
|
||||
|
||||
if (currentTeam.teamIdList[i] == null)
|
||||
{
|
||||
currentTeam.teamIdList[i] = new CharacterView(heroId, boundaryLevel);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentTeam.teamIdList[i].characterId = heroId;
|
||||
currentTeam.teamIdList[i].currentBoundaryLevel = boundaryLevel;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentTeam.LeaderId <= 0 || !ContainsHeroId(currentTeam.teamIdList, currentTeam.LeaderId))
|
||||
{
|
||||
currentTeam.LeaderId = FindFirstHeroId(ids);
|
||||
}
|
||||
|
||||
teamManager.setCurrentSelectedTeam(currentTeam, teamManager.currentSelectedTeam);
|
||||
}
|
||||
|
||||
private static int GetIdAt(int[] ids, int index)
|
||||
{
|
||||
if (ids == null || index < 0 || index >= ids.Length)
|
||||
return 0;
|
||||
|
||||
return Mathf.Max(0, ids[index]);
|
||||
}
|
||||
|
||||
private static bool ContainsHeroId(List<CharacterView> teamIdList, int heroId)
|
||||
{
|
||||
if (teamIdList == null || heroId <= 0)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < teamIdList.Count; i++)
|
||||
{
|
||||
CharacterView view = teamIdList[i];
|
||||
if (view != null && view.characterId == heroId)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int FindFirstHeroId(int[] ids)
|
||||
{
|
||||
if (ids == null)
|
||||
return -1;
|
||||
|
||||
for (int i = 0; i < ids.Length; i++)
|
||||
{
|
||||
if (ids[i] > 0)
|
||||
return ids[i];
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private string ResolveBoundaryLevel(int heroId)
|
||||
{
|
||||
if (heroId <= 0)
|
||||
return null;
|
||||
|
||||
AllyHero_SO hero = FindHeroById(heroId);
|
||||
return hero != null ? GetRatingFromSO(hero) : null;
|
||||
}
|
||||
|
||||
private IEnumerator RefreshSkillsGradually()
|
||||
@@ -273,6 +460,15 @@ public class newTeamSelector : MonoBehaviour
|
||||
}
|
||||
TeamSelectorAnimController.PlaySkillsFlash(null);
|
||||
refreshSkillsRoutine = null;
|
||||
RefreshTeamShareCodeDisplay();
|
||||
}
|
||||
|
||||
public void RefreshTeamShareCodeDisplay()
|
||||
{
|
||||
if (teamShareApplyPanel != null)
|
||||
{
|
||||
teamShareApplyPanel.RefreshShareCodeDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
private AllyHero_SO FindHeroById(int id)
|
||||
@@ -280,6 +476,11 @@ public class newTeamSelector : MonoBehaviour
|
||||
EnsureHeroCache();
|
||||
if (cachedHeroesById != null && cachedHeroesById.TryGetValue(id, out var hero))
|
||||
return hero;
|
||||
|
||||
RebuildHeroCache();
|
||||
if (cachedHeroesById != null && cachedHeroesById.TryGetValue(id, out hero))
|
||||
return hero;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -288,6 +489,12 @@ public class newTeamSelector : MonoBehaviour
|
||||
if (cachedHeroesById != null && cachedHeroesById.Count > 0)
|
||||
return;
|
||||
|
||||
RebuildHeroCache();
|
||||
}
|
||||
|
||||
private static void RebuildHeroCache()
|
||||
{
|
||||
cachedHeroes = Resources.LoadAll<AllyHero_SO>("so/ally");
|
||||
if (cachedHeroes == null || cachedHeroes.Length == 0)
|
||||
cachedHeroes = Resources.LoadAll<AllyHero_SO>("");
|
||||
|
||||
@@ -301,4 +508,33 @@ public class newTeamSelector : MonoBehaviour
|
||||
cachedHeroesById[hero.ally_heroID] = hero;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetRatingFromSO(AllyHero_SO so)
|
||||
{
|
||||
if (so == null || so.levelStats == null || so.levelStats.Count == 0) return "C";
|
||||
|
||||
List<AllyHero_SO.AllyLevelInfo> sorted = new List<AllyHero_SO.AllyLevelInfo>();
|
||||
foreach (var level in so.levelStats)
|
||||
{
|
||||
if (level != null)
|
||||
sorted.Add(level);
|
||||
}
|
||||
|
||||
sorted.Sort((left, right) => left.requiredEXP.CompareTo(right.requiredEXP));
|
||||
|
||||
int currentExp = so.ally_currentEXP;
|
||||
int selectedIndex = 0;
|
||||
for (int i = 0; i < sorted.Count; i++)
|
||||
{
|
||||
if (currentExp >= sorted[i].requiredEXP)
|
||||
selectedIndex = i;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (selectedIndex <= 0) return "C";
|
||||
if (selectedIndex == 1) return "B";
|
||||
if (selectedIndex == 2) return "A";
|
||||
return "S";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,6 +232,11 @@ public class teamSettingPanel : MonoBehaviour
|
||||
List<CharacterView> selectAbleCharacters = teamManager.SelectableCharacterList;
|
||||
foreach (CharacterView c in selectAbleCharacters) //id and level
|
||||
{
|
||||
if (!IsCharacterUnlocked(c != null ? c.characterId : 0))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
GameObject characterObj = Instantiate(teamCharacterPrefab, teamCharacterViewContent.transform);
|
||||
CharacterCardView ccv = characterObj.GetComponent<CharacterCardView>();
|
||||
TeamCharacterDataInfo tcdi = getCharacterViewInfo(c.characterId);
|
||||
@@ -251,6 +256,27 @@ public class teamSettingPanel : MonoBehaviour
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsCharacterUnlocked(int characterID)
|
||||
{
|
||||
if (characterID <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AllyHero_SO[] heroes = Resources.LoadAll<AllyHero_SO>("");
|
||||
for (int i = 0; i < heroes.Length; i++)
|
||||
{
|
||||
AllyHero_SO hero = heroes[i];
|
||||
if (hero != null && hero.ally_heroID == characterID)
|
||||
{
|
||||
return hero.isUnlocked;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool checkExistenceStatus(List<CharacterView> currentTeam,int characterID)
|
||||
{
|
||||
foreach (CharacterView c in currentTeam)
|
||||
|
||||
Reference in New Issue
Block a user