2019-12-28 23:32:53 -05:00
|
|
|
package d2player
|
|
|
|
|
|
|
|
import (
|
2020-07-11 11:25:34 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
|
2020-06-23 14:12:30 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
2020-06-29 00:41:58 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
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"
|
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
2020-07-11 11:25:34 -04:00
|
|
|
func NewInventory(record *d2datadict.InventoryRecord) *Inventory {
|
2019-12-28 23:32:53 -05:00
|
|
|
return &Inventory{
|
2020-07-11 11:25:34 -04:00
|
|
|
grid: NewItemGrid(record),
|
|
|
|
originX: record.Panel.Left,
|
|
|
|
// originY: record.Panel.Top,
|
|
|
|
originY: 0, // expansion data has these all offset by +60 ...
|
2019-12-28 23:32:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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"),
|
2020-06-23 14:12:30 -04:00
|
|
|
// TODO: Load the player's actual items
|
2019-12-28 23:32:53 -05:00
|
|
|
}
|
2020-07-08 19:08:07 -04:00
|
|
|
g.grid.ChangeEquippedSlot(d2enum.EquippedSlotLeftArm, d2inventory.GetWeaponItemByCode("wnd"))
|
|
|
|
g.grid.ChangeEquippedSlot(d2enum.EquippedSlotRightArm, d2inventory.GetArmorItemByCode("buc"))
|
|
|
|
g.grid.ChangeEquippedSlot(d2enum.EquippedSlotHead, d2inventory.GetArmorItemByCode("crn"))
|
|
|
|
g.grid.ChangeEquippedSlot(d2enum.EquippedSlotTorso, d2inventory.GetArmorItemByCode("plt"))
|
|
|
|
g.grid.ChangeEquippedSlot(d2enum.EquippedSlotLegs, d2inventory.GetArmorItemByCode("vbt"))
|
|
|
|
g.grid.ChangeEquippedSlot(d2enum.EquippedSlotBelt, d2inventory.GetArmorItemByCode("vbl"))
|
|
|
|
g.grid.ChangeEquippedSlot(d2enum.EquippedSlotGloves, d2inventory.GetArmorItemByCode("lgl"))
|
|
|
|
g.grid.ChangeEquippedSlot(d2enum.EquippedSlotLeftHand, d2inventory.GetMiscItemByCode("rin"))
|
|
|
|
g.grid.ChangeEquippedSlot(d2enum.EquippedSlotRightHand, d2inventory.GetMiscItemByCode("rin"))
|
|
|
|
g.grid.ChangeEquippedSlot(d2enum.EquippedSlotNeck, d2inventory.GetMiscItemByCode("amu"))
|
2020-06-23 14:12:30 -04:00
|
|
|
// TODO: Load the player's actual items
|
2019-12-28 23:32:53 -05:00
|
|
|
g.grid.Add(items...)
|
|
|
|
}
|
|
|
|
|
2020-07-26 14:52:54 -04:00
|
|
|
func (g *Inventory) Render(target d2interface.Surface) error {
|
2019-12-28 23:32:53 -05:00
|
|
|
if !g.isOpen {
|
2020-07-26 14:52:54 -04:00
|
|
|
return nil
|
2019-12-28 23:32:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
x, y := g.originX, g.originY
|
|
|
|
|
|
|
|
// Frame
|
|
|
|
// Top left
|
2020-07-26 14:52:54 -04:00
|
|
|
if err := g.frame.SetCurrentFrame(5); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
w, h := g.frame.GetCurrentFrameSize()
|
2020-07-26 14:52:54 -04:00
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
g.frame.SetPosition(x, y+h)
|
2020-07-26 14:52:54 -04:00
|
|
|
|
|
|
|
if err := g.frame.Render(target); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
x += w
|
|
|
|
|
|
|
|
// Top right
|
2020-07-26 14:52:54 -04:00
|
|
|
if err := g.frame.SetCurrentFrame(6); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
w, h = g.frame.GetCurrentFrameSize()
|
2020-07-26 14:52:54 -04:00
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
g.frame.SetPosition(x, y+h)
|
2020-07-26 14:52:54 -04:00
|
|
|
|
|
|
|
if err := g.frame.Render(target); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
x += w
|
|
|
|
y += h
|
|
|
|
|
|
|
|
// Right
|
2020-07-26 14:52:54 -04:00
|
|
|
if err := g.frame.SetCurrentFrame(7); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
w, h = g.frame.GetCurrentFrameSize()
|
2020-07-26 14:52:54 -04:00
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
g.frame.SetPosition(x-w, y+h)
|
2020-07-26 14:52:54 -04:00
|
|
|
|
|
|
|
if err := g.frame.Render(target); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
y += h
|
|
|
|
|
|
|
|
// Bottom right
|
2020-07-26 14:52:54 -04:00
|
|
|
if err := g.frame.SetCurrentFrame(8); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
w, h = g.frame.GetCurrentFrameSize()
|
2020-07-26 14:52:54 -04:00
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
g.frame.SetPosition(x-w, y+h)
|
2020-07-26 14:52:54 -04:00
|
|
|
|
|
|
|
if err := g.frame.Render(target); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
x -= w
|
|
|
|
|
|
|
|
// Bottom left
|
2020-07-26 14:52:54 -04:00
|
|
|
if err := g.frame.SetCurrentFrame(9); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
w, h = g.frame.GetCurrentFrameSize()
|
2020-07-26 14:52:54 -04:00
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
g.frame.SetPosition(x-w, y+h)
|
2020-07-26 14:52:54 -04:00
|
|
|
|
|
|
|
if err := g.frame.Render(target); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-12-28 23:32:53 -05:00
|
|
|
|
|
|
|
x, y = g.originX, g.originY
|
|
|
|
y += 64
|
|
|
|
|
|
|
|
// Panel
|
|
|
|
// Top left
|
2020-07-26 14:52:54 -04:00
|
|
|
if err := g.panel.SetCurrentFrame(4); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
w, h = g.panel.GetCurrentFrameSize()
|
2020-07-26 14:52:54 -04:00
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
g.panel.SetPosition(x, y+h)
|
2020-07-26 14:52:54 -04:00
|
|
|
|
|
|
|
if err := g.panel.Render(target); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
x += w
|
|
|
|
|
|
|
|
// Top right
|
2020-07-26 14:52:54 -04:00
|
|
|
if err := g.panel.SetCurrentFrame(5); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
w, h = g.panel.GetCurrentFrameSize()
|
2020-07-26 14:52:54 -04:00
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
g.panel.SetPosition(x, y+h)
|
2020-07-26 14:52:54 -04:00
|
|
|
|
|
|
|
if err := g.panel.Render(target); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
y += h
|
|
|
|
|
|
|
|
// Bottom right
|
2020-07-26 14:52:54 -04:00
|
|
|
if err := g.panel.SetCurrentFrame(7); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
w, h = g.panel.GetCurrentFrameSize()
|
|
|
|
g.panel.SetPosition(x, y+h)
|
2020-07-26 14:52:54 -04:00
|
|
|
|
|
|
|
if err := g.panel.Render(target); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-12-28 23:32:53 -05:00
|
|
|
|
|
|
|
// Bottom left
|
2020-07-26 14:52:54 -04:00
|
|
|
if err := g.panel.SetCurrentFrame(6); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
w, h = g.panel.GetCurrentFrameSize()
|
2020-07-26 14:52:54 -04:00
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
g.panel.SetPosition(x-w, y+h)
|
2020-07-26 14:52:54 -04:00
|
|
|
|
|
|
|
if err := g.panel.Render(target); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-12-28 23:32:53 -05:00
|
|
|
|
|
|
|
g.grid.Render(target)
|
2020-07-26 14:52:54 -04:00
|
|
|
|
|
|
|
return nil
|
2019-12-28 23:32:53 -05:00
|
|
|
}
|