コード例 #1
0
        /// <summary>
        /// Draws a line from one node to another.
        /// </summary>
        /// <param name="node">The node to draw the lines from.</param>
        /// <param name="g">Graphics supplied from the draw source.</param>
        private void DrawLinesToNextNodes(SpaceNode node, Graphics g, bool isForSelection)
        {
            Pen pen;

            // a highlighted line will be transparent and thicker
            if (isForSelection)
            {
                pen       = new Pen(Color.FromArgb(128, Color.OrangeRed));
                pen.Width = 0.7f;
            }
            else
            {
                pen       = new Pen(Color.FromArgb(128, Color.Cyan));
                pen.Width = 0.2f;
            }

            SpaceNode curNode;

            for (int i = 0; i < node.mNumNextNodes; i++)
            {
                // get our space from the id
                curNode = GetSpaceFromID(node.mNextNodes[i]);

                if (curNode == null)
                {
                    continue;
                }

                // draw the line
                g.DrawLine(pen, GetPointFromNodeID(node.mNodeID, true), GetPointFromNodeID(curNode.mNodeID, true));
            }
        }
コード例 #2
0
 /// <summary>
 /// Gets the location of a node from a Node ID.
 /// </summary>
 /// <param name="nodeID">Node ID to get the position for.</param>
 /// <param name="isCSVNode">Is a node from the CSV file.</param>
 /// <returns></returns>
 private PointF GetPointFromNodeID(string nodeID, bool isCSVNode)
 {
     if (isCSVNode)
     {
         SpaceNode node = mNodes["hook_" + nodeID.PadLeft(3, '0')];
         return(new PointF(node.mPosX, isSidewaysView == true ? node.mPosY : node.mPosZ));
     }
     else
     {
         SpaceNode node = mNodes[nodeID];
         return(new PointF(node.mPosX, isSidewaysView == true ? node.mPosY : node.mPosZ));
     }
 }
コード例 #3
0
        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            SpaceNode node = (SpaceNode)e.Node.Tag;

            try
            {
                spaceInfoGrid.SelectedObject = node;
                isNodeSelected = true;
                panel1.Invalidate();
            }
            catch
            {
                Console.WriteLine("whoops");
            }
        }
コード例 #4
0
        private void deleteSpaceButton_Click(object sender, EventArgs e)
        {
            if (treeView1.SelectedNode == null)
            {
                MessageBox.Show("You need to have a space selected to delete it!");
                return;
            }

            // we need to check if there are nodes connected to this node
            // if there are, we need to set the node that connects with
            // the one being deleted to no longer point to it
            SpaceNode theNode = (SpaceNode)treeView1.SelectedNode.Tag;
            string    nodeID  = theNode.mNodeID;

            foreach (SpaceNode node in mNodes.Values)
            {
                // ignore if our current node shows up here or if the node is null
                if (node == null || node.mNodeID == nodeID)
                {
                    continue;
                }

                for (int i = 0; i < 4; i++)
                {
                    // is our ID we are deleting in this node?
                    // if it is, we clear it and decrement the next node count
                    if (node.mNextNodes[i] == nodeID)
                    {
                        node.mNumNextNodes--;
                        node.mNextNodes[i] = "";
                    }
                }
            }

            // remove the node from the treeview
            treeView1.Nodes.Remove(treeView1.SelectedNode);
            // remove the node from the node dictionary
            mNodes.Remove("hook_" + nodeID.PadLeft(3, '0'));
            // update status label
            statusStrip.Text = "Successfully removed node!";
            // refresh panel
            panel1.Invalidate();
        }
コード例 #5
0
        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            if (!drawFlag)
            {
                return;
            }

            Graphics g = e.Graphics;

            g.SetClip(e.ClipRectangle);
            g.ScaleTransform(curZoom, curZoom);
            g.TranslateTransform(55.0f, 30.0f);
            g.Clear(Color.Black);

            Pen pen = null;

            // got a node selected?
            if (isNodeSelected)
            {
                // get our node
                SpaceNode selectedNode = (SpaceNode)treeView1.SelectedNode.Tag;

                // somehow its null?
                if (selectedNode == null)
                {
                    Console.WriteLine("Node is null, yay");
                }
                else
                {
                    // get our point based on the selected node
                    mSelectionPoint = GetPointFromNodeID(selectedNode.mNodeID, true);

                    // draw a semi-transparent circle
                    SolidBrush b = new SolidBrush(Color.FromArgb(128, Color.LightYellow));
                    e.Graphics.FillEllipse(b, mSelectionPoint.X - 1, mSelectionPoint.Y - 1.5f, 3, 3);

                    // draw the lines to our next nodes
                    DrawLinesToNextNodes(selectedNode, e.Graphics, true);
                }
            }

            int curSpace = 0;

            // decide the color of the space (lol)
            foreach (string key in mNodes.Keys)
            {
                /// skip the first node since it's never an actual space, just a header
                if (curSpace == 0)
                {
                    curSpace++;
                    continue;
                }

                // some hooks dont have spaces
                if (key == "hook_group")
                {
                    continue;
                }

                SpaceNode node = mNodes[key];

                // no node? ignore it
                if (node == null)
                {
                    continue;
                }

                PointF pos = new PointF(node.mPosX, isSidewaysView == true ? node.mPosY : node.mPosZ);

                if (Helper.mNodeTypeToColor.ContainsKey(node.mSpaceType))
                {
                    pen = new Pen(mNodeTypeToColor[node.mSpaceType]);
                    DrawSpace(pen, pos, g);
                }
                else
                {
                    DrawSpace(new Pen(Color.Gold), pos, g);
                }

                // draw the actual lines to the next nodes
                DrawLinesToNextNodes(node, g, false);
            }
        }
コード例 #6
0
        private void PerformOpen(string where)
        {
            treeView1.Nodes.Clear();
            isNodeSelected = false;

            EndianBinaryReader reader = new EndianBinaryReader(File.Open(where, FileMode.Open));

            BEA    bea         = new BEA(ref reader);
            string fileName    = Path.GetFileName(where);
            string assetNumber = fileName.Split('_', '.')[1];

            byte[] bfresArray = bea.GetAssetDataByKey(String.Format("mainmode/bds001_{0}/model/bds001_{0}_hook_mass.fmdb", assetNumber));

            if (bfresArray == null)
            {
                MessageBox.Show("The archive selected does not contain hooks for spaces.");
                return;
            }

            EndianBinaryReader bfresReader = new EndianBinaryReader(bfresArray);

            mBfres = new BFRES(ref bfresReader);

            byte[] csvArray = bea.GetAssetDataByKey(String.Format("mainmode/bds001_{0}/csv/bds001_{0}_map.csv", assetNumber));

            if (csvArray == null)
            {
                MessageBox.Show("The archive selected does not contain the CSV file for space attributes.");
                return;
            }

            StreamReader txtReader = new StreamReader(new MemoryStream(csvArray), Encoding.GetEncoding(932));

            mBoard = new Board(ref txtReader);

            mNodes = new Dictionary <string, SpaceNode>();

            foreach (FSKL.Bone bone in mBfres.mSkeleton.mBones)
            {
                SpaceNode node = GetSpaceFromKey(bone.mName);
                mNodes.Add(bone.mName, GetSpaceFromKey(bone.mName));

                if (node != null)
                {
                    node.SetPosition(bone.mTranslation);

                    string nodeName;

                    try
                    {
                        nodeName = Helper.mSimpleNodeNames[node.mSpaceType];
                    }
                    catch
                    {
                        nodeName = node.mSpaceType;
                    }

                    TreeNode tnode = new TreeNode(nodeName)
                    {
                        Tag = node
                    };

                    treeView1.Nodes.Add(tnode);
                }
            }

            drawFlag         = true;
            statusStrip.Text = "File successfully loaded!";
            panel1.Invalidate();
        }
コード例 #7
0
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (isNodeSelected)
            {
                if (e.Button == MouseButtons.Middle)
                {
                    // convert our position to the new position
                    double curPosX = Math.Round((e.X / 14.0f) - 55.0f, 1);
                    double curPosY = Math.Round((e.Y / 14.0f) - 30.0f, 1);

                    SpaceNode node = (SpaceNode)treeView1.SelectedNode.Tag;
                    node.mPosX = (float)curPosX;
                    node.mPosZ = (float)curPosY;

                    panel1.Invalidate();
                }
            }


            // since we scale the entire thing up by 14x on startup, and we moved it...
            // we need to convert our mouse click position to what the coords are and round to 1 decmial place
            double posX = Math.Round((e.X / curZoom) - 55.0f, 1);
            double posY = Math.Round((e.Y / curZoom) - 30.0f, 1);

            // index to see which node we land on if we get a hit
            int curIndex = 0;

            foreach (SpaceNode node in mNodes.Values)
            {
                // nodes that don't have a position get thrown out
                if (node == null)
                {
                    continue;
                }

                /*
                 * Here is how the selection really works:
                 * The values for node positions is REALLY small.
                 * Due to this, it's nearly impossible to hit a node position dead on.
                 * So we do some bounding by 0.7f, which is the width of each box.
                 * Then we check if it is in the bounds, and if it is, that's our node.
                 */
                double upperX = node.mPosX + 0.7f;
                double lowerX = node.mPosX - 0.7f;

                double upperY = node.mPosZ + 0.7f;
                double lowerY = node.mPosZ - 0.7f;

                if (posX > lowerX && posX < upperX)
                {
                    if (posY > lowerY && posY < upperY)
                    {
                        // make this node our selected node
                        treeView1.SelectedNode = treeView1.Nodes[curIndex];
                        // load into PropertyGrid
                        spaceInfoGrid.SelectedObject = node;
                        isNodeSelected = true;

                        panel1.Invalidate();
                    }
                }

                curIndex++;
            }
        }