mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-09-27 21:56:19 -04:00
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:
parent
d4ec09db6c
commit
b60465fd6c
@ -62,6 +62,7 @@ var ButtonLayouts = map[ButtonType]ButtonLayout{
|
|||||||
ButtonTypeMedium: {1, 1, d2resource.MediumButtonBlank, d2resource.PaletteUnits, false, 0, 0, d2resource.FontExocet10, nil, true, 0},
|
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},
|
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},
|
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.Wide, new ButtonLayout { XSegments = 2, ResourceName = ResourcePaths.WideButtonBlank, PaletteName = PaletteDefs.Units } },
|
||||||
{eButtonType.Narrow, new ButtonLayout { ResourceName = ResourcePaths.NarrowButtonBlank, 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) {
|
func (v *Button) Advance(elapsed float64) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ type GameControls struct {
|
|||||||
menuButton *d2ui.Sprite
|
menuButton *d2ui.Sprite
|
||||||
skillIcon *d2ui.Sprite
|
skillIcon *d2ui.Sprite
|
||||||
zoneChangeText *d2ui.Label
|
zoneChangeText *d2ui.Label
|
||||||
|
runButton d2ui.Button
|
||||||
isZoneTextShown bool
|
isZoneTextShown bool
|
||||||
actionableRegions []ActionableRegion
|
actionableRegions []ActionableRegion
|
||||||
}
|
}
|
||||||
@ -157,9 +158,7 @@ func (g *GameControls) OnKeyDown(event d2input.KeyEvent) bool {
|
|||||||
g.heroStats.Toggle()
|
g.heroStats.Toggle()
|
||||||
g.updateLayout()
|
g.updateLayout()
|
||||||
case d2input.KeyR:
|
case d2input.KeyR:
|
||||||
g.hero.ToggleRunWalk()
|
g.onToggleRunButton()
|
||||||
// TODO: change the running menu icon
|
|
||||||
g.hero.SetIsRunning(g.hero.IsRunToggled())
|
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -278,11 +277,31 @@ func (g *GameControls) Load() {
|
|||||||
animation, _ = d2asset.LoadAnimation(d2resource.GenericSkills, d2resource.PaletteSky)
|
animation, _ = d2asset.LoadAnimation(d2resource.GenericSkills, d2resource.PaletteSky)
|
||||||
g.skillIcon, _ = d2ui.LoadSprite(animation)
|
g.skillIcon, _ = d2ui.LoadSprite(animation)
|
||||||
|
|
||||||
|
g.loadUIButtons()
|
||||||
|
|
||||||
g.inventory.Load()
|
g.inventory.Load()
|
||||||
g.heroStats.Load()
|
g.heroStats.Load()
|
||||||
g.escapeMenu.OnLoad()
|
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
|
// ScreenAdvanceHandler
|
||||||
func (g *GameControls) Advance(elapsed float64) error {
|
func (g *GameControls) Advance(elapsed float64) error {
|
||||||
g.escapeMenu.Advance(elapsed)
|
g.escapeMenu.Advance(elapsed)
|
||||||
|
Loading…
Reference in New Issue
Block a user