Skip to content

Commit

Permalink
Closes #860: Allow hiding the library source column
Browse files Browse the repository at this point in the history
  • Loading branch information
richardwilkes committed Jul 19, 2024
1 parent 078df6b commit 83f439a
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 11 deletions.
1 change: 1 addition & 0 deletions model/gurps/sheet_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type SheetSettingsData struct {
ShowTraitModifierAdj bool `json:"show_trait_modifier_adj,alt=show_advantage_modifier_adj,omitempty"`
ShowEquipmentModifierAdj bool `json:"show_equipment_modifier_adj,omitempty"`
ShowSpellAdj bool `json:"show_spell_adj,omitempty"`
HideSourceMismatch bool `json:"hide_source_mismatch,omitempty"`
UseTitleInFooter bool `json:"use_title_in_footer,omitempty"`
ExcludeUnspentPointsFromTotal bool `json:"exclude_unspent_points_from_total"`
}
Expand Down
4 changes: 3 additions & 1 deletion ux/equipment_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ func (p *equipmentProvider) ColumnIDs() []int {
}
columnIDs = append(columnIDs, gurps.EquipmentReferenceColumn)
if p.forPage {
columnIDs = append(columnIDs, gurps.EquipmentLibSrcColumn)
if entity := p.DataOwner().OwningEntity(); entity != nil && !entity.SheetSettings.HideSourceMismatch {
columnIDs = append(columnIDs, gurps.EquipmentLibSrcColumn)
}
}
return columnIDs
}
Expand Down
4 changes: 3 additions & 1 deletion ux/notes_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ func (p *notesProvider) ColumnIDs() []int {
gurps.NoteReferenceColumn,
}
if p.forPage {
columnIDs = append(columnIDs, gurps.NoteLibSrcColumn)
if entity := p.DataOwner().OwningEntity(); entity != nil && !entity.SheetSettings.HideSourceMismatch {
columnIDs = append(columnIDs, gurps.NoteLibSrcColumn)
}
}
return columnIDs
}
Expand Down
16 changes: 16 additions & 0 deletions ux/page_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ func newPageList[T gurps.NodeTypes](owner Rebuildable, provider TableProvider[T]
return p
}

func (p *PageList[T]) needReconstruction() bool {
if p == nil {
return true
}
ids := p.provider.ColumnIDs()
if len(ids) != len(p.Table.Columns) {
return true
}
for i, col := range p.Table.Columns {
if col.ID != ids[i] {
return true
}
}
return false
}

func (p *PageList[T]) installMoveToCarriedEquipmentHandler(owner Rebuildable) {
if sheet, ok := owner.AsPanel().Self.(*Sheet); ok {
var t *unison.Table[*Node[*gurps.Equipment]]
Expand Down
12 changes: 6 additions & 6 deletions ux/sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,42 +634,42 @@ func (s *Sheet) createLists() {
rowPanel.AddChild(s.RangedWeapons)
}
case gurps.BlockLayoutTraitsKey:
if s.Traits == nil {
if s.Traits.needReconstruction() {
s.Traits = NewTraitsPageList(s, s.entity)
} else {
s.Traits.Sync()
}
rowPanel.AddChild(s.Traits)
case gurps.BlockLayoutSkillsKey:
if s.Skills == nil {
if s.Skills.needReconstruction() {
s.Skills = NewSkillsPageList(s, s.entity)
} else {
s.Skills.Sync()
}
rowPanel.AddChild(s.Skills)
case gurps.BlockLayoutSpellsKey:
if s.Spells == nil {
if s.Spells.needReconstruction() {
s.Spells = NewSpellsPageList(s, s.entity)
} else {
s.Spells.Sync()
}
rowPanel.AddChild(s.Spells)
case gurps.BlockLayoutEquipmentKey:
if s.CarriedEquipment == nil {
if s.CarriedEquipment.needReconstruction() {
s.CarriedEquipment = NewCarriedEquipmentPageList(s, s.entity)
} else {
s.CarriedEquipment.Sync()
}
rowPanel.AddChild(s.CarriedEquipment)
case gurps.BlockLayoutOtherEquipmentKey:
if s.OtherEquipment == nil {
if s.OtherEquipment.needReconstruction() {
s.OtherEquipment = NewOtherEquipmentPageList(s, s.entity)
} else {
s.OtherEquipment.Sync()
}
rowPanel.AddChild(s.OtherEquipment)
case gurps.BlockLayoutNotesKey:
if s.Notes == nil {
if s.Notes.needReconstruction() {
s.Notes = NewNotesPageList(s, s.entity)
} else {
s.Notes.Sync()
Expand Down
7 changes: 7 additions & 0 deletions ux/sheet_settings_dockable.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type sheetSettingsDockable struct {
showTraitModifier *unison.CheckBox
showEquipmentModifier *unison.CheckBox
showSpellAdjustments *unison.CheckBox
hideSourceMismatch *unison.CheckBox
showTitleInsteadOfNameInPageFooter *unison.CheckBox
useMultiplicativeModifiers *unison.CheckBox
useModifyDicePlusAdds *unison.CheckBox
Expand Down Expand Up @@ -149,6 +150,11 @@ func (d *sheetSettingsDockable) createOptions(content *unison.Panel) {
HSpacing: unison.StdHSpacing,
VSpacing: unison.StdVSpacing,
})
d.hideSourceMismatch = d.addCheckBox(panel, i18n.Text("Show library source column"),
!s.HideSourceMismatch, func() {
d.settings().HideSourceMismatch = d.hideSourceMismatch.State != check.On
d.syncSheet(true)
})
d.showTraitModifier = d.addCheckBox(panel, i18n.Text("Show trait modifier cost adjustments"),
s.ShowTraitModifierAdj, func() {
d.settings().ShowTraitModifierAdj = d.showTraitModifier.State == check.On
Expand Down Expand Up @@ -397,6 +403,7 @@ func (d *sheetSettingsDockable) reset() {
func (d *sheetSettingsDockable) sync() {
s := d.settings()
d.damageProgressionPopup.Select(s.DamageProgression)
d.hideSourceMismatch.State = check.FromBool(!s.HideSourceMismatch)
d.showTraitModifier.State = check.FromBool(s.ShowTraitModifierAdj)
d.showEquipmentModifier.State = check.FromBool(s.ShowEquipmentModifierAdj)
d.showSpellAdjustments.State = check.FromBool(s.ShowSpellAdj)
Expand Down
4 changes: 3 additions & 1 deletion ux/skills_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ func (p *skillsProvider) ColumnIDs() []int {
}
columnIDs = append(columnIDs, gurps.SkillReferenceColumn)
if p.forPage {
columnIDs = append(columnIDs, gurps.SkillLibSrcColumn)
if entity := p.DataOwner().OwningEntity(); entity != nil && !entity.SheetSettings.HideSourceMismatch {
columnIDs = append(columnIDs, gurps.SkillLibSrcColumn)
}
}
return columnIDs
}
Expand Down
4 changes: 3 additions & 1 deletion ux/spells_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ func (p *spellsProvider) ColumnIDs() []int {
}
columnIDs = append(columnIDs, gurps.SpellReferenceColumn)
if p.forPage {
columnIDs = append(columnIDs, gurps.SpellLibSrcColumn)
if entity := p.DataOwner().OwningEntity(); entity != nil && !entity.SheetSettings.HideSourceMismatch {
columnIDs = append(columnIDs, gurps.SpellLibSrcColumn)
}
}
return columnIDs
}
Expand Down
4 changes: 3 additions & 1 deletion ux/traits_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ func (p *traitsProvider) ColumnIDs() []int {
}
columnIDs = append(columnIDs, gurps.TraitReferenceColumn)
if p.forPage {
columnIDs = append(columnIDs, gurps.TraitLibSrcColumn)
if entity := p.DataOwner().OwningEntity(); entity != nil && !entity.SheetSettings.HideSourceMismatch {
columnIDs = append(columnIDs, gurps.TraitLibSrcColumn)
}
}
return columnIDs
}
Expand Down

0 comments on commit 83f439a

Please sign in to comment.