Skip to content

Commit

Permalink
Make the inc/dec qty & uses menu items work in Equipment Lists, too
Browse files Browse the repository at this point in the history
  • Loading branch information
richardwilkes committed Jun 21, 2023
1 parent f1dc977 commit 809fa8e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 41 deletions.
40 changes: 0 additions & 40 deletions ux/page_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ func NewTraitsPageList(owner Rebuildable, provider gurps.ListProvider) *PageList
func NewCarriedEquipmentPageList(owner Rebuildable, provider gurps.ListProvider) *PageList[*gurps.Equipment] {
p := newPageList(owner, NewEquipmentProvider(provider, true, true))
p.installToggleEquippedHandler(owner)
p.installIncrementQuantityHandler(owner)
p.installDecrementQuantityHandler(owner)
p.installIncrementUsesHandler(owner)
p.installDecrementUsesHandler(owner)
p.installIncrementTechLevelHandler(owner)
p.installDecrementTechLevelHandler(owner)
p.installContainerConversionHandlers(owner)
Expand All @@ -57,10 +53,6 @@ func NewCarriedEquipmentPageList(owner Rebuildable, provider gurps.ListProvider)
// NewOtherEquipmentPageList creates the other equipment page list.
func NewOtherEquipmentPageList(owner Rebuildable, provider gurps.ListProvider) *PageList[*gurps.Equipment] {
p := newPageList(owner, NewEquipmentProvider(provider, true, false))
p.installIncrementQuantityHandler(owner)
p.installDecrementQuantityHandler(owner)
p.installIncrementUsesHandler(owner)
p.installDecrementUsesHandler(owner)
p.installIncrementTechLevelHandler(owner)
p.installDecrementTechLevelHandler(owner)
p.installContainerConversionHandlers(owner)
Expand Down Expand Up @@ -229,38 +221,6 @@ func (p *PageList[T]) installDecrementLevelHandler(owner Rebuildable) {
}
}

func (p *PageList[T]) installIncrementQuantityHandler(owner Rebuildable) {
if t, ok := (any(p.Table)).(*unison.Table[*Node[*gurps.Equipment]]); ok {
p.InstallCmdHandlers(IncrementItemID,
func(_ any) bool { return canAdjustQuantity(t, true) },
func(_ any) { adjustQuantity(owner, t, true) })
}
}

func (p *PageList[T]) installDecrementQuantityHandler(owner Rebuildable) {
if t, ok := (any(p.Table)).(*unison.Table[*Node[*gurps.Equipment]]); ok {
p.InstallCmdHandlers(DecrementItemID,
func(_ any) bool { return canAdjustQuantity(t, false) },
func(_ any) { adjustQuantity(owner, t, false) })
}
}

func (p *PageList[T]) installIncrementUsesHandler(owner Rebuildable) {
if t, ok := (any(p.Table)).(*unison.Table[*Node[*gurps.Equipment]]); ok {
p.InstallCmdHandlers(IncrementUsesItemID,
func(_ any) bool { return canAdjustUses(t, 1) },
func(_ any) { adjustUses(owner, t, 1) })
}
}

func (p *PageList[T]) installDecrementUsesHandler(owner Rebuildable) {
if t, ok := (any(p.Table)).(*unison.Table[*Node[*gurps.Equipment]]); ok {
p.InstallCmdHandlers(DecrementUsesItemID,
func(_ any) bool { return canAdjustUses(t, -1) },
func(_ any) { adjustUses(owner, t, -1) })
}
}

func (p *PageList[T]) installIncrementSkillHandler(owner Rebuildable) {
p.InstallCmdHandlers(IncrementSkillLevelItemID,
func(_ any) bool { return canAdjustSkillLevel(p.Table, true) },
Expand Down
16 changes: 15 additions & 1 deletion ux/table.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright ©1998-2022 by Richard A. Wilkes. All rights reserved.
* Copyright ©1998-2023 by Richard A. Wilkes. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, version 2.0. If a copy of the MPL was not distributed with
Expand Down Expand Up @@ -161,6 +161,20 @@ func NewNodeTable[T gurps.NodeTypes](provider TableProvider[T], font unison.Font
func(_ any) { copySelectionToSheet(table) })
table.InstallCmdHandlers(CopyToTemplateItemID, func(_ any) bool { return canCopySelectionToTemplate(table) },
func(_ any) { copySelectionToTemplate(table) })
if t, ok := (any(table)).(*unison.Table[*Node[*gurps.Equipment]]); ok {
t.InstallCmdHandlers(IncrementItemID,
func(_ any) bool { return canAdjustQuantity(t, true) },
func(_ any) { adjustQuantity(unison.AncestorOrSelf[Rebuildable](t), t, true) })
t.InstallCmdHandlers(DecrementItemID,
func(_ any) bool { return canAdjustQuantity(t, false) },
func(_ any) { adjustQuantity(unison.AncestorOrSelf[Rebuildable](t), t, false) })
t.InstallCmdHandlers(IncrementUsesItemID,
func(_ any) bool { return canAdjustUses(t, 1) },
func(_ any) { adjustUses(unison.AncestorOrSelf[Rebuildable](t), t, 1) })
t.InstallCmdHandlers(DecrementUsesItemID,
func(_ any) bool { return canAdjustUses(t, -1) },
func(_ any) { adjustUses(unison.AncestorOrSelf[Rebuildable](t), t, -1) })
}

return header, table
}
Expand Down

0 comments on commit 809fa8e

Please sign in to comment.