1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2025-01-11 20:06:54 -05:00

lintfix: fixed lint errors

This commit is contained in:
M. Sz 2021-01-15 13:04:46 +01:00
parent 4575df572f
commit 877da921bf
4 changed files with 46 additions and 31 deletions

View File

@ -208,8 +208,8 @@ const (
) )
// nolint:funlen // cant reduce // nolint:funlen // cant reduce
func getButtonLayouts() map[ButtonType]ButtonLayout { func getButtonLayouts() map[ButtonType]*ButtonLayout {
return map[ButtonType]ButtonLayout{ return map[ButtonType]*ButtonLayout{
ButtonTypeWide: { ButtonTypeWide: {
XSegments: buttonWideSegmentsX, XSegments: buttonWideSegmentsX,
YSegments: buttonWideSegmentsY, YSegments: buttonWideSegmentsY,
@ -774,7 +774,7 @@ var _ ClickableWidget = &Button{}
// Button defines a standard wide UI button // Button defines a standard wide UI button
type Button struct { type Button struct {
*BaseWidget *BaseWidget
buttonLayout ButtonLayout buttonLayout *ButtonLayout
normalSurface d2interface.Surface normalSurface d2interface.Surface
pressedSurface d2interface.Surface pressedSurface d2interface.Surface
toggledSurface d2interface.Surface toggledSurface d2interface.Surface
@ -796,8 +796,9 @@ func (ui *UIManager) NewButton(buttonType ButtonType, text string) *Button {
return btn return btn
} }
// NewCustomButton creates new custom button
func (ui *UIManager) NewCustomButton(path string, frame int) *Button { func (ui *UIManager) NewCustomButton(path string, frame int) *Button {
layout := ButtonLayout{ layout := &ButtonLayout{
XSegments: 1, XSegments: 1,
YSegments: 1, YSegments: 1,
DisabledFrame: -1, DisabledFrame: -1,
@ -819,7 +820,7 @@ func (ui *UIManager) NewCustomButton(path string, frame int) *Button {
} }
// createButton creates button using input layout and text // 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 := NewBaseWidget(ui)
base.SetVisible(true) 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! ui.addWidget(btn) // important that this comes before prerenderStates!
btn.prerenderStates(buttonSprite, &layout, lbl) btn.prerenderStates(buttonSprite, layout, lbl)
return btn return btn
} }

View File

@ -1,7 +1,11 @@
package d2ui 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 { type SwitchableButton struct {
*BaseWidget *BaseWidget
active *Button active *Button
@ -11,6 +15,7 @@ type SwitchableButton struct {
state bool state bool
} }
// NewSwitchableButton creates new switchable button
func (ui *UIManager) NewSwitchableButton(active, inactive *Button, state bool) *SwitchableButton { func (ui *UIManager) NewSwitchableButton(active, inactive *Button, state bool) *SwitchableButton {
base := NewBaseWidget(ui) base := NewBaseWidget(ui)
base.SetVisible(true) base.SetVisible(true)
@ -28,10 +33,12 @@ func (ui *UIManager) NewSwitchableButton(active, inactive *Button, state bool) *
return sbtn return sbtn
} }
// SetVisible sets widget's visibility
func (sbtn *SwitchableButton) SetVisible(visible bool) { func (sbtn *SwitchableButton) SetVisible(visible bool) {
if !visible { if !visible {
sbtn.active.SetVisible(false) sbtn.active.SetVisible(false)
sbtn.inactive.SetVisible(false) sbtn.inactive.SetVisible(false)
return return
} }
@ -44,6 +51,7 @@ func (sbtn *SwitchableButton) SetVisible(visible bool) {
} }
} }
// OnActivated sets onActivate callback
func (sbtn *SwitchableButton) OnActivated(cb func()) { func (sbtn *SwitchableButton) OnActivated(cb func()) {
sbtn.active.OnActivated(func() { sbtn.active.OnActivated(func() {
cb() cb()
@ -52,10 +60,12 @@ func (sbtn *SwitchableButton) OnActivated(cb func()) {
}) })
} }
// Activate switches widget into active state
func (sbtn *SwitchableButton) Activate() { func (sbtn *SwitchableButton) Activate() {
sbtn.onActivate() sbtn.onActivate()
} }
// OnDezactivated sets onDezactivate callback
func (sbtn *SwitchableButton) OnDezactivated(cb func()) { func (sbtn *SwitchableButton) OnDezactivated(cb func()) {
sbtn.inactive.OnActivated(func() { sbtn.inactive.OnActivated(func() {
cb() cb()
@ -64,12 +74,25 @@ func (sbtn *SwitchableButton) OnDezactivated(cb func()) {
}) })
} }
// Dezactivate switch widget to inactive state
func (sbtn *SwitchableButton) Dezactivate() { func (sbtn *SwitchableButton) Dezactivate() {
sbtn.onDezactivate() sbtn.onDezactivate()
} }
// SetPosition sets widget's position
func (sbtn *SwitchableButton) SetPosition(x, y int) { func (sbtn *SwitchableButton) SetPosition(x, y int) {
sbtn.BaseWidget.SetPosition(x, y) sbtn.BaseWidget.SetPosition(x, y)
sbtn.active.SetPosition(x, y) sbtn.active.SetPosition(x, y)
sbtn.inactive.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
}

View File

@ -173,7 +173,7 @@ func NewGameControls(
heroStatsPanel := NewHeroStatsPanel(asset, ui, hero.Name(), hero.Class, l, hero.Stats) 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) questLog := NewQuestLog(asset, ui, l, audioProvider, hero.Act)

View File

@ -1,15 +1,11 @@
package d2player package d2player
import ( import (
//"strconv" // "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
//"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
//"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui" "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, func NewPartyPanel(asset *d2asset.AssetManager,
ui *d2ui.UIManager, ui *d2ui.UIManager,
heroName string, heroName string,
heroClass d2enum.Hero,
l d2util.LogLevel, l d2util.LogLevel,
heroState *d2hero.HeroStatsState) *PartyPanel { heroState *d2hero.HeroStatsState) *PartyPanel {
originX := 0 originX := 0
@ -113,7 +108,6 @@ func NewPartyPanel(asset *d2asset.AssetManager,
originY: originY, originY: originY,
heroState: heroState, heroState: heroState,
heroName: heroName, heroName: heroName,
heroClass: heroClass,
labels: &StatsPanelLabels{}, labels: &StatsPanelLabels{},
} }
@ -124,19 +118,16 @@ func NewPartyPanel(asset *d2asset.AssetManager,
return hsp return hsp
} }
// HeroStatsPanel represents the hero status panel // PartyPanel represents the party panel
type PartyPanel struct { type PartyPanel struct {
asset *d2asset.AssetManager asset *d2asset.AssetManager
uiManager *d2ui.UIManager uiManager *d2ui.UIManager
panel *d2ui.Sprite panel *d2ui.Sprite
heroState *d2hero.HeroStatsState heroState *d2hero.HeroStatsState
heroName string heroName string
heroClass d2enum.Hero
labels *StatsPanelLabels labels *StatsPanelLabels
onCloseCb func() onCloseCb func()
panelGroup *d2ui.WidgetGroup panelGroup *d2ui.WidgetGroup
newStatPoints *d2ui.WidgetGroup
remainingPoints *d2ui.Label
originX int originX int
originY int originY int
@ -278,12 +269,12 @@ func (s *PartyPanel) Close() {
s.panelGroup.SetVisible(false) s.panelGroup.SetVisible(false)
} }
/* // SetOnCloseCb the callback run on closing the PartyPanel
// SetOnCloseCb the callback run on closing the HeroStatsPanel func (s *PartyPanel) SetOnCloseCb(cb func()) {
func (s *HeroStatsPanel) SetOnCloseCb(cb func()) {
s.onCloseCb = cb s.onCloseCb = cb
} }
/*
// Advance updates labels on the panel // Advance updates labels on the panel
func (s *HeroStatsPanel) Advance(elapsed float64) { func (s *HeroStatsPanel) Advance(elapsed float64) {
if !s.isOpen { if !s.isOpen {