Ejemplo n.º 1
0
        private async void cmdEditCharacterOption_Click(object sender, EventArgs e)
        {
            using (await CursorWait.NewAsync(this))
            {
                object objOldSelected = await cboCharacterSetting.DoThreadSafeFuncAsync(x => x.SelectedValue);

                using (ThreadSafeForm <EditCharacterSettings> frmOptions
                           = await ThreadSafeForm <EditCharacterSettings> .GetAsync(
                                 () => new EditCharacterSettings(objOldSelected as CharacterSettings)))
                    await frmOptions.ShowDialogSafeAsync(this);

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

                try
                {
                    // Populate the Gameplay Settings list.
                    using (new FetchSafelyFromPool <List <ListItem> >(
                               Utils.ListItemListPool, out List <ListItem> lstGameplayOptions))
                    {
                        lstGameplayOptions.AddRange(SettingsManager.LoadedCharacterSettings.Values
                                                    .Select(objLoopOptions =>
                                                            new ListItem(
                                                                objLoopOptions,
                                                                objLoopOptions.DisplayName)));
                        lstGameplayOptions.Sort(CompareListItems.CompareNames);
                        await cboCharacterSetting.PopulateWithListItemsAsync(lstGameplayOptions);

                        await cboCharacterSetting.DoThreadSafeAsync(x => x.SelectedValue = objOldSelected);

                        if (await cboCharacterSetting.DoThreadSafeFuncAsync(x => x.SelectedIndex) == -1 &&
                            lstGameplayOptions.Count > 0)
                        {
                            (bool blnSuccess, CharacterSettings objSetting)
                                = await SettingsManager.LoadedCharacterSettings.TryGetValueAsync(
                                      GlobalSettings.DefaultCharacterSetting);

                            await cboCharacterSetting.DoThreadSafeAsync(x =>
                            {
                                if (blnSuccess)
                                {
                                    x.SelectedValue = objSetting;
                                }
                                if (x.SelectedIndex == -1 && lstGameplayOptions.Count > 0)
                                {
                                    x.SelectedIndex = 0;
                                }
                            });
                        }
                    }
                }
                finally
                {
                    await this.DoThreadSafeAsync(x => x.ResumeLayout());
                }
            }
        }
Ejemplo n.º 2
0
 private async void cmdEditCharacterSetting_Click(object sender, EventArgs e)
 {
     try
     {
         using (await CursorWait.NewAsync(this, token: _objGenericToken))
         {
             using (ThreadSafeForm <EditCharacterSettings> frmOptions = await ThreadSafeForm <EditCharacterSettings> .GetAsync(
                        () => new EditCharacterSettings(cboCharacterSetting.SelectedValue as CharacterSettings), _objGenericToken))
                 await frmOptions.ShowDialogSafeAsync(this, _objGenericToken);
             // Do not repopulate the character settings list because that will happen from frmCharacterSettings where appropriate
         }
     }
     catch (OperationCanceledException)
     {
         //swallow this
     }
 }
Ejemplo n.º 3
0
        private async void cmdNotes_Click(object sender, EventArgs e)
        {
            using (ThreadSafeForm <EditNotes> frmSpiritNotes = await ThreadSafeForm <EditNotes> .GetAsync(() => new EditNotes(_objSpirit.Notes, _objSpirit.NotesColor)))
            {
                if (await frmSpiritNotes.ShowDialogSafeAsync(_objSpirit.CharacterObject) != DialogResult.OK)
                {
                    return;
                }
                _objSpirit.Notes = frmSpiritNotes.MyForm.Notes;
            }

            string strTooltip = await LanguageManager.GetStringAsync(_objSpirit.EntityType == SpiritType.Spirit? "Tip_Spirit_EditNotes" : "Tip_Sprite_EditNotes");

            if (!string.IsNullOrEmpty(_objSpirit.Notes))
            {
                strTooltip += Environment.NewLine + Environment.NewLine + _objSpirit.Notes;
            }
            await cmdNotes.SetToolTipTextAsync(strTooltip.WordWrap());

            ContactDetailChanged?.Invoke(this, e);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Writes notes to an IHasNotes object, returns True if notes were changed and False otherwise.
        /// </summary>
        /// <param name="objNotes"></param>
        /// <param name="treNode"></param>
        public static async ValueTask <bool> WriteNotes(this IHasNotes objNotes, TreeNode treNode)
        {
            if (objNotes == null || treNode == null)
            {
                return(false);
            }
            TreeView objTreeView = treNode.TreeView;
            Form     frmToUse    = objTreeView != null
                ? await objTreeView.DoThreadSafeFuncAsync(x => x.FindForm()) ?? Program.MainForm
                : Program.MainForm;

            using (ThreadSafeForm <EditNotes> frmItemNotes = await ThreadSafeForm <EditNotes> .GetAsync(() => new EditNotes(objNotes.Notes, objNotes.NotesColor)))
            {
                if (await frmItemNotes.ShowDialogSafeAsync(frmToUse) != DialogResult.OK)
                {
                    return(false);
                }

                objNotes.Notes      = frmItemNotes.MyForm.Notes;
                objNotes.NotesColor = frmItemNotes.MyForm.NotesColor;
            }

            if (objTreeView != null)
            {
                await objTreeView.DoThreadSafeAsync(() =>
                {
                    treNode.ForeColor   = objNotes.PreferredColor;
                    treNode.ToolTipText = objNotes.Notes.WordWrap();
                });
            }
            else
            {
                treNode.ForeColor   = objNotes.PreferredColor;
                treNode.ToolTipText = objNotes.Notes.WordWrap();
            }

            return(true);
        }
        private async void cmdAddQuality_Click(object sender, EventArgs e)
        {
            string strBaseLifestyle = await cboBaseLifestyle.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString()) ?? string.Empty;

            bool blnAddAgain;

            do
            {
                using (ThreadSafeForm <SelectLifestyleQuality> frmSelectLifestyleQuality =
                           await ThreadSafeForm <SelectLifestyleQuality> .GetAsync(() => new SelectLifestyleQuality(_objCharacter,
                                                                                                                    strBaseLifestyle, _objLifestyle.LifestyleQualities)))
                {
                    // Don't do anything else if the form was canceled.
                    if (await frmSelectLifestyleQuality.ShowDialogSafeAsync(this) == DialogResult.Cancel)
                    {
                        return;
                    }
                    blnAddAgain = frmSelectLifestyleQuality.MyForm.AddAgain;

                    XmlNode objXmlQuality = _xmlDocument.SelectSingleNode("/chummer/qualities/quality[id = " + frmSelectLifestyleQuality.MyForm.SelectedQuality.CleanXPath() + ']');

                    LifestyleQuality objQuality = new LifestyleQuality(_objCharacter);

                    objQuality.Create(objXmlQuality, _objLifestyle, _objCharacter, QualitySource.Selected);
                    //objNode.ContextMenuStrip = cmsQuality;
                    if (objQuality.InternalId.IsEmptyGuid())
                    {
                        objQuality.Remove(false);
                        objQuality.Dispose();
                        continue;
                    }
                    objQuality.Free = frmSelectLifestyleQuality.MyForm.FreeCost;

                    await _objLifestyle.LifestyleQualities.AddAsync(objQuality);
                }
            }while (blnAddAgain);
        }
Ejemplo n.º 6
0
        private async Task DoImport(CancellationToken token = default)
        {
            TreeNode objSelectedNode = await treCharacterList.DoThreadSafeFuncAsync(x => x.SelectedNode, token);

            if (objSelectedNode == null || objSelectedNode.Level <= 0)
            {
                return;
            }
            int intIndex = Convert.ToInt32(objSelectedNode.Tag, GlobalSettings.InvariantCultureInfo);

            if (intIndex < 0 || intIndex >= _lstCharacterCache.Count)
            {
                return;
            }
            HeroLabCharacterCache objCache = _lstCharacterCache[intIndex];

            if (objCache == null)
            {
                return;
            }
            string strFile        = objCache.FilePath;
            string strCharacterId = objCache.CharacterId;

            if (string.IsNullOrEmpty(strFile) || string.IsNullOrEmpty(strCharacterId))
            {
                return;
            }
            using (await CursorWait.NewAsync(this, token: token))
            {
                bool      blnLoaded    = false;
                Character objCharacter = new Character();
                try
                {
                    await Program.OpenCharacters.AddAsync(objCharacter);

                    CharacterSettings objHeroLabSettings =
                        SettingsManager.LoadedCharacterSettings.Values.FirstOrDefault(
                            x => x.Name == objCache.SettingsName && x.BuildMethod == objCache.BuildMethod);
                    if (objHeroLabSettings != null)
                    {
                        objCharacter.SettingsKey = objHeroLabSettings.DictionaryKey;
                    }
                    else
                    {
                        objHeroLabSettings = SettingsManager.LoadedCharacterSettings.Values.FirstOrDefault(
                            x => x.Name.Contains(objCache.SettingsName) && x.BuildMethod == objCache.BuildMethod);
                        if (objHeroLabSettings != null)
                        {
                            objCharacter.SettingsKey = objHeroLabSettings.DictionaryKey;
                        }
                        else
                        {
                            (bool blnSuccess, CharacterSettings objDefaultCharacterSettings)
                                = await SettingsManager.LoadedCharacterSettings.TryGetValueAsync(
                                      GlobalSettings.DefaultCharacterSetting, token);

                            if (blnSuccess && objCache.BuildMethod.UsesPriorityTables()
                                == objDefaultCharacterSettings.BuildMethod.UsesPriorityTables())
                            {
                                objCharacter.SettingsKey = objDefaultCharacterSettings.DictionaryKey;
                            }
                            else
                            {
                                objCharacter.SettingsKey = SettingsManager.LoadedCharacterSettings.Values
                                                           .FirstOrDefault(
                                    x => x.BuiltInOption &&
                                    x.BuildMethod == objCache.BuildMethod)
                                                           ?.DictionaryKey
                                                           ?? SettingsManager.LoadedCharacterSettings.Values
                                                           .FirstOrDefault(
                                    x => x.BuiltInOption &&
                                    x.BuildMethod.UsesPriorityTables()
                                    == objCache.BuildMethod
                                    .UsesPriorityTables())
                                                           ?.DictionaryKey
                                                           ?? GlobalSettings.DefaultCharacterSetting;
                            }
                        }
                    }

                    using (ThreadSafeForm <SelectBuildMethod> frmPickBP = await ThreadSafeForm <SelectBuildMethod> .GetAsync(() => new SelectBuildMethod(objCharacter, true), token))
                    {
                        if (await frmPickBP.ShowDialogSafeAsync(this, token) != DialogResult.OK)
                        {
                            return;
                        }
                    }

                    //Timekeeper.Start("load_file");
                    if (!await objCharacter.LoadFromHeroLabFileAsync(strFile, strCharacterId, objCharacter.SettingsKey))
                    {
                        return;
                    }
                    blnLoaded = true;
                    //Timekeeper.Finish("load_file");
                    await Program.OpenCharacter(objCharacter, token : token);
                }
                finally
                {
                    await cmdImport.DoThreadSafeAsync(x => x.Enabled = true, token);

                    await cmdSelectFile.DoThreadSafeAsync(x => x.Enabled = true, token);

                    if (!blnLoaded)
                    {
                        await Program.OpenCharacters.RemoveAsync(objCharacter);
                    }
                }
            }

            await this.DoThreadSafeAsync(x => x.Close(), token);
        }