コード例 #1
0
        /// <summary>
        /// Allows the user to input notes that should be linked to the selected object.
        /// TODO: Should be linked back to CharacterShared in some way or moved into a more generic helper class.
        /// </summary>
        /// <param name="objNotes"></param>
        /// <param name="treNode"></param>
        private async ValueTask WriteNotes(IHasNotes objNotes, TreeNode treNode)
        {
            using (EditNotes frmItemNotes = new EditNotes(objNotes.Notes, objNotes.NotesColor))
            {
                await frmItemNotes.ShowDialogSafeAsync(this);

                if (frmItemNotes.DialogResult != DialogResult.OK)
                {
                    return;
                }

                objNotes.Notes      = frmItemNotes.Notes;
                objNotes.NotesColor = frmItemNotes.NotesColor;
            }
            treNode.ForeColor   = objNotes.PreferredColor;
            treNode.ToolTipText = objNotes.Notes.WordWrap();
            MakeDirty?.Invoke(this, EventArgs.Empty);
        }
コード例 #2
0
        private async void tssLimitModifierNotes_Click(object sender, EventArgs e)
        {
            if (treLimit.SelectedNode == null)
            {
                return;
            }
            if (treLimit.SelectedNode?.Tag is IHasNotes objNotes)
            {
                await WriteNotes(objNotes, treLimit.SelectedNode);
            }
            else
            {
                // the limit modifier has a source
                foreach (Improvement objImprovement in _objCharacter.Improvements)
                {
                    if (objImprovement.ImproveType != Improvement.ImprovementType.LimitModifier ||
                        objImprovement.SourceName != treLimit.SelectedNode?.Tag.ToString())
                    {
                        continue;
                    }
                    using (EditNotes frmItemNotes = new EditNotes(objImprovement.Notes, objImprovement.NotesColor))
                    {
                        await frmItemNotes.ShowDialogSafeAsync(this);

                        if (frmItemNotes.DialogResult != DialogResult.OK)
                        {
                            continue;
                        }

                        objImprovement.Notes = frmItemNotes.Notes;
                    }
                    treLimit.SelectedNode.ForeColor   = objImprovement.PreferredColor;
                    treLimit.SelectedNode.ToolTipText = objImprovement.Notes.WordWrap();
                    MakeDirty?.Invoke(this, EventArgs.Empty);
                }
            }
        }
コード例 #3
0
        private void InitializeTable()
        {
            _table = new TableView <Power>
            {
                Dock    = DockStyle.Top,
                ToolTip = _tipTooltip
            };
            // create columns
            TableColumn <Power> nameColumn = new TableColumn <Power>(() => new TextTableCell())
            {
                Text      = "Power",
                Extractor = (power => power.CurrentDisplayName),
                Tag       = "String_Power",
                Sorter    = (name1, name2) => string.Compare((string)name1, (string)name2, GlobalSettings.CultureInfo, CompareOptions.Ordinal)
            };

            nameColumn.AddDependency(nameof(Power.CurrentDisplayName));

            TableColumn <Power> actionColumn = new TableColumn <Power>(() => new TextTableCell())
            {
                Text      = "Action",
                Extractor = (power => power.DisplayAction),
                Tag       = "ColumnHeader_Action",
                Sorter    = (action1, action2) => string.Compare((string)action1, (string)action2, GlobalSettings.CultureInfo, CompareOptions.Ordinal)
            };

            actionColumn.AddDependency(nameof(Power.DisplayAction));

            TableColumn <Power> ratingColumn = new TableColumn <Power>(() => new SpinnerTableCell <Power>(_table)
            {
                EnabledExtractor = (p => p.LevelsEnabled),
                MaxExtractor     = (p => Math.Max(p.TotalMaximumLevels - p.FreeLevels, 0)),
                ValueUpdater     = (p, newRating) =>
                {
                    int delta = ((int)newRating) - p.Rating;
                    if (delta != 0)
                    {
                        p.Rating += delta;
                    }
                },
                MinExtractor = (p => 0),
                ValueGetter  = (p => p.Rating)
            })
            {
                Text   = "Rating",
                Tag    = "String_Rating",
                Sorter = (o1, o2) =>
                {
                    if (o1 is Power objPower1 && o2 is Power objPower2)
                    {
                        return(objPower1.Rating - objPower2.Rating);
                    }
                    string strMessage = "Can't sort an Object of Type " + o1.GetType() +
                                        " against another one of Type " + o2.GetType() + " in the ratingColumn." +
                                        Environment.NewLine + "Both objects SHOULD be of the type \"Power\".";
                    throw new ArgumentException(strMessage, nameof(o1));
                }
            };

            ratingColumn.AddDependency(nameof(Power.LevelsEnabled));
            ratingColumn.AddDependency(nameof(Power.FreeLevels));
            ratingColumn.AddDependency(nameof(Power.TotalMaximumLevels));
            ratingColumn.AddDependency(nameof(Power.TotalRating));
            TableColumn <Power> totalRatingColumn = new TableColumn <Power>(() => new TextTableCell())
            {
                Text      = "Total Rating",
                Extractor = (power => power.TotalRating),
                Tag       = "String_TotalRating",
                Sorter    = (o1, o2) =>
                {
                    if (o1 is Power objPower1 && o2 is Power objPower2)
                    {
                        return(objPower1.TotalRating - objPower2.TotalRating);
                    }
                    string strMessage = "Can't sort an Object of Type " + o1.GetType() +
                                        " against another one of Type " + o2.GetType() + " in the totalRatingColumn." +
                                        Environment.NewLine + "Both objects SHOULD be of the type \"Power\".";
                    throw new ArgumentException(strMessage, nameof(o1));
                }
            };

            totalRatingColumn.AddDependency(nameof(Power.TotalRating));

            TableColumn <Power> powerPointsColumn = new TableColumn <Power>(() => new TextTableCell())
            {
                Text             = "Power Points",
                Extractor        = (power => power.DisplayPoints),
                Tag              = "ColumnHeader_Power_Points",
                ToolTipExtractor = (item => item.ToolTip)
            };

            powerPointsColumn.AddDependency(nameof(Power.DisplayPoints));
            powerPointsColumn.AddDependency(nameof(Power.ToolTip));

            TableColumn <Power> sourceColumn = new TableColumn <Power>(() => new TextTableCell
            {
                Cursor = Cursors.Hand
            })
            {
                Text             = "Source",
                Extractor        = (power => power.SourceDetail),
                Tag              = "Label_Source",
                ToolTipExtractor = (item => item.SourceDetail.LanguageBookTooltip)
            };

            powerPointsColumn.AddDependency(nameof(Power.Source));

            TableColumn <Power> adeptWayColumn = new TableColumn <Power>(() => new CheckBoxTableCell <Power>
            {
                ValueGetter      = p => p.DiscountedAdeptWay,
                ValueUpdater     = (p, check) => p.DiscountedAdeptWay = check,
                VisibleExtractor = p => p.AdeptWayDiscountEnabled,
                EnabledExtractor = p => p.CharacterObject.AllowAdeptWayPowerDiscount || p.DiscountedAdeptWay,
                Alignment        = Alignment.Center
            })
            {
                Text = "Adept Way",
                Tag  = "Checkbox_Power_AdeptWay"
            };

            adeptWayColumn.AddDependency(nameof(Power.DiscountedAdeptWay));
            adeptWayColumn.AddDependency(nameof(Power.AdeptWayDiscountEnabled));
            adeptWayColumn.AddDependency(nameof(Character.AllowAdeptWayPowerDiscount));
            adeptWayColumn.AddDependency(nameof(Power.Rating));

            /*
             * TableColumn<Power> geasColumn = new TableColumn<Power>(() => new CheckBoxTableCell<Power>()
             * {
             *  ValueGetter = (p => p.DiscountedGeas),
             *  ValueUpdater = (p, check) => p.DiscountedGeas = check,
             *  Alignment = Alignment.Center
             * })
             * {
             *  Text = "Geas",
             *  Tag = "Checkbox_Power_Geas"
             * };
             * geasColumn.AddDependency(nameof(Power.DiscountedGeas));
             */

            TableColumn <Power> noteColumn = new TableColumn <Power>(() => new ButtonTableCell <Power>(new PictureBox
            {
                Image = Resources.note_edit,
                Size  = GetImageSize(Resources.note_edit)
            })
            {
                ClickHandler = async p =>
                {
                    using (EditNotes frmPowerNotes = new EditNotes(p.Notes, p.NotesColor))
                    {
                        await frmPowerNotes.ShowDialogSafeAsync(this);
                        if (frmPowerNotes.DialogResult == DialogResult.OK)
                        {
                            p.Notes = frmPowerNotes.Notes;
                        }
                    }
                },
                Alignment = Alignment.Center
            })
            {
                Text             = "Notes",
                Tag              = "ColumnHeader_Notes",
                ToolTipExtractor = (p =>
                {
                    string strTooltip = LanguageManager.GetString("Tip_Power_EditNotes");
                    if (!string.IsNullOrEmpty(p.Notes))
                    {
                        strTooltip += Environment.NewLine + Environment.NewLine + p.Notes.RtfToPlainText();
                    }
                    return(strTooltip.WordWrap());
                })
            };

            noteColumn.AddDependency(nameof(Power.Notes));

            TableColumn <Power> deleteColumn = new TableColumn <Power>(() => new ButtonTableCell <Power>(new Button
            {
                Text = LanguageManager.GetString("String_Delete"),
                Tag  = "String_Delete",
                Dock = DockStyle.Fill
            })
            {
                ClickHandler = p =>
                {
                    //Cache the parentform prior to deletion, otherwise the relationship is broken.
                    Form frmParent = ParentForm;
                    if (p.FreeLevels > 0)
                    {
                        string strExtra = p.Extra;
                        string strImprovementSourceName = ImprovementManager.GetCachedImprovementListForValueOf(p.CharacterObject, Improvement.ImprovementType.AdeptPowerFreePoints, p.Name)
                                                          .Find(x => x.UniqueName == strExtra)?.SourceName;
                        if (!string.IsNullOrWhiteSpace(strImprovementSourceName))
                        {
                            Gear objGear = p.CharacterObject.Gear.FindById(strImprovementSourceName);
                            if (objGear?.Bonded == true)
                            {
                                objGear.Equipped = false;
                                objGear.Extra    = string.Empty;
                            }
                        }
                    }
                    p.DeletePower();
                    p.UnbindPower();

                    if (frmParent is CharacterShared objParent)
                    {
                        objParent.IsCharacterUpdateRequested = true;
                    }
                    return(Task.CompletedTask);
                },
                EnabledExtractor = (p => p.FreeLevels == 0)
            });