render the run button the UI, and allow the user to toggle it with their mouse, in addition to the R key on the keyboard (#400) (#443)

This commit is contained in:
Natureknight 2020-06-24 22:23:38 +03:00 committed by GitHub
parent d4ec09db6c
commit b60465fd6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 3 deletions

View File

@ -62,6 +62,7 @@ var ButtonLayouts = map[ButtonType]ButtonLayout{
ButtonTypeMedium: {1, 1, d2resource.MediumButtonBlank, d2resource.PaletteUnits, false, 0, 0, d2resource.FontExocet10, nil, true, 0},
ButtonTypeTall: {1, 1, d2resource.TallButtonBlank, d2resource.PaletteUnits, false, 0, 0, d2resource.FontExocet10, nil, true, 5},
ButtonTypeOkCancel: {1, 1, d2resource.CancelButton, d2resource.PaletteUnits, false, 0, -1, d2resource.FontRediculous, nil, true, 0},
ButtonTypeRun: {1, 1, d2resource.RunButton, d2resource.PaletteSky, true, 0, -1, d2resource.FontRediculous, nil, true, 0},
/*
{eButtonType.Wide, new ButtonLayout { XSegments = 2, ResourceName = ResourcePaths.WideButtonBlank, PaletteName = PaletteDefs.Units } },
{eButtonType.Narrow, new ButtonLayout { ResourceName = ResourcePaths.NarrowButtonBlank, PaletteName = PaletteDefs.Units } },
@ -194,6 +195,10 @@ func (v *Button) Render(target d2render.Surface) {
}
}
func (v *Button) Toggle() {
v.toggled = !v.toggled
}
func (v *Button) Advance(elapsed float64) {
}

View File

@ -44,6 +44,7 @@ type GameControls struct {
menuButton *d2ui.Sprite
skillIcon *d2ui.Sprite
zoneChangeText *d2ui.Label
runButton d2ui.Button
isZoneTextShown bool
actionableRegions []ActionableRegion
}
@ -157,9 +158,7 @@ func (g *GameControls) OnKeyDown(event d2input.KeyEvent) bool {
g.heroStats.Toggle()
g.updateLayout()
case d2input.KeyR:
g.hero.ToggleRunWalk()
// TODO: change the running menu icon
g.hero.SetIsRunning(g.hero.IsRunToggled())
g.onToggleRunButton()
default:
return false
}
@ -278,11 +277,31 @@ func (g *GameControls) Load() {
animation, _ = d2asset.LoadAnimation(d2resource.GenericSkills, d2resource.PaletteSky)
g.skillIcon, _ = d2ui.LoadSprite(animation)
g.loadUIButtons()
g.inventory.Load()
g.heroStats.Load()
g.escapeMenu.OnLoad()
}
func (g *GameControls) loadUIButtons() {
// Run button
g.runButton = d2ui.CreateButton(d2ui.ButtonTypeRun, "")
g.runButton.SetPosition(255, 570)
g.runButton.OnActivated(func() { g.onToggleRunButton() })
if g.hero.IsRunToggled() {
g.runButton.Toggle()
}
d2ui.AddWidget(&g.runButton)
}
func (g *GameControls) onToggleRunButton() {
g.runButton.Toggle()
g.hero.ToggleRunWalk()
// TODO: change the running menu icon
g.hero.SetIsRunning(g.hero.IsRunToggled())
}
// ScreenAdvanceHandler
func (g *GameControls) Advance(elapsed float64) error {
g.escapeMenu.Advance(elapsed)