Пример #1
0
        private async void treQualities_AfterSelect(object sender, TreeViewEventArgs e)
        {
            string strSource         = string.Empty;
            string strPage           = string.Empty;
            string strSourceIDString = await treQualities.DoThreadSafeFuncAsync(x => x.SelectedNode?.Tag.ToString());

            if (!string.IsNullOrEmpty(strSourceIDString))
            {
                XmlNode objXmlQuality = _objXmlDocument.SelectSingleNode("/chummer/qualities/quality[id = " + strSourceIDString.CleanXPath() + ']');
                if (objXmlQuality != null)
                {
                    strSource = objXmlQuality["source"]?.InnerText ?? string.Empty;
                    strPage   = objXmlQuality["altpage"]?.InnerText ?? objXmlQuality["page"]?.InnerText ?? string.Empty;
                }
            }

            if (!string.IsNullOrEmpty(strSource) && !string.IsNullOrEmpty(strPage))
            {
                SourceString objSource = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language,
                                                                                 GlobalSettings.CultureInfo, _objCharacter);

                await objSource.SetControlAsync(lblSource);

                await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = true);
            }
            else
            {
                lblSource.Text = string.Empty;
                await lblSource.SetToolTipAsync(string.Empty);

                await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = false);
            }
        }
Пример #2
0
        private async void lstMetamagic_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnLoading)
            {
                return;
            }

            string strSelectedId = lstMetamagic.SelectedValue?.ToString();

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                // Retireve the information for the selected piece of Cyberware.
                XPathNavigator objXmlMetamagic = _objXmlDocument.SelectSingleNode(_strRootXPath + "[id = " + strSelectedId.CleanXPath() + ']');

                if (objXmlMetamagic != null)
                {
                    string       strSource       = objXmlMetamagic.SelectSingleNode("source")?.Value;
                    string       strPage         = (await objXmlMetamagic.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? objXmlMetamagic.SelectSingleNode("page")?.Value;
                    SourceString objSourceString = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter);

                    await objSourceString.SetControlAsync(lblSource);

                    lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
                    tlpRight.Visible       = true;
                }
                else
                {
                    tlpRight.Visible = false;
                }
            }
            else
            {
                tlpRight.Visible = false;
            }
        }
Пример #3
0
        private async void lstPowers_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnLoading)
            {
                return;
            }

            string strSelectedId = await lstPowers.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString());

            XPathNavigator objXmlPower = null;

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                objXmlPower = _xmlBasePowerDataNode.SelectSingleNode("powers/power[id = " + strSelectedId.CleanXPath() + ']');
            }

            if (objXmlPower != null)
            {
                string strSpace = await LanguageManager.GetStringAsync("String_Space");

                // Display the information for the selected Power.
                string strPowerPointsText = objXmlPower.SelectSingleNode("points")?.Value ?? string.Empty;
                if (objXmlPower.SelectSingleNode("levels")?.Value == bool.TrueString)
                {
                    strPowerPointsText += strSpace + '/' + strSpace + await LanguageManager.GetStringAsync("Label_Power_Level");
                }
                string strExtrPointCost = objXmlPower.SelectSingleNode("extrapointcost")?.Value;
                if (!string.IsNullOrEmpty(strExtrPointCost))
                {
                    strPowerPointsText = strExtrPointCost + strSpace + '+' + strSpace + strPowerPointsText;
                }
                await lblPowerPoints.DoThreadSafeAsync(x => x.Text = strPowerPointsText);

                string strSource = objXmlPower.SelectSingleNode("source")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown");

                string strPage = (await objXmlPower.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? objXmlPower.SelectSingleNode("page")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown");

                SourceString objSource = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language,
                                                                                 GlobalSettings.CultureInfo, _objCharacter);

                await objSource.SetControlAsync(lblSource);

                await lblPowerPointsLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strPowerPointsText));

                await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(objSource.ToString()));

                await tlpRight.DoThreadSafeAsync(x => x.Visible = true);
            }
            else
            {
                await tlpRight.DoThreadSafeAsync(x => x.Visible = false);
            }
        }
Пример #4
0
        private async void lstTechniques_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnLoading)
            {
                return;
            }

            string strSelectedId = await lstTechniques.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString());

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                XPathNavigator xmlTechnique = _xmlBaseChummerNode.SelectSingleNode("/chummer/techniques/technique[id = " + strSelectedId.CleanXPath() + ']');

                if (xmlTechnique != null)
                {
                    string strSource = xmlTechnique.SelectSingleNode("source")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown");

                    string strPage = (await xmlTechnique.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? xmlTechnique.SelectSingleNode("page")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown");

                    SourceString objSourceString = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter);

                    await objSourceString.SetControlAsync(lblSource);

                    string strSourceText = lblSource.ToString();
                    await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strSourceText));

                    await tlpRight.DoThreadSafeAsync(x => x.Visible = true);
                }
                else
                {
                    await tlpRight.DoThreadSafeAsync(x => x.Visible = false);
                }
            }
            else
            {
                await tlpRight.DoThreadSafeAsync(x => x.Visible = false);
            }
        }
Пример #5
0
        private async void lstArt_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnLoading)
            {
                return;
            }

            string strSelected = await lstArt.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString());

            if (string.IsNullOrEmpty(strSelected))
            {
                await tlpRight.DoThreadSafeAsync(x => x.Visible = false);

                return;
            }

            // Retrieve the information for the selected art
            XPathNavigator objXmlMetamagic = _objXmlDocument.SelectSingleNode(_strBaseXPath + "[id = " + strSelected.CleanXPath() + ']');

            if (objXmlMetamagic == null)
            {
                await tlpRight.DoThreadSafeAsync(x => x.Visible = false);

                return;
            }

            string strSource = objXmlMetamagic.SelectSingleNode("source")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown");

            string strPage = (await objXmlMetamagic.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? objXmlMetamagic.SelectSingleNode("page")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown");

            SourceString objSource = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language,
                                                                             GlobalSettings.CultureInfo, _objCharacter);

            await objSource.SetControlAsync(lblSource);

            await tlpRight.DoThreadSafeAsync(x => x.Visible = true);
        }
Пример #6
0
        private async void lstQualities_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnLoading)
            {
                return;
            }

            _blnLoading = true;

            try
            {
                XPathNavigator xmlQuality         = null;
                string         strSelectedQuality = await lstQualities.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString());

                if (!string.IsNullOrEmpty(strSelectedQuality))
                {
                    xmlQuality = _xmlBaseQualityDataNode.SelectSingleNode(
                        "qualities/quality[id = " + strSelectedQuality.CleanXPath() + ']');
                }

                if (xmlQuality != null)
                {
                    await nudRating.DoThreadSafeAsync(x => x.ValueAsInt = x.MinimumAsInt);

                    int intMaxRating = int.MaxValue;
                    if (xmlQuality.TryGetInt32FieldQuickly("limit", ref intMaxRating) &&
                        xmlQuality.SelectSingleNode("nolevels") == null)
                    {
                        await lblRatingNALabel.DoThreadSafeAsync(x => x.Visible = false);

                        await nudRating.DoThreadSafeAsync(x =>
                        {
                            x.MaximumAsInt = intMaxRating;
                            x.Visible      = true;
                        });
                    }
                    else
                    {
                        await lblRatingNALabel.DoThreadSafeAsync(x => x.Visible = true);

                        await nudRating.DoThreadSafeAsync(x =>
                        {
                            x.MaximumAsInt = 1;
                            x.ValueAsInt   = 1;
                            x.Visible      = false;
                        });
                    }

                    await UpdateCostLabel(xmlQuality);

                    string strSource = xmlQuality.SelectSingleNode("source")?.Value
                                       ?? await LanguageManager.GetStringAsync("String_Unknown");

                    string strPage = (await xmlQuality.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value
                                     ?? xmlQuality.SelectSingleNode("page")?.Value
                                     ?? await LanguageManager.GetStringAsync("String_Unknown");

                    SourceString objSource = await SourceString.GetSourceStringAsync(
                        strSource, strPage, GlobalSettings.Language,
                        GlobalSettings.CultureInfo, _objCharacter);

                    await objSource.SetControlAsync(lblSource);

                    await lblSourceLabel.DoThreadSafeAsync(
                        x => x.Visible = !string.IsNullOrEmpty(objSource.ToString()));

                    await tlpRight.DoThreadSafeAsync(x => x.Visible = true);
                }
                else
                {
                    await tlpRight.DoThreadSafeAsync(x => x.Visible = false);
                }
            }
            finally
            {
                _blnLoading = false;
            }
        }
Пример #7
0
        /// <summary>
        /// Refresh the information for the selected Vehicle.
        /// </summary>
        private async ValueTask UpdateSelectedVehicle()
        {
            if (_blnLoading)
            {
                return;
            }

            string strSelectedId = await lstVehicle.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString());

            XPathNavigator objXmlVehicle = null;

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                // Retrieve the information for the selected Vehicle.
                objXmlVehicle = _xmlBaseVehicleDataNode.SelectSingleNode("vehicles/vehicle[id = " + strSelectedId.CleanXPath() + ']');
            }
            if (objXmlVehicle == null)
            {
                await tlpRight.DoThreadSafeAsync(x => x.Visible = false);

                return;
            }

            await this.DoThreadSafeAsync(x => x.SuspendLayout());

            try
            {
                string strHandling = objXmlVehicle.SelectSingleNode("handling")?.Value;
                await lblVehicleHandling.DoThreadSafeAsync(x => x.Text = strHandling);

                string strAccel = objXmlVehicle.SelectSingleNode("accel")?.Value;
                await lblVehicleAccel.DoThreadSafeAsync(x => x.Text = strAccel);

                string strSpeed = objXmlVehicle.SelectSingleNode("speed")?.Value;
                await lblVehicleSpeed.DoThreadSafeAsync(x => x.Text = strSpeed);

                string strPilot = objXmlVehicle.SelectSingleNode("pilot")?.Value;
                await lblVehiclePilot.DoThreadSafeAsync(x => x.Text = strPilot);

                string strBody = objXmlVehicle.SelectSingleNode("body")?.Value;
                await lblVehicleBody.DoThreadSafeAsync(x => x.Text = strBody);

                string strArmor = objXmlVehicle.SelectSingleNode("armor")?.Value;
                await lblVehicleArmor.DoThreadSafeAsync(x => x.Text = strArmor);

                string strSeats = objXmlVehicle.SelectSingleNode("seats")?.Value;
                await lblVehicleSeats.DoThreadSafeAsync(x => x.Text = strSeats);

                string strSensor = objXmlVehicle.SelectSingleNode("sensor")?.Value;
                await lblVehicleSensor.DoThreadSafeAsync(x => x.Text = strSensor);

                await lblVehicleHandlingLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strHandling));

                await lblVehicleAccelLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strAccel));

                await lblVehicleSpeedLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strSpeed));

                await lblVehiclePilotLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strPilot));

                await lblVehicleBodyLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strBody));

                await lblVehicleArmorLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strArmor));

                await lblVehicleSeatsLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strSeats));

                await lblVehicleSensorLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strSensor));

                AvailabilityValue objTotalAvail
                    = new AvailabilityValue(0, objXmlVehicle.SelectSingleNode("avail")?.Value,
                                            await chkUsedVehicle.DoThreadSafeFuncAsync(x => x.Checked) ? -4 : 0);
                string strAvail = objTotalAvail.ToString();
                await lblVehicleAvail.DoThreadSafeAsync(x => x.Text = strAvail);

                await lblVehicleAvailLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strAvail));

                bool blnCanBlackMarketDiscount
                    = _setBlackMarketMaps.Contains(objXmlVehicle.SelectSingleNode("category")?.Value);
                await chkBlackMarketDiscount.DoThreadSafeAsync(x =>
                {
                    x.Enabled = blnCanBlackMarketDiscount;
                    if (!x.Checked)
                    {
                        x.Checked = GlobalSettings.AssumeBlackMarket && blnCanBlackMarketDiscount;
                    }
                    else if (!blnCanBlackMarketDiscount)
                    {
                        //Prevent chkBlackMarketDiscount from being checked if the category doesn't match.
                        x.Checked = false;
                    }
                });

                await UpdateSelectedVehicleCost();

                string strSource = objXmlVehicle.SelectSingleNode("source")?.Value
                                   ?? await LanguageManager.GetStringAsync("String_Unknown");

                string strPage = (await objXmlVehicle.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value
                                 ?? objXmlVehicle.SelectSingleNode("page")?.Value
                                 ?? await LanguageManager.GetStringAsync("String_Unknown");

                SourceString objSource = await SourceString.GetSourceStringAsync(
                    strSource, strPage, GlobalSettings.Language,
                    GlobalSettings.CultureInfo, _objCharacter);

                await objSource.SetControlAsync(lblSource);

                await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(objSource.ToString()));

                await tlpRight.DoThreadSafeAsync(x => x.Visible = true);
            }
            finally
            {
                await this.DoThreadSafeAsync(x => x.ResumeLayout());
            }
        }
Пример #8
0
        private async void lstMartialArts_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnLoading)
            {
                return;
            }

            string strSelectedId = lstMartialArts.SelectedValue?.ToString();

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                // Populate the Martial Arts list.
                XPathNavigator objXmlArt = _xmlBaseMartialArtsNode.SelectSingleNode("martialart[id = " + strSelectedId.CleanXPath() + ']');

                if (objXmlArt != null)
                {
                    lblKarmaCost.Text         = (await objXmlArt.SelectSingleNodeAndCacheExpressionAsync("cost"))?.Value ?? 7.ToString(GlobalSettings.CultureInfo);
                    lblKarmaCostLabel.Visible = !string.IsNullOrEmpty(lblKarmaCost.Text);

                    using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool, out StringBuilder sbdTechniques))
                    {
                        foreach (XPathNavigator xmlMartialArtsTechnique in await objXmlArt.SelectAndCacheExpressionAsync(
                                     "techniques/technique"))
                        {
                            string strLoopTechniqueName
                                = (await xmlMartialArtsTechnique.SelectSingleNodeAndCacheExpressionAsync("name"))?.Value
                                  ?? string.Empty;
                            if (!string.IsNullOrEmpty(strLoopTechniqueName))
                            {
                                XPathNavigator xmlTechniqueNode
                                    = _xmlBaseMartialArtsTechniquesNode.SelectSingleNode(
                                          "technique[name = " + strLoopTechniqueName.CleanXPath() + " and ("
                                          + _objCharacter.Settings.BookXPath() + ")]");
                                if (xmlTechniqueNode != null)
                                {
                                    if (sbdTechniques.Length > 0)
                                    {
                                        sbdTechniques.AppendLine(',');
                                    }
                                    sbdTechniques.Append(
                                        !GlobalSettings.Language.Equals(GlobalSettings.DefaultLanguage,
                                                                        StringComparison.OrdinalIgnoreCase)
                                            ? (await xmlTechniqueNode.SelectSingleNodeAndCacheExpressionAsync("translate"))?.Value
                                        ?? strLoopTechniqueName
                                            : strLoopTechniqueName);
                                }
                            }
                        }

                        lblIncludedTechniques.Text = sbdTechniques.ToString();
                    }

                    gpbIncludedTechniques.Visible = !string.IsNullOrEmpty(lblIncludedTechniques.Text);

                    string strSource = (await objXmlArt.SelectSingleNodeAndCacheExpressionAsync("source"))?.Value ?? await LanguageManager.GetStringAsync("String_Unknown");

                    string strPage = (await objXmlArt.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? (await objXmlArt.SelectSingleNodeAndCacheExpressionAsync("page"))?.Value ?? await LanguageManager.GetStringAsync("String_Unknown");

                    SourceString objSourceString = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter);

                    await objSourceString.SetControlAsync(lblSource);

                    lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
                    tlpRight.Visible       = true;
                }
                else
                {
                    tlpRight.Visible = false;
                    gpbIncludedTechniques.Visible = false;
                }
            }
            else
            {
                tlpRight.Visible = false;
                gpbIncludedTechniques.Visible = false;
            }
        }
Пример #9
0
        private async void lstMentor_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnSkipRefresh)
            {
                return;
            }
            SuspendLayout();
            try
            {
                XPathNavigator objXmlMentor = null;
                if (lstMentor.SelectedIndex >= 0)
                {
                    string strSelectedId = lstMentor.SelectedValue?.ToString();
                    if (!string.IsNullOrEmpty(strSelectedId))
                    {
                        objXmlMentor =
                            _xmlBaseMentorSpiritDataNode.SelectSingleNode("mentors/mentor[id = " +
                                                                          strSelectedId.CleanXPath() + ']');
                    }
                }

                if (objXmlMentor != null)
                {
                    // If the Mentor offers a choice of bonuses, build the list and let the user select one.
                    XPathNavigator xmlChoices = await objXmlMentor.SelectSingleNodeAndCacheExpressionAsync("choices");

                    if (xmlChoices != null)
                    {
                        using (new FetchSafelyFromPool <List <ListItem> >(Utils.ListItemListPool, out List <ListItem> lstChoice1))
                            using (new FetchSafelyFromPool <List <ListItem> >(Utils.ListItemListPool,
                                                                              out List <ListItem> lstChoice2))
                            {
                                foreach (XPathNavigator objChoice in await xmlChoices.SelectAndCacheExpressionAsync("choice"))
                                {
                                    string strName = (await objChoice.SelectSingleNodeAndCacheExpressionAsync("name"))?.Value
                                                     ?? string.Empty;
                                    if ((_objCharacter.AdeptEnabled ||
                                         !strName.StartsWith("Adept:", StringComparison.Ordinal)) &&
                                        (_objCharacter.MagicianEnabled ||
                                         !strName.StartsWith("Magician:", StringComparison.Ordinal)))
                                    {
                                        if (objChoice.SelectSingleNode("@set")?.Value == "2")
                                        {
                                            lstChoice2.Add(new ListItem(strName,
                                                                        (await objChoice.SelectSingleNodeAndCacheExpressionAsync(
                                                                             "translate"))?.Value ?? strName));
                                        }
                                        else
                                        {
                                            lstChoice1.Add(new ListItem(strName,
                                                                        (await objChoice.SelectSingleNodeAndCacheExpressionAsync(
                                                                             "translate"))?.Value ?? strName));
                                        }
                                    }
                                }

                                //If there is only a single option, show it as a label.
                                //If there are more, show the drop down menu
                                if (lstChoice1.Count > 0)
                                {
                                    await cboChoice1.PopulateWithListItemsAsync(lstChoice1);
                                }
                                cboChoice1.Visible    = lstChoice1.Count > 1;
                                lblBonusText1.Visible = lstChoice1.Count == 1;
                                if (lstChoice1.Count == 1)
                                {
                                    lblBonusText1.Text = lstChoice1[0].Name;
                                }
                                if (lstChoice2.Count > 0)
                                {
                                    await cboChoice2.PopulateWithListItemsAsync(lstChoice2);
                                }
                                cboChoice2.Visible    = lstChoice2.Count > 1;
                                lblBonusText2.Visible = lstChoice2.Count == 1;
                                if (lstChoice2.Count == 1)
                                {
                                    lblBonusText2.Text = lstChoice2[0].Name;
                                }
                            }
                    }
                    else
                    {
                        cboChoice1.Visible    = false;
                        cboChoice2.Visible    = false;
                        lblBonusText1.Visible = false;
                        lblBonusText2.Visible = false;
                    }

                    lblChoice1.Visible = cboChoice1.Visible;
                    lblChoice2.Visible = cboChoice2.Visible;
                    lblBonus1.Visible  = lblBonusText1.Visible;
                    lblBonus2.Visible  = lblBonusText2.Visible;

                    // Get the information for the selected Mentor.
                    lblAdvantage.Text = objXmlMentor.SelectSingleNode("altadvantage")?.Value ??
                                        objXmlMentor.SelectSingleNode("advantage")?.Value ??
                                        await LanguageManager.GetStringAsync("String_Unknown");

                    lblAdvantageLabel.Visible = !string.IsNullOrEmpty(lblAdvantage.Text);
                    lblDisadvantage.Text      = objXmlMentor.SelectSingleNode("altdisadvantage")?.Value ??
                                                objXmlMentor.SelectSingleNode("disadvantage")?.Value ??
                                                await LanguageManager.GetStringAsync("String_Unknown");

                    lblDisadvantageLabel.Visible = !string.IsNullOrEmpty(lblDisadvantage.Text);

                    string strSource = objXmlMentor.SelectSingleNode("source")?.Value ??
                                       await LanguageManager.GetStringAsync("String_Unknown");

                    string strPage = (await objXmlMentor.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ??
                                     objXmlMentor.SelectSingleNode("page")?.Value ??
                                     await LanguageManager.GetStringAsync("String_Unknown");

                    SourceString objSourceString = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language,
                                                                                           GlobalSettings.CultureInfo, _objCharacter);

                    await objSourceString.SetControlAsync(lblSource);

                    lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
                    cmdOK.Enabled          = true;
                    tlpRight.Visible       = true;
                    tlpBottomRight.Visible = true;
                }
                else
                {
                    tlpRight.Visible       = false;
                    tlpBottomRight.Visible = false;
                    cmdOK.Enabled          = false;
                }
            }
            finally
            {
                ResumeLayout();
            }
        }
Пример #10
0
        /// <summary>
        /// Calculate the LP value for the selected items.
        /// </summary>
        private async ValueTask CalculateValues(bool blnIncludePercentage = true)
        {
            if (_blnSkipRefresh)
            {
                return;
            }

            decimal decRoommates = await nudRoommates.DoThreadSafeFuncAsync(x => x.Value);

            decimal decBaseCost      = 0;
            decimal decCost          = 0;
            decimal decMod           = 0;
            string  strBaseLifestyle = string.Empty;
            // Get the base cost of the lifestyle
            string strSelectedId = await cboLifestyle.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString());

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                XmlNode objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/lifestyles/lifestyle[id = " + strSelectedId.CleanXPath() + ']');

                if (objXmlAspect != null)
                {
                    objXmlAspect.TryGetStringFieldQuickly("name", ref strBaseLifestyle);
                    decimal decTemp = 0;
                    if (objXmlAspect.TryGetDecFieldQuickly("cost", ref decTemp))
                    {
                        decBaseCost += decTemp;
                    }
                    string strSource = objXmlAspect["source"]?.InnerText;
                    string strPage   = objXmlAspect["altpage"]?.InnerText ?? objXmlAspect["page"]?.InnerText;
                    if (!string.IsNullOrEmpty(strSource) && !string.IsNullOrEmpty(strPage))
                    {
                        SourceString objSource = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language,
                                                                                         GlobalSettings.CultureInfo, _objCharacter);

                        await objSource.SetControlAsync(lblSource);

                        await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = true);
                    }
                    else
                    {
                        lblSource.Text = string.Empty;
                        await lblSource.SetToolTipAsync(string.Empty);

                        await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = false);
                    }

                    // Add the flat costs from qualities
                    foreach (TreeNode objNode in await treQualities.DoThreadSafeFuncAsync(x => x.Nodes))
                    {
                        if (objNode.Checked)
                        {
                            string strCost = _objXmlDocument.SelectSingleNode("/chummer/qualities/quality[id = " + objNode.Tag.ToString().CleanXPath() + "]/cost")?.InnerText;
                            if (!string.IsNullOrEmpty(strCost))
                            {
                                object objProcess = CommonFunctions.EvaluateInvariantXPath(strCost, out bool blnIsSuccess);
                                if (blnIsSuccess)
                                {
                                    decCost += Convert.ToDecimal(objProcess, GlobalSettings.InvariantCultureInfo);
                                }
                            }
                        }
                    }

                    decimal decBaseMultiplier = 0;
                    if (blnIncludePercentage)
                    {
                        // Add the modifiers from qualities
                        foreach (TreeNode objNode in await treQualities.DoThreadSafeFuncAsync(x => x.Nodes))
                        {
                            if (!objNode.Checked)
                            {
                                continue;
                            }
                            objXmlAspect = _objXmlDocument.SelectSingleNode("/chummer/qualities/quality[id = " + objNode.Tag.ToString().CleanXPath() + ']');
                            if (objXmlAspect == null)
                            {
                                continue;
                            }
                            if (objXmlAspect.TryGetDecFieldQuickly("multiplier", ref decTemp))
                            {
                                decMod += decTemp / 100.0m;
                            }
                            if (objXmlAspect.TryGetDecFieldQuickly("multiplierbaseonly", ref decTemp))
                            {
                                decBaseMultiplier += decTemp / 100.0m;
                            }
                        }

                        // Check for modifiers in the improvements
                        decMod += await ImprovementManager.ValueOfAsync(_objCharacter, Improvement.ImprovementType.LifestyleCost) / 100.0m;
                    }

                    decBaseCost += decBaseCost * decBaseMultiplier;
                    if (decRoommates > 0)
                    {
                        decBaseCost *= 1.0m + Math.Max(decRoommates / 10.0m, 0);
                    }
                }
                else
                {
                    await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = false);
                }
            }
            else
            {
                await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = false);
            }

            decimal decNuyen = decBaseCost + decBaseCost * decMod + decCost;

            await lblCost.DoThreadSafeAsync(x => x.Text = decNuyen.ToString(_objCharacter.Settings.NuyenFormat, GlobalSettings.CultureInfo) + '¥');

            decimal decPercentage = await nudPercentage.DoThreadSafeFuncAsync(x => x.Value);

            if (decPercentage != 100 || decRoommates != 0 && !await chkPrimaryTenant.DoThreadSafeFuncAsync(x => x.Checked))
            {
                decimal decDiscount = decNuyen;
                decDiscount *= decPercentage / 100;
                if (decRoommates != 0)
                {
                    decDiscount /= decRoommates;
                }

                string strSpace = await LanguageManager.GetStringAsync("String_Space");

                await lblCost.DoThreadSafeAsync(x => x.Text += strSpace + '(' + decDiscount.ToString(_objCharacter.Settings.NuyenFormat, GlobalSettings.CultureInfo) + "¥)");
            }

            await lblCost.DoThreadSafeFuncAsync(x => x.Text)
            .ContinueWith(
                y => lblCostLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(y.Result)))
            .Unwrap();

            // Characters with the Trust Fund Quality can have the lifestyle discounted.
            if (Lifestyle.StaticIsTrustFundEligible(_objCharacter, strBaseLifestyle))
            {
                bool blnTrustFund = _objSourceLifestyle?.TrustFund ?? !await _objCharacter.Lifestyles.AnyAsync(x => x.TrustFund);

                await chkTrustFund.DoThreadSafeAsync(x =>
                {
                    x.Visible = true;
                    x.Checked = blnTrustFund;
                });
            }
            else
            {
                await chkTrustFund.DoThreadSafeAsync(x =>
                {
                    x.Checked = false;
                    x.Visible = false;
                });
            }
        }
Пример #11
0
        private async ValueTask UpdateGearInfo(bool blnUpdateMountComboBoxes = true)
        {
            if (_blnLoading)
            {
                return;
            }

            XPathNavigator xmlAccessory  = null;
            string         strSelectedId = lstAccessory.SelectedValue?.ToString();

            // Retrieve the information for the selected Accessory.
            if (!string.IsNullOrEmpty(strSelectedId))
            {
                xmlAccessory = _xmlBaseChummerNode.SelectSingleNode("accessories/accessory[id = " + strSelectedId.CleanXPath() + ']');
            }
            if (xmlAccessory == null)
            {
                tlpRight.Visible = false;
                return;
            }

            string strRC = xmlAccessory.SelectSingleNode("rc")?.Value;

            if (!string.IsNullOrEmpty(strRC))
            {
                lblRC.Visible      = true;
                lblRCLabel.Visible = true;
                lblRC.Text         = strRC;
            }
            else
            {
                lblRC.Visible      = false;
                lblRCLabel.Visible = false;
            }
            if (int.TryParse(xmlAccessory.SelectSingleNode("rating")?.Value, out int intMaxRating) && intMaxRating > 0)
            {
                nudRating.Maximum = intMaxRating;
                if (chkHideOverAvailLimit.Checked)
                {
                    while (nudRating.Maximum > nudRating.Minimum && !xmlAccessory.CheckAvailRestriction(_objCharacter, nudRating.MaximumAsInt))
                    {
                        --nudRating.Maximum;
                    }
                }
                if (chkShowOnlyAffordItems.Checked && !chkFreeItem.Checked)
                {
                    decimal decCostMultiplier = 1 + (nudMarkup.Value / 100.0m);
                    if (_setBlackMarketMaps.Contains(xmlAccessory.SelectSingleNode("category")?.Value))
                    {
                        decCostMultiplier *= 0.9m;
                    }
                    while (nudRating.Maximum > nudRating.Minimum && !xmlAccessory.CheckNuyenRestriction(_objCharacter.Nuyen, decCostMultiplier, nudRating.MaximumAsInt))
                    {
                        --nudRating.Maximum;
                    }
                }
                nudRating.Enabled        = nudRating.Maximum != nudRating.Minimum;
                nudRating.Visible        = true;
                lblRatingLabel.Visible   = true;
                lblRatingNALabel.Visible = false;
            }
            else
            {
                lblRatingNALabel.Visible = true;
                nudRating.Enabled        = false;
                nudRating.Visible        = false;
                lblRatingLabel.Visible   = true;
            }

            if (blnUpdateMountComboBoxes)
            {
                string        strDataMounts = xmlAccessory.SelectSingleNode("mount")?.Value;
                List <string> strMounts     = new List <string>(1);
                if (!string.IsNullOrEmpty(strDataMounts))
                {
                    strMounts.AddRange(strDataMounts.SplitNoAlloc('/', StringSplitOptions.RemoveEmptyEntries));
                }

                strMounts.Add("None");

                List <string> strAllowed = new List <string>(_lstAllowedMounts)
                {
                    "None"
                };
                cboMount.Visible = true;
                cboMount.Items.Clear();
                foreach (string strCurrentMount in strMounts)
                {
                    if (!string.IsNullOrEmpty(strCurrentMount))
                    {
                        foreach (string strAllowedMount in strAllowed)
                        {
                            if (strCurrentMount == strAllowedMount)
                            {
                                cboMount.Items.Add(strCurrentMount);
                            }
                        }
                    }
                }

                cboMount.Enabled       = cboMount.Items.Count > 1;
                cboMount.SelectedIndex = 0;
                lblMountLabel.Visible  = true;

                List <string> strExtraMounts = new List <string>(1);
                string        strExtraMount  = xmlAccessory.SelectSingleNode("extramount")?.Value;
                if (!string.IsNullOrEmpty(strExtraMount))
                {
                    foreach (string strItem in strExtraMount.SplitNoAlloc('/', StringSplitOptions.RemoveEmptyEntries))
                    {
                        strExtraMounts.Add(strItem);
                    }
                }

                strExtraMounts.Add("None");

                cboExtraMount.Items.Clear();
                foreach (string strCurrentMount in strExtraMounts)
                {
                    if (!string.IsNullOrEmpty(strCurrentMount))
                    {
                        foreach (string strAllowedMount in strAllowed)
                        {
                            if (strCurrentMount == strAllowedMount)
                            {
                                cboExtraMount.Items.Add(strCurrentMount);
                            }
                        }
                    }
                }

                cboExtraMount.Enabled       = cboExtraMount.Items.Count > 1;
                cboExtraMount.SelectedIndex = 0;
                if (cboMount.SelectedItem.ToString() != "None" && cboExtraMount.SelectedItem.ToString() != "None" &&
                    cboMount.SelectedItem.ToString() == cboExtraMount.SelectedItem.ToString())
                {
                    ++cboExtraMount.SelectedIndex;
                }
                cboExtraMount.Visible      = cboExtraMount.Enabled && cboExtraMount.SelectedItem.ToString() != "None";
                lblExtraMountLabel.Visible = cboExtraMount.Visible;
            }

            // Avail.
            // If avail contains "F" or "R", remove it from the string so we can use the expression.
            lblAvail.Text         = new AvailabilityValue(Convert.ToInt32(nudRating.Value), xmlAccessory.SelectSingleNode("avail")?.Value).ToString();
            lblAvailLabel.Visible = !string.IsNullOrEmpty(lblAvail.Text);

            if (!chkFreeItem.Checked)
            {
                string strCost = "0";
                if (xmlAccessory.TryGetStringFieldQuickly("cost", ref strCost))
                {
                    strCost = (await strCost.CheapReplaceAsync("Weapon Cost",
                                                               () => _objParentWeapon.OwnCost.ToString(GlobalSettings.InvariantCultureInfo))
                               .CheapReplaceAsync("Weapon Total Cost",
                                                  () => _objParentWeapon.MultipliableCost(null)
                                                  .ToString(GlobalSettings.InvariantCultureInfo)))
                              .Replace("Rating", nudRating.Value.ToString(GlobalSettings.CultureInfo));
                }
                if (strCost.StartsWith("Variable(", StringComparison.Ordinal))
                {
                    decimal decMin;
                    decimal decMax = decimal.MaxValue;
                    strCost = strCost.TrimStartOnce("Variable(", true).TrimEndOnce(')');
                    if (strCost.Contains('-'))
                    {
                        string[] strValues = strCost.Split('-');
                        decimal.TryParse(strValues[0], NumberStyles.Any, GlobalSettings.InvariantCultureInfo, out decMin);
                        decimal.TryParse(strValues[1], NumberStyles.Any, GlobalSettings.InvariantCultureInfo, out decMax);
                    }
                    else
                    {
                        decimal.TryParse(strCost.FastEscape('+'), NumberStyles.Any, GlobalSettings.InvariantCultureInfo, out decMin);
                    }

                    if (decMax == decimal.MaxValue)
                    {
                        lblCost.Text = decMin.ToString(_objCharacter.Settings.NuyenFormat, GlobalSettings.CultureInfo) + "¥+";
                    }
                    else
                    {
                        string strSpace = await LanguageManager.GetStringAsync("String_Space");

                        lblCost.Text = decMin.ToString(_objCharacter.Settings.NuyenFormat, GlobalSettings.CultureInfo) + strSpace + '-'
                                       + strSpace + decMax.ToString(_objCharacter.Settings.NuyenFormat, GlobalSettings.CultureInfo) + '¥';
                    }

                    lblTest.Text = _objCharacter.AvailTest(decMax, lblAvail.Text);
                }
                else
                {
                    object  objProcess = CommonFunctions.EvaluateInvariantXPath(strCost, out bool blnIsSuccess);
                    decimal decCost    = blnIsSuccess ? Convert.ToDecimal(objProcess, GlobalSettings.InvariantCultureInfo) : 0;

                    // Apply any markup.
                    decCost *= 1 + (nudMarkup.Value / 100.0m);

                    if (chkBlackMarketDiscount.Checked)
                    {
                        decCost *= 0.9m;
                    }
                    decCost *= _objParentWeapon.AccessoryMultiplier;
                    if (!string.IsNullOrEmpty(_objParentWeapon.DoubledCostModificationSlots))
                    {
                        string[] astrParentDoubledCostModificationSlots = _objParentWeapon.DoubledCostModificationSlots.Split('/', StringSplitOptions.RemoveEmptyEntries);
                        if (astrParentDoubledCostModificationSlots.Contains(cboMount.SelectedItem?.ToString()) ||
                            astrParentDoubledCostModificationSlots.Contains(cboExtraMount.SelectedItem?.ToString()))
                        {
                            decCost *= 2;
                        }
                    }

                    lblCost.Text = decCost.ToString(_objCharacter.Settings.NuyenFormat, GlobalSettings.CultureInfo) + '¥';
                    lblTest.Text = _objCharacter.AvailTest(decCost, lblAvail.Text);
                }
            }
            else
            {
                lblCost.Text = (0.0m).ToString(_objCharacter.Settings.NuyenFormat, GlobalSettings.CultureInfo) + '¥';
                lblTest.Text = _objCharacter.AvailTest(0, lblAvail.Text);
            }

            lblRatingLabel.Text = xmlAccessory.SelectSingleNode("ratinglabel") != null
                ? string.Format(GlobalSettings.CultureInfo, await LanguageManager.GetStringAsync("Label_RatingFormat"),
                                await LanguageManager.GetStringAsync(xmlAccessory.SelectSingleNode("ratinglabel").Value))
                : await LanguageManager.GetStringAsync("Label_Rating");

            lblCostLabel.Visible = !string.IsNullOrEmpty(lblCost.Text);
            lblTestLabel.Visible = !string.IsNullOrEmpty(lblTest.Text);

            chkBlackMarketDiscount.Enabled = _blnIsParentWeaponBlackMarketAllowed;
            if (!chkBlackMarketDiscount.Checked)
            {
                chkBlackMarketDiscount.Checked = GlobalSettings.AssumeBlackMarket && _blnIsParentWeaponBlackMarketAllowed;
            }
            else if (!_blnIsParentWeaponBlackMarketAllowed)
            {
                //Prevent chkBlackMarketDiscount from being checked if the gear category doesn't match.
                chkBlackMarketDiscount.Checked = false;
            }

            string strSource = xmlAccessory.SelectSingleNode("source")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown");

            string strPage = (await xmlAccessory.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? xmlAccessory.SelectSingleNode("page")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown");

            SourceString objSourceString = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter);

            await objSourceString.SetControlAsync(lblSource);

            lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
            tlpRight.Visible       = true;
        }
Пример #12
0
        private async void lstDrug_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnLoading)
            {
                return;
            }
            _blnLoading = true;
            XPathNavigator xmlDrug       = null;
            string         strSelectedId = await lstDrug.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString());

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                // Retrieve the information for the selected piece of Drug.
                xmlDrug = _xmlBaseDrugDataNode.SelectSingleNode(_strNodeXPath + "[id = " + strSelectedId.CleanXPath() + ']');
            }
            string strForceGrade;

            if (xmlDrug != null)
            {
                strForceGrade = xmlDrug.SelectSingleNode("forcegrade")?.Value;
                // If the piece has a Rating value, enable the Rating control, otherwise, disable it and set its value to 0.
                XPathNavigator xmlRatingNode = xmlDrug.SelectSingleNode("rating");
                if (xmlRatingNode != null)
                {
                    string strMinRating = xmlDrug.SelectSingleNode("minrating")?.Value;
                    int    intMinRating = 1;
                    // Not a simple integer, so we need to start mucking around with strings
                    if (!string.IsNullOrEmpty(strMinRating) && !int.TryParse(strMinRating, out intMinRating))
                    {
                        strMinRating = await strMinRating
                                       .CheapReplaceAsync("MaximumSTR",
                                                          () => (ParentVehicle != null
                                                                        ? Math.Max(1, ParentVehicle.TotalBody * 2)
                                                                        : _objCharacter.STR.TotalMaximum)
                                                          .ToString(GlobalSettings.InvariantCultureInfo))
                                       .CheapReplaceAsync("MaximumAGI",
                                                          () => (ParentVehicle != null
                                                                        ? Math.Max(1, ParentVehicle.Pilot * 2)
                                                                        : _objCharacter.AGI.TotalMaximum)
                                                          .ToString(GlobalSettings.InvariantCultureInfo))
                                       .CheapReplaceAsync("MinimumSTR",
                                                          () => (ParentVehicle?.TotalBody ?? 3).ToString(
                                                              GlobalSettings.InvariantCultureInfo))
                                       .CheapReplaceAsync("MinimumAGI",
                                                          () => (ParentVehicle?.Pilot ?? 3).ToString(
                                                              GlobalSettings.InvariantCultureInfo));

                        object objProcess = CommonFunctions.EvaluateInvariantXPath(strMinRating, out bool blnIsSuccess);
                        intMinRating = blnIsSuccess ? ((double)objProcess).StandardRound() : 1;
                    }
                    await nudRating.DoThreadSafeAsync(x => x.Minimum = intMinRating);

                    string strMaxRating = xmlRatingNode.Value;
                    int    intMaxRating = 0;
                    // Not a simple integer, so we need to start mucking around with strings
                    if (!string.IsNullOrEmpty(strMaxRating) && !int.TryParse(strMaxRating, out intMaxRating))
                    {
                        strMaxRating = await strMaxRating
                                       .CheapReplaceAsync("MaximumSTR",
                                                          () => (ParentVehicle != null
                                                                        ? Math.Max(1, ParentVehicle.TotalBody * 2)
                                                                        : _objCharacter.STR.TotalMaximum)
                                                          .ToString(GlobalSettings.InvariantCultureInfo))
                                       .CheapReplaceAsync("MaximumAGI",
                                                          () => (ParentVehicle != null
                                                                        ? Math.Max(1, ParentVehicle.Pilot * 2)
                                                                        : _objCharacter.AGI.TotalMaximum)
                                                          .ToString(GlobalSettings.InvariantCultureInfo))
                                       .CheapReplaceAsync("MinimumSTR",
                                                          () => (ParentVehicle?.TotalBody ?? 3).ToString(
                                                              GlobalSettings.InvariantCultureInfo))
                                       .CheapReplaceAsync("MinimumAGI",
                                                          () => (ParentVehicle?.Pilot ?? 3).ToString(
                                                              GlobalSettings.InvariantCultureInfo));

                        object objProcess = CommonFunctions.EvaluateInvariantXPath(strMaxRating, out bool blnIsSuccess);
                        intMaxRating = blnIsSuccess ? ((double)objProcess).StandardRound() : 1;
                    }
                    await nudRating.DoThreadSafeAsync(x => x.Maximum = intMaxRating);

                    if (await chkHideOverAvailLimit.DoThreadSafeFuncAsync(x => x.Checked))
                    {
                        int intAvailModifier = strForceGrade == "None" ? 0 : _intAvailModifier;
                        await nudRating.DoThreadSafeAsync(x =>
                        {
                            while (x.Maximum > intMinRating &&
                                   !xmlDrug.CheckAvailRestriction(_objCharacter, x.MaximumAsInt,
                                                                  intAvailModifier))
                            {
                                --x.Maximum;
                            }
                        });
                    }

                    if (await chkShowOnlyAffordItems.DoThreadSafeFuncAsync(x => x.Checked) && !await chkFree.DoThreadSafeFuncAsync(x => x.Checked))
                    {
                        decimal decCostMultiplier = 1 + nudMarkup.Value / 100.0m;
                        if (await chkBlackMarketDiscount.DoThreadSafeFuncAsync(x => x.Checked))
                        {
                            decCostMultiplier *= 0.9m;
                        }
                        await nudRating.DoThreadSafeAsync(x =>
                        {
                            while (x.Maximum > intMinRating &&
                                   !xmlDrug.CheckNuyenRestriction(_objCharacter.Nuyen, decCostMultiplier,
                                                                  x.MaximumAsInt))
                            {
                                --x.Maximum;
                            }
                        });
                    }

                    await nudRating.DoThreadSafeAsync(x =>
                    {
                        x.Value   = x.Minimum;
                        x.Enabled = x.Minimum != x.Maximum;
                        x.Visible = true;
                    });

                    await lblRatingNALabel.DoThreadSafeAsync(x => x.Visible = false);

                    await lblRatingLabel.DoThreadSafeAsync(x => x.Visible = true);
                }
                else
                {
                    await lblRatingLabel.DoThreadSafeAsync(x => x.Visible = true);

                    await lblRatingNALabel.DoThreadSafeAsync(x => x.Visible = true);

                    await nudRating.DoThreadSafeAsync(x =>
                    {
                        x.Minimum = 0;
                        x.Value   = 0;
                        x.Visible = false;
                    });
                }

                string strSource = xmlDrug.SelectSingleNode("source")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown");

                string strPage = (await xmlDrug.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? xmlDrug.SelectSingleNode("page")?.Value ?? await LanguageManager.GetStringAsync("String_Unknown");

                SourceString objSource = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language,
                                                                                 GlobalSettings.CultureInfo, _objCharacter);

                await objSource.SetControlAsync(lblSource);

                await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(objSource.ToString()));

                Grade objForcedGrade = null;
                if (!string.IsNullOrEmpty(strForceGrade))
                {
                    // Force the Drug to be a particular Grade.
                    await cboGrade.DoThreadSafeAsync(x =>
                    {
                        if (x.Enabled)
                        {
                            x.Enabled = false;
                        }
                    });

                    objForcedGrade = _lstGrades.Find(x => x.Name == strForceGrade);
                    strForceGrade  = objForcedGrade?.SourceId.ToString("D", GlobalSettings.InvariantCultureInfo);
                }
                else
                {
                    await cboGrade.DoThreadSafeAsync(x => x.Enabled = !_blnLockGrade);

                    if (_blnLockGrade)
                    {
                        strForceGrade  = _objForcedGrade?.SourceId.ToString("D", GlobalSettings.InvariantCultureInfo) ?? cboGrade.SelectedValue?.ToString();
                        objForcedGrade = _objForcedGrade ?? _lstGrades.Find(x => x.SourceId.ToString("D", GlobalSettings.InvariantCultureInfo) == strForceGrade);
                    }
                }

                bool blnCanBlackMarketDiscount = _setBlackMarketMaps.Contains(xmlDrug.SelectSingleNode("category")?.Value);
                await chkBlackMarketDiscount.DoThreadSafeAsync(x =>
                {
                    x.Enabled = blnCanBlackMarketDiscount;
                    if (!x.Checked)
                    {
                        x.Checked = GlobalSettings.AssumeBlackMarket && blnCanBlackMarketDiscount;
                    }
                    else if (!blnCanBlackMarketDiscount)
                    {
                        //Prevent chkBlackMarketDiscount from being checked if the category doesn't match.
                        x.Checked = false;
                    }
                });

                // We may need to rebuild the Grade list since Cultured Bioware is not allowed to select Standard (Second-Hand) as Grade and ForceGrades can change.
                await PopulateGrades(xmlDrug.SelectSingleNode("nosecondhand") != null || !await cboGrade.DoThreadSafeFuncAsync(x => x.Enabled) && objForcedGrade?.SecondHand != true, false, strForceGrade);

                /*
                 * string strNotes = xmlDrug.SelectSingleNode("altnotes")?.Value ?? xmlDrug.SelectSingleNode("notes")?.Value;
                 * if (!string.IsNullOrEmpty(strNotes))
                 * {
                 *  await lblDrugNotesLabel.DoThreadSafeAsync(x => x.Visible = true);
                 *  await lblDrugNotes.DoThreadSafeAsync(x =>
                 *  {
                 *      x.Text = strNotes;
                 *      x.Visible = true;
                 *  });
                 * }
                 * else
                 * {
                 *  await lblDrugNotes.DoThreadSafeAsync(x => x.Visible = false);
                 *  await lblDrugNotesLabel.DoThreadSafeAsync(x => x.Visible = false);
                 * }*/
                await tlpRight.DoThreadSafeAsync(x => x.Visible = true);
            }
            else
            {
                await tlpRight.DoThreadSafeAsync(x => x.Visible = false);

                await cboGrade.DoThreadSafeAsync(x => x.Enabled = !_blnLockGrade);

                strForceGrade = string.Empty;
                Grade objForcedGrade = null;
                if (_blnLockGrade)
                {
                    strForceGrade = _objForcedGrade?.SourceId.ToString("D", GlobalSettings.InvariantCultureInfo) ?? await cboGrade.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString());

                    objForcedGrade = _objForcedGrade ?? _lstGrades.Find(x => x.SourceId.ToString("D", GlobalSettings.InvariantCultureInfo) == strForceGrade);
                }
                await PopulateGrades(_blnLockGrade && objForcedGrade?.SecondHand != true, false, strForceGrade);

                await chkBlackMarketDiscount.DoThreadSafeAsync(x => x.Checked = false);
            }
            _blnLoading = false;
            await UpdateDrugInfo();
        }
        private async ValueTask RefreshSelectedLifestyle()
        {
            if (_blnSkipRefresh)
            {
                return;
            }

            _objLifestyle.BaseLifestyle = await cboBaseLifestyle.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString()) ?? string.Empty;

            XPathNavigator xmlAspect = await _objLifestyle.GetNodeXPathAsync();

            if (xmlAspect != null)
            {
                string strSource = xmlAspect.SelectSingleNode("source")?.Value ?? string.Empty;
                string strPage   = (await xmlAspect.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? xmlAspect.SelectSingleNode("page")?.Value ?? string.Empty;
                if (!string.IsNullOrEmpty(strSource) && !string.IsNullOrEmpty(strPage))
                {
                    SourceString objSource = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language,
                                                                                     GlobalSettings.CultureInfo, _objCharacter);

                    await objSource.SetControlAsync(lblSource);

                    await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = true);
                }
                else
                {
                    await SourceString.Blank.SetControlAsync(lblSource);

                    await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = false);
                }
            }
            else
            {
                await SourceString.Blank.SetControlAsync(lblSource);

                await lblSourceLabel.DoThreadSafeAsync(x => x.Visible = false);
            }

            // Characters with the Trust Fund Quality can have the lifestyle discounted.
            if (_objLifestyle.IsTrustFundEligible)
            {
                await chkTrustFund.DoThreadSafeAsync(x =>
                {
                    x.Visible = true;
                    x.Checked = _objLifestyle.TrustFund;
                });
            }
            else
            {
                await chkTrustFund.DoThreadSafeAsync(x =>
                {
                    x.Checked = false;
                    x.Visible = false;
                });
            }

            if (_objLifestyle.AllowBonusLP)
            {
                await lblBonusLP.DoThreadSafeAsync(x => x.Visible = true);

                await nudBonusLP.DoThreadSafeAsync(x => x.Visible = true);

                await chkBonusLPRandomize.DoThreadSafeAsync(x => x.Visible = true);

                if (await chkBonusLPRandomize.DoThreadSafeFuncAsync(x => x.Checked))
                {
                    int intValue = await GlobalSettings.RandomGenerator.NextD6ModuloBiasRemovedAsync();

                    await nudBonusLP.DoThreadSafeAsync(x =>
                    {
                        x.Enabled       = false;
                        _blnSkipRefresh = true;
                        x.Value         = intValue;
                        _blnSkipRefresh = false;
                    });
                }
                else
                {
                    await nudBonusLP.DoThreadSafeAsync(x => x.Enabled = true);
                }
            }
            else
            {
                await lblBonusLP.DoThreadSafeAsync(x => x.Visible = false);

                await nudBonusLP.DoThreadSafeAsync(x => x.Visible = false);

                await nudBonusLP.DoThreadSafeAsync(x => x.Value = 0);

                await chkBonusLPRandomize.DoThreadSafeAsync(x => x.Visible = false);
            }
        }
Пример #14
0
        private async void trePowers_AfterSelect(object sender, TreeViewEventArgs e)
        {
            await lblPowerPoints.DoThreadSafeAsync(x => x.Visible = false);

            await lblPowerPointsLabel.DoThreadSafeAsync(x => x.Visible = false);

            string strSelectedPower = await trePowers.DoThreadSafeFuncAsync(x => x.SelectedNode.Tag?.ToString());

            if (!string.IsNullOrEmpty(strSelectedPower))
            {
                XPathNavigator objXmlPower = _xmlBaseCritterPowerDataNode.SelectSingleNode("powers/power[id = " + strSelectedPower.CleanXPath() + ']');
                if (objXmlPower != null)
                {
                    string strCategory = (await objXmlPower.SelectSingleNodeAndCacheExpressionAsync("category"))?.Value
                                         ?? string.Empty;
                    await lblCritterPowerCategory.DoThreadSafeAsync(x => x.Text = strCategory);

                    string strType = (await objXmlPower.SelectSingleNodeAndCacheExpressionAsync("type"))?.Value
                                     ?? string.Empty;
                    switch (strType)
                    {
                    case "M":
                        strType = await LanguageManager.GetStringAsync("String_SpellTypeMana");

                        break;

                    case "P":
                        strType = await LanguageManager.GetStringAsync("String_SpellTypePhysical");

                        break;
                    }
                    await lblCritterPowerType.DoThreadSafeAsync(x => x.Text = strType);

                    string strAction = objXmlPower.SelectSingleNode("action")?.Value ?? string.Empty;
                    switch (strAction)
                    {
                    case "Auto":
                        strAction = await LanguageManager.GetStringAsync("String_ActionAutomatic");

                        break;

                    case "Free":
                        strAction = await LanguageManager.GetStringAsync("String_ActionFree");

                        break;

                    case "Simple":
                        strAction = await LanguageManager.GetStringAsync("String_ActionSimple");

                        break;

                    case "Complex":
                        strAction = await LanguageManager.GetStringAsync("String_ActionComplex");

                        break;

                    case "Special":
                        strAction = await LanguageManager.GetStringAsync("String_SpellDurationSpecial");

                        break;
                    }
                    await lblCritterPowerAction.DoThreadSafeAsync(x => x.Text = strAction);

                    string strRange = objXmlPower.SelectSingleNode("range")?.Value ?? string.Empty;
                    if (!string.IsNullOrEmpty(strRange))
                    {
                        strRange = await strRange.CheapReplaceAsync("Self",
                                                                    () => LanguageManager.GetStringAsync("String_SpellRangeSelf"))
                                   .CheapReplaceAsync("Special",
                                                      () => LanguageManager.GetStringAsync("String_SpellDurationSpecial"))
                                   .CheapReplaceAsync("LOS", () => LanguageManager.GetStringAsync("String_SpellRangeLineOfSight"))
                                   .CheapReplaceAsync("LOI",
                                                      () => LanguageManager.GetStringAsync("String_SpellRangeLineOfInfluence"))
                                   .CheapReplaceAsync("Touch", () => LanguageManager.GetStringAsync("String_SpellRangeTouchLong"))
                                   .CheapReplaceAsync("T", () => LanguageManager.GetStringAsync("String_SpellRangeTouch"))
                                   .CheapReplaceAsync("(A)", async() => '(' + await LanguageManager.GetStringAsync("String_SpellRangeArea") + ')')
                                   .CheapReplaceAsync("MAG", () => LanguageManager.GetStringAsync("String_AttributeMAGShort"));
                    }
                    await lblCritterPowerRange.DoThreadSafeAsync(x => x.Text = strRange);

                    string strDuration = (await objXmlPower.SelectSingleNodeAndCacheExpressionAsync("duration"))?.Value ?? string.Empty;
                    switch (strDuration)
                    {
                    case "Instant":
                        strDuration = await LanguageManager.GetStringAsync("String_SpellDurationInstantLong");

                        break;

                    case "Sustained":
                        strDuration = await LanguageManager.GetStringAsync("String_SpellDurationSustained");

                        break;

                    case "Always":
                        strDuration = await LanguageManager.GetStringAsync("String_SpellDurationAlways");

                        break;

                    case "Special":
                        strDuration = await LanguageManager.GetStringAsync("String_SpellDurationSpecial");

                        break;
                    }
                    await lblCritterPowerDuration.DoThreadSafeAsync(x => x.Text = strDuration);

                    string strSource = (await objXmlPower.SelectSingleNodeAndCacheExpressionAsync("source"))?.Value ?? await LanguageManager.GetStringAsync("String_Unknown");

                    string strPage = (await objXmlPower.SelectSingleNodeAndCacheExpressionAsync("altpage"))?.Value ?? (await objXmlPower.SelectSingleNodeAndCacheExpressionAsync("page"))?.Value ?? await LanguageManager.GetStringAsync("String_Unknown");

                    SourceString objSource = await SourceString.GetSourceStringAsync(strSource, strPage, GlobalSettings.Language,
                                                                                     GlobalSettings.CultureInfo, _objCharacter);

                    await objSource.SetControlAsync(lblCritterPowerSource);

                    bool blnVisible = await objXmlPower.SelectSingleNodeAndCacheExpressionAsync("rating") != null;

                    await nudCritterPowerRating.DoThreadSafeAsync(x => x.Visible = blnVisible);

                    string strKarma = (await objXmlPower.SelectSingleNodeAndCacheExpressionAsync("karma"))?.Value
                                      ?? "0";
                    await lblKarma.DoThreadSafeAsync(x => x.Text = strKarma);

                    // If the character is a Free Spirit, populate the Power Points Cost as well.
                    if (_objCharacter.Metatype == "Free Spirit")
                    {
                        XPathNavigator xmlOptionalPowerCostNode = _xmlMetatypeDataNode.SelectSingleNode("optionalpowers/power[. = " + objXmlPower.SelectSingleNode("name")?.Value.CleanXPath() + "]/@cost");
                        if (xmlOptionalPowerCostNode != null)
                        {
                            await lblPowerPoints.DoThreadSafeAsync(x =>
                            {
                                x.Text    = xmlOptionalPowerCostNode.Value;
                                x.Visible = true;
                            });

                            await lblPowerPointsLabel.DoThreadSafeAsync(x => x.Visible = true);
                        }
                    }

                    await lblCritterPowerTypeLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strType));

                    await lblCritterPowerActionLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strAction));

                    await lblCritterPowerRangeLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strRange));

                    await lblCritterPowerDurationLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strDuration));

                    await lblCritterPowerSourceLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(objSource.ToString()));

                    await lblKarmaLabel.DoThreadSafeAsync(x => x.Visible = !string.IsNullOrEmpty(strKarma));

                    await tlpRight.DoThreadSafeAsync(x => x.Visible = true);
                }
                else
                {
                    await tlpRight.DoThreadSafeAsync(x => x.Visible = false);
                }
            }
            else
            {
                await tlpRight.DoThreadSafeAsync(x => x.Visible = false);
            }
        }