181 lines
7.6 KiB
C#

using CG.Framework;
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/********************************************************************************
*Create By CG
*Function 操作步骤栏控制 顺序拆解显示
*********************************************************************************/
namespace ZXK.GYJQR
{
public class OperationStepBJCJPanel : OperationStepPanel
{
//允许点击的子步骤
private Dictionary<string, List<GameObject>> _stepchildrenBtns = new Dictionary<string, List<GameObject>>();
private void OnEnable()
{
GameManager.Instance._DataBJCJHandler._CurDismountStephandler.OnValueChanged += OnDismountStepChanged;
AddEventListener("ShrinkBtn_N", UIEventType.OnButtonClick, Shrink);
AddEventListener("ExtBtn_N", UIEventType.OnButtonClick, Extend);
}
private void OnDisable()
{
GameManager.Instance._DataBJCJHandler._CurDismountStephandler.OnValueChanged -= OnDismountStepChanged;
}
/// <summary>
/// 实例化数据到流程栏
/// </summary>
/// <param name="partsInfo"></param>
public void InitData(List<BJCJ_SXCJ> partsInfo)
{
string curShowGeo = GameManager.Instance._DataBJCJHandler._ShowPartsName.Value;
if(!_stepchildrenBtns.ContainsKey(curShowGeo))
{
_stepchildrenBtns.Add(curShowGeo, new List<GameObject>());
}
foreach (Transform item in _stepContent)
{
if (!item.gameObject.name.Contains("Prefab"))
item.gameObject.SetActive(false);
}
if (_stepchildrenBtns[curShowGeo].Count==0)
{
List<string[]> parts = new List<string[]>();
for (int i = 0; i < partsInfo.Count; i++)
{
if (i > 0 && partsInfo[i].stepNameChild.Equals(partsInfo[i - 1].stepNameChild))
{//过滤掉子步骤相同的
continue;
}
parts.Add(new string[] { partsInfo[i].id.ToString(), partsInfo[i].stepName, partsInfo[i].stepNameChild });
}
_stepchildrenBtns[curShowGeo] = InitStepSecondMenuDataUI(parts);
for (int i = 0; i < _stepchildrenBtns[curShowGeo].Count; i++)
{
GameObject btn = _stepchildrenBtns[curShowGeo][i];
btn.GetComponent<Button>().onClick.AddListener(() =>
{
if (BJCZSceneCtrl._Instance._isPlaySplitAnm) return;//没有播放完动画禁止切换按钮
foreach (BJCJ_SXCJ item in GameManager.Instance._DataBJCJHandler._SXCJDataArray[curShowGeo])
{
if (item.id == int.Parse(btn.name)&&
ClickAble(item))//只能切换上下两个步骤
{//每次点击的时候,返回的是第一个
GameManager.Instance._DataBJCJHandler._CurDismountStephandler.SetValue(curShowGeo, item);
break;
}
}
});
}
}
else
{
for (int i = 0; i < _stepchildrenBtns[curShowGeo].Count; i++)
{
_stepchildrenBtns[curShowGeo][i].transform.parent.parent.gameObject.SetActive(true);
}
}
}
/// <summary>
/// 收回步骤流程面板
/// </summary>
private void Shrink()
{
//聚焦面板变化
string curShowGeo = GameManager.Instance._DataBJCJHandler._ShowPartsName.Value;
Dictionary<string, BJCJ_SXCJ> stepDic = GameManager.Instance._DataBJCJHandler._CurDismountStephandler.GetValue();
ShrinkPanel(stepDic[curShowGeo].stepNameChild);
}
/// <summary>
/// 伸展步骤流程面板
/// </summary>
private void Extend()
{
Extpanel();
}
/// <summary>
/// 限制只能切换上下两个步骤
/// </summary>
/// <param name="id">点击的按钮ID</param>
private bool ClickAble(BJCJ_SXCJ nextStep)
{
string curShowGeo = GameManager.Instance._DataBJCJHandler._ShowPartsName.Value;
BJCJ_SXCJ curStep = GameManager.Instance._DataBJCJHandler._CurDismountStephandler.GetValue()[curShowGeo];
//string curStepName = curStep.stepNameChild;
if (!curStep.stepName.Equals(nextStep.stepName))
{
return true;
}
else
{
List<BJCJ_SXCJ> sxcjInfos = GameManager.Instance._DataBJCJHandler._SXCJDataArray[curShowGeo];
for (int i = 0; i < sxcjInfos.Count; i++)
{
if (curStep.stepNameChild.Equals(sxcjInfos[i].stepNameChild))
{
if (nextStep.id < curStep.id)
{
string previousStepName = "";
for (int j = i; j >= 0; j--)
{
//第一个不相等的最后一个id就是上一步
if (!sxcjInfos[j].stepNameChild.Equals(curStep.stepNameChild))
{
if (string.IsNullOrEmpty(previousStepName))
{
previousStepName = sxcjInfos[j].stepNameChild;
if (GameManager.Instance._DataBJCJHandler._SXCJDataArray[curShowGeo][0].stepNameChild.Equals(previousStepName))
{//已经返回到最上层
return true;
}
}
if (!sxcjInfos[j].stepNameChild.Equals(previousStepName))
{
if (nextStep.id == (sxcjInfos[j].id + 1)) return true;
break;
}
}
}
}
else if(nextStep.id > curStep.id)
{
for (int k = i; k < sxcjInfos.Count; k++)
{
//第一个不相等的就是下一步
if (!sxcjInfos[k].stepNameChild.Equals(curStep.stepNameChild))
{
if (nextStep.id == sxcjInfos[k].id)
{
return true;
}
break;
}
}
}
break;
}
}
}
return false;
}
private void OnDismountStepChanged(Dictionary<string, BJCJ_SXCJ> obj)
{
string curShowGeo = GameManager.Instance._DataBJCJHandler._ShowPartsName.Value;
ItemChanged(curShowGeo+"_"+obj[curShowGeo].stepName, obj[curShowGeo].id.ToString());
GameObject focusGeo = GetWedage("FocusStep_N");
focusGeo.transform.Find("Stepdetail").GetComponent<Text>().text = obj[curShowGeo].stepNameChild;
}
}
}