From 297b9fac226a219bb77b75f7dd2e6755a313caa4 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Thu, 26 Dec 2024 15:44:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=96=87=E5=AD=97=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E9=A2=98=E8=AF=84=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Actions/ActionHelper.cs | 4 +- Assets/Scripts/Actions/TextQuestionAction.cs | 30 ++++++-- Assets/Scripts/UI/UITextQuestion.cs | 78 ++++++++++++++++++++ Assets/Scripts/Xml/XmlParser.cs | 69 ++++++++++++++--- Doc/Xml配置文档.xml | 15 +++- 5 files changed, 174 insertions(+), 22 deletions(-) diff --git a/Assets/Scripts/Actions/ActionHelper.cs b/Assets/Scripts/Actions/ActionHelper.cs index b75e54c6..c6a99514 100644 --- a/Assets/Scripts/Actions/ActionHelper.cs +++ b/Assets/Scripts/Actions/ActionHelper.cs @@ -115,8 +115,8 @@ public class ActionHelper case "TextQuestion": { - var strAction = (XMLTool.StringListAction)act; - return TextQuestionAction.Allocate(strAction.args[0], strAction.args[1], strAction.args[2], strAction.args[3], strAction.args[4], strAction.args[5]); + var strAction = (XMLTool.DictionaryAction)act; + return TextQuestionAction.Allocate(strAction.args); } case "Hint": { diff --git a/Assets/Scripts/Actions/TextQuestionAction.cs b/Assets/Scripts/Actions/TextQuestionAction.cs index 666632c9..7f1d1f17 100644 --- a/Assets/Scripts/Actions/TextQuestionAction.cs +++ b/Assets/Scripts/Actions/TextQuestionAction.cs @@ -20,18 +20,27 @@ public class TextQuestionAction : IAction string btns = string.Empty; string wait = string.Empty; string showAnswer = string.Empty; - public static TextQuestionAction Allocate(string title, string options, string answers, string btns, string wait, string showAnswer, System.Action onDelayFinish = null) + string rightScore = string.Empty; + string errorScore = string.Empty; + string scoreName = string.Empty; + string absolutely = string.Empty; + + public static TextQuestionAction Allocate(Dictionary datas, System.Action onDelayFinish = null) { var retNode = mPool.Allocate(); retNode.ActionID = ActionKit.ID_GENERATOR++; retNode.Deinited = false; retNode.Reset(); - retNode.title = title; - retNode.options = options; - retNode.btns = btns; - retNode.answers = answers; - retNode.wait = wait; - retNode.showAnswer = showAnswer; + retNode.title = datas.ContainsKey("title") ? datas["title"] : string.Empty; + retNode.options = datas.ContainsKey("options") ? datas["options"] : string.Empty; + retNode.btns = datas.ContainsKey("btns") ? datas["btns"] : string.Empty; + retNode.answers = datas.ContainsKey("answers") ? datas["answers"] : string.Empty; + retNode.wait = datas.ContainsKey("wait") ? datas["wait"] : string.Empty; + retNode.showAnswer = datas.ContainsKey("showAnswer") ? datas["showAnswer"] : string.Empty; + retNode.rightScore = datas.ContainsKey("rightScore") ? datas["rightScore"] : string.Empty; + retNode.errorScore = datas.ContainsKey("errorScore") ? datas["errorScore"] : string.Empty; + retNode.scoreName = datas.ContainsKey("scoreName") ? datas["scoreName"] : string.Empty; + retNode.absolutely = datas.ContainsKey("absolutely") ? datas["absolutely"] : string.Empty; return retNode; } @@ -66,6 +75,13 @@ public class TextQuestionAction : IAction data.btns = btns.Split(',').ToList(); float.TryParse(wait, out data.waitCloseTime); bool.TryParse(showAnswer, out data.showAnswer); + if (string.IsNullOrEmpty(scoreName)==false) + { + data.scoreName = scoreName; + float.TryParse(rightScore, out data.rightScore); + float.TryParse(errorScore, out data.errorScore); + bool.TryParse(absolutely, out data.absolutely); + } UIKit.OpenPanelAsync(uiData: data, canvasLevel: UILevel.PopUI).ToAction().StartGlobal(() => this.Finish()); } diff --git a/Assets/Scripts/UI/UITextQuestion.cs b/Assets/Scripts/UI/UITextQuestion.cs index e6af6366..3f8fc014 100644 --- a/Assets/Scripts/UI/UITextQuestion.cs +++ b/Assets/Scripts/UI/UITextQuestion.cs @@ -3,6 +3,9 @@ using UnityEngine.UI; using QFramework; using System.Collections.Generic; using TMPro; +using System; +using Microsoft.SqlServer.Server; +using XMLTool; namespace QFramework.Example { @@ -14,6 +17,14 @@ namespace QFramework.Example public List btns = new List(); public float waitCloseTime = -1; public bool showAnswer = false; + public float rightScore = 0; + public float errorScore = 0; + public string scoreName = string.Empty; + public string format; + /// + /// Ե ÷ Ծ͵÷ Ͳ÷ + /// + public bool absolutely = true; } public partial class UITextQuestion : UIPanel { @@ -56,6 +67,35 @@ namespace QFramework.Example } } } + + if (string.IsNullOrEmpty(mData.scoreName) == false) + { + if (mData.rightScore != 0) + { + Check(true, count => + { + if (count > 0) + { + float score = mData.rightScore / mData.answers.Count * count; + string scoreStr = score.ToString(mData.format); + ScoreController.Instance.Add(mData.scoreName, float.Parse(scoreStr)); + } + }); + } + else if(mData.errorScore != 0) + { + Check(false, count => + { + if (count > 0) + { + float score = mData.errorScore / mData.answers.Count * count; + string scoreStr = score.ToString(mData.format); + ScoreController.Instance.Add(mData.scoreName, float.Parse(scoreStr)); + } + }); + } + } + if (mData.waitCloseTime != -1) { @@ -63,12 +103,50 @@ namespace QFramework.Example return; } + Hide(); }); } } + public void Check(bool isRight, Action callback) + { + int count = 0; + if (isRight) + { + for (int i = 0; i < OptionContent.transform.childCount; i++) + { + Toggle toggle = OptionContent.transform.GetChild(i).GetComponent(); + if (mData.answers.Contains(toggle.name) && toggle.isOn) + { + count++; + } + } + if (mData.absolutely == true && count != mData.answers.Count) + { + count = 0; + } + callback?.Invoke(count); + } + else + { + for (int i = 0; i < OptionContent.transform.childCount; i++) + { + Toggle toggle = OptionContent.transform.GetChild(i).GetComponent(); + if (mData.answers.Contains(toggle.name) && toggle.isOn == false) + { + count++; + } + } + if (mData.absolutely == true && count > 0) + { + count = mData.answers.Count; + } + callback?.Invoke(count); + } + } + protected override void OnShow() { } diff --git a/Assets/Scripts/Xml/XmlParser.cs b/Assets/Scripts/Xml/XmlParser.cs index b1ab911e..51db6872 100644 --- a/Assets/Scripts/Xml/XmlParser.cs +++ b/Assets/Scripts/Xml/XmlParser.cs @@ -1,3 +1,4 @@ +using Microsoft.SqlServer.Server; using QFramework; using System.Collections.Generic; using System.Linq; @@ -463,13 +464,63 @@ namespace XMLTool break; case "TextQuestion": { - var act = new StringListAction(); - act.args.Add(action.Attribute("title").Value); - act.args.Add(action.Attribute("options").Value); - act.args.Add(action.Attribute("answers").Value); - act.args.Add(action.Attribute("btns").Value); - act.args.Add(action.Attribute("wait").Value); - act.args.Add(action.Attribute("showAnswer").Value); + var act = new DictionaryAction(); + XAttribute title = action.Attribute("title"); + if (title != null) + { + act.args.Add("title", title.Value); + } + XAttribute options = action.Attribute("options"); + if (options != null) + { + act.args.Add("options", options.Value); + } + XAttribute answers = action.Attribute("answers"); + if (answers != null) + { + act.args.Add("answers", answers.Value); + } + XAttribute btns = action.Attribute("btns"); + if (btns != null) + { + act.args.Add("btns", btns.Value); + } + XAttribute wait = action.Attribute("wait"); + if (wait != null) + { + act.args.Add("wait", wait.Value); + } + XAttribute showAnswer = action.Attribute("showAnswer"); + if (showAnswer != null) + { + act.args.Add("showAnswer", showAnswer.Value); + } + XAttribute rightScore = action.Attribute("rightScore"); + if (rightScore != null) + { + act.args.Add("rightScore", rightScore.Value); + } + XAttribute errorScore = action.Attribute("wrongScore"); + if (errorScore != null) + { + act.args.Add("errorScore", errorScore.Value); + } + XAttribute scoreName = action.Attribute("scoreName"); + if (scoreName != null) + { + act.args.Add("scoreName", scoreName.Value); + } + XAttribute absolutely = action.Attribute("absolutely"); + if (absolutely != null) + { + act.args.Add("absolutely", absolutely.Value); + } + + XAttribute format = action.Attribute("format"); + if (format != null) + { + act.args.Add("format", format.Value); + } newAction = act; } break; @@ -595,7 +646,7 @@ namespace XMLTool } else { - act.args.Add("nearTime","0"); + act.args.Add("nearTime", "0"); } XAttribute normalTime = action.Attribute("normalTime"); @@ -605,7 +656,7 @@ namespace XMLTool } else { - act.args.Add("normalTime","0"); + act.args.Add("normalTime", "0"); } XAttribute isNear = action.Attribute("isNear"); if (isNear != null) diff --git a/Doc/Xml配置文档.xml b/Doc/Xml配置文档.xml index fee1a0fe..79bdef6d 100644 --- a/Doc/Xml配置文档.xml +++ b/Doc/Xml配置文档.xml @@ -31,8 +31,14 @@ - - + + @@ -91,12 +97,12 @@ - +