1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-12-25 11:36:26 -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) {
config, ok := buttonStyleConfigs[buttonStyle]
if !ok {
config := getButtonStyleConfig(buttonStyle)
if config == nil {
return nil, errors.New("invalid button style")
}

View File

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

View File

@ -11,7 +11,7 @@ var (
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
func Initialize(inputManager d2interface.InputManager) error {

View File

@ -24,15 +24,19 @@ type fontStyleConfig struct {
palettePath string
}
var fontStyleConfigs = map[FontStyle]fontStyleConfig{
FontStyle16Units: {d2resource.Font16, d2resource.PaletteUnits},
FontStyle30Units: {d2resource.Font30, d2resource.PaletteUnits},
FontStyle42Units: {d2resource.Font42, d2resource.PaletteUnits},
FontStyleExocet10: {d2resource.FontExocet10, d2resource.PaletteUnits},
FontStyleFormal10Static: {d2resource.FontFormal10, d2resource.PaletteStatic},
FontStyleFormal11Units: {d2resource.FontFormal11, d2resource.PaletteUnits},
FontStyleFormal12Static: {d2resource.FontFormal12, d2resource.PaletteStatic},
FontStyleRediculous: {d2resource.FontRediculous, d2resource.PaletteUnits},
func getFontStyleConfig(f FontStyle) *fontStyleConfig {
fontStyles := map[FontStyle]*fontStyleConfig{
FontStyle16Units: {d2resource.Font16, d2resource.PaletteUnits},
FontStyle30Units: {d2resource.Font30, d2resource.PaletteUnits},
FontStyle42Units: {d2resource.Font42, d2resource.PaletteUnits},
FontStyleExocet10: {d2resource.FontExocet10, d2resource.PaletteUnits},
FontStyleFormal10Static: {d2resource.FontFormal10, d2resource.PaletteStatic},
FontStyleFormal11Units: {d2resource.FontFormal11, 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
@ -58,10 +62,14 @@ type buttonStyleConfig struct {
textOffset int
}
var buttonStyleConfigs = map[ButtonStyle]buttonStyleConfig{
ButtonStyleMedium: {1, 1, d2resource.MediumButtonBlank, d2resource.PaletteUnits, FontStyleExocet10, 0},
ButtonStyleOkCancel: {1, 1, d2resource.CancelButton, d2resource.PaletteUnits, FontStyleRediculous, 0},
ButtonStyleShort: {1, 1, d2resource.ShortButtonBlank, d2resource.PaletteUnits, FontStyleRediculous, -1},
ButtonStyleTall: {1, 1, d2resource.TallButtonBlank, d2resource.PaletteUnits, FontStyleExocet10, 5},
ButtonStyleWide: {2, 1, d2resource.WideButtonBlank, d2resource.PaletteUnits, FontStyleExocet10, 1},
func getButtonStyleConfig(b ButtonStyle) *buttonStyleConfig {
buttonStyleConfigs := map[ButtonStyle]*buttonStyleConfig{
ButtonStyleMedium: {1, 1, d2resource.MediumButtonBlank, d2resource.PaletteUnits, FontStyleExocet10, 0},
ButtonStyleOkCancel: {1, 1, d2resource.CancelButton, d2resource.PaletteUnits, FontStyleRediculous, 0},
ButtonStyleShort: {1, 1, d2resource.ShortButtonBlank, d2resource.PaletteUnits, FontStyleRediculous, -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
}
func (w *widgetBase) getPosition() (int, int) {
func (w *widgetBase) getPosition() (x, y int) {
return w.x, w.y
}
func (w *widgetBase) getSize() (int, int) {
func (w *widgetBase) getSize() (width, height int) {
return 0, 0
}