Exemple #1
0
        private async ValueTask DoLanguageUpdate()
        {
            if (!_blnLoading)
            {
                _strExportLanguage = cboLanguage.SelectedValue?.ToString() ?? GlobalSettings.Language;
                try
                {
                    _objExportCulture = CultureInfo.GetCultureInfo(_strExportLanguage);
                }
                catch (CultureNotFoundException)
                {
                    // Swallow this
                }

                _objCharacterXml = null;
                await Task.WhenAll(
                    imgSheetLanguageFlag.DoThreadSafeAsync(() =>
                                                           imgSheetLanguageFlag.Image
                                                               = Math.Min(imgSheetLanguageFlag.Width,
                                                                          imgSheetLanguageFlag.Height) >= 32
                                                                       ? FlagImageGetter.GetFlagFromCountryCode192Dpi(
                                                                     _strExportLanguage.Substring(3, 2))
                                                                       : FlagImageGetter.GetFlagFromCountryCode(
                                                                     _strExportLanguage.Substring(3, 2))),
                    DoXsltUpdate().AsTask());
            }
        }
        private async Task DoLanguageUpdate(CancellationToken token = default)
        {
            token.ThrowIfCancellationRequested();
            if (!_blnLoading)
            {
                _strExportLanguage = await cboLanguage.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString(), token) ?? GlobalSettings.Language;

                try
                {
                    _objExportCulture = CultureInfo.GetCultureInfo(_strExportLanguage);
                }
                catch (CultureNotFoundException)
                {
                    // Swallow this
                }

                _objCharacterXml = null;
                token.ThrowIfCancellationRequested();
                await Task.WhenAll(
                    imgSheetLanguageFlag.DoThreadSafeAsync(x =>
                                                           x.Image
                                                               = Math.Min(x.Width, x.Height) >= 32
                                                                       ? FlagImageGetter.GetFlagFromCountryCode192Dpi(
                                                                     _strExportLanguage.Substring(3, 2))
                                                                       : FlagImageGetter.GetFlagFromCountryCode(
                                                                     _strExportLanguage.Substring(3, 2)), token),
                    DoXsltUpdate(token));

                token.ThrowIfCancellationRequested();
            }
        }
        private void cboLanguage_SelectedIndexChanged(object sender, EventArgs e)
        {
            _strPrintLanguage          = cboLanguage.SelectedValue?.ToString() ?? GlobalOptions.Language;
            imgSheetLanguageFlag.Image = FlagImageGetter.GetFlagFromCountryCode(_strPrintLanguage.Substring(3, 2));
            try
            {
                _objPrintCulture = CultureInfo.GetCultureInfo(_strPrintLanguage);
            }
            catch (CultureNotFoundException)
            {
            }
            if (_blnLoading)
            {
                return;
            }

            string strOldSelected = _strSelectedSheet;

            // Strip away the language prefix
            if (strOldSelected.Contains(Path.DirectorySeparatorChar))
            {
                strOldSelected = strOldSelected.Substring(strOldSelected.LastIndexOf(Path.DirectorySeparatorChar) + 1);
            }
            _blnLoading = true;
            PopulateXsltList();
            string strNewLanguage = cboLanguage.SelectedValue?.ToString() ?? strOldSelected;

            if (strNewLanguage == strOldSelected)
            {
                _strSelectedSheet = strNewLanguage == GlobalOptions.DefaultLanguage ? strOldSelected : Path.Combine(strNewLanguage, strOldSelected);
            }
            cboXSLT.SelectedValue = _strSelectedSheet;
            // If the desired sheet was not found, fall back to the Shadowrun 5 sheet.
            if (cboXSLT.SelectedIndex == -1)
            {
                var intNameIndex = cboXSLT.FindStringExact(strNewLanguage == GlobalOptions.DefaultLanguage ? GlobalOptions.DefaultCharacterSheet : GlobalOptions.DefaultCharacterSheet.Substring(strNewLanguage.LastIndexOf(Path.DirectorySeparatorChar) + 1));
                if (intNameIndex != -1)
                {
                    cboXSLT.SelectedIndex = intNameIndex;
                }
                else if (cboXSLT.Items.Count > 0)
                {
                    _strSelectedSheet     = strNewLanguage == GlobalOptions.DefaultLanguage ? GlobalOptions.DefaultCharacterSheetDefaultValue : Path.Combine(strNewLanguage, GlobalOptions.DefaultCharacterSheetDefaultValue);
                    cboXSLT.SelectedValue = _strSelectedSheet;
                    if (cboXSLT.SelectedIndex == -1)
                    {
                        cboXSLT.SelectedIndex = 0;
                        _strSelectedSheet     = cboXSLT.SelectedValue?.ToString();
                    }
                }
            }
            _blnLoading = false;
            RefreshCharacters();
        }
Exemple #4
0
        private void cboLanguage_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnLoading)
            {
                return;
            }
            _strExportLanguage         = cboLanguage.SelectedValue?.ToString() ?? GlobalOptions.Language;
            imgSheetLanguageFlag.Image = FlagImageGetter.GetFlagFromCountryCode(_strExportLanguage.Substring(3, 2));
            try
            {
                _objExportCulture = CultureInfo.GetCultureInfo(_strExportLanguage);
            }
            catch (CultureNotFoundException)
            {
            }

            _objCharacterXml = null;
            cboXSLT_SelectedIndexChanged(sender, e);
        }
Exemple #5
0
        private async void cboLanguage_SelectedIndexChanged(object sender, EventArgs e)
        {
            _strPrintLanguage          = cboLanguage.SelectedValue?.ToString() ?? GlobalSettings.Language;
            imgSheetLanguageFlag.Image = Math.Min(imgSheetLanguageFlag.Width, imgSheetLanguageFlag.Height) >= 32
                ? FlagImageGetter.GetFlagFromCountryCode192Dpi(_strPrintLanguage.Substring(3, 2))
                : FlagImageGetter.GetFlagFromCountryCode(_strPrintLanguage.Substring(3, 2));
            try
            {
                _objPrintCulture = CultureInfo.GetCultureInfo(_strPrintLanguage);
            }
            catch (CultureNotFoundException)
            {
                // Swallow this
            }

            if (!_blnLoading)
            {
                _blnLoading = true;
                string strOldSelected = _strSelectedSheet;
                // Strip away the language prefix
                if (strOldSelected.Contains(Path.DirectorySeparatorChar))
                {
                    strOldSelected
                        = strOldSelected.Substring(strOldSelected.LastIndexOf(Path.DirectorySeparatorChar) + 1);
                }
                PopulateXsltList();
                string strNewLanguage = cboLanguage.SelectedValue?.ToString() ?? strOldSelected;
                if (strNewLanguage == strOldSelected)
                {
                    _strSelectedSheet
                        = strNewLanguage.Equals(GlobalSettings.DefaultLanguage, StringComparison.OrdinalIgnoreCase)
                            ? strOldSelected
                            : Path.Combine(strNewLanguage, strOldSelected);
                }

                cboXSLT.SelectedValue = _strSelectedSheet;
                // If the desired sheet was not found, fall back to the Shadowrun 5 sheet.
                if (cboXSLT.SelectedIndex == -1)
                {
                    int intNameIndex = cboXSLT.FindStringExact(
                        strNewLanguage.Equals(GlobalSettings.DefaultLanguage, StringComparison.OrdinalIgnoreCase)
                            ? GlobalSettings.DefaultCharacterSheet
                            : GlobalSettings.DefaultCharacterSheet.Substring(
                            strNewLanguage.LastIndexOf(Path.DirectorySeparatorChar) + 1));
                    if (intNameIndex != -1)
                    {
                        cboXSLT.SelectedIndex = intNameIndex;
                    }
                    else if (cboXSLT.Items.Count > 0)
                    {
                        _strSelectedSheet
                            = strNewLanguage.Equals(GlobalSettings.DefaultLanguage, StringComparison.OrdinalIgnoreCase)
                                ? GlobalSettings.DefaultCharacterSheetDefaultValue
                                : Path.Combine(strNewLanguage, GlobalSettings.DefaultCharacterSheetDefaultValue);
                        cboXSLT.SelectedValue = _strSelectedSheet;
                        if (cboXSLT.SelectedIndex == -1)
                        {
                            cboXSLT.SelectedIndex = 0;
                            _strSelectedSheet     = cboXSLT.SelectedValue?.ToString();
                        }
                    }
                }

                _blnLoading = false;
                await RefreshCharacters();
            }
        }