//////////////////////////////////////////////////////////////////////////
        public RectangleResizer(WUIWindow Window, RectType Type)
        {
            this.Window = Window;
            this.Type   = Type;

            _OrigRect = GetRect();
        }
        //////////////////////////////////////////////////////////////////////////
        public RectangleResizer(WUIWindow Window, RectType Type)
        {
            this.Window = Window;
            this.Type = Type;

            _OrigRect = GetRect();
        }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (Game == null)
            {
                Game = new WAdGame();
                Canvas.Create(Game, @"F:\Program Files\WME DevKit\projects\wme_demo\wme_demo.wpr", @"c:\test.log");

                Sprite = new WSprite(Game);
                Sprite.LoadFromFile(@"actors\molly\rr\walk.sprite");

                Entity = new WAdEntity(Game);
                Entity.LoadFromFile(@"entities\oldguy\oldguy.entity");

                Win = new WUIWindow(Game);
                Win.LoadFromFile(@"interface\system\mainmenu.window");
                Game.Windows.Add(Win);
                Game.FocusedWindow = Win;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if(Game==null)
            {
                Game = new WAdGame();
                Canvas.Create(Game, @"F:\Program Files\WME DevKit\projects\wme_demo\wme_demo.wpr", @"c:\test.log");

                Sprite = new WSprite(Game);
                Sprite.LoadFromFile(@"actors\molly\rr\walk.sprite");

                Entity = new WAdEntity(Game);
                Entity.LoadFromFile(@"entities\oldguy\oldguy.entity");

                Win = new WUIWindow(Game);
                Win.LoadFromFile(@"interface\system\mainmenu.window");
                Game.Windows.Add(Win);
                Game.FocusedWindow = Win;
            }
        }
Exemplo n.º 5
0
 //////////////////////////////////////////////////////////////////////////
 public UiWindowProxy(WUIWindow NativeObject) : base(NativeObject)
 {
 }
        //////////////////////////////////////////////////////////////////////////
        private Rectangle GetWindowSize(WUIWindow Win, int OffsetX, int OffsetY)
        {
            Rectangle Rect = new Rectangle(OffsetX + Win.X, OffsetY + Win.Y, Win.Width, Win.Height);
            foreach(WUIObject Obj in Win.Controls)
            {
                Rectangle Rect2;
                if(Obj is WUIWindow) Rect2 = GetWindowSize((WUIWindow)Obj, OffsetX + Win.X, OffsetY + Win.Y);
                else Rect2 = new Rectangle(OffsetX + Win.X + Obj.X, OffsetY + Win.Y + Obj.Y, Obj.Width, Obj.Height);

                Rect = Rectangle.Union(Rect, Rect2);
            }
            return Rect;
        }
 //////////////////////////////////////////////////////////////////////////
 private Rectangle GetWindowSize(WUIWindow Win)
 {
     return GetWindowSize(Win, 0, 0);
 }
 //////////////////////////////////////////////////////////////////////////
 private void GetSelectedObjects(WUIWindow Win, List<WUIObject> SelObj)
 {
     if (Win.EditorSelected) SelObj.Add(Win);
     foreach(WUIObject C in Win.Controls)
     {
         if (C is WUIWindow) GetSelectedObjects(C as WUIWindow, SelObj);
         else if (C.EditorSelected) SelObj.Add(C);
     }
 }
 //////////////////////////////////////////////////////////////////////////
 private void GetAllObjects(WUIWindow Win, List<WUIObject> AllObj)
 {
     AllObj.Add(Win);
     foreach (WUIObject C in Win.Controls)
     {
         if (C is WUIWindow) GetAllObjects(C as WUIWindow, AllObj);
         else AllObj.Add(C);
     }
 }
        //////////////////////////////////////////////////////////////////////////
        private void FillLayoutNodes(TreeNodeCollection Nodes, WUIWindow Win)
        {
            TreeNode Node = new TreeNode();

            Node.ImageKey = GetIconKey(Win);
            UiWindowProxy WinProxy = new UiWindowProxy(Win);
            WinProxy.RefreshNeeded += new EventHandler(OnTreeRefresh);
            WinProxy.PropertyChanging += new PropertyChangedEventHandler(OnPropertyChanging);
            WinProxy.PropertyChanged += new PropertyChangedEventHandler(OnLayoutChanged);
            Node.Tag = WinProxy;
            Nodes.Add(Node);

            foreach(WUIObject Obj in Win.Controls)
            {
                if (Obj is WUIWindow)
                {
                    FillLayoutNodes(Node.Nodes, Obj as WUIWindow);
                }
                else
                {
                    TreeNode Node2 = new TreeNode();
                    Node2.ImageKey = GetIconKey(Obj);

                    UiProxy ControlProxy;
                    if(Obj is WUIEntity)
                        ControlProxy = new UiEntityProxy(Obj as WUIEntity);
                    else if(Obj is WUIStatic)
                        ControlProxy = new UiStaticProxy(Obj as WUIStatic);
                    else if(Obj is WUIButton)
                        ControlProxy = new UiButtonProxy(Obj as WUIButton);
                    else if (Obj is WUIEdit)
                        ControlProxy = new UiEditorProxy(Obj as WUIEdit);
                    else
                        ControlProxy = new UiControlProxy(Obj);

                    ControlProxy.RefreshNeeded += new EventHandler(OnTreeRefresh);
                    ControlProxy.PropertyChanging += new PropertyChangedEventHandler(OnPropertyChanging);
                    ControlProxy.PropertyChanged += new PropertyChangedEventHandler(OnLayoutChanged);
                    Node2.Tag = ControlProxy;

                    Node.Nodes.Add(Node2);
                    Node.Expand();
                }
            }
        }
        //////////////////////////////////////////////////////////////////////////
        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 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 PaintSelections(WUIWindow Win)
        {
            Rectangle Rect;

            int OffsetX = 0;
            int OffsetY = 0;

            bool MultiSel = SelectedControls.Length > 1;

            bool WinVisible = Win.Visible;

            WUIObject Parent = Win.Parent;
            while(Parent != null)
            {
                if (!Parent.Visible) WinVisible = false;
                OffsetX += Parent.X;
                OffsetY += Parent.Y;
                Parent = Parent.Parent;
            }

            Rect = new Rectangle(OffsetX + Win.X, OffsetY + Win.Y, Win.Width - 1, Win.Height - 1);

            if(WinVisible)
                HotSpots.Add(new HotSpot(Rect, Win, HotSpot.HotSpotType.Container));

            if (Win.EditorSelected && RectResizer == null)
            {
                Game.Renderer.DrawRect(Rect, SelectionColor);
                if (!MultiSel && WinVisible) PaintResizeHandles(Rect, Win);
            }

            OffsetX += Win.X;
            OffsetY += Win.Y;
            foreach(WUIObject C in Win.Controls)
            {
                if (C is WUIWindow) PaintSelections(C as WUIWindow);
                else
                {
                    bool IsVisible = C.Visible && WinVisible;

                    Rect = new Rectangle(OffsetX + C.X, OffsetY + C.Y, C.Width - 1, C.Height - 1);
                    if(IsVisible)
                        HotSpots.Add(new HotSpot(Rect, C, HotSpot.HotSpotType.Control));

                    if (C.EditorSelected && RectResizer == null)
                    {
                        Game.Renderer.DrawRect(Rect, SelectionColor);
                        if (!MultiSel && !(C is WUIEntity) && IsVisible) PaintResizeHandles(Rect, C);
                    }
                }
            }
        }
 //////////////////////////////////////////////////////////////////////////
 public UiWindowProxy(WUIWindow NativeObject)
     : base(NativeObject)
 {
 }