扩展UITools功能支持自动关闭

This commit is contained in:
shenjianxing 2025-01-14 18:16:35 +08:00
parent 114b996c3c
commit 632966423e
6 changed files with 71 additions and 80 deletions

View File

@ -111,10 +111,8 @@ public class ActionHelper
}
case "UITools":
{
var strAction = (XMLTool.StringListAction)act;
return UIToolsAction.Allocate(strAction.args[0], strAction.args[1], strAction.args[2], strAction.args[3],
strAction.args[4], strAction.args[5], strAction.args[6], strAction.args[7],
strAction.args[8], strAction.args[9]);
var strAction = (XMLTool.DictionaryAction)act;
return UIToolsAction.Allocate(strAction.args);
}
case "PointQuestion":
return PointQuestionAction.Allocate(act.Value);

View File

@ -14,35 +14,34 @@ public class UIToolsAction : IAction
private static readonly SimpleObjectPool<UIToolsAction> mPool =
new SimpleObjectPool<UIToolsAction>(() => new UIToolsAction(), null, 10);
string answer = string.Empty;
string devices = string.Empty;
string setActive = string.Empty;
string rightLabel = string.Empty;
string wrongLabel = string.Empty;
string rightEvent = string.Empty;
string wrongEvent = string.Empty;
string rightScore = string.Empty;
string wrongScore = string.Empty;
string scoreStepName = string.Empty;
public static UIToolsAction Allocate(string devices, string answer,
string setActive, string rightLabel, string wrongLabel, string rightEvent,
string wrongEvent,string rightScore, string wrongScore, string scoreStepName,
System.Action onDelayFinish = null)
string answer;
string devices;
string setActive;
string rightLabel;
string wrongLabel;
string rightEvent;
string wrongEvent;
string rightScore;
string wrongScore;
string scoreStepName;
string autoHide;
public static UIToolsAction Allocate(Dictionary<string, string> datas, System.Action onDelayFinish = null)
{
var retNode = mPool.Allocate();
retNode.ActionID = ActionKit.ID_GENERATOR++;
retNode.Deinited = false;
retNode.Reset();
retNode.answer = answer;
retNode.devices = devices;
retNode.setActive = setActive;
retNode.rightLabel = rightLabel;
retNode.wrongLabel = wrongLabel;
retNode.rightEvent = rightEvent;
retNode.wrongEvent = wrongEvent;
retNode.rightScore = rightScore;
retNode.wrongScore = wrongScore;
retNode.scoreStepName = scoreStepName;
retNode.answer = datas.ContainsKey("answers") ? datas["answers"] : "";
retNode.devices = datas.ContainsKey("devices") ? datas["devices"] : "";
retNode.setActive = datas.ContainsKey("setActive") ? datas["setActive"] : "true";
retNode.rightLabel = datas.ContainsKey("rightLabel") ? datas["rightLabel"] : "";
retNode.wrongLabel = datas.ContainsKey("wrongLabel") ? datas["wrongLabel"] : "";
retNode.rightEvent = datas.ContainsKey("rightEvent") ? datas["rightEvent"] : "";
retNode.wrongEvent = datas.ContainsKey("wrongEvent") ? datas["wrongEvent"] : "";
retNode.rightScore = datas.ContainsKey("rightScore") ? datas["rightScore"] : "";
retNode.wrongScore = datas.ContainsKey("wrongScore") ? datas["wrongScore"] : "";
retNode.scoreStepName = datas.ContainsKey("scoreStepName") ? datas["scoreStepName"] : "";
retNode.autoHide = datas.ContainsKey("autoHide") ? datas["autoHide"] : "";
return retNode;
}
@ -78,6 +77,7 @@ public class UIToolsAction : IAction
float.TryParse(wrongScore, out data.wrongScore);
data.scoreStepName = scoreStepName;
bool.TryParse(setActive, out data.SetActive);
float.TryParse(autoHide, out data.autoHideResult);
UIKit.OpenPanelAsync<UITools>(uiData: data, canvasLevel: UILevel.PopUI).ToAction().StartGlobal(() => this.Finish());
}

View File

@ -11,6 +11,7 @@ namespace QFramework.Example
{
public bool isRight = false;
public string label;
public float autoHideTime = -1;
public Action callback;
}
public partial class UIResultTip : UIPanel
@ -44,15 +45,31 @@ namespace QFramework.Example
}
obj.SetActive(true);
obj.transform.Find("Bg/Label").GetComponent<TextMeshProUGUI>().text = mData.label;
if (mData.autoHideTime == -1)
{
Button btn = obj.GetComponent<Button>();
btn.onClick.RemoveAllListeners();
btn.onClick.AddListener(() =>
{
mData.callback?.Invoke();
Hide();
SetHide();
});
}
else
{
ActionKit.Delay(mData.autoHideTime, () =>
{
SetHide();
});
}
}
public void SetHide()
{
mData.callback?.Invoke();
Hide();
}
protected override void OnShow()
{
}

View File

@ -21,6 +21,7 @@ namespace QFramework.Example
public float rightScore;
public float wrongScore;
public string scoreStepName;
public float autoHideResult = -1;
}
public partial class UITools : UIPanel
{

View File

@ -402,82 +402,54 @@ namespace XMLTool
break;
case "UITools":
{
var act = new StringListAction();
act.args.Add(action.Attribute("devices").Value);
act.args.Add(action.Attribute("answers").Value);
var act = new DictionaryAction();
act.args.Add("devices", action.Attribute("devices").Value);
act.args.Add("answers", action.Attribute("answers").Value);
var setActive = action.Attribute("setActive");
if (setActive != null)
{
act.args.Add(setActive.Value);
}
else
{
act.args.Add("true");
act.args.Add("setActive", setActive.Value);
}
var rightLabel = action.Attribute("rightLabel");
if (rightLabel != null)
{
act.args.Add(rightLabel.Value);
}
else
{
act.args.Add("");
act.args.Add("rightLabel", rightLabel.Value);
}
var wrongLabel = action.Attribute("wrongLabel");
if (wrongLabel != null)
{
act.args.Add(wrongLabel.Value);
}
else
{
act.args.Add("");
act.args.Add("wrongLabel", wrongLabel.Value);
}
var rightEvent = action.Attribute("rightEvent");
if (rightEvent != null)
{
act.args.Add(rightEvent.Value);
}
else
{
act.args.Add("");
act.args.Add("rightEvent", rightEvent.Value);
}
var wrongEvent = action.Attribute("wrongEvent");
if (wrongEvent != null)
{
act.args.Add(wrongEvent.Value);
}
else
{
act.args.Add("");
act.args.Add("wrongEvent", wrongEvent.Value);
}
var rightScore = action.Attribute("rightScore");
if (rightScore != null)
{
act.args.Add(rightScore.Value);
}
else
{
act.args.Add("");
act.args.Add("rightScore", rightScore.Value);
}
var wrongScore = action.Attribute("wrongScore");
if (wrongScore != null)
{
act.args.Add(wrongScore.Value);
}
else
{
act.args.Add("");
act.args.Add("wrongScore", wrongScore.Value);
}
var scoreStepName = action.Attribute("scoreStepName");
if (scoreStepName != null)
{
act.args.Add(scoreStepName.Value);
act.args.Add("scoreStepName", scoreStepName.Value);
}
else
var autoHide = action.Attribute("autoHide");
if (autoHide != null)
{
act.args.Add("");
act.args.Add("autoHide", autoHide.Value);
}
newAction = act;
}
break;

View File

@ -21,7 +21,9 @@
<Action type="Anim" value="物体路径" deviceName="" animName="动画名字" frame="-1" speed="1"></Action>
<!--右下角生成按钮 可生成多个 用逗号分开-->
<Action type="Btns" value="按钮1,按钮2,按钮3"></Action>
<!--用于右侧道具栏选择正确的道具 event用于配合StrEventCondition 做检测 rightScore 正确选择一个 得分 wrongScore 错误一个 得分 scoreStepName是评分的key -->
<!--用于右侧道具栏选择正确的道具 event用于配合StrEventCondition 做检测
rightScore 正确选择一个 得分 wrongScore 错误一个 得分 scoreStepName是评分的key
autoHide =-1 则点击结束 否则 等待对应时间后自动结束-->
<Action type="UITools" devices="道具名字1" answers="正确道具"
setActive="true"
rightLabel="提示:器械选择正确。"
@ -30,7 +32,8 @@
wrongEvent=""
rightScore=""
wrongScore=""
scoreStepName="手术准备器械选择"></Action>
scoreStepName="手术准备器械选择"
autoHide="-1"></Action>
<!--物体点位选择 物体的中心点-->
<Action type="PointQuestion" value="路径1,路径2"></Action>