void ScreenControl_SelectedObjectChanged(object sender, EventArgs e) { ScreenControl newControl = sender as ScreenControl; ScreenControl oldSelectedScreen = SelectedScreen; selectedScreenIndex = (int)(newControl.Tag); if (newControl != oldSelectedScreen) { oldSelectedScreen.Deselect(); oldSelectedScreen.ShowScreen(); oldSelectedScreen.BackColor = this.BackColor; oldSelectedScreen.ForeColor = this.ForeColor; newControl.BackColor = SystemColors.Highlight; newControl.ForeColor = SystemColors.HighlightText; ScreenBorder.Bounds = new Rectangle(newControl.Left - 2, newControl.Top - 2, 260, 260); OnSelectedScreenChanged(); } OnSelectedObjectChanged(); GlobalEventManager.Manager.OnObjectSelected(this, newControl.LevelIndex, newControl.SelectedItem); }
/// <summary> /// Sets the size of the screen grid. /// </summary> /// <param name="width">The width of the grid in screens.</param> /// <param name="height">The height of the grid in screens.</param> /// <param name="mapX">The location of the map editor.</param> /// <param name="mapY">The location of the map editor.</param> public void SetSize(int width, int height, int mapX, int mapY) { int newCount = width * height - 1; int diff = screens.Count - newCount; // Destroy extra screens for (int i = 0; i < diff; i++) { ScreenControl removedControl = screens[screens.Count - 1]; Controls.Remove(removedControl); removedControl.Dispose(); removedControl.SelectedObjectChanged -= new EventHandler(ScreenControl_SelectedObjectChanged); removedControl.SelectionDragged -= new EventHandler(ScreenControl_SelectionDragged); screens.Remove(removedControl); } // Create needed screens for (int i = 0; i > diff; i--) { ScreenControl newControl = new ScreenControl(); newControl.Rom = rom; newControl.Size = new Size(256, 256); newControl.SelectedObjectChanged += new EventHandler(ScreenControl_SelectedObjectChanged); newControl.SelectionDragged += new EventHandler(ScreenControl_SelectionDragged); screens.Add(newControl); Controls.Add(newControl); } ScreenBorder.SendToBack(); // position screens, specify indecies int screenIndex = 0; for (int sy = 0; sy < height; sy++) { for (int sx = 0; sx < width; sx++) { if (sx == mapX && sy == mapY) { mapEditor.Bounds = new Rectangle(2 + sx * 258, sy * 258, 256, 256); } else { screens[screenIndex].Bounds = new Rectangle(2 + sx * 258, 2 + sy * 258, 256, 256); screens[screenIndex].Tag = screenIndex; screens[screenIndex].Show(); screenIndex++; } } } // Update variables gridSize = new Size(width, height); mapEditorLocation = new Point(mapX, mapY); mapEditor_LocationIndex = mapX + mapY * width; MapEditor.SelectionSize = new Size(width, height); ScreenBorder.Location = new Point(screens[0].Left - 2, screens[0].Top - 2); screens[0].BackColor = SystemColors.Highlight; screens[0].ForeColor = SystemColors.HighlightText; selectedScreenIndex = 0; }