广西桂平帝恒管道燃气投资有限公司多角色网上演练
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

252 lines
7.9 KiB

using AX.MessageSystem;
using AX.NetworkSystem;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 战后调查(必填)
/// </summary>
public class UIViewQuestionnaire : UIView
{
public CommonButton ButtonEnter;
// ScrollView
public GameObject ScrollViewContent;
// QuestionItem
public GameObject QuestionItem;
// Mask
public GameObject Mask;
// LoadingBar
public Slider LoadingBar;
// LoadingText
public Text LoadingText;
public override UIViewType ViewType
{
get
{
return UIViewType.Normal;
}
}
public List<Question> Questions { get; set; }
private void Awake()
{
if (!CheckZD())
{
LoadPromptWin.Instance.LoadTextPromptWindow("未检测到中队,跳过打分环节",2f);
gameObject.SetActive(false);
return;
}
// 读取数据
Questions = ResourceManager.LoadJson<List<Question>>("Question.json");
if (ReportDataMgr.IsVictory)
{
// 去除失败的调查
Questions.RemoveAt(5);
}
else
{
// 去除胜利的调查
Questions.RemoveAt(6);
}
//
GetNewQuestionContent();
// 根据数据创建Item
StartCoroutine(CreateItem());
ButtonEnter.GetComponent<Button>().interactable = false;
}
private bool CheckZD()
{
bool has = false;
for (int i = 0; i < CurrentUserInfo.room.UserList.Count; i++)
{
if (CurrentUserInfo.room.UserList[i].Role==Role.)
{
has = true;
break;
}
}
return has;
}
internal void SetSyncData(List<Question> questions)
{
// count +1
ReportDataMgr.SubmitQuestionnaireNumber += 1;
// 添加数据
ReportDataMgr.AllQuestionnaire.Add(questions);
UpdateLoading();
// 如果所有用户都提交完成
if (LoadingBar.value == LoadingBar.maxValue)
{
// 获取所有得分
ReportDataMgr.GetAllScoure();
// 隐藏
Mask.SetActive(false);
Hide();
// 所有用户提交完成
UIManager.ShowView<UIViewScore>();
}
}
public void UpdateLoading()
{
LoadingText.text = string.Format("(等待其他参演人员完成评分{0}/{1})", ReportDataMgr.SubmitQuestionnaireNumber, ReportDataMgr.QuestionnaireNumber);
LoadingBar.value = ReportDataMgr.SubmitQuestionnaireNumber;
LoadingBar.maxValue = ReportDataMgr.QuestionnaireNumber;
}
private void GetNewQuestionContent()
{
foreach (var item in Questions)
{
switch (item.ID)
{
case "0":
case "10":
case "11":
case "12":
case "13":
case "14":
// 清空原有数据
item.Content.Clear();
// 获取参演的所有中队
foreach (var user in CurrentUserInfo.room.UserList)
{
if (user.Role == Role.)
{
item.Content.Add(user.Org.DisplayName);
}
}
break;
case "1":
// 清空原有数据
item.Content.Clear();
// 获取参演的所有指挥员
foreach (var user in CurrentUserInfo.room.UserList)
{
if (user.Role == Role. ||
user.Role == Role. ||
user.Role == Role. ||
user.Role == Role.)
{
string name = string.Format("{1}_{0}({2})", user.UserInfo.RealName, user.Org.DisplayName, user.Role);
item.Content.Add(name);
}
}
break;
case "2":
// 清空原有数据
item.Content.Clear();
// 获取参演的所有参演人员,不包括导调组/观察团/指挥中心
foreach (var user in CurrentUserInfo.room.UserList)
{
if (user.Role != Role. &&
user.Role != Role. &&
user.Role != Role. &&
user.Role != Role.)
{
string name = string.Format("{1}_{0}({2})", user.UserInfo.RealName, user.Org.DisplayName, user.Role);
item.Content.Add(name);
}
}
break;
}
}
}
private IEnumerator CreateItem()
{
foreach (var item in Questions)
{
// 创建问题
GameObject obj = Instantiate(QuestionItem);
// 记录问题位置,大小
Vector3 tempPos = obj.transform.localPosition;
Vector3 tempSca = obj.transform.localScale;
// 设置父对象
obj.transform.SetParent(ScrollViewContent.transform);
obj.transform.localPosition = tempPos;
obj.transform.localScale = tempSca;
// 获取ScriteItem
QuestionItem ScripteItem = obj.GetComponent<QuestionItem>();
//ScripteItem.SetData(item);
//item.Result.Clear();
yield return StartCoroutine(ScripteItem.SetData(item));
}
//刷新大小
LayoutRebuilder.MarkLayoutForRebuild(ScrollViewContent.transform as RectTransform);
}
private void OnEnable()
{
ButtonEnter.OnClicked += ButtonEnter_OnClicked;
MessageDispatcher.AddListener("CHECK_QUESTION_BUTTON", CheckButton);
}
private void OnDisable()
{
ButtonEnter.OnClicked -= ButtonEnter_OnClicked;
MessageDispatcher.RemoveListener("CHECK_QUESTION_BUTTON", CheckButton);
}
private void CheckButton(IMessage obj)
{
foreach (var item in Questions)
{
if (item.Type == QuestionType.FillInTheBlanks)
{
// 填空
foreach (var result in item.ScoreResult.Values)
{
if (result.Equals(0))
{
ButtonEnter.GetComponent<Button>().interactable = false;
//Debug.Log("有未填写的填空题,请填写完整。");
return;
}
}
}
else
{
// 选择题
bool b = true;
foreach (var result in item.SelectionResult.Values)
{
if (result)
{
b = false;
}
}
if (b)
{
ButtonEnter.GetComponent<Button>().interactable = false;
//Debug.Log("有未填写的填空题,请填写完整。");
return;
}
}
}
//Debug.Log("问卷填写完成。");
ButtonEnter.GetComponent<Button>().interactable = true;
}
private void ButtonEnter_OnClicked(CommonButton obj)
{
Mask.SetActive(true);
UpdateLoading();
//QUESTIONNAIRE_SYNC 问卷同步
//GetActInPersonCount();
NetworkManager.Default.SendAsync("QUESTIONNAIRE_SYNC", Questions);
}
public override void Refresh()
{
base.Refresh();
}
}