コード例 #1
0
        public static ElasticComboBox PopulateLanguageList(ElasticComboBox myCboLanguage, string myStrSelectedSheet)
        {
            if (myCboLanguage == null)
            {
                throw new ArgumentNullException(nameof(myCboLanguage));
            }
            string strDefaultSheetLanguage        = GlobalOptions.Language;
            int?   intLastIndexDirectorySeparator = myStrSelectedSheet?.LastIndexOf(Path.DirectorySeparatorChar);

            if (intLastIndexDirectorySeparator.HasValue && (intLastIndexDirectorySeparator != -1))
            {
                string strSheetLanguage = myStrSelectedSheet.Substring(0, intLastIndexDirectorySeparator.Value);
                if (strSheetLanguage.Length == 5)
                {
                    strDefaultSheetLanguage = strSheetLanguage;
                }
            }

            myCboLanguage.BeginUpdate();
            myCboLanguage.ValueMember   = "Value";
            myCboLanguage.DisplayMember = "Name";
            myCboLanguage.DataSource    = LstLanguages;
            myCboLanguage.SelectedValue = strDefaultSheetLanguage;
            if (myCboLanguage.SelectedIndex == -1)
            {
                myCboLanguage.SelectedValue = GlobalOptions.DefaultLanguage;
            }
            myCboLanguage.EndUpdate();
            return(myCboLanguage);
        }
コード例 #2
0
        public static async Task <bool> ProcessMatrixAttributeComboBoxChangeAsync(this IHasMatrixAttributes objThis, Character objCharacter, ElasticComboBox cboChangedAttribute, ElasticComboBox cboAttack, ElasticComboBox cboSleaze, ElasticComboBox cboDataProcessing, ElasticComboBox cboFirewall, CancellationToken token = default)
        {
            token.ThrowIfCancellationRequested();
            if (objThis == null)
            {
                return(false);
            }
            if (objCharacter == null)
            {
                throw new ArgumentNullException(nameof(objCharacter));
            }
            if (cboChangedAttribute == null)
            {
                throw new ArgumentNullException(nameof(cboChangedAttribute));
            }
            if (cboAttack == null)
            {
                throw new ArgumentNullException(nameof(cboAttack));
            }
            if (cboSleaze == null)
            {
                throw new ArgumentNullException(nameof(cboSleaze));
            }
            if (cboDataProcessing == null)
            {
                throw new ArgumentNullException(nameof(cboDataProcessing));
            }
            if (cboFirewall == null)
            {
                throw new ArgumentNullException(nameof(cboFirewall));
            }

            string          strTemp;
            Action <string> funcAttributePropertySetter;

            if (cboChangedAttribute == cboAttack)
            {
                strTemp = objThis.Attack;
                funcAttributePropertySetter = (x => objThis.Attack = x);
            }
            else if (cboChangedAttribute == cboSleaze)
            {
                strTemp = objThis.Sleaze;
                funcAttributePropertySetter = (x => objThis.Sleaze = x);
            }
            else if (cboChangedAttribute == cboDataProcessing)
            {
                strTemp = objThis.DataProcessing;
                funcAttributePropertySetter = (x => objThis.DataProcessing = x);
            }
            else if (cboChangedAttribute == cboFirewall)
            {
                strTemp = objThis.Firewall;
                funcAttributePropertySetter = (x => objThis.Firewall = x);
            }
            else
            {
                return(false);
            }

            int intCurrentIndex = await cboChangedAttribute.DoThreadSafeFuncAsync(x => x.SelectedIndex, token);

            bool blnRefreshCharacter = false;
            bool blnDPChanged        = cboChangedAttribute == cboDataProcessing;

            // Find the combo with the same value as this one and change it to the missing value.
            if (cboChangedAttribute != cboAttack && await cboAttack.DoThreadSafeFuncAsync(x => x.SelectedIndex, token) == intCurrentIndex)
            {
                funcAttributePropertySetter.Invoke(objThis.Attack);
                objThis.Attack      = strTemp;
                blnRefreshCharacter = true;
            }
            else if (cboChangedAttribute != cboSleaze && await cboSleaze.DoThreadSafeFuncAsync(x => x.SelectedIndex, token) == intCurrentIndex)
            {
                funcAttributePropertySetter.Invoke(objThis.Sleaze);
                objThis.Sleaze      = strTemp;
                blnRefreshCharacter = true;
            }
            else if (!blnDPChanged && await cboDataProcessing.DoThreadSafeFuncAsync(x => x.SelectedIndex, token) == intCurrentIndex)
            {
                funcAttributePropertySetter.Invoke(objThis.DataProcessing);
                objThis.DataProcessing = strTemp;
                blnRefreshCharacter    = true;
                blnDPChanged           = true;
            }
            else if (cboChangedAttribute != cboFirewall && await cboFirewall.DoThreadSafeFuncAsync(x => x.SelectedIndex, token) == intCurrentIndex)
            {
                funcAttributePropertySetter.Invoke(objThis.Firewall);
                objThis.Firewall    = strTemp;
                blnRefreshCharacter = true;
            }

            if (blnRefreshCharacter)
            {
                await objThis.RefreshMatrixAttributeComboBoxesAsync(cboAttack, cboSleaze, cboDataProcessing, cboFirewall, token);

                if (objThis.IsActiveCommlink(objCharacter) || objThis.IsHomeNode(objCharacter))
                {
                    if (blnDPChanged)
                    {
                        if (objThis.IsActiveCommlink(objCharacter))
                        {
                            if (objThis.IsHomeNode(objCharacter))
                            {
                                objCharacter.OnMultiplePropertyChanged(nameof(Character.MatrixInitiativeValue),
                                                                       nameof(Character.MatrixInitiativeColdValue),
                                                                       nameof(Character.MatrixInitiativeHotValue));
                            }
                            else
                            {
                                objCharacter.OnMultiplePropertyChanged(nameof(Character.MatrixInitiativeColdValue),
                                                                       nameof(Character.MatrixInitiativeHotValue));
                            }
                        }
                        else
                        {
                            objCharacter.OnPropertyChanged(nameof(Character.MatrixInitiativeValue));
                        }
                    }
                    return(true);
                }
            }

            return(false);
        }
コード例 #3
0
        public static ElasticComboBox PopulateLanguageList(ElasticComboBox myCboLanguage, string myStrSelectedSheet)
        {
            List <ListItem> lstLanguages          = new List <ListItem>();
            string          languageDirectoryPath = Path.Combine(Utils.GetStartupPath, "lang");

            string[] languageFilePaths = Directory.GetFiles(languageDirectoryPath, "*.xml");

            foreach (string filePath in languageFilePaths)
            {
                XmlDocument xmlDocument = new XmlDocument();

                try
                {
                    using (StreamReader objStreamReader = new StreamReader(filePath, Encoding.UTF8, true))
                    {
                        xmlDocument.Load(objStreamReader);
                    }
                }
                catch (IOException)
                {
                    continue;
                }
                catch (XmlException)
                {
                    continue;
                }

                XmlNode node = xmlDocument.SelectSingleNode("/chummer/name");

                if (node == null)
                {
                    continue;
                }

                string strLanguageCode = Path.GetFileNameWithoutExtension(filePath);
                if (GetXslFilesFromLocalDirectory(strLanguageCode).Count > 0)
                {
                    lstLanguages.Add(new ListItem(strLanguageCode, node.InnerText));
                }
            }

            lstLanguages.Sort(CompareListItems.CompareNames);

            string strDefaultSheetLanguage        = GlobalOptions.Language;
            int?   intLastIndexDirectorySeparator = myStrSelectedSheet?.LastIndexOf(Path.DirectorySeparatorChar);

            if (intLastIndexDirectorySeparator.HasValue && (intLastIndexDirectorySeparator != -1))
            {
                string strSheetLanguage = myStrSelectedSheet.Substring(0, intLastIndexDirectorySeparator.Value);
                if (strSheetLanguage.Length == 5)
                {
                    strDefaultSheetLanguage = strSheetLanguage;
                }
            }

            myCboLanguage.BeginUpdate();
            myCboLanguage.ValueMember   = "Value";
            myCboLanguage.DisplayMember = "Name";
            myCboLanguage.DataSource    = lstLanguages;
            myCboLanguage.SelectedValue = strDefaultSheetLanguage;
            if (myCboLanguage.SelectedIndex == -1)
            {
                myCboLanguage.SelectedValue = GlobalOptions.DefaultLanguage;
            }
            myCboLanguage.EndUpdate();
            return(myCboLanguage);
        }
コード例 #4
0
        /// <summary>
        /// Refreshes a set of ComboBoxes corresponding to Matrix attributes
        /// </summary>
        public static async Task RefreshMatrixAttributeComboBoxesAsync(this IHasMatrixAttributes objThis, ElasticComboBox cboAttack, ElasticComboBox cboSleaze, ElasticComboBox cboDataProcessing, ElasticComboBox cboFirewall, CancellationToken token = default)
        {
            token.ThrowIfCancellationRequested();
            if (objThis == null)
            {
                return;
            }
            if (cboAttack == null)
            {
                throw new ArgumentNullException(nameof(cboAttack));
            }
            if (cboSleaze == null)
            {
                throw new ArgumentNullException(nameof(cboSleaze));
            }
            if (cboDataProcessing == null)
            {
                throw new ArgumentNullException(nameof(cboDataProcessing));
            }
            if (cboFirewall == null)
            {
                throw new ArgumentNullException(nameof(cboFirewall));
            }

            int intBaseAttack          = objThis.GetBaseMatrixAttribute("Attack");
            int intBaseSleaze          = objThis.GetBaseMatrixAttribute("Sleaze");
            int intBaseDataProcessing  = objThis.GetBaseMatrixAttribute("Data Processing");
            int intBaseFirewall        = objThis.GetBaseMatrixAttribute("Firewall");
            int intBonusAttack         = objThis.GetBonusMatrixAttribute("Attack");
            int intBonusSleaze         = objThis.GetBonusMatrixAttribute("Sleaze");
            int intBonusDataProcessing = objThis.GetBonusMatrixAttribute("Data Processing");
            int intBonusFirewall       = objThis.GetBonusMatrixAttribute("Firewall");

            await cboAttack.DoThreadSafeAsync(x =>
            {
                x.SuspendLayout();
                x.BeginUpdate();
            }, token);

            await cboSleaze.DoThreadSafeAsync(x =>
            {
                x.SuspendLayout();
                x.BeginUpdate();
            }, token);

            await cboDataProcessing.DoThreadSafeAsync(x =>
            {
                x.SuspendLayout();
                x.BeginUpdate();
            }, token);

            await cboFirewall.DoThreadSafeAsync(x =>
            {
                x.SuspendLayout();
                x.BeginUpdate();
            }, token);

            try
            {
                await cboAttack.DoThreadSafeAsync(x =>
                {
                    x.Enabled        = false;
                    x.BindingContext = new BindingContext();
                    x.DataSource     = new List <string>(4)
                    {
                        (intBaseAttack + intBonusAttack).ToString(GlobalSettings.InvariantCultureInfo),
                        (intBaseSleaze + intBonusAttack).ToString(GlobalSettings.InvariantCultureInfo),
                        (intBaseDataProcessing + intBonusAttack).ToString(GlobalSettings.InvariantCultureInfo),
                        (intBaseFirewall + intBonusAttack).ToString(GlobalSettings.InvariantCultureInfo)
                    };
                    x.SelectedIndex = 0;
                    x.Visible       = true;
                    x.Enabled       = objThis.CanSwapAttributes;
                }, token);

                await cboSleaze.DoThreadSafeAsync(x =>
                {
                    x.Enabled        = false;
                    x.BindingContext = new BindingContext();
                    x.DataSource     = new List <string>(4)
                    {
                        (intBaseAttack + intBonusSleaze).ToString(GlobalSettings.InvariantCultureInfo),
                        (intBaseSleaze + intBonusSleaze).ToString(GlobalSettings.InvariantCultureInfo),
                        (intBaseDataProcessing + intBonusSleaze).ToString(GlobalSettings.InvariantCultureInfo),
                        (intBaseFirewall + intBonusSleaze).ToString(GlobalSettings.InvariantCultureInfo)
                    };
                    x.SelectedIndex = 1;
                    x.Visible       = true;
                    x.Enabled       = objThis.CanSwapAttributes;
                }, token);

                await cboDataProcessing.DoThreadSafeAsync(x =>
                {
                    x.Enabled        = false;
                    x.BindingContext = new BindingContext();
                    x.DataSource     = new List <string>(4)
                    {
                        (intBaseAttack + intBonusDataProcessing).ToString(GlobalSettings.InvariantCultureInfo),
                        (intBaseSleaze + intBonusDataProcessing).ToString(GlobalSettings.InvariantCultureInfo),
                        (intBaseDataProcessing + intBonusDataProcessing).ToString(GlobalSettings.InvariantCultureInfo),
                        (intBaseFirewall + intBonusDataProcessing).ToString(GlobalSettings.InvariantCultureInfo)
                    };
                    x.SelectedIndex = 2;
                    x.Visible       = true;
                    x.Enabled       = objThis.CanSwapAttributes;
                }, token);

                await cboFirewall.DoThreadSafeAsync(x =>
                {
                    x.Enabled        = false;
                    x.BindingContext = new BindingContext();
                    x.DataSource     = new List <string>(4)
                    {
                        (intBaseAttack + intBonusFirewall).ToString(GlobalSettings.InvariantCultureInfo),
                        (intBaseSleaze + intBonusFirewall).ToString(GlobalSettings.InvariantCultureInfo),
                        (intBaseDataProcessing + intBonusFirewall).ToString(GlobalSettings.InvariantCultureInfo),
                        (intBaseFirewall + intBonusFirewall).ToString(GlobalSettings.InvariantCultureInfo)
                    };
                    x.SelectedIndex = 3;
                    x.Visible       = true;
                    x.Enabled       = objThis.CanSwapAttributes;
                }, token);
            }
            finally
            {
                await cboAttack.DoThreadSafeAsync(x =>
                {
                    x.EndUpdate();
                    x.ResumeLayout();
                }, token);

                await cboSleaze.DoThreadSafeAsync(x =>
                {
                    x.EndUpdate();
                    x.ResumeLayout();
                }, token);

                await cboDataProcessing.DoThreadSafeAsync(x =>
                {
                    x.EndUpdate();
                    x.ResumeLayout();
                }, token);

                await cboFirewall.DoThreadSafeAsync(x =>
                {
                    x.EndUpdate();
                    x.ResumeLayout();
                }, token);
            }
        }