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