示例#1
0
    public bool IsConstructable(NodeObject node)
    {
        int matchCount   = 0;
        int connectCount = 0;

        for (int i = 0; i < Direction.Length; i++)
        {
            Vector2Int neighborPos = node.Position + Direction[i];
            var        neighbor    = entireNodes[neighborPos];
            if (neighbor.NodeType == ENodeType.Wall)
            {
                connectCount++;
                continue;
            }

            EJointType joint         = node.GetJoint(i);
            EJointType neighborJoint = neighbor.GetJoint2(i);
            if (joint == EJointType.None ||
                neighborJoint == EJointType.None)
            {
                connectCount++;
            }
            else if (joint == neighborJoint)
            {
                connectCount++;
                matchCount++;
            }
        }

        Log.Debug($"Connect : {connectCount} / {matchCount}");

        return((connectCount == 4) && (matchCount > 0));
    }
示例#2
0
    private void FixNode(NodeObject node)
    {
        Vector2Int pos = node.Position;

        for (int i = 0; i < Direction.Length; i++)
        {
            EJointType joint = node.GetJoint(i);
            if (joint != EJointType.None)
            {
                if (node.Neighbors[i] == null)
                {
                    Vector2Int neighborPos = pos + Direction[i];
                    if (entireNodes.ContainsKey(neighborPos))
                    {
                        NodeObject neighbor = entireNodes[neighborPos];
                        EJointType nJoint   = neighbor.GetJoint2(i);
                        if (joint == nJoint)
                        {
                            node.Neighbors[i] = neighbor;
                            neighbor.Neighbors[(i + 2) % 4] = node;
                        }
                    }
                }
            }
        }
    }
        private static TimelineAction ConvertTimeLineAction(TimelineActionData objectData, VisualObject vObject, Dictionary <int, VisualObject> objectTagDictionary)
        {
            TimelineAction timelineAction = new TimelineAction();

            timelineAction.Duration = objectData.Duration;
            timelineAction.Speed    = objectData.Speed;
            if (objectData.Timelines == null || objectData.Timelines.Count <= 0)
            {
                return(timelineAction);
            }
            foreach (TimelineData timeline1 in objectData.Timelines)
            {
                if (objectTagDictionary.ContainsKey(timeline1.ActionTag))
                {
                    NodeObject objectTag = objectTagDictionary[timeline1.ActionTag] as NodeObject;
                    if (objectTag != null)
                    {
                        Timeline timeline2 = Timeline.CreateTimeline(timeline1.FrameType, objectTag);
                        if (timeline1.Frames != null && timeline1.Frames.Count > 0)
                        {
                            foreach (FrameData frame1 in timeline1.Frames)
                            {
                                Frame frame2 = GameProjectLoader.ConvertTimeLineFrame(frame1, timeline1.FrameType);
                                timeline2.Frames.Add(frame2);
                            }
                        }
                    }
                }
            }
            return(timelineAction);
        }
示例#4
0
    private void CreateGrid()
    {
        grid = new Node[sizeX, sizeZ];

        for (int x = 0; x < sizeX; x++)
        {
            for (int z = 0; z < sizeZ; z++)
            {
                float posX = x * offset;
                float posZ = z * offset;

                GameObject go = Instantiate(nodePrefab, new Vector3(posX, 0, posZ), Quaternion.identity) as GameObject;
                // go.transform.parent = transform.GetChild(0).transform;

                NodeObject nodeObj = go.GetComponent <NodeObject>();
                nodeObj.posX = x;
                nodeObj.posZ = z;

                Node node = new Node();
                node.vis          = go;
                node.tileRenderer = node.vis.GetComponentInChildren <MeshRenderer>();
                node.nodePosX     = x;
                node.nodePosZ     = z;
                grid[x, z]        = node;
            }
        }
    }
示例#5
0
 private static void ConvertTimeLineActionData(NodeObject nObject, TimelineActionData nTimelineActionData)
 {
     foreach (NodeObject current in nObject.Children)
     {
         GameProjectLoader.ConvertTimeLineActionData(current, nTimelineActionData);
         foreach (Timeline current2 in current.Timelines)
         {
             if (current2.Frames.Count > 0)
             {
                 TimelineData timelineData = new TimelineData();
                 timelineData.ActionTag = current.ActionTag;
                 timelineData.FrameType = current2.FrameType;
                 timelineData.Frames    = new List <FrameData>();
                 foreach (Frame current3 in current2.OrderedFrames)
                 {
                     string name = current3.GetType().BaseType.Name;
                     if (name == "Frame")
                     {
                         name = current3.GetType().Name;
                     }
                     string    newValue  = name + "Data";
                     string    typeName  = current3.GetType().FullName.Replace("CocoStudio.Model.ViewModel", "CocoStudio.Model.DataModel").Replace(current3.GetType().Name, newValue);
                     FrameData frameData = Activator.CreateInstance(Type.GetType(typeName), true) as FrameData;
                     if (frameData != null)
                     {
                         PropertyInfo[] properties = current3.GetType().GetProperties();
                         PropertyInfo[] array      = properties;
                         for (int i = 0; i < array.Length; i++)
                         {
                             PropertyInfo propertyInfo = array[i];
                             string       name2        = propertyInfo.Name;
                             if (!(name2 == "Children"))
                             {
                                 PropertyInfo property = frameData.GetType().GetProperty(name2);
                                 object       value    = propertyInfo.GetValue(current3, null);
                                 if (property != null && value != null)
                                 {
                                     object obj = value;
                                     if (!property.PropertyType.Equals(propertyInfo.PropertyType))
                                     {
                                         obj = Activator.CreateInstance(property.PropertyType, true);
                                         if (!(obj is IDataConvert))
                                         {
                                             string message = string.Format("Property type are not same, the item is {0}, ViewType is {1}, DataType is {2}, Can use IDataConvert interface to convert.", nObject.GetType().Name, propertyInfo.PropertyType.Name, property.PropertyType.Name);
                                             throw new InvalidCastException(message);
                                         }
                                         ((IDataConvert)obj).SetData(value);
                                     }
                                     property.SetValue(frameData, obj, null);
                                 }
                             }
                         }
                         timelineData.Frames.Add(frameData);
                     }
                 }
                 nTimelineActionData.Timelines.Add(timelineData);
             }
         }
     }
 }
示例#6
0
        public void deleteNode(TreeNode treeNode)
        {
            NodeObject nodeObject = treeNode.Tag as NodeObject;

            if (nodeObject != null)
            {
                if (nodeObject.NodeTag != NodeTag.Root)
                {
                    TreeNode parentNode = treeNode.Parent;
                    if (parentNode != null)
                    {
                        NodeObject parentNodeObject = parentNode.Tag as NodeObject;
                        parentNode.Nodes.Remove(treeNode);
                        if (parentNodeObject != null)
                        {
                            parentNodeObject.ChildNodes.Remove(nodeObject);
                        }

                        ISolutionPlugin.expandTree(parentNode);
                    }
                }
                else
                {
                    treeNode.Nodes.Clear();
                    nodeObject.ChildNodes.Clear();

                    ISolutionPlugin.expandTree(treeNode);
                }
            }
        }
示例#7
0
    void CreateGrid()
    {
        //creating a node with size x & y
        grid = new Node[sizeX, sizeY];
        for (int x = 0; x < sizeX; x++)
        {
            for (int y = 0; y < sizeY; y++)
            {
                float posX = x * offset;
                float posY = y * offset;

                GameObject go = Instantiate(nodePrefab, new Vector3(posX, posY, 0), Quaternion.identity) as GameObject;
                go.transform.parent = transform.GetChild(0).transform;

                NodeObject nodeObj = go.GetComponent <NodeObject>();
                nodeObj.posX = x;
                nodeObj.posY = y;

                Node node = new Node();
                node.vis          = go;
                node.tileRenderer = node.vis.GetComponent <MeshRenderer>();
                node.isWalkable   = true;
                node.nodePosX     = x;
                node.nodePosY     = y;
                grid[x, y]        = node;
            }
        }
    }
示例#8
0
        /// <summary>
        /// Recursivly compares and removes nodes not satisfying the filter text.
        /// </summary>
        /// <param name="treeNode">The tree node and siblings to recursivly check.</param>
        /// <param name="filterText">The text to compare the node text to.</param>
        /// <returns>True if the node was removed from tree, false otherwise.</returns>
        private static bool _ApplyFilter(TreeNode treeNode, String filterText)
        {
            NodeObject nodeObject = (NodeObject)treeNode.Tag;

            if (nodeObject.IsFolder)
            {
                int nodeCount = treeNode.Nodes.Count;
                for (int i = 0; i < nodeCount; i++)
                {
                    if (!_ApplyFilter(treeNode.Nodes[i], filterText))
                    {
                        continue;
                    }

                    i--;
                    nodeCount--;
                }

                if (treeNode.Nodes.Count != 0)
                {
                    return(false);
                }

                treeNode.Remove();
                return(true);
            }

            if (PathMatchSpec(treeNode.Text, filterText))
            {
                return(false);
            }

            treeNode.Remove();
            return(true);
        }
示例#9
0
        /// <summary>
        /// Adds all checked nodes from a TreeNodeCollection to a Collection of TreeNodes.<br />
        /// If the node is a folder, it is not added; instead its children are checked.
        /// </summary>
        /// <param name="nodes">Root TreeNodeCollection to recursivly search.</param>
        /// <param name="checkedNodes">The Collection to add checked nodes to.</param>
        /// <returns>The total number of checked nodes.</returns>
        private static int _GetCheckedNodes(TreeNodeCollection nodes, ICollection <TreeNode> checkedNodes)
        {
            Debug.Assert(checkedNodes != null);

            foreach (TreeNode childNode in nodes)
            {
                // check children
                if (childNode.Nodes.Count > 0)
                {
                    _GetCheckedNodes(childNode.Nodes, checkedNodes);

                    // don't want folders
                    NodeObject nodeObject = (NodeObject)childNode.Tag;
                    if (nodeObject.IsFolder)
                    {
                        continue;
                    }
                }

                if (!childNode.Checked)
                {
                    continue;
                }

                checkedNodes.Add(childNode);
            }

            return(checkedNodes.Count);
        }
示例#10
0
        private void DrawObjects(SpriteBatch spriteBatch, SpriteSortMode sortMode, BlendState blendState, bool drawDecals, bool shadowPass)
        {
            Matrix         cameraTransform = Camera.Instance.GetTransformMatrix();
            NodeObject     obj             = new NodeObject();
            GraphicsDevice graphics        = this.ScreenManager.GraphicsDevice;

            spriteBatch.Begin(sortMode, blendState, SamplerState.AnisotropicWrap, null, null, null, cameraTransform);

            if (drawDecals)
            {
                this._level.DecalManager.Draw(spriteBatch);
                SpriteManager.Instance.Draw(spriteBatch);
            }

            Player.Instance.Draw(spriteBatch);

            for (int i = 0; i < _level.ObjectsList.Count; i++)
            {
                obj = _level.ObjectsList[i];

                //  If it is the shadow pass and the object doesn't cast
                //  shadows, move on.
                if (shadowPass && !obj.CastShadows)
                {
                    continue;
                }

                obj.Draw(spriteBatch, graphics);
            }

            spriteBatch.End();
        }
示例#11
0
    private void CollectNeighborRecursive(NodeObject root, NodeObject neighbor, int direction)
    {
        if (!ReferenceEquals(null, neighbor))
        {
            if (!connExits[root].Contains(neighbor.Position))
            {
                connExits[root].Add(neighbor.Position);
                for (int i = 0; i < 4; i++)
                {
                    if (!neighbor.RouteData.IsTransfer &&
                        neighbor.GetJoint2(direction) != neighbor.GetJoint(i))
                    {
                        continue;
                    }

                    var newNeighbor = neighbor.Neighbors[i];
                    if (!ReferenceEquals(null, newNeighbor))
                    {
                        if (neighbor.GetJoint(i) == newNeighbor.GetJoint2(i))
                        {
                            CollectNeighborRecursive(root, newNeighbor, i);
                        }
                    }
                }
            }
        }
    }
示例#12
0
文件: HSF.cs 项目: ST3RmY/Metanoia
        private void ReadNodes(DataReader reader, int count, uint stringTableOffset)
        {
            for (int i = 0; i < count; i++)
            {
                NodeObject node = new NodeObject();
                Nodes.Add(node);

                node.Name = reader.ReadString(stringTableOffset + reader.ReadUInt32(), -1);
                node.Type = reader.ReadInt32();

                reader.Position += 0x8;

                node.ParentIndex = reader.ReadInt32();
                if (node.ParentIndex < 0)
                {
                    node.ParentIndex = -1;
                }

                reader.Position += 0x8;// unknown

                node.Position = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                node.Rotation = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()) * (float)Math.PI / 180;
                node.Scale    = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

                reader.Position += 0xD4;

                node.MaterialIndex = reader.ReadInt32();

                reader.Position += 0x2C;
            }
        }
    public string GetDir(GetDirHelper data)
    {
        /*  this should be the return structure
        {
         "name": "flare",
         "children": [
          {
           "name": "analytics",
           "children": []
           },
           {
           "name": "analytics",
           "children": []
           }
          ]
        }

         */
        DirectoryInfo rootDir = new DirectoryInfo("C:\\users\\jamyers\\Documents\\Visual Studio 2010\\Projects");
        NodeObject currentNode = new NodeObject();
        currentNode.name = rootDir.Name;
        currentNode.children = new List<NodeObject>();
        currentNode.children.Add(WalkDirectoryTree(rootDir, currentNode));

        return jsonSerialize(currentNode);
    }
示例#14
0
            public DemoApplication()
            {
                LoadCertificateAndPrivateKey();

                uaAppDesc = new ApplicationDescription(
                    "url:qs:DemoApplication", "http://quantensystems.com/",
                    new LocalizedText("en-US", "QuantenSystems demo server"), ApplicationType.Server,
                    null, null, null);

                ItemsRoot = new NodeObject(new NodeId(2, 0), new QualifiedName("Items"), new LocalizedText("Items"), new LocalizedText("Items"), 0, 0, 0);

                // Objects organizes Items
                AddressSpaceTable[new NodeId(UAConst.ObjectsFolder)].References.Add(new ReferenceNode(new NodeId(UAConst.Organizes), new NodeId(2, 0), false));
                ItemsRoot.References.Add(new ReferenceNode(new NodeId(UAConst.Organizes), new NodeId(UAConst.ObjectsFolder), true));
                AddressSpaceTable.TryAdd(ItemsRoot.Id, ItemsRoot);

                TrendNodes = new NodeVariable[1000];
                var nodeTypeFloat = new NodeId(0, 10);

                for (int i = 0; i < TrendNodes.Length; i++)
                {
                    var id = string.Format("Trend {0}", (1 + i).ToString("D6"));
                    TrendNodes[i] = new NodeVariable(new NodeId(2, (uint)(1 + i)), new QualifiedName(id),
                                                     new LocalizedText(id), new LocalizedText(id), 0, 0,
                                                     AccessLevel.CurrentRead | AccessLevel.HistoryRead,
                                                     AccessLevel.CurrentRead | AccessLevel.HistoryRead, 0, true, nodeTypeFloat);

                    ItemsRoot.References.Add(new ReferenceNode(new NodeId(UAConst.Organizes), TrendNodes[i].Id, false));
                    TrendNodes[i].References.Add(new ReferenceNode(new NodeId(UAConst.Organizes), ItemsRoot.Id, true));
                    AddressSpaceTable.TryAdd(TrendNodes[i].Id, TrendNodes[i]);
                }
            }
示例#15
0
        public void _0004_Nodes()
        {
            NodeObject nodes = new NodeObject();

            nodes.Parse("BU_: New_Node_11New_Node_11 1New_Node_10New_Node_101 New_Node_8New_Node_8New_Node_8 New_Node_6_New_ DGT Omron PC");
            Assert.AreEqual("New_Node_11New_Node_11", nodes.Names[0]);
        }
示例#16
0
 public override void Update()
 {
     node = UnityEngine.Object.FindObjectsOfType <NodeObject>().Single(n => n.Id == TutorialData.Id);
     GameTutorialObject.clickedObject = node;
     TutorialObj.SetRect(node.GetColliderCenter(), node.GetColliderSize(), 1);
     TutorialObj.SetText(TutorialData.Text);
 }
示例#17
0
        /// <summary>
        /// Recursively sets the node colors to match the node object states.
        /// </summary>
        /// <param name="treeNodeCollection">The tree nodes to recursively check.</param>
        private static void _AssignColors(TreeNodeCollection treeNodeCollection)
        {
            foreach (TreeNode treeNode in treeNodeCollection)
            {
                if (treeNode.Nodes != null && treeNode.Nodes.Count > 1)
                {
                    _AssignColors(treeNode.Nodes);
                    continue;
                }

                //if (treeNode.Text == "ct_conna.mop")
                //{
                //    int bp = 0;
                //}

                NodeObject nodeObject = (NodeObject)treeNode.Tag;
                if (nodeObject.FileEntry != null && nodeObject.FileEntry.IsPatchedOut)
                {
                    treeNode.ForeColor = BackupColor;
                }
                else if (!nodeObject.CanEdit)
                {
                    treeNode.ForeColor = NoEditColor;
                }
            }
        }
示例#18
0
        void tsAdd_Click(object sender, EventArgs e)
        {
            if (curryFocusedNode != null)
            {
                NodeObject nodeObject = curryFocusedNode.Tag as NodeObject;
                if (nodeObject != null)
                {
                    switch (nodeObject.NodeTag)
                    {
                    case NodeTag.Root:

                        Form1 form1 = new Form1();
                        form1.sendValue += new Action <string>(form1_sendValue);
                        //form1.Left = Screen.PrimaryScreen.Bounds.Width/2 - form1.Width/2;
                        //form1.Top = Screen.PrimaryScreen.Bounds.Height/2 - form1.Height/2;
                        //form1.Location = new Point(form1.Left, form1.Top);
                        form1.Show();

                        break;

                    case NodeTag.Group:

                        Form2 form2 = new Form2();
                        form2.sendValue += new Action <string>(form1_sendValue);

                        form2.Show();
                        break;

                    default:
                        break;
                    }
                }
            }
        }
        void Update()
        {
            if (mcts != null)
            {
                //While the MCTS is still running, display progress information about the time remaining and the amounts of nodes created to the user
                if (!mcts.Finished)
                {
                    //Display the amount of nodes created so far if the timer is still running
                    if (stopTimer != null)
                    {
                        aiTurnProgressText.text = mcts.UniqueNodes + " nodes       " + TimeLeft.Seconds.ToString() + "." + TimeLeft.Milliseconds.ToString("000") + "s/" + timeToRunFor + "s";
                    }

                    //Add new nodes to the LineDraw Lines array, so that they can be represented graphically
                    for (int targetIndex = mcts.AllNodes.Count; currentIndex < targetIndex & mcts.AllNodes.Count > 1; currentIndex++)
                    {
                        NodeObject currentNode = mcts.AllNodes[currentIndex];

                        if ((NodeObject)currentNode.Parent == null)
                        {
                            return;
                        }

                        currentNode.SetPosition(VisualisationType.Standard3D);
                        LineDraw.Lines.Add(new ColoredLine(currentNode.Position, ((NodeObject)currentNode.Parent).Position, LineDraw.lineColors[currentNode.Depth % LineDraw.lineColors.Length]));
                    }
                }
            }
        }
        /// <summary>
        /// Mainline method: Creates a hexagon grid.
        /// </summary>
        /// <param name="blueprint">The size as well as the type of elements included in the grid.</param>
        /// <param name="prefab">A prefab reference to create said grid.</param>
        /// <returns>A 2D array of the hexagon grid.</returns>
        public static TestBoardModel.Board CreateHexagonGrid(int[,] blueprint, NodeObject prefab)
        {
            Transform parent   = CreateCanvas($"{prefab.name}'s list.");
            Board     newBoard = new TestBoardModel.Board(blueprint.GetLength(0), blueprint.GetLength(1));

            globalNodeViewList = new List <NodeObject>();
            int xPos;

            for (int x = 0; x < blueprint.GetLength(0); x++)
            {
                for (int y = 0; y < blueprint.GetLength(1); y++)
                {
                    xPos = y - x / 2;
                    Team currentTeam =
                        (blueprint[x, y] > 8 && blueprint[x, y] != 11) ?
                        (blueprint[x, y] == 14 || blueprint[x, y] == 19) ?
                        Team.BigRed : (blueprint[x, y] == 16 || blueprint[x, y] == 17) ?
                        Team.BigGreen : Team.Unoccupied :
                        (Team)blueprint[x, y]; //O: Massive condition to limit only the bigRed and bigGreen to be used when nessesary.
                    Vector2Int boardPos  = new Vector2Int(x, y);
                    Vector2    objectPos = SetPosition(new Vector2Int(x, xPos) - new Vector2(newBoard.GetLength(0) / centerPointX, newBoard.GetLength(1) / centerPointY));
                    //Like here (O)
                    newBoard[x, y] = new BoardNode(boardPos, objectPos, currentTeam);

                    //The NodeObject uses the raw information to set its proper color on the node.
                    globalNodeViewList.Add(NodeObject.CreateNodeObject(prefab, objectPos, (NodeColor)blueprint[x, y], parent, boardPos));
                }
            }

            return(newBoard);
        }
示例#21
0
        public void createNode(TreeNode treeNode, string name)
        {
            NodeObject nodeObject = treeNode.Tag as NodeObject;

            if (nodeObject != null)
            {
                switch (nodeObject.NodeTag)
                {
                case NodeTag.Root:
                    NodeObject no = createNodeObject(name, NodeTag.Group);
                    nodeObject.ChildNodes.Add(no);
                    treeNode.Nodes.Add(createTreeNode(name, no, (int)ImageIndex.Group));

                    break;

                case NodeTag.Group:
                    NodeObject noo = createNodeObject(name, NodeTag.Node);
                    nodeObject.ChildNodes.Add(noo);
                    treeNode.Nodes.Add(createTreeNode(name, noo, (int)ImageIndex.Node));

                    break;

                default:
                    break;
                }
            }

            ISolutionPlugin.expandTree(treeNode);
        }
示例#22
0
        public void createNode(NodeObject nodeObject, TreeNode node)
        {
            if (nodeObject.NodeTag == NodeTag.Group)
            {
                TreeNode group = new TreeNode()
                {
                    Text       = nodeObject.Name,
                    Tag        = nodeObject,
                    ImageIndex = (int)ImageIndex.Group
                };
                node.Nodes.Add(group);

                foreach (NodeObject no in nodeObject.ChildNodes)
                {
                    createNode(no, group);
                }
            }
            else if (nodeObject.NodeTag == NodeTag.Node)
            {
                TreeNode tn = new TreeNode()
                {
                    Text       = nodeObject.Name,
                    Tag        = nodeObject,
                    ImageIndex = (int)ImageIndex.Node
                };

                node.Nodes.Add(tn);
            }
        }
示例#23
0
    //到达目的地
    void ReachTarget(NodeItem _node)
    {
        //清除路径
        ClearPath();

        //停止移动动画
        Hero hero = TravelManager.currentHero;

        hero.SetMovingStatus(0);

        hero.transform.position = _node.transform.position;

        GameManager.gameState = GameState.playerControl;

        if (targetNodeObject != null)
        {
            NodeObject_Travel obj = (NodeObject_Travel)targetNodeObject;
            targetNodeObject = null;

            obj.advantureObject.OnInteracted(hero);

            Destroy(obj.gameObject);
        }

        //镜头停止跟随
        TravelCamMgr.instance.StopFocus();
    }
示例#24
0
        private void SetControl()
        {
            NodeObject data      = this._propertyItem.Instance as NodeObject;
            bool       isPrecent = data.PreSizeEnable;

            if (this._propertyItem.IsEnable)
            {
                this.widget.SetMenuEnable(!this._propertyItem.IsEnable);
                isPrecent = false;
            }
            this.widget.SetValue(delegate
            {
                if (this.sizeTypeObject != null)
                {
                    this.widget.SetSizeTypeMode(this.sizeTypeObject.IsCustomSize, isPrecent, (double)data.Size.X, (double)data.Size.Y, (double)(data.PreSize.X * 100f), (double)(data.PreSize.Y * 100f));
                }
                else if (this.scale9 != null)
                {
                    this.widget.SetScale9Mode(data is PanelObject, isPrecent, (double)data.Size.X, (double)data.Size.Y, (double)(data.PreSize.X * 100f), (double)(data.PreSize.Y * 100f));
                    this.widget.SetSquard(this.scale9.Scale9Enable, (double)this.scale9.TopEage, (double)this.scale9.BottomEage, (double)this.scale9.LeftEage, (double)this.scale9.RightEage);
                }
                else
                {
                    this.widget.SetShowOnlyMode(data is TextFieldObject, isPrecent, (double)data.Size.X, (double)data.Size.Y, (double)(data.PreSize.X * 100f), (double)(data.PreSize.Y * 100f));
                }
            });
        }
示例#25
0
    private int CalcLongestWayScoreRecursive(NodeObject node, EJointType joint, ref HashSet <NodeObject> visited)
    {
        int highestScore = 0;

        visited.Add(node);
        if (node.NodeType == ENodeType.Entrance)
        {
            return(0);
        }

        for (int i = 0; i < 4; i++)
        {
            var joint1 = node.GetJoint(i);
            if (joint == joint1)
            {
                var neighbor = node.Neighbors[i];
                if (!ReferenceEquals(null, neighbor))
                {
                    if (!visited.Contains(neighbor))
                    {
                        var joint2 = neighbor.GetJoint2(i);
                        if (joint1 == joint2)
                        {
                            int score = CalcLongestWayScoreRecursive(neighbor, joint, ref visited);
                            highestScore = score > highestScore ? score : highestScore;
                        }
                    }
                }
            }
        }

        return(1 + highestScore);
    }
示例#26
0
 private static void RefreshObjectsRecorder(NodeObject vObject)
 {
     vObject.BindingRecorder((string)null);
     foreach (NodeObject child in (Collection <NodeObject>)vObject.Children)
     {
         GameProjectLoader.RefreshObjectsRecorder(child);
     }
 }
示例#27
0
 public void ClearOccupyingNodeObject(NodeObject _caller)
 {
     if (occupyingNodeObject != null && occupyingNodeObject != _caller)
     {
         Debug.LogErrorFormat("{0} tried to set Node({1})'s occupyingNodeObject to null, but isn't actually its current occupant!", _caller.transform.name, GridPos);
     }
     occupyingNodeObject = null;
 }
示例#28
0
 private static void RefreshObjectsRecorder(NodeObject vObject)
 {
     vObject.BindingRecorder(null);
     foreach (NodeObject current in vObject.Children)
     {
         GameProjectLoader.RefreshObjectsRecorder(current);
     }
 }
示例#29
0
 public void SetOccupyingNodeObject(NodeObject _newOccupant)
 {
     if (occupyingNodeObject != null && occupyingNodeObject != _newOccupant)
     {
         Debug.LogErrorFormat("{0}'s new node ({1}) is occupied by {2}! This shouldn't happen!", _newOccupant.transform.name, GridPos, occupyingNodeObject.transform.name);
     }
     occupyingNodeObject = _newOccupant;
 }
示例#30
0
 /// <summary>
 /// Changes the highlight mode of a selectedNode based on set parameters.
 /// </summary>
 /// <param name="go">The selectedNode in question</param>
 /// <param name="isHighlighted">If said node will be highlighted or not</param>
 static void OnInteract(NodeObject go, bool isHighlighted)
 {
     if (go == null)
     {
         return;
     }
     go.HighlightNode(Color.green, false);
 }
示例#31
0
 //Resets the lists highlight.
 private void ResetSelection()
 {
     for (int i = 0; i < results.Count; i++)
     {
         NodeObject obj = globalNodeViewList.Find(p => p.boardCoordinate == results[i]);
         obj.OnInteract();
     }
 }
    private NodeObject WalkDirectoryTree(DirectoryInfo root, NodeObject currentNode)
    {
        currentNode.children = new List<NodeObject>();

        FileInfo[] files = null;
        DirectoryInfo[] subDirs = null;
        // First, process all the files directly under this folder
        try
        {
            files = root.GetFiles("*.*");
        }
        // This is thrown if even one of the files requires permissions greater
        // than the application provides.
        catch (UnauthorizedAccessException e)
        {
            // Console.WriteLine(e.Message);
        }

        catch (System.IO.DirectoryNotFoundException e)
        {
            // Console.WriteLine(e.Message);
        }

        if (files != null)
        {
            foreach (System.IO.FileInfo fi in files)
            {
                NodeObject obj = new NodeObject();
                obj.name = fi.Name;

                currentNode.children.Add(obj);

            }

            // Now find all the subdirectories under this directory.
            subDirs = root.GetDirectories();

            foreach (System.IO.DirectoryInfo dirInfo in subDirs)
            {
                // Resursive call for each subdirectory.
                // Console.WriteLine("{0}", dirInfo.Name);
                NodeObject obj = new NodeObject();
                obj.name = dirInfo.Name;
                obj.children = new List<NodeObject>();
                //currentNode.children.Add(obj);
                currentNode.children.Add(WalkDirectoryTree(dirInfo, obj));
                //WalkDirectoryTree(dirInfo, obj);

            }

        }
        return currentNode;
    }
        private void BindingTree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            
            if (e.Node.Tag != null)
            {
                System.Type nodeType = e.Node.Tag.GetType();
                if (nodeType == typeof(ControllerDescription))
                {
                    //store controller's name and value to be able 
                    //to show additional info On_ShowBindingsResources

                    curObject = NodeObject.Controller;
                    curCtrl = (ControllerDescription)e.Node.Tag;
                }
                else if (nodeType == typeof(Resource))
                {
                    curObject = NodeObject.Resource;
                    curResource = (Resource)e.Node.Tag;
                }
            }
            FillPropertiesTree();
        }
示例#34
0
        /// <summary>
        /// Draws the control, using SpriteBatch, PrimitiveBatch and SpriteFont.
        /// </summary>
        protected override void Draw()
        {
            Vector2 offset = new Vector2(((GraphicsDevice.Viewport.Width * 0.5f) / Camera.Zoom) - Camera.Pos.X, ((GraphicsDevice.Viewport.Height * 0.5f) / Camera.Zoom) - Camera.Pos.Y);

            if (!bDoNotDraw)
            {
                UpdateTime();

                GraphicsDevice.Clear(Color.CornflowerBlue);

                List<Decal> decalList = STATIC_EDITOR_MODE.levelInstance.DecalManager.DecalList;
                List<NodeObject> objectsList = STATIC_EDITOR_MODE.levelInstance.ObjectsList;
                List<ObjectIndex> selectedList = STATIC_EDITOR_MODE.selectedObjectIndices;

                #region Objects and selection overlay
                spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.AnisotropicWrap, null, null, null, Camera.get_transformation(new Vector2(this.Width, this.Height)));

                #region Draw Generics
                if (levelBackground != null)
                {
                    spriteBatch.Draw(levelBackground, new Rectangle(-(int)(levelDimensions.X * 0.5f), -(int)(levelDimensions.Y * 0.5f), (int)levelDimensions.X, (int)levelDimensions.Y),
                        new Rectangle(0, 0, (int)this.levelDimensions.X, (int)this.levelDimensions.Y), Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 1.0f);
                }

                if (!HidePlayerSpawn)
                {
                    spriteBatch.Draw(devCharacter, STATIC_EDITOR_MODE.levelInstance.PlayerSpawnLocation,
                    null, Color.White, 0.0f, new Vector2(this.devCharacter.Width, this.devCharacter.Height) * 0.5f,
                    0.43f, SpriteEffects.None, 0.3f);
                }

                #endregion

                #region Draw PhysicsObjects and Decals
                if (objectsList.Count > 0)
                {
                    for (int i = objectsList.Count - 1; i >= 0; i--)
                    {
                        objectsList[i].Draw(spriteBatch);
                    }
                }

                if (decalList.Count > 0)
                {
                    for (int i = decalList.Count - 1; i >= 0; i--)
                    {
                        decalList[i].Draw(spriteBatch);
                    }
                }

                #endregion

                #region Draw object overlay

                if (!HideOverlay)
                {
                    for (int i = selectedList.Count - 1; i >= 0; i--)
                    {
                        int index = selectedList[i].Index;

                        if (selectedList[i].Type == OBJECT_TYPE.Physics)
                        {
                            spriteBatch.Draw(debugOverlay,
                                                objectsList[index].Position,
                                                new Rectangle(0, 0,
                                                    (int)objectsList[index].Width,
                                                    (int)objectsList[index].Height),
                                                Color.Green * 0.3f, 0.0f, new Vector2(objectsList[index].Width, objectsList[index].Height) * 0.5f,
                                                1.0f, SpriteEffects.None, 0.001f);
                        }
                        else
                        {
                            float width = decalList[index].Width * decalList[index].Scale;
                            float height = decalList[index].Height * decalList[index].Scale;

                            spriteBatch.Draw(debugOverlay,
                                        decalList[index].Position,
                                        new Rectangle(0, 0, (int)width, (int)height),
                                        Color.Green * 0.3f, decalList[index].Rotation,
                                        new Vector2(width, height) * 0.5f, 1.0f, SpriteEffects.None, 0.001f);
                        }
                    }
                }

                #endregion

                #region Draw Names

                if (!HideObjectNames)
                {
                    for (int i = objectsList.Count - 1; i >= 0; i--)
                    {
                        NodeObject obj = objectsList[i];

                        if (obj.Name != null || obj.Name != "")
                        {
                            Vector2 textOrigin = font.MeasureString(obj.Name) * 0.5f;

                            spriteBatch.DrawString(font, obj.Name, obj.Position, Color.White, 0.0f, textOrigin, 1.5f, SpriteEffects.None, 0.0f);
                        }
                    }
                }

                #endregion

                spriteBatch.End();
                #endregion

                #region Primitives
                //  Primitive batch calls need to be made OUTSIDE of a spriteBatch,
                //  otherwise it causes horrible FPS problems.
                //  Therefore, we'll do it afterwards and apply a basic transform
                //  on their positions using the camera.
                primBatch.Begin(PrimitiveType.LineList);

                #region Movement paths
                if (!HideMovementPath)
                {

                    for (int i = 0; i < objectsList.Count; i++)
                    {
                        Type t = objectsList[i].GetType();
                        if (t.BaseType == typeof(DynamicObject))
                        {
                            DynamicObject dyObj = (DynamicObject)objectsList[i];
                            primBatch.AddVertex((dyObj.Position + offset) * Camera.Zoom, Color.Red);
                            primBatch.AddVertex((dyObj.EndPosition + offset) * Camera.Zoom, Color.Red);

                        }
                        else if (t == typeof(Rope))
                        {
                            Rope ropeObj = (Rope)objectsList[i];
                            primBatch.AddVertex((ropeObj.Position + offset) * Camera.Zoom, Color.Red);
                            primBatch.AddVertex((ropeObj.EndPosition + offset) * Camera.Zoom, Color.Red);
                        }
                    }
                }
                #endregion

                #region Grid
                if (!HideGrid)
                {
                    for (int i = 0; i < xLineCount + 2; i++)
                    {
                        primBatch.AddVertex(new Vector2(xOffset + xySpacing * i, 0), Color.White * 0.2f);
                        primBatch.AddVertex(new Vector2(xOffset + xySpacing * i, GraphicsDevice.Viewport.Height), Color.White * 0.2f);

                    }
                    for (int i = 0; i < yLineCount + 2; i++)
                    {
                        primBatch.AddVertex(new Vector2(0, yOffset + xySpacing * i), Color.White * 0.2f);
                        primBatch.AddVertex(new Vector2(GraphicsDevice.Viewport.Width, yOffset + xySpacing * i), Color.White * 0.2f);
                    }
                }
                #endregion

                #region Event Targets

                if (!HideEventTargets)
                {
                    NodeObject obj = new NodeObject();

                    for (int i = 0; i < objectsList.Count; i++)
                    {
                        obj = objectsList[i];

                        //  Check if the object has a name (it can't use events if it doesn't).
                        if (obj.Name != null && obj.Name != "")
                        {

                            //  Check it has some events to target.
                            if (obj.EventList.Count > 0)
                            {

                                //  For the next part we need to check the name of each target
                                //  in the event list and compare it with objects in the objectList
                                for (int j = 0; j < obj.EventList.Count; j++)
                                {
                                    for (int x = 0; x < objectsList.Count; x++)
                                    {

                                        //  Check if the name of the object in the objectList matches
                                        //  the target
                                        if (obj.EventList[j].TargetName == objectsList[x].Name)
                                        {
                                            //  It is our target, so draw it.
                                            primBatch.AddVertex((obj.Position + offset) * Camera.Zoom, Color.Pink);
                                            primBatch.AddVertex((objectsList[x].Position + offset) * Camera.Zoom, Color.Pink);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                #endregion

                primBatch.End();
                #endregion

                #region Screen Rotation Point

                spriteBatch.Begin();

                spriteBatch.Draw(crosshair,
                                new Vector2((GraphicsDevice.Viewport.Width / 2 / Camera.Zoom) - Camera.Pos.X - (crosshair.Width / 2 / Camera.Zoom),
                                            (GraphicsDevice.Viewport.Height / 2 / Camera.Zoom) - Camera.Pos.Y - (crosshair.Height / 2 / Camera.Zoom)) * Camera.Zoom,
                                            Color.White * 0.2f);

                spriteBatch.End();
                #endregion

                #region Text Coordinates

                if (!HideCoordinates)
                {
                    spriteBatch.Begin();

                    spriteBatch.DrawString(font, "Level Co-ords: ",
                        new Vector2(0, 0),
                        Color.White);
                    spriteBatch.DrawString(font, worldCoOrds,
                        new Vector2(0, 20),
                        Color.White);

                    spriteBatch.End();
                }
                #endregion
            }
        }
        public void RemoteEventTriggersTest()
        {
            MathIdentifier flagId = new MathIdentifier("TX_F", "FundamentTest");

            NodeFlag flag = NodeFlag.Register(flagId, typeof(FundamentTest));

            NodeFlag flagEnableRemote = NodeFlag.Register(flagId.DerivePostfix("EnableRemote"), typeof(FundamentTest), FlagKind.Default,
                new NodeEventTrigger(EventTriggerAction.Enable, flag, flag.FlagEnabledEvent));
            NodeFlag flagEnableLocal = NodeFlag.Register(flagId.DerivePostfix("EnableLocal"), typeof(FundamentTest), FlagKind.Default,
                new NodeEventTrigger(EventTriggerAction.Enable, flag.FlagEnabledEvent));

            NodeFlag flagDisableRemote = NodeFlag.Register(flagId.DerivePostfix("DisableRemote"), typeof(FundamentTest), FlagKind.Default,
                new NodeEventTrigger(EventTriggerAction.Disable, flag, flag.FlagChangedEvent));
            NodeFlag flagDisableLocal = NodeFlag.Register(flagId.DerivePostfix("DisableLocal"), typeof(FundamentTest), FlagKind.Default,
                new NodeEventTrigger(EventTriggerAction.Disable, flag.FlagChangedEvent));

            NodeObject n = new NodeObject();
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flag), "A01");
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagEnableRemote), "A02");
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagEnableLocal), "A03");
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagDisableRemote), "A04");
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagDisableLocal), "A05");

            n.EnableFlag(flag);
            Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flag), "B01");
            Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flagEnableRemote), "B02");
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagEnableLocal), "B03");
            Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flagDisableRemote), "B04");
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagDisableLocal), "B05");

            n.ClearFlag(flag);
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flag), "C01");
            Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flagEnableRemote), "C02");
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagEnableLocal), "C03");
            Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flagDisableRemote), "C04");
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagDisableLocal), "C05");

            n.EnableFlag(flagDisableLocal);
            n.DisableFlag(flagEnableLocal);
            n.ClearFlag(flagDisableRemote);
            n.ClearFlag(flagEnableRemote);
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flag), "D01");
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagEnableRemote), "D02");
            Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flagEnableLocal), "D03");
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagDisableRemote), "D04");
            Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flagDisableLocal), "D05");

            n.DisableFlag(flag);
            Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flag), "E01");
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flagEnableRemote), "E02");
            Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flagEnableLocal), "E03");
            Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flagDisableRemote), "E04");
            Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flagDisableLocal), "E05");

            n.EnableFlag(flag);
            Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flag), "F01");
            Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flagEnableRemote), "F02");
            Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flagEnableLocal), "F03");
            Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flagDisableRemote), "F04");
            Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flagDisableLocal), "F05");
        }
        public void FlagAspectTest()
        {
            MathIdentifier flagId = new MathIdentifier("T1_FA", "FundamentTest");
            NodeFlag flag = NodeFlag.Register(flagId, typeof(FundamentTest));

            NodeObject n = new NodeObject();
            _counter = 0;
            n.AddHandler(flag.FlagChangedEvent, new EventHandler<NodeFlagChangedEventArgs>(OnFlagChanged));

            Assert.AreEqual(0, _counter, "X1");
            Assert.IsFalse(n.IsFlagSet(flag, false), "A01");
            Assert.IsFalse(n.IsFlagSet(flag, true), "A02");
            Assert.IsFalse(n.IsFlagDirty(flag), "A03");
            Assert.IsFalse(n.IsFlagEnabled(flag, false), "A04");
            Assert.IsFalse(n.IsFlagEnabled(flag, true), "A05");
            Assert.IsFalse(n.IsFlagDisabled(flag, false), "A06");
            Assert.IsFalse(n.IsFlagDisabled(flag, true), "A07");
            Assert.IsTrue(n.IsFlagUnknown(flag), "A08");
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flag), "A09");

            n.EnableFlag(flag);
            Assert.AreEqual(-1, _counter, "X2");
            Assert.AreEqual(FlagState.Unknown, _lastFlagChangedEventArgs.OldState, "X2a");
            Assert.AreEqual(FlagState.Enabled, _lastFlagChangedEventArgs.NewState, "X2b");
            Assert.IsTrue(n.IsFlagSet(flag, false), "B01");
            Assert.IsTrue(n.IsFlagSet(flag, true), "B02");
            Assert.IsFalse(n.IsFlagDirty(flag), "B03");
            Assert.IsTrue(n.IsFlagEnabled(flag, false), "B04");
            Assert.IsTrue(n.IsFlagEnabled(flag, true), "B05");
            Assert.IsFalse(n.IsFlagDisabled(flag, false), "B06");
            Assert.IsFalse(n.IsFlagDisabled(flag, true), "B07");
            Assert.IsFalse(n.IsFlagUnknown(flag), "B08");
            Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flag), "B09");

            n.DisableFlag(flag);
            Assert.AreEqual(-2, _counter, "X3");
            Assert.AreEqual(FlagState.Enabled, _lastFlagChangedEventArgs.OldState, "X3a");
            Assert.AreEqual(FlagState.Disabled, _lastFlagChangedEventArgs.NewState, "X3b");
            Assert.IsTrue(n.IsFlagSet(flag, false), "C01");
            Assert.IsTrue(n.IsFlagSet(flag, true), "C02");
            Assert.IsFalse(n.IsFlagDirty(flag), "C03");
            Assert.IsFalse(n.IsFlagEnabled(flag, false), "C04");
            Assert.IsFalse(n.IsFlagEnabled(flag, true), "C05");
            Assert.IsTrue(n.IsFlagDisabled(flag, false), "C06");
            Assert.IsTrue(n.IsFlagDisabled(flag, true), "C07");
            Assert.IsFalse(n.IsFlagUnknown(flag), "C08");
            Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flag), "C09");

            n.DirtyFlagIfSet(flag);
            Assert.AreEqual(-2, _counter, "X4");
            Assert.IsFalse(n.IsFlagSet(flag, false), "D01");
            Assert.IsTrue(n.IsFlagSet(flag, true), "D02");
            Assert.IsTrue(n.IsFlagDirty(flag), "D03");
            Assert.IsFalse(n.IsFlagEnabled(flag, false), "D04");
            Assert.IsFalse(n.IsFlagEnabled(flag, true), "D05");
            Assert.IsFalse(n.IsFlagDisabled(flag, false), "D06");
            Assert.IsTrue(n.IsFlagDisabled(flag, true), "D07");
            Assert.IsFalse(n.IsFlagUnknown(flag), "D08");
            Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flag), "D09");

            n.EnableFlag(flag);
            Assert.AreEqual(-3, _counter, "X5");
            Assert.AreEqual(FlagState.Disabled, _lastFlagChangedEventArgs.OldState, "X5a");
            Assert.AreEqual(FlagState.Enabled, _lastFlagChangedEventArgs.NewState, "X5b");
            Assert.IsTrue(n.IsFlagSet(flag, false), "E01");
            Assert.IsTrue(n.IsFlagSet(flag, true), "E02");
            Assert.IsFalse(n.IsFlagDirty(flag), "E03");
            Assert.IsTrue(n.IsFlagEnabled(flag, false), "E04");
            Assert.IsTrue(n.IsFlagEnabled(flag, true), "E05");
            Assert.IsFalse(n.IsFlagDisabled(flag, false), "E06");
            Assert.IsFalse(n.IsFlagDisabled(flag, true), "E07");
            Assert.IsFalse(n.IsFlagUnknown(flag), "E08");
            Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flag), "E09");

            n.ClearFlag(flag);
            Assert.AreEqual(-4, _counter, "X6");
            Assert.AreEqual(FlagState.Enabled, _lastFlagChangedEventArgs.OldState, "X6a");
            Assert.AreEqual(FlagState.Unknown, _lastFlagChangedEventArgs.NewState, "X6b");
            Assert.IsFalse(n.IsFlagSet(flag, false), "F01");
            Assert.IsFalse(n.IsFlagSet(flag, true), "F02");
            Assert.IsFalse(n.IsFlagDirty(flag), "F03");
            Assert.IsFalse(n.IsFlagEnabled(flag, false), "F04");
            Assert.IsFalse(n.IsFlagEnabled(flag, true), "F05");
            Assert.IsFalse(n.IsFlagDisabled(flag, false), "F06");
            Assert.IsFalse(n.IsFlagDisabled(flag, true), "F07");
            Assert.IsTrue(n.IsFlagUnknown(flag), "F08");
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flag), "F09");
        }
        public void PropertyTriggerTest()
        {
            MathIdentifier propertyId = new MathIdentifier("T2_PT", "FundamentTest");

            NodeEvent clearEvent = NodeEvent.Register(propertyId.DerivePostfix("ClearTrigger"), typeof(EventHandler), typeof(FundamentTest));
            NodeEvent clear2Event = NodeEvent.Register(propertyId.DerivePostfix("Clear2Trigger"), typeof(EventHandler), typeof(FundamentTest));
            NodeEvent clear3Event = NodeEvent.Register(propertyId.DerivePostfix("Clear3Trigger"), typeof(EventHandler), typeof(FundamentTest));
            NodeEvent reevaluateEvent = NodeEvent.Register(propertyId.DerivePostfix("ReevaluateTrigger"), typeof(EventHandler), typeof(FundamentTest));

            NodeProperty property = NodeProperty.Register(propertyId, typeof(string), typeof(FundamentTest),
                new NodeEventTrigger(EventTriggerAction.Clear, clearEvent, clear2Event),
                new NodeEventTrigger(EventTriggerAction.Clear, clear3Event),
                new NodeEventTrigger(EventTriggerAction.Reevaluate, reevaluateEvent));

            NodeObject n = new NodeObject();
            Assert.IsFalse(n.IsPropertySet(property), "A01");

            n.SetProperty(property, "test");
            Assert.IsTrue(n.IsPropertySet(property), "B01");

            n.RaiseEvent(clearEvent, EventArgs.Empty);
            Assert.IsFalse(n.IsPropertySet(property), "C01");

            n.SetProperty(property, "test2");
            Assert.IsTrue(n.IsPropertySet(property), "D01");
            Assert.AreEqual("test2", n.GetProperty(property), "D02");

            n.RaiseEvent(reevaluateEvent, EventArgs.Empty);
            Assert.IsTrue(n.IsPropertySet(property), "E01");
            Assert.AreEqual("test2", n.GetProperty(property), "E02");

            n.RaiseEvent(clear2Event, EventArgs.Empty);
            Assert.IsFalse(n.IsPropertySet(property), "F01");

            n.SetProperty(property, "test3");
            Assert.IsTrue(n.IsPropertySet(property), "G01");

            n.RaiseEvent(clear3Event, EventArgs.Empty);
            Assert.IsFalse(n.IsPropertySet(property), "H01");
        }
        public void PropertyAspectTest()
        {
            MathIdentifier propertyId = new MathIdentifier("T0_PA", "FundamentTest");
            NodeProperty property = NodeProperty.Register(propertyId, typeof(string), typeof(FundamentTest));

            NodeObject n = new NodeObject();
            _counter = 0;
            n.AddHandler(property.PropertyChangedEvent, new EventHandler<NodePropertyChangedEventArgs>(OnPropertyChanged));

            Assert.AreEqual(0, _counter, "X1");
            Assert.IsFalse(n.IsPropertySet(property, false), "A01");
            Assert.IsFalse(n.IsPropertySet(property, true), "A02");
            Assert.IsFalse(n.IsPropertyDirty(property), "A03");
            Assert.AreEqual("nothing", n.GetProperty(property, "nothing", false), "A04");
            Assert.AreEqual("nothing", n.GetProperty(property, "nothing", true), "A05");

            n.SetProperty(property, "myvalue");
            Assert.AreEqual(1, _counter, "X2");
            Assert.AreEqual(null, _lastPropertyChangedEventArgs.OldValue, "X2a");
            Assert.AreEqual("myvalue", _lastPropertyChangedEventArgs.NewValue, "X2b");
            Assert.IsTrue(n.IsPropertySet(property, false), "B01");
            Assert.IsTrue(n.IsPropertySet(property, true), "B02");
            Assert.IsFalse(n.IsPropertyDirty(property), "B03");
            Assert.AreEqual("myvalue", n.GetProperty(property, "nothing", false), "B04");
            Assert.AreEqual("myvalue", n.GetProperty(property, "nothing", true), "B05");

            n.DirtyPropertyIfSet(property);
            Assert.AreEqual(1, _counter, "X3");
            Assert.IsFalse(n.IsPropertySet(property, false), "C01");
            Assert.IsTrue(n.IsPropertySet(property, true), "C02");
            Assert.IsTrue(n.IsPropertyDirty(property), "C03");
            Assert.AreEqual("nothing", n.GetProperty(property, "nothing", false), "C04");
            Assert.AreEqual("myvalue", n.GetProperty(property, "nothing", true), "C05");

            n.SetProperty(property, "newvalue");
            Assert.AreEqual(2, _counter, "X4");
            Assert.AreEqual("myvalue", _lastPropertyChangedEventArgs.OldValue, "X4a");
            Assert.AreEqual("newvalue", _lastPropertyChangedEventArgs.NewValue, "X4b");
            Assert.IsTrue(n.IsPropertySet(property, false), "D01");
            Assert.IsTrue(n.IsPropertySet(property, true), "D02");
            Assert.IsFalse(n.IsPropertyDirty(property), "D03");
            Assert.AreEqual("newvalue", n.GetProperty(property, "nothing", false), "D04");
            Assert.AreEqual("newvalue", n.GetProperty(property, "nothing", true), "D05");

            n.ClearProperty(property);
            Assert.AreEqual(3, _counter, "X5");
            Assert.AreEqual("newvalue", _lastPropertyChangedEventArgs.OldValue, "X5a");
            Assert.AreEqual(null, _lastPropertyChangedEventArgs.NewValue, "X5b");
            Assert.IsFalse(n.IsPropertySet(property, false), "E01");
            Assert.IsFalse(n.IsPropertySet(property, true), "E02");
            Assert.IsFalse(n.IsPropertyDirty(property), "E03");
            Assert.AreEqual("nothing", n.GetProperty(property, "nothing", false), "E04");
            Assert.AreEqual("nothing", n.GetProperty(property, "nothing", true), "E05");
        }
        public void FlagTriggerTest()
        {
            MathIdentifier flagId = new MathIdentifier("T3_FT", "FundamentTest");

            NodeEvent clearEvent = NodeEvent.Register(flagId.DerivePostfix("ClearTrigger"), typeof(EventHandler), typeof(FundamentTest));
            NodeEvent enableEvent = NodeEvent.Register(flagId.DerivePostfix("EnableTrigger"), typeof(EventHandler), typeof(FundamentTest));
            NodeEvent disableEvent = NodeEvent.Register(flagId.DerivePostfix("DisableTrigger"), typeof(EventHandler), typeof(FundamentTest));
            NodeEvent disable2Event = NodeEvent.Register(flagId.DerivePostfix("Disable2Trigger"), typeof(EventHandler), typeof(FundamentTest));
            NodeEvent reevaluateEvent = NodeEvent.Register(flagId.DerivePostfix("ReevaluateTrigger"), typeof(EventHandler), typeof(FundamentTest));

            NodeFlag flag = NodeFlag.Register(flagId, typeof(FundamentTest), FlagKind.Default,
                new NodeEventTrigger(EventTriggerAction.Clear, clearEvent),
                new NodeEventTrigger(EventTriggerAction.Enable, enableEvent),
                new NodeEventTrigger(EventTriggerAction.Disable, disableEvent, disable2Event),
                new NodeEventTrigger(EventTriggerAction.Reevaluate, reevaluateEvent));

            NodeObject n = new NodeObject();
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flag), "A01");

            n.EnableFlag(flag);
            Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flag), "B01");

            n.RaiseEvent(disableEvent, EventArgs.Empty);
            Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flag), "C01");

            n.RaiseEvent(enableEvent, EventArgs.Empty);
            Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flag), "D01");

            n.RaiseEvent(reevaluateEvent, EventArgs.Empty);
            Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flag), "E01");

            n.RaiseEvent(disable2Event, EventArgs.Empty);
            Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flag), "F01");

            n.RaiseEvent(clearEvent, EventArgs.Empty);
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flag), "G01");
        }
示例#40
0
        /// <summary>
        /// User-friendly uncooking of Tree Node list.
        /// </summary>
        /// <param name="progressForm">A progress form to update.</param>
        /// <param name="param">The Tree Node List.</param>
        private void _DoUnooking(ProgressForm progressForm, Object param)
        {
            List<TreeNode> uncookingNodes = (List<TreeNode>)param;
            const int progressUpdateFreq = 20;
            if (progressForm != null)
            {
                progressForm.ConfigBar(1, uncookingNodes.Count, progressUpdateFreq);
            }

            int i = 0;
            foreach (TreeNode treeNode in uncookingNodes)
            {
                NodeObject nodeObject = (NodeObject)treeNode.Tag;
                PackFileEntry fileEntry = nodeObject.FileEntry;

                // update progress if applicable
                if (i % progressUpdateFreq == 0 && progressForm != null)
                {
                    progressForm.SetCurrentItemText(fileEntry.Path);
                }
                i++;

                // get the file bytes
                String relativePath = fileEntry.Path;
                byte[] fileBytes;
                try
                {
                    fileBytes = _fileManager.GetFileBytes(fileEntry, true);
                    if (fileBytes == null) continue;
                }
                catch (Exception e)
                {
                    ExceptionLogger.LogException(e);
                    continue;
                }

                // determine file type
                HellgateFile hellgateFile;
                if (relativePath.EndsWith(XmlCookedFile.Extension))
                {
                    hellgateFile = new XmlCookedFile(_fileManager);
                }
                else if (relativePath.EndsWith(RoomDefinitionFile.Extension))
                {
                    hellgateFile = new RoomDefinitionFile(relativePath);
                }
                else if (relativePath.EndsWith(MLIFile.Extension))
                {
                    hellgateFile = new MLIFile();
                }
                else
                {
                    Debug.Assert(false, "wtf");
                    continue;
                }

                // deserialise file
                DialogResult dr = DialogResult.Retry;
                bool uncooked = false;
                while (dr == DialogResult.Retry && !uncooked)
                {
                    try
                    {
                        hellgateFile.ParseFileBytes(fileBytes);
                        uncooked = true;
                    }
                    catch (Exception e)
                    {
                        ExceptionLogger.LogException(e, true);

                        String errorMsg = String.Format("Failed to uncooked file!\n{0}\n\n{1}", relativePath, e);
                        dr = MessageBox.Show(errorMsg, "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation);
                        if (dr == DialogResult.Abort) return;
                        if (dr == DialogResult.Ignore) break;
                    }
                }
                if (!uncooked) continue;

                // save file
                String relativeSavePath = relativePath.Replace(HellgateFile.Extension, HellgateFile.ExtensionDeserialised);
                String savePath = Path.Combine(Config.HglDir, relativeSavePath);

                dr = DialogResult.Retry;
                bool saved = false;
                byte[] documentBytes = null;
                while (dr == DialogResult.Retry && !saved)
                {
                    try
                    {
                        if (documentBytes == null) documentBytes = hellgateFile.ExportAsDocument();
                        File.WriteAllBytes(savePath, documentBytes);
                        saved = true;
                    }
                    catch (Exception e)
                    {
                        ExceptionLogger.LogException(e, true);

                        String errorMsg = String.Format("Failed to save file!\n{0}\n\n{1}", relativePath, e);
                        dr = MessageBox.Show(errorMsg, "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation);
                        if (dr == DialogResult.Abort) return;
                        if (dr == DialogResult.Ignore) break;
                    }
                }

                // update tree view
                TreeNode newTreeNode = new TreeNode();
                NodeObject newNodeObject = new NodeObject
                {
                    CanEdit = true,
                    IsUncookedVersion = true
                };
                newTreeNode.Tag = newNodeObject;
                treeNode.Nodes.Add(newTreeNode);
            }
        }
示例#41
0
        /// <summary>
        /// Loop over all file entries and generate tree nodes.
        /// </summary>
        private void _GenerateFileTree()
        {
            foreach (PackFileEntry fileEntry in _fileManager.FileEntries.Values)
            {
                NodeObject nodeObject = new NodeObject { Index = fileEntry.Pack, FileEntry = fileEntry };
                String[] nodeKeys = fileEntry.Directory.Split('\\');
                TreeNode treeNode = null;

                //if (fileEntry.FileNameString == "ct_conna.mop")
                //{
                //    int bp = 0;
                //}

                // set up folders and get applicable root folder
                foreach (String nodeKey in nodeKeys.Where(nodeKey => !String.IsNullOrEmpty(nodeKey)))
                {
                    if (treeNode == null)
                    {
                        treeNode = _files_fileTreeView.Nodes[nodeKey] ?? _files_fileTreeView.Nodes.Add(nodeKey, nodeKey);
                    }
                    else
                    {
                        treeNode = treeNode.Nodes[nodeKey] ?? treeNode.Nodes.Add(nodeKey, nodeKey);
                    }
                }
                Debug.Assert(treeNode != null);

                // need to have canEdit check before we update the node below or it'll be false for newer versions);
                if (fileEntry.Name.EndsWith(XmlCookedFile.Extension))
                    // todo: before we can do this, need to fix up the "sanity check" part just below
                    //fileEntry.FileNameString.EndsWith(RoomDefinitionFile.Extension) ||
                    //fileEntry.FileNameString.EndsWith(LevelRulesFile.Extension) ||
                    //fileEntry.FileNameString.EndsWith(MLIFile.Extension))
                {
                    nodeObject.CanEdit = true;
                    nodeObject.CanCookWith = true;
                }
                else if (fileEntry.Name.EndsWith(ExcelFile.Extension) ||
                         fileEntry.Name.EndsWith(StringsFile.Extention) ||
                         fileEntry.Name.EndsWith("txt"))
                {
                    nodeObject.CanEdit = true;
                }

                // our new node
                TreeNode node = treeNode.Nodes.Add(fileEntry.Path, fileEntry.Name);
                _AssignIcons(node);

                // if we can cook with it, then check if the uncooked version is present
                if (nodeObject.CanCookWith)
                {
                    // sanity check
                    String nodeFullPath = node.FullPath;
                    Debug.Assert(nodeFullPath.EndsWith(".cooked"));

                    String uncookedDataPath = nodeFullPath.Replace(".cooked", "");
                    String uncookedFilePath = Path.Combine(Config.HglDir, uncookedDataPath);
                    if (File.Exists(uncookedFilePath))
                    {
                        String uncookedFileName = Path.GetFileName(uncookedFilePath);
                        TreeNode uncookedNode = node.Nodes.Add(uncookedDataPath, uncookedFileName);
                        _AssignIcons(uncookedNode);

                        NodeObject uncookedNodeObject = new NodeObject
                        {
                            IsUncookedVersion = true,
                            CanCookWith = true,
                            CanEdit = true
                        };
                        uncookedNode.Tag = uncookedNodeObject;
                    }
                }

                // final nodeObject setups
                if (nodeObject.FileEntry.IsPatchedOut)
                {
                    node.ForeColor = BackupColor;
                }
                else if (!nodeObject.CanEdit)
                {
                    node.ForeColor = NoEditColor;
                }
                node.Tag = nodeObject;
            }

            // aesthetics etc
            foreach (TreeNode treeNode in _files_fileTreeView.Nodes)
            {
                if (treeNode.Index == 0)
                {
                    _files_fileTreeView.SelectedNode = treeNode;
                }

                treeNode.Expand();
                _FlagFolderNodes(treeNode);
            }
        }