Files
SVSimServer/SVSim.BattleEngine/Engine/Wizard/SelectRandomSkinDialog.cs
gamer147 2d9a6eea4b engine cleanup passes 4-7 + multi-instancing ambient rip
Squashes 146 commits from battle-engine-extraction. Net: 2,045 files changed,
+11,896 / -158,687 lines. Ships engine passes 4-7 (dead-code cull, view-layer
stub, receive-path shrink) plus the Phase-5 AsyncLocal ambient deletion that
turns concurrent battles into a type-system property rather than a scope
contract.

## What landed

**Passes 4-7 (chunks 1-34):** Extended the Phase-4 const-false collapse into a
cascading cull across the skill graph, view layer, and receive-path periphery.
Six mode flags (IsWatchBattle/IsReplayBattle/IsAdmin/IsAdminWatch/IsPuzzleQuest/
IsAINetwork) became `const false`, every guarded block deleted. Field*.cs
subclass ctors + BackGroundBase + ObjectChecker culled to no-ops. Mulligan
family reworked to take a mgr param through IMulliganMgr.InitMulligan.
Emotion/Recovery/Resource clusters null-stubbed. Prediction/OperationSimulator/
skill filters converted from static ambient reads to per-mgr reads via
SkillPrm.ownerCard.SelfBattlePlayer.BattleMgr / ins.BattleMgr / this.BattleMgr.

**Phase-5 ambient rip (chunks 35-47):** Deleted BattleAmbient / BattleAmbient-
Context / TestBattleScope in full. Every per-battle mutable slot now lives on
the mgr instance itself:
  mgr.InstanceIsForecast / InstanceIsRandomDraw / InstanceRecoveryInfo /
  InstanceViewerId / InstanceNetworkAgent / GameMgr
BattleManagerBase.GetIns() returns null unconditionally; the residual static
flags + 3 façades (Certification.ViewerId, Data.BattleRecoveryInfo,
ToolboxGame.RealTimeNetworkAgent) are null-tolerant defaults kept for the
handful of engine-internal readers that still reference their types. Zero
BattleAmbient references anywhere in engine + node + tests.

Added pre-seeded GameMgr ctor overload threaded through the mgr chain
(BattleManagerBase → SingleBattleMgr / NetworkBattleManagerBase → NetworkStandard-
BattleMgr → HeadlessBattleMgr / HeadlessNetworkBattleMgr). Fixtures build a
GameMgr, seed it via HeadlessEngineEnv.SeedCharaIds/SeedNetUser, and pass it
to the mgr's ctor — no ambient reach.

Node side (SVSim.BattleNode/SessionBattleEngine): _ctx replaced with a plain
GameMgr field; 34 `using var _ambient = BattleAmbient.Enter(_ctx)` scope wraps
ripped from every accessor and mutator; EngineGlobalInit.WirePerSessionGameMgr
takes GameMgr as a param and runs from SessionBattleEngine.SetupInternal
BEFORE mgr construction.

Test side: TestBattleScope deleted; 18 fixture [SetUp]s migrated to
`HeadlessEngineEnv.EnsureProcessGlobals()`; MultiInstanceEngineTests rewritten
around per-mgr construction (GetIns() → null is the pinned invariant).

## Regression fixes

- **chunk-48** (MulliganCtrl): chunk-35's `= null` stubs on card lookups broke
  the live receive-driven Deal path (BattlePlayerBase.DrawCard NRE'd downstream
  of NetworkPlayerMulliganCtrl.StartMulliganVfx). Restored the three lookups
  via `_battlePlayer.BattleMgr.GetBattleCardIdx`. Engine tests were satisfied
  by the WireMulliganPhase seam; unit tests exposed the live-path gap.

## Ship state

- SVSim.BattleEngine.Tests: 56/56 pass, 2 skip
- SVSim.UnitTests: 1554/1554 pass (was 1523/31-fail before chunk 48)
- Solution build: 0 source warnings (40 pre-existing NU1902 MessagePack CVEs
  in SVSim.EmulatedEntrypoint, unrelated)
- Sequential PVP smoke: verified live (two back-to-back battles, no regression
  on cleanup/spinup)
- Concurrent PVP smoke: verified live

Adds tools/engine-port/ClosureAnalyzer/ — the Roslyn transitive-type-closure
analyzer needed to make future cascade cleanup safe (per feedback memory
"Engine cleanup needs closure tool" from the 2026-06-28 pass-3 failure).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-07-03 19:18:54 -04:00

269 lines
7.5 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Cute;
using UnityEngine;
namespace Wizard;
public class SelectRandomSkinDialog : MonoBehaviour
{
[SerializeField]
private UIGrid _itemGrid;
[SerializeField]
private GameObject _skinButtonItemOriginal;
[SerializeField]
private UIButton _btnAllOff;
[SerializeField]
private UILabel _labelButton;
[SerializeField]
private UIButton _btnPrevPage;
[SerializeField]
private UIButton _btnNextPage;
[SerializeField]
private BoxCollider _flickCollider;
[SerializeField]
private UIPageIndicator _indicator;
private int _currentPageIndex;
private int _lastPageIndex = 1;
private bool _flickStart;
protected List<string> _loadedResourceList = new List<string>();
private DialogBase _dialog;
private List<int> _usableSkinIdList;
private List<int> _selecteSkinIdList;
private List<SelectRandomSkinButton> _skinButtonList;
private bool IsFirstPage => _currentPageIndex <= 1;
private bool IsLastPage => _currentPageIndex >= _lastPageIndex;
public static DialogBase Create(List<int> usableSkinIdList, List<int> selectedSkinIdList, Action<List<int>> onClickOk)
{
SelectRandomSkinDialog component = (UnityEngine.Object.Instantiate(Resources.Load("UI/layoutParts/Dialog/SelectRandomSkinDialog")) as GameObject).GetComponent<SelectRandomSkinDialog>();
component.CreateDialog(onClickOk);
component.Initialize(usableSkinIdList, selectedSkinIdList);
return component._dialog;
}
private void CreateDialog(Action<List<int>> onClickOk)
{
_dialog = UIManager.GetInstance().CreateDialogClose();
_dialog.SetSize(DialogBase.Size.XL);
_dialog.SetTitleLabel(Data.SystemText.Get("Card_0258"));
_dialog.SetButtonLayout(DialogBase.ButtonLayout.OkBtn);
_dialog.SetButtonDelegate(delegate
{
_selecteSkinIdList.Sort();
onClickOk.Call(_selecteSkinIdList);
});
_dialog.SetObj(base.gameObject);
}
private void Initialize(List<int> usableSkinIdList, List<int> selectedSkinIdList)
{
UIManager.GetInstance().createInSceneCenterLoading();
StartCoroutine(LoadResources(usableSkinIdList, delegate
{
GenerateSkinButtons(usableSkinIdList, selectedSkinIdList);
InitializePage(usableSkinIdList);
ShowPage(1);
UIManager.GetInstance().closeInSceneCenterLoading();
}));
}
private IEnumerator LoadResources(List<int> usableSkinIdList, Action onFinish)
{
List<string> skinButtonPathList = new List<string>();
for (int i = 0; i < usableSkinIdList.Count; i++)
{
string path = usableSkinIdList[i].ToString();
string assetTypePath = Toolbox.ResourcesManager.GetAssetTypePath(path, ResourcesManager.AssetLoadPathType.ClassCharaButton);
skinButtonPathList.Add(assetTypePath);
}
yield return StartCoroutine(Toolbox.ResourcesManager.LoadAssetGroupAsync(skinButtonPathList, null));
_loadedResourceList.AddRange(skinButtonPathList);
onFinish.Call();
}
private void GenerateSkinButtons(List<int> usableSkinIdList, List<int> selectedSkinIdList)
{
_usableSkinIdList = usableSkinIdList;
_selecteSkinIdList = new List<int>(selectedSkinIdList);
_skinButtonList = new List<SelectRandomSkinButton>();
List<int> list = new List<int>();
selectedSkinIdList.Sort();
list.AddRange(selectedSkinIdList);
List<int> list2 = usableSkinIdList.Except(selectedSkinIdList).ToList();
list2.Sort();
list.AddRange(list2);
for (int i = 0; i < list.Count; i++)
{
SelectRandomSkinButton component = NGUITools.AddChild(_itemGrid.gameObject, _skinButtonItemOriginal.gameObject).GetComponent<SelectRandomSkinButton>();
int skinId = list[i];
component.Initialize(skinId, _selecteSkinIdList.Contains(skinId), delegate(int id, bool status)
{
if (status)
{
_selecteSkinIdList.Add(skinId);
}
else
{
_selecteSkinIdList.Remove(skinId);
}
UpdateAllButton();
}, OnDragStart, OnDrag);
_skinButtonList.Add(component);
}
}
private void InitializePage(List<int> usableSkinList)
{
_lastPageIndex = (usableSkinList.Count - 1) / 21 + 1;
_currentPageIndex = 1;
_indicator.Init(_lastPageIndex);
if (_lastPageIndex > 1)
{
_flickCollider.gameObject.SetActive(value: true);
UIEventListener uIEventListener = UIEventListener.Get(_flickCollider.gameObject);
uIEventListener.onDragStart = (UIEventListener.VoidDelegate)Delegate.Combine(uIEventListener.onDragStart, new UIEventListener.VoidDelegate(OnDragStart));
UIEventListener uIEventListener2 = UIEventListener.Get(_flickCollider.gameObject);
uIEventListener2.onDrag = (UIEventListener.VectorDelegate)Delegate.Combine(uIEventListener2.onDrag, new UIEventListener.VectorDelegate(OnDrag));
_btnPrevPage.gameObject.SetActive(value: true);
_btnNextPage.gameObject.SetActive(value: true);
UIEventListener uIEventListener3 = UIEventListener.Get(_btnPrevPage.gameObject);
uIEventListener3.onClick = (UIEventListener.VoidDelegate)Delegate.Combine(uIEventListener3.onClick, (UIEventListener.VoidDelegate)delegate
{
ShowPrevPage();
});
UIEventListener uIEventListener4 = UIEventListener.Get(_btnNextPage.gameObject);
uIEventListener4.onClick = (UIEventListener.VoidDelegate)Delegate.Combine(uIEventListener4.onClick, (UIEventListener.VoidDelegate)delegate
{
ShowNextPage();
});
}
_btnAllOff.onClick.Clear();
_btnAllOff.onClick.Add(new EventDelegate(delegate
{
OnClickAllOffButton();
}));
UpdateAllButton();
}
private void UpdateAllButton()
{
SystemText systemText = Data.SystemText;
if (_selecteSkinIdList.Count > 0)
{
_labelButton.text = systemText.Get("Card_0259");
UIManager.SetObjectToGrey(_dialog.button1.gameObject, b: false);
}
else
{
_labelButton.text = systemText.Get("Card_0260");
UIManager.SetObjectToGrey(_dialog.button1.gameObject, b: true);
}
}
private void OnClickAllOffButton()
{
if (_selecteSkinIdList.Count > 0)
{
_selecteSkinIdList.Clear();
for (int i = 0; i < _skinButtonList.Count; i++)
{
_skinButtonList[i].SetSelectStatus(isSelect: false);
}
}
else
{
_selecteSkinIdList.AddRange(_usableSkinIdList);
for (int j = 0; j < _skinButtonList.Count; j++)
{
_skinButtonList[j].SetSelectStatus(isSelect: true);
}
}
UpdateAllButton();
}
private void ShowPage(int pageIndex)
{
_currentPageIndex = pageIndex;
for (int i = 0; i < _skinButtonList.Count; i++)
{
_skinButtonList[i].gameObject.SetActive(value: false);
}
int num = (_currentPageIndex - 1) * 21;
int num2 = Mathf.Min(num + 21, _skinButtonList.Count);
for (int j = num; j < num2; j++)
{
_skinButtonList[j].gameObject.SetActive(value: true);
}
_itemGrid.Reposition();
_btnPrevPage.gameObject.SetActive(!IsFirstPage);
_btnNextPage.gameObject.SetActive(!IsLastPage);
_indicator.UpdateIndicator(_currentPageIndex);
}
private void ShowPrevPage()
{
if (!IsFirstPage)
{
ShowPage(_currentPageIndex - 1);
}
}
private void ShowNextPage()
{
if (!IsLastPage)
{
ShowPage(_currentPageIndex + 1);
}
}
private void OnDragStart(GameObject obj)
{
_flickStart = true;
}
private void OnDrag(GameObject obj, Vector2 dir)
{
if (_flickStart)
{
if (_lastPageIndex <= 1)
{
_flickStart = false;
}
else if (dir.x >= 70f)
{
_flickStart = false;
ShowPrevPage();
}
else if (dir.x <= -70f)
{
_flickStart = false;
ShowNextPage();
}
}
}
}