1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-12-25 19:46:50 -05:00

fixed lint errors in d2gui (#692)

This commit is contained in:
lord 2020-08-05 10:51:19 -07:00 committed by GitHub
parent e73299b99e
commit 04275eb8b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 24 deletions

View File

@ -31,8 +31,8 @@ type Button struct {
} }
func createButton(renderer d2interface.Renderer, text string, buttonStyle ButtonStyle) (*Button, error) { func createButton(renderer d2interface.Renderer, text string, buttonStyle ButtonStyle) (*Button, error) {
config, ok := buttonStyleConfigs[buttonStyle] config := getButtonStyleConfig(buttonStyle)
if !ok { if config == nil {
return nil, errors.New("invalid button style") return nil, errors.New("invalid button style")
} }

View File

@ -2,17 +2,16 @@ package d2gui
import ( import (
"errors" "errors"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
"image/color" "image/color"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
) )
func loadFont(fontStyle FontStyle) (d2interface.Font, error) { func loadFont(fontStyle FontStyle) (d2interface.Font, error) {
config, ok := fontStyleConfigs[fontStyle] config := getFontStyleConfig(fontStyle)
if !ok { if config == nil {
return nil, errors.New("invalid font style") return nil, errors.New("invalid font style")
} }

View File

@ -11,7 +11,7 @@ var (
errNotInit = errors.New("gui system is not initialized") errNotInit = errors.New("gui system is not initialized")
) )
var singleton *manager var singleton *manager // nolint:gochecknoglobals // currently global by design
// Initialize creates a singleton gui manager // Initialize creates a singleton gui manager
func Initialize(inputManager d2interface.InputManager) error { func Initialize(inputManager d2interface.InputManager) error {

View File

@ -24,15 +24,19 @@ type fontStyleConfig struct {
palettePath string palettePath string
} }
var fontStyleConfigs = map[FontStyle]fontStyleConfig{ func getFontStyleConfig(f FontStyle) *fontStyleConfig {
FontStyle16Units: {d2resource.Font16, d2resource.PaletteUnits}, fontStyles := map[FontStyle]*fontStyleConfig{
FontStyle30Units: {d2resource.Font30, d2resource.PaletteUnits}, FontStyle16Units: {d2resource.Font16, d2resource.PaletteUnits},
FontStyle42Units: {d2resource.Font42, d2resource.PaletteUnits}, FontStyle30Units: {d2resource.Font30, d2resource.PaletteUnits},
FontStyleExocet10: {d2resource.FontExocet10, d2resource.PaletteUnits}, FontStyle42Units: {d2resource.Font42, d2resource.PaletteUnits},
FontStyleFormal10Static: {d2resource.FontFormal10, d2resource.PaletteStatic}, FontStyleExocet10: {d2resource.FontExocet10, d2resource.PaletteUnits},
FontStyleFormal11Units: {d2resource.FontFormal11, d2resource.PaletteUnits}, FontStyleFormal10Static: {d2resource.FontFormal10, d2resource.PaletteStatic},
FontStyleFormal12Static: {d2resource.FontFormal12, d2resource.PaletteStatic}, FontStyleFormal11Units: {d2resource.FontFormal11, d2resource.PaletteUnits},
FontStyleRediculous: {d2resource.FontRediculous, d2resource.PaletteUnits}, FontStyleFormal12Static: {d2resource.FontFormal12, d2resource.PaletteStatic},
FontStyleRediculous: {d2resource.FontRediculous, d2resource.PaletteUnits},
}
return fontStyles[f]
} }
// ButtonStyle is a representation of a button style. Button styles have // ButtonStyle is a representation of a button style. Button styles have
@ -58,10 +62,14 @@ type buttonStyleConfig struct {
textOffset int textOffset int
} }
var buttonStyleConfigs = map[ButtonStyle]buttonStyleConfig{ func getButtonStyleConfig(b ButtonStyle) *buttonStyleConfig {
ButtonStyleMedium: {1, 1, d2resource.MediumButtonBlank, d2resource.PaletteUnits, FontStyleExocet10, 0}, buttonStyleConfigs := map[ButtonStyle]*buttonStyleConfig{
ButtonStyleOkCancel: {1, 1, d2resource.CancelButton, d2resource.PaletteUnits, FontStyleRediculous, 0}, ButtonStyleMedium: {1, 1, d2resource.MediumButtonBlank, d2resource.PaletteUnits, FontStyleExocet10, 0},
ButtonStyleShort: {1, 1, d2resource.ShortButtonBlank, d2resource.PaletteUnits, FontStyleRediculous, -1}, ButtonStyleOkCancel: {1, 1, d2resource.CancelButton, d2resource.PaletteUnits, FontStyleRediculous, 0},
ButtonStyleTall: {1, 1, d2resource.TallButtonBlank, d2resource.PaletteUnits, FontStyleExocet10, 5}, ButtonStyleShort: {1, 1, d2resource.ShortButtonBlank, d2resource.PaletteUnits, FontStyleRediculous, -1},
ButtonStyleWide: {2, 1, d2resource.WideButtonBlank, d2resource.PaletteUnits, FontStyleExocet10, 1}, ButtonStyleTall: {1, 1, d2resource.TallButtonBlank, d2resource.PaletteUnits, FontStyleExocet10, 5},
ButtonStyleWide: {2, 1, d2resource.WideButtonBlank, d2resource.PaletteUnits, FontStyleExocet10, 1},
}
return buttonStyleConfigs[b]
} }

View File

@ -110,11 +110,11 @@ func (w *widgetBase) SetMouseClickHandler(handler MouseHandler) {
w.mouseClickHandler = handler w.mouseClickHandler = handler
} }
func (w *widgetBase) getPosition() (int, int) { func (w *widgetBase) getPosition() (x, y int) {
return w.x, w.y return w.x, w.y
} }
func (w *widgetBase) getSize() (int, int) { func (w *widgetBase) getSize() (width, height int) {
return 0, 0 return 0, 0
} }