94 lines
2.1 KiB
C#
94 lines
2.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BITKit;
|
|
using BITKit.CommandPattern;
|
|
using BITKit.Mod;
|
|
using BITKit.UX;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace BITFactory.Cutting
|
|
{
|
|
public class UXCuttingTool : MonoBehaviour
|
|
{
|
|
[SerializeField] private UIDocument document;
|
|
|
|
[SerializeReference,SubclassSelector] private ICuttingTool cuttingTool;
|
|
|
|
[UXBindPath("commands-container")]
|
|
private VisualElement _commandsContainer;
|
|
[UXBindPath("export-button")]
|
|
private Button exportButton;
|
|
[UXBindPath("clear-button")]
|
|
private Button clearButton;
|
|
[UXBindPath("undo-button")]
|
|
private Button undoButton;
|
|
|
|
private void Start()
|
|
{
|
|
UXUtils.Inject(this);
|
|
|
|
_commandsContainer.Clear();
|
|
|
|
cuttingTool.OnExecute += OnExecute;
|
|
cuttingTool.OnUndo += OnUndo;
|
|
cuttingTool.OnClear += OnClear;
|
|
cuttingTool.OnRelease += OnRelease;
|
|
|
|
exportButton.clicked += cuttingTool.Release;
|
|
clearButton.clicked += cuttingTool.Clear;
|
|
undoButton.clicked += cuttingTool.Undo;
|
|
}
|
|
|
|
|
|
private static void OnRelease(ICommand[] commands)
|
|
{
|
|
var stringBuilder = new System.Text.StringBuilder();
|
|
foreach (var x in commands.OfType<ICuttingCommand>())
|
|
{
|
|
stringBuilder.AppendLine(x.Name);
|
|
}
|
|
var value = stringBuilder.ToString();
|
|
Alert.Print(new BITKit.UX.Internal.Alert()
|
|
{
|
|
message =ModService.Mods.Length>0 ? "已安装Mod,其他程序正在处理数据" :value.Length>1024 ?"数据过长,请复制到剪贴板查看": value,
|
|
OnConfirm = Copy,
|
|
title = "已命令,按[确定]复制到剪切板"
|
|
});
|
|
return;
|
|
void Copy()
|
|
{
|
|
GUIUtility.systemCopyBuffer = stringBuilder.ToString();
|
|
}
|
|
}
|
|
|
|
private void OnClear(ICommand obj)
|
|
{
|
|
_commandsContainer.Clear();
|
|
}
|
|
|
|
private void OnUndo(ICommand obj)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
private void OnExecute(ICommand obj)
|
|
{
|
|
if (obj is not ICuttingCommand command) return;
|
|
|
|
var button = _commandsContainer.Create<Button>();
|
|
|
|
button.text = command.Name;
|
|
button.clicked += Undo;
|
|
|
|
return;
|
|
|
|
void Undo()
|
|
{
|
|
cuttingTool.Trace(obj);
|
|
}
|
|
}
|
|
}
|
|
}
|