//////////////////////////////////////////////////////////////////////////
        private void DisposeNatives()
        {
            if(_Canvas != null)
            {
                _Canvas.PaintContent -= new WmeCanvas.PaintContentDelegate(OnPaintContent);
                _Canvas.MouseMove -= new MouseEventHandler(OnMouseMove);
                _Canvas.MouseDown -= new MouseEventHandler(OnMouseDown);
                _Canvas.MouseUp -= new MouseEventHandler(OnMouseUp);
                _Canvas.KeyDown -= new KeyEventHandler(OnKeyDown);

                _Canvas.Release();
                _Canvas.Invalidate();
                _Canvas = null;
            }

            if(LayoutTree != null)
            {
                LayoutTree.SelectionsChanged -= new EventHandler(OnSelectionChanged);
                LayoutTree.ItemDrag -= new ItemDragEventHandler(TreeItemDrag);
                LayoutTree.DragEnter -= new DragEventHandler(TreeDragEnter);
                LayoutTree.DragOver -= new DragEventHandler(TreeDragOver);
                LayoutTree.DragLeave -= new EventHandler(TreeDragLeave);
                LayoutTree.DragDrop -= new DragEventHandler(TreeDragDrop);
                LayoutTree.KeyUp -= new KeyEventHandler(TreeKeyUp);

                LayoutTree.Nodes.Clear();
                LayoutTree.SelectedNodes.Clear();
            }
            Application.Idle -= new EventHandler(OnAppIdle);

            if (_PropGrid != null)
            {
                _PropGrid.SelectedGridItemChanged -= new SelectedGridItemChangedEventHandler(OnPropertySelected);
                _PropGrid.SelectedObject = null;
            }

            RectResizer = null;

            if (Window != null)
            {
                Window.Dispose();
                Window = null;
            }

            if (InvBox != null)
            {
                InvBox.Dispose();
                InvBox = null;
            }

            if (RespBox != null)
            {
                RespBox.Dispose();
                RespBox = null;
            }

            if (Game != null)
            {
                Game.Dispose();
                Game = null;
            }
        }
 //////////////////////////////////////////////////////////////////////////
 public RespBoxProxy(WAdResponseBox NativeObject)
     : base(NativeObject)
 {
     _NativeObject = NativeObject;
 }
        //////////////////////////////////////////////////////////////////////////
        public DocumentOpenResult OpenDocument(WmeCanvas Canvas, string FileName)
        {
            if (FileName == null)
            {
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.Filter = "Windows and definition files (*.window; *.def)|*.window;*.def|Windows (*.window)|*.window|Defintion files (*.def)|*.def|All files (*.*)|*.*";
                dlg.RestoreDirectory = true;
                dlg.CheckFileExists = true;

                if (dlg.ShowDialog() != DialogResult.OK) return DocumentOpenResult.Cancel;
                else FileName = dlg.FileName;
            }

            DefinitionFile DefFile = new DefinitionFile();
            string FileType = "";

            if(DefFile.ParseFile(FileName) && DefFile.Children.Count > 0)
                FileType = DefFile.Children[0].Name.ToUpper();

            if(FileType != "WINDOW" && FileType != "INVENTORY_BOX" && FileType != "RESPONSE_BOX")
            {
                MessageBox.Show("Unsupported file type.", Form.ActiveForm.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return DocumentOpenResult.Cancel;
            }

            bool Ret = false;

            if (InitEngine(FileName, Canvas))
            {
                Game.AbsolutePathWarning = false;
                switch(FileType)
                {
                    case "WINDOW":
                        Window = new WUIWindow(Game);
                        Ret = Window.LoadFromFile(FileName);
                        if(Ret)
                        {
                            Game.Windows.Add(Window);
                            Game.FocusedWindow = Window;
                        }
                        break;

                    case "INVENTORY_BOX":
                        InvBox = new WAdInventoryBox(Game);
                        Ret = InvBox.LoadFromFile(FileName);
                        if(Ret && InvBox.Window != null)
                        {
                            Game.Windows.Add(InvBox.Window);
                            Game.FocusedWindow = InvBox.Window;
                        }
                        break;

                    case "RESPONSE_BOX":
                        RespBox = new WAdResponseBox(Game);
                        Ret = RespBox.LoadFromFile(FileName);
                        if (Ret && RespBox.Window != null)
                        {
                            Game.Windows.Add(RespBox.Window);
                            Game.FocusedWindow = RespBox.Window;
                        }
                        break;

                }
                Game.AbsolutePathWarning = true;
                UpdateScrollSize();

                this.FileName = FileName;
            }
            else Ret = false;

            if (!Ret) DisposeNatives();

            if (Ret) return DocumentOpenResult.Ok;
            else return DocumentOpenResult.Error;
        }
        //////////////////////////////////////////////////////////////////////////
        public bool NewDocument(WmeCanvas Canvas)
        {
            DocumentTypeForm dlg = new DocumentTypeForm();
            dlg.AppMgr = ParentForm.AppMgr;
            if (dlg.ShowDialog() != DialogResult.OK) return false;

            if (InitEngine(null, Canvas))
            {
                WUIWindow Win = new WUIWindow(Game);
                Win.Width = 200;
                Win.Height = 100;
                Game.Windows.Add(Win);
                Game.FocusedWindow = Win;

                switch(dlg.SelectedType)
                {
                    case "InvBox":
                        InvBox = new WAdInventoryBox(Game);
                        InvBox.Window = Win;
                        InvBox.Area = new Rectangle(0, 0, Win.Width, Win.Height);
                        break;
                    case "RespBox":
                        RespBox = new WAdResponseBox(Game);
                        RespBox.Window = Win;
                        RespBox.Area = new Rectangle(0, 0, Win.Width, Win.Height);
                        break;
                    default:
                        Window = Win;
                        break;
                }

                UpdateScrollSize();
                FileName = "";
                IsDirty = true;

                return true;
            }
            else return false;
        }
        //////////////////////////////////////////////////////////////////////////
        public void LoadUndoState(string State)
        {
            if(InvBox != null)
            {
                WAdInventoryBox NewInvBox = new WAdInventoryBox(Game);
                if (NewInvBox.LoadFromBuffer(State))
                {
                    Game.Windows.Remove(MainWindow);
                    InvBox.Dispose();
                    InvBox = NewInvBox;
                }
                else NewInvBox.Dispose();
            }
            else if(RespBox != null)
            {
                WAdResponseBox NewRespBox = new WAdResponseBox(Game);
                if (NewRespBox.LoadFromBuffer(State))
                {
                    Game.Windows.Remove(MainWindow);
                    RespBox.Dispose();
                    RespBox = NewRespBox;
                }
                else NewRespBox.Dispose();
            }
            else if(Window != null)
            {
                WUIWindow NewWin = new WUIWindow(Game);
                if (NewWin.LoadFromBuffer(State))
                {
                    Game.Windows.Remove(MainWindow);
                    Window.Dispose();
                    Window = NewWin;
                }
                else NewWin.Dispose();
            }

            Game.Windows.Add(MainWindow);
            Game.FocusedWindow = MainWindow;

            FillLayout();
            RefreshTree(true);
        }
        //////////////////////////////////////////////////////////////////////////
        private void PaintResponseBox(WAdResponseBox RespBox)
        {
            int OffsetX = 0;
            int OffsetY = 0;

            if (MainWindow != null)
            {
                OffsetX += MainWindow.X;
                OffsetY += MainWindow.Y;
            }

            Color Col = RespBox.EditorSelected ? SelectionColor : BoxColor;

            Rectangle Rect = new Rectangle(OffsetX + RespBox.Area.X, OffsetY + RespBox.Area.Y, RespBox.Area.Width - 1, RespBox.Area.Height - 1);
            Game.Renderer.DrawRect(Rect, Col);

            if (RespBox.EditorSelected && RectResizer == null)
            {
                HotSpots.Add(new HotSpot(Rect, RespBox, HotSpot.HotSpotType.Control));
                PaintResizeHandles(Rect, RespBox);
            }
        }
Example #7
0
 //////////////////////////////////////////////////////////////////////////
 public RespBoxProxy(WAdResponseBox NativeObject) : base(NativeObject)
 {
     _NativeObject = NativeObject;
 }