private static void WriteNode(XmlTextWriter writer, TextureNode node, string filePath) { WriteElement(writer, "Node", new string[] { "name" }, new string[] { node.Text }); WriteElement(writer, "Position", new string[] { "x", "y" }, new string[] { node.xLocation.ToString(), node.yLocation.ToString() }, true); WriteElement(writer, "Center", new string[] { "x", "y" }, new string[] { node.xCenter.ToString(), node.yCenter.ToString() }, true); if (node.Texture != null) { WriteElement(writer, "Texture", new string[] { "name", "safeName" }, new string[] { GetRelativPath(node.TextureName, filePath), node.SafeTextureName }, true); } Color color = node.Color; WriteElement(writer, "Color", new string[] { "A", "R", "G", "B" }, new string[] { color.A.ToString(), color.R.ToString(), color.G.ToString(), color.B.ToString() }, true); WriteElement(writer, "Dimension", new string[] { "Size", "Aspect" }, new string[] { node.NodeSize.ToString(), node.AspectRatio.ToString() }, true); WriteElement(writer, "Rotation", new string[] { "value" }, new string[] { node.Rotation.ToString() }, true); WriteElement(writer, "Layer", new string[] { "value" }, new string[] { node.Layer.ToString() }, true); foreach (TreeNode child in node.Nodes) { WriteNode(writer, child as TextureNode, filePath); } writer.WriteEndElement(); }
public static void WriteChar(string fileName, TextureNode root, List <Pose> poseList, Pose basePose) { XmlTextWriter writer = new XmlTextWriter(fileName, null); writer.WriteStartDocument(); writer.Formatting = Formatting.Indented; writer.WriteStartElement("Char"); // + char name ? writer.WriteStartElement("Nodes"); WriteNode(writer, root, Path.GetFullPath(fileName)); writer.WriteEndElement(); if (basePose != null && poseList.IndexOf(basePose) != -1 && poseList.Count > 1) { writer.WriteStartElement("Poses"); foreach (Pose pose in poseList) { writePose(writer, pose, basePose, root); } writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); }
public PoseNode GetNode(TextureNode node) { foreach (PoseNode pnv in this.PoseNodes) { if (node == pnv.Node) { return(pnv); } } return(null); }
public void Create(TextureNode root, string[] properties, Pose basePose = null) { this.ClearPoseNodes(); this.DifferentPropertiesCount = 0; List <TextureNode> nodes = new List <TextureNode>(); nodes.Add(root); int baseIndex = 0; while (nodes.Count > 0) { PoseNode pnv = new PoseNode(nodes[0]); foreach (string property in properties) { if (basePose == null) { pnv.SetProperty(property, nodes[0].GetProperty(property)); } else { if (basePose.PoseNodes.Count > baseIndex && basePose.PoseNodes[baseIndex].Properties.ContainsKey(property)) { float val1 = (float)nodes[0].GetProperty(property); float val2 = (float)basePose.PoseNodes[baseIndex].Properties[property]; if (val1 != val2) { pnv.SetProperty(property, val1); } } else { throw new IndexOutOfRangeException("base pose is not correct initialized"); } } } if (pnv.Properties.Count > 0) { this.PoseNodes.Add(pnv); this.DifferentPropertiesCount += pnv.Properties.Count; } else { pnv.Clear(); } baseIndex++; foreach (TreeNode n in nodes[0].Nodes) { nodes.Add(n as TextureNode); } nodes.RemoveAt(0); } }
private static Pose ReadPose(XmlTextReader reader, TextureNode root) { Pose pose = new Pose(reader.GetAttribute(0)); pose.Mode = reader.GetAttribute(1).Equals(PoseMode.Collection.ToString()) ? PoseMode.Collection : PoseMode.Pose; while (reader.Read()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.Name == "Pose") { return(pose); } } if (reader.NodeType == XmlNodeType.Element) { if (reader.Name == "PoseNode") { string[] path = reader.GetAttribute(1).Split('.'); TreeNode node = root; node = root; for (int index = 0; index < path.Length; index++) { if (path.Length > 0) { int i = 0; if (int.TryParse(path[index], out i)) { node = node.Nodes[i]; } } } PoseNode poseNode = new PoseNode(node as TextureNode); ReadProperty(reader, poseNode); pose.MergeAdd(poseNode); } if (reader.Name == "Pose") // if Pose is collection { Pose pose2 = ReadPose(reader, root); pose.Nodes.Add(pose2); } } } return(pose); }
private void createRootItem() { TextureNode root = new TextureNode("Root"); root.Checked = true; this.nodeViewer.Root = root; this.nodeViewer.Selected = root; Pose basePose = new Pose("Base"); this.poseViewer.BasePose = basePose; this.poseViewer.Selected = basePose; resetZoomScrollClickEvent(this, EventArgs.Empty); }
public static TextureNode ReadChar(string fileName, Form1 form) { TextureNode root = null; Pose basePose = null; List <Pose> allPoses = new List <Pose>(); XmlTextReader reader = new XmlTextReader(fileName); try { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.Name == "Node") { root = ReadNode(reader, Path.GetFullPath(fileName), form); } if (reader.Name == "Pose" && root != null) { Pose pose = ReadPose(reader, root); if (pose != null) { allPoses.Add(pose); } } } if (root != null && basePose == null) { basePose = new Pose("Base"); basePose.Create(root, new string[] { "Rotation", "NodeSize" }); allPoses.Add(basePose); } } reader.Close(); form.poseViewer.Poses = allPoses; form.poseViewer.Selected = basePose; } catch (Exception e) { Console.WriteLine(e); } return(root); }
public bool CurrentlyChanging(TextureNode node) { bool result = this.IsCurrentlyChanging; if (!this.IsCurrentlyChanging) { if (Vector2.Distance(node.GlobalPosition, this.NewMousePos) < 10) { this.SetMode(EditorSubMode.CenterMoveMode); } else { Vector4 mT = Vector2.Transform(this.NewMousePos, node.TransformInv); this.CheckMouseMode(new Vector2(mT.X, mT.Y), new Vector2(node.Destination.Width, node.Destination.Height), 10); } } return(result); }
public void Update(bool updateChilds) { if (this.Parent != null && this.Parent is TextureNode) { TextureNode parent = this.Parent as TextureNode; this.ReferenceLength = parent.ReferenceLength * parent.NodeSize;; this.GlobalRotation = this.Rotation + parent.GlobalRotation; this.GlobalAspectRatio = this.AspectRatio;// need rework: +parent.GlobalAspectRatio; Vector4 posNew = Vector2.Transform(this.ReferenceLength * this.position, Matrix.RotationZ(parent.GlobalRotation)); this.dest.Location = parent.GlobalPosition + new Vector2(posNew.X, posNew.Y); } else { // Update Root if (this.TreeView != null) { Game1 game = (this.TreeView.TopLevelControl as Form1).Game; this.ReferenceLength = game.ReferenceLength; this.dest.Location = game.GameCenter + this.position * this.ReferenceLength; this.GlobalRotation = this.Rotation; this.GlobalAspectRatio = this.AspectRatio; } } this.dest.Height = this.ReferenceLength * this.NodeSize; this.dest.Width = dest.Height * this.GlobalAspectRatio; this.GlobalPosition = this.dest.Location; this.Transform = Matrix.Translation(-new Vector3(this.Destination.Width * this.Center.X, this.Destination.Height * this.Center.Y, 0)) * Matrix.RotationZ(this.GlobalRotation) * Matrix.Translation(new Vector3(this.Destination.X, this.Destination.Y, 0)); this.TransformInv = Matrix.Invert(this.Transform); if (updateChilds) { foreach (TreeNode node in this.Nodes) { if (node is TextureNode) { (node as TextureNode).Update(true); } } } }
private void LoadFileOkEvent(object sender, CancelEventArgs e) { this.nodeViewer.SelectNothing(); clearTree(); TextureNode newRoot = CharXML.ReadChar(this.openFileDialog1.FileName, this); if (newRoot != null) { this.nodeViewer.Root = newRoot; this.nodeViewer.Root.Update(true); this.statusLabel.Text = this.openFileDialog1.SafeFileName; } else { clearTree(); createRootItem(); } this.nodeViewer.SelectNothing(); }
public void Draw(TextureNode node, float width, float height) { for (int index = 0; index < 4; index++) { Vector2 vec = GameMode.ModePoints[index] * new Vector2(node.Destination.Width, node.Destination.Height); Vector4 pos = Vector2.Transform(vec, node.Transform); Vector3 pos2 = new Vector3(2 * pos.X / width - 1.0f, 2 * pos.Y / -height + 1.0f, 0); vertices[index * 2].Position = pos2; } for (int index = 0; index < 4; index++) { vertices[index * 2 + 1].Position = (vertices[index * 2].Position + vertices[index * 2 + 2].Position) / 2; } vertices[8] = vertices[0]; effect.CurrentTechnique.Passes[0].Apply(); batch.Begin(); batch.Draw(PrimitiveType.LineStrip, vertices); batch.End(); }
public void Clear() { this.Node = null; this.Properties.Clear(); }
private static void writePose(XmlTextWriter writer, Pose pose, Pose basePose, TextureNode root) { if (basePose != pose) // exclude BasePose { PoseMode poseMode = pose.Mode; WriteElement(writer, "Pose", new string[] { "name", "type" }, new string[] { pose.Text, poseMode.ToString() }); if (pose.PoseNodes.Count > 0 && poseMode == PoseMode.Pose) { foreach (PoseNode poseNode in pose.PoseNodes) { PoseNode baseNode = basePose.GetNode(poseNode.Node); // check null ? string[] values = { poseNode.Node.Text, poseNode.Node.GetIndexPath() }; WriteElement(writer, "PoseNode", new string[] { "name", "path" }, values); foreach (string property in poseNode.Properties.Keys) { string[] pValues = new string[] { property, poseNode.Properties[property].ToString() }; WriteElement(writer, "Property", new string[] { "name", "value" }, pValues, true); } writer.WriteEndElement(); } } else { WriteElement(writer, "Equals", new string[] { "Pose" }, new String[] { basePose.Text }, true); } foreach (TreeNode subPose in pose.Nodes) { writePose(writer, subPose as Pose, basePose, root); } writer.WriteEndElement(); } }
private static TextureNode ReadNode(XmlTextReader reader, string path, Form1 form) { TextureNode output = new TextureNode(reader.GetAttribute(0)); while (reader.Read()) { if (reader.NodeType == XmlNodeType.EndElement) { if (reader.Name == "Node") { return(output); } } if (reader.NodeType == XmlNodeType.Element) { if (reader.Name == "Node") { output.Nodes.Add(ReadNode(reader, path, form)); } if (reader.Name == "Position") { output.xLocation = float.Parse(reader.GetAttribute(0)); output.yLocation = float.Parse(reader.GetAttribute(1)); } if (reader.Name == "Center") { output.xCenter = float.Parse(reader.GetAttribute(0)); output.yCenter = float.Parse(reader.GetAttribute(1)); } if (reader.Name == "Texture") { output.TextureName = Path.GetFullPath(Path.Combine(path, reader.GetAttribute(0))); output.SafeTextureName = reader.GetAttribute(1); output.Texture = form.Game.Content.Load <SharpDX.Toolkit.Graphics.Texture2D>(output.TextureName); output.Image = System.Drawing.Image.FromFile(output.TextureName); output.Checked = true; } if (reader.Name == "Color") { Color color = new Color(); color.A = byte.Parse(reader.GetAttribute(0)); color.R = byte.Parse(reader.GetAttribute(1)); color.G = byte.Parse(reader.GetAttribute(2)); color.B = byte.Parse(reader.GetAttribute(3)); output.Color = color; } if (reader.Name == "Dimension") { output.NodeSize = float.Parse(reader.GetAttribute(0)); output.AspectRatio = float.Parse(reader.GetAttribute(1)); } if (reader.Name == "Rotation") { output.Rotation = float.Parse(reader.GetAttribute(0)); } if (reader.Name == "Layer") { output.Layer = float.Parse(reader.GetAttribute(0)); } } } return(output); }
protected override void Draw(XGame.XGameTime gameTime) { this.GraphicsDevice.Clear(this.backColor); if (this.OnDraw != null) { this.OnDraw(this, EventArgs.Empty); } if (this.DrawGrid && this.Window != null) { this.gridDrawer.Draw(this.Scroll, this.ReferenceLength); } if (this.form.nodeViewer.Root != null) { spritebatch.Begin(spritemode: SpriteSortMode.BackToFront); this.form.nodeViewer.Root.Draw(spritebatch); spritebatch.End(); } if (this.selectedNode != null) { TextureNode n = this.selectedNode; textureBorderDrawer.Draw(n, (this.Window as DXGameWindow).Control.ClientSize.Width, (this.Window as DXGameWindow).Control.ClientSize.Height); spritebatch.Begin(); spritebatch.Draw( this.overlayTex.Texture, n.Destination, null, this.overlayColor, n.GlobalRotation, n.Center * this.overlayTex.Size, SpriteEffects.None, 0.6f); if (n.Texture != null) { Color c = n.Color; c.A = byte.MaxValue; spritebatch.Draw(n.Texture, n.Destination, null, c, n.GlobalRotation, n.Origin, SpriteEffects.None, 0.5f); } if (this.Mode.BasePoseSelected) { spritebatch.Draw( this.centerTex.Texture, n.GlobalPosition, null, Color.Red, 0, this.centerTex.Origin, 0.25f, SpriteEffects.None, 0f); } Vector4 point; Vector2 vec; for (int index = 0; index < (this.Mode.BasePoseSelected ? 8 : 4); index++) { vec = GameMode.ModePoints[index]; point = Vector2.Transform(new Vector2(vec.X * n.Destination.Width, vec.Y * n.Destination.Height), n.Transform); spritebatch.Draw( this.circleTex.Texture, new Vector2(point.X, point.Y), null, Color.White, n.GlobalRotation, this.circleTex.Origin, 0.025f, SpriteEffects.None, 0f); } spritebatch.End(); } }
private void nodeViewer_SelectedChanged(object sender, Controls.TreeViewerEventArgs args) { this.selectedNode = args.Node as TextureNode; }
private void OnMouseMove() { if (this.selectedNode != null) { TextureNode n = this.selectedNode; if (this.Mode.CurrentlyChanging(n)) { switch (this.Mode.Mode) { case EditorMode.None: this.Scroll += (this.Mode.NewMousePos - this.Mode.OldMousePos); this.form.nodeViewer.Root.Update(true); break; case EditorMode.Rotate: Vector2 oldVec = this.Mode.OldMousePos - n.GlobalPosition; Vector2 newVec = this.Mode.NewMousePos - n.GlobalPosition; double arc = Math.Atan2(newVec.Y, newVec.X) - Math.Atan2(oldVec.Y, oldVec.X); double newRot = n.Rotation + arc; if (newRot < 0) { newRot += 2 * Math.PI; } if (newRot >= 2 * Math.PI) { newRot -= 2 * Math.PI; } n.Rotation = (float)newRot; break; case EditorMode.Move: Vector2 mouseDiff = this.Mode.NewMousePos - this.Mode.OldMousePos; Vector4 diff = Vector2.Transform(mouseDiff, Matrix.RotationZ(-(n.GlobalRotation - n.Rotation))); Vector2 diffXY = new Vector2(diff.X, diff.Y); if (this.Mode.SubMode == EditorSubMode.CenterMoveMode) { Vector4 diff2 = Vector2.Transform(mouseDiff, Matrix.RotationZ(-n.GlobalRotation)); n.xCenter += diff2.X / n.Destination.Width; n.yCenter += diff2.Y / n.Destination.Height; } n.Position += diffXY / n.ReferenceLength; break; case EditorMode.Aspect: Vector4 oldM = Vector2.Transform(this.Mode.OldMousePos, n.TransformInv); Vector4 newM = Vector2.Transform(this.Mode.NewMousePos, n.TransformInv); if (this.Mode.SubMode == EditorSubMode.AspectXMode) { float differ = (newM.X < n.Destination.Width / 2) ? (newM.X - oldM.X) : (oldM.X - newM.X); n.AspectRatio -= differ / (0.5f * n.Destination.Width / n.AspectRatio); } else if (this.Mode.SubMode == EditorSubMode.AspectYMode) { float differ = (newM.Y < n.Destination.Height / 2) ? (newM.Y - oldM.Y) : (oldM.Y - newM.Y); n.AspectRatio += differ / (0.5f * n.Destination.Height / n.AspectRatio); n.NodeSize *= 1 - (differ / (0.5f * n.Destination.Height)); } break; } //UpdateNodeInfo(); } } }
public PoseNode(TextureNode node) { this.Node = node; this.Properties = new Dictionary <string, object>(); }