Exemple #1
0
 public void SetupGameEvent(GameEvent g)
 {
     g.MouseClick += new MouseEventHandler(TileClick);
 }
Exemple #2
0
        private void SetEvent(int xIndex, int yIndex)
        {
            switch (mode)
            {
            case EditorMode.Remove:
                // Store  all events that occur at the coordinates
                List <GameEvent> eventsAtLocation = new List <GameEvent>();
                foreach (GameEvent g in events)
                {
                    if (g.XIndex == xIndex && g.YIndex == yIndex)
                    {
                        eventsAtLocation.Add(g);
                    }
                }

                // Remove all events at these coordinates

                foreach (GameEvent g in eventsAtLocation)
                {
                    events.Remove(g);

                    Controls.Remove(g);
                }

                break;

            case EditorMode.Enemy:
                // Only one enemy can exist at a location at a time, so first check for other enemies
                GameEvent enemyEvent = null;
                foreach (GameEvent g in events)
                {
                    if (g.EventType == EventType.Enemy && g.XIndex == xIndex && g.YIndex == yIndex)
                    {
                        enemyEvent = g;
                        break;
                    }
                }

                // Only place an enemy if one doesn't exist
                if (enemyEvent == null)
                {
                    enemyEvent             = new GameEvent();
                    enemyEvent.EventType   = EventType.Enemy;
                    enemyEvent.Location    = new Point(1 + xIndex * 32 + AutoScrollPosition.X, 1 + yIndex * 32 + AutoScrollPosition.Y);
                    enemyEvent.Image       = Properties.Resources.Enemy;
                    enemyEvent.MouseClick += new MouseEventHandler(TileClick);
                    enemyEvent.XIndex      = xIndex;
                    enemyEvent.YIndex      = yIndex;
                    events.Add(enemyEvent);
                    Controls.Add(enemyEvent);
                    enemyEvent.BringToFront();
                }

                break;

            case EditorMode.Warp:
                // Only one warp can exist at a location at a time, so first check for other warps
                GameEvent warpEvent = null;
                foreach (GameEvent g in events)
                {
                    if (g.EventType == EventType.Warp && g.XIndex == xIndex && g.YIndex == yIndex)
                    {
                        // Do stuff then break
                        warpEvent = g;
                        break;
                    }
                }

                // Either edit the current warp if it exists or create a new one
                if (warpEvent == null)
                {
                    WarpCreator creator = new WarpCreator();
                    creator.ShowDialog();

                    if (creator.Finished)
                    {
                        warpEvent             = new GameEvent();
                        warpEvent.EventType   = EventType.Warp;
                        warpEvent.WarpData    = new WarpData(creator);
                        warpEvent.Location    = new Point(1 + xIndex * 32 + AutoScrollPosition.X, 1 + yIndex * 32 + AutoScrollPosition.Y);
                        warpEvent.MouseClick += new MouseEventHandler(TileClick);
                        warpEvent.Image       = Properties.Resources.Warp;
                        warpEvent.XIndex      = xIndex;
                        warpEvent.YIndex      = yIndex;
                        events.Add(warpEvent);
                        Controls.Add(warpEvent);
                        warpEvent.BringToFront();
                    }
                }
                else
                {
                    warpEvent.WarpData.WarpCreator.Show();
                }

                break;
            }
        }