294 lines
11 KiB
C#
294 lines
11 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Drawing;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class UI_BaseTicket : BasePanel
|
||
{
|
||
[Header("工作票")]
|
||
public WorkTicketType workTicketType = WorkTicketType.无;
|
||
public string triggerName;
|
||
public RectTransform workTickeContent; // 注意事项生成容器
|
||
public RectTransform workTickeRequstContent; // 注意事项选择结果容器
|
||
public WorkingLineNameOrEquipmentDualName itemUIPrefab; // 背包中显示物品的UI预制体
|
||
public RectTransform allContent; // 总父物体
|
||
public RectTransform backpack; // 工作任务的父物体
|
||
public RectTransform terminalPart;//结束部分
|
||
public RectTransform leftItemPrefab; //
|
||
public UI_MatterItem matterItemPrefab; //
|
||
public Toggle allToggle; //全选按钮// 总父物体
|
||
public char missionSplitChar = ';'; // 任务分割符
|
||
protected List<UI_MatterItem> miTemp = new List<UI_MatterItem>();
|
||
[HideInInspector]
|
||
public List<GameObject> highlightTipList = new List<GameObject>();
|
||
|
||
public override void ShowMe()
|
||
{
|
||
base.ShowMe();
|
||
|
||
highlightTipList.Clear();
|
||
//Transform backBtn = ToolFuncManager.GetChild(transform, "BackBtn");//低压工作票上一步按钮
|
||
|
||
GameManager.EventMgr.EventTrigger<bool>(Enum_EventType.PlayerCanMove, false);
|
||
if (GameManager.RunModelMgr.SceneType != E_SceneType.Site)
|
||
{
|
||
terminalPart.gameObject.SetActive(false);
|
||
if (GameManager.RunModelMgr.ModeType == E_ModeType.Study)
|
||
{
|
||
GetControl<Button>("closeBtn").gameObject.SetActive(false);
|
||
GetControl<Button>("BackBtn").gameObject.SetActive(false);
|
||
GetControl<Button>("NewAddBtn").gameObject.SetActive(false);
|
||
int i = 1;
|
||
while (true)//点亮全部的提示
|
||
{
|
||
Transform tip_tag = ToolFuncManager.GetChild(transform, "ImageTips_" + i);
|
||
if (tip_tag == null)
|
||
break;
|
||
else
|
||
{
|
||
ToolFuncManager.ActiveEmbededTip(tip_tag.gameObject);
|
||
highlightTipList.Add(tip_tag.gameObject);
|
||
i++;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
GetControl<Button>("closeBtn").gameObject.SetActive(true);
|
||
GetControl<Button>("BackBtn").gameObject.SetActive(true);
|
||
}
|
||
LoadDefaultValue();//学习模式下填充正确值,并且记录每个空应该填的内容
|
||
}
|
||
else
|
||
{
|
||
terminalPart.gameObject.SetActive(true);
|
||
GetControl<Button>("BackBtn").gameObject.SetActive(false);
|
||
triggerName = "办理工作票终结_确定";
|
||
}
|
||
|
||
|
||
WorkTicketItem temp = GameManager.WorkorderMgr.GetCurrentSchemeWorkTicketDataBySchemeID(GameManager.RunModelMgr.schemeID);
|
||
Dictionary<string, UI_MatterItem> leftBtnActionMap = GameManager.WorkorderMgr.leftBtnActionMap;
|
||
for (int i = 0; i < temp.workTicketLabels.Count; i++)
|
||
{
|
||
int index = i;
|
||
UI_MatterItem mi = Instantiate(matterItemPrefab, workTickeContent);
|
||
mi.Init(temp.workTicketLabels[index], (isOn) =>
|
||
{
|
||
OnLabelClick(isOn, temp.workTicketLabels[index], mi);
|
||
});
|
||
mi.selfToggle.onValueChanged.AddListener((isOn) => { CheckAllToggle(); });
|
||
miTemp.Add(mi);
|
||
}
|
||
|
||
for (int i = 0; i < miTemp.Count; i++)
|
||
{
|
||
int index = i;
|
||
if (leftBtnActionMap.ContainsKey(miTemp[index].label.text))
|
||
{
|
||
leftBtnActionMap[miTemp[index].label.text] = miTemp[index];
|
||
CreateLeftBtn(miTemp[index].label.text, miTemp[index]);
|
||
miTemp[index].selfToggle.isOn = true;
|
||
}
|
||
}
|
||
|
||
allToggle.onValueChanged.AddListener((isOn) =>
|
||
{
|
||
for (int i = 0; i < miTemp.Count; i++)
|
||
{
|
||
miTemp[i].selfToggle.isOn = isOn;
|
||
miTemp[i].selfToggle.onValueChanged?.Invoke(isOn);
|
||
}
|
||
});
|
||
|
||
if (GameManager.RunModelMgr.SceneType == E_SceneType.Site)
|
||
{
|
||
LoadTicketValue();
|
||
}
|
||
else if (GameManager.RunModelMgr.ModeType != E_ModeType.Study)
|
||
{
|
||
LoadTicketValue();
|
||
}
|
||
}
|
||
|
||
public void InitialDefaultValues(string key, string value, bool initialed)
|
||
{
|
||
if (!initialed)
|
||
MissionMgr.Instance.defaultTicketValues.Add(key, value);
|
||
}
|
||
|
||
public void OnSetUIRect(GameObject obj)
|
||
{
|
||
StartCoroutine(SetUIRect(obj));
|
||
}
|
||
|
||
public IEnumerator SetUIRect(GameObject obj)
|
||
{
|
||
Destroy(obj);
|
||
yield return new WaitForEndOfFrame();
|
||
LayoutRebuilder.ForceRebuildLayoutImmediate(backpack);
|
||
LayoutRebuilder.ForceRebuildLayoutImmediate(allContent);
|
||
}
|
||
|
||
public override void HideMe()
|
||
{
|
||
base.HideMe();
|
||
GameManager.EventMgr.EventTrigger<bool>(Enum_EventType.PlayerCanMove, true);
|
||
}
|
||
|
||
public virtual void LoadDefaultValue() { }
|
||
|
||
/// <summary>
|
||
/// 加载低压工作票内容,用于完成操作后的最后加载;学习模式加载默认数据,其他模式加载已保存的数据
|
||
/// </summary>
|
||
public virtual void LoadTicketValue()
|
||
{
|
||
|
||
if (GameManager.RunModelMgr.ModeType != E_ModeType.Study && GameManager.MissionMgr.selectedWorkTicketType != WorkTicketType.无)
|
||
{
|
||
foreach (var item in MissionMgr.Instance.selectedTicketValues)
|
||
{
|
||
Transform target = ToolFuncManager.GetChild(transform, item.Key);
|
||
if (target != null)
|
||
{
|
||
if (target.GetComponent<TMP_InputField>() != null)
|
||
{
|
||
target.GetComponent<TMP_InputField>().text = MissionMgr.Instance.selectedTicketValues[item.Key];
|
||
}
|
||
else if (target.GetComponent<TMP_Dropdown>() != null)
|
||
{
|
||
target.GetComponent<TMP_Dropdown>().captionText.text = MissionMgr.Instance.selectedTicketValues[item.Key];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 当注意事项点击和取消点击的时候
|
||
/// </summary>
|
||
/// <param name="isOn"></param>
|
||
public void OnLabelClick(bool isOn, string label, UI_MatterItem mi)
|
||
{
|
||
if (isOn)
|
||
{
|
||
if (!GameManager.WorkorderMgr.IsCantainskey(label))
|
||
{
|
||
CreateLeftBtn(label, mi);
|
||
GameManager.WorkorderMgr.AddLeftBtnActionMap(label, mi);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
mi.selfToggle.isOn = false;
|
||
GameManager.WorkorderMgr.RemoveLeftBtnActionMap(label);
|
||
if (mi.result != null)
|
||
DestroyImmediate(mi.result.gameObject);
|
||
mi.result = null;
|
||
}
|
||
}
|
||
|
||
public void CreateLeftBtn(string label, UI_MatterItem mi) //添加选中的注意事项按钮
|
||
{
|
||
RectTransform lb = Instantiate(leftItemPrefab, workTickeRequstContent);
|
||
|
||
lb.GetComponentInChildren<TextMeshProUGUI>().text = label;
|
||
if (GameManager.RunModelMgr.ModeType != E_ModeType.Study)
|
||
{
|
||
lb.GetComponentInChildren<Button>().onClick.AddListener(() =>
|
||
{
|
||
mi.selfToggle.isOn = false;
|
||
if (mi.result != null)
|
||
DestroyImmediate(mi.result.gameObject);
|
||
mi.result = null;
|
||
GameManager.WorkorderMgr.RemoveLeftBtnActionMap(label);
|
||
});
|
||
}
|
||
else
|
||
{
|
||
lb.GetComponentInChildren<Button>().gameObject.SetActive(false);
|
||
}
|
||
|
||
mi.result = lb;
|
||
}
|
||
|
||
public virtual void SaveTicketValue()
|
||
{
|
||
MissionMgr.Instance.selectedWorkTicketType = workTicketType;//保存工作票类型
|
||
MissionMgr.Instance.selectedTicketValues.Clear();
|
||
foreach (var item in MissionMgr.Instance.defaultTicketValues)
|
||
{
|
||
Transform target = ToolFuncManager.GetChild(transform, item.Key);
|
||
if (target != null && !item.Key.StartsWith("mission_InputField_"))
|
||
{
|
||
if (target.GetComponent<TMP_InputField>() != null)
|
||
{
|
||
MissionMgr.Instance.selectedTicketValues.Add(item.Key, target.GetComponent<TMP_InputField>().text);
|
||
}
|
||
else if (target.GetComponent<TMP_Dropdown>() != null)
|
||
{
|
||
MissionMgr.Instance.selectedTicketValues.Add(item.Key, target.GetComponent<TMP_Dropdown>().options[target.GetComponent<TMP_Dropdown>().value].text);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
public bool NeedLoadTicketDefaultValue()
|
||
{
|
||
return ((GameManager.RunModelMgr.ModeType != E_ModeType.Study && (GameManager.MissionMgr.selectedTicketValues != null || GameManager.MissionMgr.selectedTicketValues.Count > 0) && GameManager.RunModelMgr.SceneType == E_SceneType.Site) ||
|
||
(GameManager.RunModelMgr.ModeType == E_ModeType.Study && GameManager.RunModelMgr.SceneType == E_SceneType.Site));
|
||
|
||
}
|
||
public void FixedUpdate()
|
||
{
|
||
if (GameManager.RunModelMgr.ModeType == E_ModeType.Study)
|
||
{
|
||
if (GameManager.RunModelMgr.SceneType == E_SceneType.Office)
|
||
{
|
||
if (highlightTipList.Count > 0)
|
||
{
|
||
bool checking = false;
|
||
for (int i = 0; i < highlightTipList.Count; i++)
|
||
{
|
||
if (highlightTipList[i].gameObject.activeInHierarchy)
|
||
{
|
||
checking = true;
|
||
break;
|
||
}
|
||
}
|
||
if (!checking)
|
||
{
|
||
Transform ConfirmBtn_ImageTips = ToolFuncManager.GetChild(transform, "ConfirmBtn_ImageTips");
|
||
ConfirmBtn_ImageTips.gameObject.SetActive(true);
|
||
ToolFuncManager.ActiveEmbededTip(ConfirmBtn_ImageTips.gameObject);
|
||
highlightTipList.Clear();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 点亮全选按钮
|
||
/// </summary>
|
||
public void CheckAllToggle()
|
||
{
|
||
bool isAllOn = true;
|
||
foreach (Transform item in workTickeContent)
|
||
{
|
||
UnityEngine.UI.Toggle toggle = item.GetComponentInChildren<UnityEngine.UI.Toggle>();
|
||
if (toggle != null)
|
||
{
|
||
if (!toggle.isOn)
|
||
{
|
||
isAllOn = false;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
allToggle.SetIsOnWithoutNotify(isAllOn);
|
||
}
|
||
}
|