Пример #1
0
        /// <summary>
        /// Handles the <see cref="Selector.SelectionChanged"/> event for the "Entity Class" <see
        /// cref="ListView"/>.</summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="SelectionChangedEventArgs"/> object containing event data.</param>
        /// <remarks>
        /// <b>OnClassSelected</b> updates all dialog controls to reflect the selected item in the
        /// "Entity Class" list view.</remarks>

        private void OnClassSelected(object sender, SelectionChangedEventArgs args)
        {
            args.Handled = true;
            if (!this._initialized)
            {
                return;
            }

            // retrieve selected item, if any
            int           index = ClassList.SelectedIndex;
            BuildListItem item  = (index < 0 ? null : (BuildListItem)ClassList.Items[index]);

            // show resources for selected entity class
            ShowResources(item == null ? null : item.EntityClass);

            // check if we can build the selected class
            bool canBuild = (item != null && item.BuildCount > 0);

            // enable Build & Place command for placeable entities
            Debug.Assert(!canBuild || item.EntityClass != null);
            BuildPlaceButton.IsEnabled = (canBuild &&
                                          this._classTargets.ContainsKey(item.EntityClass.Id));

            // enable Build Only command for all entities
            BuildOnlyButton.IsEnabled = canBuild;
        }
Пример #2
0
        /// <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();
                });
            });
        }
Пример #3
0
        /// <summary>
        /// Handles the <see cref="ButtonBase.Click"/> event for the "Build &amp; Place" <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>OnClassBuildPlace</b> sets the <see cref="BuildingClass"/> property to the selected
        /// item in the "Entity Class" list view, if any, and then closes the dialog with a <see
        /// cref="Window.DialogResult"/> of <c>true</c>. The caller should allow the user to select
        /// a placement site for the new <see cref="BuildingClass"/> instance.</remarks>

        private void OnClassBuildPlace(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;
            }

            // quit if entity cannot be placed
            Debug.Assert(item.EntityClass != null);
            if (!this._classTargets.ContainsKey(item.EntityClass.Id))
            {
                return;
            }

            // communicate entity class to caller
            BuildingClass = item.EntityClass;

            // close dialog automatically
            DialogResult = true;
            Close();
        }
Пример #4
0
        /// <summary>
        /// Handles the <see cref="Control.MouseDoubleClick"/> event for a <see
        /// cref="ListViewItem"/> of the hosted <see cref="PropertyListView"/>.</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>OnResourceActivate</b> displays a <see cref="ShowVariables"/> dialog containing
        /// information on the selected item in the "Resource" list view.</remarks>

        private void OnResourceActivate(object sender, MouseButtonEventArgs args)
        {
            args.Handled = true;

            // retrieve double-clicked item, if any
            var source   = args.OriginalSource as DependencyObject;
            var listItem = ItemsControl.ContainerFromElement(ClassList, source) as ListViewItem;

            if (listItem == null)
            {
                return;
            }

            // show info dialog for resource class
            BuildListItem item   = (BuildListItem)listItem.Content;
            var           dialog = new Dialog.ShowVariables(item.ResourceClass)
            {
                Owner = this
            };

            dialog.ShowDialog();
        }
Пример #5
0
        /// <summary>
        /// Updates the "Entity Class" <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 Class" <see cref="ListView"/>; <c>false</c> to not select any item.</param>

        private void UpdateClasses(bool select)
        {
            // remember selected item, if any
            BuildListItem selectedItem = null;

            if (select)
            {
                int index = ClassList.SelectedIndex;
                if (index >= 0)
                {
                    selectedItem = (BuildListItem)ClassList.Items[index];
                }
            }

            // clear Entity Class list view
            ClassList.Items.Clear();

            // get all buildable classes for current category
            var classes = this._faction.GetBuildableClasses(CurrentCategory);

            // quit if no buildable classes
            if (classes == null || classes.Count == 0)
            {
                return;
            }

            // get current filter settings
            bool?showSite  = SiteToggle.IsChecked;
            bool?showPlace = PlaceToggle.IsChecked;

            foreach (EntityClass entityClass in classes.Values)
            {
                // get all place targets for entity class
                IList <PointI> targets;
                this._classTargets.TryGetValue(entityClass.Id, out targets);

                // Site filter: skip classes without this place target
                if (showSite == true &&
                    (targets == null || !targets.Contains(this._selectedSite)))
                {
                    continue;
                }

                // Can Place filter: skip classes with or without place targets
                if ((showPlace == true && targets == null) ||
                    (showPlace == false && targets != null))
                {
                    continue;
                }

                ClassList.Items.Add(new BuildListItem(entityClass));
            }

            // show current & build counts
            ShowClassCounts();

            // select remembered or first item, if any
            if (select && ClassList.Items.Count > 0)
            {
                if (selectedItem != null)
                {
                    for (int i = 0; i < ClassList.Items.Count; i++)
                    {
                        var item = (BuildListItem)ClassList.Items[i];

                        if (item.EntityClass == selectedItem.EntityClass)
                        {
                            ClassList.SelectedIndex = i;
                            ClassList.ScrollIntoView(item);
                            break;
                        }
                    }
                }

                if (ClassList.SelectedIndex < 0)
                {
                    ClassList.SelectedIndex = 0;
                }
            }
        }