新增文字选择题评分
This commit is contained in:
parent
f1b1d91758
commit
297b9fac22
@ -115,8 +115,8 @@ public class ActionHelper
|
|||||||
case "TextQuestion":
|
case "TextQuestion":
|
||||||
{
|
{
|
||||||
|
|
||||||
var strAction = (XMLTool.StringListAction)act;
|
var strAction = (XMLTool.DictionaryAction)act;
|
||||||
return TextQuestionAction.Allocate(strAction.args[0], strAction.args[1], strAction.args[2], strAction.args[3], strAction.args[4], strAction.args[5]);
|
return TextQuestionAction.Allocate(strAction.args);
|
||||||
}
|
}
|
||||||
case "Hint":
|
case "Hint":
|
||||||
{
|
{
|
||||||
|
|||||||
@ -20,18 +20,27 @@ public class TextQuestionAction : IAction
|
|||||||
string btns = string.Empty;
|
string btns = string.Empty;
|
||||||
string wait = string.Empty;
|
string wait = string.Empty;
|
||||||
string showAnswer = 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<string, string> datas, System.Action onDelayFinish = null)
|
||||||
{
|
{
|
||||||
var retNode = mPool.Allocate();
|
var retNode = mPool.Allocate();
|
||||||
retNode.ActionID = ActionKit.ID_GENERATOR++;
|
retNode.ActionID = ActionKit.ID_GENERATOR++;
|
||||||
retNode.Deinited = false;
|
retNode.Deinited = false;
|
||||||
retNode.Reset();
|
retNode.Reset();
|
||||||
retNode.title = title;
|
retNode.title = datas.ContainsKey("title") ? datas["title"] : string.Empty;
|
||||||
retNode.options = options;
|
retNode.options = datas.ContainsKey("options") ? datas["options"] : string.Empty;
|
||||||
retNode.btns = btns;
|
retNode.btns = datas.ContainsKey("btns") ? datas["btns"] : string.Empty;
|
||||||
retNode.answers = answers;
|
retNode.answers = datas.ContainsKey("answers") ? datas["answers"] : string.Empty;
|
||||||
retNode.wait = wait;
|
retNode.wait = datas.ContainsKey("wait") ? datas["wait"] : string.Empty;
|
||||||
retNode.showAnswer = showAnswer;
|
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;
|
return retNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,6 +75,13 @@ public class TextQuestionAction : IAction
|
|||||||
data.btns = btns.Split(',').ToList();
|
data.btns = btns.Split(',').ToList();
|
||||||
float.TryParse(wait, out data.waitCloseTime);
|
float.TryParse(wait, out data.waitCloseTime);
|
||||||
bool.TryParse(showAnswer, out data.showAnswer);
|
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<UITextQuestion>(uiData: data, canvasLevel: UILevel.PopUI).ToAction().StartGlobal(() => this.Finish());
|
UIKit.OpenPanelAsync<UITextQuestion>(uiData: data, canvasLevel: UILevel.PopUI).ToAction().StartGlobal(() => this.Finish());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,9 @@ using UnityEngine.UI;
|
|||||||
using QFramework;
|
using QFramework;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
|
using System;
|
||||||
|
using Microsoft.SqlServer.Server;
|
||||||
|
using XMLTool;
|
||||||
|
|
||||||
namespace QFramework.Example
|
namespace QFramework.Example
|
||||||
{
|
{
|
||||||
@ -14,6 +17,14 @@ namespace QFramework.Example
|
|||||||
public List<string> btns = new List<string>();
|
public List<string> btns = new List<string>();
|
||||||
public float waitCloseTime = -1;
|
public float waitCloseTime = -1;
|
||||||
public bool showAnswer = false;
|
public bool showAnswer = false;
|
||||||
|
public float rightScore = 0;
|
||||||
|
public float errorScore = 0;
|
||||||
|
public string scoreName = string.Empty;
|
||||||
|
public string format;
|
||||||
|
/// <summary>
|
||||||
|
/// 绝对的 不计算分项得分 对就得分 错就不得分
|
||||||
|
/// </summary>
|
||||||
|
public bool absolutely = true;
|
||||||
}
|
}
|
||||||
public partial class UITextQuestion : UIPanel
|
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)
|
if (mData.waitCloseTime != -1)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -63,12 +103,50 @@ namespace QFramework.Example
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Hide();
|
Hide();
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Check(bool isRight, Action<int> callback)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
if (isRight)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < OptionContent.transform.childCount; i++)
|
||||||
|
{
|
||||||
|
Toggle toggle = OptionContent.transform.GetChild(i).GetComponent<Toggle>();
|
||||||
|
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<Toggle>();
|
||||||
|
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()
|
protected override void OnShow()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
using Microsoft.SqlServer.Server;
|
||||||
using QFramework;
|
using QFramework;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -463,13 +464,63 @@ namespace XMLTool
|
|||||||
break;
|
break;
|
||||||
case "TextQuestion":
|
case "TextQuestion":
|
||||||
{
|
{
|
||||||
var act = new StringListAction();
|
var act = new DictionaryAction();
|
||||||
act.args.Add(action.Attribute("title").Value);
|
XAttribute title = action.Attribute("title");
|
||||||
act.args.Add(action.Attribute("options").Value);
|
if (title != null)
|
||||||
act.args.Add(action.Attribute("answers").Value);
|
{
|
||||||
act.args.Add(action.Attribute("btns").Value);
|
act.args.Add("title", title.Value);
|
||||||
act.args.Add(action.Attribute("wait").Value);
|
}
|
||||||
act.args.Add(action.Attribute("showAnswer").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;
|
newAction = act;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -595,7 +646,7 @@ namespace XMLTool
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
act.args.Add("nearTime","0");
|
act.args.Add("nearTime", "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
XAttribute normalTime = action.Attribute("normalTime");
|
XAttribute normalTime = action.Attribute("normalTime");
|
||||||
@ -605,7 +656,7 @@ namespace XMLTool
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
act.args.Add("normalTime","0");
|
act.args.Add("normalTime", "0");
|
||||||
}
|
}
|
||||||
XAttribute isNear = action.Attribute("isNear");
|
XAttribute isNear = action.Attribute("isNear");
|
||||||
if (isNear != null)
|
if (isNear != null)
|
||||||
|
|||||||
@ -31,8 +31,14 @@
|
|||||||
|
|
||||||
<!--物体点位选择 物体的中心点-->
|
<!--物体点位选择 物体的中心点-->
|
||||||
<Action type="PointQuestion" value="路径1,路径2"></Action>
|
<Action type="PointQuestion" value="路径1,路径2"></Action>
|
||||||
<!--文字选择题-->
|
<!--文字选择题 scoreName="分数名"
|
||||||
<Action type="TextQuestion" title="这里是标题" options="A.111|B.222|C.333|D.4444" answers="2" btns="确定" wait="1" showAnswer="true"></Action>
|
rightScore="5" 可以是正确加分
|
||||||
|
wrongScore="-5" 也可以是错误减分
|
||||||
|
absolutely="false" true错一个选项就扣全部分 false按错的选项数量来算分
|
||||||
|
format="{0:F1}" F1代表保留1位小数 F2代表2位 F0代表不保留小数
|
||||||
|
注意:rightScore与wrongScore不能同时存在 同时存在则只生效rightScore
|
||||||
|
-->
|
||||||
|
<Action type="TextQuestion" title="这里是标题" options="A.111|B.222|C.333|D.4444" answers="2" btns="确定" wait="1" showAnswer="true" scoreName="分数名" rightScore="5" wrongScore="-5" absolutely="false" format="{0:F1}"></Action>
|
||||||
<!--提示 time为显示的时间 -1则一直显示 icon是前面的绿色图标是否显示 audio是音频 位于data文件夹下的Audio-->
|
<!--提示 time为显示的时间 -1则一直显示 icon是前面的绿色图标是否显示 audio是音频 位于data文件夹下的Audio-->
|
||||||
<Action type="Hint" value="这里是文字描述" time="5" icon="false" audio="音频.mp3"></Action>
|
<Action type="Hint" value="这里是文字描述" time="5" icon="false" audio="音频.mp3"></Action>
|
||||||
<!--设置变量 value只能是数字可以是小数-->
|
<!--设置变量 value只能是数字可以是小数-->
|
||||||
@ -91,12 +97,12 @@
|
|||||||
<Action type="Script" value="MyAction" finishedEvent="111"/>
|
<Action type="Script" value="MyAction" finishedEvent="111"/>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
给物体设置Collider path是物体路径 DeviceName是Device名字 与path二选一 colliderType:AddBox AddMesh Remove Active
|
给物体设置Collider value是物体路径 DeviceName是Device名字 与path二选一 colliderType:AddBox AddMesh Remove Active
|
||||||
当colliderType为AddBox的时候 args用|分割后 第一个参数是 中心点 第二个参数是box碰撞的大小
|
当colliderType为AddBox的时候 args用|分割后 第一个参数是 中心点 第二个参数是box碰撞的大小
|
||||||
当colliderType为Active的时候 args为false或者是true
|
当colliderType为Active的时候 args为false或者是true
|
||||||
当colliderType为AddMesh和Remove的时候 args不需要
|
当colliderType为AddMesh和Remove的时候 args不需要
|
||||||
-->
|
-->
|
||||||
<Action type="Collider" path="路径和DeviceName二选一" deviceName="肠钳" colliderType="AddBox" args="0,0,0|1,1,1"></Action>
|
<Action type="Collider" value="路径和DeviceName二选一" deviceName="肠钳" colliderType="AddBox" args="0,0,0|1,1,1"></Action>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
倒计时动画 value是文字描述 支持富文本 要按照xml的语法 把<>括号转义 <代表< >代表>
|
倒计时动画 value是文字描述 支持富文本 要按照xml的语法 把<>括号转义 <代表< >代表>
|
||||||
@ -105,6 +111,7 @@
|
|||||||
finishedEvent 是倒计时结束后的回调
|
finishedEvent 是倒计时结束后的回调
|
||||||
needClick如果为true 动画结束后不会自动小时 需要点击空白处
|
needClick如果为true 动画结束后不会自动小时 需要点击空白处
|
||||||
reverse 是时钟倒计时动画是否倒序播放
|
reverse 是时钟倒计时动画是否倒序播放
|
||||||
|
format="{0:F1}" F1代表保留1位小数 F2代表2位 F0代表不保留小数
|
||||||
-->
|
-->
|
||||||
<Action type="TimeTip" value="这里是文字描述<color=#FF00FF>{0}</color>-{1}" time="5" values="5,10|50,100" format="{0:F1}" finishedEvent="close" needClick="false" reverse="false" ></Action>
|
<Action type="TimeTip" value="这里是文字描述<color=#FF00FF>{0}</color>-{1}" time="5" values="5,10|50,100" format="{0:F1}" finishedEvent="close" needClick="false" reverse="false" ></Action>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user