123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- using UnityEngine;
- using UnityEngine.UI;
- using QFramework;
- using System.Collections.Generic;
- using UniRx.Triggers;
- using System.Xml.Linq;
- using System;
- using UnityEngine.Rendering;
- namespace QFramework
- {
- public class ChallengeConfigurationPanelData : UIPanelData
- {
- /// <summary>
- /// 设备编码
- /// </summary>
- public int DeviceUniqueNumber = 1003;
- /// <summary>
- /// 关卡配置信息
- /// </summary>
- public ChallengeConfigurationManager ChallengeConfigurations = new ChallengeConfigurationManager();
- }
- public partial class ChallengeConfigurationPanel : UIPanel
- {
- Dictionary<int, CorrespondTabelOfEquipmentInfo> m_DicCorrespondTabelOfEquipmentInfos;
- private List<LeveItem> m_LeveItems = new List<LeveItem>();
- private int m_MinIndex = -1;
- private int m_MaxIndex = -1;
- protected override void OnInit(IUIData uiData = null)
- {
- mData = uiData as ChallengeConfigurationPanelData ?? new ChallengeConfigurationPanelData();
- //读取数据
- //m_DicCorrespondTabelOfEquipmentInfos = ExcelDataAnalyze.GetAllDataForTable<CorrespondTabelOfEquipmentInfo>(Enum_TableType.CorrespondTabelOfEquipmentTable);
- //保存按钮
- SaveBtn.onClick.AddListener(OnSaveBtnClick);
- }
- protected override void OnOpen(IUIData uiData = null)
- {
- mData = uiData as ChallengeConfigurationPanelData ?? new ChallengeConfigurationPanelData();
- if (UIKit.GetPanel<PranticePromptPanel>()) UIKit.GetPanel<PranticePromptPanel>();
- CorrespondTabelOfEquipmentInfo correspondTabelOfEquipmentInfo;
- if (m_DicCorrespondTabelOfEquipmentInfos.TryGetValue(mData.DeviceUniqueNumber, out correspondTabelOfEquipmentInfo))
- {
- StepListProxy tmpStepListProxy = DAL.Instance.Get<StepListProxy>();
- List<OperationStepDataInfo> tmpOperationStepInfos = tmpStepListProxy.ReadStepMsgInfoFromTable(correspondTabelOfEquipmentInfo.MaintenancConfigurationTableName);
- Dictionary<string, List<OperationStepDataInfo>> tmpDic = tmpStepListProxy.ProcessingData(tmpOperationStepInfos);
- GenerateLeveItem(tmpDic);
- }
- }
- private void GenerateLeveItem(Dictionary<string, List<OperationStepDataInfo>> keyValues)
- {
- int tmpIndex = 0;
- foreach (var item in keyValues)
- {
- GameObject tmpLeveItemObj = Instantiate(LeveItem.gameObject, Content);
- tmpLeveItemObj.SetActive(true);
- LeveItem tmpLeveItem = tmpLeveItemObj.GetComponent<LeveItem>();
- tmpLeveItem.InitData(tmpIndex, keyValues[item.Key][0]);
- m_LeveItems.Add(tmpLeveItem);
- tmpIndex++;
- }
- //设置初始选择的关卡的选中状态
- SetSelectedLeveItemState();
- //刷新分数
- RefreshSelectItems();
- }
- /// <summary>
- /// 设置已选中的关卡状态
- /// </summary>
- private void SetSelectedLeveItemState()
- {
- if (mData.ChallengeConfigurations.challengeConfigurations == null)return;
- StepListProxy tmpStepListProxy = DAL.Instance.Get<StepListProxy>();
- foreach (var item in mData.ChallengeConfigurations.challengeConfigurations)
- {
- OperationStepDataInfo tmpInfo = tmpStepListProxy.GetOperationStepDataInfoById(item.LeveId);
- LeveItem tmpIeveItem = m_LeveItems.Find(t => t.m_LevelName == tmpInfo.parentStepName);
- if (tmpIeveItem != null)
- {
- if (m_MinIndex == -1) m_MinIndex = tmpIeveItem.m_index;
- tmpIeveItem.SetSelectedData(item);
- m_MaxIndex = tmpIeveItem.m_index;
- }
- }
- }
- /// <summary>
- /// 设置选择状态
- /// </summary>
- /// <param name="index"></param>
- public void SetSelectState(int index, bool selectSate)
- {
- if (selectSate)
- {
- if (m_MinIndex > index)
- {
- m_LeveItems[index].SetSelectState(false);
- return;
- }
- if (GetSelectCount() == 1) m_MinIndex = index;
- if (GetSelectCount() > 1) m_MaxIndex = index;
- }
- else
- {
- if (m_MinIndex == index)
- {
- m_MinIndex = -1;
- m_MaxIndex = -1;
- }
- else if (index > m_MinIndex)
- {
- m_MaxIndex = index;
- }
- }
- RefreshSelectItems();
- }
- public void RefreshSelectItems()
- {
- for (int i = 0; i < m_LeveItems.Count; i++)
- {
- if (m_MinIndex != -1 && m_MinIndex == i)
- {
- continue;
- }
- else
- {
- if (i >= m_MinIndex && i <= m_MaxIndex)
- {
- m_LeveItems[i].SetSelectState(true);
- }
- else
- {
- m_LeveItems[i].SetSelectState(false);
- }
- }
- }
- RefreshTotalTime();
- }
- /// <summary>
- /// 获取目前选择的数量
- /// </summary>
- public int GetSelectCount()
- {
- return m_LeveItems.FindAll(t => t.m_SelectState == true).Count;
- }
- /// <summary>
- /// 刷新总时间
- /// </summary>
- public void RefreshTotalTime()
- {
- int totalTime = 0;
- for (int i = 0; i < m_LeveItems.Count; i++)
- {
- if (m_LeveItems[i].m_SelectState)
- {
- if (!string.IsNullOrEmpty(m_LeveItems[i].TimeInputField.text))
- {
- totalTime += int.Parse(m_LeveItems[i].TimeInputField.text);
- }
- }
- }
- TimeText.text = totalTime.ToString();
- }
- public void OnSaveBtnClick()
- {
-
- }
- protected override void OnShow()
- {
- }
- protected override void OnHide()
- {
- }
- protected override void OnClose()
- {
- }
- }
- }
- [Serializable]
- public class ChallengeConfigurationManager
- {
- public ChallengeConfiguration[] challengeConfigurations;
- }
- /// <summary>
- /// 关卡信息
- /// </summary>
- [Serializable]
- public class ChallengeConfiguration
- {
- /// <summary>
- /// 关卡名称
- /// </summary>
- public int LeveId;
- /// <summary>
- /// 关卡时间
- /// </summary>
- public string LeveTime;
- }
- public class LeveInfo
- {
- /// <summary>
- /// 关卡名称
- /// </summary>
- public string leveName;
- /// <summary>
- /// 关卡时间
- /// </summary>
- public string leveTime;
- }
|