From 2ac4fe28e5f565bb22b9b16b9f10f59156607e8f Mon Sep 17 00:00:00 2001
From: yhh <359807859@qq.com>
Date: Wed, 17 Jul 2019 14:09:45 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96fairygui?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Engine/CLEngine.Core/CHelper.cs | 644 +++++++++---------
.../CLEngine.Core/gui/Core/Text/TextField.cs | 34 +-
Engine/CLEngine.Core/gui/UI/GProgressBar.cs | 40 +-
Engine/CLEngine.Core/gui/UI/GSlider.cs | 42 +-
Engine/CLEngine.Core/gui/UI/ScrollPane.cs | 17 +
5 files changed, 405 insertions(+), 372 deletions(-)
diff --git a/Engine/CLEngine.Core/CHelper.cs b/Engine/CLEngine.Core/CHelper.cs
index da6c012..c48bf05 100644
--- a/Engine/CLEngine.Core/CHelper.cs
+++ b/Engine/CLEngine.Core/CHelper.cs
@@ -12,79 +12,79 @@ using System.Xml;
namespace CLEngine.Core
{
- ///
- /// 一个静态类,为游戏开发编辑器或引擎提供有用的方法
- ///
- public static class CHelper
- {
- private static readonly string _updaterPath = Path.Combine(Application.StartupPath, "qupdater.exe");
+ ///
+ /// 一个静态类,为游戏开发编辑器或引擎提供有用的方法
+ ///
+ public static class CHelper
+ {
+ private static readonly string _updaterPath = Path.Combine(Application.StartupPath, "qupdater.exe");
///
///
///
///
- public static int CheckNewFiles()
- {
- return RunUpdater("-checkforupdates", true);
- }
+ public static int CheckNewFiles()
+ {
+ return RunUpdater("-checkforupdates", true);
+ }
///
///
///
- public static void RunUpdater()
- {
- RunUpdater(string.Empty, false);
- }
-
- private static int RunUpdater(string arguments, bool waitForExit)
- {
- try
- {
- var info = new FileInfo(_updaterPath);
- if (!info.Exists)
- {
- return 0;
- }
-
- var info2 = new ProcessStartInfo { FileName = info.FullName };
- if (info.Directory != null) info2.WorkingDirectory = info.Directory.FullName;
- info2.Arguments = arguments;
- var process = new Process { StartInfo = info2 };
- process.Start();
- if (!waitForExit)
- {
- return 0;
- }
- process.WaitForExit();
-
- return process.ExitCode;
- }
- catch (Exception)
- {
- // ignored
- }
-
- return 0;
- }
+ public static void RunUpdater()
+ {
+ RunUpdater(string.Empty, false);
+ }
+
+ private static int RunUpdater(string arguments, bool waitForExit)
+ {
+ try
+ {
+ var info = new FileInfo(_updaterPath);
+ if (!info.Exists)
+ {
+ return 0;
+ }
+
+ var info2 = new ProcessStartInfo { FileName = info.FullName };
+ if (info.Directory != null) info2.WorkingDirectory = info.Directory.FullName;
+ info2.Arguments = arguments;
+ var process = new Process { StartInfo = info2 };
+ process.Start();
+ if (!waitForExit)
+ {
+ return 0;
+ }
+ process.WaitForExit();
+
+ return process.ExitCode;
+ }
+ catch (Exception)
+ {
+ // ignored
+ }
+
+ return 0;
+ }
#if WIN
public static void SerializeObject(string filename, object objectToSerialize)
- {
- try
- {
- MemoryStream stream = new MemoryStream();
- BinaryFormatter formatter = new BinaryFormatter();
- formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;
- formatter.Serialize(stream, objectToSerialize);
- byte[] serializedData = stream.ToArray();
-
- File.WriteAllBytes(filename, serializedData);
- }
- catch (Exception ex)
- {
- Console.Write(string.Format("错误!\n错误信息: {0}\n{1}", ex.Message, ex.StackTrace));
- }
- }
+ {
+ try
+ {
+ MemoryStream stream = new MemoryStream();
+ BinaryFormatter formatter = new BinaryFormatter();
+ formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;
+ formatter.Serialize(stream, objectToSerialize);
+ byte[] serializedData = stream.ToArray();
+
+ File.WriteAllBytes(filename, serializedData);
+ }
+ catch (Exception ex)
+ {
+ Console.Write(string.Format("错误!\n错误信息: {0}\n{1}", ex.Message, ex.StackTrace));
+ }
+ }
#elif WINRT
public async static void SerializeObject(string filename, object objectToSerialize)
{
@@ -93,78 +93,78 @@ namespace CLEngine.Core
#endif
#if WIN
- public static void SerializeObjectXML(string filename, object objectToSerialize)
- {
- try
- {
- MemoryStream stream = new MemoryStream();
- DataContractSerializer serializer = new DataContractSerializer(objectToSerialize.GetType(), null,
- int.MaxValue, false, true, null);
-
- var settings = new XmlWriterSettings()
- {
- Indent = true,
- IndentChars = "\t"
- };
-
- settings.NamespaceHandling = NamespaceHandling.OmitDuplicates;
- //settings.OutputMethod = XmlOutputMethod.Xml;
- settings.ConformanceLevel = ConformanceLevel.Fragment;
-
- using (XmlDictionaryWriter writer =
- XmlDictionaryWriter.CreateDictionaryWriter(XmlWriter.Create(stream, settings)))
- {
- serializer.WriteObject(writer, objectToSerialize, new MyCustomerResolver());
- }
-
- byte[] serializedData = stream.ToArray();
- File.WriteAllBytes(filename, serializedData);
-
- //var emptyNamepsaces = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty });
- //var serializer = new XmlSerializer(objectToSerialize.GetType());
- //var settings = new XmlWriterSettings();
- //settings.Indent = true;
- //settings.OmitXmlDeclaration = true;
-
- //MemoryStream stream = new MemoryStream();
- //using (var writer = XmlWriter.Create(stream, settings))
- //{
- // serializer.Serialize(writer, objectToSerialize, emptyNamepsaces);
- //}
-
- //byte[] serializedData = stream.ToArray();
- //File.WriteAllBytes(filename, serializedData);
-
- //stream.Dispose();
- }
- catch (Exception ex)
- {
- Console.Write(string.Format("Error!\nError Message: {0}\n{1}", ex.Message, ex.StackTrace));
- }
- }
+ public static void SerializeObjectXML(string filename, object objectToSerialize)
+ {
+ try
+ {
+ MemoryStream stream = new MemoryStream();
+ DataContractSerializer serializer = new DataContractSerializer(objectToSerialize.GetType(), null,
+ int.MaxValue, false, true, null);
+
+ var settings = new XmlWriterSettings()
+ {
+ Indent = true,
+ IndentChars = "\t"
+ };
+
+ settings.NamespaceHandling = NamespaceHandling.OmitDuplicates;
+ //settings.OutputMethod = XmlOutputMethod.Xml;
+ settings.ConformanceLevel = ConformanceLevel.Fragment;
+
+ using (XmlDictionaryWriter writer =
+ XmlDictionaryWriter.CreateDictionaryWriter(XmlWriter.Create(stream, settings)))
+ {
+ serializer.WriteObject(writer, objectToSerialize, new MyCustomerResolver());
+ }
+
+ byte[] serializedData = stream.ToArray();
+ File.WriteAllBytes(filename, serializedData);
+
+ //var emptyNamepsaces = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty });
+ //var serializer = new XmlSerializer(objectToSerialize.GetType());
+ //var settings = new XmlWriterSettings();
+ //settings.Indent = true;
+ //settings.OmitXmlDeclaration = true;
+
+ //MemoryStream stream = new MemoryStream();
+ //using (var writer = XmlWriter.Create(stream, settings))
+ //{
+ // serializer.Serialize(writer, objectToSerialize, emptyNamepsaces);
+ //}
+
+ //byte[] serializedData = stream.ToArray();
+ //File.WriteAllBytes(filename, serializedData);
+
+ //stream.Dispose();
+ }
+ catch (Exception ex)
+ {
+ Console.Write(string.Format("Error!\nError Message: {0}\n{1}", ex.Message, ex.StackTrace));
+ }
+ }
#endif
#if WIN
- public static object DeserializeObject(string filename)
- {
- try
- {
- byte[] bytes = File.ReadAllBytes(filename);
-
- MemoryStream stream = new MemoryStream(bytes);
- BinaryFormatter formatter = new BinaryFormatter();
- formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;
- formatter.Binder = new VersionConfigToNamespaceAssemblyObjectBinder();
-
- return (Object) formatter.Deserialize(stream);
- }
- catch (Exception ex)
- {
- Console.Write(string.Format("反序列化时出错!\n错误信息: {0}\n{1}", ex.Message, ex.StackTrace));
- return null;
- }
+ public static object DeserializeObject(string filename)
+ {
+ try
+ {
+ byte[] bytes = File.ReadAllBytes(filename);
+
+ MemoryStream stream = new MemoryStream(bytes);
+ BinaryFormatter formatter = new BinaryFormatter();
+ formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;
+ formatter.Binder = new VersionConfigToNamespaceAssemblyObjectBinder();
+
+ return (Object)formatter.Deserialize(stream);
+ }
+ catch (Exception ex)
+ {
+ Console.Write(string.Format("反序列化时出错!\n错误信息: {0}\n{1}", ex.Message, ex.StackTrace));
+ return null;
+ }
- }
+ }
#elif WINRT
public static object DeserializeObject(Type type, string filename)
{
@@ -179,127 +179,127 @@ namespace CLEngine.Core
}
#endif
- private static readonly Random random = new Random();
- private static readonly object syncLock = new object();
+ private static readonly Random random = new Random();
+ private static readonly object syncLock = new object();
- public static int RandomNumber(int min, int max)
- {
- lock (syncLock)
- {
- return random.Next(min, max);
- }
- }
+ public static int RandomNumber(int min, int max)
+ {
+ lock (syncLock)
+ {
+ return random.Next(min, max);
+ }
+ }
- ///
- /// 创建从一个文件或文件夹到另一个文件或文件夹的相对路径
- ///
- ///
- ///
- ///
- public static String MakeExclusiveRelativePath(String fromPath, String toPath)
- {
- if (String.IsNullOrEmpty(fromPath)) throw new ArgumentNullException("fromPath");
- if (String.IsNullOrEmpty(toPath)) throw new ArgumentNullException("toPath");
+ ///
+ /// 创建从一个文件或文件夹到另一个文件或文件夹的相对路径
+ ///
+ ///
+ ///
+ ///
+ public static String MakeExclusiveRelativePath(String fromPath, String toPath)
+ {
+ if (String.IsNullOrEmpty(fromPath)) throw new ArgumentNullException("fromPath");
+ if (String.IsNullOrEmpty(toPath)) throw new ArgumentNullException("toPath");
#if WIN
- return toPath.Replace(fromPath, string.Empty).TrimStart(System.IO.Path.DirectorySeparatorChar);
+ return toPath.Replace(fromPath, string.Empty).TrimStart(System.IO.Path.DirectorySeparatorChar);
#elif WINRT
return toPath.Replace(fromPath, string.Empty).TrimStart('\\');
#endif
- }
+ }
- public static string EncryptMD5(string input)
- {
+ public static string EncryptMD5(string input)
+ {
#if WIN
- MD5 md5Hasher = MD5.Create();
- byte[] data = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(input));
-
- // 创建一个新的Stringbuilder来收集字节
- // 并创建一个字符串。
- StringBuilder sBuilder = new StringBuilder();
-
- // 循环遍历散列数据的每个字节
- // 并将每个格式化为十六进制字符串。
- for (int i = 0; i < data.Length; i++)
- {
- sBuilder.Append(data[i].ToString("x2"));
- }
-
- // 返回十六进制字符串
- return sBuilder.ToString();
+ MD5 md5Hasher = MD5.Create();
+ byte[] data = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(input));
+
+ // 创建一个新的Stringbuilder来收集字节
+ // 并创建一个字符串。
+ StringBuilder sBuilder = new StringBuilder();
+
+ // 循环遍历散列数据的每个字节
+ // 并将每个格式化为十六进制字符串。
+ for (int i = 0; i < data.Length; i++)
+ {
+ sBuilder.Append(data[i].ToString("x2"));
+ }
+
+ // 返回十六进制字符串
+ return sBuilder.ToString();
#elif WINRT
// TODO:
throw new NotImplementedException();
#endif
- }
+ }
#if WIN
- ///
- /// 将整个目录复制到目标
- ///
- /// Source directory path
- /// Destination path
- /// Copy sub directories
- public static void CopyDirectory(string sourceDirName, string destDirName, bool copySubDirs)
- {
- DirectoryInfo dir = new DirectoryInfo(sourceDirName);
- DirectoryInfo[] dirs = dir.GetDirectories();
-
- // 如果源目录不存在,则抛出异常
- if (!dir.Exists)
- {
- throw new DirectoryNotFoundException(
- "源目录不存在或找不到: "
- + sourceDirName);
- }
-
- // 如果目标目录不存在,请创建它
- if (!Directory.Exists(destDirName))
- {
- Directory.CreateDirectory(destDirName);
- }
-
- // 获取要复制的目录的文件内容
- FileInfo[] files = dir.GetFiles();
-
- foreach (FileInfo file in files)
- {
- // 创建文件新副本的路径
- string temppath = System.IO.Path.Combine(destDirName, file.Name);
-
- // 复制文件
- file.CopyTo(temppath, true);
- }
-
- // 如果copySubDirs为true,则复制子目录
- if (copySubDirs)
- {
- foreach (DirectoryInfo subdir in dirs)
- {
- // Create the subdirectory.
- string temppath = System.IO.Path.Combine(destDirName, subdir.Name);
-
- // Copy the subdirectories.
- CopyDirectory(subdir.FullName, temppath, copySubDirs);
- }
- }
- }
+ ///
+ /// 将整个目录复制到目标
+ ///
+ /// Source directory path
+ /// Destination path
+ /// Copy sub directories
+ public static void CopyDirectory(string sourceDirName, string destDirName, bool copySubDirs)
+ {
+ DirectoryInfo dir = new DirectoryInfo(sourceDirName);
+ DirectoryInfo[] dirs = dir.GetDirectories();
+
+ // 如果源目录不存在,则抛出异常
+ if (!dir.Exists)
+ {
+ throw new DirectoryNotFoundException(
+ "源目录不存在或找不到: "
+ + sourceDirName);
+ }
+
+ // 如果目标目录不存在,请创建它
+ if (!Directory.Exists(destDirName))
+ {
+ Directory.CreateDirectory(destDirName);
+ }
+
+ // 获取要复制的目录的文件内容
+ FileInfo[] files = dir.GetFiles();
+
+ foreach (FileInfo file in files)
+ {
+ // 创建文件新副本的路径
+ string temppath = System.IO.Path.Combine(destDirName, file.Name);
+
+ // 复制文件
+ file.CopyTo(temppath, true);
+ }
+
+ // 如果copySubDirs为true,则复制子目录
+ if (copySubDirs)
+ {
+ foreach (DirectoryInfo subdir in dirs)
+ {
+ // Create the subdirectory.
+ string temppath = System.IO.Path.Combine(destDirName, subdir.Name);
+
+ // Copy the subdirectories.
+ CopyDirectory(subdir.FullName, temppath, copySubDirs);
+ }
+ }
+ }
#endif
- public static string SplitCamelCase(string str)
- {
- string camelCase = Regex.Replace(Regex.Replace(str, @"(\P{Ll})(\P{Ll}\p{Ll})", "$1 $2"),
- @"(\p{Ll})(\P{Ll})", "$1 $2");
+ public static string SplitCamelCase(string str)
+ {
+ string camelCase = Regex.Replace(Regex.Replace(str, @"(\P{Ll})(\P{Ll}\p{Ll})", "$1 $2"),
+ @"(\p{Ll})(\P{Ll})", "$1 $2");
- // 删除双空格并返回
- return Regex.Replace(camelCase, @"\s+", " ");
+ // 删除双空格并返回
+ return Regex.Replace(camelCase, @"\s+", " ");
- }
+ }
///
/// 改变Settings.ini文件为release模式
///
- public static void ChangeSettingsToRelease(string path)
+ public static void ChangeSettingsToRelease(string path)
{
var destination = Path.Combine(path, "settings.ini");
var iniFile = new IniFile(destination);
@@ -310,93 +310,93 @@ namespace CLEngine.Core
iniFile.IniWriteValue("Console", "Visible", "False");
iniFile.IniWriteValue("Console", "WriteToConsole", "False");
}
- }
+ }
#if WIN
- internal sealed class VersionConfigToNamespaceAssemblyObjectBinder : SerializationBinder
- {
- ///
- ///
- ///
- ///
- ///
- ///
- public override Type BindToType(string assemblyName, string typeName)
- {
- Type typeToDeserialize = null;
-
- try
- {
- string ToAssemblyName = assemblyName.Split(',')[0];
-
- Assembly[] Assemblies = AppDomain.CurrentDomain.GetAssemblies();
- foreach (Assembly ass in Assemblies)
- {
- if (ass.FullName.Split(',')[0] == ToAssemblyName)
- {
- typeToDeserialize = ass.GetType(typeName);
-
- break;
- }
- }
- }
-
- catch (System.Exception exception)
- {
- throw exception;
- }
-
- return typeToDeserialize;
- }
- }
+ internal sealed class VersionConfigToNamespaceAssemblyObjectBinder : SerializationBinder
+ {
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override Type BindToType(string assemblyName, string typeName)
+ {
+ Type typeToDeserialize = null;
+
+ try
+ {
+ string ToAssemblyName = assemblyName.Split(',')[0];
+
+ Assembly[] Assemblies = AppDomain.CurrentDomain.GetAssemblies();
+ foreach (Assembly ass in Assemblies)
+ {
+ if (ass.FullName.Split(',')[0] == ToAssemblyName)
+ {
+ typeToDeserialize = ass.GetType(typeName);
+
+ break;
+ }
+ }
+ }
+
+ catch (System.Exception exception)
+ {
+ throw exception;
+ }
+
+ return typeToDeserialize;
+ }
+ }
#endif
- public class MyCustomerResolver : DataContractResolver
- {
- public override bool TryResolveType(Type dataContractType, Type declaredType,
- DataContractResolver knownTypeResolver, out XmlDictionaryString typeName,
- out XmlDictionaryString typeNamespace)
- {
- //return knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace);
- //XmlDictionary dictionary = new XmlDictionary();
- //typeName = dictionary.Add(dataContractType.FullName);
- //typeNamespace = dictionary.Add(dataContractType.Namespace);
- ////knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace);
- //return true;
-
- //if (dataContractType == typeof(Customer))
- //{
- // XmlDictionary dictionary = new XmlDictionary();
- // typeName = dictionary.Add("SomeCustomer");
- // typeNamespace = dictionary.Add("http://tempuri.com");
- // return true;
- //}
- //else
- //{
- // return knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace);
- //}
-
- string name = dataContractType.Name;
- string namesp = dataContractType.Namespace;
- typeName = new XmlDictionaryString(XmlDictionary.Empty, name, 0);
- typeNamespace = new XmlDictionaryString(XmlDictionary.Empty, namesp, 0);
-
- return true;
- }
+ public class MyCustomerResolver : DataContractResolver
+ {
+ public override bool TryResolveType(Type dataContractType, Type declaredType,
+ DataContractResolver knownTypeResolver, out XmlDictionaryString typeName,
+ out XmlDictionaryString typeNamespace)
+ {
+ //return knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace);
+ //XmlDictionary dictionary = new XmlDictionary();
+ //typeName = dictionary.Add(dataContractType.FullName);
+ //typeNamespace = dictionary.Add(dataContractType.Namespace);
+ ////knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace);
+ //return true;
+
+ //if (dataContractType == typeof(Customer))
+ //{
+ // XmlDictionary dictionary = new XmlDictionary();
+ // typeName = dictionary.Add("SomeCustomer");
+ // typeNamespace = dictionary.Add("http://tempuri.com");
+ // return true;
+ //}
+ //else
+ //{
+ // return knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace);
+ //}
+
+ string name = dataContractType.Name;
+ string namesp = dataContractType.Namespace;
+ typeName = new XmlDictionaryString(XmlDictionary.Empty, name, 0);
+ typeNamespace = new XmlDictionaryString(XmlDictionary.Empty, namesp, 0);
+
+ return true;
+ }
- public override Type ResolveName(string typeName, string typeNamespace, Type declaredType,
- DataContractResolver knownTypeResolver)
- {
- //Console.Info(typeNamespace + "." + typeName);
- //Type tx = declaredType;
- //Console.Info(tx);
- //Type t = Assembly.GetExecutingAssembly().GetType(typeName);
- //return t;
- //Debug.Info("TESTE::: " + typeName + "::" + declaredType.Name);
- //return declaredType;
+ public override Type ResolveName(string typeName, string typeNamespace, Type declaredType,
+ DataContractResolver knownTypeResolver)
+ {
+ //Console.Info(typeNamespace + "." + typeName);
+ //Type tx = declaredType;
+ //Console.Info(tx);
+ //Type t = Assembly.GetExecutingAssembly().GetType(typeName);
+ //return t;
+ //Debug.Info("TESTE::: " + typeName + "::" + declaredType.Name);
+ //return declaredType;
- //Debug.Info("TESTE: " + typeNamespace + "." + typeName + " (" + declaredType + ")");
- Type t = SceneManager.ScriptsAssembly.GetType(typeNamespace + "." + typeName);
+ //Debug.Info("TESTE: " + typeNamespace + "." + typeName + " (" + declaredType + ")");
+ Type t = SceneManager.ScriptsAssembly.GetType(typeNamespace + "." + typeName);
#if WINRT
if (t == null)
@@ -405,18 +405,18 @@ namespace CLEngine.Core
t = declaredType.GetType().GetTypeInfo().Assembly.GetType(typeNamespace + "." + typeName);
}
#endif
- //if (typeName == "Single")
- // return typeof(Single);
- //else if (typeName == "Boolean")
- // return typeof(Boolean);
- //else if (typeName.ToLower() == "string")
- // return typeof(string);
- //else if (typeName.ToLower() == "float")
- // return typeof(float);
- //else if (typeName.ToLower() == "int32")
- // return typeof(Int32);
-
- return t;
- }
- }
+ //if (typeName == "Single")
+ // return typeof(Single);
+ //else if (typeName == "Boolean")
+ // return typeof(Boolean);
+ //else if (typeName.ToLower() == "string")
+ // return typeof(string);
+ //else if (typeName.ToLower() == "float")
+ // return typeof(float);
+ //else if (typeName.ToLower() == "int32")
+ // return typeof(Int32);
+
+ return t;
+ }
+ }
}
\ No newline at end of file
diff --git a/Engine/CLEngine.Core/gui/Core/Text/TextField.cs b/Engine/CLEngine.Core/gui/Core/Text/TextField.cs
index 8407041..80f47cd 100644
--- a/Engine/CLEngine.Core/gui/Core/Text/TextField.cs
+++ b/Engine/CLEngine.Core/gui/Core/Text/TextField.cs
@@ -43,6 +43,7 @@ namespace FairyGUI
bool _textChanged;
int _yOffset;
float _fontSizeScale;
+ string _parsedText;
float _globalScale;
Bitmap _canvas;
NTexture _texture;
@@ -60,6 +61,12 @@ namespace FairyGUI
-1, 1, 1, 1
};
+ static float[] BOLD_OFFSET = new float[]
+ {
+ -0.5f, 0f, 0.5f, 0f,
+ 0f, -0.5f, 0f, 0.5f
+ };
+
public TextField()
{
_touchDisabled = true;
@@ -71,6 +78,7 @@ namespace FairyGUI
_wordWrap = false;
_text = string.Empty;
+ _parsedText = string.Empty;
_elements = new List(0);
_lines = new List(1);
@@ -95,6 +103,14 @@ namespace FairyGUI
if (_richTextField is InputTextField)
{
_input = true;
+ EnableCharPositionSupport();
+ }
+ }
+
+ public void EnableCharPositionSupport()
+ {
+ if (_charPositions == null)
+ {
_charPositions = new List();
_textChanged = true;
}
@@ -161,10 +177,15 @@ namespace FairyGUI
{
_text = ToolSet.FormatCRLF(value);
_textChanged = true;
- _html = false;
+ _html = true;
}
}
+ public string parsedText
+ {
+ get { return _parsedText; }
+ }
+
///
///
///
@@ -251,8 +272,11 @@ namespace FairyGUI
}
set
{
- _strokeColor = value;
- graphics.SetMeshDirty();
+ if (_strokeColor != value)
+ {
+ _strokeColor = value;
+ graphics.SetMeshDirty();
+ }
}
}
@@ -456,10 +480,10 @@ namespace FairyGUI
public override void Update()
{
- base.Update();
-
if (_richTextField == null) //如果是richTextField,会在update前主动调用了Rebuild
Rebuild();
+
+ base.Update();
}
void ResolveFont()
diff --git a/Engine/CLEngine.Core/gui/UI/GProgressBar.cs b/Engine/CLEngine.Core/gui/UI/GProgressBar.cs
index 35f9d3d..eecee9a 100644
--- a/Engine/CLEngine.Core/gui/UI/GProgressBar.cs
+++ b/Engine/CLEngine.Core/gui/UI/GProgressBar.cs
@@ -13,7 +13,7 @@ namespace FairyGUI
ProgressTitleType _titleType;
bool _reverse;
- GTextField _titleObject;
+ GObject _titleObject;
GMovieClip _aniObject;
GObject _barObjectH;
GObject _barObjectV;
@@ -154,20 +154,12 @@ namespace FairyGUI
{
if (_barObjectH != null)
{
- if ((_barObjectH is GImage) && ((GImage)_barObjectH).fillMethod != FillMethod.None)
- ((GImage)_barObjectH).fillAmount = percent;
- else if ((_barObjectH is GLoader) && ((GLoader)_barObjectH).fillMethod != FillMethod.None)
- ((GLoader)_barObjectH).fillAmount = percent;
- else
+ if (!SetFillAmount(_barObjectH, percent))
_barObjectH.width = (int)Math.Round(fullWidth * percent);
}
if (_barObjectV != null)
{
- if ((_barObjectV is GImage) && ((GImage)_barObjectV).fillMethod != FillMethod.None)
- ((GImage)_barObjectV).fillAmount = percent;
- else if ((_barObjectV is GLoader) && ((GLoader)_barObjectV).fillMethod != FillMethod.None)
- ((GLoader)_barObjectV).fillAmount = percent;
- else
+ if (!SetFillAmount(_barObjectH, percent))
_barObjectV.height = (int)Math.Round(fullHeight * percent);
}
}
@@ -175,11 +167,7 @@ namespace FairyGUI
{
if (_barObjectH != null)
{
- if ((_barObjectH is GImage) && ((GImage)_barObjectH).fillMethod != FillMethod.None)
- ((GImage)_barObjectH).fillAmount = 1 - percent;
- else if ((_barObjectH is GLoader) && ((GLoader)_barObjectH).fillMethod != FillMethod.None)
- ((GLoader)_barObjectH).fillAmount = 1 - percent;
- else
+ if (!SetFillAmount(_barObjectH, percent))
{
_barObjectH.width = (int)Math.Round(fullWidth * percent);
_barObjectH.x = _barStartX + (fullWidth - _barObjectH.width);
@@ -187,11 +175,7 @@ namespace FairyGUI
}
if (_barObjectV != null)
{
- if ((_barObjectV is GImage) && ((GImage)_barObjectV).fillMethod != FillMethod.None)
- ((GImage)_barObjectV).fillAmount = 1 - percent;
- else if ((_barObjectV is GLoader) && ((GLoader)_barObjectV).fillMethod != FillMethod.None)
- ((GLoader)_barObjectV).fillAmount = 1 - percent;
- else
+ if (!SetFillAmount(_barObjectH, percent))
{
_barObjectV.height = (int)Math.Round(fullHeight * percent);
_barObjectV.y = _barStartY + (fullHeight - _barObjectV.height);
@@ -202,6 +186,18 @@ namespace FairyGUI
_aniObject.frame = (int)Math.Round(percent * 100);
}
+ bool SetFillAmount(GObject bar, float amount)
+ {
+ if ((bar is GImage) && ((GImage)bar).fillMethod != FillMethod.None)
+ ((GImage)bar).fillAmount = amount;
+ else if ((bar is GLoader) && ((GLoader)bar).fillMethod != FillMethod.None)
+ ((GLoader)bar).fillAmount = amount;
+ else
+ return false;
+
+ return true;
+ }
+
override protected void ConstructExtension(ByteBuffer buffer)
{
buffer.Seek(0, 6);
@@ -209,7 +205,7 @@ namespace FairyGUI
_titleType = (ProgressTitleType)buffer.ReadByte();
_reverse = buffer.ReadBool();
- _titleObject = GetChild("title") as GTextField;
+ _titleObject = GetChild("title");
_barObjectH = GetChild("bar");
_barObjectV = GetChild("bar_v");
_aniObject = GetChild("ani") as GMovieClip;
diff --git a/Engine/CLEngine.Core/gui/UI/GSlider.cs b/Engine/CLEngine.Core/gui/UI/GSlider.cs
index c8adcf3..ab09514 100644
--- a/Engine/CLEngine.Core/gui/UI/GSlider.cs
+++ b/Engine/CLEngine.Core/gui/UI/GSlider.cs
@@ -14,7 +14,7 @@ namespace FairyGUI
ProgressTitleType _titleType;
bool _reverse;
- GTextField _titleObject;
+ GObject _titleObject;
GObject _barObjectH;
GObject _barObjectV;
float _barMaxWidth;
@@ -127,7 +127,7 @@ namespace FairyGUI
switch (_titleType)
{
case ProgressTitleType.Percent:
- _titleObject.text = (int)Math.Round(percent * 100) + "%";
+ _titleObject.text = Math.Floor(percent * 100) + "%";
break;
case ProgressTitleType.ValueAndMax:
@@ -150,20 +150,12 @@ namespace FairyGUI
{
if (_barObjectH != null)
{
- if ((_barObjectH is GImage) && ((GImage)_barObjectH).fillMethod != FillMethod.None)
- ((GImage)_barObjectH).fillAmount = percent;
- else if ((_barObjectH is GLoader) && ((GLoader)_barObjectH).fillMethod != FillMethod.None)
- ((GLoader)_barObjectH).fillAmount = percent;
- else
+ if (!SetFillAmount(_barObjectH, percent))
_barObjectH.width = (int)Math.Round(fullWidth * percent);
}
if (_barObjectV != null)
{
- if ((_barObjectV is GImage) && ((GImage)_barObjectV).fillMethod != FillMethod.None)
- ((GImage)_barObjectV).fillAmount = percent;
- else if ((_barObjectV is GLoader) && ((GLoader)_barObjectV).fillMethod != FillMethod.None)
- ((GLoader)_barObjectV).fillAmount = percent;
- else
+ if (!SetFillAmount(_barObjectH, percent))
_barObjectV.height = (int)Math.Round(fullHeight * percent);
}
}
@@ -171,11 +163,7 @@ namespace FairyGUI
{
if (_barObjectH != null)
{
- if ((_barObjectH is GImage) && ((GImage)_barObjectH).fillMethod != FillMethod.None)
- ((GImage)_barObjectH).fillAmount = 1 - percent;
- else if ((_barObjectH is GLoader) && ((GLoader)_barObjectH).fillMethod != FillMethod.None)
- ((GLoader)_barObjectH).fillAmount = 1 - percent;
- else
+ if (!SetFillAmount(_barObjectH, percent))
{
_barObjectH.width = (int)Math.Round(fullWidth * percent);
_barObjectH.x = _barStartX + (fullWidth - _barObjectH.width);
@@ -183,11 +171,7 @@ namespace FairyGUI
}
if (_barObjectV != null)
{
- if ((_barObjectV is GImage) && ((GImage)_barObjectV).fillMethod != FillMethod.None)
- ((GImage)_barObjectV).fillAmount = 1 - percent;
- else if ((_barObjectV is GLoader) && ((GLoader)_barObjectV).fillMethod != FillMethod.None)
- ((GLoader)_barObjectV).fillAmount = 1 - percent;
- else
+ if (!SetFillAmount(_barObjectH, percent))
{
_barObjectV.height = (int)Math.Round(fullHeight * percent);
_barObjectV.y = _barStartY + (fullHeight - _barObjectV.height);
@@ -196,6 +180,18 @@ namespace FairyGUI
}
}
+ bool SetFillAmount(GObject bar, float amount)
+ {
+ if ((bar is GImage) && ((GImage)bar).fillMethod != FillMethod.None)
+ ((GImage)bar).fillAmount = amount;
+ else if ((bar is GLoader) && ((GLoader)bar).fillMethod != FillMethod.None)
+ ((GLoader)bar).fillAmount = amount;
+ else
+ return false;
+
+ return true;
+ }
+
override protected void ConstructExtension(ByteBuffer buffer)
{
buffer.Seek(0, 6);
@@ -203,7 +199,7 @@ namespace FairyGUI
_titleType = (ProgressTitleType)buffer.ReadByte();
_reverse = buffer.ReadBool();
- _titleObject = GetChild("title") as GTextField;
+ _titleObject = GetChild("title");
_barObjectH = GetChild("bar");
_barObjectV = GetChild("bar_v");
_gripObject = GetChild("grip");
diff --git a/Engine/CLEngine.Core/gui/UI/ScrollPane.cs b/Engine/CLEngine.Core/gui/UI/ScrollPane.cs
index 9efa7e4..0a6046a 100644
--- a/Engine/CLEngine.Core/gui/UI/ScrollPane.cs
+++ b/Engine/CLEngine.Core/gui/UI/ScrollPane.cs
@@ -560,6 +560,8 @@ namespace FairyGUI
if (!_pageMode)
return 0;
+ _owner.EnsureBoundsCorrect();
+
int page = (int)Math.Floor(_xPos / _pageSize.X);
if (_xPos - page * _pageSize.X > _pageSize.X * 0.5f)
page++;
@@ -583,6 +585,11 @@ namespace FairyGUI
/// 是否使用缓动到达目标。
public void SetCurrentPageX(int value, bool ani)
{
+ if (!_pageMode)
+ return;
+
+ _owner.EnsureBoundsCorrect();
+
if (_overlapSize.X > 0)
this.SetPosX(value * _pageSize.X, ani);
}
@@ -605,6 +612,11 @@ namespace FairyGUI
}
set
{
+ if (!_pageMode)
+ return;
+
+ _owner.EnsureBoundsCorrect();
+
if (_overlapSize.Y > 0)
this.SetPosY(value * _pageSize.Y, false);
}
@@ -617,6 +629,11 @@ namespace FairyGUI
/// 是否使用缓动到达目标。
public void SetCurrentPageY(int value, bool ani)
{
+ if (!_pageMode)
+ return;
+
+ _owner.EnsureBoundsCorrect();
+
if (_overlapSize.Y > 0)
this.SetPosY(value * _pageSize.Y, ani);
}
--
Gitee