1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-03 01:37:18 -04:00
OpenDiablo2/d2game/d2player/inventory.go

326 lines
8.2 KiB
Go
Raw Normal View History

package d2player
import (
"fmt"
Removing d2datadict singletons (#738) * Remove weapons, armor, misc, itemCommon, itemTyps datadict singletons - removed loader calls from d2app - removed the HeroObjects singleton from `d2core/d2inventory` - added an InventoryItemFactory in d2inventory - package-level functions that use data records are now methods of the InventoryItemFactory - renamed ItemGenerator in d2item to ItemFactory - package-level functions that use records are now methods of ItemFactory - d2map.MapEntityFactory now has an item factory instance for creating items - fixed a bug in unique item record loader where it loaded an empty record - added a PlayerStateFactory for creating a player state (uses the asset manager) - updated the test inventory/equipment code in d2player to handle errors from the ItemFactory - character select and character creation screens have a player state and inventory item factory - updated item tests to use the item factory * minor edit * Removed d2datadict.Experience singleton added a HeroStatsFactory, much like the other factories. The factory gets an asset manager reference in order to use data records. * removed d2datadict.AutoMagic singleton * removed d2datadict.AutoMap singleton * removed d2datadict.BodyLocations singleton * removed d2datadict.Books singleton * Removed singletons for level records - removed loader calls in d2app - changed type references from d2datadict to d2records - added a `MapGenerator` in d2mapgen which uses thew asset manager and map engine - package-level map generation functions are now MapGenerator methods - `d2datadict.GetLevelDetails(id int)` is now a method of the RecordManager * remove SkillCalc and MissileCalc singletons * Removed CharStats and ItemStatCost singletons - added an ItemStatFactory which uses the asset manager to create stats - package-level functions for stats in d2item are now StatFactory methods - changed type references from d2datadict to d2records - `d2player.GetAllPlayerStates` is now a method of the `PlayerStateFactory` * Removed DkillDesc and Skills singletons from d2datadict - removed loader calls from d2app - diablo2stats.Stat instances are given a reference to the factory for doing record lookups * update the stats test to use mock a asset manager and stat factory * fixed diablo2stats tests and diablo2item tests * removed CompCodes singleton from d2datadict * remove cubemain singleton from d2datadict * removed DifficultyLevels singleton from d2datadict * removed ElemTypes singleton from d2datadict * removed events.go loader from d2datadict (was unused) * removed Gems singleton from d2datadict * removed Hireling and Inventory singletons from d2datadict * removed MagicPrefix and MagicSuffix singletons from d2datadict * removed ItemRatios singleton from d2datadict * removed Missiles singleton from d2datadict * removed MonModes singleton * Removed all monster and npc singletons from d2datadict - MapStamp instances now get a reference to their factory for doing record lookups * removed SoundEntry and SoundEnviron singletons from d2datadict
2020-09-20 17:52:01 -04:00
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2records"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2item/diablo2item"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
)
const (
frameInventoryTopLeft = 4
frameInventoryTopRight = 5
frameInventoryBottomLeft = 6
frameInventoryBottomRight = 7
)
const (
invCloseButtonX, invCloseButtonY = 419, 449
invGoldButtonX, invGoldButtonY = 485, 455
invGoldLabelX, invGoldLabelY = 510, 455
)
// NewInventory creates an inventory instance and returns a pointer to it
func NewInventory(asset *d2asset.AssetManager,
ui *d2ui.UIManager,
l d2util.LogLevel,
gold int,
record *d2records.InventoryRecord) (*Inventory, error) {
itemTooltip := ui.NewTooltip(d2resource.FontFormal11, d2resource.PaletteStatic, d2ui.TooltipXCenter, d2ui.TooltipYBottom)
itemFactory, err := diablo2item.NewItemFactory(asset)
if err != nil {
return nil, fmt.Errorf("during creating new item factory: %s", err)
}
2020-12-12 13:29:12 -05:00
mgp := NewMoveGoldPanel(asset, ui, gold, l)
inventory := &Inventory{
asset: asset,
uiManager: ui,
item: itemFactory,
grid: NewItemGrid(asset, ui, l, record),
originX: record.Panel.Left,
itemTooltip: itemTooltip,
// originY: record.Panel.Top,
originY: 0, // expansion data has these all offset by +60 ...
gold: gold,
moveGoldPanel: mgp,
}
inventory.moveGoldPanel.SetOnCloseCb(func() { inventory.onCloseGoldPanel() })
inventory.Logger = d2util.NewLogger()
inventory.Logger.SetLevel(l)
inventory.Logger.SetPrefix(logPrefix)
return inventory, nil
}
2020-08-11 18:01:33 -04:00
// Inventory represents the inventory
type Inventory struct {
asset *d2asset.AssetManager
item *diablo2item.ItemFactory
uiManager *d2ui.UIManager
panel *d2ui.Sprite
goldLabel *d2ui.Label
grid *ItemGrid
itemTooltip *d2ui.Tooltip
panelGroup *d2ui.WidgetGroup
hoverX int
hoverY int
originX int
originY int
lastMouseX int
lastMouseY int
hovering bool
isOpen bool
onCloseCb func()
gold int
moveGoldPanel *MoveGoldPanel
Removing d2datadict singletons (#738) * Remove weapons, armor, misc, itemCommon, itemTyps datadict singletons - removed loader calls from d2app - removed the HeroObjects singleton from `d2core/d2inventory` - added an InventoryItemFactory in d2inventory - package-level functions that use data records are now methods of the InventoryItemFactory - renamed ItemGenerator in d2item to ItemFactory - package-level functions that use records are now methods of ItemFactory - d2map.MapEntityFactory now has an item factory instance for creating items - fixed a bug in unique item record loader where it loaded an empty record - added a PlayerStateFactory for creating a player state (uses the asset manager) - updated the test inventory/equipment code in d2player to handle errors from the ItemFactory - character select and character creation screens have a player state and inventory item factory - updated item tests to use the item factory * minor edit * Removed d2datadict.Experience singleton added a HeroStatsFactory, much like the other factories. The factory gets an asset manager reference in order to use data records. * removed d2datadict.AutoMagic singleton * removed d2datadict.AutoMap singleton * removed d2datadict.BodyLocations singleton * removed d2datadict.Books singleton * Removed singletons for level records - removed loader calls in d2app - changed type references from d2datadict to d2records - added a `MapGenerator` in d2mapgen which uses thew asset manager and map engine - package-level map generation functions are now MapGenerator methods - `d2datadict.GetLevelDetails(id int)` is now a method of the RecordManager * remove SkillCalc and MissileCalc singletons * Removed CharStats and ItemStatCost singletons - added an ItemStatFactory which uses the asset manager to create stats - package-level functions for stats in d2item are now StatFactory methods - changed type references from d2datadict to d2records - `d2player.GetAllPlayerStates` is now a method of the `PlayerStateFactory` * Removed DkillDesc and Skills singletons from d2datadict - removed loader calls from d2app - diablo2stats.Stat instances are given a reference to the factory for doing record lookups * update the stats test to use mock a asset manager and stat factory * fixed diablo2stats tests and diablo2item tests * removed CompCodes singleton from d2datadict * remove cubemain singleton from d2datadict * removed DifficultyLevels singleton from d2datadict * removed ElemTypes singleton from d2datadict * removed events.go loader from d2datadict (was unused) * removed Gems singleton from d2datadict * removed Hireling and Inventory singletons from d2datadict * removed MagicPrefix and MagicSuffix singletons from d2datadict * removed ItemRatios singleton from d2datadict * removed Missiles singleton from d2datadict * removed MonModes singleton * Removed all monster and npc singletons from d2datadict - MapStamp instances now get a reference to their factory for doing record lookups * removed SoundEntry and SoundEnviron singletons from d2datadict
2020-09-20 17:52:01 -04:00
*d2util.Logger
}
2020-08-11 18:01:33 -04:00
// Toggle negates the open state of the inventory
func (g *Inventory) Toggle() {
if g.isOpen {
g.Close()
} else {
g.Open()
}
}
// Load the resources required by the inventory
func (g *Inventory) Load() {
var err error
g.panelGroup = g.uiManager.NewWidgetGroup(d2ui.RenderPriorityInventory)
frame := d2ui.NewUIFrame(g.asset, g.uiManager, d2ui.FrameRight)
g.panelGroup.AddWidget(frame)
g.panel, err = g.uiManager.NewSprite(d2resource.InventoryCharacterPanel, d2resource.PaletteSky)
if err != nil {
g.Error(err.Error())
}
closeButton := g.uiManager.NewButton(d2ui.ButtonTypeSquareClose, "")
closeButton.SetVisible(false)
closeButton.SetPosition(invCloseButtonX, invCloseButtonY)
closeButton.OnActivated(func() { g.Close() })
g.panelGroup.AddWidget(closeButton)
goldButton := g.uiManager.NewButton(d2ui.ButtonTypeGoldCoin, "")
goldButton.SetVisible(false)
goldButton.SetPosition(invGoldButtonX, invGoldButtonY)
goldButton.OnActivated(func() { g.onGoldClicked() })
// nolint:gocritic // this variable will be used in future
// deposite := g.asset.TranslateString("strGoldDeposit")
drop := g.asset.TranslateString("strGoldDrop")
// nolint:gocritic // this variable will be used in future
// withdraw := g.asset.TranslateString("strGoldWithdraw")
tooltip := g.uiManager.NewTooltip(d2resource.Font16, d2resource.PaletteSky, d2ui.TooltipXCenter, d2ui.TooltipYBottom)
// here should be switch-case statement for each of move-gold button descr
tooltip.SetText(drop)
tooltip.SetPosition(invGoldButtonX, invGoldButtonY)
goldButton.SetTooltip(tooltip)
g.panelGroup.AddWidget(goldButton)
g.goldLabel = g.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteStatic)
g.goldLabel.Alignment = d2ui.HorizontalAlignLeft
g.goldLabel.SetText(fmt.Sprintln(g.moveGoldPanel.gold))
g.goldLabel.SetPosition(invGoldLabelX, invGoldLabelY)
g.panelGroup.AddWidget(g.goldLabel)
// https://github.com/OpenDiablo2/OpenDiablo2/issues/795
Removing d2datadict singletons (#738) * Remove weapons, armor, misc, itemCommon, itemTyps datadict singletons - removed loader calls from d2app - removed the HeroObjects singleton from `d2core/d2inventory` - added an InventoryItemFactory in d2inventory - package-level functions that use data records are now methods of the InventoryItemFactory - renamed ItemGenerator in d2item to ItemFactory - package-level functions that use records are now methods of ItemFactory - d2map.MapEntityFactory now has an item factory instance for creating items - fixed a bug in unique item record loader where it loaded an empty record - added a PlayerStateFactory for creating a player state (uses the asset manager) - updated the test inventory/equipment code in d2player to handle errors from the ItemFactory - character select and character creation screens have a player state and inventory item factory - updated item tests to use the item factory * minor edit * Removed d2datadict.Experience singleton added a HeroStatsFactory, much like the other factories. The factory gets an asset manager reference in order to use data records. * removed d2datadict.AutoMagic singleton * removed d2datadict.AutoMap singleton * removed d2datadict.BodyLocations singleton * removed d2datadict.Books singleton * Removed singletons for level records - removed loader calls in d2app - changed type references from d2datadict to d2records - added a `MapGenerator` in d2mapgen which uses thew asset manager and map engine - package-level map generation functions are now MapGenerator methods - `d2datadict.GetLevelDetails(id int)` is now a method of the RecordManager * remove SkillCalc and MissileCalc singletons * Removed CharStats and ItemStatCost singletons - added an ItemStatFactory which uses the asset manager to create stats - package-level functions for stats in d2item are now StatFactory methods - changed type references from d2datadict to d2records - `d2player.GetAllPlayerStates` is now a method of the `PlayerStateFactory` * Removed DkillDesc and Skills singletons from d2datadict - removed loader calls from d2app - diablo2stats.Stat instances are given a reference to the factory for doing record lookups * update the stats test to use mock a asset manager and stat factory * fixed diablo2stats tests and diablo2item tests * removed CompCodes singleton from d2datadict * remove cubemain singleton from d2datadict * removed DifficultyLevels singleton from d2datadict * removed ElemTypes singleton from d2datadict * removed events.go loader from d2datadict (was unused) * removed Gems singleton from d2datadict * removed Hireling and Inventory singletons from d2datadict * removed MagicPrefix and MagicSuffix singletons from d2datadict * removed ItemRatios singleton from d2datadict * removed Missiles singleton from d2datadict * removed MonModes singleton * Removed all monster and npc singletons from d2datadict - MapStamp instances now get a reference to their factory for doing record lookups * removed SoundEntry and SoundEnviron singletons from d2datadict
2020-09-20 17:52:01 -04:00
testInventoryCodes := [][]string{
{"kit", "Crimson", "of the Bat", "of Frost"},
{"rin", "Steel", "of Shock"},
{"jav"},
{"buc"},
}
inventoryItems := make([]InventoryItem, 0)
for idx := range testInventoryCodes {
item, itemErr := g.item.NewItem(testInventoryCodes[idx]...)
if itemErr != nil {
Removing d2datadict singletons (#738) * Remove weapons, armor, misc, itemCommon, itemTyps datadict singletons - removed loader calls from d2app - removed the HeroObjects singleton from `d2core/d2inventory` - added an InventoryItemFactory in d2inventory - package-level functions that use data records are now methods of the InventoryItemFactory - renamed ItemGenerator in d2item to ItemFactory - package-level functions that use records are now methods of ItemFactory - d2map.MapEntityFactory now has an item factory instance for creating items - fixed a bug in unique item record loader where it loaded an empty record - added a PlayerStateFactory for creating a player state (uses the asset manager) - updated the test inventory/equipment code in d2player to handle errors from the ItemFactory - character select and character creation screens have a player state and inventory item factory - updated item tests to use the item factory * minor edit * Removed d2datadict.Experience singleton added a HeroStatsFactory, much like the other factories. The factory gets an asset manager reference in order to use data records. * removed d2datadict.AutoMagic singleton * removed d2datadict.AutoMap singleton * removed d2datadict.BodyLocations singleton * removed d2datadict.Books singleton * Removed singletons for level records - removed loader calls in d2app - changed type references from d2datadict to d2records - added a `MapGenerator` in d2mapgen which uses thew asset manager and map engine - package-level map generation functions are now MapGenerator methods - `d2datadict.GetLevelDetails(id int)` is now a method of the RecordManager * remove SkillCalc and MissileCalc singletons * Removed CharStats and ItemStatCost singletons - added an ItemStatFactory which uses the asset manager to create stats - package-level functions for stats in d2item are now StatFactory methods - changed type references from d2datadict to d2records - `d2player.GetAllPlayerStates` is now a method of the `PlayerStateFactory` * Removed DkillDesc and Skills singletons from d2datadict - removed loader calls from d2app - diablo2stats.Stat instances are given a reference to the factory for doing record lookups * update the stats test to use mock a asset manager and stat factory * fixed diablo2stats tests and diablo2item tests * removed CompCodes singleton from d2datadict * remove cubemain singleton from d2datadict * removed DifficultyLevels singleton from d2datadict * removed ElemTypes singleton from d2datadict * removed events.go loader from d2datadict (was unused) * removed Gems singleton from d2datadict * removed Hireling and Inventory singletons from d2datadict * removed MagicPrefix and MagicSuffix singletons from d2datadict * removed ItemRatios singleton from d2datadict * removed Missiles singleton from d2datadict * removed MonModes singleton * Removed all monster and npc singletons from d2datadict - MapStamp instances now get a reference to their factory for doing record lookups * removed SoundEntry and SoundEnviron singletons from d2datadict
2020-09-20 17:52:01 -04:00
continue
}
item.Identify()
inventoryItems = append(inventoryItems, item)
}
// https://github.com/OpenDiablo2/OpenDiablo2/issues/795
Removing d2datadict singletons (#738) * Remove weapons, armor, misc, itemCommon, itemTyps datadict singletons - removed loader calls from d2app - removed the HeroObjects singleton from `d2core/d2inventory` - added an InventoryItemFactory in d2inventory - package-level functions that use data records are now methods of the InventoryItemFactory - renamed ItemGenerator in d2item to ItemFactory - package-level functions that use records are now methods of ItemFactory - d2map.MapEntityFactory now has an item factory instance for creating items - fixed a bug in unique item record loader where it loaded an empty record - added a PlayerStateFactory for creating a player state (uses the asset manager) - updated the test inventory/equipment code in d2player to handle errors from the ItemFactory - character select and character creation screens have a player state and inventory item factory - updated item tests to use the item factory * minor edit * Removed d2datadict.Experience singleton added a HeroStatsFactory, much like the other factories. The factory gets an asset manager reference in order to use data records. * removed d2datadict.AutoMagic singleton * removed d2datadict.AutoMap singleton * removed d2datadict.BodyLocations singleton * removed d2datadict.Books singleton * Removed singletons for level records - removed loader calls in d2app - changed type references from d2datadict to d2records - added a `MapGenerator` in d2mapgen which uses thew asset manager and map engine - package-level map generation functions are now MapGenerator methods - `d2datadict.GetLevelDetails(id int)` is now a method of the RecordManager * remove SkillCalc and MissileCalc singletons * Removed CharStats and ItemStatCost singletons - added an ItemStatFactory which uses the asset manager to create stats - package-level functions for stats in d2item are now StatFactory methods - changed type references from d2datadict to d2records - `d2player.GetAllPlayerStates` is now a method of the `PlayerStateFactory` * Removed DkillDesc and Skills singletons from d2datadict - removed loader calls from d2app - diablo2stats.Stat instances are given a reference to the factory for doing record lookups * update the stats test to use mock a asset manager and stat factory * fixed diablo2stats tests and diablo2item tests * removed CompCodes singleton from d2datadict * remove cubemain singleton from d2datadict * removed DifficultyLevels singleton from d2datadict * removed ElemTypes singleton from d2datadict * removed events.go loader from d2datadict (was unused) * removed Gems singleton from d2datadict * removed Hireling and Inventory singletons from d2datadict * removed MagicPrefix and MagicSuffix singletons from d2datadict * removed ItemRatios singleton from d2datadict * removed Missiles singleton from d2datadict * removed MonModes singleton * Removed all monster and npc singletons from d2datadict - MapStamp instances now get a reference to their factory for doing record lookups * removed SoundEntry and SoundEnviron singletons from d2datadict
2020-09-20 17:52:01 -04:00
testEquippedItemCodes := map[d2enum.EquippedSlot][]string{
d2enum.EquippedSlotLeftArm: {"wnd"},
d2enum.EquippedSlotRightArm: {"buc"},
d2enum.EquippedSlotHead: {"crn"},
d2enum.EquippedSlotTorso: {"plt"},
d2enum.EquippedSlotLegs: {"vbt"},
d2enum.EquippedSlotBelt: {"vbl"},
d2enum.EquippedSlotGloves: {"lgl"},
d2enum.EquippedSlotLeftHand: {"rin"},
d2enum.EquippedSlotRightHand: {"rin"},
d2enum.EquippedSlotNeck: {"amu"},
}
for slot := range testEquippedItemCodes {
item, itemErr := g.item.NewItem(testEquippedItemCodes[slot]...)
if itemErr != nil {
Removing d2datadict singletons (#738) * Remove weapons, armor, misc, itemCommon, itemTyps datadict singletons - removed loader calls from d2app - removed the HeroObjects singleton from `d2core/d2inventory` - added an InventoryItemFactory in d2inventory - package-level functions that use data records are now methods of the InventoryItemFactory - renamed ItemGenerator in d2item to ItemFactory - package-level functions that use records are now methods of ItemFactory - d2map.MapEntityFactory now has an item factory instance for creating items - fixed a bug in unique item record loader where it loaded an empty record - added a PlayerStateFactory for creating a player state (uses the asset manager) - updated the test inventory/equipment code in d2player to handle errors from the ItemFactory - character select and character creation screens have a player state and inventory item factory - updated item tests to use the item factory * minor edit * Removed d2datadict.Experience singleton added a HeroStatsFactory, much like the other factories. The factory gets an asset manager reference in order to use data records. * removed d2datadict.AutoMagic singleton * removed d2datadict.AutoMap singleton * removed d2datadict.BodyLocations singleton * removed d2datadict.Books singleton * Removed singletons for level records - removed loader calls in d2app - changed type references from d2datadict to d2records - added a `MapGenerator` in d2mapgen which uses thew asset manager and map engine - package-level map generation functions are now MapGenerator methods - `d2datadict.GetLevelDetails(id int)` is now a method of the RecordManager * remove SkillCalc and MissileCalc singletons * Removed CharStats and ItemStatCost singletons - added an ItemStatFactory which uses the asset manager to create stats - package-level functions for stats in d2item are now StatFactory methods - changed type references from d2datadict to d2records - `d2player.GetAllPlayerStates` is now a method of the `PlayerStateFactory` * Removed DkillDesc and Skills singletons from d2datadict - removed loader calls from d2app - diablo2stats.Stat instances are given a reference to the factory for doing record lookups * update the stats test to use mock a asset manager and stat factory * fixed diablo2stats tests and diablo2item tests * removed CompCodes singleton from d2datadict * remove cubemain singleton from d2datadict * removed DifficultyLevels singleton from d2datadict * removed ElemTypes singleton from d2datadict * removed events.go loader from d2datadict (was unused) * removed Gems singleton from d2datadict * removed Hireling and Inventory singletons from d2datadict * removed MagicPrefix and MagicSuffix singletons from d2datadict * removed ItemRatios singleton from d2datadict * removed Missiles singleton from d2datadict * removed MonModes singleton * Removed all monster and npc singletons from d2datadict - MapStamp instances now get a reference to their factory for doing record lookups * removed SoundEntry and SoundEnviron singletons from d2datadict
2020-09-20 17:52:01 -04:00
continue
}
g.grid.ChangeEquippedSlot(slot, item)
}
2020-08-11 18:01:33 -04:00
_, err = g.grid.Add(inventoryItems...)
2020-08-11 18:01:33 -04:00
if err != nil {
g.Errorf("could not add items to the inventory, err: %v", err.Error())
2020-08-11 18:01:33 -04:00
}
g.moveGoldPanel.Load()
g.panelGroup.SetVisible(false)
}
// Open opens the inventory
func (g *Inventory) Open() {
g.isOpen = true
g.panelGroup.SetVisible(true)
}
// Close closes the inventory
func (g *Inventory) Close() {
g.isOpen = false
g.moveGoldPanel.Close()
g.panelGroup.SetVisible(false)
g.onCloseCb()
}
// SetOnCloseCb the callback run on closing the inventory
func (g *Inventory) SetOnCloseCb(cb func()) {
g.onCloseCb = cb
}
func (g *Inventory) onGoldClicked() {
g.Info("Move gold action clicked")
g.toggleMoveGoldPanel()
}
func (g *Inventory) toggleMoveGoldPanel() {
g.moveGoldPanel.Toggle()
}
func (g *Inventory) onCloseGoldPanel() {
}
// IsOpen returns true if the inventory is open
func (g *Inventory) IsOpen() bool {
return g.isOpen
}
// Advance advances the state of the Inventory
func (g *Inventory) Advance(_ float64) {
if !g.IsOpen() {
return
}
g.goldLabel.SetText(fmt.Sprintln(g.moveGoldPanel.gold))
}
2020-08-11 18:01:33 -04:00
// Render draws the inventory onto the given surface
func (g *Inventory) Render(target d2interface.Surface) {
if !g.isOpen {
return
}
g.renderFrame(target)
2020-07-26 14:52:54 -04:00
g.grid.Render(target)
g.renderItemHover(target)
}
2020-07-26 14:52:54 -04:00
func (g *Inventory) renderFrame(target d2interface.Surface) {
frames := []int{
frameInventoryTopLeft,
frameInventoryTopRight,
frameInventoryBottomRight,
frameInventoryBottomLeft,
2020-07-26 14:52:54 -04:00
}
x, y := g.originX+1, g.originY
y += 64
2020-07-26 14:52:54 -04:00
for _, frame := range frames {
if err := g.panel.SetCurrentFrame(frame); err != nil {
g.Error(err.Error())
return
}
w, h := g.panel.GetCurrentFrameSize()
2020-07-26 14:52:54 -04:00
g.panel.SetPosition(x, y+h)
g.panel.Render(target)
2020-07-26 14:52:54 -04:00
switch frame {
case frameInventoryTopLeft:
x += w
case frameInventoryTopRight:
y += h
case frameInventoryBottomRight:
2020-10-26 08:00:30 -04:00
x = g.originX + 1
}
2020-07-26 14:52:54 -04:00
}
}
2020-07-26 14:52:54 -04:00
func (g *Inventory) renderItemHover(target d2interface.Surface) {
hovering := false
for idx := range g.grid.items {
item := g.grid.items[idx]
ix, iy := g.grid.SlotToScreen(item.InventoryGridSlot())
iw, ih := g.grid.sprites[item.GetItemCode()].GetCurrentFrameSize()
mx, my := g.lastMouseX, g.lastMouseY
hovering = hovering || ((mx > ix) && (mx < ix+iw) && (my > iy) && (my < iy+ih))
if hovering {
if !g.hovering {
// set the initial hover coordinates
// this is so that moving mouse doesnt move the description
g.hoverX, g.hoverY = mx, my
}
g.renderItemDescription(target, item)
break
}
}
g.hovering = hovering
}
func (g *Inventory) renderItemDescription(target d2interface.Surface, i InventoryItem) {
if !g.moveGoldPanel.IsOpen() {
lines := i.GetItemDescription()
g.itemTooltip.SetTextLines(lines)
_, y := g.grid.SlotToScreen(i.InventoryGridSlot())
g.itemTooltip.SetPosition(g.hoverX, y)
g.itemTooltip.Render(target)
}
}