/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Build Only" <see /// cref="Button"/>.</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>OnClassBuildOnly</b> issues a <see cref="BuildCommand"/> for the selected item in the /// "Entity Class" list view, if any, and updates all dialog controls to reflect the changed /// entity and resource counts.</remarks> private void OnClassBuildOnly(object sender, RoutedEventArgs args) { args.Handled = true; // retrieve selected item, if any int index = ClassList.SelectedIndex; BuildListItem item = (index < 0 ? null : (BuildListItem)ClassList.Items[index]); // quit if nothing to build if (item == null || item.BuildCount <= 0) { return; } // issue Build command Debug.Assert(item.EntityClass != null); AsyncAction.BeginRun(delegate { Session.Instance.Executor.ExecuteBuild(this._worldState, item.EntityClass.Id, 1); AsyncAction.BeginInvoke(delegate { // show new entity and build counts ShowClassCounts(); // reselect item to update dialog ClassList.SelectedIndex = -1; ClassList.SelectAndShow(index); AsyncAction.EndRun(); }); }); }
/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Destroy" <see cref="Button"/>. /// </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>OnEntityDestroy</b> asks for confirmation and then issues a <see /// cref="DestroyCommand"/> for the selected item in the "Entity" list view, if any. /// </remarks> private void OnEntityDestroy(object sender, RoutedEventArgs args) { args.Handled = true; // retrieve selected entity, if any int index = EntityList.SelectedIndex; if (index < 0) { return; } Entity entity = ((EntityListItem)EntityList.Items[index]).Item1; if (!entity.CanDestroy) { return; } // ask user to confirm destruction string caption = String.Format(ApplicationInfo.Culture, Global.Strings.TitleEntityDestroy, entity.Name); MessageBoxResult result = MessageBox.Show(this, Global.Strings.DialogEntityDestroy, caption, MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel); if (result == MessageBoxResult.Cancel) { return; } // issue Destroy command AsyncAction.BeginRun(delegate { Session.Instance.Executor.ExecuteDestroy( this._worldState, new List <Entity>(1) { entity }); // refresh list view and re-select index AsyncAction.BeginInvoke(delegate { UpdateEntities(false); EntityList.SelectAndShow(Math.Max(index, EntityList.Items.Count - 1)); AsyncAction.EndRun(); }); }); }