191 lines
6.2 KiB
C#
191 lines
6.2 KiB
C#
using UnityEngine;
|
|
using AibisDream.UI;
|
|
using UnityEngine.UI;
|
|
using System;
|
|
using UnityEngine.Events;
|
|
using AibisDream.Framework;
|
|
|
|
namespace AibisDream.FixSystem
|
|
{
|
|
public class BlockPuzzlePanel : MonoBehaviour, IOperatorPanel
|
|
{
|
|
public UnityEvent OnSubmit => lockButton.onClick;
|
|
public UnityEvent OnPopUp => popUpButton.onClick;
|
|
|
|
[Header("面板UI部分")]
|
|
[SerializeField] private GameObject panelUIRoot;
|
|
|
|
private void Awake()
|
|
{
|
|
EnumEventSystem.Global.Register<ScreenEventEnum, GameObject>(ScreenEventEnum.Selected, OnSelected);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
EnumEventSystem.Global.UnRegister(ScreenEventEnum.Selected);
|
|
}
|
|
|
|
// ------------------------ 屏幕显示 -------------------------
|
|
[Header("屏幕")]
|
|
[SerializeField] private UniversalScreen blockPuzzleScreen;
|
|
|
|
public void SwitchToLogScreen()
|
|
{
|
|
blockPuzzleScreen.gameObject.SetActive(false);
|
|
}
|
|
|
|
public void ShowShapeInScreen(BlockShapeInfo shape)
|
|
{
|
|
EnumEventSystem.Global.Send(ScreenEventEnum.Selected, blockPuzzleScreen.gameObject);
|
|
|
|
blockPuzzleScreen.SetImage("设备缩略图", shape.GetDetailImage());
|
|
|
|
blockPuzzleScreen.SetText("设备名称", shape.shapeName);
|
|
blockPuzzleScreen.SetText("设备描述", shape.shapeDescription);
|
|
|
|
blockPuzzleScreen.SetText("PWR", $"PWR\n{shape.paramValue.power.ToString("+0;-0;+0")}");
|
|
blockPuzzleScreen.SetText("NOISE", $"NOISE\n{shape.paramValue.noise.ToString("+0;-0;+0")}");
|
|
blockPuzzleScreen.SetText("HEAT", $"HEAT\n{shape.paramValue.heat.ToString("+0;-0;+0")}");
|
|
|
|
for (int i = 1; i <= 3; i++)
|
|
{
|
|
if (i <= shape.states.Length)
|
|
{
|
|
blockPuzzleScreen.SetText($"设备状态{i}", shape.states[i - 1]);
|
|
}
|
|
else
|
|
{
|
|
blockPuzzleScreen.SetText($"设备状态{i}", "");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnSelected(GameObject obj)
|
|
{
|
|
blockPuzzleScreen.gameObject.SetActive(obj == blockPuzzleScreen.gameObject);
|
|
}
|
|
|
|
public void ClearShapeInScreen()
|
|
{
|
|
blockPuzzleScreen.SetImage("设备缩略图", null);
|
|
|
|
blockPuzzleScreen.SetText("设备名称", "待选择");
|
|
blockPuzzleScreen.SetText("设备描述", null);
|
|
|
|
blockPuzzleScreen.SetText("PWR", "0");
|
|
blockPuzzleScreen.SetText("NOISE", "0");
|
|
blockPuzzleScreen.SetText("HEAT", "0");
|
|
|
|
for (int i = 1; i <= 3; i++)
|
|
{
|
|
blockPuzzleScreen.SetText($"设备状态{i}", "");
|
|
}
|
|
}
|
|
|
|
// ------------------------ 进度条 -------------------------
|
|
|
|
// [Header("进度条")]
|
|
[SerializeField] private SpriteProgressBar powerProgressBar;
|
|
[SerializeField] private SpriteProgressBar noiseProgressBar;
|
|
[SerializeField] private SpriteProgressBar heatProgressBar;
|
|
|
|
/// <summary>
|
|
/// 设置进度条最大值
|
|
/// </summary>
|
|
/// <param name="paramValue"></param>
|
|
public void SetProgressMaxValue(BlockPuzzleParamValue paramValue)
|
|
{
|
|
powerProgressBar.MaxValue = paramValue.power;
|
|
noiseProgressBar.MaxValue = paramValue.noise;
|
|
heatProgressBar.MaxValue = paramValue.heat;
|
|
}
|
|
|
|
public void OnProgressChanged(ValidateResult validateResult)
|
|
{
|
|
|
|
var paramValue = validateResult.propValue;
|
|
// 更新进度条
|
|
powerProgressBar.CurrentValue = paramValue.power;
|
|
noiseProgressBar.CurrentValue = paramValue.noise;
|
|
heatProgressBar.CurrentValue = paramValue.heat;
|
|
|
|
// TODO 更新通过情况
|
|
|
|
// TODO 更新提示文本
|
|
}
|
|
|
|
public void OnRangeChanged(BlockPuzzleParamValue paramValue)
|
|
{
|
|
// TODO 更新进度条范围
|
|
}
|
|
|
|
// ------------------------ 器件选择 -------------------------
|
|
[Header("器件选择")]
|
|
[SerializeField] private RectTransform _deviceButtonRoot;
|
|
[SerializeField] private GameObject _deviceItemPrefab;
|
|
|
|
private BlockShapeData[] deviceButtonDatas;
|
|
public BlockShapeData[] DeviceButtonDatas { set => deviceButtonDatas = value; }
|
|
|
|
public event Action<BlockShapeInfo> OnDeviceSelected;
|
|
|
|
public void LoadBackupDevices()
|
|
{
|
|
foreach (var data in deviceButtonDatas)
|
|
{
|
|
AddDeviceButton(data.blockShapeInfo);
|
|
}
|
|
}
|
|
|
|
public void OnDeviceRecycle(BlockShape blockShape)
|
|
{
|
|
AddDeviceButton(blockShape.BlockShapeData.blockShapeInfo);
|
|
}
|
|
|
|
private void AddDeviceButton(BlockShapeInfo blockShapeInfo)
|
|
{
|
|
var button = Instantiate(_deviceItemPrefab, _deviceButtonRoot).GetComponent<ShapeCreateButton>();
|
|
|
|
button.SetInfo(blockShapeInfo);
|
|
button.OnClicked.AddListener(() => OnDeviceSelected?.Invoke(blockShapeInfo));
|
|
}
|
|
|
|
public void RemoveDeviceButton(string shapeName)
|
|
{
|
|
var button = _deviceButtonRoot.Find(shapeName).gameObject;
|
|
Destroy(button);
|
|
}
|
|
|
|
// ------------------------ 按钮组 ---------------------------
|
|
|
|
[Header("提交按钮")]
|
|
[SerializeField] private Button lockButton;
|
|
[SerializeField] private Button popUpButton;
|
|
|
|
public Button LockButton => lockButton;
|
|
public Button PopUpButton => popUpButton;
|
|
|
|
public void SetVaildState(ValidateResult validateResult)
|
|
{
|
|
lockButton.GetComponent<BlockSubmitHander>().SetValidState(validateResult.isPass);
|
|
}
|
|
|
|
// ------------------------ 面板收放 -------------------------
|
|
public void Init()
|
|
{
|
|
|
|
}
|
|
|
|
public void Open()
|
|
{
|
|
TimelineCenter.Instance.PlayTimeline("维修面板/石头维修开启");
|
|
}
|
|
|
|
public void Close()
|
|
{
|
|
TimelineCenter.Instance.PlayTimeline("维修面板/石头维修关闭");
|
|
}
|
|
|
|
public FixState TargetState => FixState.BlockPuzzle;
|
|
}
|
|
} |