1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-25 16:45:23 +00:00

Fix checkboxes (#138)

And change the names of things because it was confusing me.
This commit is contained in:
Ziemas 2019-11-10 23:52:30 +01:00 committed by Tim Sarbin
parent 3f01ad09ae
commit 1ec7d2379e

View File

@ -11,7 +11,7 @@ import (
type Checkbox struct { type Checkbox struct {
x, y int x, y int
pressed bool checkState bool
visible bool visible bool
width, height uint32 width, height uint32
Image *ebiten.Image Image *ebiten.Image
@ -20,13 +20,13 @@ type Checkbox struct {
enabled bool enabled bool
} }
func CreateCheckbox(fileProvider d2interface.FileProvider, toggleState bool) Checkbox { func CreateCheckbox(fileProvider d2interface.FileProvider, checkState bool) Checkbox {
result := Checkbox{ result := Checkbox{
pressed: toggleState, checkState: checkState,
visible: true, visible: true,
width: 0, width: 0,
height: 0, height: 0,
enabled: true, enabled: true,
} }
checkboxSprite := d2render.CreateSprite(fileProvider.LoadFile(d2resource.Checkbox), d2datadict.Palettes[d2enum.Fechar]) checkboxSprite := d2render.CreateSprite(fileProvider.LoadFile(d2resource.Checkbox), d2datadict.Palettes[d2enum.Fechar])
result.width, result.height = checkboxSprite.GetFrameSize(0) result.width, result.height = checkboxSprite.GetFrameSize(0)
@ -46,7 +46,7 @@ func (v Checkbox) Draw(target *ebiten.Image) {
Filter: ebiten.FilterNearest, Filter: ebiten.FilterNearest,
} }
opts.GeoM.Translate(float64(v.x), float64(v.y)) opts.GeoM.Translate(float64(v.x), float64(v.y))
if v.pressed == false { if v.checkState == false {
target.DrawImage(v.Image, opts) target.DrawImage(v.Image, opts)
} else { } else {
target.DrawImage(v.checkedImage, opts) target.DrawImage(v.checkedImage, opts)
@ -60,12 +60,19 @@ func (v *Checkbox) SetEnabled(enabled bool) {
v.enabled = enabled v.enabled = enabled
} }
func (v *Checkbox) SetPressed(pressed bool) { func (v Checkbox) SetPressed(pressed bool) {
v.pressed = pressed }
func (v *Checkbox) SetCheckState(checkState bool) {
v.checkState = checkState
}
func (v Checkbox) GetCheckState() bool {
return v.checkState
} }
func (v Checkbox) GetPressed() bool { func (v Checkbox) GetPressed() bool {
return v.pressed return v.checkState
} }
func (v *Checkbox) OnActivated(callback func()) { func (v *Checkbox) OnActivated(callback func()) {
@ -73,7 +80,7 @@ func (v *Checkbox) OnActivated(callback func()) {
} }
func (v *Checkbox) Activate() { func (v *Checkbox) Activate() {
v.pressed = !v.pressed v.checkState = !v.checkState
if v.onClick == nil { if v.onClick == nil {
return return
} }