Esempio n. 1
0
        public void OnKeyPressed(object sender, SFML.Window.KeyEventArgs e)
        {
            if (e.Code == Keyboard.Key.F1)
                cursorMode = CursorMode.AddRoom;
            if (e.Code == Keyboard.Key.F2)
                cursorMode = CursorMode.AddDoor;

            if (e.Code == Keyboard.Key.Return)
            {
                ExportShip();
            }

            if (e.Code == Keyboard.Key.F12)
            {
                //ImportShip();
            }

            if (e.Code == Keyboard.Key.Escape)
            {
                cursorMode = CursorMode.None;
            }

            if (e.Code == Keyboard.Key.Space)
            {

                if (selectedDoor != null)
                    selectedDoor.horiz = !selectedDoor.horiz;
                else
                    DoorHorizontal = !DoorHorizontal;

            }

            if (cursorMode == CursorMode.PlacedBGCursor)
            {
                if (e.Code == Keyboard.Key.Left)
                {
                    bgOffset += new Vector2f(-1, 0);
                }
                if (e.Code == Keyboard.Key.Right)
                {
                    bgOffset += new Vector2f(1, 0);
                }
                if (e.Code == Keyboard.Key.Up)
                {
                    bgOffset += new Vector2f(0, -1);
                }
                if (e.Code == Keyboard.Key.Down)
                {
                    bgOffset += new Vector2f(0, 1);
                }
            }

            if (e.Code == Keyboard.Key.Delete)
            {
                switch (cursorMode)
                {
                    case CursorMode.None:
                        break;
                    case CursorMode.RoomSelected:
                        foreach (RoomFunc roomfunc in ship.rooms.Values)
                        {
                            if (roomfunc.location == selectedRoom)
                                roomfunc.location = null;
                        }

                        ShipRooms.Remove(selectedRoom);
                        selectedRoom = null;
                        cursorMode = CursorMode.None;
                        break;
                    case CursorMode.DoorSelected:
                        ShipDoors.Remove(selectedDoor);
                        selectedDoor = null;
                        cursorMode = CursorMode.None;
                        break;
                    case CursorMode.AddRoom:
                        break;
                    case CursorMode.AddDoor:
                        break;
                    case CursorMode.PlacingRoomFunc:
                        break;
                    default:
                        break;
                }
            }

            if (cursorMode == CursorMode.RoomSelected)
            {
                if (selectedRoom == null)
                {
                    cursorMode = CursorMode.None;
                    return;
                }
                if (e.Shift == true)
                {
                    // Shrink mode
                    if (selectedRoom.size.X * selectedRoom.size.Y <= 1)
                        return;

                    if (selectedRoom.size.Y > 1)
                    {

                        if (e.Code == Keyboard.Key.Up)
                        {
                            selectedRoom.size += new Vector2i(0, -1);
                        }

                        if (e.Code == Keyboard.Key.Down)
                        {
                            selectedRoom.position += new Vector2i(0, 1);
                            selectedRoom.size += new Vector2i(0, -1);
                        }
                    }

                    if (selectedRoom.size.X > 1)
                    {
                        if (e.Code == Keyboard.Key.Right)
                        {
                            selectedRoom.position += new Vector2i(1, 0);
                            selectedRoom.size += new Vector2i(-1, 0);
                        }
                        if (e.Code == Keyboard.Key.Left)
                        {
                            selectedRoom.size += new Vector2i(-1, 0);
                        }

                    }
                }
                else
                {
                    if (e.Code == Keyboard.Key.Up)
                    {
                        selectedRoom.position += new Vector2i(0, -1);
                        selectedRoom.size += new Vector2i(0, 1);
                    }
                    if (e.Code == Keyboard.Key.Right)
                    {
                        selectedRoom.size += new Vector2i(1, 0);
                    }
                    if (e.Code == Keyboard.Key.Down)
                    {
                        selectedRoom.size += new Vector2i(0, 1);
                    }
                    if (e.Code == Keyboard.Key.Left)
                    {
                        selectedRoom.position += new Vector2i(-1, 0);
                        selectedRoom.size += new Vector2i(1, 0);
                    }

                }
            }
        }
Esempio n. 2
0
        public void Update()
        {
            Vector2i mouseScreenPos = Mouse.GetPosition(Program.app);
            Vector2i mouseActualPos = Mouse.GetPosition(Program.app) - new Vector2i((int)Game.ship.LayoutData.X_OFFSET * 35, (int)Game.ship.LayoutData.Y_OFFSET * 35);

            switch (cursorMode)
            {
                case CursorMode.None:
                    if (Mouse.IsButtonPressed(Mouse.Button.Left) && lastLMBState == false)
                    {
                        // Single click somewhere!
                        if (Mouse.GetPosition(Program.app).X >= GUIStartX)
                        {
                            GUIClick(mouseScreenPos);

                        }

                        else
                        {
                            // Single click on the screen!
                            bool clickedADoor = false;
                            foreach (FTLDoor tempDoor in ShipDoors)
                            {
                                if (tempDoor.WasClicked(new Vector2f(mouseActualPos.X, mouseActualPos.Y)))
                                {
                                    clickedADoor = true;
                                    selectedDoor = tempDoor;
                                    cursorMode = CursorMode.DoorSelected;
                                    selectedDoor.selected = true;
                                    break;

                                }
                            }

                            if (clickedADoor == false)
                            {
                                bool clickedARoom = false;
                                foreach (FTLRoom tempRoom in ShipRooms)
                                {

                                    if (tempRoom.WasClicked(new Vector2f(mouseActualPos.X, mouseActualPos.Y)))
                                    {
                                        selectedRoom = tempRoom;
                                        cursorMode = CursorMode.RoomSelected;
                                        selectedRoom.selected = true;
                                        clickedARoom = true;
                                        break;

                                    }
                                }
                                if (clickedARoom == false)
                                {
                                    if (selectedRoom != null)
                                    {
                                        selectedRoom.selected = false;
                                        selectedRoom = null;
                                        cursorMode = CursorMode.None;
                                    }
                                }
                            }
                        }

                    }
                    break;
                case CursorMode.RoomSelected:
                    if (Mouse.IsButtonPressed(Mouse.Button.Right))
                    {
                        // Work out which tile we clicked

                        Vector2i tileClicked = new Vector2i((mouseActualPos.X / 35), (mouseActualPos.Y / 35));
                        Vector2i diff = tileClicked - selectedRoom.position + new Vector2i(1, 1);
                        if (diff.X > 0 && diff.Y > 0)
                        {
                            selectedRoom.size += diff - selectedRoom.size;
                        }
                        else
                        {
                            if (diff.X < 0)
                            {
                                selectedRoom.position.X += diff.X;
                                selectedRoom.size.X -= diff.X;
                            }
                            if (diff.Y < 0)
                            {
                                selectedRoom.position.Y += diff.Y;
                                selectedRoom.size.Y -= diff.Y;
                            }
                        }

                    }

                    if (lastLMBState == true && Mouse.IsButtonPressed(Mouse.Button.Left))
                    {
                        selectedRoom.position = new Vector2i((mouseActualPos.X / 35), (mouseActualPos.Y / 35));

                    }
                    else if (lastLMBState == false && Mouse.IsButtonPressed(Mouse.Button.Left))
                    {
                        // Somewhere was clicked whilst a room was selected

                        // Did we click the current room?
                        if (selectedRoom.WasClicked(new Vector2f(mouseActualPos.X, mouseActualPos.Y)))
                        {
                            cursorMode = CursorMode.RoomSelected;
                        }
                        else
                        {

                            selectedRoom.selected = false;
                            selectedRoom = null;
                            cursorMode = CursorMode.None;
                        }

                    }
                    break;
                case CursorMode.DoorSelected:
                    if (lastLMBState == true && Mouse.IsButtonPressed(Mouse.Button.Left))
                    {
                        selectedDoor.position = new Vector2i(mouseActualPos.X / 35, mouseActualPos.Y / 35);

                    }
                    else if (lastLMBState == false && Mouse.IsButtonPressed(Mouse.Button.Left))
                    {
                        // Somewhere was clicked whilst a room was selected

                        // Did we click the current room?
                        if (selectedDoor.WasClicked(new Vector2f(mouseActualPos.X, mouseActualPos.Y)))
                        {
                            cursorMode = CursorMode.DoorSelected;
                        }
                        else
                        {

                            selectedDoor.selected = false;
                            selectedDoor = null;
                            cursorMode = CursorMode.None;
                        }

                    }
                    break;
                case CursorMode.AddRoom:
                    if (Mouse.IsButtonPressed(Mouse.Button.Left) && lastLMBState == false)
                    {
                        cursorMode = CursorMode.None;
                        FTLRoom newRoom = new FTLRoom(new Vector2i(mouseActualPos.X / 35, mouseActualPos.Y / 35), new Vector2i(1, 1));
                        ShipRooms.Add(newRoom);
                        newRoom.selected = true;
                        if (selectedRoom != null)
                            selectedRoom.selected = false;
                        selectedRoom = newRoom;
                        cursorMode = CursorMode.RoomSelected;

                        if (Mouse.IsButtonPressed(Mouse.Button.Right))
                        {
                            if (selectedRoom != null)
                                selectedRoom.selected = false;
                            selectedRoom = null;
                            cursorMode = CursorMode.None;
                        }
                    }
                    break;
                case CursorMode.AddDoor:

                    if (Mouse.IsButtonPressed(Mouse.Button.Left) && lastLMBState == false)
                    {
                        cursorMode = CursorMode.None;
                        FTLDoor newDoor = new FTLDoor(new Vector2i(mouseActualPos.X / 35, mouseActualPos.Y / 35), DoorHorizontal);
                        ShipDoors.Add(newDoor);
                    }

                    if (Mouse.IsButtonPressed(Mouse.Button.Right))
                    {
                        cursorMode = CursorMode.None;
                    }
                    break;
                case CursorMode.PlacingRoomFunc:

                    if (setRoom == RoomID.None || Mouse.IsButtonPressed(Mouse.Button.Right))
                    {
                        cursorMode = CursorMode.None;
                        break;
                    }
                    if (Mouse.IsButtonPressed(Mouse.Button.Left) && lastLMBState == false)
                    {
                        foreach (FTLRoom tempRoom in ShipRooms)
                        {

                            if (tempRoom.WasClicked(new Vector2f(mouseActualPos.X, mouseActualPos.Y)))
                            {
                                // Are we placing a room?
                                if (setRoom != RoomID.None)
                                {
                                    ship.rooms[Enum.GetName(typeof(RoomID), setRoom)].location = tempRoom;
                                    setRoom = RoomID.None;
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case CursorMode.PlaceBGCursor:
                    bgOffset = new Vector2f((int)mouseScreenPos.X - Game.ship.LayoutData.X_OFFSET * 35, (int)mouseScreenPos.Y - Game.ship.LayoutData.Y_OFFSET * 35);
                    bgOffset -= new Vector2f(BaseTex.TextureRect.Width / 2, BaseTex.TextureRect.Height / 2);
                    if (Mouse.IsButtonPressed(Mouse.Button.Left) && lastLMBState == false)
                    {
                        cursorMode = CursorMode.PlacedBGCursor;
                    }
                    break;
                case CursorMode.PlacedBGCursor:
                    if (Mouse.IsButtonPressed(Mouse.Button.Left) && lastLMBState == false)
                    {
                        cursorMode = CursorMode.None;
                    }
                    if (Keyboard.IsKeyPressed(Keyboard.Key.Return))
                    {
                        cursorMode = CursorMode.None;
                    }
                    break;
                default:
                    break;
            }

            lastLMBState = Mouse.IsButtonPressed(Mouse.Button.Left);
        }
Esempio n. 3
0
        public void ImportLayout(string path)
        {
            // create a reader and open the file
            if (path == "")
                return;

            TextReader tr = new StreamReader(path);

            string line;

            while ((line = tr.ReadLine()) != null)
            {
                if (line == "X_OFFSET")
                    ship.LayoutData.X_OFFSET = Convert.ToInt32(tr.ReadLine());
                if (line == "Y_OFFSET")
                    ship.LayoutData.Y_OFFSET = Convert.ToInt32(tr.ReadLine());

                if (line == "VERTICAL")
                    ship.LayoutData.VERTICAL = Convert.ToInt32(tr.ReadLine());
                if (line == "ELLIPSE")
                {
                    ship.LayoutData.SHIELDWIDTH = Convert.ToInt32(tr.ReadLine());
                    ship.LayoutData.SHIELDHEIGHT = Convert.ToInt32(tr.ReadLine());
                    ship.LayoutData.SHIELDX = Convert.ToInt32(tr.ReadLine());
                    ship.LayoutData.SHIELDY = Convert.ToInt32(tr.ReadLine());
                }

                if (line == "ROOM")
                {
                    int id = Convert.ToInt32(tr.ReadLine());

                    Vector2i pos = new Vector2i(Convert.ToInt32(tr.ReadLine()), Convert.ToInt32(tr.ReadLine()));
                    Vector2i size = new Vector2i(Convert.ToInt32(tr.ReadLine()), Convert.ToInt32(tr.ReadLine()));
                    FTLRoom room = new FTLRoom(pos, size);
                    room.id = id;
                    ShipRooms.Add(room);
                }
                else if (line == "DOOR")
                {
                    Vector2i pos = new Vector2i(Convert.ToInt32(tr.ReadLine()), Convert.ToInt32(tr.ReadLine()));
                    tr.ReadLine(); // room A
                    tr.ReadLine(); // room B
                    bool horiz = !Convert.ToBoolean(Convert.ToInt32(tr.ReadLine()));
                    FTLDoor door = new FTLDoor(pos, horiz);
                    ShipDoors.Add(door);
                }
            }
        }