Beispiel #1
0
        public override void Initialize()
        {
            var l1 = new AbsoluteLayout(10, 10, 300, 300, Color.White);
            var l2 = new AbsoluteLayout(10, 10, 100, 100, Color.Green);

            l1.AddComponent(l2);
            var tb     = new TextBlock(50, 20, "STAS", "Arial", 11, StringAlignment.Center, Color.Black);
            var button = new ButtonCircle(10, 20, 25, new Font("Arial", 10), "BUTTON", Color.FromArgb(50, 50, 50));

            l2.AddComponent(button);
            l1.ListenerMouse.AddDown((m) =>
            {
                Console.WriteLine(m.UI);
            });
            AddComponent(l1);

            LayoutGrid grid = new LayoutGrid(400, 100, 400, 400, Color.FromArgb(0, 0, 0));

            grid.InitGrid(2, 2);
            grid.AddComponent(0, 0, new AbsoluteLayout(0, 0, 10, 10, Color.Green));
            grid.AddComponent(1, 0, new AbsoluteLayout(0, 0, 10, 10, Color.Red));
            grid.AddComponent(0, 1, new AbsoluteLayout(0, 0, 10, 10, Color.Blue));
            grid.AddComponent(1, 1, new AbsoluteLayout(0, 0, 10, 10, Color.Gray));
            this.AddComponent(grid);

            Window win    = new Window(400, 400, 500, 500, "My Window");
            var    scroll = new Scroll(10, 150, 100);
            var    lsb    = new ListBox(200, 200, 200, 200);

            scroll.ChangeScroll += (o, e) => { win.Title.Value = scroll.Value.ToString(); };
            win.AddComponent(lsb);
            lsb.AddItem(new ButtonRect(0, 0, 20, 40, new Font("Arial", 12), "Sta", Color.Blue));
            this.AddComponent(win);

            var tabs = new TabLayout <TextBlock>(100, 100, 400, 30, Color.Silver);

            this.AddComponent(tabs);
            for (int i = 0; i < 3; i++)
            {
                tabs.AddTab($"File {i}.cs", new TextBlock(10, 10, "1", "Arial", 14,
                                                          StringAlignment.Center, Color.Red)).Active = (name, ui) => {
                    Console.WriteLine("name: " + name);
                }
            }
            ;
        }
Beispiel #2
0
        private void CreateWindows()
        {
            main = new Window(100, 100, 500, 500, "Main Menu");
            int y = 130;

            main.AddComponent(new Button(110, y += 32, 480, 24, "Layers", StartSelectLayer));
            main.AddComponent(new Button(110, y += 32, 480, 24, "Entities", StartSelectEntity));
            main.AddComponent(new Button(110, y += 32, 480, 24, "Clear Map", ClearMap));
            main.AddComponent(new Button(110, y += 32, 480, 24, "Save Map", SaveMap));
            main.AddComponent(new Button(110, y += 32, 480, 24, "Open Map", OpenMap));
            main.AddComponent(new Button(110, y += 32, 480, 24, "Close Menu", CloseMenu));
            main.AddComponent(new Button(110, y += 32, 480, 24, "Close Editor", CloseEditor));

            layerWindow       = new Window(100, 100, 500, 500, "Layers");
            layerWindow.Ghost = true;
            for (int i = 0; i < layers.Count; i++)
            {
                layerWindow.AddComponent(new Button(110, 130 + i * 32, 480, 24, layers[i].Name, SelectLayer));
            }
        }
Beispiel #3
0
 public IComponent()
 {
     Perent.AddComponent(this);
 }
Beispiel #4
0
        private void CreatePropertiesWindow(string name, Component component)
        {
            propertiesWindowTarget = component;
            propertiesWindow       = new Window(100, 100, 500, 500, name + " Properties");

            propertiesWindow.AddComponent(new Button(100 + 300, 100 + 450, 80, 32, "OK", SaveProperties));
            propertiesWindow.AddComponent(new Button(100 + 400, 100 + 450, 80, 32, "Cancel", CloseProperties));



            int x = 100;
            int y = 30;

            if (component is Entity)
            {
                propertiesWindow.AddComponent(new EditBox(100 + x, 100 + y, 100, 20, (component as Entity).Position.X.ToString(), "X", EditBox.ValueType.Float, null, null, null));
                y += 24;
                propertiesWindow.AddComponent(new EditBox(100 + x, 100 + y, 100, 20, (component as Entity).Position.Y.ToString(), "Y", EditBox.ValueType.Float, null, null, null));
                y += 24;
                propertiesWindow.AddComponent(new EditBox(100 + x, 100 + y, 100, 20, MathHelper.ToDegrees((component as Entity).Orientation).ToString(), "Orientation", EditBox.ValueType.Float, null, null, null));
                y += 24;
            }

            foreach (KeyValuePair <string, int> property in component.Properties.Ints)
            {
                if (property.Key[0] >= 'A' && property.Key[0] <= 'Z')
                {
                    propertiesWindow.AddComponent(new EditBox(100 + x, 100 + y, 100, 20, property.Value.ToString(), property.Key, EditBox.ValueType.Int, null, null, null));
                    y += 24;
                    if (y > 500 - 30)
                    {
                        y  = 30;
                        x += 200;
                    }
                }
            }

            foreach (KeyValuePair <string, float> property in component.Properties.Floats)
            {
                if (property.Key[0] >= 'A' && property.Key[0] <= 'Z')
                {
                    propertiesWindow.AddComponent(new EditBox(100 + x, 100 + y, 100, 20, property.Value.ToString(), property.Key, EditBox.ValueType.Float, null, null, null));
                    y += 24;
                    if (y > 500 - 30)
                    {
                        y  = 30;
                        x += 200;
                    }
                }
            }
            foreach (KeyValuePair <string, object> property in component.Properties.Objects)
            {
                if (property.Key[0] >= 'A' && property.Key[0] <= 'Z')
                {
                    if (property.Value is string)
                    {
                        propertiesWindow.AddComponent(new EditBox(100 + x, 100 + y, 100, 20, property.Value as String, property.Key, EditBox.ValueType.String, null, null, null));
                        y += 24;
                    }
                    if (property.Value is Color)
                    {
                        string hex = "#" + ((Color)property.Value).A.ToString("X2") + ((Color)property.Value).R.ToString("X2") + ((Color)property.Value).G.ToString("X2") + ((Color)property.Value).B.ToString("X2");
                        propertiesWindow.AddComponent(new EditBox(100 + x, 100 + y, 100, 20, hex, property.Key, EditBox.ValueType.Color, null, null, null));
                        y += 24;
                    }
                    if (y > 500 - 30)
                    {
                        y  = 30;
                        x += 200;
                    }
                }
            }

            propertiesWindow.Show();
        }
Beispiel #5
0
        public override void Update(float elapsed)
        {
            base.Update(elapsed);

            MouseState currentMouse = Mouse.GetState();


            if (Editing.Camera != null)
            {
                mousePosition.X = currentMouse.X + Editing.Camera.Left;
                mousePosition.Y = currentMouse.Y + Editing.Camera.Top;
            }
            else
            {
                mousePosition.X = currentMouse.X;
                mousePosition.Y = currentMouse.Y;
            }

            switch (layers[currentLayer].Type)
            {
            case LayerType.Tiles:
                if (drawingEntity != null)
                {
                    drawingEntity.Position = SnapPosition(mousePosition);
                }
                if (currentMouse.LeftButton == ButtonState.Pressed)
                {
                    MouseLeftDownTiles();
                }
                if (currentMouse.RightButton == ButtonState.Pressed && previousMouse.RightButton == ButtonState.Released)
                {
                    MouseRightDownTiles();
                }
                break;

            case LayerType.Entities:
                if (drawingEntity != null)
                {
                    drawingEntity.Position = mousePosition;
                }
                if (currentMouse.LeftButton == ButtonState.Pressed && previousMouse.LeftButton == ButtonState.Released)
                {
                    MouseLeftDownEntities();
                }
                MouseMoveEntities(currentMouse.LeftButton == ButtonState.Pressed);
                if (currentMouse.RightButton == ButtonState.Pressed && previousMouse.RightButton == ButtonState.Released)
                {
                    MouseRightDownEntities();
                }
                int delta = currentMouse.ScrollWheelValue - previousMouse.ScrollWheelValue;
                if (previousKeyboard.IsKeyDown(Keys.LeftShift) || previousKeyboard.IsKeyDown(Keys.RightShift))
                {
                    delta *= 10;
                }
                MouseWheelEntities(delta);

                break;
            }


            previousMouse = currentMouse;

            KeyboardState currentKeyboard = Keyboard.GetState();


            if (Editing.Camera != null)
            {
                Editing.Camera.Update(elapsed);
                Vector2 camMove = new Vector2();
                if (currentKeyboard.IsKeyDown(Keys.Left))
                {
                    camMove.X -= elapsed * 500;
                }
                if (currentKeyboard.IsKeyDown(Keys.Right))
                {
                    camMove.X += elapsed * 500;
                }
                if (currentKeyboard.IsKeyDown(Keys.Up))
                {
                    camMove.Y -= elapsed * 500;
                }
                if (currentKeyboard.IsKeyDown(Keys.Down))
                {
                    camMove.Y += elapsed * 500;
                }

                if (camMove.LengthSquared() > 0)
                {
                    Editing.Camera.HandleMessage(Messages.CameraMoveBy, camMove);
                }
            }

            if ((currentKeyboard.IsKeyDown(Keys.Delete) && previousKeyboard.IsKeyUp(Keys.Delete)) || (currentKeyboard.IsKeyDown(Keys.Back) && previousKeyboard.IsKeyUp(Keys.Back)))
            {
                if (selectedEntity != null)
                {
                    selectedEntity.Destroyed = true;
                    layers[currentLayer].Layer.RemoveComponent(selectedEntity);
                    selectedEntity = null;
                }
            }
            if (currentKeyboard.IsKeyDown(Keys.L) && previousKeyboard.IsKeyUp(Keys.L))
            {
                if (layerWindow.Ghost)
                {
                    layerWindow.Show();
                }
                else
                {
                    layerWindow.Hide();
                }
            }
            if ((currentKeyboard.IsKeyDown(Keys.E) && previousKeyboard.IsKeyUp(Keys.E)))
            {
                if (entitiesWindow == null)
                {
                    StartSelectEntity(null);
                }
                else
                {
                    entitiesWindow.Hide();
                }
            }
            if (currentKeyboard.IsKeyDown(Keys.Escape) && previousKeyboard.IsKeyUp(Keys.Escape))
            {
                CloseEditor(null);
            }
            if (currentKeyboard.IsKeyDown(Keys.Space) && previousKeyboard.IsKeyUp(Keys.Space))
            {
                main.Show();
            }

            //TEMP TEST CODE
            if ((currentKeyboard.IsKeyDown(Keys.T) && previousKeyboard.IsKeyUp(Keys.T)))
            {
                Window   t  = new Window(100, 100, 500, 500, "Test Window");
                string   st = "Test text, this is a test text. [C2]This is a piece in red. [C0]And now it its [C1]BLACK [C0]again... This should be a link[LINK] and this shouled be one too.[LINKTOO]    I hope it all works out as planned...[PLANNED]";
                TextArea ta = new TextArea("test", new Vector2(110, 140), new Vector2(480, 400), UILayer.Font, st, 1.5f, 1f, new Color[] { Color.Black, Color.Blue, Color.Red });
                t.AddComponent(ta);
                ta.OnLinkClicked = LinkClicked;
                t.Show();
            }


            previousKeyboard = currentKeyboard;
        }
Beispiel #6
0
        private Window BuildEntitiesWindow(Dictionary <string, PCNComponent> entityList, string name, int first)
        {
            int buttonWidth  = 160;
            int buttonHeight = 24;
            int spacing      = 8;
            int width        = buttonWidth * 3 + spacing * 4;
            int height       = 500;

            entitiesWindow       = new Window(100, 100, width, height, name);
            entitiesWindow.Ghost = true;
            int  x       = spacing;
            int  y       = 20 + spacing;
            bool next    = false;
            bool buttons = false;

            if (first == -1)
            {
                entitiesWindow.AddComponent(new Button(100 + x, 100 + y, buttonWidth, buttonHeight, "<none>", SelectEntity));
                y += buttonHeight + spacing;
                first++;
                buttons = true;
            }

            int i = first;

            foreach (KeyValuePair <string, PCNComponent> entity in entityList)
            {
                if (i > 0)
                {
                    i--;
                }
                else
                {
                    buttons = true;
                    entitiesWindow.AddComponent(new Button(100 + x, 100 + y, buttonWidth, buttonHeight, entity.Key, SelectEntity));
                    y += buttonHeight + spacing;
                    if (y > height - 2 * (buttonHeight + spacing))
                    {
                        x += buttonWidth + spacing;
                        y  = 20 + spacing;
                    }

                    if (x > width - spacing - buttonWidth)
                    {
                        next = true;
                        break;
                    }
                }
            }

            if (first != 0)
            {
                entitiesWindow.AddComponent(new Button(spacing, height - spacing - buttonHeight, buttonWidth, buttonHeight, "Previous", SelectPreviousEntities));
            }
            if (next)
            {
                entitiesWindow.AddComponent(new Button(width - spacing - buttonWidth, height - spacing - buttonHeight, buttonWidth, buttonHeight, "Next", SelectNextEntities));
            }

            entitiesWindow.OnClose = CloseEntityWindow;

            if (!buttons && first > 0)
            {
                firstEntity -= numberOfEntities;
                return(BuildEntitiesWindow(entityList, name, first - numberOfEntities));
            }
            else
            {
                return(entitiesWindow);
            }
        }