示例#1
0
        public void Logic()
        {
            if (KeyboardInput.Current[Key.LControl])
            {
                if (KeyboardInput.KeyPressed(Key.S))
                {
                    Save();
                }
                if (KeyboardInput.KeyPressed(Key.O))
                {
                    Load();
                }
                if (KeyboardInput.KeyPressed(Key.N))
                {
                    DisposeEditor();
                    editor = new Editor(this);
                }
            }

            if (editor != null)
            {
                string fn = editor.FileName == null ? "Untitled" : editor.FileName;

                if (editor.SaveFlag)
                {
                    fn += " *";
                }
                program.Title = fn + " - Map Editor";

                editor.Logic();
            }
        }
示例#2
0
        public void Logic()
        {
            position += (TargetPosition - position) * 5f * Editor.delta;

            //Change tab
            if (KeyboardInput.Current[Key.LAlt])
            {
                if (KeyboardInput.KeyPressed(Key.Down))
                {
                    tabIndex++;
                }
                if (KeyboardInput.KeyPressed(Key.Up))
                {
                    tabIndex--;
                }
            }

            if (MouseInput.Current.Wheel != MouseInput.Previous.Wheel)
            {
                if (Hovered)
                {
                    float delta = MouseInput.Current.Wheel - MouseInput.Previous.Wheel;

                    scrollSpeed -= 4.5f * delta;
                }
                else if (TabHovered)
                {
                    tabIndex -= (int)(MouseInput.Current.Wheel - MouseInput.Previous.Wheel);
                }
            }

            tabIndex = MathHelper.Clamp(tabIndex, 0, tabList.Length - 1);

            if (Math.Abs(scrollSpeed) > 0.001f)
            {
                scrollAmount[tabIndex] += scrollSpeed * Editor.delta;
                scrollSpeed            -= scrollSpeed * 5 * Editor.delta;
            }

            scrollAmount[tabIndex] = MathHelper.Clamp(scrollAmount[tabIndex], 0, ScrollAvailable);

            removeBuffer = null;

            foreach (TemplateButton btn in CurrentTab)
            {
                btn.Logic();
            }

            if (removeBuffer != null)
            {
                RemoveTemplate(removeBuffer);
            }
        }
示例#3
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            base.OnUpdateFrame(e);

            if (Focused)
            {
                MouseInput.Update(this);
                KeyboardInput.Update();

                container.Logic();
            }
        }
示例#4
0
        public override void Logic()
        {
            base.Logic();

            if (MouseInput.ButtonPressed(MouseButton.Right) && !KeyboardInput.Current[Key.LAlt])
            {
                origin = new Vector2((float)Math.Floor(MouseInput.Current.Position.X), (float)Math.Ceiling(MouseInput.Current.Position.Y));
                a      = origin;
                b      = origin + new Vector2(1, 1);
            }
            if (MouseInput.Current[MouseButton.Right])
            {
                Vector2 pos = new Vector2((float)Math.Floor(MouseInput.Current.Position.X), (float)Math.Ceiling(MouseInput.Current.Position.Y));
                if (pos.X <= origin.X)
                {
                    a.X = pos.X;
                    b.X = origin.X + 1;
                }
                else
                {
                    b.X = pos.X + 1;
                    a.X = origin.X;
                }

                if (pos.Y >= origin.Y)
                {
                    a.Y = pos.Y;
                    b.Y = origin.Y - 1;
                }
                else
                {
                    b.Y = pos.Y - 1;
                    a.Y = origin.Y;
                }
            }

            if (MouseInput.ButtonReleased(MouseButton.Right))
            {
                CreateSolid(a, b);
            }

            if (KeyboardInput.KeyPressed(Key.Number1))
            {
                typeIndex = 0;
            }
            if (KeyboardInput.KeyPressed(Key.Number2))
            {
                typeIndex = 1;
            }
        }
示例#5
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here
            // _testMap.Update(gameTime);
            MouseInput.Update();
            KeyboardInput.Update();
            _editor.Update(gameTime);
            base.Update(gameTime);
        }
示例#6
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            ShapeGenerator.Initialize(GraphicsDevice);
            spriteBatch = new SpriteBatch(GraphicsDevice);
            spriteSheet = Content.Load <Texture2D>("tileset1");


            _editor = new Editor();
            _editor.Load(Content);
            EditorText.Load(Content);
            KeyboardInput.AddKey(Keys.P);
            KeyboardInput.AddKey(Keys.Q);
            KeyboardInput.AddKey(Keys.E);
            //_testMap = new Map(500, 500, spriteSheet);
            //_testMap.Load(Content);

            // TODO: use this.Content to load your game content here
        }
示例#7
0
        public void Logic()
        {
            if (!Active && KeyboardInput.KeyPressed(Key.L) && KeyboardInput.Current[Key.LControl])
            {
                active         = true;
                sliderPosition = 0f;
                editor.SetActiveLayer(editor.layerList[0]);
            }

            if (!Active)
            {
                return;
            }

            if (MouseInput.Current[OpenTK.Input.MouseButton.Left])
            {
                sliderPosition = MouseInput.Current.X;
                if (KeyboardInput.Current[Key.LControl])
                {
                    sliderPosition *= 4f;
                    sliderPosition  = (float)Math.Round(sliderPosition);
                    sliderPosition /= 4f;
                }
            }

            if (KeyboardInput.KeyPressed(Key.Enter))
            {
                editor.CreateLayer(-sliderPosition * 10f);
                active = false;
            }

            if (KeyboardInput.KeyPressed(Key.Escape))
            {
                active = false;
            }
        }
示例#8
0
        public void Logic()
        {
            CalculateDelta();
            UpdateEditMode();

            tilesetList.Logic();
            templateCreator.Logic();
            templateMenu.Logic();
            layerCreator.Logic();

            camera.Logic();

            CurrentManipulator.Logic();

            if (!Paused)
            {
                {
                    float mousex = MouseInput.Current.Position.X;
                    float mousey = MouseInput.Current.Position.Y;

                    mousex = (float)Math.Round(mousex);
                    mousey = (float)Math.Round(mousey);

                    Console.Clear();
                    Console.WriteLine(mousex + ", " + mousey);
                }

                if (KeyboardInput.Current[Key.LControl])
                {
                    if (KeyboardInput.KeyPressed(Key.Z))
                    {
                        Undo();
                    }

                    if (KeyboardInput.KeyPressed(Key.Y))
                    {
                        Redo();
                    }

                    if (KeyboardInput.KeyPressed(Key.D))
                    {
                        DuplicateSelected();
                    }

                    if (KeyboardInput.KeyPressed(Key.B))
                    {
                        background.LoadTexture();
                    }

                    if (KeyboardInput.KeyPressed(Key.Delete) && MessageBox.Show("Are you sure you want to delete this layer?", "Please confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        DeleteLayer(ActiveLayer);
                    }
                }
                else
                {
                    if (KeyboardInput.KeyPressed(Key.G))
                    {
                        showGrid = !showGrid;
                    }

                    if (KeyboardInput.KeyPressed(Key.B))
                    {
                        background.show = !background.show;
                    }

                    if (KeyboardInput.KeyPressed(Key.L))
                    {
                        preview = !preview;
                    }

                    if (KeyboardInput.KeyPressed(Key.H))
                    {
                        hideVertices = !hideVertices;
                    }

                    if (KeyboardInput.KeyPressed(Key.Z))
                    {
                        hideSolids = !hideSolids;
                    }

                    if (KeyboardInput.KeyPressed(Key.F1))
                    {
                        if (dataForm == null)
                        {
                            dataForm = new LevelDataForm(this);
                            dataForm.Show();
                        }
                        else
                        {
                            dataForm.Dispose();
                            dataForm = null;
                        }
                    }

                    if (KeyboardInput.KeyPressed(Key.F2))
                    {
                        List <EventObject> events = new List <EventObject>();

                        foreach (EditorObject o in ActiveObjects)
                        {
                            if ((o is EventObject) && o.Selected)
                            {
                                events.Add(o as EventObject);
                            }
                        }

                        if (events.Count > 0)
                        {
                            new EventForm(events.ToArray()).Show();
                        }
                    }

                    if (KeyboardInput.KeyPressed(Key.Delete))
                    {
                        DeleteSelected();
                    }
                }

                if (KeyboardInput.KeyPressed(Key.Minus))
                {
                    MoveSelected(1);
                }
                if (KeyboardInput.KeyPressed(Key.Slash))
                {
                    MoveSelected(-1);
                }

                if (MouseInput.ButtonPressed(MouseButton.Right))
                {
                    DeselectAll();
                }
                if (MouseInput.ButtonPressed(MouseButton.Left) && !CurrentManipulator.Hovered && !templateMenu.Hovered)
                {
                    Vertex       v     = GetVertexAt(MouseInput.Current.Position);
                    EditorObject obj   = GetObjectAt(MouseInput.Current.Position);
                    Layer        layer = GetHoveredLayer();

                    if (layer != null)
                    {
                        SetActiveLayer(layer);
                    }
                    if (v != null)
                    {
                        Select(v);
                    }
                    else if (obj != null)
                    {
                        obj.Select();
                    }
                    else
                    {
                        selectionBox = new SelectionBox(MouseInput.Current.Position, this);
                    }
                }

                if (MouseInput.ButtonReleased(MouseButton.Left) && selectionBox != null)
                {
                    if (KeyboardInput.Current[Key.LControl])
                    {
                        Deselect(selectionBox.GetObjects().ToArray());
                    }
                    else
                    {
                        Select(selectionBox.GetObjects().ToArray());
                    }

                    selectionBox.Dispose();
                    selectionBox = null;
                }

                if (selectionBox != null)
                {
                    selectionBox.Logic();
                }

                ActiveLayer.Logic();
            }
        }
示例#9
0
        //---------------------------------------------
        //private void Undo()
        //{
        //    //_undoManager.Undo();
        //}

        private void ParseKeys()
        {
            KeyboardState state = Keyboard.GetState();

            // Control is Down
            if (state.IsKeyDown(Keys.LeftControl))
            {
                if (state.IsKeyDown(Keys.T))
                {
                    SwitchTextures();
                }

                if (state.IsKeyDown(Keys.A))
                {
                    ChangeMapDimensions();
                }

                if (state.IsKeyDown(Keys.O))
                {
                    OpenMap();
                }

                if (state.IsKeyDown(Keys.S))
                {
                    SaveMap();
                }

                if (state.IsKeyDown(Keys.N))
                {
                    NewMap();
                }

                //---------| UNDO |
                //if (state.IsKeyDown(Keys.Z))
                //{
                //}
            }
            else
            {
                float speed = (_mapMovementReverse ? -1 : 1) * _speed;
                if (state.IsKeyDown(Keys.A))
                {
                    _mapPosition.X  -= speed;
                    _selectionPos.X -= (int)speed;
                }
                if (state.IsKeyDown(Keys.D))
                {
                    _mapPosition.X  += speed;
                    _selectionPos.X += (int)speed;
                }
                if (state.IsKeyDown(Keys.W))
                {
                    _mapPosition.Y  -= speed;
                    _selectionPos.Y -= (int)speed;
                }
                if (state.IsKeyDown(Keys.S))
                {
                    _mapPosition.Y  += speed;
                    _selectionPos.Y += (int)speed;
                }
                if (state.IsKeyDown(Keys.OemTilde))
                {
                    EditorDraw.PlaceTile(_tileSelectionID, _selectionX, _selectionY, ShowCollision);
                }
                if (state.IsKeyDown(Keys.R))
                {
                    _zoom        = 1f;
                    _mapPosition = Vector2.Zero;
                }
                if (KeyboardInput.CheckIsPressed(Keys.P))
                {
                    ShowCollision = !ShowCollision;
                }
                if (KeyboardInput.CheckIsPressed(Keys.O))
                {
                    ShowTriggers = !ShowTriggers;
                }

                if (KeyboardInput.CheckIsPressed(Keys.Q))
                {
                    if (_tileSelectionID > 0)
                    {
                        _tileSelectionID--;
                        CurrentTileSelectionID--;
                    }
                }
                if (KeyboardInput.CheckIsPressed(Keys.E))
                {
                    if (_tileSelectionID < CurrentMap.TextureMap.GetTilesPerRow() - 1)
                    {
                        _tileSelectionID++;
                        CurrentTileSelectionID++;
                    }
                }
            }
        }
示例#10
0
            public void Logic()
            {
                if (!KeyboardInput.Current[Key.LAlt])
                {
                    if (MouseInput.ButtonPressed(MouseButton.Left))
                    {
                        a = (MouseInput.Current.PositionOrtho - creator.Position) * new Vector2(1 / creator.Size.X, 1 / creator.Size.Y);
                    }
                    if (MouseInput.Current[MouseButton.Left])
                    {
                        b = (MouseInput.Current.PositionOrtho - creator.Position) * new Vector2(1 / creator.Size.X, 1 / creator.Size.Y);
                    }
                }

                a = Vector2.Clamp(a, new Vector2(-0.5f, -0.5f), new Vector2(0.5f, 0.5f));
                b = Vector2.Clamp(b, new Vector2(-0.5f, -0.5f), new Vector2(0.5f, 0.5f));

                if (KeyboardInput.KeyPressed(Key.Enter) && Active)
                {
                    DRAW.RectangleF uv = UV;

                    float right, left, up, down;
                    creator.CurrentTileset.GetOpaqueOffset(uv, out left, out right, out up, out down);

                    System.Drawing.RectangleF uvOpaque = new DRAW.RectangleF(uv.X + left, uv.Y + up, uv.Width - right - left, uv.Height - down - up);

                    if (uvOpaque.Width * creator.CurrentTileset.Width > 1f && uvOpaque.Height * creator.CurrentTileset.Height > 1f)
                    {
                        if (creator.replaceReference == null)
                        {
                            creator.editor.CreateTemplate(creator.tilesetIndex, uvOpaque);
                            Active = false;
                        }
                        else
                        {
                            Template t = creator.replaceReference.template;

                            t.UV           = uvOpaque;
                            creator.Active = false;
                            creator.replaceReference.size = t.Size;

                            creator.replaceReference = null;
                        }

                        Active = false;
                    }
                }

                DRAW.RectangleF meshRect = UV;

                mesh.Vertices = new Vector2[] {
                    new Vector2(meshRect.X - .5f, 0.5f - meshRect.Y),
                    new Vector2(meshRect.X - .5f + meshRect.Width, 0.5f - meshRect.Y),
                    new Vector2(meshRect.X - .5f + meshRect.Width, 0.5f - (meshRect.Y + meshRect.Height)),
                    new Vector2(meshRect.X - .5f, 0.5f - (meshRect.Y + meshRect.Height))
                };

                mesh.UV = new Vector2[] {
                    new Vector2(meshRect.X, meshRect.Y),
                    new Vector2(meshRect.X + meshRect.Width, meshRect.Y),
                    new Vector2(meshRect.X + meshRect.Width, meshRect.Y + meshRect.Height),
                    new Vector2(meshRect.X, meshRect.Y + meshRect.Height)
                };
            }
示例#11
0
        public void Logic()
        {
            if (KeyboardInput.KeyPressed(Key.Tab))
            {
                if (editor.tilesetList.Count == 0)
                {
                    editor.tilesetList.PromptLoad();
                }

                if (editor.tilesetList.Count > 0)
                {
                    active = true;
                }
            }

            if (!Active)
            {
                return;
            }

            marker.Logic();

            if (KeyboardInput.KeyPressed(Key.N))
            {
                editor.tilesetList.PromptLoad();
            }

            if (KeyboardInput.KeyPressed(Key.R))
            {
                CurrentTileset.LoadNewFile();
            }

            if (KeyboardInput.KeyPressed(Key.Delete) && MessageBox.Show("Are you sure you want to delete this tileset?", "Please confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                RemoveTileset(CurrentTileset);
            }

            if (KeyboardInput.KeyPressed(Key.Escape))
            {
                active = false;
            }

            if (KeyboardInput.Current[Key.LAlt])
            {
                if (KeyboardInput.KeyPressed(Key.Right))
                {
                    SwitchTileset(1);
                }
                if (KeyboardInput.KeyPressed(Key.Left))
                {
                    SwitchTileset(-1);
                }

                if (MouseInput.Current[MouseButton.Left])
                {
                    positionOffset += MouseInput.Current.PositionOrtho - MouseInput.Previous.PositionOrtho;
                }
            }

            if (MouseInput.Current[MouseButton.Middle])
            {
                positionOffset += MouseInput.Current.PositionOrtho - MouseInput.Previous.PositionOrtho;
            }

            zoomSpeed += (MouseInput.Current.Wheel - MouseInput.Previous.Wheel) * 0.5f;

            zoom      += zoomSpeed * 5 * Editor.delta;
            zoomSpeed -= zoomSpeed * 5 * Editor.delta;
            zoom       = MathHelper.Clamp(zoom, 1f, 5f);
        }