198 lines
9.1 KiB
C#
198 lines
9.1 KiB
C#
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using ZXKFramework;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
using UnityEngine.EventSystems;
|
|||
|
|
using System;
|
|||
|
|
using System.Linq;
|
|||
|
|
|
|||
|
|
public class ToolPanel : UIBase
|
|||
|
|
{
|
|||
|
|
public override string Name => "ToolPanel";
|
|||
|
|
public override string GroupName => UIGroupLiao.Tool.ToString();
|
|||
|
|
private Dictionary<string, List<int>> dic = new();
|
|||
|
|
private GameModel gameModel;
|
|||
|
|
private List<Transform> btnList = new();
|
|||
|
|
List<MainData> mainDatas = null;
|
|||
|
|
private bool randomBtn;
|
|||
|
|
public override void HandleEvent(string name, object data) { }
|
|||
|
|
public override void Init(IUIManager uictrl)
|
|||
|
|
{
|
|||
|
|
base.Init(uictrl);
|
|||
|
|
gameModel = GetModel<GameModel>();
|
|||
|
|
}
|
|||
|
|
public override void ShowData(params object[] obj)
|
|||
|
|
{
|
|||
|
|
base.ShowData(obj);
|
|||
|
|
if (gameModel.GetModeType() == ModeType.KaoHe && randomBtn == false)
|
|||
|
|
{
|
|||
|
|
randomBtn = true;
|
|||
|
|
mainDatas = gameModel.mainData.GetMainDataList().OrderBy(i => Guid.NewGuid()).ToList();
|
|||
|
|
}
|
|||
|
|
else if (gameModel.GetModeType() == ModeType.LiuLan || gameModel.GetModeType() == ModeType.ShiXun)
|
|||
|
|
{
|
|||
|
|
mainDatas = gameModel.mainData.GetMainDataList();
|
|||
|
|
randomBtn = false;
|
|||
|
|
}
|
|||
|
|
foreach (var loData in mainDatas)
|
|||
|
|
{
|
|||
|
|
if (loData.ModuleName == gameModel.mainData.GetModuleName(gameModel.GetId()))
|
|||
|
|
{
|
|||
|
|
if (!string.IsNullOrEmpty(loData.ToolName))
|
|||
|
|
{
|
|||
|
|
if (dic.ContainsKey(loData.ToolName))
|
|||
|
|
{
|
|||
|
|
dic[loData.ToolName].Add(loData.id);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
List<int> list = new();
|
|||
|
|
list.Add(loData.id);
|
|||
|
|
dic.Add(loData.ToolName, list);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
public override void Show()
|
|||
|
|
{
|
|||
|
|
base.Show();
|
|||
|
|
Game.Instance.objectPool.Unspawn("ToolBtnBase");
|
|||
|
|
Transform loBenParent = transform.FindFirst<Transform>("ToolsPanelData");
|
|||
|
|
foreach (var item in dic)
|
|||
|
|
{
|
|||
|
|
Game.Instance.objectPool.Spawn("ToolBtnBase", loBenParent, m =>
|
|||
|
|
{
|
|||
|
|
btnList.Add(m.transform);
|
|||
|
|
m.transform.localScale = Vector3.one;
|
|||
|
|
m.FindFirst<Text>("Text").text = item.Key;
|
|||
|
|
Game.Instance.res.Load<Texture2D>(gameModel.mainData.GetToolImagePath(item.Value[0]), t => {
|
|||
|
|
m.FindFirst<Image>("Image").sprite = UnityTools.ToSprite(t);
|
|||
|
|
m.FindFirst<Image>("Image").color = new Color(1, 1, 1, 1);
|
|||
|
|
});
|
|||
|
|
UIEventListener loBtn = m.GetComponent<UIEventListener>();
|
|||
|
|
loBtn.Click = null;
|
|||
|
|
loBtn.Down = null;
|
|||
|
|
loBtn.Click = (PointerEventData eventData) =>
|
|||
|
|
{
|
|||
|
|
int tempId = item.Value.Find(e => e == gameModel.GetId());
|
|||
|
|
EventType type = (EventType)Enum.Parse(typeof(EventType), gameModel.mainData.GetMessageType(gameModel.GetId()));
|
|||
|
|
if (type != EventType.<EFBFBD><EFBFBD>ק)
|
|||
|
|
{
|
|||
|
|
if (gameModel.GetModeType() == ModeType.KaoHe && gameModel.mainData.GetScoreMode(gameModel.GetId()) != 0)
|
|||
|
|
{
|
|||
|
|
Game.Instance.eventManager.Raise(new ScoreRecordEvent()
|
|||
|
|
{
|
|||
|
|
subModule = gameModel.mainData.GetSubModuleName(gameModel.GetId()),
|
|||
|
|
task = gameModel.mainData.GetTaskName(gameModel.GetId()),
|
|||
|
|
right = tempId != 0
|
|||
|
|
});
|
|||
|
|
Game.Instance.eventManager.Raise(new ProcessEvent()
|
|||
|
|
{
|
|||
|
|
subModule = gameModel.mainData.GetSubModuleName(gameModel.GetId()),
|
|||
|
|
task = gameModel.mainData.GetTaskName(gameModel.GetId())
|
|||
|
|
});
|
|||
|
|
Game.Instance.eventManager.Raise(new StepRecordEvent()
|
|||
|
|
{
|
|||
|
|
subModule = gameModel.mainData.GetSubModuleName(gameModel.GetId()),
|
|||
|
|
task = gameModel.mainData.GetTaskName(gameModel.GetId()),
|
|||
|
|
stepType = gameModel.mainData.GetMessageType(gameModel.GetId()),
|
|||
|
|
answer = gameModel.mainData.GetToolName(gameModel.GetId()),
|
|||
|
|
yourAnswer = item.Key,
|
|||
|
|
start = true
|
|||
|
|
});
|
|||
|
|
loBtn.transform.FindFirst<Transform>("Incorrect").gameObject.SetActive(tempId == 0);
|
|||
|
|
loBtn.transform.FindFirst<Transform>("Correct").gameObject.SetActive(tempId != 0);
|
|||
|
|
tempId = gameModel.GetId();//<2F><><EFBFBD><EFBFBD>ģʽ<C4A3>£<EFBFBD><C2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬҲ<C6AC><D2B2>ǿ<EFBFBD>Ƹ<EFBFBD>ֵΪ<D6B5><CEAA>ȷid
|
|||
|
|
}
|
|||
|
|
if (type == EventType.չʾ)
|
|||
|
|
{
|
|||
|
|
tempId = item.Value[0];
|
|||
|
|
}
|
|||
|
|
Game.Instance.eventManager.Raise(new MessageTypeEvent()
|
|||
|
|
{
|
|||
|
|
type = type,
|
|||
|
|
id = tempId
|
|||
|
|
});
|
|||
|
|
loBtn.transform.FindFirst<Transform>("Select").gameObject.SetActive(false);
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
loBtn.Down = (PointerEventData eventData) =>
|
|||
|
|
{
|
|||
|
|
int tempId = item.Value.Find(e => e == gameModel.GetId());
|
|||
|
|
EventType type = (EventType)Enum.Parse(typeof(EventType), gameModel.mainData.GetMessageType(gameModel.GetId()));
|
|||
|
|
if (type == EventType.<EFBFBD><EFBFBD>ק)
|
|||
|
|
{
|
|||
|
|
if (gameModel.GetModeType() == ModeType.KaoHe && gameModel.mainData.GetScoreMode(gameModel.GetId()) != 0)
|
|||
|
|
{
|
|||
|
|
Game.Instance.eventManager.Raise(new ScoreRecordEvent()
|
|||
|
|
{
|
|||
|
|
subModule = gameModel.mainData.GetSubModuleName(gameModel.GetId()),
|
|||
|
|
task = gameModel.mainData.GetTaskName(gameModel.GetId()),
|
|||
|
|
right = tempId != 0
|
|||
|
|
});
|
|||
|
|
Game.Instance.eventManager.Raise(new ProcessEvent()
|
|||
|
|
{
|
|||
|
|
subModule = gameModel.mainData.GetSubModuleName(gameModel.GetId()),
|
|||
|
|
task = gameModel.mainData.GetTaskName(gameModel.GetId())
|
|||
|
|
});
|
|||
|
|
Game.Instance.eventManager.Raise(new StepRecordEvent()
|
|||
|
|
{
|
|||
|
|
subModule = gameModel.mainData.GetSubModuleName(gameModel.GetId()),
|
|||
|
|
task = gameModel.mainData.GetTaskName(gameModel.GetId()),
|
|||
|
|
stepType = gameModel.mainData.GetMessageType(gameModel.GetId()),
|
|||
|
|
answer = gameModel.mainData.GetToolName(gameModel.GetId()),
|
|||
|
|
yourAnswer = item.Key,
|
|||
|
|
start = true
|
|||
|
|
});
|
|||
|
|
loBtn.transform.FindFirst<Transform>("Incorrect").gameObject.SetActive(tempId == 0);
|
|||
|
|
loBtn.transform.FindFirst<Transform>("Correct").gameObject.SetActive(tempId != 0);
|
|||
|
|
tempId = gameModel.GetId();//<2F><><EFBFBD><EFBFBD>ģʽ<C4A3>£<EFBFBD><C2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<CDBC><C6AC>Ҳ<EFBFBD><D2B2>ǿ<EFBFBD>Ƹ<EFBFBD>ֵΪ<D6B5><CEAA>ȷid
|
|||
|
|
}
|
|||
|
|
if (type == EventType.չʾ)
|
|||
|
|
{
|
|||
|
|
tempId = item.Value[0];
|
|||
|
|
}
|
|||
|
|
Game.Instance.eventManager.Raise(new MessageTypeEvent()
|
|||
|
|
{
|
|||
|
|
type = type,
|
|||
|
|
id = tempId
|
|||
|
|
});
|
|||
|
|
loBtn.transform.FindFirst<Transform>("Select").gameObject.SetActive(false);
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public void HighLightBtn(string value)
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < btnList.Count; i++)
|
|||
|
|
{
|
|||
|
|
if (value == btnList[i].FindFirst<Text>("Text").text)
|
|||
|
|
{
|
|||
|
|
btnList[i].FindFirst<Transform>("Select").gameObject.SetActive(true);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
btnList[i].FindFirst<Transform>("Select").gameObject.SetActive(false);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public void CloseAllHighLightBtn()
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < btnList.Count; i++)
|
|||
|
|
{
|
|||
|
|
btnList[i].FindFirst<Transform>("Select").gameObject.SetActive(false);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public override void Hide()
|
|||
|
|
{
|
|||
|
|
base.Hide();
|
|||
|
|
dic.Clear();
|
|||
|
|
CloseAllHighLightBtn();
|
|||
|
|
btnList.Clear();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|