UI update 02

This commit is contained in:
FloatGaming
2026-06-30 21:21:30 +08:00
parent b2a1e307a4
commit f62f643cfc
1666 changed files with 211081 additions and 22799 deletions
@@ -12,6 +12,7 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
private readonly Dictionary<int, int> currentExpByHeroId = new Dictionary<int, int>();
private readonly Dictionary<int, int> unlockedTierByHeroId = new Dictionary<int, int>();
private readonly Dictionary<int, bool> levelLockByHeroId = new Dictionary<int, bool>();
private readonly Dictionary<int, bool> autoBreakthroughEnabledByHeroId = new Dictionary<int, bool>();
private readonly Dictionary<int, int> deployCountsByHeroId = new Dictionary<int, int>();
private readonly Dictionary<int, int> finishCountsByHeroId = new Dictionary<int, int>();
@@ -153,6 +154,13 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
return autoBreakthroughEnabledByHeroId.TryGetValue(heroId, out value) && value;
}
public bool IsLevelLockEnabled(int heroId)
{
InitializeIfNeeded();
bool value;
return levelLockByHeroId.TryGetValue(heroId, out value) && value;
}
public void SetCurrentExp(AllyHero_SO hero, int value)
{
if (hero == null || hero.ally_heroID <= 0)
@@ -164,6 +172,11 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
int safeValue = Mathf.Max(0, value);
currentExpByHeroId[hero.ally_heroID] = safeValue;
hero.ally_currentEXP = safeValue;
int unlockedTier = GetUnlockedTierIndex(hero.ally_heroID);
bool levelLock = ResolveLevelLockState(hero, safeValue, unlockedTier);
levelLockByHeroId[hero.ally_heroID] = levelLock;
hero.level_lock = levelLock;
SyncLegacySelectedSlotExpKeys(hero.ally_heroID, safeValue);
MarkDirty(hero);
SaveNow();
if (OnHeroGrowthChanged != null)
@@ -183,7 +196,11 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
int safeValue = Mathf.Clamp(value, 0, 3);
unlockedTierByHeroId[hero.ally_heroID] = safeValue;
hero.ally_growthUnlockedTierIndex = safeValue;
hero.ally_currentEXP = GetCurrentExp(hero.ally_heroID);
int currentExp = GetCurrentExp(hero.ally_heroID);
hero.ally_currentEXP = currentExp;
bool levelLock = ResolveLevelLockState(hero, currentExp, safeValue);
levelLockByHeroId[hero.ally_heroID] = levelLock;
hero.level_lock = levelLock;
MarkDirty(hero);
SaveNow();
if (OnHeroGrowthChanged != null)
@@ -292,6 +309,7 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
}
SyncAllMirrorFlags();
SyncAllLegacySelectedSlotExpKeys();
AllyHeroDeployLedgerStorage.TrySave(BuildPayload());
}
@@ -300,6 +318,7 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
InitializeIfNeeded();
currentExpByHeroId.Clear();
unlockedTierByHeroId.Clear();
levelLockByHeroId.Clear();
autoBreakthroughEnabledByHeroId.Clear();
ResetGrowthStateToDefaults();
ClearAllPendingDebtKeys();
@@ -311,6 +330,7 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
{
currentExpByHeroId.Clear();
unlockedTierByHeroId.Clear();
levelLockByHeroId.Clear();
autoBreakthroughEnabledByHeroId.Clear();
deployCountsByHeroId.Clear();
finishCountsByHeroId.Clear();
@@ -341,6 +361,7 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
currentExpByHeroId[entry.heroId] = currentExp;
unlockedTierByHeroId[entry.heroId] = unlockedTier;
levelLockByHeroId[entry.heroId] = entry.levelLock;
autoBreakthroughEnabledByHeroId[entry.heroId] = entry.autoBreakthroughEnabled;
deployCountsByHeroId[entry.heroId] = Mathf.Max(0, entry.deployCount);
finishCountsByHeroId[entry.heroId] = Mathf.Max(0, entry.finishCount);
@@ -356,8 +377,9 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
{
currentExpByHeroId.Clear();
unlockedTierByHeroId.Clear();
levelLockByHeroId.Clear();
autoBreakthroughEnabledByHeroId.Clear();
AllyHero_SO[] heroes = Resources.LoadAll<AllyHero_SO>(string.Empty);
AllyHero_SO[] heroes = RuntimeResourcesCache.LoadAllAllyHeroes();
for (int i = 0; i < heroes.Length; i++)
{
AllyHero_SO hero = heroes[i];
@@ -368,6 +390,7 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
currentExpByHeroId[hero.ally_heroID] = 0;
unlockedTierByHeroId[hero.ally_heroID] = 0;
levelLockByHeroId[hero.ally_heroID] = false;
autoBreakthroughEnabledByHeroId[hero.ally_heroID] = false;
if (hero.ally_currentEXP != 0)
@@ -387,12 +410,18 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
hero.ally_autoBreakthroughEnabled = false;
MarkDirty(hero);
}
if (hero.level_lock)
{
hero.level_lock = false;
MarkDirty(hero);
}
}
}
private void SyncAllMirrorFlags()
{
AllyHero_SO[] heroes = Resources.LoadAll<AllyHero_SO>(string.Empty);
AllyHero_SO[] heroes = RuntimeResourcesCache.LoadAllAllyHeroes();
for (int i = 0; i < heroes.Length; i++)
{
AllyHero_SO hero = heroes[i];
@@ -421,6 +450,12 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
unlockedTierByHeroId[hero.ally_heroID] = unlockedTier;
}
bool levelLock;
if (!levelLockByHeroId.TryGetValue(hero.ally_heroID, out levelLock))
{
levelLock = false;
}
bool autoBreakthroughEnabled;
if (!autoBreakthroughEnabledByHeroId.TryGetValue(hero.ally_heroID, out autoBreakthroughEnabled))
{
@@ -431,6 +466,8 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
NormalizeGrowthState(hero, ref currentExp, ref unlockedTier);
currentExpByHeroId[hero.ally_heroID] = currentExp;
unlockedTierByHeroId[hero.ally_heroID] = unlockedTier;
levelLock = ResolveLevelLockState(hero, currentExp, unlockedTier);
levelLockByHeroId[hero.ally_heroID] = levelLock;
int finishCount;
if (!finishCountsByHeroId.TryGetValue(hero.ally_heroID, out finishCount))
@@ -469,6 +506,12 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
changed = true;
}
if (hero.level_lock != levelLock)
{
hero.level_lock = levelLock;
changed = true;
}
if (hero.ally_battleDeployCount != count)
{
hero.ally_battleDeployCount = count;
@@ -503,7 +546,7 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
private static Dictionary<int, AllyHero_SO> BuildHeroLookup()
{
Dictionary<int, AllyHero_SO> heroById = new Dictionary<int, AllyHero_SO>();
AllyHero_SO[] heroes = Resources.LoadAll<AllyHero_SO>(string.Empty);
AllyHero_SO[] heroes = RuntimeResourcesCache.LoadAllAllyHeroes();
for (int i = 0; i < heroes.Length; i++)
{
AllyHero_SO hero = heroes[i];
@@ -564,9 +607,41 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
unlockedTier = Mathf.Min(unlockedTier, reachableTier);
}
private static bool ResolveLevelLockState(AllyHero_SO hero, int currentExp, int unlockedTier)
{
if (hero == null || hero.levelStats == null || hero.levelStats.Count == 0)
{
return false;
}
List<AllyHero_SO.AllyLevelInfo> levels = new List<AllyHero_SO.AllyLevelInfo>();
for (int i = 0; i < hero.levelStats.Count; i++)
{
if (hero.levelStats[i] != null)
{
levels.Add(hero.levelStats[i]);
}
}
if (levels.Count < 2)
{
return false;
}
levels.Sort((left, right) => left.requiredEXP.CompareTo(right.requiredEXP));
int clampedTier = Mathf.Clamp(unlockedTier, 0, levels.Count - 1);
if (clampedTier >= levels.Count - 1)
{
return false;
}
int currentCap = Mathf.Max(levels[clampedTier].requiredEXP, levels[clampedTier + 1].requiredEXP);
return Mathf.Max(0, currentExp) >= currentCap;
}
private static void ClearAllPendingDebtKeys()
{
AllyHero_SO[] heroes = Resources.LoadAll<AllyHero_SO>(string.Empty);
AllyHero_SO[] heroes = RuntimeResourcesCache.LoadAllAllyHeroes();
for (int i = 0; i < heroes.Length; i++)
{
AllyHero_SO hero = heroes[i];
@@ -581,6 +656,63 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
PlayerPrefs.Save();
}
private static void SyncLegacySelectedSlotExpKeys(int heroId, int expValue)
{
if (heroId <= 0)
{
return;
}
int safeExp = Mathf.Max(0, expValue);
bool changed = false;
for (int slot = 1; slot <= 5; slot++)
{
string heroKey = $"selected_heroSlot0{slot}_heroID";
if (PlayerPrefs.GetInt(heroKey, 0) != heroId)
{
continue;
}
string expKey = $"selected_heroSlot0{slot}_exp";
if (PlayerPrefs.GetInt(expKey, int.MinValue) == safeExp)
{
continue;
}
PlayerPrefs.SetInt(expKey, safeExp);
changed = true;
}
if (changed)
{
PlayerPrefs.Save();
}
}
private void SyncAllLegacySelectedSlotExpKeys()
{
bool changed = false;
for (int slot = 1; slot <= 5; slot++)
{
string heroKey = $"selected_heroSlot0{slot}_heroID";
int heroId = PlayerPrefs.GetInt(heroKey, 0);
string expKey = $"selected_heroSlot0{slot}_exp";
int expValue = heroId > 0 ? GetCurrentExp(heroId) : 0;
if (PlayerPrefs.GetInt(expKey, int.MinValue) == expValue)
{
continue;
}
PlayerPrefs.SetInt(expKey, expValue);
changed = true;
}
if (changed)
{
PlayerPrefs.Save();
}
}
private AllyHeroDeployLedgerPayload BuildPayload()
{
AllyHeroDeployLedgerPayload payload = AllyHeroDeployLedgerStorage.CreateDefaultPayload();
@@ -595,6 +727,11 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
allHeroIds.Add(pair.Key);
}
foreach (KeyValuePair<int, bool> pair in levelLockByHeroId)
{
allHeroIds.Add(pair.Key);
}
foreach (KeyValuePair<int, bool> pair in autoBreakthroughEnabledByHeroId)
{
allHeroIds.Add(pair.Key);
@@ -627,6 +764,7 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
heroId = heroId,
currentExp = Mathf.Max(0, GetCurrentExp(heroId)),
unlockedTierIndex = Mathf.Clamp(GetUnlockedTierIndex(heroId), 0, 3),
levelLock = IsLevelLockEnabled(heroId),
autoBreakthroughEnabled = IsAutoBreakthroughEnabled(heroId),
deployCount = Mathf.Max(0, GetDeployCount(heroId)),
finishCount = Mathf.Max(0, GetFinishCount(heroId)),