Exemplo n.º 1
0
        private 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.
                XmlNode objXmlMetamagic = _objXmlDocument.SelectSingleNode(_strRootXPath + "[id = \"" + strSelectedId + "\"]");

                if (objXmlMetamagic != null)
                {
                    string       strSource       = objXmlMetamagic["source"]?.InnerText;
                    string       strPage         = objXmlMetamagic["altpage"]?.InnerText ?? objXmlMetamagic["page"]?.InnerText;
                    SourceString objSourceString = new SourceString(strSource, strPage, GlobalOptions.Language);
                    objSourceString.SetControl(lblSource);
                }
                else
                {
                    lblSource.Text = string.Empty;
                    lblSource.SetToolTip(string.Empty);
                }
            }
            else
            {
                lblSource.Text = string.Empty;
                lblSource.SetToolTip(string.Empty);
            }

            lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
        }
Exemplo n.º 2
0
        private 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         = objXmlMetamagic.SelectSingleNode("altpage")?.Value ?? objXmlMetamagic.SelectSingleNode("page")?.Value;
                    SourceString objSourceString = new SourceString(strSource, strPage, GlobalOptions.Language, GlobalOptions.CultureInfo, _objCharacter);
                    objSourceString.SetControl(lblSource);
                    lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
                    tlpRight.Visible       = true;
                }
                else
                {
                    tlpRight.Visible = false;
                }
            }
            else
            {
                tlpRight.Visible = false;
            }
        }
        private void lstTechniques_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnLoading)
            {
                return;
            }

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

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

                if (xmlTechnique != null)
                {
                    string       strSource       = xmlTechnique.SelectSingleNode("source")?.Value ?? LanguageManager.GetString("String_Unknown");
                    string       strPage         = xmlTechnique.SelectSingleNode("altpage")?.Value ?? xmlTechnique.SelectSingleNode("page")?.Value ?? LanguageManager.GetString("String_Unknown");
                    SourceString objSourceString = new SourceString(strSource, strPage, GlobalOptions.Language, GlobalOptions.CultureInfo, _objCharacter);
                    objSourceString.SetControl(lblSource);
                    lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
                }
                else
                {
                    lblSource.Text = string.Empty;
                    lblSource.SetToolTip(string.Empty);
                    lblSourceLabel.Visible = false;
                }
            }
            else
            {
                lblSource.Text = string.Empty;
                lblSource.SetToolTip(string.Empty);
                lblSourceLabel.Visible = false;
            }
        }
Exemplo n.º 4
0
        private 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         = objXmlArt.SelectSingleNode("cost")?.Value ?? 7.ToString(GlobalOptions.CultureInfo);
                    lblKarmaCostLabel.Visible = !string.IsNullOrEmpty(lblKarmaCost.Text);

                    StringBuilder objTechniqueStringBuilder = new StringBuilder();
                    foreach (XPathNavigator xmlMartialArtsTechnique in objXmlArt.Select("techniques/technique"))
                    {
                        string strLoopTechniqueName = xmlMartialArtsTechnique.SelectSingleNode("name")?.Value ?? string.Empty;
                        if (!string.IsNullOrEmpty(strLoopTechniqueName))
                        {
                            XPathNavigator xmlTechniqueNode = _xmlBaseMartialArtsTechniquesNode.SelectSingleNode(string.Format(GlobalOptions.InvariantCultureInfo, "technique[name = {0} and ({1})]",
                                                                                                                               strLoopTechniqueName.CleanXPath(), _objCharacter.Options.BookXPath()));
                            if (xmlTechniqueNode != null)
                            {
                                if (objTechniqueStringBuilder.Length > 0)
                                {
                                    objTechniqueStringBuilder.AppendLine(",");
                                }

                                objTechniqueStringBuilder.Append(!GlobalOptions.Language.Equals(GlobalOptions.DefaultLanguage, StringComparison.OrdinalIgnoreCase) ? xmlTechniqueNode.SelectSingleNode("translate")?.Value ?? strLoopTechniqueName: strLoopTechniqueName);
                            }
                        }
                    }
                    lblIncludedTechniques.Text    = objTechniqueStringBuilder.ToString();
                    gpbIncludedTechniques.Visible = !string.IsNullOrEmpty(lblIncludedTechniques.Text);

                    string       strSource       = objXmlArt.SelectSingleNode("source")?.Value ?? LanguageManager.GetString("String_Unknown");
                    string       strPage         = objXmlArt.SelectSingleNode("altpage")?.Value ?? objXmlArt.SelectSingleNode("page")?.Value ?? LanguageManager.GetString("String_Unknown");
                    SourceString objSourceString = new SourceString(strSource, strPage, GlobalOptions.Language, GlobalOptions.CultureInfo, _objCharacter);
                    objSourceString.SetControl(lblSource);
                    lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
                    tlpRight.Visible       = true;
                }
                else
                {
                    tlpRight.Visible = false;
                    gpbIncludedTechniques.Visible = false;
                }
            }
            else
            {
                tlpRight.Visible = false;
                gpbIncludedTechniques.Visible = false;
            }
        }
Exemplo n.º 5
0
        private void UpdateGearInfo(bool blnUpdateMountCBOs = 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)
            {
                lblRC.Visible            = false;
                lblRCLabel.Visible       = false;
                nudRating.Enabled        = false;
                nudRating.Visible        = false;
                lblRatingLabel.Visible   = false;
                lblRatingNALabel.Visible = false;
                lblMountLabel.Visible    = false;
                cboMount.Visible         = false;
                cboMount.Items.Clear();
                lblExtraMountLabel.Visible = false;
                cboExtraMount.Visible      = false;
                cboExtraMount.Items.Clear();
                lblAvailLabel.Visible  = false;
                lblAvail.Text          = string.Empty;
                lblCostLabel.Visible   = false;
                lblCost.Text           = string.Empty;
                lblTestLabel.Visible   = false;
                lblTest.Text           = string.Empty;
                lblSourceLabel.Visible = false;
                lblSource.Text         = string.Empty;
                lblSource.SetToolTip(string.Empty);
                return;
            }

            string strSpace = LanguageManager.GetString("String_Space");
            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 -= 1;
                    }
                }
                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 -= 1;
                    }
                }
                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 (blnUpdateMountCBOs)
            {
                string        strDataMounts = xmlAccessory.SelectSingleNode("mount")?.Value;
                List <string> strMounts     = new List <string>();
                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>();
                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 += 1;
                }
                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 = strCost.CheapReplace("Weapon Cost", () => _objParentWeapon.OwnCost.ToString(GlobalOptions.InvariantCultureInfo))
                              .CheapReplace("Weapon Total Cost", () => _objParentWeapon.MultipliableCost(null).ToString(GlobalOptions.InvariantCultureInfo))
                              .Replace("Rating", nudRating.Value.ToString(GlobalOptions.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, GlobalOptions.InvariantCultureInfo, out decMin);
                        decimal.TryParse(strValues[1], NumberStyles.Any, GlobalOptions.InvariantCultureInfo, out decMax);
                    }
                    else
                    {
                        decimal.TryParse(strCost.FastEscape('+'), NumberStyles.Any, GlobalOptions.InvariantCultureInfo, out decMin);
                    }

                    if (decMax == decimal.MaxValue)
                    {
                        lblCost.Text = decMin.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + "¥+";
                    }
                    else
                    {
                        lblCost.Text = decMin.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + strSpace + '-'
                                       + strSpace + decMax.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                    }

                    lblTest.Text = _objCharacter.AvailTest(decMax, lblAvail.Text);
                }
                else
                {
                    object  objProcess = CommonFunctions.EvaluateInvariantXPath(strCost, out bool blnIsSuccess);
                    decimal decCost    = blnIsSuccess ? Convert.ToDecimal(objProcess, GlobalOptions.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.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                    lblTest.Text = _objCharacter.AvailTest(decCost, lblAvail.Text);
                }
            }
            else
            {
                lblCost.Text = (0.0m).ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                lblTest.Text = _objCharacter.AvailTest(0, lblAvail.Text);
            }

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

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


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

            chkBlackMarketDiscount.Enabled = _blnIsParentWeaponBlackMarketAllowed;
            string       strSource       = xmlAccessory.SelectSingleNode("source")?.Value ?? LanguageManager.GetString("String_Unknown");
            string       strPage         = xmlAccessory.SelectSingleNode("altpage")?.Value ?? xmlAccessory.SelectSingleNode("page")?.Value ?? LanguageManager.GetString("String_Unknown");
            SourceString objSourceString = new SourceString(strSource, strPage, GlobalOptions.Language, GlobalOptions.CultureInfo, _objCharacter);

            objSourceString.SetControl(lblSource);
            lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
        }
Exemplo n.º 6
0
        private void lstMentor_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnSkipRefresh)
            {
                return;
            }

            XPathNavigator objXmlMentor  = null;
            string         strSelectedId = lstMentor.SelectedValue?.ToString();

            if (!string.IsNullOrEmpty(strSelectedId))
            {
                objXmlMentor = _xmlBaseMentorSpiritDataNode.SelectSingleNode("mentors/mentor[id = " + lstMentor.SelectedValue.ToString().CleanXPath() + "]");
            }
            if (objXmlMentor != null)
            {
                cboChoice1.BeginUpdate();
                cboChoice2.BeginUpdate();
                cboChoice1.DataSource = null;
                cboChoice2.DataSource = null;

                // If the Mentor offers a choice of bonuses, build the list and let the user select one.
                XPathNavigator xmlChoices = objXmlMentor.SelectSingleNode("choices");
                if (xmlChoices != null)
                {
                    List <ListItem> lstChoice1 = new List <ListItem>();
                    List <ListItem> lstChoice2 = new List <ListItem>();

                    foreach (XPathNavigator objChoice in xmlChoices.Select("choice"))
                    {
                        string strName = objChoice.SelectSingleNode("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, objChoice.SelectSingleNode("translate")?.Value ?? strName));
                            }
                            else
                            {
                                lstChoice1.Add(new ListItem(strName, objChoice.SelectSingleNode("translate")?.Value ?? strName));
                            }
                        }
                    }

                    cboChoice1.Visible       = true;
                    cboChoice1.DataSource    = lstChoice1;
                    cboChoice1.ValueMember   = nameof(ListItem.Value);
                    cboChoice1.DisplayMember = nameof(ListItem.Name);

                    if (lstChoice2.Count > 0)
                    {
                        cboChoice2.Visible       = true;
                        cboChoice2.DataSource    = lstChoice2;
                        cboChoice2.ValueMember   = nameof(ListItem.Value);
                        cboChoice2.DisplayMember = nameof(ListItem.Name);
                    }
                    else
                    {
                        cboChoice2.Visible = false;
                    }

                    cboChoice1.Visible = lstChoice1.Count > 0;
                    cboChoice1.Enabled = lstChoice1.Count > 1;
                    cboChoice2.Enabled = lstChoice2.Count > 1;
                }
                else
                {
                    cboChoice1.Visible = false;
                    cboChoice2.Visible = false;
                }
                cboChoice1.EndUpdate();
                cboChoice2.EndUpdate();
                lblChoice1.Visible = cboChoice1.Visible;
                lblChoice2.Visible = cboChoice2.Visible;

                // Get the information for the selected Mentor.
                lblAdvantage.Text = objXmlMentor.SelectSingleNode("altadvantage")?.Value ??
                                    objXmlMentor.SelectSingleNode("advantage")?.Value ??
                                    LanguageManager.GetString("String_Unknown");
                lblAdvantageLabel.Visible = !string.IsNullOrEmpty(lblAdvantage.Text);
                lblDisadvantage.Text      = objXmlMentor.SelectSingleNode("altdisadvantage")?.Value ??
                                            objXmlMentor.SelectSingleNode("disadvantage")?.Value ??
                                            LanguageManager.GetString("String_Unknown");
                lblDisadvantageLabel.Visible = !string.IsNullOrEmpty(lblDisadvantage.Text);

                string       strSource       = objXmlMentor.SelectSingleNode("source")?.Value ?? LanguageManager.GetString("String_Unknown");
                string       strPage         = objXmlMentor.SelectSingleNode("altpage")?.Value ?? objXmlMentor.SelectSingleNode("page")?.Value ?? LanguageManager.GetString("String_Unknown");
                SourceString objSourceString = new SourceString(strSource, strPage, GlobalOptions.Language, GlobalOptions.CultureInfo, _objCharacter);
                objSourceString.SetControl(lblSource);
                lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
                cmdOK.Enabled          = true;
            }
            else
            {
                lblAdvantageLabel.Visible    = false;
                lblAdvantage.Text            = string.Empty;
                lblDisadvantageLabel.Visible = false;
                lblDisadvantage.Text         = string.Empty;
                lblChoice1.Visible           = false;
                lblChoice2.Visible           = false;
                cboChoice1.Visible           = false;
                cboChoice2.Visible           = false;
                lblSourceLabel.Visible       = false;
                lblSource.Text = string.Empty;
                lblSource.SetToolTip(string.Empty);
                cmdOK.Enabled = false;
            }
        }
Exemplo n.º 7
0
        private 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         = objXmlArt.SelectSingleNodeAndCacheExpression("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 objXmlArt.SelectAndCacheExpression(
                                     "techniques/technique"))
                        {
                            string strLoopTechniqueName
                                = xmlMartialArtsTechnique.SelectSingleNodeAndCacheExpression("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)
                                            ? xmlTechniqueNode.SelectSingleNodeAndCacheExpression("translate")?.Value
                                        ?? strLoopTechniqueName
                                            : strLoopTechniqueName);
                                }
                            }
                        }

                        lblIncludedTechniques.Text = sbdTechniques.ToString();
                    }

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

                    string       strSource       = objXmlArt.SelectSingleNodeAndCacheExpression("source")?.Value ?? LanguageManager.GetString("String_Unknown");
                    string       strPage         = objXmlArt.SelectSingleNodeAndCacheExpression("altpage")?.Value ?? objXmlArt.SelectSingleNodeAndCacheExpression("page")?.Value ?? LanguageManager.GetString("String_Unknown");
                    SourceString objSourceString = new SourceString(strSource, strPage, GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter);
                    objSourceString.SetControl(lblSource);
                    lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
                    tlpRight.Visible       = true;
                }
                else
                {
                    tlpRight.Visible = false;
                    gpbIncludedTechniques.Visible = false;
                }
            }
            else
            {
                tlpRight.Visible = false;
                gpbIncludedTechniques.Visible = false;
            }
        }
Exemplo n.º 8
0
        private 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)
                {
                    cboChoice1.BeginUpdate();
                    cboChoice2.BeginUpdate();

                    // If the Mentor offers a choice of bonuses, build the list and let the user select one.
                    XPathNavigator xmlChoices = objXmlMentor.SelectSingleNode("choices");
                    if (xmlChoices != null)
                    {
                        List <ListItem> lstChoice1 = new List <ListItem>();
                        List <ListItem> lstChoice2 = new List <ListItem>();

                        foreach (XPathNavigator objChoice in xmlChoices.Select("choice"))
                        {
                            string strName = objChoice.SelectSingleNode("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,
                                                                objChoice.SelectSingleNode("translate")?.Value ?? strName));
                                }
                                else
                                {
                                    lstChoice1.Add(new ListItem(strName,
                                                                objChoice.SelectSingleNode("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)
                        {
                            cboChoice1.PopulateWithListItems(lstChoice1);
                        }
                        cboChoice1.Visible    = lstChoice1.Count > 1;
                        lblBonusText1.Visible = lstChoice1.Count == 1;
                        if (lstChoice1.Count == 1)
                        {
                            lblBonusText1.Text = lstChoice1[0].Name;
                        }
                        if (lstChoice2.Count > 0)
                        {
                            cboChoice2.PopulateWithListItems(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;
                    }

                    cboChoice1.EndUpdate();
                    cboChoice2.EndUpdate();
                    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 ??
                                        LanguageManager.GetString("String_Unknown");
                    lblAdvantageLabel.Visible = !string.IsNullOrEmpty(lblAdvantage.Text);
                    lblDisadvantage.Text      = objXmlMentor.SelectSingleNode("altdisadvantage")?.Value ??
                                                objXmlMentor.SelectSingleNode("disadvantage")?.Value ??
                                                LanguageManager.GetString("String_Unknown");
                    lblDisadvantageLabel.Visible = !string.IsNullOrEmpty(lblDisadvantage.Text);

                    string strSource = objXmlMentor.SelectSingleNode("source")?.Value ??
                                       LanguageManager.GetString("String_Unknown");
                    string strPage = objXmlMentor.SelectSingleNode("altpage")?.Value ??
                                     objXmlMentor.SelectSingleNode("page")?.Value ??
                                     LanguageManager.GetString("String_Unknown");
                    SourceString objSourceString = new SourceString(strSource, strPage, GlobalOptions.Language,
                                                                    GlobalOptions.CultureInfo, _objCharacter);
                    objSourceString.SetControl(lblSource);
                    lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
                    cmdOK.Enabled          = true;
                    tlpRight.Visible       = true;
                }
                else
                {
                    tlpRight.Visible = false;
                    cmdOK.Enabled    = false;
                }
            }
            finally
            {
                ResumeLayout();
            }
        }
        private void UpdateInfo()
        {
            if (_blnLoading)
            {
                return;
            }

            XmlNode xmlSelectedMount = null;
            string  strSelectedMount = cboSize.SelectedValue?.ToString();

            if (string.IsNullOrEmpty(strSelectedMount))
            {
                cmdOK.Enabled = false;
            }
            else
            {
                xmlSelectedMount = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = " + strSelectedMount.CleanXPath() + "]");
                if (xmlSelectedMount == null)
                {
                    cmdOK.Enabled = false;
                }
                else
                {
                    string strSelectedControl = cboControl.SelectedValue?.ToString();
                    if (string.IsNullOrEmpty(strSelectedControl))
                    {
                        cmdOK.Enabled = false;
                    }
                    else if (_xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = " + strSelectedControl.CleanXPath() + "]") == null)
                    {
                        cmdOK.Enabled = false;
                    }
                    else
                    {
                        string strSelectedFlexibility = cboFlexibility.SelectedValue?.ToString();
                        if (string.IsNullOrEmpty(strSelectedFlexibility))
                        {
                            cmdOK.Enabled = false;
                        }
                        else if (_xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = " + strSelectedFlexibility.CleanXPath() + "]") == null)
                        {
                            cmdOK.Enabled = false;
                        }
                        else
                        {
                            string strSelectedVisibility = cboVisibility.SelectedValue?.ToString();
                            if (string.IsNullOrEmpty(strSelectedVisibility))
                            {
                                cmdOK.Enabled = false;
                            }
                            else if (_xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = " + strSelectedVisibility.CleanXPath() + "]") == null)
                            {
                                cmdOK.Enabled = false;
                            }
                            else
                            {
                                cmdOK.Enabled = true;
                            }
                        }
                    }
                }
            }

            string[] astrSelectedValues = { cboVisibility.SelectedValue?.ToString(), cboFlexibility.SelectedValue?.ToString(), cboControl.SelectedValue?.ToString() };

            cmdDeleteMod.Enabled = false;
            string strSelectedModId = treMods.SelectedNode?.Tag.ToString();

            if (!string.IsNullOrEmpty(strSelectedModId) && strSelectedModId.IsGuid())
            {
                VehicleMod objMod = _lstMods.FirstOrDefault(x => x.InternalId == strSelectedModId);
                if (objMod != null)
                {
                    cmdDeleteMod.Enabled = !objMod.IncludedInVehicle;
                    lblSlots.Text        = objMod.CalculatedSlots.ToString(GlobalOptions.InvariantCultureInfo);
                    lblAvailability.Text = objMod.DisplayTotalAvail;

                    if (chkFreeItem.Checked)
                    {
                        lblCost.Text = (0.0m).ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                    }
                    else
                    {
                        int intTotalSlots = Convert.ToInt32(xmlSelectedMount?["slots"]?.InnerText, GlobalOptions.InvariantCultureInfo);
                        foreach (string strSelectedId in astrSelectedValues)
                        {
                            if (!string.IsNullOrEmpty(strSelectedId))
                            {
                                XmlNode xmlLoopNode = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = " + strSelectedId.CleanXPath() + "]");
                                if (xmlLoopNode != null)
                                {
                                    intTotalSlots += Convert.ToInt32(xmlLoopNode["slots"]?.InnerText, GlobalOptions.InvariantCultureInfo);
                                }
                            }
                        }
                        foreach (VehicleMod objLoopMod in _lstMods)
                        {
                            intTotalSlots += objLoopMod.CalculatedSlots;
                        }
                        lblCost.Text = (objMod.TotalCostInMountCreation(intTotalSlots) * (1 + (nudMarkup.Value / 100.0m))).ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
                    }

                    objMod.SetSourceDetail(lblSource);
                    lblCostLabel.Visible         = !string.IsNullOrEmpty(lblCost.Text);
                    lblSlotsLabel.Visible        = !string.IsNullOrEmpty(lblSlots.Text);
                    lblAvailabilityLabel.Visible = !string.IsNullOrEmpty(lblAvailability.Text);
                    lblSourceLabel.Visible       = !string.IsNullOrEmpty(lblSource.Text);
                    return;
                }
            }

            if (xmlSelectedMount == null)
            {
                lblCost.Text                 = string.Empty;
                lblSlots.Text                = string.Empty;
                lblAvailability.Text         = string.Empty;
                lblCostLabel.Visible         = false;
                lblSlotsLabel.Visible        = false;
                lblAvailabilityLabel.Visible = false;
                return;
            }
            decimal decCost  = !chkFreeItem.Checked ? Convert.ToDecimal(xmlSelectedMount["cost"]?.InnerText, GlobalOptions.InvariantCultureInfo) : 0;
            int     intSlots = Convert.ToInt32(xmlSelectedMount["slots"]?.InnerText, GlobalOptions.InvariantCultureInfo);

            string strAvail       = xmlSelectedMount["avail"]?.InnerText ?? string.Empty;
            char   chrAvailSuffix = strAvail.Length > 0 ? strAvail[strAvail.Length - 1] : ' ';

            if (chrAvailSuffix == 'F' || chrAvailSuffix == 'R')
            {
                strAvail = strAvail.Substring(0, strAvail.Length - 1);
            }
            else
            {
                chrAvailSuffix = ' ';
            }
            int intAvail = Convert.ToInt32(strAvail, GlobalOptions.InvariantCultureInfo);

            foreach (string strSelectedId in astrSelectedValues)
            {
                if (!string.IsNullOrEmpty(strSelectedId))
                {
                    XmlNode xmlLoopNode = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = " + strSelectedId.CleanXPath() + "]");
                    if (xmlLoopNode != null)
                    {
                        if (!chkFreeItem.Checked)
                        {
                            decCost += Convert.ToInt32(xmlLoopNode["cost"]?.InnerText, GlobalOptions.InvariantCultureInfo);
                        }

                        intSlots += Convert.ToInt32(xmlLoopNode["slots"]?.InnerText, GlobalOptions.InvariantCultureInfo);

                        string strLoopAvail       = xmlLoopNode["avail"]?.InnerText ?? string.Empty;
                        char   chrLoopAvailSuffix = strLoopAvail.Length > 0 ? strLoopAvail[strLoopAvail.Length - 1] : ' ';
                        if (chrLoopAvailSuffix == 'F')
                        {
                            strLoopAvail   = strLoopAvail.Substring(0, strLoopAvail.Length - 1);
                            chrAvailSuffix = 'F';
                        }
                        else if (chrLoopAvailSuffix == 'R')
                        {
                            strLoopAvail = strLoopAvail.Substring(0, strLoopAvail.Length - 1);
                            if (chrAvailSuffix == ' ')
                            {
                                chrAvailSuffix = 'R';
                            }
                        }
                        intAvail += Convert.ToInt32(strLoopAvail, GlobalOptions.InvariantCultureInfo);
                    }
                }
            }
            foreach (VehicleMod objMod in _lstMods)
            {
                intSlots += objMod.CalculatedSlots;
                AvailabilityValue objLoopAvail = objMod.TotalAvailTuple();
                char chrLoopAvailSuffix        = objLoopAvail.Suffix;
                if (chrLoopAvailSuffix == 'F')
                {
                    chrAvailSuffix = 'F';
                }
                else if (chrAvailSuffix != 'F' && chrLoopAvailSuffix == 'R')
                {
                    chrAvailSuffix = 'R';
                }
                intAvail += objLoopAvail.Value;
            }
            if (!chkFreeItem.Checked)
            {
                foreach (VehicleMod objMod in _lstMods)
                {
                    decCost += objMod.TotalCostInMountCreation(intSlots);
                }
            }

            string strAvailText = intAvail.ToString(GlobalOptions.CultureInfo);

            if (chrAvailSuffix == 'F')
            {
                strAvailText += LanguageManager.GetString("String_AvailForbidden");
            }
            else if (chrAvailSuffix == 'R')
            {
                strAvailText += LanguageManager.GetString("String_AvailRestricted");
            }

            decCost                     *= 1 + (nudMarkup.Value / 100.0m);
            lblCost.Text                 = decCost.ToString(_objCharacter.Options.NuyenFormat, GlobalOptions.CultureInfo) + '¥';
            lblSlots.Text                = intSlots.ToString(GlobalOptions.CultureInfo);
            lblAvailability.Text         = strAvailText;
            lblCostLabel.Visible         = !string.IsNullOrEmpty(lblCost.Text);
            lblSlotsLabel.Visible        = !string.IsNullOrEmpty(lblSlots.Text);
            lblAvailabilityLabel.Visible = !string.IsNullOrEmpty(lblAvailability.Text);

            string       strSource       = xmlSelectedMount["source"]?.InnerText ?? LanguageManager.GetString("String_Unknown");
            string       strPage         = xmlSelectedMount["altpage"]?.InnerText ?? xmlSelectedMount["page"]?.InnerText ?? LanguageManager.GetString("String_Unknown");
            SourceString objSourceString = new SourceString(strSource, strPage, GlobalOptions.Language, GlobalOptions.CultureInfo, _objCharacter);

            objSourceString.SetControl(lblSource);
            lblSourceLabel.Visible = !string.IsNullOrEmpty(lblSource.Text);
        }