148 lines
5.0 KiB
C#
148 lines
5.0 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using Ichni.RhythmGame;
|
||
using Ichni.RhythmGame.Beatmap;
|
||
using UnityEngine;
|
||
using UnityEngine.InputSystem;
|
||
|
||
namespace Ichni.Editor
|
||
{
|
||
public class OperationManager
|
||
{
|
||
public List<GameElement> currentSelectedElements { get; private set; }
|
||
|
||
public CopyPasteDeleteModule CopyPasteDeleteModule;
|
||
|
||
public FindingModule FindingModule;
|
||
|
||
public OperationManager()
|
||
{
|
||
currentSelectedElements = new List<GameElement>();
|
||
CopyPasteDeleteModule = new CopyPasteDeleteModule();
|
||
FindingModule = new FindingModule();
|
||
}
|
||
|
||
public void AddSelectElement(GameElement gameElement)
|
||
{
|
||
currentSelectedElements.Add(gameElement);
|
||
|
||
gameElement.connectedTab.isSelected = true;
|
||
if (gameElement.connectedTab.BgImage != null)
|
||
{
|
||
gameElement.connectedTab.BgImage.color = new Color(0f, 0f, 0f, 0.8f);
|
||
}
|
||
}
|
||
|
||
public void RemoveSelectElement(GameElement gameElement)
|
||
{
|
||
currentSelectedElements.Remove(gameElement);
|
||
|
||
gameElement.connectedTab.isSelected = false;
|
||
if (gameElement.connectedTab.BgImage != null)
|
||
{
|
||
gameElement.connectedTab.BgImage.color = new Color(0.5f, 0.5f, 0.5f, 0);
|
||
}
|
||
}
|
||
|
||
public void ClearSelectedElements()
|
||
{
|
||
currentSelectedElements.ForEach(gameElement =>
|
||
{
|
||
gameElement.connectedTab.isSelected = false;
|
||
if (gameElement.connectedTab.BgImage != null)
|
||
{
|
||
gameElement.connectedTab.BgImage.color = new Color(0.5f, 0.5f, 0.5f, 0);
|
||
}
|
||
});
|
||
|
||
currentSelectedElements.Clear();
|
||
}
|
||
}
|
||
|
||
public class FindingModule
|
||
{
|
||
public GameElement FindGameElementByName(string elementName)
|
||
{
|
||
foreach (GameElement element in EditorManager.instance.beatmapContainer.gameElementList)
|
||
{
|
||
if (element.elementName == elementName)
|
||
{
|
||
return element;
|
||
}
|
||
}
|
||
|
||
LogWindow.Log("Element not found: " + elementName, Color.red);
|
||
return null;
|
||
}
|
||
}
|
||
|
||
public class CopyPasteDeleteModule
|
||
{
|
||
public GameElement copiedElement;
|
||
public List<GameElement> pastedElementList;
|
||
|
||
public void CopyElement(GameElement gameElement)
|
||
{
|
||
LogWindow.Log("Copied element: " + gameElement.elementName);
|
||
copiedElement = gameElement;
|
||
}
|
||
|
||
public void PasteElement(GameElement parentElement)
|
||
{
|
||
if (copiedElement == null)
|
||
{
|
||
LogWindow.Log("No element copied.");
|
||
return;
|
||
}
|
||
|
||
LogWindow.Log("Pasted element: " + copiedElement.elementName + " to " + parentElement.elementName);
|
||
pastedElementList = new List<GameElement>();
|
||
AffiliatedPaste(copiedElement, parentElement);
|
||
}
|
||
|
||
public void DeleteElement(GameElement gameElement)
|
||
{
|
||
LogWindow.Log("Deleted element: " + gameElement.elementName + " and all its children.");
|
||
|
||
if (gameElement.parentElement != null)
|
||
{
|
||
gameElement.parentElement.childElementList.Remove(gameElement); //从父物体的子物体列表中移除,避免报null
|
||
gameElement.parentElement.connectedTab.childTabList.Remove(gameElement.connectedTab);
|
||
gameElement.parentElement.connectedTab.SetStatus();
|
||
}
|
||
|
||
gameElement.Delete();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 使用递归的方式复制粘贴物体及其所有子物体
|
||
/// </summary>
|
||
/// <param name="gameElement">将要被粘贴的物体</param>
|
||
/// <param name="parent">(将要)被粘贴物体的父物体</param>
|
||
/// <returns></returns>
|
||
private void AffiliatedPaste(GameElement gameElement, GameElement parent)
|
||
{
|
||
gameElement.SaveBM();
|
||
GameElement pastedElement = (gameElement.matchedBM as GameElement_BM).DuplicateBM(parent);
|
||
pastedElementList.Add(pastedElement);
|
||
|
||
gameElement.submoduleList.ForEach(submodule =>
|
||
{
|
||
Debug.Log(submodule.GetType() + " is pasted.");
|
||
submodule.SaveBM();
|
||
try { (submodule.matchedBM as Submodule_BM).DuplicateBM(pastedElement); }
|
||
catch { Debug.LogWarning("Submodule paste error: " + submodule.GetType()); }
|
||
});
|
||
|
||
if (gameElement.childElementList != null)
|
||
{
|
||
foreach (GameElement Element in gameElement.childElementList.Where(x => !pastedElementList.Contains(x)))
|
||
{
|
||
AffiliatedPaste(Element, pastedElement);
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
} |