private void InitState()
    {
        GUILayout.Label("Input a number of waves and press the Begin Editing button", EditorStyles.boldLabel);
        levelName     = EditorGUILayout.TextField("Level Name", levelName);
        amountOfWaves = EditorGUILayout.IntField("Amount of Waves", amountOfWaves);

        if (GUI.Button(new Rect((windowWidth / 2) - buttonWidth / 2, windowHeight - (buttonHeight * 3), buttonWidth, buttonHeight), "Begin Editing"))
        {
            if (amountOfWaves == 0)
            {
                EditorUtility.DisplayDialog("Error!", "Amount of waves must be at least 1.", "Ok");
                return;
            }

            if (string.IsNullOrEmpty(levelName))
            {
                EditorUtility.DisplayDialog("Error!", "No level name entered. Please input a level name.", "OK");
                return;
            }
            else
            {
                CreateFolder();
                editorState = EditorStates.Editing;
                waveIndex   = 1;
            }
        }
    }
Ejemplo n.º 2
0
 public LevelEditor(CStrikeModel model)
 {
     driver       = model.DriverInstance;
     input        = model.Input;
     CurrentState = EditorStates.Edit;
     driver.Model.Camera.Position = new Vector2(225, 250);
 }
Ejemplo n.º 3
0
        public EditorLauncher(IPERunArgs args)
        {
            // インスタンスの作成
            Current     = new EditorStates();
            Editor      = new Editor(args, Current, Run);
            Form        = new FormEditor(Editor, Current);
            DrawContext = new DxContext(Form.DrawTargetControl)
            {
                RefreshRate = 120
            };

            // Editorへの入力
            Editor.ToolBox.Device = DrawContext.Device;
            // Formへの入力
            Form.DrawContext     = DrawContext;
            Form.CatchException += OnThrowException;
            Form.AddProcessWhenClosing((sender, e) =>
            {
                e.Cancel = true;
                if (Editor.CanContinueClosing())
                {
                    StopDraw();
                }
            });

            // フィールドの初期値を明示
            isDrawing = false;
        }
Ejemplo n.º 4
0
 public Editor(IPERunArgs args, EditorStates inputManager, Action resetter)
 {
     Args           = args;
     Current        = inputManager;
     EditParameters = new ObservableEditParameter();
     ToolBox        = new Tool.ToolBox(EditParameters);
     Resetter       = resetter;
 }
Ejemplo n.º 5
0
        public bool LoadFromFile(String Filename)
        {
            // Charge les infos sur le projet
            if (File.Exists(Filename))
            {
                FileStream   file   = File.Open(Filename, FileMode.Open);
                BinaryReader reader = new BinaryReader(file);
                states = new EditorStates();
                this.Add(states);
                states.ReadBinary(reader, null);
                reader.Close();
                file.Close();
                return(true);
            }

            return(false);
        }
    private void EditingState()
    {
        var window = (CreateNewLevelDataWizard)EditorWindow.GetWindow(typeof(CreateNewLevelDataWizard));

        GUILayout.Label("Input values for each field and press the Save button to configure the next wave.", EditorStyles.boldLabel);
        numberOfEnemiesToSpawn = EditorGUILayout.IntField("Enemy Count", numberOfEnemiesToSpawn);
        GUILayout.Space(2f);
        timeBetweenSpawns = EditorGUILayout.FloatField("Enemy Spawn Delay", timeBetweenSpawns);

        int newEnemyTypeCount = Mathf.Max(0, EditorGUILayout.IntField("Amount of Enemy Types", enemyTypes.Count)); // The amount of types we want in the wave.

        while (newEnemyTypeCount < enemyTypes.Count)                                                               // Resize the list so it displays the correct object fields corresponding to the amount of types we want.
        {
            enemyTypes.RemoveAt(enemyTypes.Count - 1);
        }

        while (newEnemyTypeCount > enemyTypes.Count)
        {
            enemyTypes.Add(null);
        }

        for (int i = 0; i < enemyTypes.Count; i++)
        {
            enemyTypes[i] = (GameObject)EditorGUILayout.ObjectField(enemyTypes[i], typeof(GameObject), false);
        }

        if (GUI.Button(new Rect((windowWidth / 2) - buttonWidth / 2, windowHeight - (buttonHeight * 3), buttonWidth, buttonHeight), "Save"))
        {
            if (waveIndex + 1 > amountOfWaves)
            {
                editorState = EditorStates.Finished;
                CreateDataObjects();
            }
            else
            {
                waveIndex++;
                CreateDataObjects();
                numberOfEnemiesToSpawn = 0;
                timeBetweenSpawns      = 0;
                window.Repaint();
            }
        }
    }
Ejemplo n.º 7
0
 public void CreateModel()
 {
     states = new EditorStates(version.ToString(), String.Empty);
     this.Add(states);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Updates the logic for level editor
        /// </summary>
        /// <param name="gameTime">the game time</param>
        public void Update(float gameTime)
        {
            // Updates logic according to the state
            switch (CurrentState)
            {
            case EditorStates.Edit:

                // Holds the mouse position according to the map
                mouseMap = input.ScreenToWorld(input.MousePosition, driver.Model.Camera, driver.Model.Center);

                // Reset the property word
                property = "";

                // If mouse is over the tile set
                if (input.MousePosition.X > tileSetOffset.X &&
                    input.MousePosition.X < tileSetOffset.X + tileSetOffset.Width &&
                    input.MousePosition.Y > tileSetOffset.Y &&
                    input.MousePosition.Y < tileSetOffset.Y + tileSetOffset.Height &&
                    showEditView)
                {
                    // If left mouse is clicked
                    if (input.LeftClick())
                    {
                        // Set the selected tile to be the one that they have clicked
                        selectedTile = (byte)((int)((input.MousePosition.Y - tileSetOffset.Y) / TILE_SIZE) * TILE_SET_WIDTH +
                                              (int)((input.MousePosition.X - tileSetOffset.X) / TILE_SIZE));
                    }
                }
                // If the mouse is over the map region
                else if (mouseMap.X > mapArea.X &&
                         mouseMap.X < mapArea.X + mapArea.Width &&
                         mouseMap.Y > mapArea.Y &&
                         mouseMap.Y < mapArea.Y + mapArea.Height)
                {
                    // Find the tile the mouse is on
                    mapTilePos = new Vector2(((mouseMap.X - mapArea.X) / TILE_SIZE), (mouseMap.Y - mapArea.Y) / TILE_SIZE);

                    // If the left mouse button is held
                    if (input.LeftHold())
                    {
                        // Set the selected tile to be in that map tile position according to the mouse keeping the properties if any
                        if (tiles[(int)mapTilePos.X, (int)mapTilePos.Y] != null &&
                            tiles[(int)mapTilePos.X, (int)mapTilePos.Y].TileType != selectedTile)
                        {
                            TempSave();
                            tiles[(int)mapTilePos.X, (int)mapTilePos.Y].SetTileType(selectedTile);
                        }
                        else if (tiles[(int)mapTilePos.X, (int)mapTilePos.Y] == null)
                        {
                            TempSave();

                            tiles[(int)mapTilePos.X, (int)mapTilePos.Y] = new Tile(selectedTile, Tile.NO_PROPERTY,
                                                                                   (int)mapTilePos.X, (int)mapTilePos.Y, destRect);
                        }
                    }
                    // If the right mouse button is held
                    else if (input.RightHold() && tiles[(int)mapTilePos.X, (int)mapTilePos.Y] != null)
                    {
                        TempSave();
                        // Set the tile that the mouse is on to be empty
                        tiles[(int)mapTilePos.X, (int)mapTilePos.Y] = null;
                    }

                    // If the tile the mouse is on is not null set a property according to the key press
                    if (tiles[(int)mapTilePos.X, (int)mapTilePos.Y] != null)
                    {
                        if (input.Tapped(Keys.D0))
                        {
                            TempSave();
                            tiles[(int)mapTilePos.X, (int)mapTilePos.Y].SetProperty(Tile.NO_PROPERTY);
                        }
                        else if (input.Tapped(Keys.D1))
                        {
                            TempSave();
                            tiles[(int)mapTilePos.X, (int)mapTilePos.Y].SetProperty(Tile.SOLID);
                        }
                        else if (input.Tapped(Keys.D2))
                        {
                            TempSave();
                            tiles[(int)mapTilePos.X, (int)mapTilePos.Y].SetProperty(Tile.A_PLANT_SPOT);
                        }
                        else if (input.Tapped(Keys.D3))
                        {
                            TempSave();
                            tiles[(int)mapTilePos.X, (int)mapTilePos.Y].SetProperty(Tile.B_PLANT_SPOT);
                        }
                        else if (input.Tapped(Keys.D4))
                        {
                            TempSave();
                            tiles[(int)mapTilePos.X, (int)mapTilePos.Y].SetProperty(Tile.SAVE_SPOT);
                        }
                        else if (input.Tapped(Keys.D5))
                        {
                            TempSave();
                            tiles[(int)mapTilePos.X, (int)mapTilePos.Y].SetProperty(Tile.CT_SPAWN_POINT);
                        }
                        else if (input.Tapped(Keys.D6))
                        {
                            TempSave();
                            tiles[(int)mapTilePos.X, (int)mapTilePos.Y].SetProperty(Tile.T_SPAWN_POINT);
                        }
                        else if (input.Tapped(Keys.D7))
                        {
                            TempSave();
                            tiles[(int)mapTilePos.X, (int)mapTilePos.Y].SetProperty(Tile.A_SITE_DEFENCE_POINT);
                        }
                        else if (input.Tapped(Keys.D8))
                        {
                            TempSave();
                            tiles[(int)mapTilePos.X, (int)mapTilePos.Y].SetProperty(Tile.B_SITE_DEFENCE_POINT);
                        }

                        // Add the specified properties to the properties string if that property is true
                        switch (tiles[(int)mapTilePos.X, (int)mapTilePos.Y].Property)
                        {
                        case Tile.NO_PROPERTY:
                            property = "No Property";
                            break;

                        case Tile.SOLID:
                            property = "Collidable Tile";
                            break;

                        case Tile.A_PLANT_SPOT:
                            property = "A Plant Tile";
                            break;

                        case Tile.B_PLANT_SPOT:
                            property = "B Plant Tile";
                            break;

                        case Tile.SAVE_SPOT:
                            property = "Save Tile";
                            break;

                        case Tile.CT_SPAWN_POINT:
                            property = "CT Spawn Tile";
                            break;

                        case Tile.T_SPAWN_POINT:
                            property = "T Spawn Tile";
                            break;

                        case Tile.A_SITE_DEFENCE_POINT:
                            property = "A Site Defence Tile";
                            break;

                        case Tile.B_SITE_DEFENCE_POINT:
                            property = "B Site Defence Tile";
                            break;
                        }
                    }
                }

                // If the left control key is held
                if (input.Held(Keys.LeftControl))
                {
                    // Prompts the user to save using a dialog prompt for the location
                    // When the S key is pressed
                    if (input.Tapped(Keys.S))
                    {
                        CurrentState = EditorStates.Save;
                    }
                    // Prompts the user to open a file using a dialog promt for the location
                    // When the O key is pressed
                    else if (input.Tapped(Keys.O))
                    {
                        OpenFileDialog openDialog = new OpenFileDialog();
                        openDialog.Filter      = "Map Files (.txt)|*.txt";
                        openDialog.FilterIndex = 1;
                        openDialog.Multiselect = false;

                        result = openDialog.ShowDialog();
                        if (result == DialogResult.OK)
                        {
                            LoadFile(openDialog.FileName);
                        }
                    }
                    // If 0 key is pressed reset the camera zoom
                    else if (input.Tapped(Keys.D0))
                    {
                        driver.Model.Camera.ResetZoom();
                    }
                    // If the A key is pressed set all the tiles to be the selected tile
                    else if (input.Tapped(Keys.A))
                    {
                        TempSave();
                        for (int col = 0; col < numCols; col++)
                        {
                            for (int row = 0; row < numRows; row++)
                            {
                                tiles[col, row] = new Tile(selectedTile, Tile.NO_PROPERTY, col, row, mapArea);
                            }
                        }
                    }
                    // If the delete key is pressed it removes all tiles placed
                    else if (input.Tapped(Keys.Delete))
                    {
                        TempSave();
                        tiles = new Tile[numCols, numRows];
                    }
                    // If the undo key is pressed it undoes the last action
                    else if (input.Tapped(Keys.Z))
                    {
                        Undo();
                    }
                }
                // Move the camera left when the A key is held
                else if (input.Held(Keys.A))
                {
                    driver.Model.Camera.Position.X -= CAMERA_MOVE_SPEED;
                }
                // Move the camera right when the D key is held
                else if (input.Held(Keys.D))
                {
                    driver.Model.Camera.Position.X += CAMERA_MOVE_SPEED;
                }
                // Move the camera up when the W key is held
                if (input.Held(Keys.W))
                {
                    driver.Model.Camera.Position.Y -= CAMERA_MOVE_SPEED;
                }
                // Move the camera down when the S key is held
                else if (input.Held(Keys.S))
                {
                    driver.Model.Camera.Position.Y += CAMERA_MOVE_SPEED;
                }

                // If the scroll up key is used zoom in
                if (input.ScrollUp())
                {
                    driver.Model.Camera.IncreaseZoom();
                }
                // If the scroll down key is used zoom out
                else if (input.ScrollDown())
                {
                    driver.Model.Camera.DecreaseZoom();
                }

                // If the tab key is pressed toggle the show edit view
                if (input.Tapped(Keys.Tab))
                {
                    showEditView = !showEditView;
                }

                // If the F2 key is pressed change the state to the hot key state
                if (input.Tapped(Keys.F12))
                {
                    CurrentState = EditorStates.ShowHotkeys;
                }

                if (input.Tapped(Keys.Escape))
                {
                    CurrentState = EditorStates.Exit;
                }
                break;

            // If the state is show hot keys
            case EditorStates.ShowHotkeys:

                // If the F2 key is pressed change the state to the edit state
                if (input.Tapped(Keys.F12))
                {
                    CurrentState = EditorStates.Edit;
                }
                break;

            // If the state is save
            case EditorStates.Save:

                if (enteringAuthor)
                {
                    // Gets the user input for author name
                    author = input.GetText(author);

                    // If they hit enter they are dont typing the author name
                    if (input.Tapped(Keys.Enter))
                    {
                        enteringAuthor = false;
                    }
                }
                else
                {
                    // Gets the user input for the author name
                    description = input.GetText(description);

                    // If the user hits enter
                    if (input.Tapped(Keys.Enter))
                    {
                        // Reset entering author variable
                        enteringAuthor = true;

                        // Prompts the user to select the save location with the filter being a .txt file
                        SaveFileDialog saveDialog = new SaveFileDialog();
                        saveDialog.Filter      = "Map Files (.txt)|*.txt";
                        saveDialog.FilterIndex = 1;
                        result = saveDialog.ShowDialog();

                        // If the uer hits save run the save method
                        if (result == DialogResult.OK)
                        {
                            SaveFile(author, description, saveDialog.FileName);
                        }

                        // Sets the state to edit
                        CurrentState = EditorStates.Edit;
                    }
                }

                // If the user his escape go back to level editor
                if (input.Tapped(Keys.Escape))
                {
                    CurrentState = EditorStates.Edit;
                }
                break;
            }
        }
Ejemplo n.º 9
0
        internal FormSaveSelection(EditorStates editorStates)
        {
            Current = editorStates;

            InitializeComponent();
        }