171 lines
5.9 KiB
C#
171 lines
5.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using XFramework;
|
|
//学员端科目一推演界面
|
|
public class Sub1LearnPanel : BasePanel
|
|
{
|
|
const string panelName = "Panel_studentSub1推演";
|
|
private GameObject finishPromptWindow;
|
|
private Text text_Timer;
|
|
private AnserWindowCtrl answerWindow;
|
|
Transform image_Map;
|
|
int time;
|
|
|
|
public Sub1LearnPanel():base(new UIType(panelName))
|
|
{
|
|
|
|
}
|
|
|
|
protected override void InitEvent()
|
|
{
|
|
finishPromptWindow = ActivePanel.Find("Image_结束提示").gameObject;
|
|
answerWindow = ActivePanel.Find("Image_答题框").GetComponent<AnserWindowCtrl>();
|
|
text_Timer = ActivePanel.Find("Text_Timer").GetComponent<Text>();
|
|
//EventCenter.Instance.AddEventListener<TuFaEnum>("TuFaTrigger",);
|
|
}
|
|
|
|
public override void OnStart()
|
|
{
|
|
base.OnStart();
|
|
finishPromptWindow.gameObject.SetActive(false);
|
|
answerWindow.gameObject.SetActive(false);
|
|
Game.StartCoroutine(Timer());
|
|
|
|
}
|
|
|
|
//int timeScale=5;//时间 按5倍快放计时
|
|
|
|
private IEnumerator Timer()
|
|
{
|
|
yield return new WaitForSeconds(1);
|
|
time += (int)Time.timeScale;
|
|
int miao = time % 60;
|
|
int min = time / 60;
|
|
int hour = 0;
|
|
if (min > 59)
|
|
{
|
|
hour = min / 60;
|
|
min = min % 60;
|
|
}
|
|
if (text_Timer != null)
|
|
LocalizationManager.SetFormatted(text_Timer, "推演时间: {0}:{1}:{2}", hour, min, miao);
|
|
Game.StartCoroutine(Timer());
|
|
}
|
|
|
|
public override void OnDestroy(bool isDestroy = false)
|
|
{
|
|
base.OnDestroy(isDestroy);
|
|
Game.StopCoroutine(Timer());
|
|
}
|
|
|
|
//初始化推演界面 小地图 沿用编辑时的GameObject
|
|
public override void Change(object newData)
|
|
{
|
|
base.Change(newData);
|
|
image_Map = newData as Transform;
|
|
image_Map.transform.SetParent(ActivePanel);
|
|
RectTransform rectTransform = image_Map.GetComponent<RectTransform>();
|
|
rectTransform.anchorMin = Vector2.zero;
|
|
rectTransform.anchorMax = Vector2.zero;
|
|
rectTransform.sizeDelta = new Vector2(480, 270);
|
|
rectTransform.anchoredPosition = new Vector2(240, 135);
|
|
image_Map.GetComponentInChildren<MyDragMap>().InitSize();
|
|
}
|
|
|
|
TuFaAnswerClass tufaMsg;//当前遇到的突发事件对应的答题选项
|
|
TuFaEnum tuFa;//当前遇到的突发事件名称
|
|
/// <summary>
|
|
/// 遇到突发事件 导调模式发送事件信息到教员端
|
|
/// </summary>
|
|
/// <param name="msgType"></param>
|
|
/// <param name="value"></param>
|
|
public override void Change(string msgType, object value)
|
|
{
|
|
if (msgType == "TuFaTrigger")
|
|
{
|
|
tuFa = (TuFaEnum)value ;
|
|
tufaMsg = TuFaAnswers.tufaEvents[tuFa];
|
|
List<string> options = new List<string>();
|
|
foreach (var item in tufaMsg.options)
|
|
{
|
|
options.Add(LocalizationManager.Get(item.Key));
|
|
}
|
|
answerWindow.SetAskAndAnswer(LocalizationManager.Get(tuFa.ToString()), options, AnswerEvent);
|
|
|
|
if (AdjustingManager.Instance.Adjusting)//导调状态下遇到突发事件发送消息到教员端
|
|
{
|
|
NetTuFaHandleMsg msg = new NetTuFaHandleMsg();
|
|
msg.msgType = TuFaMsgType.trigger;
|
|
msg.msg = tuFa.ToString();
|
|
TCPManager.Instance.SendNetMsg<NetTuFaHandleMsg>(msg, NetMsgName.TuFaEvent);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 完成答题时 检查选项是否最佳选项以及当前选项对应的罚时 并恢复车辆移动 导调模式下发送事件信息到教员端
|
|
void AnswerEvent(string selectOperations)
|
|
{
|
|
// Find the original Chinese key from the displayed (localized) text
|
|
string selectedKey = selectOperations;
|
|
foreach (var item in tufaMsg.options)
|
|
{
|
|
if (LocalizationManager.Get(item.Key) == selectOperations)
|
|
{
|
|
selectedKey = item.Key;
|
|
break;
|
|
}
|
|
}
|
|
bool isRightOption = selectedKey == tufaMsg.rightOption;
|
|
int takeTime = tufaMsg.options[selectedKey];
|
|
time -= takeTime * 60;//takeTime为负数
|
|
if (isRightOption)//正确处理方式不记录罚时
|
|
{
|
|
StudentOperateRecorder.Instance.InjectOperateMsgLocalized("行军过程中遇到{0},选择处理方式为{1}", tuFa.ToString(), selectedKey);
|
|
}
|
|
else
|
|
StudentOperateRecorder.Instance.InjectOperateMsgLocalized("行军过程中遇到{0},选择处理方式为{1},罚时{2}分钟", tuFa.ToString(), selectedKey, Mathf.Abs(takeTime));
|
|
|
|
if (AdjustingManager.Instance.Adjusting)//导调状态下遇到突发事件发送事件信息到教员端
|
|
{
|
|
NetTuFaHandleMsg msg = new NetTuFaHandleMsg();
|
|
if (isRightOption)
|
|
{
|
|
msg.msgType = TuFaMsgType.handleRight;
|
|
msg.msg = $"{ selectedKey}";
|
|
}
|
|
else
|
|
{
|
|
msg.msgType = TuFaMsgType.handleWrong;
|
|
msg.msg = $"{ selectedKey},罚时{takeTime}分钟";
|
|
}
|
|
TCPManager.Instance.SendNetMsg<NetTuFaHandleMsg>(msg, NetMsgName.TuFaEvent);
|
|
}
|
|
|
|
if (StudentStateManager.Instance.LearnState == LearnState.learning&&!isRightOption)//训练模式回答错误时 提示正确答案 并延迟3秒后消失
|
|
{
|
|
answerWindow.ShowRightResult(tufaMsg.rightOption);
|
|
Game.StartCoroutine(WaitSeconds());//延迟3秒
|
|
}
|
|
else
|
|
{
|
|
HideWindowAndMove();//直接调用 不延迟
|
|
}
|
|
|
|
}
|
|
|
|
//等待时间
|
|
IEnumerator WaitSeconds()
|
|
{
|
|
yield return new WaitForSeconds(3f);
|
|
HideWindowAndMove();
|
|
}
|
|
|
|
void HideWindowAndMove()
|
|
{
|
|
GameObjectManager.Instance.StartAIMove();//回答完成后 车队继续移动
|
|
answerWindow.Hide();
|
|
}
|
|
}
|