修改评分支持多模块显示
This commit is contained in:
parent
384a80b84a
commit
15a78a6296
@ -23,6 +23,7 @@ public class UIToolsAction : IAction
|
||||
string wrongEvent;
|
||||
string rightScore;
|
||||
string wrongScore;
|
||||
string totalScore;
|
||||
string scoreStepName;
|
||||
string autoHide;
|
||||
public static UIToolsAction Allocate(Dictionary<string, string> datas, System.Action onDelayFinish = null)
|
||||
@ -40,6 +41,7 @@ public class UIToolsAction : IAction
|
||||
retNode.wrongEvent = datas.ContainsKey("wrongEvent") ? datas["wrongEvent"] : "";
|
||||
retNode.rightScore = datas.ContainsKey("rightScore") ? datas["rightScore"] : "";
|
||||
retNode.wrongScore = datas.ContainsKey("wrongScore") ? datas["wrongScore"] : "";
|
||||
retNode.totalScore = datas.ContainsKey("totalScore") ? datas["totalScore"] : "";
|
||||
retNode.scoreStepName = datas.ContainsKey("scoreStepName") ? datas["scoreStepName"] : "";
|
||||
retNode.autoHide = datas.ContainsKey("autoHide") ? datas["autoHide"] : "";
|
||||
return retNode;
|
||||
@ -75,6 +77,7 @@ public class UIToolsAction : IAction
|
||||
data.wrongEvent = wrongEvent;
|
||||
float.TryParse(rightScore, out data.rightScore);
|
||||
float.TryParse(wrongScore, out data.wrongScore);
|
||||
float.TryParse(totalScore, out data.totalScore);
|
||||
data.scoreStepName = scoreStepName;
|
||||
bool.TryParse(setActive, out data.SetActive);
|
||||
if (float.TryParse(autoHide, out data.autoHideResult) == false)
|
||||
|
||||
@ -7,24 +7,58 @@ using XMLTool;
|
||||
|
||||
public class ScoreController : MonoSingleton<ScoreController>
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
public Dictionary<string, ScoreStep> scoreDict;
|
||||
}
|
||||
|
||||
public Dictionary<string, Data> moduleDict;
|
||||
public override void OnSingletonInit()
|
||||
{
|
||||
base.OnSingletonInit();
|
||||
scoreDict = new Dictionary<string, ScoreStep>();
|
||||
InitData();
|
||||
TypeEventSystem.Global.Register<OnModuleStart>(OnStart).UnRegisterWhenGameObjectDestroyed(gameObject);
|
||||
TypeEventSystem.Global.Register<OnModuleQuit>(OnQuit).UnRegisterWhenGameObjectDestroyed(gameObject);
|
||||
}
|
||||
|
||||
public void InitData()
|
||||
{
|
||||
moduleDict = new Dictionary<string, Data>();
|
||||
foreach (var item in Global.Instance.appData.Modules)
|
||||
{
|
||||
if (item.type == "Exam" || item.type == "All")
|
||||
{
|
||||
Data data = new Data() { scoreDict = new Dictionary<string, ScoreStep>() };
|
||||
moduleDict.Add(item.ModuleName, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void OnStart(OnModuleStart start)
|
||||
{
|
||||
var data = moduleDict[Global.Instance.curModule.ModuleName];
|
||||
data.scoreDict.Clear();
|
||||
foreach (var item in Global.Instance.curModule.score.scores)
|
||||
{
|
||||
item.value = 0;
|
||||
scoreDict.Add(item.step + item.name, item);
|
||||
data.scoreDict.Add(item.step + item.name, item);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Dictionary<string, ScoreStep> GetCurScore()
|
||||
{
|
||||
var data = moduleDict[Global.Instance.curModule.ModuleName];
|
||||
return data.scoreDict;
|
||||
}
|
||||
|
||||
|
||||
public void Add(string key, float value)
|
||||
{
|
||||
var data = moduleDict[Global.Instance.curModule.ModuleName];
|
||||
var scoreDict = data.scoreDict;
|
||||
if (scoreDict.ContainsKey(key))
|
||||
{
|
||||
scoreDict[key].value += value;
|
||||
@ -43,6 +77,8 @@ public class ScoreController : MonoSingleton<ScoreController>
|
||||
|
||||
public void Set(string key, float value)
|
||||
{
|
||||
var data = moduleDict[Global.Instance.curModule.ModuleName];
|
||||
var scoreDict = data.scoreDict;
|
||||
if (scoreDict.ContainsKey(key))
|
||||
{
|
||||
scoreDict[key].value = value;
|
||||
@ -53,6 +89,8 @@ public class ScoreController : MonoSingleton<ScoreController>
|
||||
|
||||
private void OnQuit(OnModuleQuit quit)
|
||||
{
|
||||
var data = moduleDict[Global.Instance.curModule.ModuleName];
|
||||
var scoreDict = data.scoreDict;
|
||||
scoreDict.Clear();
|
||||
}
|
||||
|
||||
|
||||
@ -49,9 +49,12 @@ namespace QFramework.Example
|
||||
{
|
||||
|
||||
Content.RemoveAllChildren();
|
||||
|
||||
float sum = 0;
|
||||
float score = 0;
|
||||
foreach (var item in ScoreController.Instance.scoreDict)
|
||||
foreach (var moduleDict in ScoreController.Instance.moduleDict)
|
||||
{
|
||||
foreach (var item in moduleDict.Value.scoreDict)
|
||||
{
|
||||
GameObject obj = GameObject.Instantiate(ItemPrefab.gameObject, Content);
|
||||
obj.transform.Find("Step").GetComponent<TextMeshProUGUI>().text = item.Value.step;
|
||||
@ -61,8 +64,11 @@ namespace QFramework.Example
|
||||
sum += float.Parse(item.Value.sum);
|
||||
score += item.Value.value;
|
||||
}
|
||||
}
|
||||
|
||||
this.Score.text = score.ToString();
|
||||
this.Sum.text = sum.ToString();
|
||||
|
||||
}
|
||||
|
||||
protected override void OnShow()
|
||||
|
||||
@ -20,6 +20,7 @@ namespace QFramework.Example
|
||||
public string wrongEvent;
|
||||
public float rightScore;
|
||||
public float wrongScore;
|
||||
public float totalScore;
|
||||
public string scoreStepName;
|
||||
public float autoHideResult = -1;
|
||||
}
|
||||
@ -42,6 +43,10 @@ namespace QFramework.Example
|
||||
protected override void OnOpen(IUIData uiData = null)
|
||||
{
|
||||
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged).UnRegisterWhenDisabled(gameObject);
|
||||
if (mData.totalScore > 0)
|
||||
{
|
||||
ScoreController.Instance.Add(mData.scoreStepName, mData.totalScore);
|
||||
}
|
||||
mResLoader = ResLoader.Allocate();
|
||||
mData = uiData as UIToolsData ?? new UIToolsData();
|
||||
if (string.IsNullOrEmpty(mData.answer) == false)
|
||||
|
||||
@ -46,6 +46,9 @@ namespace XMLTool
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public class Score
|
||||
{
|
||||
public List<ScoreStep> scores;
|
||||
@ -440,6 +443,11 @@ namespace XMLTool
|
||||
{
|
||||
act.args.Add("wrongScore", wrongScore.Value);
|
||||
}
|
||||
var totalScore = action.Attribute("totalScore");
|
||||
if (totalScore != null)
|
||||
{
|
||||
act.args.Add("totalScore", totalScore.Value);
|
||||
}
|
||||
var scoreStepName = action.Attribute("scoreStepName");
|
||||
if (scoreStepName != null)
|
||||
{
|
||||
|
||||
@ -23,7 +23,8 @@
|
||||
<Action type="Btns" value="按钮1,按钮2,按钮3"></Action>
|
||||
<!--用于右侧道具栏选择正确的道具 event用于配合StrEventCondition 做检测
|
||||
rightScore 正确选择一个 得分 wrongScore 错误一个 得分 scoreStepName是评分的key
|
||||
autoHide =-1 则点击结束 否则 等待对应时间后自动结束-->
|
||||
autoHide =-1 则点击结束 否则 等待对应时间后自动结束
|
||||
totalScore 是配合wrongScore的用于初始化一个分数 然后选择扣分-->
|
||||
<Action type="UITools" devices="道具名字1" answers="正确道具"
|
||||
setActive="true"
|
||||
rightLabel="提示:器械选择正确。"
|
||||
@ -32,6 +33,7 @@
|
||||
wrongEvent=""
|
||||
rightScore=""
|
||||
wrongScore=""
|
||||
totalScore=""
|
||||
scoreStepName="手术准备器械选择"
|
||||
autoHide="-1"></Action>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user