增加行数据结构

This commit is contained in:
shenjianxing 2025-04-29 13:39:30 +08:00
parent c756778eb4
commit 1996bda2c5
31 changed files with 126 additions and 75 deletions

View File

@ -25,6 +25,12 @@ namespace XMLTool
public class ImageSelectMapAction : Action public class ImageSelectMapAction : Action
{ {
public class Row
{
public string name = "";
public List<Item> items = new List<Item>();
}
public class Item public class Item
{ {
public string pic; public string pic;
@ -32,7 +38,7 @@ namespace XMLTool
} }
public Dictionary<string, string> args = new Dictionary<string, string>(); public Dictionary<string, string> args = new Dictionary<string, string>();
public List<Item> items = new List<Item>(); public List<Row> rows = new List<Row>();
} }

View File

@ -286,7 +286,7 @@ public class ActionHelper
case "ImageSelectMap": case "ImageSelectMap":
{ {
var dictAction = (XMLTool.ImageSelectMapAction)act; var dictAction = (XMLTool.ImageSelectMapAction)act;
return QFramework.ImageSelectMapAction.Allocate(dictAction.args,dictAction.items); return QFramework.ImageSelectMapAction.Allocate(dictAction.args,dictAction.rows);
} }
default: default:
Debug.LogError($"没有找到此Action的类型{act.Type}"); Debug.LogError($"没有找到此Action的类型{act.Type}");

View File

@ -21,14 +21,14 @@ namespace QFramework
private static readonly SimpleObjectPool<ImageSelectMapAction> mPool = private static readonly SimpleObjectPool<ImageSelectMapAction> mPool =
new SimpleObjectPool<ImageSelectMapAction>(() => new ImageSelectMapAction(), null, 10); new SimpleObjectPool<ImageSelectMapAction>(() => new ImageSelectMapAction(), null, 10);
Dictionary<string, string> datas; Dictionary<string, string> datas;
List<XMLTool.ImageSelectMapAction.Item> items; List<XMLTool.ImageSelectMapAction.Row> rows;
public static ImageSelectMapAction Allocate(Dictionary<string, string> datas, List<XMLTool.ImageSelectMapAction.Item> items, System.Action OnFinished = null) public static ImageSelectMapAction Allocate(Dictionary<string, string> datas, List<XMLTool.ImageSelectMapAction.Row> rows, System.Action OnFinished = 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.datas = datas; retNode.datas = datas;
retNode.items = items; retNode.rows = rows;
retNode.Reset(); retNode.Reset();
retNode.OnFinished = OnFinished; retNode.OnFinished = OnFinished;
return retNode; return retNode;
@ -70,13 +70,19 @@ namespace QFramework
data.random = false; data.random = false;
} }
foreach (var item in items) foreach (var rowItem in rows)
{ {
data.items.Add(new UIImageSelectMapData.OptionItem() var row = new UIImageSelectMapData.Row();
row.name = rowItem.name;
data.rows.Add(row);
foreach (var item in rowItem.items)
{ {
pic = item.pic, row.items.Add(new UIImageSelectMapData.OptionItem()
name = item.name {
}); pic = item.pic,
name = item.name
});
}
} }
UIKit.OpenPanelAsync<UIImageSelectMap>(uiData: data).ToAction().StartGlobal(() => UIKit.OpenPanelAsync<UIImageSelectMap>(uiData: data).ToAction().StartGlobal(() =>

View File

@ -5,7 +5,7 @@ using QFramework;
namespace QFramework.Example namespace QFramework.Example
{ {
// Generate Id:b499f0f9-a71b-40ff-a499-a5e4defad39f // Generate Id:ee191ed8-359d-4628-aa2b-d1711157540d
public partial class UIImageSelectMap public partial class UIImageSelectMap
{ {
public const string Name = "UIImageSelectMap"; public const string Name = "UIImageSelectMap";
@ -13,20 +13,23 @@ namespace QFramework.Example
[SerializeField] [SerializeField]
public RectTransform LeftContent; public RectTransform LeftContent;
[SerializeField] [SerializeField]
public RectTransform RightContent;
[SerializeField]
public UnityEngine.UI.Image LeftItem; public UnityEngine.UI.Image LeftItem;
[SerializeField] [SerializeField]
public UnityEngine.UI.Image RightItem; public UnityEngine.UI.Image RightItem;
[SerializeField] [SerializeField]
public RectTransform RightContent; public RectTransform RightRowItem;
private UIImageSelectMapData mPrivateData = null; private UIImageSelectMapData mPrivateData = null;
protected override void ClearUIComponents() protected override void ClearUIComponents()
{ {
LeftContent = null; LeftContent = null;
RightContent = null;
LeftItem = null; LeftItem = null;
RightItem = null; RightItem = null;
RightContent = null; RightRowItem = null;
mData = null; mData = null;
} }

View File

@ -5,6 +5,7 @@ using System.Collections.Generic;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using System; using System;
using TMPro; using TMPro;
using System.Xml;
namespace QFramework.Example namespace QFramework.Example
{ {
@ -15,6 +16,11 @@ namespace QFramework.Example
public string pic; public string pic;
public string name; public string name;
} }
public class Row
{
public string name;
public List<OptionItem> items = new List<OptionItem>();
}
public string scoreName; public string scoreName;
public float totalScore; public float totalScore;
public float rightScore; public float rightScore;
@ -23,7 +29,7 @@ namespace QFramework.Example
public string wrongLabel; public string wrongLabel;
public string finishedEvent; public string finishedEvent;
public bool random = false; public bool random = false;
public List<OptionItem> items = new List<OptionItem>(); public List<Row> rows = new List<Row>();
} }
public partial class UIImageSelectMap : UIPanel public partial class UIImageSelectMap : UIPanel
@ -57,31 +63,39 @@ namespace QFramework.Example
RightContent.RemoveAllChildren(); RightContent.RemoveAllChildren();
itemDatas.Clear(); itemDatas.Clear();
leftAndRightMap.Clear(); leftAndRightMap.Clear();
foreach (var item in mData.items)
foreach (var row in mData.rows)
{ {
var leftObj = GameObject.Instantiate(LeftItem, LeftContent); GameObject rowObj = GameObject.Instantiate(RightRowItem.gameObject, RightContent);
leftObj.name = item.pic; rowObj.transform.Find("Type").GetComponent<TextMeshProUGUI>().text = row.name.Replace("\\n", "\n");
var path = Global.imagePath + item.pic; Transform itemContent = rowObj.transform.Find("Items");
loader.Add2Load(path.ToNetImageResName(), (success, res) => foreach (var item in row.items)
{ {
if (success) var rightObj = GameObject.Instantiate(RightItem, itemContent);
rightObj.name = item.pic;
rightObj.transform.Find("PicBg/Pic").GetComponent<Image>().color = new Color(1, 1, 1, 0);
rightObj.OnPointerEnterEvent(RightOnEnter);
rightObj.OnPointerExitEvent(RightOnExit);
rightObj.OnPointerClickEvent(RightOnClick);
var leftObj = GameObject.Instantiate(LeftItem, LeftContent);
leftObj.name = item.pic;
var path = Global.imagePath + item.pic;
loader.Add2Load(path.ToNetImageResName(), (success, res) =>
{ {
leftObj.GetComponent<Image>().sprite = Utility.GetSprite(res.Asset as Texture2D); if (success)
} {
}); leftObj.GetComponent<Image>().sprite = Utility.GetSprite(res.Asset as Texture2D);
}
});
leftObj.OnBeginDragEvent(LeftOnBeginDrag); leftObj.OnBeginDragEvent(LeftOnBeginDrag);
leftObj.OnDragEvent(LeftOnDrag); leftObj.OnDragEvent(LeftOnDrag);
leftObj.OnEndDragEvent(LeftOnEndDrag); leftObj.OnEndDragEvent(LeftOnEndDrag);
itemDatas.Add(leftObj.gameObject, item); itemDatas.Add(leftObj.gameObject, item);
}
var rightObj = GameObject.Instantiate(RightItem, RightContent);
rightObj.name = item.pic;
rightObj.transform.Find("PicBg/Pic").GetComponent<Image>().color = new Color(1, 1, 1, 0);
rightObj.OnPointerEnterEvent(RightOnEnter);
rightObj.OnPointerExitEvent(RightOnExit);
rightObj.OnPointerClickEvent(RightOnClick);
} }
if (mData.random) if (mData.random)
{ {
Utility.ShuffleChildObjects(LeftContent); Utility.ShuffleChildObjects(LeftContent);
@ -183,7 +197,7 @@ namespace QFramework.Example
return false; return false;
} }
} }
return leftAndRightMap.Count == mData.items.Count; return leftAndRightMap.Count == itemDatas.Count;
} }
private void LeftOnDrag(PointerEventData data) private void LeftOnDrag(PointerEventData data)

View File

@ -1718,13 +1718,20 @@ namespace XMLTool
{ {
act.args.Add("random", random.Value); act.args.Add("random", random.Value);
} }
foreach (var itemData in action.Elements("Item"))
foreach (var rowData in action.Elements("Row"))
{ {
act.items.Add(new ImageSelectMapAction.Item() var row = new ImageSelectMapAction.Row();
row.name = rowData.Attribute("name")?.Value;
act.rows.Add(row);
foreach (var itemData in rowData.Elements("Item"))
{ {
pic = itemData.Attribute("pic")?.Value, row.items.Add(new ImageSelectMapAction.Item()
name = itemData.Attribute("name")?.Value {
}); pic = itemData.Attribute("pic")?.Value,
name = itemData.Attribute("name")?.Value
});
}
} }
newAction = act; newAction = act;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
Data/Image/yushi/墨翠.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
Data/Image/yushi/碧玉.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
Data/Image/yushi/糖玉.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
Data/Image/yushi/阳绿.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
Data/Image/yushi/青玉.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
Data/Image/yushi/黄翡.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -2,11 +2,11 @@
<Module> <Module>
<Icon>1折射仪.png</Icon> <Icon>1折射仪.png</Icon>
<Scene>ZheSheYiScene</Scene> <Scene>ZheSheYiScene</Scene>
<Type>All</Type> <Type>All</Type>
<Name>宝石分类</Name> <Name>宝石分类</Name>
<OnlyCurScore>true</OnlyCurScore> <OnlyCurScore>true</OnlyCurScore>
<!--状态机--> <!--状态机-->
<FSM name="状态机1"> <FSM name="状态机1">
@ -23,30 +23,45 @@
wrongLabel="" wrongLabel=""
finishedEvent="全部完成" finishedEvent="全部完成"
rightBg="baoshi/背景图.png"> rightBg="baoshi/背景图.png">
<Item name="碧玺(红)" pic="baoshi/碧玺(红).png"></Item>
<Item name="玻璃猫眼(白)" pic="baoshi/玻璃猫眼(白).png"></Item> <Row name="红色\n粉红">
<Item name="查罗石" pic="baoshi/查罗石.png"></Item> <Item name="碧玺(红)" pic="baoshi/碧玺(红).png"></Item>
<Item name="发晶(无色)" pic="baoshi/发晶(无色).png"></Item> <Item name="合成红宝石" pic="baoshi/合成红宝石.png"></Item>
<Item name="方柱石" pic="baoshi/方柱石.png"></Item> <Item name="红玛瑙" pic="baoshi/红玛瑙.png"></Item>
<Item name="橄榄石" pic="baoshi/橄榄石.png"></Item> <Item name="菱锰矿" pic="baoshi/菱锰矿.png"></Item>
<Item name="合成红宝石" pic="baoshi/合成红宝石.png"></Item> </Row>
<Item name="合成尖晶石" pic="baoshi/合成尖晶石.png"></Item> <Row name="黄色\n橙色">
<Item name="红玛瑙" pic="baoshi/红玛瑙.png"></Item>
<Item name="菱锰矿" pic="baoshi/菱锰矿.png"></Item> <Item name="合成立方氧化锆" pic="baoshi/合成立方氧化锆.png"></Item>
<Item name="合成立方氧化锆" pic="baoshi/合成立方氧化锆.png"></Item> <Item name="磷灰石" pic="baoshi/磷灰石.png"></Item>
<Item name="磷灰石" pic="baoshi/磷灰石.png"></Item> <Item name="石英岩玉" pic="baoshi/石英岩玉.png"></Item>
<Item name="石英岩玉" pic="baoshi/石英岩玉.png"></Item> <Item name="月光石(黄)" pic="baoshi/月光石(黄).png"></Item>
<Item name="月光石(黄)" pic="baoshi/月光石(黄).png"></Item> </Row>
<Item name="合成蓝宝石" pic="baoshi/合成蓝宝石.png"></Item> <Row name="蓝色">
<Item name="托帕石" pic="baoshi/托帕石.png"></Item> <Item name="合成尖晶石" pic="baoshi/合成尖晶石.png"></Item>
<Item name="玉髓(蓝)" pic="baoshi/玉髓(蓝).png"></Item> <Item name="合成蓝宝石" pic="baoshi/合成蓝宝石.png"></Item>
<Item name="碧玺(绿)" pic="baoshi/碧玺(绿).png"></Item> <Item name="托帕石" pic="baoshi/托帕石.png"></Item>
<Item name="合成祖母绿" pic="baoshi/合成祖母绿.png"></Item> <Item name="玉髓(蓝)" pic="baoshi/玉髓(蓝).png"></Item>
<Item name="和田玉(碧玉)" pic="baoshi/和田玉(碧玉).png"></Item> </Row>
<Item name="欧泊(白)" pic="baoshi/欧泊(白).png"></Item> <Row name="绿色">
<Item name="月光石(白)" pic="baoshi/月光石(白).png"></Item> <Item name="碧玺(绿)" pic="baoshi/碧玺(绿).png"></Item>
<Item name="合成蓝宝石" pic="baoshi/合成蓝宝石.png"></Item> <Item name="橄榄石" pic="baoshi/橄榄石.png"></Item>
<Item name="紫晶" pic="baoshi/紫晶.png"></Item> <Item name="合成祖母绿" pic="baoshi/合成祖母绿.png"></Item>
<Item name="和田玉(碧玉)" pic="baoshi/和田玉(碧玉).png"></Item>
</Row>
<Row name="无色\n">
<Item name="玻璃猫眼(白)" pic="baoshi/玻璃猫眼(白).png"></Item>
<Item name="发晶(无色)" pic="baoshi/发晶(无色).png"></Item>
<Item name="欧泊(白)" pic="baoshi/欧泊(白).png"></Item>
<Item name="月光石(白)" pic="baoshi/月光石(白).png"></Item>
</Row>
<Row name="紫色">
<Item name="查罗石" pic="baoshi/查罗石.png"></Item>
<Item name="方柱石" pic="baoshi/方柱石.png"></Item>
<Item name="合成蓝宝石" pic="baoshi/合成蓝宝石.png"></Item>
<Item name="紫晶" pic="baoshi/紫晶.png"></Item>
</Row>
</Action> </Action>