Example #1
0
        // StageBox create TBLV
        public TBLVNode NewTBLV(int numEntries)
        {
            TBLVNode node = new TBLVNode(null, numEntries)
            {
                FileType = ARCFileType.MiscData
            };

            _resource.AddChild(node);

            BaseWrapper w = this.FindResource(node, false);

            w.EnsureVisible();
            w.TreeView.SelectedNode = w;
            return(node);
        }
        public override ResourceNode Duplicate()
        {
            if (_resource._parent == null)
            {
                return(null);
            }
            _resource.Rebuild();
            TBLVNode newNode = NodeFactory.FromAddress(null, _resource.WorkingUncompressed.Address, _resource.WorkingUncompressed.Length) as TBLVNode;

            _resource._parent.InsertChild(newNode, true, _resource.Index + 1);
            newNode.Populate();
            newNode.FileType      = ((TBLVNode)_resource).FileType;
            newNode.FileIndex     = ((TBLVNode)_resource).FileIndex;
            newNode.GroupID       = ((TBLVNode)_resource).GroupID;
            newNode.RedirectIndex = ((TBLVNode)_resource).RedirectIndex;
            newNode.Name          = _resource.Name;
            return(newNode);
        }
        public unsafe void resourceTree_SelectionChanged(object sender, EventArgs e)
        {
            audioPlaybackPanel1.TargetSource  = null;
            animEditControl.TargetSequence    = null;
            texAnimEditControl.TargetSequence = null;
            shpAnimEditControl.TargetSequence = null;
            msBinEditor1.CurrentNode          = null;
            //soundPackControl1.TargetNode = null;
            clrControl.ColorSource = null;
            visEditor.TargetNode   = null;
            scN0CameraEditControl1.TargetSequence = null;
            scN0LightEditControl1.TargetSequence  = null;
            scN0FogEditControl1.TargetSequence    = null;
            texCoordControl1.TargetNode           = null;
            ppcDisassembler1.SetTarget(null, 0, null);
            modelPanel1.ClearAll();
            mdL0ObjectControl1.SetTarget(null);
            if (hexBox1.ByteProvider != null)
            {
                ((Be.Windows.Forms.DynamicFileByteProvider)hexBox1.ByteProvider).Dispose();
            }

            Control newControl  = null;
            Control newControl2 = null;

            BaseWrapper  w;
            ResourceNode node       = null;
            bool         disable2nd = false;

            if ((resourceTree.SelectedNode is BaseWrapper) && ((node = (w = resourceTree.SelectedNode as BaseWrapper).ResourceNode) != null))
            {
                propertyGrid1.SelectedObject = node;
                if (node is IBufferNode && MainForm.Instance.ShowHex)
                {
                    IBufferNode d = node as IBufferNode;
                    if (d.IsValid())
                    {
                        hexBox1.ByteProvider = new Be.Windows.Forms.DynamicFileByteProvider(new UnmanagedMemoryStream(
                                                                                                (byte *)d.GetAddress(),
                                                                                                d.GetLength(),
                                                                                                d.GetLength(),
                                                                                                FileAccess.ReadWrite))
                        {
                            _supportsInsDel = false
                        };
                        newControl = hexBox1;
                    }
                }
                else if (node is RSARGroupNode)
                {
                    rsarGroupEditor.LoadGroup(node as RSARGroupNode);
                    newControl = rsarGroupEditor;
                }
                else if (node is RELMethodNode)
                {
                    ppcDisassembler1.SetTarget((RELMethodNode)node);
                    newControl = ppcDisassembler1;
                }
                else if (node is IVideo)
                {
                    videoPlaybackPanel1.TargetSource = node as IVideo;
                    newControl = videoPlaybackPanel1;
                }
                else if (node is MDL0MaterialRefNode)
                {
                    newControl = texCoordControl1;
                }
                else if (node is MDL0ObjectNode)
                {
                    newControl = mdL0ObjectControl1;
                }
                else if (node is MSBinNode)
                {
                    msBinEditor1.CurrentNode = node as MSBinNode;
                    newControl = msBinEditor1;
                }
                else if (node is CHR0EntryNode)
                {
                    animEditControl.TargetSequence = node as CHR0EntryNode;
                    newControl = animEditControl;
                }
                else if (node is SRT0TextureNode)
                {
                    texAnimEditControl.TargetSequence = node as SRT0TextureNode;
                    newControl = texAnimEditControl;
                }
                else if (node is SHP0VertexSetNode)
                {
                    shpAnimEditControl.TargetSequence = node as SHP0VertexSetNode;
                    newControl = shpAnimEditControl;
                }
                else if (node is RSARNode)
                {
                    soundPackControl1.TargetNode = node as RSARNode;
                    newControl = soundPackControl1;
                }
                else if (node is VIS0EntryNode)
                {
                    visEditor.TargetNode = node as VIS0EntryNode;
                    newControl           = visEditor;
                }
                else if (node is SCN0CameraNode)
                {
                    scN0CameraEditControl1.TargetSequence = node as SCN0CameraNode;
                    newControl = scN0CameraEditControl1;
                }
                else if (node is SCN0LightNode)
                {
                    scN0LightEditControl1.TargetSequence = node as SCN0LightNode;
                    newControl = scN0LightEditControl1;
                    disable2nd = true;
                }
                else if (node is SCN0FogNode)
                {
                    scN0FogEditControl1.TargetSequence = node as SCN0FogNode;
                    newControl = scN0FogEditControl1;
                    disable2nd = true;
                }
                else if (node is IAudioSource)
                {
                    audioPlaybackPanel1.TargetSource = node as IAudioSource;
                    IAudioStream[] sources = audioPlaybackPanel1.TargetSource.CreateStreams();
                    if (sources != null && sources.Length > 0 && sources[0] != null)
                    {
                        newControl = audioPlaybackPanel1;
                    }
                }
                else if (node is IImageSource)
                {
                    previewPanel2.RenderingTarget = ((IImageSource)node);
                    newControl = previewPanel2;
                }
                else if (node is IRenderedObject)
                {
                    newControl = modelPanel1;
                }
                else if (node is STDTNode)
                {
                    STDTNode stdt = (STDTNode)node;

                    attributeGrid1.Clear();
                    attributeGrid1.AddRange(stdt.GetPossibleInterpretations());
                    attributeGrid1.TargetNode = stdt;
                    newControl = attributeGrid1;
                }
                else if (node is TBCLNode)
                {
                    TBCLNode tbcl = (TBCLNode)node;

                    attributeGrid1.Clear();
                    attributeGrid1.AddRange(tbcl.GetPossibleInterpretations());
                    attributeGrid1.TargetNode = tbcl;
                    newControl = attributeGrid1;
                }
                else if (node is TBGCNode)
                {
                    TBGCNode tbgc = (TBGCNode)node;

                    attributeGrid1.Clear();
                    attributeGrid1.AddRange(tbgc.GetPossibleInterpretations());
                    attributeGrid1.TargetNode = tbgc;
                    newControl = attributeGrid1;
                }
                else if (node is TBGDNode)
                {
                    TBGDNode tbgd = (TBGDNode)node;

                    attributeGrid1.Clear();
                    attributeGrid1.AddRange(tbgd.GetPossibleInterpretations());
                    attributeGrid1.TargetNode = tbgd;
                    newControl = attributeGrid1;
                }
                else if (node is TBGMNode)
                {
                    TBGMNode tbgm = (TBGMNode)node;

                    attributeGrid1.Clear();
                    attributeGrid1.AddRange(tbgm.GetPossibleInterpretations());
                    attributeGrid1.TargetNode = tbgm;
                    newControl = attributeGrid1;
                }
                else if (node is TBLVNode)
                {
                    TBLVNode tblv = (TBLVNode)node;

                    attributeGrid1.Clear();
                    attributeGrid1.AddRange(tblv.GetPossibleInterpretations());
                    attributeGrid1.TargetNode = tblv;
                    newControl = attributeGrid1;
                }
                else if (node is TBRMNode)
                {
                    TBRMNode tbrm = (TBRMNode)node;

                    attributeGrid1.Clear();
                    attributeGrid1.AddRange(tbrm.GetPossibleInterpretations());
                    attributeGrid1.TargetNode = tbrm;
                    newControl = attributeGrid1;
                }
                else if (node is TBSTNode)
                {
                    TBSTNode tbst = (TBSTNode)node;

                    attributeGrid1.Clear();
                    attributeGrid1.AddRange(tbst.GetPossibleInterpretations());
                    attributeGrid1.TargetNode = tbst;
                    newControl = attributeGrid1;
                }
                else if (node is IColorSource && !disable2nd)
                {
                    clrControl.ColorSource = node as IColorSource;
                    if (((IColorSource)node).ColorCount(0) > 0)
                    {
                        if (newControl != null)
                        {
                            newControl2 = clrControl;
                        }
                        else
                        {
                            newControl = clrControl;
                        }
                    }
                }
                else if (MainForm.Instance.ShowHex)
                {
                    if (node.WorkingUncompressed.Length > 0)
                    {
                        hexBox1.ByteProvider = new Be.Windows.Forms.DynamicFileByteProvider(new UnmanagedMemoryStream(
                                                                                                (byte *)node.WorkingUncompressed.Address,
                                                                                                node.WorkingUncompressed.Length,
                                                                                                node.WorkingUncompressed.Length,
                                                                                                FileAccess.ReadWrite))
                        {
                            _supportsInsDel = false
                        };
                        newControl = hexBox1;
                    }
                }

                if ((editToolStripMenuItem.DropDown = w.ContextMenuStrip) != null)
                {
                    editToolStripMenuItem.Enabled = true;
                }
                else
                {
                    editToolStripMenuItem.Enabled = false;
                }
            }
            else
            {
                propertyGrid1.SelectedObject = null;
                try
                {
                    editToolStripMenuItem.DropDown = null;
                }
                catch
                {
                }
                editToolStripMenuItem.Enabled = false;
            }

            if (_secondaryControl != newControl2)
            {
                if (_secondaryControl != null)
                {
                    _secondaryControl.Dock    = DockStyle.Fill;
                    _secondaryControl.Visible = false;
                }
                _secondaryControl = newControl2;
                if (_secondaryControl != null)
                {
                    _secondaryControl.Dock    = DockStyle.Right;
                    _secondaryControl.Visible = true;
                    _secondaryControl.Width   = 340;
                }
            }
            if (_currentControl != newControl)
            {
                if (_currentControl != null)
                {
                    _currentControl.Visible = false;
                }
                _currentControl = newControl;
                if (_currentControl != null)
                {
                    _currentControl.Visible = true;
                }
            }
            else if (_currentControl != null && !_currentControl.Visible)
            {
                _currentControl.Visible = true;
            }
            if (_currentControl != null)
            {
                if (_secondaryControl != null)
                {
                    _currentControl.Width = splitContainer2.Panel2.Width - _secondaryControl.Width;
                }
                _currentControl.Dock = DockStyle.Fill;
            }

            //Model panel has to be loaded first to display model correctly
            if (_currentControl is ModelPanel && renderPreviews)
            {
                if (node._children == null)
                {
                    node.Populate(0);
                }

                if (node is IModel && ModelEditControl.Instances.Count == 0)
                {
                    IModel m = node as IModel;
                    m.ResetToBindState();
                }

                IRenderedObject o = node as IRenderedObject;
                modelPanel1.AddTarget(o);
                modelPanel1.SetCamWithBox(o.GetBox());
            }
            else if (_currentControl is MDL0ObjectControl)
            {
                mdL0ObjectControl1.SetTarget(node as MDL0ObjectNode);
            }
            else if (_currentControl is TexCoordControl)
            {
                texCoordControl1.TargetNode = ((MDL0MaterialRefNode)node);
            }
        }