mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-09-27 13:46:00 -04:00
Add panel to contain hero stats (#299)
Left framing with stats panel, bound to 'C' key.
This commit is contained in:
parent
99e6acf2bb
commit
b957661915
@ -20,6 +20,7 @@ type GameControls struct {
|
|||||||
hero *d2map.Hero
|
hero *d2map.Hero
|
||||||
mapEngine *d2map.MapEngine
|
mapEngine *d2map.MapEngine
|
||||||
inventory *Inventory
|
inventory *Inventory
|
||||||
|
heroStats *HeroStats
|
||||||
|
|
||||||
// UI
|
// UI
|
||||||
globeSprite *d2ui.Sprite
|
globeSprite *d2ui.Sprite
|
||||||
@ -33,6 +34,7 @@ func NewGameControls(hero *d2map.Hero, mapEngine *d2map.MapEngine) *GameControls
|
|||||||
hero: hero,
|
hero: hero,
|
||||||
mapEngine: mapEngine,
|
mapEngine: mapEngine,
|
||||||
inventory: NewInventory(),
|
inventory: NewInventory(),
|
||||||
|
heroStats: NewHeroStats(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,6 +43,10 @@ func (g *GameControls) OnKeyDown(event d2input.KeyEvent) bool {
|
|||||||
g.inventory.Toggle()
|
g.inventory.Toggle()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
if event.Key == d2input.KeyC {
|
||||||
|
g.heroStats.Toggle()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -48,8 +54,8 @@ func (g *GameControls) OnKeyDown(event d2input.KeyEvent) bool {
|
|||||||
func (g *GameControls) OnMouseButtonDown(event d2input.MouseEvent) bool {
|
func (g *GameControls) OnMouseButtonDown(event d2input.MouseEvent) bool {
|
||||||
if event.Button == d2input.MouseButtonLeft {
|
if event.Button == d2input.MouseButtonLeft {
|
||||||
px, py := g.mapEngine.ScreenToWorld(event.X, event.Y)
|
px, py := g.mapEngine.ScreenToWorld(event.X, event.Y)
|
||||||
px = float64(int(px * 10)) / 10.0
|
px = float64(int(px*10)) / 10.0
|
||||||
py = float64(int(py * 10)) / 10.0
|
py = float64(int(py*10)) / 10.0
|
||||||
heroPosX := g.hero.AnimatedEntity.LocationX / 5.0
|
heroPosX := g.hero.AnimatedEntity.LocationX / 5.0
|
||||||
heroPosY := g.hero.AnimatedEntity.LocationY / 5.0
|
heroPosY := g.hero.AnimatedEntity.LocationY / 5.0
|
||||||
path, _, found := g.mapEngine.PathFind(heroPosX, heroPosY, px, py)
|
path, _, found := g.mapEngine.PathFind(heroPosX, heroPosY, px, py)
|
||||||
@ -75,11 +81,13 @@ func (g *GameControls) Load() {
|
|||||||
g.skillIcon, _ = d2ui.LoadSprite(animation)
|
g.skillIcon, _ = d2ui.LoadSprite(animation)
|
||||||
|
|
||||||
g.inventory.Load()
|
g.inventory.Load()
|
||||||
|
g.heroStats.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: consider caching the panels to single image that is reused.
|
// TODO: consider caching the panels to single image that is reused.
|
||||||
func (g *GameControls) Render(target d2render.Surface) {
|
func (g *GameControls) Render(target d2render.Surface) {
|
||||||
g.inventory.Render(target)
|
g.inventory.Render(target)
|
||||||
|
g.heroStats.Render(target)
|
||||||
|
|
||||||
width, height := target.GetSize()
|
width, height := target.GetSize()
|
||||||
offset := 0
|
offset := 0
|
||||||
|
124
d2game/d2player/stats.go
Normal file
124
d2game/d2player/stats.go
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
package d2player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HeroStats struct {
|
||||||
|
frame *d2ui.Sprite
|
||||||
|
panel *d2ui.Sprite
|
||||||
|
originX int
|
||||||
|
originY int
|
||||||
|
isOpen bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHeroStats() *HeroStats {
|
||||||
|
originX := 0
|
||||||
|
originY := 0
|
||||||
|
return &HeroStats{
|
||||||
|
originX: originX,
|
||||||
|
originY: originY,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *HeroStats) Load() {
|
||||||
|
animation, _ := d2asset.LoadAnimation(d2resource.Frame, d2resource.PaletteSky)
|
||||||
|
s.frame, _ = d2ui.LoadSprite(animation)
|
||||||
|
animation, _ = d2asset.LoadAnimation(d2resource.InventoryCharacterPanel, d2resource.PaletteSky)
|
||||||
|
s.panel, _ = d2ui.LoadSprite(animation)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *HeroStats) IsOpen() bool {
|
||||||
|
return s.isOpen
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *HeroStats) Toggle() {
|
||||||
|
s.isOpen = !s.isOpen
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *HeroStats) Open() {
|
||||||
|
s.isOpen = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *HeroStats) Close() {
|
||||||
|
s.isOpen = false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *HeroStats) Render(target d2render.Surface) {
|
||||||
|
if !s.isOpen {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
x, y := s.originX, s.originY
|
||||||
|
|
||||||
|
// Frame
|
||||||
|
// Top left
|
||||||
|
s.frame.SetCurrentFrame(0)
|
||||||
|
w, h := s.frame.GetCurrentFrameSize()
|
||||||
|
s.frame.SetPosition(x, y+h)
|
||||||
|
s.frame.Render(target)
|
||||||
|
x += w
|
||||||
|
y += h
|
||||||
|
|
||||||
|
// Top right
|
||||||
|
s.frame.SetCurrentFrame(1)
|
||||||
|
w, h = s.frame.GetCurrentFrameSize()
|
||||||
|
s.frame.SetPosition(x, s.originY+h)
|
||||||
|
s.frame.Render(target)
|
||||||
|
x = s.originX
|
||||||
|
|
||||||
|
// Right
|
||||||
|
s.frame.SetCurrentFrame(2)
|
||||||
|
w, h = s.frame.GetCurrentFrameSize()
|
||||||
|
s.frame.SetPosition(x, y+h)
|
||||||
|
s.frame.Render(target)
|
||||||
|
y += h
|
||||||
|
|
||||||
|
// Bottom left
|
||||||
|
s.frame.SetCurrentFrame(3)
|
||||||
|
w, h = s.frame.GetCurrentFrameSize()
|
||||||
|
s.frame.SetPosition(x, y+h)
|
||||||
|
s.frame.Render(target)
|
||||||
|
x += w
|
||||||
|
|
||||||
|
// Bottom right
|
||||||
|
s.frame.SetCurrentFrame(4)
|
||||||
|
w, h = s.frame.GetCurrentFrameSize()
|
||||||
|
s.frame.SetPosition(x, y+h)
|
||||||
|
s.frame.Render(target)
|
||||||
|
|
||||||
|
x, y = s.originX, s.originY
|
||||||
|
y += 64
|
||||||
|
x += 80
|
||||||
|
|
||||||
|
// Panel
|
||||||
|
// Top left
|
||||||
|
s.panel.SetCurrentFrame(0)
|
||||||
|
w, h = s.panel.GetCurrentFrameSize()
|
||||||
|
s.panel.SetPosition(x, y+h)
|
||||||
|
s.panel.Render(target)
|
||||||
|
x += w
|
||||||
|
|
||||||
|
// Top right
|
||||||
|
s.panel.SetCurrentFrame(1)
|
||||||
|
w, h = s.panel.GetCurrentFrameSize()
|
||||||
|
s.panel.SetPosition(x, y+h)
|
||||||
|
s.panel.Render(target)
|
||||||
|
y += h
|
||||||
|
|
||||||
|
// Bottom right
|
||||||
|
s.panel.SetCurrentFrame(3)
|
||||||
|
w, h = s.panel.GetCurrentFrameSize()
|
||||||
|
s.panel.SetPosition(x, y+h)
|
||||||
|
s.panel.Render(target)
|
||||||
|
|
||||||
|
// Bottom left
|
||||||
|
s.panel.SetCurrentFrame(2)
|
||||||
|
w, h = s.panel.GetCurrentFrameSize()
|
||||||
|
s.panel.SetPosition(x-w, y+h)
|
||||||
|
s.panel.Render(target)
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user