Ejemplo n.º 1
0
        /// <summary>
        /// Handles the <see cref="ButtonBase.Click"/> event for the "Remove Faction" <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>OnFactionRemove</b> removes the first selected item in the "Faction" list view, if
        /// any, from that list view and from the current <see cref="FactionSection"/>, and sets the
        /// <see cref="SectionTabItem.DataChanged"/> flag.</remarks>

        private void OnFactionRemove(object sender, RoutedEventArgs args)
        {
            args.Handled = true;

            // retrieve selected faction, if any
            int index = FactionList.SelectedIndex;

            if (index < 0)
            {
                return;
            }
            FactionClass faction = (FactionClass)FactionList.Items[index];

            // delete existing ID references
            var factions = MasterSection.Instance.Factions.Collection;

            if (!SectionTabItem.ProcessAllIdentifiers(factions, faction.Id, null))
            {
                return;
            }

            // select item in the same position
            FactionList.Items.Refresh();
            if (FactionList.Items.Count > 0)
            {
                FactionList.SelectAndShow(Math.Min(FactionList.Items.Count - 1, index));
            }

            // broadcast data changes
            EnableListButtons();
            SectionTab.DataChanged = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the <see cref="ButtonBase.Click"/> event for the "Move Up" <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>OnFactionUp</b> swaps the first selected item in the "Faction" list view with its
        /// upper neighbour, propagates the change to the current <see cref="FactionSection"/>, and
        /// sets the <see cref="SectionTabItem.DataChanged"/> flag.</remarks>

        private void OnFactionUp(object sender, RoutedEventArgs args)
        {
            args.Handled = true;

            // retrieve selected faction, if any
            if (FactionList.Items.Count < 2)
            {
                return;
            }
            FactionClass faction = FactionList.SelectedItem as FactionClass;

            if (faction == null)
            {
                return;
            }

            // move item up in section table
            var factions = MasterSection.Instance.Factions.Collection;
            int index    = factions.IndexOfKey(faction.Id);

            if (index > 0)
            {
                var pair = factions[index - 1];
                factions[index - 1] = factions[index];
                factions[index]     = pair;
            }

            // broadcast data changes
            FactionList.Items.Refresh();
            FactionList.SelectAndShow(index - 1);
            SectionTab.DataChanged = true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles the <see cref="ButtonBase.Click"/> event for the "Add Faction" <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><para>
        /// <b>OnFactionAdd</b> displays a <see cref="Dialog.ChangeIdentifier"/> dialog, followed by
        /// a <see cref="Dialog.ChangeFaction"/> dialog, allowing the user to define a new faction.
        /// The new faction copies the properties of the first selected item in the "Faction" list
        /// view, if any; otherwise, it is created with default properties.
        /// </para><para>
        /// If the user confirmed both dialogs, <b>OnFactionAdd</b> adds the new faction to the
        /// "Faction" list view and to the current <see cref="FactionSection"/>, and sets the <see
        /// cref="SectionTabItem.DataChanged"/> flag.</para></remarks>

        private void OnFactionAdd(object sender, RoutedEventArgs args)
        {
            args.Handled = true;

            // ask user for new faction ID
            var factions = MasterSection.Instance.Factions.Collection;
            var dialog   = new Dialog.ChangeIdentifier("faction-id",
                                                       Global.Strings.TitleFactionIdEnter, factions.ContainsKey, false);

            dialog.Owner = MainWindow.Instance;
            if (dialog.ShowDialog() != true)
            {
                return;
            }

            // retrieve new faction ID
            string id = String.Intern(dialog.Identifier);

            // create new faction based on selected faction, if any
            FactionClass faction, selection = FactionList.SelectedItem as FactionClass;

            if (selection == null)
            {
                faction = new FactionClass(id);
                // add default defeat condition (site loss)
                faction.DefeatConditions.Add(new Condition());
            }
            else
            {
                faction    = (FactionClass)selection.Clone();
                faction.Id = id;
            }

            // let user make changes to new faction
            var factionDialog = new Dialog.ChangeFaction(faction)
            {
                Owner = MainWindow.Instance
            };

            if (factionDialog.ShowDialog() != true)
            {
                return;
            }

            // add faction to section table
            factions.Add(id, faction);

            // update list view and select new item
            FactionList.Items.Refresh();
            FactionList.SelectAndShow(faction);

            // broadcast data changes
            EnableListButtons();
            SectionTab.DataChanged = true;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShowFactions"/> class with the specified
        /// <see cref="MapView"/> and initially selected <see cref="FactionClass"/>.</summary>
        /// <param name="mapView">
        /// The <see cref="MapView"/> whose <see cref="MapView.WorldState"/> contains all surviving
        /// factions.</param>
        /// <param name="factionClass">
        /// The <see cref="FactionClass"/> to select initially, or a null reference to select the
        /// first faction.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="mapView"/> is a null reference.</exception>

        public ShowFactions(MapView mapView, FactionClass factionClass)
        {
            if (mapView == null)
            {
                ThrowHelper.ThrowArgumentNullException("mapView");
            }

            // select first faction class if none specified
            if (factionClass == null)
            {
                factionClass = MasterSection.Instance.Factions.Collection[0].Value;
            }

            this._mapView      = mapView;
            this._worldState   = mapView.WorldState;
            this._factionClass = factionClass;
            this._dialogTitle  = Title;

            // count all sites that are, or can be, owned
            foreach (Site site in this._worldState.Sites)
            {
                if (site.CanCapture || site.Owner != null)
                {
                    ++this._siteCount;
                }
            }

            InitializeComponent();

            // ClassesTab: adjust column widths of Entity Class list view
            DependencyPropertyDescriptor.FromProperty(
                ListView.ActualWidthProperty, typeof(ListView))
            .AddValueChanged(ClassList, OnClassWidthChanged);

            // VariablesTab: adjust column widths of Variable list view
            DependencyPropertyDescriptor.FromProperty(
                ListView.ActualWidthProperty, typeof(ListView))
            .AddValueChanged(VariableList, OnVariableWidthChanged);

            // ConditionsTab: adjust column widths of Condition list view
            DependencyPropertyDescriptor.FromProperty(
                ListView.ActualWidthProperty, typeof(ListView))
            .AddValueChanged(ConditionList, OnConditionWidthChanged);

            // show factions and select specified faction
            FactionCombo.ItemsSource  = MasterSection.Instance.Factions.Collection.Values;
            FactionCombo.SelectedItem = factionClass;

            // default to unit classes
            UnitToggle.IsChecked = true;
        }
        public void AddFaction(FactionClass faction)
        {
            using (var client = new MyCouchClient("http://31.132.4.108:5984", "dropzonefactions"))
            {
                string output = JsonConvert.SerializeObject(faction);
                Console.WriteLine(output);

                var response = client.Documents.PostAsync(output);

                Console.WriteLine(response.IsCompleted);
                Console.WriteLine(response.Result.Reason);

                MessageBox.Show("Faction Added Sucesfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void FactionSelectButton_Click(object sender, EventArgs e)
        {
            selectedFaction = (FactionClass)FactionCombo.SelectedItem;
            string factionName  = selectedFaction.Name;
            var    getUnitsTask = Task.Run(() => GetUnits());
            bool   unitsGot     = false;

            while (unitsGot == false)
            {
                unitsGot = CheckTaskComplete(getUnitsTask);
            }

            UnitCombo.DataSource    = unitList;
            UnitCombo.DisplayMember = "Name";
            panel1.Visible          = false;
            UnitPanel.Visible       = true;
        }
        public async Task <List <FactionClass> > GetAllFactions()
        {
            List <FactionClass> factionList = new List <FactionClass>();

            using (HttpClient client = new HttpClient())
            {
                try
                {
                    string address = "http://31.132.4.108:5984/dropzonefactions/_design/factions/_view/allfactions?include_docs=true";

                    HttpResponseMessage response = await client.GetAsync(address);

                    response.EnsureSuccessStatusCode();
                    string responseBody = await response.Content.ReadAsStringAsync();

                    Console.WriteLine(responseBody);

                    var factions = FactionQT.Factions.FromJson(responseBody);

                    foreach (var row in factions.Rows)
                    {
                        FactionClass newFaction = new FactionClass();
                        newFaction.SetCouchID(row.Id);
                        newFaction.Name     = row.Doc.Name;
                        newFaction.Lore     = row.Doc.Lore;
                        newFaction.GamePlay = row.Doc.GamePlay;
                        newFaction.Imageurl = row.Doc.Imageurl;

                        factionList.Add(newFaction);
                    }
                }

                catch (HttpRequestException e)
                {
                    Console.WriteLine("Exception " + e + " caught");
                }
            }

            return(factionList);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Allows the user to change the specified <see cref="FactionClass"/>.</summary>
        /// <param name="faction">
        /// The <see cref="FactionClass"/> to change.</param>
        /// <remarks><para>
        /// <b>ChangeFaction</b> displays a <see cref="Dialog.ChangeFaction"/> dialog for the
        /// specified <paramref name="faction"/>.
        /// </para><para>
        /// If the user made any changes, <b>ChangeFaction</b> propagates them to the faction
        /// collection of the current <see cref="FactionSection"/> and sets the <see
        /// cref="SectionTabItem.DataChanged"/> flag.</para></remarks>

        private void ChangeFaction(FactionClass faction)
        {
            if (faction == null)
            {
                return;
            }

            // show dialog and let user make changes
            var dialog = new Dialog.ChangeFaction(faction)
            {
                Owner = MainWindow.Instance
            };

            dialog.ShowDialog();

            // broadcast data changes, if any
            if (dialog.DataChanged)
            {
                FactionList.Items.Refresh();
                SectionTab.DataChanged = true;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Handles the <see cref="Control.MouseDoubleClick"/> event for a <see
        /// cref="ListViewItem"/> of the "Faction" <see cref="ListView"/> on the <see
        /// cref="TablesTab"/> page.</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>OnFactionActivate</b> displays a <see cref="ShowFactions"/> dialog containing
        /// information on the selected item in the "Faction" list view, if any.</remarks>

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

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

            if (listItem == null)
            {
                return;
            }

            // show info dialog for faction
            var          item    = (RankingListItem)listItem.Content;
            FactionClass faction = item.Faction.FactionClass;
            var          dialog  = new ShowFactions(this._mapView, faction)
            {
                Owner = this
            };

            dialog.ShowDialog();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Raises and handles the <see cref="Window.Closing"/> event.</summary>
        /// <param name="args">
        /// A <see cref="CancelEventArgs"/> object containing event data.</param>
        /// <remarks><para>
        /// <b>OnClosing</b> raises the <see cref="Window.Closing"/> event by calling the base class
        /// implementation of <see cref="Window.OnClosing"/> with the specified <paramref
        /// name="args"/>.
        /// </para><para>
        /// If the event was not requested to <see cref="CancelEventArgs.Cancel"/>, <b>OnClosing</b>
        /// handles the <see cref="Window.Closing"/> event by clearing the <see cref="DataChanged"/>
        /// flag if the <see cref="Window.DialogResult"/> is not <c>true</c>, indicating that the
        /// user cancelled the dialog and wants to discard all changes.
        /// </para><para>
        /// Otherwise, <b>OnClosing</b> reads the control contents of this dialog into the current
        /// <see cref="FactionSection"/>.</para></remarks>

        protected override void OnClosing(CancelEventArgs args)
        {
            base.OnClosing(args);
            if (args.Cancel)
            {
                return;
            }

            // user cancelled dialog, ignore changes
            if (DialogResult != true)
            {
                DataChanged = false;
                return;
            }

            // store new faction colors
            FactionSection factions = MasterSection.Instance.Factions;

            foreach (FactionListItem item in FactionList.Items)
            {
                FactionClass faction = factions.Collection[item.Item1];
                faction.Color = item.Item2;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Handles the <see cref="ButtonBase.Click"/> event for the "Change ID" <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><para>
        /// <b>OnFactionId</b> displays a <see cref="Dialog.ChangeIdentifier"/> dialog for the first
        /// selected item in the "Faction" list view.
        /// </para><para>
        /// If the user made any changes, <b>OnFactionId</b> propagates them to the current <see
        /// cref="FactionSection"/> and sets the <see cref="SectionTabItem.DataChanged"/> flag.
        /// </para></remarks>

        private void OnFactionId(object sender, RoutedEventArgs args)
        {
            args.Handled = true;

            // retrieve selected faction, if any
            FactionClass faction = FactionList.SelectedItem as FactionClass;

            if (faction == null)
            {
                return;
            }

            // let user enter new faction ID
            var factions = MasterSection.Instance.Factions.Collection;
            var dialog   = new Dialog.ChangeIdentifier(faction.Id,
                                                       Global.Strings.TitleFactionIdChange, factions.ContainsKey, true);

            dialog.Owner = MainWindow.Instance;
            if (dialog.ShowDialog() != true)
            {
                return;
            }

            // retrieve new faction ID
            string id = String.Intern(dialog.Identifier);

            // change existing ID references
            if (!SectionTabItem.ProcessAllIdentifiers(factions, faction.Id, id))
            {
                return;
            }

            // broadcast data changes
            FactionList.Items.Refresh();
            SectionTab.DataChanged = true;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Raises and handles the <see cref="Window.Closing"/> event.</summary>
        /// <param name="args">
        /// A <see cref="CancelEventArgs"/> object containing event data.</param>
        /// <remarks><para>
        /// <b>OnClosing</b> raises the <see cref="Window.Closing"/> event by calling the base class
        /// implementation of <see cref="Window.OnClosing"/> with the specified <paramref
        /// name="args"/>.
        /// </para><para>
        /// If the event was not requested to <see cref="CancelEventArgs.Cancel"/>, <b>OnClosing</b>
        /// handles the <see cref="Window.Closing"/> event by clearing the <see cref="DataChanged"/>
        /// flag if the <see cref="Window.DialogResult"/> is not <c>true</c>, indicating that the
        /// user cancelled the dialog and wants to discard all changes.
        /// </para><para>
        /// Otherwise, <b>OnClosing</b> reads the control contents of this dialog into the current
        /// <see cref="AreaSection"/>.</para></remarks>

        protected override void OnClosing(CancelEventArgs args)
        {
            base.OnClosing(args);
            if (args.Cancel)
            {
                return;
            }

            // user cancelled dialog, ignore changes
            if (DialogResult != true)
            {
                DataChanged = false;
                return;
            }

            // read coordinates stored in Faction list view
            FactionSection factions = MasterSection.Instance.Factions;

            foreach (FactionListItem item in FactionList.Items)
            {
                FactionClass faction = factions.Collection[item.Item1];
                faction.HomeSite = item.Item3;
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Handles the <see cref="Selector.SelectionChanged"/> event for the "Faction" <see
        /// cref="ComboBox"/>.</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>OnFactionSelected</b> updates all dialog controls to reflect the selected item in the
        /// "Faction" combo box.</remarks>

        private void OnFactionSelected(object sender, SelectionChangedEventArgs args)
        {
            // retrieve selected faction, if any
            this._factionClass = FactionCombo.SelectedItem as FactionClass;

            // update dialog caption and color label
            if (this._factionClass == null)
            {
                Title = this._dialogTitle + Global.Strings.LabelNone;
                FactionColorInfo.Background = Background;
            }
            else
            {
                Title = this._dialogTitle + this._factionClass.Name;
                FactionColorInfo.Background = new SolidColorBrush(this._factionClass.Color);
            }

            // get surviving faction instance, if any
            this._worldState.Factions.TryGetValue(this._factionClass.Id, out this._faction);
            bool haveInstance = (this._faction != null);

            // show label indicating surviving or deleted faction
            if (haveInstance)
            {
                FactionLiveInfo.Visibility = Visibility.Visible;
                FactionDeadInfo.Visibility = Visibility.Collapsed;
            }
            else
            {
                FactionLiveInfo.Visibility = Visibility.Collapsed;
                FactionDeadInfo.Visibility = Visibility.Visible;
            }

            // GeneralTab: show informational text for faction
            if (this._factionClass == null)
            {
                FactionInfo.Clear();
            }
            else
            {
                FactionInfo.Text = String.Join(Environment.NewLine, this._factionClass.Paragraphs);
            }

            // ClassesTab: update Entity Class list view
            UpdateClasses();

            #region AssetsTab

            PointI home     = Site.InvalidLocation;
            Site   homeSite = null;

            // get current home site, if any
            if (this._factionClass != null)
            {
                home     = this._factionClass.HomeSite;
                homeSite = this._worldState.GetSite(home);
            }

            // update Home Site controls
            HomeSiteInfo.Text          = Site.Format(home);
            SelectHomeButton.IsEnabled = (homeSite != null);

            HomeOwnerInfo.Text = (homeSite == null ? "" :
                                  (homeSite.Owner == null ? Global.Strings.LabelOwnerNone :
                                   (homeSite.Owner == this._faction ?
                                    Global.Strings.LabelOwnerSame : homeSite.Owner.Name)));

            // should we enable the Show Upgrades button?
            bool haveUpgrades = (MasterSection.Instance.Entities.Upgrades.Count > 0);

            // enable buttons if faction instance available
            ShowUnitsButton.IsEnabled    = haveInstance;
            ShowUpgradesButton.IsEnabled = (haveInstance && haveUpgrades);
            ShowTerrainsButton.IsEnabled = haveInstance;

            if (haveInstance)
            {
                // show faction's share of available sites
                int owned = this._faction.Sites.Count;
                OwnedInfo.Text   = owned.ToString("N0", ApplicationInfo.Culture);
                UnownedInfo.Text = (this._siteCount - owned).ToString("N0", ApplicationInfo.Culture);
                double conquest = (this._siteCount > 0 ? owned / (double)this._siteCount : 0.0);
                ConquestInfo.Text = conquest.ToString("P1", ApplicationInfo.Culture);

                // show count of all faction possessions
                UnitsInfo.Text    = this._faction.Units.Count.ToString("N0", ApplicationInfo.Culture);
                TerrainsInfo.Text = this._faction.Terrains.Count.ToString("N0", ApplicationInfo.Culture);
                UpgradesInfo.Text = this._faction.Upgrades.Count.ToString("N0", ApplicationInfo.Culture);;
            }
            else
            {
                // faction owns none of the available sites
                OwnedInfo.Text    = "—";
                UnownedInfo.Text  = this._siteCount.ToString("N0", ApplicationInfo.Culture);
                ConquestInfo.Text = "—";

                // faction owns no possesssions
                UnitsInfo.Text    = "—";
                TerrainsInfo.Text = "—";
                UpgradesInfo.Text = "—";
            }

            #endregion
            #region VariablesTab

            // clear faction list views
            VariableList.Items.Clear();
            ModifierList.Items.Clear();
            this._modifiers = null;

            // show resources of selected faction, if any
            if (this._faction != null)
            {
                CreateResourceRows();
                CreateModifierRows();

                // compute modifiers for resetting and accumulating resources
                this._modifiers = this._faction.ComputeResourceModifiers(true);
                this._modifiers.AddRange(this._faction.ComputeResourceModifiers(false));

                // select first resource by default
                if (VariableList.Items.Count > 0)
                {
                    VariableList.SelectedIndex = 0;
                }
            }

            #endregion
            #region ConditionsTab

            // clear Condition list view
            ConditionList.Items.Clear();

            // show conditions of selected faction, if any
            if (this._faction != null)
            {
                CreateConditionRows();

                // select first condition by default
                if (ConditionList.Items.Count > 0)
                {
                    ConditionList.SelectedIndex = 0;
                }
            }

            #endregion
        }
        public async Task <List <UnitClass> > GetAllUnitsforFactionAsync(FactionClass faction)
        {
            List <UnitClass> factionUnits = new List <UnitClass>();

            using (HttpClient client = new HttpClient())
            {
                try
                {
                    string address = "http://31.132.4.108:5984/dropzoneunits/_design/" + faction.Name.ToLower() + "units/_view/allunits";

                    HttpResponseMessage response = await client.GetAsync(address);

                    response.EnsureSuccessStatusCode();
                    string responseBody = await response.Content.ReadAsStringAsync();


                    var units = UnitQT.Units.FromJson(responseBody);

                    foreach (var row in units.Rows)
                    {
                        UnitClass newUnit = new UnitClass();
                        newUnit.SetCouchID(row.Key.KeyId);
                        newUnit.SetCouchRev(row.Key.Rev);
                        newUnit.Id     = row.Key.Id;
                        newUnit.Name   = row.Key.Name;
                        newUnit.Armour = (int)row.Key.Armour;
                        newUnit.Move   = (int)row.Key.Move;
                        foreach (string cm in row.Key.CounterMeasures)
                        {
                            newUnit.AddCM(cm.ToString());
                        }
                        newUnit.DamagePoints = (int)row.Key.DamagePoints;
                        newUnit.Points       = (int)row.Key.Points;
                        newUnit.Type         = row.Key.Type;
                        newUnit.Category     = row.Key.Category;
                        newUnit.Cqb          = (decimal)row.Key.Cqb;
                        newUnit.Fortitude    = (int)row.Key.Fortitude;
                        foreach (string ssc in row.Key.SquadSizeCoherancy)
                        {
                            newUnit.AddSC(ssc);
                        }
                        newUnit.LandingZone = row.Key.LandingZone;
                        foreach (string to in row.Key.TransportOptions)
                        {
                            newUnit.AddTransport(to);
                        }
                        foreach (string exRule in row.Key.ExtraRules)
                        {
                            newUnit.AddExtraRule(exRule);
                        }
                        foreach (string special in row.Key.Special)
                        {
                            newUnit.AddSpecialRule(special);
                        }
                        foreach (UnitQT.Weapon weapon in row.Key.Weapons)
                        {
                            Weapon newWeapon = new Weapon();
                            newWeapon.Name           = weapon.Name;
                            newWeapon.Energy         = (int)weapon.Energy;
                            newWeapon.Shots          = (int)weapon.Shots;
                            newWeapon.Accuracy       = (int)weapon.Accuracy;
                            newWeapon.RangeFull      = weapon.RangeFull;
                            newWeapon.RangeCountered = weapon.RangeCountered;
                            newWeapon.MoveFire       = weapon.MoveFire;
                            newWeapon.Arc            = weapon.Arc;
                            newWeapon.Optional       = weapon.Optional;
                            newWeapon.OptionalCost   = (int)weapon.OptionalCost;
                            foreach (string special in row.Key.Special)
                            {
                                newWeapon.AddRule(special);
                            }
                            newUnit.AddWeapon(newWeapon);
                        }
                        newUnit.Faction = row.Key.Faction;
                        factionUnits.Add(newUnit);
                    }
                    Console.WriteLine(factionUnits.Count);
                }

                catch (HttpRequestException e)
                {
                    Console.WriteLine("Exception " + e + " caught");
                }
            }

            return(factionUnits);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Handles the message event represented by the specified <see cref="Instruction"/>.
        /// </summary>
        /// <param name="instruction">
        /// The <see cref="MessageInstruction"/> that represents the message event to handle.
        /// </param>
        /// <param name="textBox">
        /// The <see cref="TextBoxBase"/> control to which to append the message.</param>
        /// <param name="showDialog">
        /// <c>true</c> to display a dialog if requested by the specified <paramref
        /// name="instruction"/>; otherwise, <c>false</c>.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="instruction"/> or <paramref name="textBox"/> is a null reference.
        /// </exception>
        /// <remarks><para>
        /// <b>ShowMessageEvent</b> creates a text message from the data of the specified <paramref
        /// name="instruction"/> and appends it to the specified <paramref name="textBox"/> control.
        /// </para><para>
        /// If <paramref name="instruction"/> is of type <see cref="ShowMessageDialogInstruction"/>
        /// and <paramref name="showDialog"/> is <c>true</c>, <b>ShowMessageEvent</b> also shows the
        /// message text in a <see cref="Dialog.ShowEvent"/> dialog.</para></remarks>

        public static void ShowMessageEvent(MessageInstruction instruction,
                                            TextBoxBase textBox, bool showDialog)
        {
            if (instruction == null)
            {
                ThrowHelper.ThrowArgumentNullException("instruction");
            }
            if (textBox == null)
            {
                ThrowHelper.ThrowArgumentNullException("textBox");
            }

            // show message in a modal dialog?
            bool dialog = (instruction is ShowMessageDialogInstruction);

            // get mandatory summary text
            string summary = StringUtility.Validate(
                instruction.Text, Global.Strings.LabelEventUnknown);

            // get details text (mandatory for dialog)
            string details = instruction.Details;

            if (dialog)
            {
                details = StringUtility.Validate(details, Global.Strings.InfoEventUnknown);
            }

            // get optional faction and entity names
            FactionClass faction = instruction.Faction;

            string[] names = instruction.Names.ToArray();

            // create caption from faction and summary
            StringBuilder caption = new StringBuilder();

            if (faction != null)
            {
                caption.Append(faction.Name);
                caption.Append(": ");
            }
            caption.Append(summary);

            // create message from details and names
            StringBuilder message = new StringBuilder();

            if (details != null)
            {
                message.Append(details);
            }

            // append specified names to message
            if (names != null)
            {
                foreach (string name in names)
                {
                    if (message.Length > 0)
                    {
                        message.Append(Environment.NewLine);
                    }
                    message.Append('\t');
                    message.Append(name);
                }
            }

            // append message to event view text
            textBox.AppendText("– "); // en dash
            textBox.AppendText(caption.ToString());
            textBox.AppendText(Environment.NewLine);

            if (message.Length > 0)
            {
                textBox.AppendText(message.ToString());
                textBox.AppendText(Environment.NewLine);
            }

            // show message as dialog if desired
            if (dialog && showDialog)
            {
                // temporarily restore normal cursor if in wait mode
                var cursor = Mouse.OverrideCursor;
                Mouse.OverrideCursor = null;
                Dialog.ShowEvent.Show(MainWindow.Instance, message.ToString(), caption.ToString());
                Mouse.OverrideCursor = cursor;
            }
        }