private void listBox_SelectedIndexChanged(object sender, EventArgs e) { if (listBox.SelectedIndex == -1) { return; } //Here we need to set the form items that we're using with the information of the item we've selected in the listbox: if (mode == CreateMode.Walls) { Rectangle selectedWall = game.map.walls[listBox.SelectedIndex].wall; xPosition.Value = selectedWall.X; yPosition.Value = selectedWall.Y; height.Value = selectedWall.Height; width.Value = selectedWall.Width; } else if (mode == CreateMode.Objects) { GameObject selectedObject = game.objects[listBox.SelectedIndex]; xPosition.Value = (int)selectedObject.startPosition.X; yPosition.Value = (int)selectedObject.startPosition.Y; } else if (mode == CreateMode.Decor) { Decor selectedDecor = game.map.decor[listBox.SelectedIndex]; xPosition.Value = (decimal)selectedDecor.position.X; yPosition.Value = (decimal)selectedDecor.position.Y; layerDepth.Value = (decimal)selectedDecor.layerDepth; imagePath.Text = selectedDecor.imagePath; decorSourceX.Value = (decimal)selectedDecor.sourceRect.X; decorSourceY.Value = (decimal)selectedDecor.sourceRect.Y; decorSourceWidth.Value = (decimal)selectedDecor.sourceRect.Width; decorSourceHeight.Value = (decimal)selectedDecor.sourceRect.Height; } }
private void CopyDecor() { if (listBox.SelectedIndex == -1) { return; } //Make a new piece of decor exactly like the one we have selected: Decor selectedDecor = (Decor)game.map.decor[listBox.SelectedIndex]; Decor newDecor = new Decor(selectedDecor.position, selectedDecor.imagePath, selectedDecor.layerDepth); //Load it: newDecor.Load(game.Content, newDecor.imagePath); //Add to our list: game.map.decor.Add(newDecor); SetListBox(game.map.decor, false); }
private void DrawSelectedItem(SpriteBatch spriteBatch) { if (drawSelected.Checked == false) { return; } //Draw a slight box around whatever we're currently editing: if (mode == CreateMode.Walls) { if (game.map.walls.Count == 0) { return; } Wall selectedWall = game.map.walls[listBox.SelectedIndex]; spriteBatch.Draw(pixel, new Vector2((int)selectedWall.wall.X, (int)selectedWall.wall.Y), selectedWall.wall, Color.SkyBlue, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0); } else if (mode == CreateMode.Objects) { if (game.objects.Count == 0) { return; } GameObject selectedObject = game.objects[listBox.SelectedIndex]; spriteBatch.Draw(pixel, new Vector2((int)selectedObject.position.X, (int)selectedObject.position.Y), selectedObject.BoundingBox, new Color(80, 80, 100, 80), 0f, Vector2.Zero, 1f, SpriteEffects.None, 0); } else if (mode == CreateMode.Decor) { if (game.map.decor.Count == 0) { return; } Decor selectedDecor = game.map.decor[listBox.SelectedIndex]; spriteBatch.Draw(pixel, new Vector2((int)selectedDecor.position.X, (int)selectedDecor.position.Y), selectedDecor.BoundingBox, new Color(80, 80, 100, 80), 0f, Vector2.Zero, 1f, SpriteEffects.None, 0); } }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // IMPORTANT FUNCTION!! WHENEVER YOU ADD NEW GAMEOBJECTS TO YOUR GAME YOU'LL NEED TO ADD THEM HERE TO THE EDITOR!!!!!! // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private void addButton_Click(object sender, EventArgs e) //ADD NEW OBJECT CONSTRUCTORS IN THIS FUNCTION!!! { if (objectTypes.SelectedIndex == -1) { return; } if (mode == CreateMode.Objects) { ObjectType selectedObject = (ObjectType)objectTypes.Items[objectTypes.SelectedIndex]; GameObject newObject = null; //IMPORTANT: CREATE NEW GAME OBJECTS IN THIS IF STATEMENT BLOCK! //Each object you want to add needs to be specifically typed with its own constructor (new Enemy, new PowerUp etc.): if (selectedObject == ObjectType.Enemy) { newObject = new Enemy(Vector2.Zero); } else if (selectedObject == ObjectType.PowerUp) { newObject = new PowerUp(); } else if (selectedObject == ObjectType.IslamicEnemy) { newObject = new IslamicEnemy(); } else if (selectedObject == ObjectType.EnemyFifthLevel) { newObject = new EnemyFifthLevel(Vector2.Zero); } else if (selectedObject == ObjectType.IslamicEnemyFifthLevel) { newObject = new IslamicEnemyFifthLevel(); } if (newObject == null) { return; //No valid object created. } //Load the object and add it into our list: newObject.Load(game.Content); game.objects.Add(newObject); placingItem = true; FocusGameWindow(); SetListBox(game.objects, false); } else if (mode == CreateMode.Decor) { Decor newDecor = new Decor(); newDecor.imagePath = "decorplaceholder"; //Default image until we load the one we want. newDecor.Load(game.Content, newDecor.imagePath); game.map.decor.Add(newDecor); placingItem = true; SetListBox(game.map.decor, false); FocusGameWindow(); } }