2019-12-28 23:32:53 -05:00
|
|
|
package d2player
|
|
|
|
|
|
|
|
import (
|
2020-01-26 00:39:13 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
2020-02-01 18:55:56 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2inventory"
|
2020-02-01 20:39:28 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
2020-02-01 18:55:56 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
2019-12-28 23:32:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type Inventory struct {
|
2020-02-01 18:55:56 -05:00
|
|
|
frame *d2ui.Sprite
|
|
|
|
panel *d2ui.Sprite
|
2019-12-28 23:32:53 -05:00
|
|
|
grid *ItemGrid
|
|
|
|
originX int
|
|
|
|
originY int
|
|
|
|
isOpen bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewInventory() *Inventory {
|
|
|
|
originX := 400
|
|
|
|
originY := 0
|
|
|
|
return &Inventory{
|
|
|
|
grid: NewItemGrid(10, 4, originX+19, originY+320),
|
|
|
|
originX: originX,
|
|
|
|
originY: originY,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *Inventory) IsOpen() bool {
|
|
|
|
return g.isOpen
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *Inventory) Toggle() {
|
|
|
|
g.isOpen = !g.isOpen
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *Inventory) Open() {
|
|
|
|
g.isOpen = true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *Inventory) Close() {
|
|
|
|
g.isOpen = false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *Inventory) Load() {
|
2020-02-01 18:55:56 -05:00
|
|
|
animation, _ := d2asset.LoadAnimation(d2resource.Frame, d2resource.PaletteSky)
|
|
|
|
g.frame, _ = d2ui.LoadSprite(animation)
|
2020-01-31 23:18:11 -05:00
|
|
|
|
2020-02-01 18:55:56 -05:00
|
|
|
animation, _ = d2asset.LoadAnimation(d2resource.InventoryCharacterPanel, d2resource.PaletteSky)
|
|
|
|
g.panel, _ = d2ui.LoadSprite(animation)
|
2019-12-28 23:32:53 -05:00
|
|
|
|
|
|
|
items := []InventoryItem{
|
2020-02-01 18:55:56 -05:00
|
|
|
d2inventory.GetWeaponItemByCode("wnd"),
|
|
|
|
d2inventory.GetWeaponItemByCode("sst"),
|
|
|
|
d2inventory.GetWeaponItemByCode("jav"),
|
|
|
|
d2inventory.GetArmorItemByCode("buc"),
|
|
|
|
d2inventory.GetWeaponItemByCode("clb"),
|
2019-12-28 23:32:53 -05:00
|
|
|
}
|
|
|
|
g.grid.Add(items...)
|
|
|
|
}
|
|
|
|
|
2020-02-01 20:39:28 -05:00
|
|
|
func (g *Inventory) Render(target d2render.Surface) {
|
2019-12-28 23:32:53 -05:00
|
|
|
if !g.isOpen {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
x, y := g.originX, g.originY
|
|
|
|
|
|
|
|
// Frame
|
|
|
|
// Top left
|
|
|
|
g.frame.SetCurrentFrame(5)
|
|
|
|
w, h := g.frame.GetCurrentFrameSize()
|
|
|
|
g.frame.SetPosition(x, y+h)
|
|
|
|
g.frame.Render(target)
|
|
|
|
x += w
|
|
|
|
|
|
|
|
// Top right
|
|
|
|
g.frame.SetCurrentFrame(6)
|
|
|
|
w, h = g.frame.GetCurrentFrameSize()
|
|
|
|
g.frame.SetPosition(x, y+h)
|
|
|
|
g.frame.Render(target)
|
|
|
|
x += w
|
|
|
|
y += h
|
|
|
|
|
|
|
|
// Right
|
|
|
|
g.frame.SetCurrentFrame(7)
|
|
|
|
w, h = g.frame.GetCurrentFrameSize()
|
|
|
|
g.frame.SetPosition(x-w, y+h)
|
|
|
|
g.frame.Render(target)
|
|
|
|
y += h
|
|
|
|
|
|
|
|
// Bottom right
|
|
|
|
g.frame.SetCurrentFrame(8)
|
|
|
|
w, h = g.frame.GetCurrentFrameSize()
|
|
|
|
g.frame.SetPosition(x-w, y+h)
|
|
|
|
g.frame.Render(target)
|
|
|
|
x -= w
|
|
|
|
|
|
|
|
// Bottom left
|
|
|
|
g.frame.SetCurrentFrame(9)
|
|
|
|
w, h = g.frame.GetCurrentFrameSize()
|
|
|
|
g.frame.SetPosition(x-w, y+h)
|
|
|
|
g.frame.Render(target)
|
|
|
|
|
|
|
|
x, y = g.originX, g.originY
|
|
|
|
y += 64
|
|
|
|
|
|
|
|
// Panel
|
|
|
|
// Top left
|
|
|
|
g.panel.SetCurrentFrame(4)
|
|
|
|
w, h = g.panel.GetCurrentFrameSize()
|
|
|
|
g.panel.SetPosition(x, y+h)
|
|
|
|
g.panel.Render(target)
|
|
|
|
x += w
|
|
|
|
|
|
|
|
// Top right
|
|
|
|
g.panel.SetCurrentFrame(5)
|
|
|
|
w, h = g.panel.GetCurrentFrameSize()
|
|
|
|
g.panel.SetPosition(x, y+h)
|
|
|
|
g.panel.Render(target)
|
|
|
|
y += h
|
|
|
|
|
|
|
|
// Bottom right
|
|
|
|
g.panel.SetCurrentFrame(7)
|
|
|
|
w, h = g.panel.GetCurrentFrameSize()
|
|
|
|
g.panel.SetPosition(x, y+h)
|
|
|
|
g.panel.Render(target)
|
|
|
|
|
|
|
|
// Bottom left
|
|
|
|
g.panel.SetCurrentFrame(6)
|
|
|
|
w, h = g.panel.GetCurrentFrameSize()
|
|
|
|
g.panel.SetPosition(x-w, y+h)
|
|
|
|
g.panel.Render(target)
|
|
|
|
|
|
|
|
g.grid.Render(target)
|
|
|
|
}
|