private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { //Deselect any selected entities txtVar.Text = ""; if (creationGame.getCurrentLevel().vars.selectedEntity != null) { creationGame.getCurrentLevel().sysManager.inputManSystem.deselectEntity(); } if (creationGame.getCurrentLevel().vars.protoEntity != null) { creationGame.getCurrentLevel().removeEntity(creationGame.getCurrentLevel().vars.protoEntity); creationGame.getCurrentLevel().vars.protoEntity = null; } if (lstEntities.SelectedIndex != -1) { EntityListItem item = ( EntityListItem )lstEntities.Items[lstEntities.SelectedIndex]; ProtoEntity p = new ProtoEntity(creationGame.getCurrentLevel(), item.myType); creationGame.getCurrentLevel().addEntity(p.randId, p); creationGame.getCurrentLevel().vars.protoEntity = p; } pnlMain.Focus(); }
private void FormEditor_Load(object sender, EventArgs e) { Type type = typeof(Entity); foreach (Type t in this.GetType().Assembly.GetTypes()) { if (type.IsAssignableFrom(t) && type != t && t != typeof(EntityTemplate) && t != typeof(ProtoEntity)) { EntityListItem i = new EntityListItem(t); lstEntities.Items.Add(i); } } //Add key handlers to the main panel (pnlMain as Control).KeyPress += new KeyPressEventHandler(panelKeyPressEventHandler); (pnlMain as Control).KeyDown += new KeyEventHandler(panelKeyDownEventHandler); (pnlMain as Control).KeyUp += new KeyEventHandler(panelKeyUpEventHandler); (pnlMain as Control).MouseMove += new MouseEventHandler(MouseMoveHandler); (pnlMain as Control).MouseLeave += new EventHandler(MouseLeaveHandler); pnlMainContainer.AutoScroll = true; changeMainPanelSize(pnlMainContainer.Width, pnlMainContainer.Height); creationGame = new CreationGame(pnlMain.CreateGraphics(), pnlMain.Width, pnlMain.Height); creationGame.getCurrentLevel().vars.editForm = this; }
/// <summary> /// Creates a new item for the "Terrain Stack" or "Entity Stack" <see cref="ListView"/>, /// containing the specified <see cref="EntityTemplate"/>.</summary> /// <param name="listView"> /// The <see cref="ListView"/> that receives the specified <paramref name="template"/>. /// </param> /// <param name="template"> /// The <see cref="EntityTemplate"/> to add to the specified <paramref name="listView"/>. /// </param> /// <returns> /// The newly created <see cref="EntityListItem"/> for the specified <paramref /// name="template"/> that was added to the "Entity" <see cref="ListView"/>.</returns> /// <remarks> /// The <see cref="EntityListItem.Item2"/> component of the returned <see /// cref="EntityListItem"/> contains the specified <paramref name="template"/>.</remarks> private static EntityListItem CreateEntityItem( ListView listView, EntityTemplate template) { EntityListItem item = new EntityListItem(GetEntityText(template), template); listView.Items.Add(item); return(item); }
/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Add Entity" <see /// cref="Button"/> and the <see cref="Control.MouseDoubleClick"/> event for the "Available /// Entities" <see cref="ListView"/> on any tab page.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="RoutedEventArgs"/> or <see cref="MouseButtonEventArgs"/> object containing /// event data.</param> /// <remarks> /// <b>OnEntityAdd</b> adds either the first selected item or the double-clicked item in the /// "Available Classes" list view, depending on the exact type of the specified <paramref /// name="args"/>, to the "Entity Stack" list view and sets the <see cref="DataChanged"/> /// flag.</remarks> private void OnEntityAdd(object sender, RoutedEventArgs args) { args.Handled = true; ListView stackList, classList; EntityCategory category; Action onDataChanged; if (TerrainTab.IsSelected) { stackList = TerrainList; classList = AvailableTerrainList; category = EntityCategory.Terrain; onDataChanged = OnTerrainTabChanged; } else { stackList = EntityList; classList = AvailableEntityList; category = this._currentCategory; onDataChanged = OnOtherTabChanged; } // determine which event occurred string classItem = null; if (args.RoutedEvent == ListViewItem.MouseDoubleClickEvent) { // retrieve double-clicked item, if any var source = args.OriginalSource as DependencyObject; var listItem = ItemsControl.ContainerFromElement(classList, source) as ListViewItem; if (listItem != null) { classItem = listItem.Content as string; } } else { // retrieve selected entity class, if any classItem = classList.SelectedItem as String; } if (classItem == null) { return; } // create new entity template with selected class ID EntityTemplate template = new EntityTemplate(category); template.EntityClass = classItem; // create and select associated list view item EntityListItem item = CreateEntityItem(stackList, template); stackList.SelectAndShow(item); // broadcast data changes onDataChanged(); }
public void MatchesSearchTerm_Should_ReturnTrue() { var entity = new EntityListItem { EntityId = Guid.Empty, Name = string.Empty, }; var searchTerm = string.Empty; var result = entity.MatchesSearchTerm(searchTerm); Assert.True(result); }
/// <summary> /// Handles the <see cref="Control.MouseDoubleClick"/> event for a <see /// cref="ListViewItem"/> of the "Entity" <see cref="ListView"/>.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="MouseButtonEventArgs"/> object containing event data.</param> /// <remarks> /// <b>OnEntityActivate</b> displays a <see cref="ShowClasses"/> dialog containing /// information on the double-clicked item in the "Entity" list view.</remarks> private void OnEntityActivate(object sender, MouseButtonEventArgs args) { args.Handled = true; // retrieve double-clicked item, if any var source = args.OriginalSource as DependencyObject; var listItem = ItemsControl.ContainerFromElement(EntityList, source) as ListViewItem; if (listItem == null) { return; } // show info dialog for entity class EntityListItem item = (EntityListItem)listItem.Content; var dialog = new ShowClasses(item.Item1) { Owner = this }; dialog.ShowDialog(); }
/// <summary> /// Updates the "Entity" <see cref="ListView"/> with the current "Category" and "Filter" /// choices.</summary> /// <param name="select"> /// <c>true</c> to select the previously selected item, if any, or else the first item in /// the "Entity" <see cref="ListView"/>; <c>false</c> to not select any item.</param> private void UpdateEntities(bool select) { // remember selected item, if any EntityListItem selectedItem = null; if (select) { int index = EntityList.SelectedIndex; if (index >= 0) { selectedItem = (EntityListItem)EntityList.Items[index]; } } // clear Entity & Property list views EntityList.ItemsSource = null; PropertyList.ShowEntity(null); // get current general filter settings bool?showSite = SiteToggle.IsChecked; bool?showPlaced = PlacedToggle.IsChecked; // get category-specific filter settings EntityCategory category = CurrentCategory; bool? showCategory = null; switch (category) { case EntityCategory.Unit: showCategory = MobileToggle.IsChecked; break; case EntityCategory.Terrain: showCategory = CaptureToggle.IsChecked; break; } // get currently selected site PointI selected = this._mapView.SelectedSite; // get all owned faction entities for current category var entities = this._faction.GetEntities(category); var list = new List <EntityListItem>(entities.Count); foreach (Entity entity in entities) { // Site filter: skip entities on other sites if (showSite == true && (entity.Site == null || entity.Site.Location != selected)) { continue; } // Placed filter: skip placed or unplaced entities if ((showPlaced == true && !entity.IsPlaced) || (showPlaced == false && entity.IsPlaced)) { continue; } // get value that matches category-specific filter bool showEntity = false; switch (category) { case EntityCategory.Unit: showEntity = ((Unit)entity).IsMobile; break; case EntityCategory.Terrain: showEntity = ((Terrain)entity).CanCapture; break; } // skip entities that don't match category-specific filter if ((showCategory == true && !showEntity) || (showCategory == false && showEntity)) { continue; } // show entity name with current site string site = (entity.Site == null ? "—" : entity.Site.ToString()); list.Add(new EntityListItem(entity, site)); } // use ItemsSource for sorting & virtualization list.Sort((x, y) => StringUtility.CompareNatural(x.Item1.ToString(), y.Item1.ToString())); EntityList.ItemsSource = list; // select remembered or first item, if any if (select && EntityList.Items.Count > 0) { if (selectedItem != null) { EntityList.SelectAndShow(selectedItem); } if (EntityList.SelectedIndex < 0) { EntityList.SelectedIndex = 0; } } }
/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Change Entity" <see /// cref="Button"/> and the <see cref="Control.MouseDoubleClick"/> event for the "Entity /// Stack" <see cref="ListView"/> on any tab page.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="RoutedEventArgs"/> object containing event data.</param> /// <remarks> /// <b>OnEntityChange</b> shows the <see cref="Dialog.ChangeTemplate"/> dialog with either /// the first selected item or the double-clicked item in the "Entity Stack" list view, /// depending on the exact type of the specified <paramref name="args"/>, and sets the <see /// cref="DataChanged"/> flag if the user made any changes.</remarks> private void OnEntityChange(object sender, RoutedEventArgs args) { args.Handled = true; ListView stackList; Action onDataChanged; if (TerrainTab.IsSelected) { stackList = TerrainList; onDataChanged = OnTerrainTabChanged; } else { stackList = EntityList; onDataChanged = OnOtherTabChanged; } // determine which event occurred int index = -1; if (args.RoutedEvent == ListViewItem.MouseDoubleClickEvent) { // retrieve double-clicked entity, if any var source = args.OriginalSource as DependencyObject; var listItem = ItemsControl.ContainerFromElement(stackList, source) as ListViewItem; if (listItem != null) { index = stackList.Items.IndexOf(listItem.Content); } } else { // retrieve selected entity, if any index = stackList.SelectedIndex; } if (index < 0) { return; } EntityListItem item = (EntityListItem)stackList.Items[index]; EntityTemplate template = item.Item2; // attempt to find underlying entity class EntityClass entityClass; if (!ChangeTemplate.CanEdit(this, template, out entityClass)) { return; } // show Change Template dialog var dialog = new ChangeTemplate(template, entityClass) { Owner = this }; dialog.ShowDialog(); // broadcast data changes if (dialog.DataChanged) { item = new EntityListItem(GetEntityText(template), item.Item2); stackList.Items[index] = item; stackList.SelectAndShow(index); onDataChanged(); } }
public static bool MatchesSearchTerm(this EntityListItem entityListItem, string searchTerm) { return($"{entityListItem.EntityId} {entityListItem.Name}".Contains(searchTerm)); }