示例#1
0
        private void DuplicateTexture_Execute(object parameter)
        {
            PssgTextureViewModel   texView = (PssgTextureViewModel)parameter;
            DuplicateTextureWindow dtw     = new DuplicateTextureWindow();

            dtw.TextureName = texView.DisplayName + "_2";

            if (dtw.ShowDialog() == true)
            {
                // Copy and Edit Name
                PssgNode nodeToCopy = texView.Texture;
                PssgNode newTexture = new PssgNode(nodeToCopy);
                newTexture.Attributes["id"].Value = dtw.TextureName;

                // Add to Library
                if (nodeToCopy.ParentNode != null)
                {
                    nodeToCopy.ParentNode.AppendChild(newTexture);
                    PssgNodeViewModel newNodeView = new PssgNodeViewModel(newTexture, texView.NodeView.Parent);
                    texView.NodeView.Parent.Children.Add(newNodeView);
                    Textures.Add(new PssgTextureViewModel(newNodeView));
                }
                else
                {
                    nodeToCopy.AppendChild(newTexture);
                    PssgNodeViewModel newNodeView = new PssgNodeViewModel(newTexture, texView.NodeView);
                    texView.NodeView.Children.Add(newNodeView);
                    Textures.Add(new PssgTextureViewModel(newNodeView));
                }
            }
        }
        private void ExportData_Execute(object parameter)
        {
            PssgNodeViewModel nodeView = (PssgNodeViewModel)parameter;
            SaveFileDialog    dialog   = new SaveFileDialog();

            dialog.Filter     = "Bin files|*.bin|All files|*.*";
            dialog.Title      = "Select the byte data save location and file name";
            dialog.DefaultExt = "bin";
            dialog.FileName   = "nodeData.bin";
            if (dialog.ShowDialog() == true)
            {
                try
                {
                    PssgNode node = nodeView.Node;
                    using (PssgBinaryWriter writer = new PssgBinaryWriter(new BigEndianBitConverter(), File.Open(dialog.FileName, FileMode.Create)))
                    {
                        writer.WriteObject(node.Value);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Could not export data!" + Environment.NewLine + Environment.NewLine +
                                    ex.Message, "Export Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
        private void ImportData_Execute(object parameter)
        {
            PssgNodeViewModel nodeView = (PssgNodeViewModel)parameter;
            OpenFileDialog    dialog   = new OpenFileDialog();

            dialog.Filter   = "Bin files|*.bin|All files|*.*";
            dialog.Title    = "Select a bin file";
            dialog.FileName = "nodeData.bin";
            if (dialog.ShowDialog() == true)
            {
                try
                {
                    PssgNode node = nodeView.Node;
                    using (PssgBinaryReader reader = new PssgBinaryReader(new BigEndianBitConverter(), File.Open(dialog.FileName, FileMode.Open, FileAccess.Read)))
                    {
                        node.Value          = reader.ReadNodeValue(node.ValueType, (int)reader.BaseStream.Length);
                        nodeView.IsSelected = false;
                        nodeView.IsSelected = true;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Could not import data!" + Environment.NewLine + Environment.NewLine +
                                    ex.Message, "Import Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
        private void AddNode_Execute(object parameter)
        {
            PssgNodeViewModel nodeView = (PssgNodeViewModel)parameter;

            if (nodeView.Node.IsDataNode)
            {
                MessageBox.Show("Adding sub nodes to a node with data is not allowed!", Properties.Resources.AppTitleShort, MessageBoxButton.OK, MessageBoxImage.Stop);
                return;
            }

            AddNodeWindow aaw = new AddNodeWindow();

            if (aaw.ShowDialog() == true)
            {
                PssgNode newNode = nodeView.Node.AppendChild(aaw.NodeName);

                if (newNode == null)
                {
                    return;
                }

                PssgNodeViewModel newNodeView = new PssgNodeViewModel(newNode, nodeView);
                nodeView.Children.Add(newNodeView);
            }
        }
示例#5
0
        private void CloneNode_Execute(object parameter)
        {
            try
            {
                PssgNodeViewModel nodeView = (PssgNodeViewModel)parameter;
                var newNode = nodeView.Node.File.CloneNode(nodeView.Node);

                PssgNodeViewModel newNodeView = new PssgNodeViewModel(newNode, nodeView.Parent);
                var nodeViewIndex             = nodeView.Parent.Children.IndexOf(nodeView);
                if (nodeViewIndex < 0 || nodeViewIndex >= nodeView.Parent.Children.Count)
                {
                    nodeView.Parent.Children.Add(newNodeView);
                }
                else
                {
                    nodeView.Parent.Children.Insert(nodeViewIndex + 1, newNodeView);
                }

                mainView.TexturesWorkspace.LoadTextures(newNodeView);
                newNodeView.IsSelected = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not clone node!" + Environment.NewLine + Environment.NewLine +
                                ex.Message, Properties.Resources.AppTitleLong, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void RemoveNode_Execute(object parameter)
        {
            PssgNodeViewModel nodeView = (PssgNodeViewModel)parameter;

            nodeView.Node.ParentNode.RemoveChild(nodeView.Node);

            nodeView.Parent.Children.Remove(nodeView);
            mainView.TexturesWorkspace.RemoveTexture(nodeView);
        }
示例#7
0
        private void LoadTextures(PssgNodeViewModel nodeView)
        {
            if (nodeView.Node.Name == "TEXTURE" && nodeView.Node.HasAttribute("id"))
            {
                textures.Add(new PssgTextureViewModel(nodeView));
            }

            foreach (PssgNodeViewModel childNodeView in nodeView.Children)
            {
                LoadTextures(childNodeView);
            }
        }
        public PssgNodeViewModel(PssgNode node, PssgNodeViewModel parent)
        {
            this.node   = node;
            this.parent = parent;

            attributes = new ObservableCollection <PssgAttributeViewModel>();
            //this.attributes = new ObservableCollection<PssgAttributeViewModel>(
            //    from attribute in node.Attributes
            //    select new PssgAttributeViewModel(attribute));

            children = new ObservableCollection <PssgNodeViewModel>(
                from child in node.ChildNodes
                select new PssgNodeViewModel(child, this));
        }
        private void AddAttribute_Execute(object parameter)
        {
            PssgNodeViewModel  nodeView = (PssgNodeViewModel)parameter;
            AddAttributeWindow aaw      = new AddAttributeWindow();

            if (aaw.ShowDialog() == true)
            {
                PssgAttribute attr = nodeView.Node.AddAttribute(aaw.AttributeName, Convert.ChangeType(aaw.Value, aaw.AttributeValueType));
                if (attr == null)
                {
                    return;
                }

                nodeView.IsSelected = false;
                nodeView.IsSelected = true;
            }
        }
        private void AddNode_Execute(object parameter)
        {
            PssgNodeViewModel nodeView = (PssgNodeViewModel)parameter;
            AddNodeWindow     aaw      = new AddNodeWindow();

            if (aaw.ShowDialog() == true)
            {
                PssgNode newNode = nodeView.Node.AppendChild(aaw.NodeName);

                if (newNode == null)
                {
                    return;
                }

                PssgNodeViewModel newNodeView = new PssgNodeViewModel(newNode, nodeView);
                nodeView.Children.Add(newNodeView);
            }
        }
        private void Import_Execute(object parameter)
        {
            PssgNodeViewModel nodeView = (PssgNodeViewModel)parameter;
            OpenFileDialog    dialog   = new OpenFileDialog();

            dialog.Filter   = "Xml files|*.xml|All files|*.*";
            dialog.Title    = "Select a xml file";
            dialog.FileName = "node.xml";
            if (dialog.ShowDialog() == true)
            {
                try
                {
                    PssgNode node = nodeView.Node;
                    using (FileStream fileStream = File.Open(dialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        XDocument xDoc = XDocument.Load(fileStream);

                        PssgNode newNode = new PssgNode((XElement)((XElement)xDoc.FirstNode).FirstNode, node.File, node.ParentNode);
                        if (node.ParentNode != null)
                        {
                            node = node.ParentNode.SetChild(node, newNode);
                            int index = nodeView.Parent.Children.IndexOf(nodeView);
                            PssgNodeViewModel newNodeView = new PssgNodeViewModel(node, nodeView.Parent);
                            nodeView.Parent.Children[index] = newNodeView;
                            newNodeView.IsSelected          = true;
                        }
                        else
                        {
                            node.File.RootNode = newNode;
                            LoadData(node.File);
                            rootNode.IsSelected = true;
                        }

                        mainView.TexturesWorkspace.ClearData();
                        mainView.TexturesWorkspace.LoadData(RootNode);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Could not import the node!" + Environment.NewLine + Environment.NewLine +
                                    ex.Message, "Import Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
示例#12
0
        public void RemoveTexture(PssgNodeViewModel nodeView)
        {
            int index = -1;

            for (int i = 0; i < textures.Count; ++i)
            {
                if (object.ReferenceEquals(textures[i].NodeView, nodeView))
                {
                    index = i;
                    break;
                }
            }
            if (index >= 0)
            {
                textures.RemoveAt(index);
            }

            foreach (PssgNodeViewModel childNodeView in nodeView.Children)
            {
                RemoveTexture(childNodeView);
            }
        }
示例#13
0
 public PssgTextureViewModel(PssgNodeViewModel nodeView)
 {
     this.nodeView = nodeView;
 }
 public override void ClearData()
 {
     rootNode = null;
     pssgNodes.Clear();
 }
 public override void LoadData(object data)
 {
     RootNode            = new PssgNodeViewModel(((PssgFile)data).RootNode);
     RootNode.IsExpanded = true;
 }
 public PssgAttributeViewModel(PssgAttribute attribute, PssgNodeViewModel parent)
 {
     this.attribute = attribute;
     this.parent    = parent;
 }