From d5a4774dc82ca76e0509b78bb063414afd6818a8 Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Wed, 10 Jul 2019 14:00:37 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=20fairygui?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Engine/CLEngine.Core/gui/Core/Container.cs | 44 +- .../gui/Core/HitTest/HitTestContext.cs | 4 +- .../CLEngine.Core/gui/Core/Mesh/FillMesh.cs | 128 +- Engine/CLEngine.Core/gui/Core/NGraphics.cs | 2 +- Engine/CLEngine.Core/gui/Core/Shape.cs | 46 +- Engine/CLEngine.Core/gui/Core/Stage.cs | 112 +- .../gui/Core/Text/DynamicFont.cs | 4 +- .../gui/Core/Text/IInputHandler.cs | 20 +- .../CLEngine.Core/gui/Core/Text/IMEAdapter.cs | 2 +- .../CLEngine.Core/gui/Core/Text/TextField.cs | 90 +- Engine/CLEngine.Core/gui/UI/GButton.cs | 34 +- Engine/CLEngine.Core/gui/UI/GList.cs | 68 +- Engine/CLEngine.Core/gui/UI/GLoader.cs | 1274 ++++++++--------- Engine/CLEngine.Core/gui/UI/GObject.cs | 16 +- Engine/CLEngine.Core/gui/UI/GProgressBar.cs | 10 +- Engine/CLEngine.Core/gui/UI/GSlider.cs | 2 +- Engine/CLEngine.Core/gui/UI/Gears/GearBase.cs | 26 +- Engine/CLEngine.Core/gui/UI/Transition.cs | 92 +- Engine/CLEngine.Core/gui/Utils/Timers.cs | 490 +++---- 19 files changed, 1232 insertions(+), 1232 deletions(-) diff --git a/Engine/CLEngine.Core/gui/Core/Container.cs b/Engine/CLEngine.Core/gui/Core/Container.cs index 32bf9e2..aa2a31d 100644 --- a/Engine/CLEngine.Core/gui/Core/Container.cs +++ b/Engine/CLEngine.Core/gui/Core/Container.cs @@ -26,12 +26,12 @@ namespace FairyGUI /// public bool touchChildren; - /// - /// - /// - public bool reversedMask; + /// + /// + /// + public bool reversedMask; - List _children; + List _children; DisplayObject _mask; Rectangle? _clipRect; @@ -363,21 +363,21 @@ namespace FairyGUI return rect; } - /// - /// - /// - /// - /// - /// - /// - public DisplayObject HitTest(Vector2 stagePoint, bool forTouch, int displayIndex = -1) + /// + /// + /// + /// + /// + /// + /// + public DisplayObject HitTest(Vector2 stagePoint, bool forTouch, int displayIndex = -1) { HitTestContext.screenPoint = stagePoint; HitTestContext.forTouch = forTouch; HitTestContext.raycastDone = false; - HitTestContext.displayIndex = displayIndex; + HitTestContext.displayIndex = displayIndex; - DisplayObject ret = HitTest(); + DisplayObject ret = HitTest(); if (ret != null) return ret; else if (this is Stage) @@ -405,14 +405,14 @@ namespace FairyGUI return null; } - if (_mask != null && _mask.parent == this) - { - DisplayObject tmp = _mask.InternalHitTestMask(); - if (!reversedMask && tmp == null || reversedMask && tmp != null) - return null; - } + if (_mask != null && _mask.parent == this) + { + DisplayObject tmp = _mask.InternalHitTestMask(); + if (!reversedMask && tmp == null || reversedMask && tmp != null) + return null; + } - DisplayObject target = null; + DisplayObject target = null; if (touchChildren) { int count = _children.Count; diff --git a/Engine/CLEngine.Core/gui/Core/HitTest/HitTestContext.cs b/Engine/CLEngine.Core/gui/Core/HitTest/HitTestContext.cs index 2324f15..95400b0 100644 --- a/Engine/CLEngine.Core/gui/Core/HitTest/HitTestContext.cs +++ b/Engine/CLEngine.Core/gui/Core/HitTest/HitTestContext.cs @@ -13,6 +13,6 @@ namespace FairyGUI public static uint hitEntityId; public static Vector2 hitUV; public static bool forTouch; - public static int displayIndex; - } + public static int displayIndex; + } } diff --git a/Engine/CLEngine.Core/gui/Core/Mesh/FillMesh.cs b/Engine/CLEngine.Core/gui/Core/Mesh/FillMesh.cs index d3270fb..2e3f816 100644 --- a/Engine/CLEngine.Core/gui/Core/Mesh/FillMesh.cs +++ b/Engine/CLEngine.Core/gui/Core/Mesh/FillMesh.cs @@ -86,70 +86,70 @@ namespace FairyGUI //4 vertex static void FillRadial90(VertexBuffer vb, Rectangle vertRect, Origin90 origin, float amount, bool clockwise) { - bool flipX = origin == Origin90.TopRight || origin == Origin90.BottomRight; - bool flipY = origin == Origin90.BottomLeft || origin == Origin90.BottomRight; - if (flipX != flipY) - clockwise = !clockwise; - - float ratio = clockwise ? amount : (1 - amount); - float tan = (float)Math.Tan(Math.PI * 0.5f * ratio); - bool thresold = false; - if (ratio != 1) - thresold = (vertRect.Height / vertRect.Width - tan) > 0; - if (!clockwise) - thresold = !thresold; - float x = vertRect.X + (ratio == 0 ? float.MaxValue : (vertRect.Height / tan)); - float y = vertRect.Y + (ratio == 1 ? float.MaxValue : (vertRect.Width * tan)); - float x2 = x; - float y2 = y; - if (flipX) - x2 = vertRect.Width - x; - if (flipY) - y2 = vertRect.Height - y; - float xMin = flipX ? (vertRect.Width - vertRect.X) : vertRect.X; - float yMin = flipY ? (vertRect.Height - vertRect.Y) : vertRect.Y; - float xMax = flipX ? -vertRect.X : vertRect.Right; - float yMax = flipY ? -vertRect.Y : vertRect.Bottom; - - vb.AddVert(new Vector3(xMin, yMin, 0)); - - if (clockwise) - vb.AddVert(new Vector3(xMax, yMin, 0)); - - if (y > vertRect.Bottom) - { - if (thresold) - vb.AddVert(new Vector3(x2, yMax, 0)); - else - vb.AddVert(new Vector3(xMax, yMax, 0)); - } - else - vb.AddVert(new Vector3(xMax, y2, 0)); - - if (x > vertRect.Right) - { - if (thresold) - vb.AddVert(new Vector3(xMax, y2, 0)); - else - vb.AddVert(new Vector3(xMax, yMax, 0)); - } - else - vb.AddVert(new Vector3(x2, yMax, 0)); - - if (!clockwise) - vb.AddVert(new Vector3(xMin, yMax, 0)); - - if (flipX == flipY) - { - vb.AddTriangle(0, 1, 2); - vb.AddTriangle(0, 2, 3); - } - else - { - vb.AddTriangle(2, 1, 0); - vb.AddTriangle(3, 2, 0); - } - } + bool flipX = origin == Origin90.TopRight || origin == Origin90.BottomRight; + bool flipY = origin == Origin90.BottomLeft || origin == Origin90.BottomRight; + if (flipX != flipY) + clockwise = !clockwise; + + float ratio = clockwise ? amount : (1 - amount); + float tan = (float)Math.Tan(Math.PI * 0.5f * ratio); + bool thresold = false; + if (ratio != 1) + thresold = (vertRect.Height / vertRect.Width - tan) > 0; + if (!clockwise) + thresold = !thresold; + float x = vertRect.X + (ratio == 0 ? float.MaxValue : (vertRect.Height / tan)); + float y = vertRect.Y + (ratio == 1 ? float.MaxValue : (vertRect.Width * tan)); + float x2 = x; + float y2 = y; + if (flipX) + x2 = vertRect.Width - x; + if (flipY) + y2 = vertRect.Height - y; + float xMin = flipX ? (vertRect.Width - vertRect.X) : vertRect.X; + float yMin = flipY ? (vertRect.Height - vertRect.Y) : vertRect.Y; + float xMax = flipX ? -vertRect.X : vertRect.Right; + float yMax = flipY ? -vertRect.Y : vertRect.Bottom; + + vb.AddVert(new Vector3(xMin, yMin, 0)); + + if (clockwise) + vb.AddVert(new Vector3(xMax, yMin, 0)); + + if (y > vertRect.Bottom) + { + if (thresold) + vb.AddVert(new Vector3(x2, yMax, 0)); + else + vb.AddVert(new Vector3(xMax, yMax, 0)); + } + else + vb.AddVert(new Vector3(xMax, y2, 0)); + + if (x > vertRect.Right) + { + if (thresold) + vb.AddVert(new Vector3(xMax, y2, 0)); + else + vb.AddVert(new Vector3(xMax, yMax, 0)); + } + else + vb.AddVert(new Vector3(x2, yMax, 0)); + + if (!clockwise) + vb.AddVert(new Vector3(xMin, yMax, 0)); + + if (flipX == flipY) + { + vb.AddTriangle(0, 1, 2); + vb.AddTriangle(0, 2, 3); + } + else + { + vb.AddTriangle(2, 1, 0); + vb.AddTriangle(3, 2, 0); + } + } //8 vertex static void FillRadial180(VertexBuffer vb, Rectangle vertRect, Origin180 origin, float amount, bool clockwise) diff --git a/Engine/CLEngine.Core/gui/Core/NGraphics.cs b/Engine/CLEngine.Core/gui/Core/NGraphics.cs index fd9e382..a6bbe13 100644 --- a/Engine/CLEngine.Core/gui/Core/NGraphics.cs +++ b/Engine/CLEngine.Core/gui/Core/NGraphics.cs @@ -29,7 +29,7 @@ namespace FairyGUI NTexture _texture; IMeshFactory _meshFactory; - + Color _color; bool _meshDirty; Rectangle _contentRect; diff --git a/Engine/CLEngine.Core/gui/Core/Shape.cs b/Engine/CLEngine.Core/gui/Core/Shape.cs index 7cf9fd1..c1a13b6 100644 --- a/Engine/CLEngine.Core/gui/Core/Shape.cs +++ b/Engine/CLEngine.Core/gui/Core/Shape.cs @@ -99,16 +99,16 @@ namespace FairyGUI /// public void DrawEllipse(Color fillColor) { - EllipseMesh mesh = graphics.GetMeshFactory(); - mesh.lineWidth = 0; - mesh.startDegree = 0; - mesh.endDegreee = 360; - mesh.fillColor = null; - mesh.centerColor = null; + EllipseMesh mesh = graphics.GetMeshFactory(); + mesh.lineWidth = 0; + mesh.startDegree = 0; + mesh.endDegreee = 360; + mesh.fillColor = null; + mesh.centerColor = null; - graphics.color = fillColor; - graphics.SetMeshDirty(); - } + graphics.color = fillColor; + graphics.SetMeshDirty(); + } /// /// @@ -121,20 +121,20 @@ namespace FairyGUI /// public void DrawEllipse(float lineSize, Color centerColor, Color lineColor, Color fillColor, float startDegree, float endDegree) { - EllipseMesh mesh = graphics.GetMeshFactory(); - mesh.lineWidth = lineSize; - if (centerColor.Equals(fillColor)) - mesh.centerColor = null; - else - mesh.centerColor = centerColor; - mesh.lineColor = lineColor; - mesh.fillColor = null; - mesh.startDegree = startDegree; - mesh.endDegreee = endDegree; - - graphics.color = fillColor; - graphics.SetMeshDirty(); - } + EllipseMesh mesh = graphics.GetMeshFactory(); + mesh.lineWidth = lineSize; + if (centerColor.Equals(fillColor)) + mesh.centerColor = null; + else + mesh.centerColor = centerColor; + mesh.lineColor = lineColor; + mesh.fillColor = null; + mesh.startDegree = startDegree; + mesh.endDegreee = endDegree; + + graphics.color = fillColor; + graphics.SetMeshDirty(); + } /// /// diff --git a/Engine/CLEngine.Core/gui/Core/Stage.cs b/Engine/CLEngine.Core/gui/Core/Stage.cs index f8b5ec6..ec007de 100644 --- a/Engine/CLEngine.Core/gui/Core/Stage.cs +++ b/Engine/CLEngine.Core/gui/Core/Stage.cs @@ -35,10 +35,10 @@ namespace FairyGUI Keys[] _lastKeys; int _lastScrollWheelValue; - /// - /// - /// - public static EventCallback0 beforeUpdate; + /// + /// + /// + public static EventCallback0 beforeUpdate; /// /// /// @@ -69,23 +69,23 @@ namespace FairyGUI get { return false; } } - public IInputHandler _wic { get; } + public IInputHandler _wic { get; } - public static readonly char[] SPECIAL_CHARACTERS = { '\a', '\b', '\n', '\r', '\f', '\t', '\v' }; + public static readonly char[] SPECIAL_CHARACTERS = { '\a', '\b', '\n', '\r', '\f', '\t', '\v' }; - /// - /// - /// - public Stage(Game game, IInputHandler handler) - { - _inst = this; - _wic = handler; - Stage.game = game; + /// + /// + /// + public Stage(Game game, IInputHandler handler) + { + _inst = this; + _wic = handler; + Stage.game = game; - if (handler == null) - game.Window.TextInput += WindowOnTextInput; + if (handler == null) + game.Window.TextInput += WindowOnTextInput; - soundVolume = 1; + soundVolume = 1; _batch = new FairyBatch(); _soundEnabled = true; @@ -101,13 +101,13 @@ namespace FairyGUI } private void WindowOnTextInput(object sender, TextInputEventArgs e) - { - if (!SPECIAL_CHARACTERS.Contains(e.Character)) - { - IMEAdapter.compositionString += e.Character; - } + { + if (!SPECIAL_CHARACTERS.Contains(e.Character)) + { + IMEAdapter.compositionString += e.Character; + } - } + } /// @@ -447,7 +447,7 @@ namespace FairyGUI { Keys key = keys[i]; - switch (key) + switch (key) { case Keys.LeftShift: modifiers |= InputModifierFlags.LShift; @@ -678,10 +678,10 @@ namespace FairyGUI Timers.inst.Update(gameTime); TweenManager.Update(gameTime); - HandleInputCapturer(); - HandleKeyEvents(); + HandleInputCapturer(); + HandleKeyEvents(); HandleMouseEvents(); - if (_focused is InputTextField) + if (_focused is InputTextField) HandleTextInput(); _tempDelegate = beforeUpdate; @@ -704,23 +704,23 @@ namespace FairyGUI afterUpdate = null; } - public void HandleInputCapturer() - { - if (_wic == null) - return; + public void HandleInputCapturer() + { + if (_wic == null) + return; - var getChars = _wic.myCharacters; - foreach (var character in getChars) - { - if (!character.IsUsed && character.CharacterType == 0) - { - IMEAdapter.compositionString += character.Chars; - character.IsUsed = true; - } - } - } + var getChars = _wic.myCharacters; + foreach (var character in getChars) + { + if (!character.IsUsed && character.CharacterType == 0) + { + IMEAdapter.compositionString += character.Chars; + character.IsUsed = true; + } + } + } - /// + /// /// /// /// @@ -887,27 +887,27 @@ namespace FairyGUI public DisplayObject ClickTest() { - if (downTargets.Count == 0 - || clickCancelled - || Math.Abs(x - downX) > 50 || Math.Abs(y - downY) > 50) - { - downTargets.Clear(); - return null; - } + if (downTargets.Count == 0 + || clickCancelled + || Math.Abs(x - downX) > 50 || Math.Abs(y - downY) > 50) + { + downTargets.Clear(); + return null; + } DisplayObject obj = downTargets[0]; - if (obj.stage != null) //依然派发到原来的downTarget,虽然可能它已经偏离当前位置,主要是为了正确处理点击缩放的效果 - { - downTargets.Clear(); - return obj; - } + if (obj.stage != null) //依然派发到原来的downTarget,虽然可能它已经偏离当前位置,主要是为了正确处理点击缩放的效果 + { + downTargets.Clear(); + return obj; + } obj = target; while (obj != null) { int i = downTargets.IndexOf(obj); - if (i != -1 && obj.stage != null) - break; + if (i != -1 && obj.stage != null) + break; obj = obj.parent; } diff --git a/Engine/CLEngine.Core/gui/Core/Text/DynamicFont.cs b/Engine/CLEngine.Core/gui/Core/Text/DynamicFont.cs index d1c7c51..4d6547b 100644 --- a/Engine/CLEngine.Core/gui/Core/Text/DynamicFont.cs +++ b/Engine/CLEngine.Core/gui/Core/Text/DynamicFont.cs @@ -12,12 +12,12 @@ namespace FairyGUI int _size; FontStyle _style; - static Dictionary sFontCache = new Dictionary(); + static Dictionary sFontCache = new Dictionary(); public DynamicFont(string name) { this.name = name; - } + } override public void SetFormat(TextFormat format, float fontSizeScale) { diff --git a/Engine/CLEngine.Core/gui/Core/Text/IInputHandler.cs b/Engine/CLEngine.Core/gui/Core/Text/IInputHandler.cs index a53c15c..435d19b 100644 --- a/Engine/CLEngine.Core/gui/Core/Text/IInputHandler.cs +++ b/Engine/CLEngine.Core/gui/Core/Text/IInputHandler.cs @@ -2,17 +2,17 @@ namespace FairyGUI { - public interface IInputHandler - { - List myCharacters { get; set; } - } + public interface IInputHandler + { + List myCharacters { get; set; } + } - public interface ICharacter - { - bool IsUsed { get; set; } + public interface ICharacter + { + bool IsUsed { get; set; } - int CharacterType { get; set; } + int CharacterType { get; set; } - char Chars { get; set; } - } + char Chars { get; set; } + } } \ No newline at end of file diff --git a/Engine/CLEngine.Core/gui/Core/Text/IMEAdapter.cs b/Engine/CLEngine.Core/gui/Core/Text/IMEAdapter.cs index e28f720..6de1e50 100644 --- a/Engine/CLEngine.Core/gui/Core/Text/IMEAdapter.cs +++ b/Engine/CLEngine.Core/gui/Core/Text/IMEAdapter.cs @@ -63,7 +63,7 @@ namespace FairyGUI get; set; } - public static string candidataString { get; set; } + public static string candidataString { get; set; } static IMEAdapter() diff --git a/Engine/CLEngine.Core/gui/Core/Text/TextField.cs b/Engine/CLEngine.Core/gui/Core/Text/TextField.cs index 1290d7f..8407041 100644 --- a/Engine/CLEngine.Core/gui/Core/Text/TextField.cs +++ b/Engine/CLEngine.Core/gui/Core/Text/TextField.cs @@ -44,11 +44,11 @@ namespace FairyGUI int _yOffset; float _fontSizeScale; float _globalScale; - Bitmap _canvas; - NTexture _texture; - VertAlignType lineVAlign = UIConfig.richTextRowVerticalAlign; + Bitmap _canvas; + NTexture _texture; + VertAlignType lineVAlign = UIConfig.richTextRowVerticalAlign; - RichTextField _richTextField; + RichTextField _richTextField; const int GUTTER_X = 2; const int GUTTER_Y = 2; @@ -85,11 +85,11 @@ namespace FairyGUI { base.Dispose(); - if (_canvas != null) + if (_canvas != null) _canvas.Dispose(); - } + } - internal void EnableRichSupport(RichTextField richTextField) + internal void EnableRichSupport(RichTextField richTextField) { _richTextField = richTextField; if (_richTextField is InputTextField) @@ -754,9 +754,9 @@ namespace FairyGUI wordChars = 0; wordPossible = true; } - else if (wordPossible && (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || - ch >= '0' && ch <= '9' || ch == '.' || ch == '"' || ch == '\'')) - { + else if (wordPossible && (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || + ch >= '0' && ch <= '9' || ch == '.' || ch == '"' || ch == '\'')) + { if (wordChars == 0) wordStart = line.width; else if (wordChars > 10) @@ -873,7 +873,7 @@ namespace FairyGUI _richTextField.SetSize(_textWidth, _textHeight); else SetSize(_textWidth, _textHeight); - _updatingSize = false; + _updatingSize = false; } else if (_autoSize == AutoSizeType.Height) { @@ -941,7 +941,7 @@ namespace FairyGUI return; } - if (_font is DynamicFont) + if (_font is DynamicFont) BuildMesh_systemFont(vb); else BuildMesh_bitmapFont(vb); @@ -1072,25 +1072,25 @@ namespace FairyGUI } else { - IHtmlObject htmlObj = element.htmlObject; - if (htmlObj != null) - { - if (lineVAlign == VertAlignType.Bottom) - yIndent = (int)(line.height - htmlObj.height); - else if (lineVAlign == VertAlignType.Middle) - yIndent = (int)((line.height - htmlObj.height) / 2); - else - yIndent = 0; - - element.position = new Vector2(charX + 1, line.y + yIndent); - htmlObj.SetPosition(element.position.X, element.position.Y); - if (lineClipped || clipped && (element.position.X < GUTTER_X || element.position.X + htmlObj.width > _contentRect.Width - GUTTER_X)) - element.status |= 1; - else - element.status &= 254; - charX += htmlObj.width + letterSpacing + 2; - } - } + IHtmlObject htmlObj = element.htmlObject; + if (htmlObj != null) + { + if (lineVAlign == VertAlignType.Bottom) + yIndent = (int)(line.height - htmlObj.height); + else if (lineVAlign == VertAlignType.Middle) + yIndent = (int)((line.height - htmlObj.height) / 2); + else + yIndent = 0; + + element.position = new Vector2(charX + 1, line.y + yIndent); + htmlObj.SetPosition(element.position.X, element.position.Y); + if (lineClipped || clipped && (element.position.X < GUTTER_X || element.position.X + htmlObj.width > _contentRect.Width - GUTTER_X)) + element.status |= 1; + else + element.status &= 254; + charX += htmlObj.width + letterSpacing + 2; + } + } } else { @@ -1340,20 +1340,20 @@ namespace FairyGUI continue; } - if (lineVAlign == VertAlignType.Bottom) - yIndent = (int)(line.height - glyph.height); - else if (lineVAlign == VertAlignType.Middle) - yIndent = (int)((line.height + line.textHeight) / 2 - glyph.height); - else - yIndent = (int)(line.textHeight - glyph.height); - if (format.specialStyle == TextFormat.SpecialStyle.Subscript) - yIndent += (int)(glyph.height * 0.333f); - else if (format.specialStyle == TextFormat.SpecialStyle.Superscript) - yIndent -= (int)(lastGlyphHeight - glyph.height * 0.667f); - else - lastGlyphHeight = glyph.height; - - v0.X = charX + glyph.vertMin.X; + if (lineVAlign == VertAlignType.Bottom) + yIndent = (int)(line.height - glyph.height); + else if (lineVAlign == VertAlignType.Middle) + yIndent = (int)((line.height + line.textHeight) / 2 - glyph.height); + else + yIndent = (int)(line.textHeight - glyph.height); + if (format.specialStyle == TextFormat.SpecialStyle.Subscript) + yIndent += (int)(glyph.height * 0.333f); + else if (format.specialStyle == TextFormat.SpecialStyle.Superscript) + yIndent -= (int)(lastGlyphHeight - glyph.height * 0.667f); + else + lastGlyphHeight = glyph.height; + + v0.X = charX + glyph.vertMin.X; v0.Y = line.y + yIndent + glyph.vertMin.Y; v1.X = charX + glyph.vertMax.X; v1.Y = line.y + yIndent + glyph.vertMax.Y; diff --git a/Engine/CLEngine.Core/gui/UI/GButton.cs b/Engine/CLEngine.Core/gui/UI/GButton.cs index 567b4c5..f8009d8 100644 --- a/Engine/CLEngine.Core/gui/UI/GButton.cs +++ b/Engine/CLEngine.Core/gui/UI/GButton.cs @@ -317,23 +317,23 @@ namespace FairyGUI /// If the down effect will simulate too. public void FireClick(bool downEffect, bool clickCall = false) { - if (downEffect && _mode == ButtonMode.Common) - { - SetState(OVER); - Timers.inst.Add(0.1f, 1, (object param) => { SetState(DOWN); }); - Timers.inst.Add(0.2f, 1, (object param) => - { - SetState(UP); - if (clickCall) { } - }); - } - else - { - if (clickCall) - { - onClick.Call(); - } - } + if (downEffect && _mode == ButtonMode.Common) + { + SetState(OVER); + Timers.inst.Add(0.1f, 1, (object param) => { SetState(DOWN); }); + Timers.inst.Add(0.2f, 1, (object param) => + { + SetState(UP); + if (clickCall) { } + }); + } + else + { + if (clickCall) + { + onClick.Call(); + } + } __click(); } diff --git a/Engine/CLEngine.Core/gui/UI/GList.cs b/Engine/CLEngine.Core/gui/UI/GList.cs index fb9d2e5..68c9820 100644 --- a/Engine/CLEngine.Core/gui/UI/GList.cs +++ b/Engine/CLEngine.Core/gui/UI/GList.cs @@ -1931,8 +1931,8 @@ namespace FairyGUI if (deltaSize != 0 || firstItemDeltaSize != 0) this.scrollPane.ChangeContentSizeOnScrolling(0, deltaSize, 0, firstItemDeltaSize); - if (curIndex > 0 && this.numChildren > 0 && this.container.y <= 0 && GetChildAt(0).y > -this.container.y)//最后一页没填满! - return true; + if (curIndex > 0 && this.numChildren > 0 && this.container.y <= 0 && GetChildAt(0).y > -this.container.y)//最后一页没填满! + return true; else return false; } @@ -2100,8 +2100,8 @@ namespace FairyGUI if (deltaSize != 0 || firstItemDeltaSize != 0) this.scrollPane.ChangeContentSizeOnScrolling(deltaSize, 0, firstItemDeltaSize, 0); - if (curIndex > 0 && this.numChildren > 0 && this.container.x <= 0 && GetChildAt(0).x > -this.container.x)//最后一页没填满! - return true; + if (curIndex > 0 && this.numChildren > 0 && this.container.x <= 0 && GetChildAt(0).x > -this.container.x)//最后一页没填满! + return true; else return false; } @@ -2456,10 +2456,10 @@ namespace FairyGUI { float lineSize = 0; int lineStart = 0; - float remainSize; - float remainPercent; + float remainSize; + float remainPercent; - for (i = 0; i < cnt; i++) + for (i = 0; i < cnt; i++) { child = GetChildAt(i); if (foldInvisibleItems && !child.visible) @@ -2479,11 +2479,11 @@ namespace FairyGUI continue; child.SetPosition(curX, curY); - float perc = child.sourceWidth / lineSize; - child.SetSize((float)Math.Round(perc / remainPercent * remainSize), child.height, true); - remainSize -= child.width; - remainPercent -= perc; - curX += child.width + _columnGap; + float perc = child.sourceWidth / lineSize; + child.SetSize((float)Math.Round(perc / remainPercent * remainSize), child.height, true); + remainSize -= child.width; + remainPercent -= perc; + curX += child.width + _columnGap; if (child.height > maxHeight) maxHeight = child.height; @@ -2537,10 +2537,10 @@ namespace FairyGUI { float lineSize = 0; int lineStart = 0; - float remainSize; - float remainPercent; + float remainSize; + float remainPercent; - for (i = 0; i < cnt; i++) + for (i = 0; i < cnt; i++) { child = GetChildAt(i); if (foldInvisibleItems && !child.visible) @@ -2550,9 +2550,9 @@ namespace FairyGUI j++; if (j == _lineCount || i == cnt - 1) { - remainSize = viewHeight - (j - 1) * _lineGap; - remainPercent = 1; - curY = 0; + remainSize = viewHeight - (j - 1) * _lineGap; + remainPercent = 1; + curY = 0; for (j = lineStart; j <= i; j++) { child = GetChildAt(j); @@ -2561,11 +2561,11 @@ namespace FairyGUI child.SetPosition(curX, curY); - float perc = child.sourceHeight / lineSize; - child.SetSize(child.width, (float)Math.Round(perc / remainPercent * remainSize), true); - remainSize -= child.height; - remainPercent -= perc; - curY += child.height + _lineGap; + float perc = child.sourceHeight / lineSize; + child.SetSize(child.width, (float)Math.Round(perc / remainPercent * remainSize), true); + remainSize -= child.height; + remainPercent -= perc; + curY += child.height + _lineGap; if (child.width > maxWidth) maxWidth = child.width; @@ -2624,10 +2624,10 @@ namespace FairyGUI { float lineSize = 0; int lineStart = 0; - float remainSize; - float remainPercent; + float remainSize; + float remainPercent; - for (i = 0; i < cnt; i++) + for (i = 0; i < cnt; i++) { child = GetChildAt(i); if (foldInvisibleItems && !child.visible) @@ -2646,9 +2646,9 @@ namespace FairyGUI j++; if (j == _columnCount || i == cnt - 1) { - remainSize = viewWidth - (j - 1) * _columnGap; - remainPercent = 1; - curX = 0; + remainSize = viewWidth - (j - 1) * _columnGap; + remainPercent = 1; + curX = 0; for (j = lineStart; j <= i; j++) { child = GetChildAt(j); @@ -2657,11 +2657,11 @@ namespace FairyGUI child.SetPosition(page * viewWidth + curX, curY); - float perc = child.sourceWidth / lineSize; - child.SetSize((float)Math.Round(perc / remainPercent * remainSize), _lineCount > 0 ? eachHeight : child.height, true); - remainSize -= child.width; - remainPercent -= perc; - curX += child.width + _columnGap; + float perc = child.sourceWidth / lineSize; + child.SetSize((float)Math.Round(perc / remainPercent * remainSize), _lineCount > 0 ? eachHeight : child.height, true); + remainSize -= child.width; + remainPercent -= perc; + curX += child.width + _columnGap; if (child.height > maxHeight) maxHeight = child.height; diff --git a/Engine/CLEngine.Core/gui/UI/GLoader.cs b/Engine/CLEngine.Core/gui/UI/GLoader.cs index 4e35f16..455fe57 100644 --- a/Engine/CLEngine.Core/gui/UI/GLoader.cs +++ b/Engine/CLEngine.Core/gui/UI/GLoader.cs @@ -8,641 +8,641 @@ using Rectangle = System.Drawing.RectangleF; namespace FairyGUI { - /// - /// GLoader class - /// - public class GLoader : GObject, IAnimationGear, IColorGear - { - /// - /// Display an error sign if the loader fails to load the content. - /// UIConfig.loaderErrorSign muse be set. - /// - public bool showErrorSign; - - string _url; - AlignType _align; - VertAlignType _verticalAlign; - bool _autoSize; - FillType _fill; - bool _shrinkOnly; - bool _updatingLayout; - PackageItem _contentItem; - float _contentWidth; - float _contentHeight; - float _contentSourceWidth; - float _contentSourceHeight; - - MovieClip _content; - GObject _errorSign; - GComponent _content2; - - public GLoader() - { - _url = string.Empty; - _align = AlignType.Left; - _verticalAlign = VertAlignType.Top; - showErrorSign = true; - } - - override protected void CreateDisplayObject() - { - displayObject = new Container(); - displayObject.gOwner = this; - _content = new MovieClip(); - ((Container)displayObject).AddChild(_content); - ((Container)displayObject).opaque = true; - } - - override public void Dispose() - { - if (_content.texture != null) - { - if (_contentItem == null) - FreeExternal(image.texture); - } - if (_errorSign != null) - _errorSign.Dispose(); - if (_content2 != null) - _content2.Dispose(); - _content.Dispose(); - base.Dispose(); - } - - /// - /// - /// - public string url - { - get { return _url; } - set - { - if (_url == value) - return; - - _url = value; - LoadContent(); - UpdateGear(7); - } - } - - override public string icon - { - get { return _url; } - set { this.url = value; } - } - - /// - /// - /// - public AlignType align - { - get { return _align; } - set - { - if (_align != value) - { - _align = value; - UpdateLayout(); - } - } - } - - /// - /// - /// - public VertAlignType verticalAlign - { - get { return _verticalAlign; } - set - { - if (_verticalAlign != value) - { - _verticalAlign = value; - UpdateLayout(); - } - } - } - - /// - /// - /// - public FillType fill - { - get { return _fill; } - set - { - if (_fill != value) - { - _fill = value; - UpdateLayout(); - } - } - } - - /// - /// - /// - public bool shrinkOnly - { - get { return _shrinkOnly; } - set - { - if (_shrinkOnly != value) - { - _shrinkOnly = value; - UpdateLayout(); - } - } - } - - /// - /// - /// - public bool autoSize - { - get { return _autoSize; } - set - { - if (_autoSize != value) - { - _autoSize = value; - UpdateLayout(); - } - } - } - - /// - /// - /// - public bool playing - { - get { return _content.playing; } - set - { - _content.playing = value; - UpdateGear(5); - } - } - - /// - /// - /// - public int frame - { - get { return _content.frame; } - set - { - _content.frame = value; - UpdateGear(5); - } - } - - /// - /// - /// - public float timeScale - { - get { return _content.timeScale; } - set { _content.timeScale = value; } - } - - /// - /// - /// - public bool ignoreEngineTimeScale - { - get { return _content.ignoreEngineTimeScale; } - set { _content.ignoreEngineTimeScale = value; } - } - - /// - /// - /// - /// - public void Advance(float time) - { - _content.Advance(time); - } - - /// - /// - /// - public Color color - { - get { return _content.color; } - set - { - _content.color = value; - UpdateGear(4); - } - } - - /// - /// - /// - public FillMethod fillMethod - { - get { return _content.fillMethod; } - set { _content.fillMethod = value; } - } - - /// - /// - /// - public int fillOrigin - { - get { return _content.fillOrigin; } - set { _content.fillOrigin = value; } - } - - /// - /// - /// - public bool fillClockwise - { - get { return _content.fillClockwise; } - set { _content.fillClockwise = value; } - } - - /// - /// - /// - public float fillAmount - { - get { return _content.fillAmount; } - set { _content.fillAmount = value; } - } - - /// - /// - /// - public Image image - { - get { return _content; } - } - - /// - /// - /// - public MovieClip movieClip - { - get { return _content; } - } - - /// - /// - /// - public GComponent component - { - get { return _content2; } - } - - /// - /// - /// - public NTexture texture - { - get - { - return _content.texture; - } - - set - { - this.url = null; - - _content.texture = value; - if (value != null) - { - _contentSourceWidth = value.width; - _contentSourceHeight = value.height; - } - else - { - _contentSourceWidth = _contentHeight = 0; - } - - UpdateLayout(); - } - } - - override public IFilter filter - { - get { return _content.filter; } - set { _content.filter = value; } - } - - override public BlendMode blendMode - { - get { return _content.blendMode; } - set { _content.blendMode = value; } - } - - /// - /// - /// - protected void LoadContent() - { - ClearContent(); - - if (string.IsNullOrEmpty(_url)) - return; - - if (_url.StartsWith(UIPackage.URL_PREFIX)) - LoadFromPackage(_url); - else - LoadExternal(); - } - - protected void LoadFromPackage(string itemURL) - { - _contentItem = UIPackage.GetItemByURL(itemURL); - - if (_contentItem != null) - { - _contentItem.Load(); - - if (_contentItem.type == PackageItemType.Image) - { - _content.texture = _contentItem.texture; - _content.scale9Grid = _contentItem.scale9Grid; - _content.scaleByTile = _contentItem.scaleByTile; - _content.tileGridIndice = _contentItem.tileGridIndice; - - _contentSourceWidth = _contentItem.width; - _contentSourceHeight = _contentItem.height; - UpdateLayout(); - } - else if (_contentItem.type == PackageItemType.MovieClip) - { - _contentSourceWidth = _contentItem.width; - _contentSourceHeight = _contentItem.height; - - _content.interval = _contentItem.interval; - _content.swing = _contentItem.swing; - _content.repeatDelay = _contentItem.repeatDelay; - _content.frames = _contentItem.frames; - - UpdateLayout(); - } - else if (_contentItem.type == PackageItemType.Component) - { - _contentSourceWidth = _contentItem.width; - _contentSourceHeight = _contentItem.height; - - GObject obj = UIPackage.CreateObjectFromURL(itemURL); - if (obj == null) - SetErrorState(); - else if (!(obj is GComponent)) - { - obj.Dispose(); - SetErrorState(); - } - else - { - _content2 = (GComponent)obj; - ((Container)displayObject).AddChild(_content2.displayObject); - UpdateLayout(); - } - } - else - { - if (_autoSize) - this.SetSize(_contentItem.width, _contentItem.height); - - SetErrorState(); - - Log.Warning("Unsupported type of GLoader: " + _contentItem.type); - } - } - else - SetErrorState(); - } - - virtual protected void LoadExternal() - { - try - { - Texture2D tex = Stage.game.Content.Load(_url); - _content.texture = new NTexture(tex); - } - catch (Exception e) - { - Log.Info("LoadExternal failed: " + e.Message); - } - } - - virtual protected void FreeExternal(NTexture texture) - { - } - - protected void onExternalLoadSuccess(NTexture texture) - { - _content.texture = texture; - _contentSourceWidth = texture.width; - _contentSourceHeight = texture.height; - _content.scale9Grid = null; - _content.scaleByTile = false; - UpdateLayout(); - } - - protected void onExternalLoadFailed() - { - SetErrorState(); - } - - private void SetErrorState() - { - if (!showErrorSign) - return; - - if (_errorSign == null) - { - if (UIConfig.loaderErrorSign != null) - { - _errorSign = UIPackage.CreateObjectFromURL(UIConfig.loaderErrorSign); - } - else - return; - } - - if (_errorSign != null) - { - _errorSign.SetSize(this.width, this.height); - ((Container)displayObject).AddChild(_errorSign.displayObject); - } - } - - private void ClearErrorState() - { - if (_errorSign != null && _errorSign.displayObject.parent != null) - ((Container)displayObject).RemoveChild(_errorSign.displayObject); - } - - private void UpdateLayout() - { - if (_content2 == null && _content.texture == null && _content.frames == null) - { - if (_autoSize) - { - _updatingLayout = true; - this.SetSize(50, 30); - _updatingLayout = false; - } - return; - } - - _contentWidth = _contentSourceWidth; - _contentHeight = _contentSourceHeight; - - if (_autoSize) - { - _updatingLayout = true; - if (_contentWidth == 0) - _contentWidth = 50; - if (_contentHeight == 0) - _contentHeight = 30; - this.SetSize(_contentWidth, _contentHeight); - _updatingLayout = false; - - if (_width == _contentWidth && _height == _contentHeight) - { - if (_content2 != null) - { - _content2.SetPosition(0, 0); - _content2.SetScale(1, 1); - } - else - { - _content.SetPosition(0, 0); - _content.SetSize(_contentWidth, _contentHeight); - } - return; - } - //如果不相等,可能是由于大小限制造成的,要后续处理 - } - - float sx = 1, sy = 1; - if (_fill != FillType.None) - { - sx = this.width / _contentSourceWidth; - sy = this.height / _contentSourceHeight; - - if (sx != 1 || sy != 1) - { - if (_fill == FillType.ScaleMatchHeight) - sx = sy; - else if (_fill == FillType.ScaleMatchWidth) - sy = sx; - else if (_fill == FillType.Scale) - { - if (sx > sy) - sx = sy; - else - sy = sx; - } - else if (_fill == FillType.ScaleNoBorder) - { - if (sx > sy) - sy = sx; - else - sx = sy; - } - - if (_shrinkOnly) - { - if (sx > 1) - sx = 1; - if (sy > 1) - sy = 1; - } - - _contentWidth = (int)Math.Floor(_contentSourceWidth * sx); - _contentHeight = (int)Math.Floor(_contentSourceHeight * sy); - } - } - - if (_content2 != null) - _content2.SetScale(sx, sy); - else - _content.size = new Vector2(_contentWidth, _contentHeight); - - float nx; - float ny; - if (_align == AlignType.Center) - nx = (int)Math.Floor((this.width - _contentWidth) / 2); - else if (_align == AlignType.Right) - nx = (int)Math.Floor(this.width - _contentWidth); - else - nx = 0; - if (_verticalAlign == VertAlignType.Middle) - ny = (int)Math.Floor((this.height - _contentHeight) / 2); - else if (_verticalAlign == VertAlignType.Bottom) - ny = (int)Math.Floor(this.height - _contentHeight); - else - ny = 0; - if (_content2 != null) - _content2.SetPosition(nx, ny); - else - _content.SetPosition(nx, ny); - } - - private void ClearContent() - { - ClearErrorState(); - - if (_content.texture != null) - { - if (_contentItem == null) - FreeExternal(image.texture); - _content.texture = null; - } - _content.frames = null; - - if (_content2 != null) - { - _content2.Dispose(); - _content2 = null; - } - _contentItem = null; - } - - override protected void HandleSizeChanged() - { - base.HandleSizeChanged(); - - if (!_updatingLayout) - UpdateLayout(); - } - - override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos) - { - base.Setup_BeforeAdd(buffer, beginPos); - - buffer.Seek(beginPos, 5); - - _url = buffer.ReadS(); - _align = (AlignType)buffer.ReadByte(); - _verticalAlign = (VertAlignType)buffer.ReadByte(); - _fill = (FillType)buffer.ReadByte(); - _shrinkOnly = buffer.ReadBool(); - _autoSize = buffer.ReadBool(); - showErrorSign = buffer.ReadBool(); - _content.playing = buffer.ReadBool(); - _content.frame = buffer.ReadInt(); - - if (buffer.ReadBool()) - _content.color = buffer.ReadColor(); - _content.fillMethod = (FillMethod)buffer.ReadByte(); - if (_content.fillMethod != FillMethod.None) - { - _content.fillOrigin = buffer.ReadByte(); - _content.fillClockwise = buffer.ReadBool(); - _content.fillAmount = buffer.ReadFloat(); - } - - if (!string.IsNullOrEmpty(_url)) - LoadContent(); - } - } + /// + /// GLoader class + /// + public class GLoader : GObject, IAnimationGear, IColorGear + { + /// + /// Display an error sign if the loader fails to load the content. + /// UIConfig.loaderErrorSign muse be set. + /// + public bool showErrorSign; + + string _url; + AlignType _align; + VertAlignType _verticalAlign; + bool _autoSize; + FillType _fill; + bool _shrinkOnly; + bool _updatingLayout; + PackageItem _contentItem; + float _contentWidth; + float _contentHeight; + float _contentSourceWidth; + float _contentSourceHeight; + + MovieClip _content; + GObject _errorSign; + GComponent _content2; + + public GLoader() + { + _url = string.Empty; + _align = AlignType.Left; + _verticalAlign = VertAlignType.Top; + showErrorSign = true; + } + + override protected void CreateDisplayObject() + { + displayObject = new Container(); + displayObject.gOwner = this; + _content = new MovieClip(); + ((Container)displayObject).AddChild(_content); + ((Container)displayObject).opaque = true; + } + + override public void Dispose() + { + if (_content.texture != null) + { + if (_contentItem == null) + FreeExternal(image.texture); + } + if (_errorSign != null) + _errorSign.Dispose(); + if (_content2 != null) + _content2.Dispose(); + _content.Dispose(); + base.Dispose(); + } + + /// + /// + /// + public string url + { + get { return _url; } + set + { + if (_url == value) + return; + + _url = value; + LoadContent(); + UpdateGear(7); + } + } + + override public string icon + { + get { return _url; } + set { this.url = value; } + } + + /// + /// + /// + public AlignType align + { + get { return _align; } + set + { + if (_align != value) + { + _align = value; + UpdateLayout(); + } + } + } + + /// + /// + /// + public VertAlignType verticalAlign + { + get { return _verticalAlign; } + set + { + if (_verticalAlign != value) + { + _verticalAlign = value; + UpdateLayout(); + } + } + } + + /// + /// + /// + public FillType fill + { + get { return _fill; } + set + { + if (_fill != value) + { + _fill = value; + UpdateLayout(); + } + } + } + + /// + /// + /// + public bool shrinkOnly + { + get { return _shrinkOnly; } + set + { + if (_shrinkOnly != value) + { + _shrinkOnly = value; + UpdateLayout(); + } + } + } + + /// + /// + /// + public bool autoSize + { + get { return _autoSize; } + set + { + if (_autoSize != value) + { + _autoSize = value; + UpdateLayout(); + } + } + } + + /// + /// + /// + public bool playing + { + get { return _content.playing; } + set + { + _content.playing = value; + UpdateGear(5); + } + } + + /// + /// + /// + public int frame + { + get { return _content.frame; } + set + { + _content.frame = value; + UpdateGear(5); + } + } + + /// + /// + /// + public float timeScale + { + get { return _content.timeScale; } + set { _content.timeScale = value; } + } + + /// + /// + /// + public bool ignoreEngineTimeScale + { + get { return _content.ignoreEngineTimeScale; } + set { _content.ignoreEngineTimeScale = value; } + } + + /// + /// + /// + /// + public void Advance(float time) + { + _content.Advance(time); + } + + /// + /// + /// + public Color color + { + get { return _content.color; } + set + { + _content.color = value; + UpdateGear(4); + } + } + + /// + /// + /// + public FillMethod fillMethod + { + get { return _content.fillMethod; } + set { _content.fillMethod = value; } + } + + /// + /// + /// + public int fillOrigin + { + get { return _content.fillOrigin; } + set { _content.fillOrigin = value; } + } + + /// + /// + /// + public bool fillClockwise + { + get { return _content.fillClockwise; } + set { _content.fillClockwise = value; } + } + + /// + /// + /// + public float fillAmount + { + get { return _content.fillAmount; } + set { _content.fillAmount = value; } + } + + /// + /// + /// + public Image image + { + get { return _content; } + } + + /// + /// + /// + public MovieClip movieClip + { + get { return _content; } + } + + /// + /// + /// + public GComponent component + { + get { return _content2; } + } + + /// + /// + /// + public NTexture texture + { + get + { + return _content.texture; + } + + set + { + this.url = null; + + _content.texture = value; + if (value != null) + { + _contentSourceWidth = value.width; + _contentSourceHeight = value.height; + } + else + { + _contentSourceWidth = _contentHeight = 0; + } + + UpdateLayout(); + } + } + + override public IFilter filter + { + get { return _content.filter; } + set { _content.filter = value; } + } + + override public BlendMode blendMode + { + get { return _content.blendMode; } + set { _content.blendMode = value; } + } + + /// + /// + /// + protected void LoadContent() + { + ClearContent(); + + if (string.IsNullOrEmpty(_url)) + return; + + if (_url.StartsWith(UIPackage.URL_PREFIX)) + LoadFromPackage(_url); + else + LoadExternal(); + } + + protected void LoadFromPackage(string itemURL) + { + _contentItem = UIPackage.GetItemByURL(itemURL); + + if (_contentItem != null) + { + _contentItem.Load(); + + if (_contentItem.type == PackageItemType.Image) + { + _content.texture = _contentItem.texture; + _content.scale9Grid = _contentItem.scale9Grid; + _content.scaleByTile = _contentItem.scaleByTile; + _content.tileGridIndice = _contentItem.tileGridIndice; + + _contentSourceWidth = _contentItem.width; + _contentSourceHeight = _contentItem.height; + UpdateLayout(); + } + else if (_contentItem.type == PackageItemType.MovieClip) + { + _contentSourceWidth = _contentItem.width; + _contentSourceHeight = _contentItem.height; + + _content.interval = _contentItem.interval; + _content.swing = _contentItem.swing; + _content.repeatDelay = _contentItem.repeatDelay; + _content.frames = _contentItem.frames; + + UpdateLayout(); + } + else if (_contentItem.type == PackageItemType.Component) + { + _contentSourceWidth = _contentItem.width; + _contentSourceHeight = _contentItem.height; + + GObject obj = UIPackage.CreateObjectFromURL(itemURL); + if (obj == null) + SetErrorState(); + else if (!(obj is GComponent)) + { + obj.Dispose(); + SetErrorState(); + } + else + { + _content2 = (GComponent)obj; + ((Container)displayObject).AddChild(_content2.displayObject); + UpdateLayout(); + } + } + else + { + if (_autoSize) + this.SetSize(_contentItem.width, _contentItem.height); + + SetErrorState(); + + Log.Warning("Unsupported type of GLoader: " + _contentItem.type); + } + } + else + SetErrorState(); + } + + virtual protected void LoadExternal() + { + try + { + Texture2D tex = Stage.game.Content.Load(_url); + _content.texture = new NTexture(tex); + } + catch (Exception e) + { + Log.Info("LoadExternal failed: " + e.Message); + } + } + + virtual protected void FreeExternal(NTexture texture) + { + } + + protected void onExternalLoadSuccess(NTexture texture) + { + _content.texture = texture; + _contentSourceWidth = texture.width; + _contentSourceHeight = texture.height; + _content.scale9Grid = null; + _content.scaleByTile = false; + UpdateLayout(); + } + + protected void onExternalLoadFailed() + { + SetErrorState(); + } + + private void SetErrorState() + { + if (!showErrorSign) + return; + + if (_errorSign == null) + { + if (UIConfig.loaderErrorSign != null) + { + _errorSign = UIPackage.CreateObjectFromURL(UIConfig.loaderErrorSign); + } + else + return; + } + + if (_errorSign != null) + { + _errorSign.SetSize(this.width, this.height); + ((Container)displayObject).AddChild(_errorSign.displayObject); + } + } + + private void ClearErrorState() + { + if (_errorSign != null && _errorSign.displayObject.parent != null) + ((Container)displayObject).RemoveChild(_errorSign.displayObject); + } + + private void UpdateLayout() + { + if (_content2 == null && _content.texture == null && _content.frames == null) + { + if (_autoSize) + { + _updatingLayout = true; + this.SetSize(50, 30); + _updatingLayout = false; + } + return; + } + + _contentWidth = _contentSourceWidth; + _contentHeight = _contentSourceHeight; + + if (_autoSize) + { + _updatingLayout = true; + if (_contentWidth == 0) + _contentWidth = 50; + if (_contentHeight == 0) + _contentHeight = 30; + this.SetSize(_contentWidth, _contentHeight); + _updatingLayout = false; + + if (_width == _contentWidth && _height == _contentHeight) + { + if (_content2 != null) + { + _content2.SetPosition(0, 0); + _content2.SetScale(1, 1); + } + else + { + _content.SetPosition(0, 0); + _content.SetSize(_contentWidth, _contentHeight); + } + return; + } + //如果不相等,可能是由于大小限制造成的,要后续处理 + } + + float sx = 1, sy = 1; + if (_fill != FillType.None) + { + sx = this.width / _contentSourceWidth; + sy = this.height / _contentSourceHeight; + + if (sx != 1 || sy != 1) + { + if (_fill == FillType.ScaleMatchHeight) + sx = sy; + else if (_fill == FillType.ScaleMatchWidth) + sy = sx; + else if (_fill == FillType.Scale) + { + if (sx > sy) + sx = sy; + else + sy = sx; + } + else if (_fill == FillType.ScaleNoBorder) + { + if (sx > sy) + sy = sx; + else + sx = sy; + } + + if (_shrinkOnly) + { + if (sx > 1) + sx = 1; + if (sy > 1) + sy = 1; + } + + _contentWidth = (int)Math.Floor(_contentSourceWidth * sx); + _contentHeight = (int)Math.Floor(_contentSourceHeight * sy); + } + } + + if (_content2 != null) + _content2.SetScale(sx, sy); + else + _content.size = new Vector2(_contentWidth, _contentHeight); + + float nx; + float ny; + if (_align == AlignType.Center) + nx = (int)Math.Floor((this.width - _contentWidth) / 2); + else if (_align == AlignType.Right) + nx = (int)Math.Floor(this.width - _contentWidth); + else + nx = 0; + if (_verticalAlign == VertAlignType.Middle) + ny = (int)Math.Floor((this.height - _contentHeight) / 2); + else if (_verticalAlign == VertAlignType.Bottom) + ny = (int)Math.Floor(this.height - _contentHeight); + else + ny = 0; + if (_content2 != null) + _content2.SetPosition(nx, ny); + else + _content.SetPosition(nx, ny); + } + + private void ClearContent() + { + ClearErrorState(); + + if (_content.texture != null) + { + if (_contentItem == null) + FreeExternal(image.texture); + _content.texture = null; + } + _content.frames = null; + + if (_content2 != null) + { + _content2.Dispose(); + _content2 = null; + } + _contentItem = null; + } + + override protected void HandleSizeChanged() + { + base.HandleSizeChanged(); + + if (!_updatingLayout) + UpdateLayout(); + } + + override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos) + { + base.Setup_BeforeAdd(buffer, beginPos); + + buffer.Seek(beginPos, 5); + + _url = buffer.ReadS(); + _align = (AlignType)buffer.ReadByte(); + _verticalAlign = (VertAlignType)buffer.ReadByte(); + _fill = (FillType)buffer.ReadByte(); + _shrinkOnly = buffer.ReadBool(); + _autoSize = buffer.ReadBool(); + showErrorSign = buffer.ReadBool(); + _content.playing = buffer.ReadBool(); + _content.frame = buffer.ReadInt(); + + if (buffer.ReadBool()) + _content.color = buffer.ReadColor(); + _content.fillMethod = (FillMethod)buffer.ReadByte(); + if (_content.fillMethod != FillMethod.None) + { + _content.fillOrigin = buffer.ReadByte(); + _content.fillClockwise = buffer.ReadBool(); + _content.fillAmount = buffer.ReadFloat(); + } + + if (!string.IsNullOrEmpty(_url)) + LoadContent(); + } + } } diff --git a/Engine/CLEngine.Core/gui/UI/GObject.cs b/Engine/CLEngine.Core/gui/UI/GObject.cs index 1f11420..5bd08c6 100644 --- a/Engine/CLEngine.Core/gui/UI/GObject.cs +++ b/Engine/CLEngine.Core/gui/UI/GObject.cs @@ -1530,14 +1530,14 @@ namespace FairyGUI RemoveFromParent(); RemoveEventListeners(); relations.Dispose(); - relations = null; - for (int i = 0; i < 8; i++) - { - GearBase gear = _gears[i]; - if (gear != null) - gear.Dispose(); - } - if (displayObject != null) + relations = null; + for (int i = 0; i < 8; i++) + { + GearBase gear = _gears[i]; + if (gear != null) + gear.Dispose(); + } + if (displayObject != null) { displayObject.gOwner = null; displayObject.Dispose(); diff --git a/Engine/CLEngine.Core/gui/UI/GProgressBar.cs b/Engine/CLEngine.Core/gui/UI/GProgressBar.cs index b1d7319..35f9d3d 100644 --- a/Engine/CLEngine.Core/gui/UI/GProgressBar.cs +++ b/Engine/CLEngine.Core/gui/UI/GProgressBar.cs @@ -82,8 +82,8 @@ namespace FairyGUI { if (_value != value) { - GTween.Kill(this, TweenPropType.Progress, false); - _value = value; + GTween.Kill(this, TweenPropType.Progress, false); + _value = value; Update(_value); } } @@ -103,9 +103,9 @@ namespace FairyGUI public GTweener TweenValue(double value, float duration) { double oldValule; - GTweener twener = GTween.GetTween(this, TweenPropType.Progress); - if (twener != null) - { + GTweener twener = GTween.GetTween(this, TweenPropType.Progress); + if (twener != null) + { oldValule = twener.value.d; twener.Kill(false); } diff --git a/Engine/CLEngine.Core/gui/UI/GSlider.cs b/Engine/CLEngine.Core/gui/UI/GSlider.cs index c80e169..c8adcf3 100644 --- a/Engine/CLEngine.Core/gui/UI/GSlider.cs +++ b/Engine/CLEngine.Core/gui/UI/GSlider.cs @@ -127,7 +127,7 @@ namespace FairyGUI switch (_titleType) { case ProgressTitleType.Percent: - _titleObject.text =(int)Math.Round(percent * 100) + "%"; + _titleObject.text = (int)Math.Round(percent * 100) + "%"; break; case ProgressTitleType.ValueAndMax: diff --git a/Engine/CLEngine.Core/gui/UI/Gears/GearBase.cs b/Engine/CLEngine.Core/gui/UI/Gears/GearBase.cs index 97448ce..5b2cc7f 100644 --- a/Engine/CLEngine.Core/gui/UI/Gears/GearBase.cs +++ b/Engine/CLEngine.Core/gui/UI/Gears/GearBase.cs @@ -18,19 +18,19 @@ namespace FairyGUI _owner = owner; } - public void Dispose() - { - if (_tweenConfig != null && _tweenConfig._tweener != null) - { - _tweenConfig._tweener.Kill(); - _tweenConfig._tweener = null; - } - } - - /// - /// Controller object. - /// - public Controller controller + public void Dispose() + { + if (_tweenConfig != null && _tweenConfig._tweener != null) + { + _tweenConfig._tweener.Kill(); + _tweenConfig._tweener = null; + } + } + + /// + /// Controller object. + /// + public Controller controller { get { diff --git a/Engine/CLEngine.Core/gui/UI/Transition.cs b/Engine/CLEngine.Core/gui/UI/Transition.cs index f32b004..77d5b59 100644 --- a/Engine/CLEngine.Core/gui/UI/Transition.cs +++ b/Engine/CLEngine.Core/gui/UI/Transition.cs @@ -403,8 +403,8 @@ namespace FairyGUI { int cnt = _items.Length; object value; - bool found = false; - for (int i = 0; i < cnt; i++) + bool found = false; + for (int i = 0; i < cnt; i++) { TransitionItem item = _items[i]; if (item.label == label) @@ -413,13 +413,13 @@ namespace FairyGUI value = item.tweenConfig.startValue; else value = item.value; - found = true; - } + found = true; + } else if (item.tweenConfig != null && item.tweenConfig.endLabel == label) { value = item.tweenConfig.endValue; - found = true; - } + found = true; + } else continue; @@ -507,9 +507,9 @@ namespace FairyGUI } } - if (!found) - throw new Exception("label not exists"); - } + if (!found) + throw new Exception("label not exists"); + } /// /// @@ -519,27 +519,27 @@ namespace FairyGUI public void SetHook(string label, TransitionHook callback) { int cnt = _items.Length; - bool found = false; - for (int i = 0; i < cnt; i++) + bool found = false; + for (int i = 0; i < cnt; i++) { TransitionItem item = _items[i]; if (item.label == label) { item.hook = callback; - found = true; - break; + found = true; + break; } else if (item.tweenConfig != null && item.tweenConfig.endLabel == label) { item.tweenConfig.endHook = callback; - found = true; - break; + found = true; + break; } } - if (!found) - throw new Exception("label not exists"); - } + if (!found) + throw new Exception("label not exists"); + } /// /// @@ -564,29 +564,29 @@ namespace FairyGUI public void SetTarget(string label, GObject newTarget) { int cnt = _items.Length; - bool found = false; - for (int i = 0; i < cnt; i++) + bool found = false; + for (int i = 0; i < cnt; i++) { TransitionItem item = _items[i]; if (item.label == label) { - item.targetId = (newTarget == _owner || newTarget == null) ? string.Empty : newTarget.id; - item.target = null; if (_playing) - { - if (item.targetId.Length > 0) - item.target = _owner.GetChildById(item.targetId); - else - item.target = _owner; - } - else - item.target = null; - found = true; - } + item.targetId = (newTarget == _owner || newTarget == null) ? string.Empty : newTarget.id; + item.target = null; if (_playing) + { + if (item.targetId.Length > 0) + item.target = _owner.GetChildById(item.targetId); + else + item.target = _owner; + } + else + item.target = null; + found = true; + } } - if (!found) - throw new Exception("label not exists"); - } + if (!found) + throw new Exception("label not exists"); + } /// /// @@ -596,20 +596,20 @@ namespace FairyGUI public void SetDuration(string label, float value) { int cnt = _items.Length; - bool found = false; - for (int i = 0; i < cnt; i++) + bool found = false; + for (int i = 0; i < cnt; i++) { TransitionItem item = _items[i]; if (item.tweenConfig != null && item.label == label) - { - item.tweenConfig.duration = value; item.tweenConfig.duration = value; - found = true; - } - } - - if (!found) - throw new Exception("label not exists or not a tween label"); - } + { + item.tweenConfig.duration = value; item.tweenConfig.duration = value; + found = true; + } + } + + if (!found) + throw new Exception("label not exists or not a tween label"); + } /// /// diff --git a/Engine/CLEngine.Core/gui/Utils/Timers.cs b/Engine/CLEngine.Core/gui/Utils/Timers.cs index 49361cc..84617d4 100644 --- a/Engine/CLEngine.Core/gui/Utils/Timers.cs +++ b/Engine/CLEngine.Core/gui/Utils/Timers.cs @@ -6,252 +6,252 @@ using Microsoft.Xna.Framework; namespace FairyGUI { - public delegate void TimerCallback(object param); - - /// - /// - /// - public class Timers - { - public static bool catchCallbackExceptions = false; - - Dictionary _items; - Dictionary _toAdd; - List _toRemove; - List _pool; - - public static float time; - public static float deltaTime; - - private static Timers _inst; - public static Timers inst - { - get - { - if (_inst == null) - _inst = new Timers(); - return _inst; - } - } - - public Timers() - { - _inst = this; - - _items = new Dictionary(); - _toAdd = new Dictionary(); - _toRemove = new List(); - _pool = new List(100); - } - - public void Add(float interval, int repeat, TimerCallback callback) - { - Add(interval, repeat, callback, null); - } - - /** + public delegate void TimerCallback(object param); + + /// + /// + /// + public class Timers + { + public static bool catchCallbackExceptions = false; + + Dictionary _items; + Dictionary _toAdd; + List _toRemove; + List _pool; + + public static float time; + public static float deltaTime; + + private static Timers _inst; + public static Timers inst + { + get + { + if (_inst == null) + _inst = new Timers(); + return _inst; + } + } + + public Timers() + { + _inst = this; + + _items = new Dictionary(); + _toAdd = new Dictionary(); + _toRemove = new List(); + _pool = new List(100); + } + + public void Add(float interval, int repeat, TimerCallback callback) + { + Add(interval, repeat, callback, null); + } + + /** * @interval in seconds * @repeat 0 indicate loop infinitely, otherwise the run count **/ - public void Add(float interval, int repeat, TimerCallback callback, object callbackParam) - { - if (callback == null) - { - Log.Warning("timer callback is null, " + interval + "," + repeat); - return; - } - - Anymous_T t; - if (_items.TryGetValue(callback, out t)) - { - t.set(interval, repeat, callback, callbackParam); - t.elapsed = 0; - t.deleted = false; - return; - } - - if (_toAdd.TryGetValue(callback, out t)) - { - t.set(interval, repeat, callback, callbackParam); - return; - } - - t = GetFromPool(); - t.interval = interval; - t.repeat = repeat; - t.callback = callback; - t.param = callbackParam; - _toAdd[callback] = t; - } - - public void CallLater(TimerCallback callback) - { - Add(0.001f, 1, callback); - } - - public void CallLater(TimerCallback callback, object callbackParam) - { - Add(0.001f, 1, callback, callbackParam); - } - - public void AddUpdate(TimerCallback callback) - { - Add(0.001f, 0, callback); - } - - public void AddUpdate(TimerCallback callback, object callbackParam) - { - Add(0.001f, 0, callback, callbackParam); - } - - public bool Exists(TimerCallback callback) - { - if (_toAdd.ContainsKey(callback)) - return true; - - Anymous_T at; - if (_items.TryGetValue(callback, out at)) - return !at.deleted; - - return false; - } - - public void Remove(TimerCallback callback) - { - Anymous_T t; - if (_toAdd.TryGetValue(callback, out t)) - { - _toAdd.Remove(callback); - ReturnToPool(t); - } - - if (_items.TryGetValue(callback, out t)) - t.deleted = true; - } - - private Anymous_T GetFromPool() - { - Anymous_T t; - int cnt = _pool.Count; - if (cnt > 0) - { - t = _pool[cnt - 1]; - _pool.RemoveAt(cnt - 1); - t.deleted = false; - t.elapsed = 0; - } - else - t = new Anymous_T(); - return t; - } - - private void ReturnToPool(Anymous_T t) - { - t.callback = null; - _pool.Add(t); - } - - public void Update(GameTime gameTime) - { - time = (float)gameTime.TotalGameTime.TotalMilliseconds / 1000f; - deltaTime = (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000f; - - float elapsed = deltaTime; - - Dictionary.Enumerator iter; - - if (_items.Count > 0) - { - iter = _items.GetEnumerator(); - while (iter.MoveNext()) - { - Anymous_T i = iter.Current.Value; - if (i.deleted) - { - _toRemove.Add(i); - continue; - } - - i.elapsed += elapsed; - if (i.elapsed < i.interval) - continue; - - i.elapsed -= i.interval; - if (i.elapsed < 0 || i.elapsed > 0.03f) - i.elapsed = 0; - - if (i.repeat > 0) - { - i.repeat--; - if (i.repeat == 0) - { - i.deleted = true; - _toRemove.Add(i); - } - } - if (i.callback != null) - { - if (catchCallbackExceptions) - { - try - { - i.callback(i.param); - } - catch (System.Exception e) - { - i.deleted = true; - Log.Warning("FairyGUI: timer(internal=" + i.interval + ", repeat=" + i.repeat + ") callback error > " + e.Message); - } - } - else - i.callback(i.param); - } - } - iter.Dispose(); - } - - int len = _toRemove.Count; - if (len > 0) - { - for (int k = 0; k < len; k++) - { - Anymous_T i = _toRemove[k]; - if (i.deleted && i.callback != null) - { - _items.Remove(i.callback); - ReturnToPool(i); - } - } - _toRemove.Clear(); - } - - if (_toAdd.Count > 0) - { - iter = _toAdd.GetEnumerator(); - while (iter.MoveNext()) - _items.Add(iter.Current.Key, iter.Current.Value); - iter.Dispose(); - _toAdd.Clear(); - } - } - } - - class Anymous_T - { - public float interval; - public int repeat; - public TimerCallback callback; - public object param; - - public float elapsed; - public bool deleted; - - public void set(float interval, int repeat, TimerCallback callback, object param) - { - this.interval = interval; - this.repeat = repeat; - this.callback = callback; - this.param = param; - } - } + public void Add(float interval, int repeat, TimerCallback callback, object callbackParam) + { + if (callback == null) + { + Log.Warning("timer callback is null, " + interval + "," + repeat); + return; + } + + Anymous_T t; + if (_items.TryGetValue(callback, out t)) + { + t.set(interval, repeat, callback, callbackParam); + t.elapsed = 0; + t.deleted = false; + return; + } + + if (_toAdd.TryGetValue(callback, out t)) + { + t.set(interval, repeat, callback, callbackParam); + return; + } + + t = GetFromPool(); + t.interval = interval; + t.repeat = repeat; + t.callback = callback; + t.param = callbackParam; + _toAdd[callback] = t; + } + + public void CallLater(TimerCallback callback) + { + Add(0.001f, 1, callback); + } + + public void CallLater(TimerCallback callback, object callbackParam) + { + Add(0.001f, 1, callback, callbackParam); + } + + public void AddUpdate(TimerCallback callback) + { + Add(0.001f, 0, callback); + } + + public void AddUpdate(TimerCallback callback, object callbackParam) + { + Add(0.001f, 0, callback, callbackParam); + } + + public bool Exists(TimerCallback callback) + { + if (_toAdd.ContainsKey(callback)) + return true; + + Anymous_T at; + if (_items.TryGetValue(callback, out at)) + return !at.deleted; + + return false; + } + + public void Remove(TimerCallback callback) + { + Anymous_T t; + if (_toAdd.TryGetValue(callback, out t)) + { + _toAdd.Remove(callback); + ReturnToPool(t); + } + + if (_items.TryGetValue(callback, out t)) + t.deleted = true; + } + + private Anymous_T GetFromPool() + { + Anymous_T t; + int cnt = _pool.Count; + if (cnt > 0) + { + t = _pool[cnt - 1]; + _pool.RemoveAt(cnt - 1); + t.deleted = false; + t.elapsed = 0; + } + else + t = new Anymous_T(); + return t; + } + + private void ReturnToPool(Anymous_T t) + { + t.callback = null; + _pool.Add(t); + } + + public void Update(GameTime gameTime) + { + time = (float)gameTime.TotalGameTime.TotalMilliseconds / 1000f; + deltaTime = (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000f; + + float elapsed = deltaTime; + + Dictionary.Enumerator iter; + + if (_items.Count > 0) + { + iter = _items.GetEnumerator(); + while (iter.MoveNext()) + { + Anymous_T i = iter.Current.Value; + if (i.deleted) + { + _toRemove.Add(i); + continue; + } + + i.elapsed += elapsed; + if (i.elapsed < i.interval) + continue; + + i.elapsed -= i.interval; + if (i.elapsed < 0 || i.elapsed > 0.03f) + i.elapsed = 0; + + if (i.repeat > 0) + { + i.repeat--; + if (i.repeat == 0) + { + i.deleted = true; + _toRemove.Add(i); + } + } + if (i.callback != null) + { + if (catchCallbackExceptions) + { + try + { + i.callback(i.param); + } + catch (System.Exception e) + { + i.deleted = true; + Log.Warning("FairyGUI: timer(internal=" + i.interval + ", repeat=" + i.repeat + ") callback error > " + e.Message); + } + } + else + i.callback(i.param); + } + } + iter.Dispose(); + } + + int len = _toRemove.Count; + if (len > 0) + { + for (int k = 0; k < len; k++) + { + Anymous_T i = _toRemove[k]; + if (i.deleted && i.callback != null) + { + _items.Remove(i.callback); + ReturnToPool(i); + } + } + _toRemove.Clear(); + } + + if (_toAdd.Count > 0) + { + iter = _toAdd.GetEnumerator(); + while (iter.MoveNext()) + _items.Add(iter.Current.Key, iter.Current.Value); + iter.Dispose(); + _toAdd.Clear(); + } + } + } + + class Anymous_T + { + public float interval; + public int repeat; + public TimerCallback callback; + public object param; + + public float elapsed; + public bool deleted; + + public void set(float interval, int repeat, TimerCallback callback, object param) + { + this.interval = interval; + this.repeat = repeat; + this.callback = callback; + this.param = param; + } + } } -- Gitee From 8b3f0d2fa0647e243e264c4415d27767e8ebf47e Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Wed, 10 Jul 2019 15:58:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8DaddBtn=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9EitemManager=20=E4=BC=98=E5=8C=96Log?= =?UTF-8?q?=E4=B8=BALogger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CLEditor/App.xaml.cs | 2 +- CLEditor/MainWindow.xaml.cs | 107 +++++++++++++++--- CLEditor/Project Templates/CLEngine.Core.xml | 70 ++++++------ CLEditor/controls/DragDropTreeViewItem.cs | 20 ++-- CLEditor/core/EditorCommands.cs | 2 +- .../graphics_device/SceneViewGameControl.cs | 4 +- CLEditor/model/ScriptsBuilder.cs | 8 +- CLEditor/viewmodel/MainViewModel.cs | 2 +- CLEditor/windows/ManageTagsWindow.xaml.cs | 2 +- .../windows/ProjectExplorerTreeView.xaml.cs | 8 +- Engine/CLEngine.Core/CHelper.cs | 66 +++++++++-- Engine/CLEngine.Core/CLEngine.Core.csproj | 3 +- Engine/CLEngine.Core/DragonBones/CFactory.cs | 2 +- Engine/CLEngine.Core/DragonBones/MiniJSON.cs | 14 +-- Engine/CLEngine.Core/GameObject.cs | 4 +- Engine/CLEngine.Core/GameScene.cs | 2 +- Engine/CLEngine.Core/Log.cs | 61 ---------- Engine/CLEngine.Core/Logger.cs | 101 +++++++++++++++++ Engine/CLEngine.Core/SceneManager.cs | 1 - .../CLEngine.Core/components/TextureBody.cs | 2 +- .../CDT/Delaunay/Sweep/DTSweepContext.cs | 4 +- Engine/CLEngine.Core/framework/ItemManager.cs | 73 ++++++++++++ Engine/CLEngine.Core/framework/ItemObject.cs | 25 +++- Engine/CLEngine.Core/gameObjects/Sprite.cs | 2 +- Engine/CLEngine.Core/gameObjects/Tileset.cs | 10 +- Engine/CLEngine.Core/steam/SteamServer.cs | 4 +- Game/Game.Desktop/MainGame.cs | 2 +- 27 files changed, 429 insertions(+), 172 deletions(-) delete mode 100644 Engine/CLEngine.Core/Log.cs create mode 100644 Engine/CLEngine.Core/Logger.cs create mode 100644 Engine/CLEngine.Core/framework/ItemManager.cs diff --git a/CLEditor/App.xaml.cs b/CLEditor/App.xaml.cs index 06d56c0..e62c811 100644 --- a/CLEditor/App.xaml.cs +++ b/CLEditor/App.xaml.cs @@ -17,7 +17,7 @@ namespace CLEngine.Editor { base.OnStartup(e); - if (SceneManager.GameProject != null && + if (SceneManager.GameProject != null && SceneManager.GameProject.EditorSettings != null && !SceneManager.GameProject.EditorSettings.CatchError) { diff --git a/CLEditor/MainWindow.xaml.cs b/CLEditor/MainWindow.xaml.cs index 35051b9..8f1524e 100644 --- a/CLEditor/MainWindow.xaml.cs +++ b/CLEditor/MainWindow.xaml.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.ComponentModel; using System.Deployment.Application; using System.Diagnostics; using System.Globalization; @@ -62,6 +63,8 @@ namespace CLEngine.Editor string versionInfo; ContextMenu gameViewContextMenu; + private BackgroundWorker backgroundWorker; + private void Initialize() { OutputDataGrid.ItemsSource = EditorHandler.OutputMessages; @@ -101,16 +104,58 @@ namespace CLEngine.Editor .Background("#333") .HasBadge("提示") .HasMessage("欢迎使用CL游戏引擎.") - .Dismiss().WithButton("检查更新", button => - { - // TODO: 检查更新 - }) - .Dismiss().WithButton("更新日志", button => + .Dismiss().WithButton("检查更新", button => { checkforUpdate(); }) + .Dismiss().WithButton("暂不检查", button => { - // TODO: 更新日志 - }) - .Dismiss().WithDelay(TimeSpan.FromSeconds(5)) + }).Dismiss().WithDelay(TimeSpan.FromSeconds(5)) .Queue(); + + backgroundWorker = new BackgroundWorker(); + backgroundWorker.DoWork += BackgroundWorkerOnDoWork; + backgroundWorker.RunWorkerAsync(); + } + + private void BackgroundWorkerOnDoWork(object sender, DoWorkEventArgs e) + { + // 日志检查 + while (true) + { + if (Logger.Messages.Count > 0) + { + var log = Logger.Messages.Dequeue(); + Dispatcher.Invoke(() => + { + var message = App.Manager.CreateMessage(); + + if (log.Type == LogType.Info) + { + message.Accent("#1751C3") + .HasBadge("提示") + .Background("#333"); + } + else if (log.Type == LogType.Warn) + { + message.Accent("#E0A030") + .HasBadge("警告") + .Background("#333"); + } + else if (log.Type == LogType.Error) + { + message.Accent("#F15B19") + .HasBadge("错误") + .Background("#F15B19"); + } + + message.Animates(true) + .AnimationInDuration(0.75) + .AnimationOutDuration(2) + .HasMessage(log.Message) + .Dismiss().WithButton("确定", button => { }) + .Dismiss().WithDelay(TimeSpan.FromSeconds(10)) + .Queue(); + }); + } + } } private void SceneViewGameControlOnDragOver(object sender, DragEventArgs e) @@ -367,10 +412,39 @@ namespace CLEngine.Editor sceneViewGameControl.EditorMode = EditorModes.Select; } - private async void checkForUpdatesBtn_Click(object sender, RoutedEventArgs e) + private void checkForUpdatesBtn_Click(object sender, RoutedEventArgs e) { + checkforUpdate(); } + private void checkforUpdate() + { + int num = CHelper.CheckNewFiles(); + if (num > 0) + { + App.Manager.CreateMessage() + .Accent("#1751C3") + .Animates(true) + .AnimationInDuration(0.75) + .AnimationOutDuration(2) + .Background("#333") + .HasBadge("提示") + .HasMessage("在网站上发现的更新,现在进行升级?") + .Dismiss().WithButton("现在更新", button => + { + CHelper.RunUpdater(); + Application.Current.Shutdown(); + }).Dismiss().WithButton("稍后再说", button => + { + + }).Queue(); + } + else + { + Logger.Info("已是最新版本, 无需更新"); + } + } + private void websiteBtn_Click(object sender, RoutedEventArgs e) { Process.Start("http://www.hyuan.org/"); @@ -646,8 +720,8 @@ namespace CLEngine.Editor //循环遍历引用的程序集名称数组 foreach (AssemblyName strAssmbName in arrReferencedAssmbNames) { - //Console.WriteLine("search: " + SceneManager.GameProject.ProjectPath + "\\" + args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll"); - //Console.WriteLine("aa: " + args.Name.Substring(0, args.Name.IndexOf(","))); + //Console.Info("search: " + SceneManager.GameProject.ProjectPath + "\\" + args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll"); + //Console.Info("aa: " + args.Name.Substring(0, args.Name.IndexOf(","))); //检查引发“AssemblyResolve”事件的程序集名称 if (strAssmbName.FullName.Substring(0, strAssmbName.FullName.IndexOf(",")) == args.Name.Substring(0, args.Name.IndexOf(","))) { @@ -663,10 +737,10 @@ namespace CLEngine.Editor foreach (string fileName in Directory.GetFiles(SceneManager.GameProject.ProjectPath + "\\libs\\")) { string asmName = Path.GetFileName(fileName); - //Console.WriteLine("search: " + asmName.Replace(".dll", "") + " == " + args.Name.Substring(0, args.Name.IndexOf(","))); + //Console.Info("search: " + asmName.Replace(".dll", "") + " == " + args.Name.Substring(0, args.Name.IndexOf(","))); if (asmName.Replace(".dll", "") == args.Name.Substring(0, args.Name.IndexOf(","))) { - // Console.WriteLine("entrei"); + // Console.Info("entrei"); strTempAssmbPath = SceneManager.GameProject.ProjectPath + "\\libs\\" + asmName; break; } @@ -695,7 +769,7 @@ namespace CLEngine.Editor gridSnappingBtn.IsChecked = SceneManager.GameProject.EditorSettings.SnapToGrid; showCollisionsBtn.IsChecked = SceneManager.GameProject.EditorSettings.ShowCollisions; debugViewBtn.IsChecked = Properties.Settings.Default.ShowDebugView; - // Console.WriteLine(sceneEditorControl1.EditorMode + ":" + lastEditorMode); + // Console.Info(sceneEditorControl1.EditorMode + ":" + lastEditorMode); if (sceneViewGameControl.EditorMode != lastEditorMode) { @@ -1116,8 +1190,9 @@ namespace CLEngine.Editor private void LoginOrRegisterBtn_Click(object sender, MouseButtonEventArgs e) { - var loginOrRegisteWin = new LoginOrRegister(); - loginOrRegisteWin.ShowDialog(); + //var loginOrRegisteWin = new LoginOrRegister(); + //loginOrRegisteWin.ShowDialog(); + Logger.Error("不允许登陆"); } private void QuickCreateCollision_Click(object sender, RoutedEventArgs e) diff --git a/CLEditor/Project Templates/CLEngine.Core.xml b/CLEditor/Project Templates/CLEngine.Core.xml index b28817e..bdb31d2 100644 --- a/CLEditor/Project Templates/CLEngine.Core.xml +++ b/CLEditor/Project Templates/CLEngine.Core.xml @@ -1666,7 +1666,7 @@ The context. 第一类参数. - + 获取或设置输出超时。 默认值:1000 = 1秒 @@ -10040,53 +10040,53 @@ if set to true [connect first and last]. if set to true [collide connected]. - + Contains filter data that can determine whether an object should be processed or not. - + Disable the logic on specific categories. Category.None by default. - + Disable the logic on specific groups - + Enable the logic on specific categories Category.All by default. - + Enable the logic on specific groups. - + - + Adds the category. The category. - + Removes the category. The category. - + Determines whether this body ignores the the specified controller. @@ -10095,19 +10095,19 @@ true if the object has the specified category; otherwise, false. - + Adds the category. The category. - + Removes the category. The category. - + Determines whether this body ignores the the specified controller. @@ -10116,19 +10116,19 @@ true if the object has the specified category; otherwise, false. - + Ignores the controller. The controller has no effect on this body. The logic type. - + Restore the controller. The controller affects this body. The logic type. - + Determines whether this body ignores the the specified controller. @@ -10137,55 +10137,55 @@ true if the body has the specified flag; otherwise, false. - + This is a comprarer used for detecting angle difference between rays - + Creates a realistic explosion based on raycasting. Objects in the open will be affected, but objects behind static bodies will not. A body that is half in cover, half in the open will get half the force applied to the end in the open. - + Two degrees: maximum angle from edges to first ray tested - + Ratio of arc length to angle from edges to first ray tested. Defaults to 1/40. - + Ignore Explosion if it happens inside a shape. Default value is false. - + Max angle between rays (used when segment is large). Defaults to 15 degrees - + Maximum number of shapes involved in the explosion. Defaults to 100 - + How many rays per shape/body/segment. Defaults to 5 - + Activate the explosion at the specified position. @@ -10194,18 +10194,18 @@ The explosion force at the explosion point (then is inversely proportional to the square of the distance) A list of bodies and the amount of force that was applied to them. - + Creates a simple explosion that ignores other bodies hiding behind static bodies. - + This is the power used in the power function. A value of 1 means the force applied to bodies in the explosion is linear. A value of 2 means it is exponential. - + Activate the explosion at the specified position. @@ -22360,7 +22360,7 @@ configuration on Steam. Ask Valve for help with this. - + Checks if the current user's Steam client is connected to the Steam servers. If it's not then no real-time services provided by the Steamworks API will be enabled. The Steam @@ -23118,20 +23118,20 @@ When querying the server list you can filter by these tags. - + - Log onto Steam anonymously. + Logger onto Steam anonymously. - + - Log onto Steam anonymously. + Logger onto Steam anonymously. - + Returns true if the server is connected and registered with the Steam master server - You should have called LogOnAnonymous etc on startup. + You should have called LoggerOnAnonymous etc on startup. diff --git a/CLEditor/controls/DragDropTreeViewItem.cs b/CLEditor/controls/DragDropTreeViewItem.cs index 3ebfdf4..58e2b6b 100644 --- a/CLEditor/controls/DragDropTreeViewItem.cs +++ b/CLEditor/controls/DragDropTreeViewItem.cs @@ -33,7 +33,7 @@ namespace CLEngine.Editor.controls DragDropTreeViewItem targetNode = GetNearestContainer(e.Source as UIElement); if (targetNode == null) DragDropHelper.RemoveInsertionAdorner(); - //Console.WriteLine(this.PointFromScreen(Mouse.GetPosition(targetNode))); + //Console.Info(this.PointFromScreen(Mouse.GetPosition(targetNode))); } protected override void OnDragOver(DragEventArgs e) @@ -49,19 +49,19 @@ namespace CLEngine.Editor.controls if (e.GetPosition(targetNode).Y < targetNode.ActualHeight * 0.2f) { // meter em cima - //Console.WriteLine("cima"); + //Console.Info("cima"); DragDropHelper.insertionPlace = DragDropHelper.InsertionPlace.Top; DragDropHelper.CreateInsertionAdorner(targetNode, true); } else if (e.GetPosition(targetNode).Y > targetNode.ActualHeight * 0.8f) { - //Console.WriteLine("baixo"); + //Console.Info("baixo"); DragDropHelper.insertionPlace = DragDropHelper.InsertionPlace.Bottom; DragDropHelper.CreateInsertionAdorner(targetNode, false); } else { - //Console.WriteLine("centro"); + //Console.Info("centro"); DragDropHelper.RemoveInsertionAdorner(); DragDropHelper.insertionPlace = DragDropHelper.InsertionPlace.Center; var converter = new System.Windows.Media.BrushConverter(); @@ -83,19 +83,19 @@ namespace CLEngine.Editor.controls // if (e.GetPosition(targetNode).Y < targetNode.ActualHeight * 0.2f) // { // // meter em cima - // //Console.WriteLine("cima"); + // //Console.Info("cima"); // DragDropHelper.insertionPlace = DragDropHelper.InsertionPlace.Top; // DragDropHelper.CreateInsertionAdorner(targetNode, true); // } // else if (e.GetPosition(targetNode).Y > targetNode.ActualHeight * 0.8f) // { - // //Console.WriteLine("baixo"); + // //Console.Info("baixo"); // DragDropHelper.insertionPlace = DragDropHelper.InsertionPlace.Bottom; // DragDropHelper.CreateInsertionAdorner(targetNode, false); // } // else // { - // //Console.WriteLine("centro"); + // //Console.Info("centro"); // DragDropHelper.insertionPlace = DragDropHelper.InsertionPlace.Center; // var converter = new System.Windows.Media.BrushConverter(); // Background = (Brush)converter.ConvertFromString("#555"); @@ -103,10 +103,10 @@ namespace CLEngine.Editor.controls //} //DragDropTreeViewItem targetNode = GetNearestContainer(e.Source as UIElement); - //Console.WriteLine("op2: " + e.GetPosition(targetNode)); + //Console.Info("op2: " + e.GetPosition(targetNode)); //Mouse.GetPosition(this); ve se da algo de jeito deve dar, le a info eu sei fui eu que fiz -mas. a-cho qeu nao dava vou ver - //Console.WriteLine(this.PointToScreen(Mouse.GetPosition(targetNode))); - //Console.WriteLine("op: " + Mouse.GetPosition(targetNode)); + //Console.Info(this.PointToScreen(Mouse.GetPosition(targetNode))); + //Console.Info("op: " + Mouse.GetPosition(targetNode)); } diff --git a/CLEditor/core/EditorCommands.cs b/CLEditor/core/EditorCommands.cs index de41688..8ccb3c6 100644 --- a/CLEditor/core/EditorCommands.cs +++ b/CLEditor/core/EditorCommands.cs @@ -593,7 +593,7 @@ namespace CLEngine.Editor.core CreateBindCtx(0, out bindCtx); string displayName; moniker[0].GetDisplayName(bindCtx, null, out displayName); - //Console.WriteLine("Display Name: {0}", displayName); + //Console.Info("Display Name: {0}", displayName); bool isVisualStudio = displayName.StartsWith("!VisualStudio"); if (isVisualStudio) { diff --git a/CLEditor/graphics_device/SceneViewGameControl.cs b/CLEditor/graphics_device/SceneViewGameControl.cs index f4a6295..42f331c 100644 --- a/CLEditor/graphics_device/SceneViewGameControl.cs +++ b/CLEditor/graphics_device/SceneViewGameControl.cs @@ -245,7 +245,7 @@ namespace CLEngine.Editor.graphics_device delta = (float)gameTime.ElapsedGameTime.Milliseconds; if (GameInput.IsKeyDown(Keys.LeftShift)) delta *= 3; - //Console.WriteLine(MousePosition.X); + //Console.Info(MousePosition.X); if (leftMouseKeyDown) { @@ -781,7 +781,7 @@ namespace CLEngine.Editor.graphics_device selectionEnd = new Vector2(mouseWorldPosition.X, mouseWorldPosition.Y); } - //Console.WriteLine(selectionStart + ":" + selectionEnd); + //Console.Info(selectionStart + ":" + selectionEnd); selectionArea = MathExtension.RectangleFromVectors(selectionStart, selectionEnd); } diff --git a/CLEditor/model/ScriptsBuilder.cs b/CLEditor/model/ScriptsBuilder.cs index 8469ab8..bcd0f26 100644 --- a/CLEditor/model/ScriptsBuilder.cs +++ b/CLEditor/model/ScriptsBuilder.cs @@ -110,7 +110,7 @@ namespace CLEngine.Editor.model //} //catch (Exception ex) //{ - // Console.WriteLine(ex.Message); + // Console.Info(ex.Message); //} /* Compile project */ @@ -133,10 +133,10 @@ namespace CLEngine.Editor.model //foreach (var tr in logger.Errors) //{ - // Console.WriteLine(tr.ToString()); + // Console.Info(tr.ToString()); //} - //Console.WriteLine(buildResult.OverallResult); + //Console.Info(buildResult.OverallResult); string cPath = SceneManager.GameProject.ProjectPath + @"\bin\" + (SceneManager.GameProject.Debug ? "Debug" : "Release") + "\\" + hash + ".dll"; @@ -152,7 +152,7 @@ namespace CLEngine.Editor.model SceneManager.ActiveScene.Initialize(); } - //Console.WriteLine("Path: " + SceneManager.ScriptsAssembly.GetName().Name); + //Console.Info("Path: " + SceneManager.ScriptsAssembly.GetName().Name); } else { diff --git a/CLEditor/viewmodel/MainViewModel.cs b/CLEditor/viewmodel/MainViewModel.cs index 46c79bc..0c47662 100644 --- a/CLEditor/viewmodel/MainViewModel.cs +++ b/CLEditor/viewmodel/MainViewModel.cs @@ -83,7 +83,7 @@ namespace CLEngine.Editor.ViewModel private bool CanDataBaseAction() { - return false; + return true; } private void ClearTextureBuffAction() diff --git a/CLEditor/windows/ManageTagsWindow.xaml.cs b/CLEditor/windows/ManageTagsWindow.xaml.cs index 5d9766e..e3b254d 100644 --- a/CLEditor/windows/ManageTagsWindow.xaml.cs +++ b/CLEditor/windows/ManageTagsWindow.xaml.cs @@ -24,7 +24,7 @@ namespace CLEngine.Editor.windows { if (e.Key == Key.Enter) { - string text = this.addBtn.Text.Trim(); + string text = this.AddTextBox.Text.Trim(); if (text.Equals(string.Empty)) return; if (!SceneManager.ActiveScene.CommonTags.Contains(text)) diff --git a/CLEditor/windows/ProjectExplorerTreeView.xaml.cs b/CLEditor/windows/ProjectExplorerTreeView.xaml.cs index 2cf0ce5..33111dc 100644 --- a/CLEditor/windows/ProjectExplorerTreeView.xaml.cs +++ b/CLEditor/windows/ProjectExplorerTreeView.xaml.cs @@ -435,7 +435,7 @@ namespace CLEngine.Editor.windows bool found = false; foreach (ExplorerTreeViewItem node in folder.Items) { - //Console.WriteLine(filename + "::::" + node.FullPath.ToLower()); + //Console.Info(filename + "::::" + node.FullPath.ToLower()); if (node.FullPath.ToLower().Equals(filename.ToLower()) && node.Tag.ToString().Equals("file")) { found = true; @@ -620,7 +620,7 @@ namespace CLEngine.Editor.windows { if (_node.Name.ToLower().Equals("compile")) { - //Console.WriteLine("val: " + _node.Attributes.GetNamedItem("Include").Value); + //Console.Info("val: " + _node.Attributes.GetNamedItem("Include").Value); if (_node.Attributes.GetNamedItem("Include").Value.ToLower().Equals(oldValue.ToLower())) { _node.Attributes.GetNamedItem("Include").Value = newValue; @@ -1043,7 +1043,7 @@ namespace CLEngine.Editor.windows // SetForegroundWindow(sharpDevelop.MainWindowHandle); // //sharpDevelop. - // //sharpDevelop.StandardInput.WriteLine(CHelper.MakeExclusiveRelativePath(SceneManager.GameProject.ProjectPath, explorerTreeViewItem.FullPath)); + // //sharpDevelop.StandardInput.Info(CHelper.MakeExclusiveRelativePath(SceneManager.GameProject.ProjectPath, explorerTreeViewItem.FullPath)); // //ProcessStartInfo pinfo = new ProcessStartInfo(); // //pinfo.FileName = @"C:\Program Files (x86)\SharpDevelop\4.3\bin\SharpDevelop.exe"; @@ -1054,7 +1054,7 @@ namespace CLEngine.Editor.windows // //{ // // if (sw.BaseStream.CanWrite) // // { - // // sw.WriteLine(CHelper.MakeExclusiveRelativePath(SceneManager.GameProject.ProjectPath, explorerTreeViewItem.FullPath)); + // // sw.Info(CHelper.MakeExclusiveRelativePath(SceneManager.GameProject.ProjectPath, explorerTreeViewItem.FullPath)); // // } // //} //} diff --git a/Engine/CLEngine.Core/CHelper.cs b/Engine/CLEngine.Core/CHelper.cs index f73cca9..8bded64 100644 --- a/Engine/CLEngine.Core/CHelper.cs +++ b/Engine/CLEngine.Core/CHelper.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.Serialization; @@ -6,6 +7,7 @@ using System.Runtime.Serialization.Formatters.Binary; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; +using System.Windows.Forms; using System.Xml; namespace CLEngine.Core @@ -15,8 +17,58 @@ namespace CLEngine.Core /// 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 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) + public static void SerializeObject(string filename, object objectToSerialize) { try { @@ -118,7 +170,7 @@ namespace CLEngine.Core { Task t = new Task(() => { - //Debug.WriteLine("LE STUPID: " + Windows.ApplicationModel.Package.Current.InstalledLocation.Path + "\\" + filename); + //Debug.Info("LE STUPID: " + Windows.ApplicationModel.Package.Current.InstalledLocation.Path + "\\" + filename); return Serializer.Deserialize(type, Windows.ApplicationModel.Package.Current.InstalledLocation, filename).Result; }); @@ -320,21 +372,21 @@ namespace CLEngine.Core public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver) { - //Console.WriteLine(typeNamespace + "." + typeName); + //Console.Info(typeNamespace + "." + typeName); //Type tx = declaredType; - //Console.WriteLine(tx); + //Console.Info(tx); //Type t = Assembly.GetExecutingAssembly().GetType(typeName); //return t; - //Debug.WriteLine("TESTE::: " + typeName + "::" + declaredType.Name); + //Debug.Info("TESTE::: " + typeName + "::" + declaredType.Name); //return declaredType; - //Debug.WriteLine("TESTE: " + typeNamespace + "." + typeName + " (" + declaredType + ")"); + //Debug.Info("TESTE: " + typeNamespace + "." + typeName + " (" + declaredType + ")"); Type t = SceneManager.ScriptsAssembly.GetType(typeNamespace + "." + typeName); #if WINRT if (t == null) { - //Debug.WriteLine("M: " + typeof(object).GetTypeInfo().Assembly.GetType(typeNamespace + "." + typeName)); + //Debug.Info("M: " + typeof(object).GetTypeInfo().Assembly.GetType(typeNamespace + "." + typeName)); t = declaredType.GetType().GetTypeInfo().Assembly.GetType(typeNamespace + "." + typeName); } #endif diff --git a/Engine/CLEngine.Core/CLEngine.Core.csproj b/Engine/CLEngine.Core/CLEngine.Core.csproj index 69832db..bc641c7 100644 --- a/Engine/CLEngine.Core/CLEngine.Core.csproj +++ b/Engine/CLEngine.Core/CLEngine.Core.csproj @@ -293,6 +293,7 @@ + @@ -441,7 +442,7 @@ - + diff --git a/Engine/CLEngine.Core/DragonBones/CFactory.cs b/Engine/CLEngine.Core/DragonBones/CFactory.cs index ff2d0bb..0e3efca 100644 --- a/Engine/CLEngine.Core/DragonBones/CFactory.cs +++ b/Engine/CLEngine.Core/DragonBones/CFactory.cs @@ -271,7 +271,7 @@ namespace CLEngine.Core.DragonBones { internal static void LogWarning(object message) { - Log.WriteLine("[Warning] [DragonBone]" + message); + Logger.Warn("[DragonBone]" + message); } } } \ No newline at end of file diff --git a/Engine/CLEngine.Core/DragonBones/MiniJSON.cs b/Engine/CLEngine.Core/DragonBones/MiniJSON.cs index debbe14..1ad0956 100644 --- a/Engine/CLEngine.Core/DragonBones/MiniJSON.cs +++ b/Engine/CLEngine.Core/DragonBones/MiniJSON.cs @@ -53,16 +53,16 @@ namespace MiniJSON { // // var dict = Json.Deserialize(jsonString) as Dictionary; // - // Debug.Log("deserialized: " + dict.GetType()); - // Debug.Log("dict['array'][0]: " + ((List) dict["array"])[0]); - // Debug.Log("dict['string']: " + (string) dict["string"]); - // Debug.Log("dict['float']: " + (double) dict["float"]); // floats come out as doubles - // Debug.Log("dict['int']: " + (long) dict["int"]); // ints come out as longs - // Debug.Log("dict['unicode']: " + (string) dict["unicode"]); + // Debug.Logger("deserialized: " + dict.GetType()); + // Debug.Logger("dict['array'][0]: " + ((List) dict["array"])[0]); + // Debug.Logger("dict['string']: " + (string) dict["string"]); + // Debug.Logger("dict['float']: " + (double) dict["float"]); // floats come out as doubles + // Debug.Logger("dict['int']: " + (long) dict["int"]); // ints come out as longs + // Debug.Logger("dict['unicode']: " + (string) dict["unicode"]); // // var str = Json.Serialize(dict); // - // Debug.Log("serialized: " + str); + // Debug.Logger("serialized: " + str); // } // } diff --git a/Engine/CLEngine.Core/GameObject.cs b/Engine/CLEngine.Core/GameObject.cs index f9396b8..953a828 100644 --- a/Engine/CLEngine.Core/GameObject.cs +++ b/Engine/CLEngine.Core/GameObject.cs @@ -899,8 +899,8 @@ namespace CLEngine.Core List props = new List(component.GetType().GetRuntimeProperties()); foreach (PropertyInfo info in props) { - Debug.WriteLine("cc: " + component.GetType().Name + " c:" + component.Transform.gameObject + " b: " + pinfo.Name); - Debug.WriteLine("VALUE: " + pinfo.GetValue(component, null)); + Debug.Info("cc: " + component.GetType().Name + " c:" + component.Transform.gameObject + " b: " + pinfo.Name); + Debug.Info("VALUE: " + pinfo.GetValue(component, null)); } #endif for (var index = 0; index < props.Count; index++) diff --git a/Engine/CLEngine.Core/GameScene.cs b/Engine/CLEngine.Core/GameScene.cs index d5f72ad..ed42b95 100644 --- a/Engine/CLEngine.Core/GameScene.cs +++ b/Engine/CLEngine.Core/GameScene.cs @@ -237,7 +237,7 @@ namespace CLEngine.Core else { world.Step((float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f); - //Console.WriteLine((float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f); + //Console.Info((float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f); } for (int i = markedForRemoval.Count - 1; i >= 0; i--) diff --git a/Engine/CLEngine.Core/Log.cs b/Engine/CLEngine.Core/Log.cs deleted file mode 100644 index b2d18ef..0000000 --- a/Engine/CLEngine.Core/Log.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.Xna.Framework; - -namespace CLEngine.Core -{ - public static class Log - { - #region fields - - private static Queue messages = new Queue(); - private static int outputTimeout = 1000; - private static float outputYield = 0; - - #endregion - - #region properties - - /// - /// 获取或设置输出超时。 默认值:1000 = 1秒 - /// - public static int OutputTimeout - { - get { return outputTimeout; } - set { outputTimeout = value; } - } - - #endregion - - #region methods - - public static void WriteLine(string message, bool immediate = false) - { - message += Environment.NewLine; - Write(message, immediate); - } - - public static void Write(string message, bool immediate = false) - { - if (!immediate) - messages.Enqueue(message); - else - Console.Write(message); - } - - internal static void Update(GameTime gameTime) - { - outputYield -= (float)gameTime.ElapsedGameTime.TotalMilliseconds; - if (outputYield <= 0) - { - outputYield = outputTimeout; - while (messages.Count != 0) - { - Console.Write(messages.Dequeue()); - } - } - } - - #endregion - } -} \ No newline at end of file diff --git a/Engine/CLEngine.Core/Logger.cs b/Engine/CLEngine.Core/Logger.cs new file mode 100644 index 0000000..0886b78 --- /dev/null +++ b/Engine/CLEngine.Core/Logger.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; + +namespace CLEngine.Core +{ + /// + /// 日志类型 + /// + public enum LogType + { + /// + /// 消息 + /// + Info, + /// + /// 警告 + /// + Warn, + /// + /// 错误 + /// + Error, + } + + /// + /// 日志类 + /// + public class Log + { + /// + /// 消息内容 + /// + public string Message { get; set; } + /// + /// 消息类型 + /// + public LogType Type { get; set; } + + /// + /// + /// + /// + /// + public Log(string message, LogType type = LogType.Info) + { + Message = message; + Type = type; + } + } + + /// + /// 记录编辑器/核心日志内容 + /// + public static class Logger + { + #region fields + + /// + /// 消息队列 + /// + public static readonly Queue Messages; + + #endregion + + static Logger() + { + Messages = new Queue(); + } + + #region methods + + /// + /// + /// + /// + public static void Info(string message) + { + Messages.Enqueue(new Log(message)); + } + + /// + /// + /// + /// + public static void Warn(string message) + { + Messages.Enqueue(new Log(message, LogType.Warn)); + } + + /// + /// + /// + /// + public static void Error(string message) + { + Messages.Enqueue(new Log(message, LogType.Error)); + } + + #endregion + } +} \ No newline at end of file diff --git a/Engine/CLEngine.Core/SceneManager.cs b/Engine/CLEngine.Core/SceneManager.cs index 5828620..07fb9bf 100644 --- a/Engine/CLEngine.Core/SceneManager.cs +++ b/Engine/CLEngine.Core/SceneManager.cs @@ -187,7 +187,6 @@ namespace CLEngine.Core public static void Update(GameTime gameTime) { GameInput.Update(); - Log.Update(gameTime); deltaFPSTime += (float)gameTime.ElapsedGameTime.TotalSeconds; if (deltaFPSTime >= 1) diff --git a/Engine/CLEngine.Core/components/TextureBody.cs b/Engine/CLEngine.Core/components/TextureBody.cs index fd4aa86..4326ede 100644 --- a/Engine/CLEngine.Core/components/TextureBody.cs +++ b/Engine/CLEngine.Core/components/TextureBody.cs @@ -110,7 +110,7 @@ namespace CLEngine.Core.components { if (texture != null) { - //Console.WriteLine("aa"); + //Console.Info("aa"); Vertices outline = PolygonTools.CreatePolygon(data, texture.Width, true); Vector2 centroid = -new Vector2(texture.Width / 2, texture.Height / 2);//-outline.GetCentroid(); outline.Translate(ref centroid); diff --git a/Engine/CLEngine.Core/farseer/Common/Decomposition/CDT/Delaunay/Sweep/DTSweepContext.cs b/Engine/CLEngine.Core/farseer/Common/Decomposition/CDT/Delaunay/Sweep/DTSweepContext.cs index 7ee0ee3..bc92164 100644 --- a/Engine/CLEngine.Core/farseer/Common/Decomposition/CDT/Delaunay/Sweep/DTSweepContext.cs +++ b/Engine/CLEngine.Core/farseer/Common/Decomposition/CDT/Delaunay/Sweep/DTSweepContext.cs @@ -70,14 +70,14 @@ namespace FarseerPhysics.Common.Decomposition.CDT.Delaunay.Sweep public void AddNode(AdvancingFrontNode node) { - // Console.WriteLine( "add:" + node.key + ":" + System.identityHashCode(node.key)); + // Console.Info( "add:" + node.key + ":" + System.identityHashCode(node.key)); // m_nodeTree.put( node.getKey(), node ); aFront.AddNode(node); } public void RemoveNode(AdvancingFrontNode node) { - // Console.WriteLine( "remove:" + node.key + ":" + System.identityHashCode(node.key)); + // Console.Info( "remove:" + node.key + ":" + System.identityHashCode(node.key)); // m_nodeTree.delete( node.getKey() ); aFront.RemoveNode(node); } diff --git a/Engine/CLEngine.Core/framework/ItemManager.cs b/Engine/CLEngine.Core/framework/ItemManager.cs new file mode 100644 index 0000000..3e8bbd7 --- /dev/null +++ b/Engine/CLEngine.Core/framework/ItemManager.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Path = System.IO.Path; + +namespace CLEngine.Core.framework +{ + /// + /// 物品管理器 + /// + public static class ItemManager + { + /// + /// 全局物品 + /// + private static Dictionary _worldItem; + /// + /// 全局物品Id + /// + private static int _worldId; + + static ItemManager() + { + _worldItem = new Dictionary(); + _worldId = 0; + } + + /// + /// 创建物品 + /// + public static ItemObject CreateItem(string name) + { + var item = new ItemObject(name) { Id = _worldId++ }; + _worldItem.Add(name, item); + + return item; + } + + /// + /// 删除物品 + /// + /// + /// + public static ItemObject RemoveItem(string name) + { + var item = new ItemObject(name); + _worldItem.Remove(name); + + return item; + } + + /// + /// 保存全局物品 + /// + public static void SaveWorldItem() + { + if (string.IsNullOrEmpty(SceneManager.GameProject.ProjectPath)) + throw new Exception("未加载工程前无法保存物品信息"); + + var itemPath = Path.Combine(SceneManager.GameProject.ProjectPath, "Content", "Items"); + Directory.CreateDirectory(itemPath); + try + { + CHelper.SerializeObject(Path.Combine(itemPath, "items.db"), _worldItem); + Logger.Info("物品保存成功"); + } + catch (Exception e) + { + throw new Exception(e.Message); + } + } + } +} \ No newline at end of file diff --git a/Engine/CLEngine.Core/framework/ItemObject.cs b/Engine/CLEngine.Core/framework/ItemObject.cs index d0bce5d..dd9a07d 100644 --- a/Engine/CLEngine.Core/framework/ItemObject.cs +++ b/Engine/CLEngine.Core/framework/ItemObject.cs @@ -3,6 +3,7 @@ using System.Runtime.Serialization; using System.Collections.Generic; using Microsoft.Xna.Framework.Graphics; using System.IO; +using Microsoft.Xna.Framework; namespace CLEngine.Core.framework { @@ -66,7 +67,7 @@ namespace CLEngine.Core.framework [DataMember] private int _addHeroMp; [DataMember] private int _addReturnHp; [DataMember] private int _addReturnMp; - [DataMember] private Dictionary customProp; + [DataMember] private Dictionary _customProp; [NonSerialized] private Texture2D _texture; /// @@ -136,6 +137,11 @@ namespace CLEngine.Core.framework /// 最大耐久 /// public int MaxHp { get { return _maxHp; } set { _maxHp = value; } } + /// + /// 所在背包的位置 + /// + public Vector2 BagPosition { get; set; } + /// /// 附加属性:移动速度 /// @@ -164,6 +170,17 @@ namespace CLEngine.Core.framework /// 附加属性:角色魔法值恢复 /// public int AddReturnMp { get { return _addReturnMp; } set { _addReturnMp = value; } } + + /// + /// + /// + /// 物品名称 + public ItemObject(string name = "") + { + BagPosition = Vector2.Zero; + Name = name; + } + /// /// 设置自定义值 /// @@ -171,11 +188,11 @@ namespace CLEngine.Core.framework /// public void SetcustomProp(string name, object customprop) { - if (customProp.ContainsKey(name)) + if (_customProp.ContainsKey(name)) { throw new Exception("自定义值" + name + "不允许重复"); } - customProp[name] = customprop; + _customProp[name] = customprop; } /// /// 获取自定义值 @@ -184,7 +201,7 @@ namespace CLEngine.Core.framework /// public object GetcustomProp(string name) { - return customProp[name]; + return _customProp[name]; } /// /// 使用物品 diff --git a/Engine/CLEngine.Core/gameObjects/Sprite.cs b/Engine/CLEngine.Core/gameObjects/Sprite.cs index 245f2db..1afa713 100644 --- a/Engine/CLEngine.Core/gameObjects/Sprite.cs +++ b/Engine/CLEngine.Core/gameObjects/Sprite.cs @@ -313,7 +313,7 @@ namespace CLEngine.Core { spriteBatch.Begin(SpriteSortMode.Deferred, this.blendState, SamplerState.LinearClamp, null, RasterizerState.CullNone, null, SceneManager.ActiveCamera.TransformMatrix); - //Console.WriteLine("rr: " + Transform.Rotation); + //Console.Info("rr: " + Transform.Rotation); if (sourceRectangle == Rectangle.Empty) spriteBatch.Draw(texture, Transform.Position, null, color, Transform.Rotation, Origin, Transform.Scale, spriteEffect, 1); diff --git a/Engine/CLEngine.Core/gameObjects/Tileset.cs b/Engine/CLEngine.Core/gameObjects/Tileset.cs index 1eef7c6..252150f 100644 --- a/Engine/CLEngine.Core/gameObjects/Tileset.cs +++ b/Engine/CLEngine.Core/gameObjects/Tileset.cs @@ -319,7 +319,7 @@ namespace CLEngine.Core { if (tiles[x, y] != null) { - // Console.WriteLine(TileWorldPos(x, y)); + // Console.Info(TileWorldPos(x, y)); //Vector2 worldPos = TileWorldPos(x, y); Vector2 worldPos = new Vector2() { X = x * tileWidth, Y = y * tileHeight }; Rectangle nsrc = tiles[x, y].Source; @@ -374,7 +374,7 @@ namespace CLEngine.Core { if (tiles[x, y] != null) { - // Console.WriteLine(TileWorldPos(x, y)); + // Console.Info(TileWorldPos(x, y)); Vector2 worldPos = TileWorldPos(x, y); // use highlight mode? @@ -421,10 +421,10 @@ namespace CLEngine.Core if ((_area = WorldAreaToMatrix(area)) == Rectangle.Empty) return null; - //Console.WriteLine("valido {0}", endPos); + //Console.Info("valido {0}", endPos); Tile[,] result = new Tile[_area.Width, _area.Height]; - //Console.WriteLine(result.GetLength(0) + ":" + result.GetLength(1)); + //Console.Info(result.GetLength(0) + ":" + result.GetLength(1)); for (int x = _area.X; x < _area.X + _area.Width; x++) { @@ -562,7 +562,7 @@ namespace CLEngine.Core else return Rectangle.Empty; } - //Console.WriteLine(startPos); + //Console.Info(startPos); Vector2 endPos = TileMatrixPos(area.X + area.Width, area.Y + area.Height); if (!ValidPosition(endPos)) diff --git a/Engine/CLEngine.Core/steam/SteamServer.cs b/Engine/CLEngine.Core/steam/SteamServer.cs index 544b43a..1248eab 100644 --- a/Engine/CLEngine.Core/steam/SteamServer.cs +++ b/Engine/CLEngine.Core/steam/SteamServer.cs @@ -276,7 +276,7 @@ namespace Steamworks private static string _gametags = ""; /// - /// Log onto Steam anonymously. + /// Logger onto Steam anonymously. /// public static void LogOnAnonymous() { @@ -285,7 +285,7 @@ namespace Steamworks } /// - /// Log onto Steam anonymously. + /// Logger onto Steam anonymously. /// public static void LogOff() { diff --git a/Game/Game.Desktop/MainGame.cs b/Game/Game.Desktop/MainGame.cs index fd12324..e0e7936 100644 --- a/Game/Game.Desktop/MainGame.cs +++ b/Game/Game.Desktop/MainGame.cs @@ -192,7 +192,7 @@ namespace game_win // arguments string arguments = settings.IniReadValue("Console", "Arguments"); - //Console.WriteLine("arguments: " + arguments); + //Console.Info("arguments: " + arguments); if (arguments.Trim() != string.Empty && SceneManager.GameArgs.Length == 0) { SceneManager.GameArgs = arguments.Trim().Split(','); -- Gitee