Exemplo n.º 1
0
        private void levelRenderer_MouseMove(object sender, MouseEventArgs e)
        {
            if (!mouseStartedInRenderer)
            {
                return;
            }

            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                if (levelListBox.SelectedItem == null)
                {
                    return;
                }

                Level             activeLevel = (Level)levelListBox.SelectedItem;
                ImageObject2DType activeType  = (ImageObject2DType)objectPalette.SelectedItem;

                if (ActiveTool == Tool.Pencil)
                {
                    Point position = new Point(e.X, e.Y);
                    int   row      = position.Y / activeLevel.Settings.CellHeight;
                    int   column   = position.X / activeLevel.Settings.CellWidth;

                    if (row < 0)
                    {
                        return;
                    }
                    if (row >= activeLevel.Settings.Rows)
                    {
                        return;
                    }

                    if (column < 0)
                    {
                        return;
                    }
                    if (column >= activeLevel.Settings.Columns)
                    {
                        return;
                    }

                    ImageObject2D type = (ImageObject2D)activeLevel.Get(column, row);

                    if (type == null || type.ParentType != activeType)
                    {
                        activeLevel.Put(activeType == null ? null : activeType.GenerateNew(), column, row);
                        levelRenderer.Refresh();
                        somethingChanged = true;
                    }
                }
                if (ActiveTool == Tool.Eraser)
                {
                    Point position = new Point(e.X, e.Y);
                    int   row      = position.Y / activeLevel.Settings.CellHeight;
                    int   column   = position.X / activeLevel.Settings.CellWidth;

                    if (row < 0)
                    {
                        return;
                    }
                    if (row >= activeLevel.Settings.Rows)
                    {
                        return;
                    }

                    if (column < 0)
                    {
                        return;
                    }
                    if (column >= activeLevel.Settings.Columns)
                    {
                        return;
                    }

                    GameObject gameObject = activeLevel.Get(column, row);
                    if (gameObject != null)
                    {
                        activeLevel.Erase(column, row);
                        levelRenderer.Refresh();
                        somethingChanged = true;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void levelRenderer_MouseDown(object sender, MouseEventArgs e)
        {
            if (levelListBox.SelectedItem == null)
            {
                return;
            }

            mouseStartedInRenderer = true;

            Level             activeLevel = (Level)levelListBox.SelectedItem;
            ImageObject2DType activeType  = (ImageObject2DType)objectPalette.SelectedItem;

            if (ActiveTool == Tool.Pencil)
            {
                Point position = new Point(e.X, e.Y);
                int   row      = position.Y / activeLevel.Settings.CellHeight;
                int   column   = position.X / activeLevel.Settings.CellWidth;

                if (row < 0)
                {
                    return;
                }
                if (row >= activeLevel.Settings.Rows)
                {
                    return;
                }

                if (column < 0)
                {
                    return;
                }
                if (column >= activeLevel.Settings.Columns)
                {
                    return;
                }

                ImageObject2D type = (ImageObject2D)activeLevel.Get(column, row);
                if (type == null || type.ParentType != activeType)
                {
                    if (type != null && !project.Types.Contains(activeType))
                    {
                        throw new Exception("type not in project");
                    }
                    activeLevel.Put(type == null ? null : activeType.GenerateNew(), column, row);
                    levelRenderer.Refresh();
                    somethingChanged = true;
                }
            }
            if (ActiveTool == Tool.Eraser)
            {
                Point position = new Point(e.X, e.Y);
                int   row      = position.Y / activeLevel.Settings.CellHeight;
                int   column   = position.X / activeLevel.Settings.CellWidth;

                if (row < 0)
                {
                    return;
                }
                if (row >= activeLevel.Settings.Rows)
                {
                    return;
                }

                if (column < 0)
                {
                    return;
                }
                if (column >= activeLevel.Settings.Columns)
                {
                    return;
                }

                ImageObject2D type = (ImageObject2D)activeLevel.Get(column, row);
                if (type != null)
                {
                    activeLevel.Erase(column, row);
                    levelRenderer.Refresh();
                    somethingChanged = true;
                }
            }
            if (ActiveTool == Tool.Bucket)
            {
                Point position = new Point(e.X, e.Y);
                int   row      = position.Y / activeLevel.Settings.CellHeight;
                int   column   = position.X / activeLevel.Settings.CellWidth;

                if (row < 0)
                {
                    return;
                }
                if (row >= activeLevel.Settings.Rows)
                {
                    return;
                }

                if (column < 0)
                {
                    return;
                }
                if (column >= activeLevel.Settings.Columns)
                {
                    return;
                }

                if (activeLevel.Get(column, row) == null || activeLevel.Get(column, row).ParentType != activeType)
                {
                    Fill(activeLevel, row, column, activeLevel.Get(column, row), activeType.GenerateNew());
                }

                levelRenderer.Refresh();

                somethingChanged = true;
            }
        }