private void InitializeTable() { _table = this.DoThreadSafeFunc(() => new TableView <Power> { Dock = DockStyle.Top, ToolTip = _tipTooltip }); // create columns TableColumn <Power> nameColumn = this.DoThreadSafeFunc( () => 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 = this.DoThreadSafeFunc( () => 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 = this.DoThreadSafeFunc(() => 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)); } });
private void InitializeTable() { _table = new TableView <Power> { Location = new Point(3, 3), ToolTip = _tipTooltip }; // create columns TableColumn <Power> nameColumn = new TableColumn <Power>(() => new TextTableCell()) { Text = "Power", Extractor = (power => power.DisplayName), Tag = "String_Power", Sorter = (name1, name2) => string.Compare((string)name1, (string)name2, GlobalOptions.CultureInfo, CompareOptions.Ordinal) }; nameColumn.AddDependency(nameof(Power.DisplayName)); 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, GlobalOptions.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", }; ratingColumn.Sorter = (o1, o2) => { if ((o1 is Power) && (o2 is Power)) { return(((Power)o1).Rating - ((Power)o2).Rating); } string msg = "Can't sort an Object of Type " + o1.GetType() + " against another one of Type " + o2.GetType() + " in the ratingColumn." + Environment.NewLine; msg += "Both objects SHOULD be of the type \"Power\"."; throw new ArgumentException(msg, 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", }; totalRatingColumn.Sorter = (o1, o2) => { if ((o1 is Power) && (o2 is Power)) { return(((Power)o1).TotalRating - ((Power)o2).TotalRating); } string msg = "Can't sort an Object of Type " + o1.GetType() + " against another one of Type " + o2.GetType() + " in the totalRatingColumn." + Environment.NewLine; msg += "Both objects SHOULD be of the type \"Power\"."; throw new ArgumentException(msg, 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()) { 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), Alignment = Alignment.Center }) { Text = "Adept Way", Tag = "Checkbox_Power_AdeptWay" }; adeptWayColumn.AddDependency(nameof(Power.DiscountedAdeptWay)); adeptWayColumn.AddDependency(nameof(Power.AdeptWayDiscountEnabled)); 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 = Properties.Resources.note_edit, Size = GetImageSize(Properties.Resources.note_edit), }) { ClickHandler = p => { frmNotes frmPowerNotes = new frmNotes { Notes = p.Notes }; frmPowerNotes.ShowDialog(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", GlobalOptions.Language); if (!string.IsNullOrEmpty(p.Notes)) { strTooltip += Environment.NewLine + Environment.NewLine + p.Notes; } return(strTooltip.WordWrap(100)); }) }; noteColumn.AddDependency(nameof(Power.Notes)); TableColumn <Power> deleteColumn = new TableColumn <Power>(() => new ButtonTableCell <Power>(new Button() { Text = "Delete", Tag = "String_Delete", BackColor = SystemColors.Control }) { ClickHandler = p => { //Cache the parentform prior to deletion, otherwise the relationship is broken. Form frmParent = ParentForm; if (p.FreeLevels > 0) { string strImprovementSourceName = p.CharacterObject.Improvements.FirstOrDefault(x => x.ImproveType == Improvement.ImprovementType.AdeptPowerFreePoints && x.ImprovedName == p.Name && x.UniqueName == p.Extra)?.SourceName; Gear objGear = p.CharacterObject.Gear.FirstOrDefault(x => x.Bonded && x.InternalId == strImprovementSourceName); if (objGear != null) { objGear.Equipped = false; objGear.Extra = string.Empty; } } p.DeletePower(); p.UnbindPower(); if (frmParent is CharacterShared objParent) { objParent.IsCharacterUpdateRequested = true; } }, EnabledExtractor = (p => p.FreeLevels == 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) });