コード例 #1
0
ファイル: Container.cs プロジェクト: DuckMonster/Time-Dash-Re
        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
        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;
            }
        }
コード例 #4
0
            public void Logic()
            {
                if (Hovered)
                {
                    if (MouseInput.ButtonPressed(MouseButton.Left))
                    {
                        CloneToMap();
                    }
                    if (MouseInput.ButtonPressed(MouseButton.Right) && MessageBox.Show("Are you sure you want to delete this template?", "Please confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        menu.removeBuffer = this;
                    }

                    if (KeyboardInput.KeyPressed(Key.R))
                    {
                        menu.editor.templateCreator.replaceReference = this;
                        menu.editor.templateCreator.Active           = true;
                    }
                }
            }
コード例 #5
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;
            }
        }
コード例 #6
0
ファイル: Editor.cs プロジェクト: DuckMonster/Time-Dash-Re
        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();
            }
        }
コード例 #7
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)
                };
            }
コード例 #8
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);
        }