using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace RimWorldAnimationStudio { public class StageCardManager : Singleton { public StageCard stageCardPrefab; public void Initialize() { foreach(AnimationStage stage in Workspace.animationDef.animationStages) { MakeStageCard(stage.stageName); } } public void Reset() { foreach(StageCard stageCard in GetComponentsInChildren()) { Destroy(stageCard.gameObject); } } public StageCard MakeStageCard(string stageName = null) { StageCard stageCard = Instantiate(stageCardPrefab, transform); if (stageName != null) { stageCard.Initialize(stageName); } return stageCard; } public void OnNewStage() { if (AddAnimationStage()) { MakeStageCard("NewStage"); } } public bool AddAnimationStage() { AnimationStage stage = new AnimationStage(); Workspace.Instance.MakeDirty(); return stage.MakeNew(); } public void OnCloneStage() { if (CloneAnimationStage()) { StageCard stageCard = MakeStageCard(Workspace.animationDef.animationStages[Workspace.stageID + 1].stageName); stageCard.transform.SetSiblingIndex(Workspace.stageID + 1); } } public bool CloneAnimationStage() { AnimationStage stage = Workspace.animationDef.animationStages[Workspace.stageID].Copy(); stage.Initialize(); stage.stageName += " (Clone)"; Workspace.animationDef.animationStages.Insert(Workspace.stageID + 1, stage); Workspace.Instance.MakeDirty(); return true; } public bool MoveAnimationStage(int startIndex, int delta) { if (startIndex + delta < 0 || startIndex + delta >= Workspace.animationDef.animationStages.Count) { return false; } AnimationStage stage = Workspace.animationDef.animationStages[startIndex]; Workspace.animationDef.animationStages[startIndex] = Workspace.animationDef.animationStages[startIndex + delta]; Workspace.animationDef.animationStages[startIndex + delta] = stage; Workspace.Instance.MakeDirty(); return true; } public void OnRemoveStage() { if (RemoveAnimationStage()) { Destroy(transform.GetChild(Workspace.stageID).gameObject); } } public bool RemoveAnimationStage() { if (Workspace.animationDef.animationStages.Count == 1) { Debug.LogWarning("Cannot delete animation stage - the animation must contain at least one animation stage."); return false; } Workspace.animationDef.animationStages.RemoveAt(Workspace.stageID); Workspace.stageID = Workspace.stageID >= Workspace.animationDef.animationStages.Count ? Workspace.stageID = Workspace.animationDef.animationStages.Count - 1 : Workspace.stageID; Workspace.Instance.MakeDirty(); return true; } } }