예제 #1
0
        private void PlaceEntity()
        {
            Point viewOrigin = ViewControl.PointToScreen(new Point(256, 256));

            double x = ((Cursor.Position.X - viewOrigin.X) / (16 * MapRenderer.CameraScale) + MapRenderer.CameraX);
            double y = ((Cursor.Position.Y - viewOrigin.Y) / (16 * MapRenderer.CameraScale) + MapRenderer.CameraY);

            if (SnapToTileCB.Checked)
            {
                x = Math.Floor(x) + 0.5;
                y = Math.Floor(y) + 0.5;
            }

            Type   t   = EntityClassCB.SelectedItem as Type;
            Entity ent = t.GetConstructor(new Type[0]).Invoke(new object[0]) as Entity;

            myCurrentMap.AddEntity(ent);
            ent.OriginX = x;
            ent.OriginY = y;

            if (ent is Light)
            {
                (ent as Light).Update();
            }

            RenderMap();
        }
예제 #2
0
        private void StartPanningView()
        {
            myDragging = true;

            myDragMid      = Cursor.Position;
            myDragSprite.X = myDragMid.X - ViewControl.PointToScreen(Point.Empty).X - 10;
            myDragSprite.Y = myDragMid.Y - ViewControl.PointToScreen(Point.Empty).Y - 10;
            Cursor.Hide();

            RenderMap();
        }
예제 #3
0
        private void ViewControl_MouseMove(object sender, MouseEventArgs e)
        {
            Point viewOrigin = ViewControl.PointToScreen(new Point(256, 256));

            Point pos = new Point()
            {
                X = (int)Math.Floor((Cursor.Position.X - viewOrigin.X) / (16 * MapRenderer.CameraScale) + MapRenderer.CameraX),
                Y = (int)Math.Floor((Cursor.Position.Y - viewOrigin.Y) / (16 * MapRenderer.CameraScale) + MapRenderer.CameraY)
            };

            myTileSprite.Position = new Vector2(
                (pos.X - MapRenderer.CameraX) * 16.0f * MapRenderer.CameraScale + 256,
                (pos.Y - MapRenderer.CameraY) * 16.0f * MapRenderer.CameraScale + 256);

            if (myDrawing)
            {
                DrawWithCursor();
            }

            if (myDragging)
            {
                if (EntityPropsRB.Checked)
                {
                    Vector2d dragPos = new Vector2d((Cursor.Position.X - viewOrigin.X) / (16.0 * MapRenderer.CameraScale) + MapRenderer.CameraX - myEntDragOrigin.X,
                                                    (Cursor.Position.Y - viewOrigin.Y) / (16.0 * MapRenderer.CameraScale) + MapRenderer.CameraY - myEntDragOrigin.Y);

                    if (SnapToTileCB.Checked)
                    {
                        dragPos.X = Math.Round(dragPos.X * 2.0) / 2.0;
                        dragPos.Y = Math.Round(dragPos.Y * 2.0) / 2.0;
                    }

                    mySelectedEntity.OriginX = dragPos.X;
                    mySelectedEntity.OriginY = dragPos.Y;

                    if (mySelectedEntity is Light)
                    {
                        (mySelectedEntity as Light).Update();
                    }

                    myDragSprite.Position = new Vector2(e.X - 8.0f, e.Y - 8.0f);
                }
                else
                {
                    PanViewWithCursor();
                }
            }

            RenderMap();
        }
예제 #4
0
        private void ViewControl_MouseDown(object sender, MouseEventArgs e)
        {
            if (EntityPropsRB.Checked)
            {
                SelectEntity();
                if (mySelectedEntity == null)
                {
                    return;
                }
            }

            if (e.Button == MouseButtons.Left)
            {
                if (EntityPlaceRB.Checked)
                {
                    PlaceEntity();
                }
                else if (EntityPropsRB.Checked)
                {
                    myDragging = true;

                    Point viewOrigin = ViewControl.PointToScreen(new Point(256, 256));

                    myEntDragOrigin = new Vector2d((Cursor.Position.X - viewOrigin.X) / (16.0 * MapRenderer.CameraScale) + MapRenderer.CameraX - mySelectedEntity.OriginX,
                                                   (Cursor.Position.Y - viewOrigin.Y) / (16.0 * MapRenderer.CameraScale) + MapRenderer.CameraY - mySelectedEntity.OriginY);

                    Cursor.Hide();
                }
                else
                {
                    StartDrawing();
                }
            }
            else
            {
                if (EntityPropsRB.Checked)
                {
                    EntityCM.Show(Cursor.Position);
                }
                else
                {
                    StartPanningView();
                }
            }
        }
예제 #5
0
        private void SelectEntity()
        {
            Point viewOrigin = ViewControl.PointToScreen(new Point(256, 256));

            Vector2d pos = new Vector2d(
                (Cursor.Position.X - viewOrigin.X) / (16 * MapRenderer.CameraScale) + MapRenderer.CameraX,
                (Cursor.Position.Y - viewOrigin.Y) / (16 * MapRenderer.CameraScale) + MapRenderer.CameraY);

            foreach (Entity ent in myCurrentMap.Chunk.Entities)
            {
                if (ent.IsIntersecting(pos))
                {
                    SelectEntity(ent);
                    return;
                }
            }

            DeselectEntity();
        }
예제 #6
0
        private void StartDrawing()
        {
            myDrawing           = true;
            myTileSprite.Colour = new Color4(0.0f, 1.0f, 0.0f, 0.25f);

            if (TilePlaceRB.Checked && PlacementBoxRB.Checked)
            {
                Point viewOrigin = ViewControl.PointToScreen(new Point(256, 256));

                myBoxOrigin = new Point()
                {
                    X = (int)Math.Floor((Cursor.Position.X - viewOrigin.X) / (16 * MapRenderer.CameraScale) + MapRenderer.CameraX),
                    Y = (int)Math.Floor((Cursor.Position.Y - viewOrigin.Y) / (16 * MapRenderer.CameraScale) + MapRenderer.CameraY)
                };

                if (myBoxOrigin.X < 0)
                {
                    myBoxOrigin.X = 0;
                }
                if (myBoxOrigin.X >= myCurrentMap.Width)
                {
                    myBoxOrigin.X = myCurrentMap.Width - 1;
                }
                if (myBoxOrigin.Y < 0)
                {
                    myBoxOrigin.Y = 0;
                }
                if (myBoxOrigin.Y >= myCurrentMap.Height)
                {
                    myBoxOrigin.Y = myCurrentMap.Height - 1;
                }
            }

            DrawWithCursor();
            RenderMap();
        }
예제 #7
0
        private void DrawWithCursor()
        {
            Point viewOrigin = ViewControl.PointToScreen(new Point(256, 256));

            Point pos = new Point()
            {
                X = (int)Math.Floor((Cursor.Position.X - viewOrigin.X) / (16 * MapRenderer.CameraScale) + MapRenderer.CameraX),
                Y = (int)Math.Floor((Cursor.Position.Y - viewOrigin.Y) / (16 * MapRenderer.CameraScale) + MapRenderer.CameraY)
            };

            if (TilePlaceRB.Checked)
            {
                if (PlacementFreeRB.Checked)
                {
                    GameTile t = myCurrentMap.GetTile(pos.X, pos.Y);

                    if (SolidityCB.Checked)
                    {
                        t.IsWall = WallRB.Checked;
                        if (myCurrentMap.IsInterior &&
                            (pos.X == 0 || pos.X == myCurrentMap.Width - 1 ||
                             pos.Y == 0 || pos.Y == myCurrentMap.Height - 1))
                        {
                            if (WallRB.Checked)
                            {
                                RemoveConnector(pos.X, pos.Y);
                            }
                            else
                            {
                                AddConnector(pos.X, pos.Y);
                            }
                        }

                        myCurrentMap.ForceLightUpdate();
                    }

                    if (SkinCB.Checked)
                    {
                        t.Skin = (byte)SkinIDNUD.Value;
                    }

                    if (VariationCB.Checked)
                    {
                        t.Alt = (byte)(DefRB.Checked ? 0 : VeraRB.Checked ? 1 : VerbRB.Checked ? 2 : VercRB.Checked ? 3 : myRand.Next(0, 4));
                    }
                }
                else
                {
                    myBoxEnd = pos;

                    if (myBoxEnd.X < 0)
                    {
                        myBoxEnd.X = 0;
                    }
                    if (myBoxEnd.X >= myCurrentMap.Width)
                    {
                        myBoxEnd.X = myCurrentMap.Width - 1;
                    }
                    if (myBoxEnd.Y < 0)
                    {
                        myBoxEnd.Y = 0;
                    }
                    if (myBoxEnd.Y >= myCurrentMap.Height)
                    {
                        myBoxEnd.Y = myCurrentMap.Height - 1;
                    }
                }
            }
        }