增加行数据结构

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 Row
{
public string name = "";
public List<Item> items = new List<Item>();
}
public class Item
{
public string pic;
@ -32,7 +38,7 @@ namespace XMLTool
}
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":
{
var dictAction = (XMLTool.ImageSelectMapAction)act;
return QFramework.ImageSelectMapAction.Allocate(dictAction.args,dictAction.items);
return QFramework.ImageSelectMapAction.Allocate(dictAction.args,dictAction.rows);
}
default:
Debug.LogError($"没有找到此Action的类型{act.Type}");

View File

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

View File

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

View File

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

View File

@ -1718,13 +1718,20 @@ namespace XMLTool
{
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,
name = itemData.Attribute("name")?.Value
});
row.items.Add(new ImageSelectMapAction.Item()
{
pic = itemData.Attribute("pic")?.Value,
name = itemData.Attribute("name")?.Value
});
}
}
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>
<Icon>1折射仪.png</Icon>
<Scene>ZheSheYiScene</Scene>
<Type>All</Type>
<Name>宝石分类</Name>
<OnlyCurScore>true</OnlyCurScore>
<Icon>1折射仪.png</Icon>
<Scene>ZheSheYiScene</Scene>
<Type>All</Type>
<Name>宝石分类</Name>
<OnlyCurScore>true</OnlyCurScore>
<!--状态机-->
<FSM name="状态机1">
@ -23,39 +23,54 @@
wrongLabel=""
finishedEvent="全部完成"
rightBg="baoshi/背景图.png">
<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>
<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>
<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 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="黄色\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>
<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>
<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>
<Condition type="StrEvent" value="全部完成"></Condition>
<Action type="TipWindow" value="恭喜你完成当前模块" btns="确定" audio=""></Action>
</Action>
</Enter>
</State>
@ -67,7 +82,7 @@
</Module>