(client):feat:添加对列表定义读取的支持,ui管理器将对没有键的窗口也进行统一管理

This commit is contained in:
m0_75251201
2025-07-20 15:21:21 +08:00
parent 2e74833a18
commit 9dcc67d710
77 changed files with 2158 additions and 3750 deletions

View File

@ -34,17 +34,49 @@ namespace Data
base.Init(xmlDef);
var nodes = xmlDef.Elements("DrawNodeDef");
if (nodes.Count() == 0)
var xElements = nodes as XElement[] ?? nodes.ToArray();
if (!xElements.Any())
return false;
foreach (var node in nodes)
{
var drawNode = new DrawNodeDef();
drawNode.Init(node);
drawNodes.Add(drawNode);
}
foreach (var node in xElements)
{
var drawNode = new DrawNodeDef();
drawNode.Init(node);
drawNodes.Add(drawNode);
}
return true;;
}
// 重载 == 运算符
public static bool operator ==(DrawingOrderDef a, DrawingOrderDef b)
{
if (ReferenceEquals(a, b)) return true; // 如果是同一个对象,直接返回 true
if (ReferenceEquals(a, null) || ReferenceEquals(b, null)) return false; // 如果其中一个为 null返回 false
return AreEqual(a, b);
}
// 重载 != 运算符
public static bool operator !=(DrawingOrderDef a, DrawingOrderDef b)
{
return !(a == b);
}
// 判断两个 DrawingOrderDef 是否相等
private static bool AreEqual(DrawingOrderDef a, DrawingOrderDef b)
{
// 比较 drawNodes 的数量
if (a.drawNodes.Count != b.drawNodes.Count)
return false;
// 递归比较每个 DrawNodeDef
for (int i = 0; i < a.drawNodes.Count; i++)
{
if (!DrawNodeDef.AreEqual(a.drawNodes[i], b.drawNodes[i]))
return false;
}
return true;
}
}
public class DrawNodeDef : Define
@ -77,16 +109,16 @@ namespace Data
public Vector2 StringToVector(string vectorDef)
{
// 去掉可能存在的括号和多余的空格
string cleanedInput = vectorDef.Replace("(", "").Replace(")", "").Trim();
var cleanedInput = vectorDef.Replace("(", "").Replace(")", "").Trim();
// 使用正则表达式匹配两个浮点数
Match match = Regex.Match(cleanedInput, @"\s*(-?\d+(\.\d*)?)\s*[, ]\s*(-?\d+(\.\d*)?)\s*");
var match = Regex.Match(cleanedInput, @"\s*(-?\d+(\.\d*)?)\s*[, ]\s*(-?\d+(\.\d*)?)\s*");
if (match.Success)
{
// 提取匹配到的两个浮点数
float x = float.Parse(match.Groups[1].Value);
float y = float.Parse(match.Groups[3].Value);
var x = float.Parse(match.Groups[1].Value);
var y = float.Parse(match.Groups[3].Value);
// 返回 Vector2 对象
return new Vector2(x, y);
@ -96,6 +128,30 @@ namespace Data
return Vector2.zero;
}
}
// 判断两个 DrawNodeDef 是否相等
public static bool AreEqual(DrawNodeDef a, DrawNodeDef b)
{
if (ReferenceEquals(a, b)) return true; // 如果是同一个对象,直接返回 true
if (ReferenceEquals(a, null) || ReferenceEquals(b, null)) return false; // 如果其中一个为 null返回 false
// 比较基本属性
if (a.drawNodeType != b.drawNodeType ||
a.nodeName != b.nodeName ||
a.position != b.position ||
Math.Abs(a.FPS - b.FPS) > 0.001f) // 浮点数比较需要考虑精度
return false;
// 比较 children 的数量
if (a.children.Count != b.children.Count)
return false;
// 递归比较每个子节点
for (var i = 0; i < a.children.Count; i++)
{
if (!AreEqual(a.children[i], b.children[i]))
return false;
}
return true;
}
}