/// <summary> /// Process a drop event. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param> private void Grid_DragDrop(object sender, DragEventArgs e) { DragDropData data = e.Data.GetData(typeof(DragDropData)) as DragDropData; Panel panel = sender as Panel; HullModule cell = panel.Tag as HullModule; data.TargetHullModule = cell; if (data.SourceHullModule == data.TargetHullModule && data.SourceHullModule != null) { return; } if (cell.AllocatedComponent != data.SelectedComponent) { cell.AllocatedComponent = data.SelectedComponent; cell.ComponentCount = 0; } cell.ComponentCount += data.ComponentCount; if (cell.ComponentCount > cell.ComponentMaximum) { cell.ComponentCount = cell.ComponentMaximum; } panel.Invalidate(); }
public void AddModule(Module.ModuleType moduleType) { IModule newModule = null; switch (moduleType) { case Module.ModuleType.HullModule: newModule = new HullModule(); break; case Module.ModuleType.WeaponModule: newModule = new WeaponModule(); break; case Module.ModuleType.AerialTechModule: newModule = new AerialTechModule(); break; case Module.ModuleType.None: Debug.LogWarning("ModuleType missing"); //newModule = new Module(); break; default: break; } newModule.IntegrateModule(playerController); integratedModules.Add(newModule); }
/// <summary> /// Instigate Drag and Drop of the selected grid item. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param> private void Grid_DragBegin(object sender, MouseEventArgs e) { Panel panel = sender as Panel; if (panel == null) { return; } HullModule cell = panel.Tag as HullModule; if (cell == null) { return; } Component component = cell.AllocatedComponent; if (component == null || cell.ComponentCount == 0) { return; } DragDropData dragData = new DragDropData(); dragData.HullName = HullName; dragData.ComponentCount = 1; dragData.SelectedComponent = component; dragData.Operation = DragDropEffects.Move; dragData.SourceHullModule = cell; if ((ModifierKeys & Keys.Shift) != 0) { dragData.ComponentCount = Math.Min(10, cell.ComponentCount); } DragDropEffects result = DoDragDrop(dragData, DragDropEffects.Move); if (dragData.SourceHullModule == dragData.TargetHullModule && dragData.SourceHullModule != null) { return; } if (result == DragDropEffects.Move || result == DragDropEffects.None) { cell.ComponentCount -= dragData.ComponentCount; if (cell.ComponentCount <= 0) { cell.AllocatedComponent = null; } DoModuleUpdated(sender, new EventArgs()); panel.Invalidate(); } }
/// <summary> /// Draw an allocated cell. /// </summary> /// <param name="panel">The <see cref="Panel"/> to draw on.</param> /// <param name="graphics">The <see cref="Graphics"/> to place on the panel.</param> private void DrawAllocatedCell(Panel panel, Graphics graphics) { HullModule cell = panel.Tag as HullModule; panel.BackColor = Color.FromName(KnownColor.Control.ToString()); panel.BackgroundImage = cell.AllocatedComponent.ComponentImage; if (cell.ComponentMaximum > 1) { format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Far; string text = cell.ComponentCount + " of " + cell.ComponentMaximum; graphics.DrawString(text, font, Brushes.Blue, textRect, format); } }
/// <summary> /// Draw a defined but empty cell. /// </summary> /// <remarks> /// TODO (priority 4) - for an engine it should say Requires N instead of Up to. Needs to be enforced also. /// TODO (priority 1) - if a cell is cleared change it back to the empty module color. /// </remarks> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param> private void DrawEmptyCell(Panel panel, Graphics graphics) { panel.BackColor = Color.Silver; panel.BackgroundImage = null; HullModule cell = panel.Tag as HullModule; string text = cell.ComponentType; if (cell.ComponentMaximum > 1) { text += "\nUp to " + cell.ComponentMaximum; } format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; graphics.DrawString(text, font, Brushes.Blue, textRect, format); }
/// <Summary> /// Deal with a hull module being selected /// </Summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param> private void DesignModuleSelected(object sender, EventArgs e) { Panel gridModule = sender as Panel; if (gridModule.Tag == null) { return; } HullModule module = gridModule.Tag as HullModule; if (module.AllocatedComponent == null) { return; } Nova.Common.Components.Component component = module.AllocatedComponent; this.componentSummary.Text = component.Description; }
public void IntegrateStartModules() { while (integratedModules.Count < 5) { if (integratedModules.Count == 0) { IModule module = new AerialTechModule(); module.IntegrateModule(playerController); integratedModules.Add(module); } if (integratedModules.Count > 3) { IModule module = new WeaponModule(); module.IntegrateModule(playerController); integratedModules.Add(module); } else { IModule module = new HullModule(); module.IntegrateModule(playerController); integratedModules.Add(module); } } }
/// <summary> /// Process a drag entering a cell and see if we are willing to accept the /// data. The component must be of the correct type and must be allowed on the /// particular hull (Settler's Delight can only be mounted on the /// Mini-Coloniser). /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param> private void Grid_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.None; if (e.Data.GetDataPresent(typeof(DragDropData)) == false) { return; } Panel panel = sender as Panel; HullModule cell = panel.Tag as HullModule; DragDropData data = e.Data.GetData(typeof(DragDropData)) as DragDropData; // Not the right component for this cell. if (!cell.ComponentType.Contains(data.SelectedComponent.Type.ToDescription()) && !(cell.ComponentType.Contains("Weapon") && (data.SelectedComponent.Type == ItemType.BeamWeapons || data.SelectedComponent.Type == ItemType.Torpedoes)) && cell.ComponentType != "General Purpose") { return; } // General Purpose dosen't allow engines if (cell.ComponentType == "General Purpose" && data.SelectedComponent.Type == ItemType.Engine) { return; } // The Settler's Delight engine is only allowed on a min-coloniser // hull. if (data.SelectedComponent.Properties.ContainsKey("Hull Affinity")) { HullAffinity affinity = data.SelectedComponent.Properties["Hull Affinity"] as HullAffinity; if (affinity.Value != data.HullName) { return; } } // Don't allow a CargoPod to be dropped into a general purpose slot as // that could allow "freighters" to be built from hulls not meant to // be freighters. // This is perfectly legal in Stars! e.g. a cargo pod on a scout hull - Daniel Apr 09 /* * if (data.SelectedComponent.Name == "CargoPod") { * if (cell.ComponentType == "General Purpose") { * return; * } * } */ // The Transport Cloak cannot be fitted to armed ships. if (data.SelectedComponent.Properties.ContainsKey("Transport Ships Only")) { foreach (Panel currentCell in panelMap) { if (((HullModule)currentCell.Tag).AllocatedComponent.Properties.ContainsKey("Weapon")) { return; } } } e.Effect = data.Operation; }
/// <summary> /// Right-click context menu has selected an item (only available when cell /// editing is enabled). /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param> private void CellContextMenuItem(object sender, ToolStripItemClickedEventArgs e) { ContextMenuStrip contextMenu = sender as ContextMenuStrip; Panel hullCell = contextMenu.SourceControl as Panel; ToolStripItem selection = e.ClickedItem; // ------------------------------------------------------------------- // Decrement the count of the number of modules that may be added to // this cell. If the count reaches zero then the cell becomes empty. // ------------------------------------------------------------------- if (selection.Text == "Decrement Modules") { if (hullCell.Tag != null) { HullModule cell = hullCell.Tag as HullModule; if (cell.ComponentMaximum > 0) { cell.ComponentMaximum--; } if (cell.ComponentMaximum == 0) { hullCell.Tag = null; } hullCell.Invalidate(); } return; } // ------------------------------------------------------------------- // Increment the count of the number of modules that may be added to // this cell. // ------------------------------------------------------------------- if (selection.Text == "Increment Modules") { if (hullCell.Tag != null) { HullModule cell = hullCell.Tag as HullModule; if (cell.ComponentMaximum > 0) { cell.ComponentMaximum++; } hullCell.Invalidate(); } return; } // ------------------------------------------------------------------- // Clear the contents of a cell // ------------------------------------------------------------------- if (selection.Text == "Clear Cell") { hullCell.Tag = null; hullCell.Invalidate(); return; } // ------------------------------------------------------------------- // Add 10 more modules of the same type // ------------------------------------------------------------------- if (selection.Text == "Add 10") { if (hullCell.Tag != null) { HullModule cell = hullCell.Tag as HullModule; cell.ComponentMaximum += 10; hullCell.Invalidate(); } return; } // ------------------------------------------------------------------- // Add a fixed cargo space to a cell. // ------------------------------------------------------------------- if (selection.Text.Contains("Base Cargo")) { contextMenu.Close(); if (hullCell.Tag != null) { HullModule cell = hullCell.Tag as HullModule; cell.ComponentType = "Base Cargo"; } else { HullModule cell = new HullModule(); cell.ComponentType = "Base Cargo"; hullCell.Tag = cell; } hullCell.Invalidate(); return; } // ------------------------------------------------------------------- // Add a component to a cell. // ------------------------------------------------------------------- if (hullCell.Tag == null) { HullModule cell = new HullModule(); cell.ComponentType = selection.Text; hullCell.Tag = cell; } else { HullModule cell = hullCell.Tag as HullModule; if (cell.ComponentType == selection.Text) { cell.ComponentMaximum++; } else { cell.ComponentType = selection.Text; hullCell.Invalidate(); } } hullCell.Invalidate(); }