From 877da921bf2c847967d8da658ae9a3caf077b11d Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Fri, 15 Jan 2021 13:04:46 +0100 Subject: [PATCH] lintfix: fixed lint errors --- d2core/d2ui/button.go | 13 +++++------ d2core/d2ui/switchable_button.go | 25 ++++++++++++++++++++- d2game/d2player/game_controls.go | 2 +- d2game/d2player/party_panel.go | 37 ++++++++++++-------------------- 4 files changed, 46 insertions(+), 31 deletions(-) diff --git a/d2core/d2ui/button.go b/d2core/d2ui/button.go index 19693a11..47fa968f 100644 --- a/d2core/d2ui/button.go +++ b/d2core/d2ui/button.go @@ -208,8 +208,8 @@ const ( ) // nolint:funlen // cant reduce -func getButtonLayouts() map[ButtonType]ButtonLayout { - return map[ButtonType]ButtonLayout{ +func getButtonLayouts() map[ButtonType]*ButtonLayout { + return map[ButtonType]*ButtonLayout{ ButtonTypeWide: { XSegments: buttonWideSegmentsX, YSegments: buttonWideSegmentsY, @@ -774,7 +774,7 @@ var _ ClickableWidget = &Button{} // Button defines a standard wide UI button type Button struct { *BaseWidget - buttonLayout ButtonLayout + buttonLayout *ButtonLayout normalSurface d2interface.Surface pressedSurface d2interface.Surface toggledSurface d2interface.Surface @@ -796,8 +796,9 @@ func (ui *UIManager) NewButton(buttonType ButtonType, text string) *Button { return btn } +// NewCustomButton creates new custom button func (ui *UIManager) NewCustomButton(path string, frame int) *Button { - layout := ButtonLayout{ + layout := &ButtonLayout{ XSegments: 1, YSegments: 1, DisabledFrame: -1, @@ -819,7 +820,7 @@ func (ui *UIManager) NewCustomButton(path string, frame int) *Button { } // createButton creates button using input layout and text -func (ui *UIManager) createButton(layout ButtonLayout, text string) *Button { +func (ui *UIManager) createButton(layout *ButtonLayout, text string) *Button { base := NewBaseWidget(ui) base.SetVisible(true) @@ -879,7 +880,7 @@ func (ui *UIManager) createButton(layout ButtonLayout, text string) *Button { ui.addWidget(btn) // important that this comes before prerenderStates! - btn.prerenderStates(buttonSprite, &layout, lbl) + btn.prerenderStates(buttonSprite, layout, lbl) return btn } diff --git a/d2core/d2ui/switchable_button.go b/d2core/d2ui/switchable_button.go index 0bda1904..85d015c9 100644 --- a/d2core/d2ui/switchable_button.go +++ b/d2core/d2ui/switchable_button.go @@ -1,7 +1,11 @@ package d2ui -var _ Widget = &Button{} +import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" +// static check if SwitchableButton implemented widget +var _ Widget = &SwitchableButton{} + +// SwitchableButton represents switchable button widget type SwitchableButton struct { *BaseWidget active *Button @@ -11,6 +15,7 @@ type SwitchableButton struct { state bool } +// NewSwitchableButton creates new switchable button func (ui *UIManager) NewSwitchableButton(active, inactive *Button, state bool) *SwitchableButton { base := NewBaseWidget(ui) base.SetVisible(true) @@ -28,10 +33,12 @@ func (ui *UIManager) NewSwitchableButton(active, inactive *Button, state bool) * return sbtn } +// SetVisible sets widget's visibility func (sbtn *SwitchableButton) SetVisible(visible bool) { if !visible { sbtn.active.SetVisible(false) sbtn.inactive.SetVisible(false) + return } @@ -44,6 +51,7 @@ func (sbtn *SwitchableButton) SetVisible(visible bool) { } } +// OnActivated sets onActivate callback func (sbtn *SwitchableButton) OnActivated(cb func()) { sbtn.active.OnActivated(func() { cb() @@ -52,10 +60,12 @@ func (sbtn *SwitchableButton) OnActivated(cb func()) { }) } +// Activate switches widget into active state func (sbtn *SwitchableButton) Activate() { sbtn.onActivate() } +// OnDezactivated sets onDezactivate callback func (sbtn *SwitchableButton) OnDezactivated(cb func()) { sbtn.inactive.OnActivated(func() { cb() @@ -64,12 +74,25 @@ func (sbtn *SwitchableButton) OnDezactivated(cb func()) { }) } +// Dezactivate switch widget to inactive state func (sbtn *SwitchableButton) Dezactivate() { sbtn.onDezactivate() } +// SetPosition sets widget's position func (sbtn *SwitchableButton) SetPosition(x, y int) { sbtn.BaseWidget.SetPosition(x, y) sbtn.active.SetPosition(x, y) sbtn.inactive.SetPosition(x, y) } + +// Advance advances widget +func (sbtn *SwitchableButton) Advance(_ float64) error { + // noop + return nil +} + +// Render renders widget +func (sbtn *SwitchableButton) Render(_ d2interface.Surface) { + // noop +} diff --git a/d2game/d2player/game_controls.go b/d2game/d2player/game_controls.go index 703cd92f..8c38845b 100644 --- a/d2game/d2player/game_controls.go +++ b/d2game/d2player/game_controls.go @@ -173,7 +173,7 @@ func NewGameControls( heroStatsPanel := NewHeroStatsPanel(asset, ui, hero.Name(), hero.Class, l, hero.Stats) - partyPanel := NewPartyPanel(asset, ui, hero.Name(), hero.Class, l, hero.Stats) + partyPanel := NewPartyPanel(asset, ui, hero.Name(), l, hero.Stats) questLog := NewQuestLog(asset, ui, l, audioProvider, hero.Act) diff --git a/d2game/d2player/party_panel.go b/d2game/d2player/party_panel.go index 02d35610..68425c6f 100644 --- a/d2game/d2player/party_panel.go +++ b/d2game/d2player/party_panel.go @@ -1,15 +1,11 @@ package d2player import ( - //"strconv" - //"strings" - - "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" + // "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset" - //"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui" ) @@ -96,11 +92,10 @@ type StatsPanelLabels struct { } */ -// NewHeroStatsPanel creates a new hero status panel +// NewPartyPanel creates a new party panel func NewPartyPanel(asset *d2asset.AssetManager, ui *d2ui.UIManager, heroName string, - heroClass d2enum.Hero, l d2util.LogLevel, heroState *d2hero.HeroStatsState) *PartyPanel { originX := 0 @@ -113,7 +108,6 @@ func NewPartyPanel(asset *d2asset.AssetManager, originY: originY, heroState: heroState, heroName: heroName, - heroClass: heroClass, labels: &StatsPanelLabels{}, } @@ -124,19 +118,16 @@ func NewPartyPanel(asset *d2asset.AssetManager, return hsp } -// HeroStatsPanel represents the hero status panel +// PartyPanel represents the party panel type PartyPanel struct { - asset *d2asset.AssetManager - uiManager *d2ui.UIManager - panel *d2ui.Sprite - heroState *d2hero.HeroStatsState - heroName string - heroClass d2enum.Hero - labels *StatsPanelLabels - onCloseCb func() - panelGroup *d2ui.WidgetGroup - newStatPoints *d2ui.WidgetGroup - remainingPoints *d2ui.Label + asset *d2asset.AssetManager + uiManager *d2ui.UIManager + panel *d2ui.Sprite + heroState *d2hero.HeroStatsState + heroName string + labels *StatsPanelLabels + onCloseCb func() + panelGroup *d2ui.WidgetGroup originX int originY int @@ -278,12 +269,12 @@ func (s *PartyPanel) Close() { s.panelGroup.SetVisible(false) } -/* -// SetOnCloseCb the callback run on closing the HeroStatsPanel -func (s *HeroStatsPanel) SetOnCloseCb(cb func()) { +// SetOnCloseCb the callback run on closing the PartyPanel +func (s *PartyPanel) SetOnCloseCb(cb func()) { s.onCloseCb = cb } +/* // Advance updates labels on the panel func (s *HeroStatsPanel) Advance(elapsed float64) { if !s.isOpen {