mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-06-12 02:30:43 +00:00
gold (#943)
* Init for gold button and label * gold button and label in inventory menu * gold value saved/loaded from player save file Co-authored-by: M. Sz <mszeptuch@protonmail.com>
This commit is contained in:
parent
24affd785c
commit
7919b742bd
|
@ -286,7 +286,6 @@ func (am *AssetManager) TranslateString(key string) string {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix to allow v.setDescLabels("#123") to be bypassed for a patch in issue #360. Reenable later.
|
// Fix to allow v.setDescLabels("#123") to be bypassed for a patch in issue #360. Reenable later.
|
||||||
// log.Panicf("Could not find a string for the key '%s'", key)
|
// log.Panicf("Could not find a string for the key '%s'", key)
|
||||||
return key
|
return key
|
||||||
|
|
|
@ -18,4 +18,5 @@ type HeroState struct {
|
||||||
Y float64 `json:"y"`
|
Y float64 `json:"y"`
|
||||||
LeftSkill int `json:"leftSkill"`
|
LeftSkill int `json:"leftSkill"`
|
||||||
RightSkill int `json:"rightSkill"`
|
RightSkill int `json:"rightSkill"`
|
||||||
|
Gold int `json:"Gold"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ func NewAnimatedEntity(x, y int, animation d2interface.Animation) *AnimatedEntit
|
||||||
// NewPlayer creates a new player entity and returns a pointer to it.
|
// NewPlayer creates a new player entity and returns a pointer to it.
|
||||||
func (f *MapEntityFactory) NewPlayer(id, name string, x, y, direction int, heroType d2enum.Hero,
|
func (f *MapEntityFactory) NewPlayer(id, name string, x, y, direction int, heroType d2enum.Hero,
|
||||||
stats *d2hero.HeroStatsState, skills map[int]*d2hero.HeroSkill, equipment *d2inventory.CharacterEquipment,
|
stats *d2hero.HeroStatsState, skills map[int]*d2hero.HeroSkill, equipment *d2inventory.CharacterEquipment,
|
||||||
leftSkill, rightSkill int) *Player {
|
leftSkill, rightSkill int, gold int) *Player {
|
||||||
layerEquipment := &[d2enum.CompositeTypeMax]string{
|
layerEquipment := &[d2enum.CompositeTypeMax]string{
|
||||||
d2enum.CompositeTypeHead: equipment.Head.GetArmorClass(),
|
d2enum.CompositeTypeHead: equipment.Head.GetArmorClass(),
|
||||||
d2enum.CompositeTypeTorso: equipment.Torso.GetArmorClass(),
|
d2enum.CompositeTypeTorso: equipment.Torso.GetArmorClass(),
|
||||||
|
@ -101,6 +101,7 @@ func (f *MapEntityFactory) NewPlayer(id, name string, x, y, direction int, heroT
|
||||||
isRunToggled: false,
|
isRunToggled: false,
|
||||||
isInTown: true,
|
isInTown: true,
|
||||||
isRunning: false,
|
isRunning: false,
|
||||||
|
Gold: gold,
|
||||||
}
|
}
|
||||||
|
|
||||||
result.mapEntity.uuid = id
|
result.mapEntity.uuid = id
|
||||||
|
|
|
@ -23,6 +23,7 @@ type Player struct {
|
||||||
LeftSkill *d2hero.HeroSkill
|
LeftSkill *d2hero.HeroSkill
|
||||||
RightSkill *d2hero.HeroSkill
|
RightSkill *d2hero.HeroSkill
|
||||||
Class d2enum.Hero
|
Class d2enum.Hero
|
||||||
|
Gold int
|
||||||
lastPathSize int
|
lastPathSize int
|
||||||
isInTown bool
|
isInTown bool
|
||||||
isRunToggled bool
|
isRunToggled bool
|
||||||
|
|
|
@ -38,9 +38,16 @@ const (
|
||||||
ButtonTypeMinipanelQuest ButtonType = 18
|
ButtonTypeMinipanelQuest ButtonType = 18
|
||||||
ButtonTypeMinipanelMen ButtonType = 19
|
ButtonTypeMinipanelMen ButtonType = 19
|
||||||
ButtonTypeSquareClose ButtonType = 20
|
ButtonTypeSquareClose ButtonType = 20
|
||||||
ButtonTypeSkillTreeTab ButtonType = 21
|
ButtonTypeSquareOk ButtonType = 21
|
||||||
ButtonTypeMinipanelOpenClose ButtonType = 22
|
ButtonTypeSkillTreeTab ButtonType = 22
|
||||||
ButtonTypeMinipanelParty ButtonType = 23
|
ButtonTypeMinipanelOpenClose ButtonType = 23
|
||||||
|
ButtonTypeMinipanelParty ButtonType = 24
|
||||||
|
ButtonTypeBuy ButtonType = 25
|
||||||
|
ButtonTypeSell ButtonType = 26
|
||||||
|
ButtonTypeRepair ButtonType = 27
|
||||||
|
ButtonTypeRepairAll ButtonType = 28
|
||||||
|
ButtonTypeLeftArrow ButtonType = 29
|
||||||
|
ButtonTypeRightArrow ButtonType = 30
|
||||||
|
|
||||||
ButtonNoFixedWidth int = -1
|
ButtonNoFixedWidth int = -1
|
||||||
ButtonNoFixedHeight int = -1
|
ButtonNoFixedHeight int = -1
|
||||||
|
@ -53,7 +60,16 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// buyButtonBaseFrame = 2 // base frame offset of the "buy" button dc6
|
||||||
|
// sellButtonBaseFrame = 4 // base frame offset of the "sell" button dc6
|
||||||
|
// repairButtonBaseFrame = 6 // base frame offset of the "repair" button dc6
|
||||||
|
// quaryButtonBaseFrame = 8 // base frame offset of the "quary" button dc6
|
||||||
closeButtonBaseFrame = 10 // base frame offset of the "close" button dc6
|
closeButtonBaseFrame = 10 // base frame offset of the "close" button dc6
|
||||||
|
// leftArrowButtonBaseFrame = 12 // base frame offset of the "leftArrow" button dc6
|
||||||
|
// rightArrowButtonBaseFrame = 14 // base frame offset of the "rightArrow" button dc6
|
||||||
|
okButtonBaseFrame = 16 // base frame offset of the "ok" button dc6
|
||||||
|
// repairAllButtonBaseFrame = 18 // base frame offset of the "repair all" button dc6
|
||||||
|
// ?AllButtonBaseFrame = 20 // base frame offset of the "?" button dc6
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -88,6 +104,7 @@ type ButtonLayout struct {
|
||||||
const (
|
const (
|
||||||
buttonTooltipNone int = iota
|
buttonTooltipNone int = iota
|
||||||
buttonTooltipClose
|
buttonTooltipClose
|
||||||
|
buttonTooltipOk
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -146,6 +163,10 @@ const (
|
||||||
buttonRunSegmentsY = 1
|
buttonRunSegmentsY = 1
|
||||||
buttonRunDisabledFrame = -1
|
buttonRunDisabledFrame = -1
|
||||||
|
|
||||||
|
buttonGoldCoinSegmentsX = 1
|
||||||
|
buttonGoldCoinSegmentsY = 1
|
||||||
|
buttonGoldCoinDisabledFrame = -1
|
||||||
|
|
||||||
pressedButtonOffset = 2
|
pressedButtonOffset = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -238,6 +259,21 @@ func getButtonLayouts() map[ButtonType]ButtonLayout {
|
||||||
FixedHeight: ButtonNoFixedHeight,
|
FixedHeight: ButtonNoFixedHeight,
|
||||||
LabelColor: greyAlpha100,
|
LabelColor: greyAlpha100,
|
||||||
},
|
},
|
||||||
|
ButtonTypeGoldCoin: {
|
||||||
|
XSegments: buttonGoldCoinSegmentsX,
|
||||||
|
YSegments: buttonGoldCoinSegmentsY,
|
||||||
|
DisabledFrame: buttonGoldCoinDisabledFrame,
|
||||||
|
DisabledColor: lightGreyAlpha75,
|
||||||
|
ResourceName: d2resource.GoldCoinButton,
|
||||||
|
PaletteName: d2resource.PaletteSky,
|
||||||
|
Toggleable: true,
|
||||||
|
FontPath: d2resource.FontRediculous,
|
||||||
|
AllowFrameChange: true,
|
||||||
|
HasImage: true,
|
||||||
|
FixedWidth: ButtonNoFixedWidth,
|
||||||
|
FixedHeight: ButtonNoFixedHeight,
|
||||||
|
LabelColor: greyAlpha100,
|
||||||
|
},
|
||||||
ButtonTypeSquareClose: {
|
ButtonTypeSquareClose: {
|
||||||
XSegments: buttonBuySellSegmentsX,
|
XSegments: buttonBuySellSegmentsX,
|
||||||
YSegments: buttonBuySellSegmentsY,
|
YSegments: buttonBuySellSegmentsY,
|
||||||
|
@ -257,6 +293,25 @@ func getButtonLayouts() map[ButtonType]ButtonLayout {
|
||||||
TooltipXOffset: buttonCloseTooltipXOffset,
|
TooltipXOffset: buttonCloseTooltipXOffset,
|
||||||
TooltipYOffset: buttonCloseTooltipYOffset,
|
TooltipYOffset: buttonCloseTooltipYOffset,
|
||||||
},
|
},
|
||||||
|
ButtonTypeSquareOk: {
|
||||||
|
XSegments: buttonBuySellSegmentsX,
|
||||||
|
YSegments: buttonBuySellSegmentsY,
|
||||||
|
DisabledFrame: buttonBuySellDisabledFrame,
|
||||||
|
DisabledColor: lightGreyAlpha75,
|
||||||
|
ResourceName: d2resource.BuySellButton,
|
||||||
|
PaletteName: d2resource.PaletteUnits,
|
||||||
|
Toggleable: true,
|
||||||
|
FontPath: d2resource.Font30,
|
||||||
|
AllowFrameChange: true,
|
||||||
|
BaseFrame: okButtonBaseFrame,
|
||||||
|
HasImage: true,
|
||||||
|
FixedWidth: ButtonNoFixedWidth,
|
||||||
|
FixedHeight: ButtonNoFixedHeight,
|
||||||
|
LabelColor: greyAlpha100,
|
||||||
|
Tooltip: buttonTooltipOk,
|
||||||
|
TooltipXOffset: buttonCloseTooltipXOffset,
|
||||||
|
TooltipYOffset: buttonCloseTooltipYOffset,
|
||||||
|
},
|
||||||
ButtonTypeSkillTreeTab: {
|
ButtonTypeSkillTreeTab: {
|
||||||
XSegments: buttonSkillTreeTabXSegments,
|
XSegments: buttonSkillTreeTabXSegments,
|
||||||
YSegments: buttonSkillTreeTabYSegments,
|
YSegments: buttonSkillTreeTabYSegments,
|
||||||
|
@ -521,6 +576,9 @@ func (v *Button) createTooltip() {
|
||||||
case buttonTooltipClose:
|
case buttonTooltipClose:
|
||||||
t = v.manager.NewTooltip(d2resource.Font16, d2resource.PaletteSky, TooltipXCenter, TooltipYBottom)
|
t = v.manager.NewTooltip(d2resource.Font16, d2resource.PaletteSky, TooltipXCenter, TooltipYBottom)
|
||||||
t.SetText(v.manager.asset.TranslateString("strClose"))
|
t.SetText(v.manager.asset.TranslateString("strClose"))
|
||||||
|
case buttonTooltipOk:
|
||||||
|
t = v.manager.NewTooltip(d2resource.Font16, d2resource.PaletteSky, TooltipXCenter, TooltipYBottom)
|
||||||
|
t.SetText(v.manager.asset.TranslateString("#971"))
|
||||||
}
|
}
|
||||||
|
|
||||||
t.SetVisible(false)
|
t.SetVisible(false)
|
||||||
|
|
|
@ -365,6 +365,7 @@ func (v *CharacterSelect) updateCharacterBoxes() {
|
||||||
&equipment,
|
&equipment,
|
||||||
v.gameStates[idx].LeftSkill,
|
v.gameStates[idx].LeftSkill,
|
||||||
v.gameStates[idx].RightSkill,
|
v.gameStates[idx].RightSkill,
|
||||||
|
v.gameStates[idx].Gold,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -209,7 +209,7 @@ func NewGameControls(
|
||||||
inventoryRecord := asset.Records.Layout.Inventory[inventoryRecordKey]
|
inventoryRecord := asset.Records.Layout.Inventory[inventoryRecordKey]
|
||||||
|
|
||||||
heroStatsPanel := NewHeroStatsPanel(asset, ui, hero.Name(), hero.Class, l, hero.Stats)
|
heroStatsPanel := NewHeroStatsPanel(asset, ui, hero.Name(), hero.Class, l, hero.Stats)
|
||||||
inventory := NewInventory(asset, ui, l, inventoryRecord)
|
inventory := NewInventory(asset, ui, l, hero.Gold, inventoryRecord)
|
||||||
skilltree := newSkillTree(hero.Skills, hero.Class, asset, l, ui)
|
skilltree := newSkillTree(hero.Skills, hero.Class, asset, l, ui)
|
||||||
|
|
||||||
miniPanel := newMiniPanel(asset, ui, l, isSinglePlayer)
|
miniPanel := newMiniPanel(asset, ui, l, isSinglePlayer)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package d2player
|
package d2player
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2records"
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2records"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||||
|
@ -21,12 +23,15 @@ const (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
invCloseButtonX, invCloseButtonY = 419, 449
|
invCloseButtonX, invCloseButtonY = 419, 449
|
||||||
|
invGoldButtonX, invGoldButtonY = 485, 455
|
||||||
|
invGoldLabelX, invGoldLabelY = 510, 455
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewInventory creates an inventory instance and returns a pointer to it
|
// NewInventory creates an inventory instance and returns a pointer to it
|
||||||
func NewInventory(asset *d2asset.AssetManager,
|
func NewInventory(asset *d2asset.AssetManager,
|
||||||
ui *d2ui.UIManager,
|
ui *d2ui.UIManager,
|
||||||
l d2util.LogLevel,
|
l d2util.LogLevel,
|
||||||
|
gold int,
|
||||||
record *d2records.InventoryRecord) *Inventory {
|
record *d2records.InventoryRecord) *Inventory {
|
||||||
itemTooltip := ui.NewTooltip(d2resource.FontFormal11, d2resource.PaletteStatic, d2ui.TooltipXCenter, d2ui.TooltipYBottom)
|
itemTooltip := ui.NewTooltip(d2resource.FontFormal11, d2resource.PaletteStatic, d2ui.TooltipXCenter, d2ui.TooltipYBottom)
|
||||||
|
|
||||||
|
@ -42,6 +47,7 @@ func NewInventory(asset *d2asset.AssetManager,
|
||||||
itemTooltip: itemTooltip,
|
itemTooltip: itemTooltip,
|
||||||
// originY: record.Panel.Top,
|
// originY: record.Panel.Top,
|
||||||
originY: 0, // expansion data has these all offset by +60 ...
|
originY: 0, // expansion data has these all offset by +60 ...
|
||||||
|
gold: gold,
|
||||||
}
|
}
|
||||||
|
|
||||||
inventory.Logger = d2util.NewLogger()
|
inventory.Logger = d2util.NewLogger()
|
||||||
|
@ -53,32 +59,32 @@ func NewInventory(asset *d2asset.AssetManager,
|
||||||
|
|
||||||
// Inventory represents the inventory
|
// Inventory represents the inventory
|
||||||
type Inventory struct {
|
type Inventory struct {
|
||||||
asset *d2asset.AssetManager
|
asset *d2asset.AssetManager
|
||||||
item *diablo2item.ItemFactory
|
item *diablo2item.ItemFactory
|
||||||
uiManager *d2ui.UIManager
|
uiManager *d2ui.UIManager
|
||||||
frame *d2ui.UIFrame
|
frame *d2ui.UIFrame
|
||||||
panel *d2ui.Sprite
|
panel *d2ui.Sprite
|
||||||
grid *ItemGrid
|
grid *ItemGrid
|
||||||
itemTooltip *d2ui.Tooltip
|
itemTooltip *d2ui.Tooltip
|
||||||
closeButton *d2ui.Button
|
closeButton *d2ui.Button
|
||||||
hoverX int
|
goldButton *d2ui.Button
|
||||||
hoverY int
|
goldLabel *d2ui.Label
|
||||||
originX int
|
panelGroup *d2ui.WidgetGroup
|
||||||
originY int
|
panelMoveGold *d2ui.WidgetGroup
|
||||||
lastMouseX int
|
hoverX int
|
||||||
lastMouseY int
|
hoverY int
|
||||||
hovering bool
|
originX int
|
||||||
isOpen bool
|
originY int
|
||||||
onCloseCb func()
|
lastMouseX int
|
||||||
|
lastMouseY int
|
||||||
|
hovering bool
|
||||||
|
isOpen bool
|
||||||
|
onCloseCb func()
|
||||||
|
gold int
|
||||||
|
|
||||||
*d2util.Logger
|
*d2util.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsOpen returns true if the inventory is open
|
|
||||||
func (g *Inventory) IsOpen() bool {
|
|
||||||
return g.isOpen
|
|
||||||
}
|
|
||||||
|
|
||||||
// Toggle negates the open state of the inventory
|
// Toggle negates the open state of the inventory
|
||||||
func (g *Inventory) Toggle() {
|
func (g *Inventory) Toggle() {
|
||||||
if g.isOpen {
|
if g.isOpen {
|
||||||
|
@ -88,34 +94,42 @@ func (g *Inventory) Toggle() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open opens the inventory
|
|
||||||
func (g *Inventory) Open() {
|
|
||||||
g.isOpen = true
|
|
||||||
g.closeButton.SetVisible(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close closes the inventory
|
|
||||||
func (g *Inventory) Close() {
|
|
||||||
g.isOpen = false
|
|
||||||
g.closeButton.SetVisible(false)
|
|
||||||
g.onCloseCb()
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetOnCloseCb the callback run on closing the inventory
|
|
||||||
func (g *Inventory) SetOnCloseCb(cb func()) {
|
|
||||||
g.onCloseCb = cb
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load the resources required by the inventory
|
// Load the resources required by the inventory
|
||||||
func (g *Inventory) Load() {
|
func (g *Inventory) Load() {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
g.panelGroup = g.uiManager.NewWidgetGroup(d2ui.RenderPriorityHeroStatsPanel)
|
||||||
|
g.panelMoveGold = g.uiManager.NewWidgetGroup(d2ui.RenderPriorityHeroStatsPanel)
|
||||||
|
|
||||||
g.frame = d2ui.NewUIFrame(g.asset, g.uiManager, d2ui.FrameRight)
|
g.frame = d2ui.NewUIFrame(g.asset, g.uiManager, d2ui.FrameRight)
|
||||||
|
g.panelGroup.AddWidget(g.frame)
|
||||||
|
|
||||||
g.closeButton = g.uiManager.NewButton(d2ui.ButtonTypeSquareClose, "")
|
g.closeButton = g.uiManager.NewButton(d2ui.ButtonTypeSquareClose, "")
|
||||||
g.closeButton.SetVisible(false)
|
g.closeButton.SetVisible(false)
|
||||||
g.closeButton.SetPosition(invCloseButtonX, invCloseButtonY)
|
g.closeButton.SetPosition(invCloseButtonX, invCloseButtonY)
|
||||||
g.closeButton.OnActivated(func() { g.Close() })
|
g.closeButton.OnActivated(func() { g.Close() })
|
||||||
|
g.panelGroup.AddWidget(g.closeButton)
|
||||||
|
|
||||||
g.panel, _ = g.uiManager.NewSprite(d2resource.InventoryCharacterPanel, d2resource.PaletteSky)
|
g.goldButton = g.uiManager.NewButton(d2ui.ButtonTypeGoldCoin, "")
|
||||||
|
g.goldButton.SetVisible(false)
|
||||||
|
g.goldButton.SetPosition(invGoldButtonX, invGoldButtonY)
|
||||||
|
g.goldButton.OnActivated(func() { g.onGoldClicked() })
|
||||||
|
g.panelGroup.AddWidget(g.goldButton)
|
||||||
|
|
||||||
|
g.goldLabel = g.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteStatic)
|
||||||
|
g.goldLabel.Alignment = d2ui.HorizontalAlignLeft
|
||||||
|
g.goldLabel.SetText(fmt.Sprintln(g.gold))
|
||||||
|
g.goldLabel.SetPosition(invGoldLabelX, invGoldLabelY)
|
||||||
|
g.panelGroup.AddWidget(g.goldLabel)
|
||||||
|
|
||||||
|
g.goldButton = g.uiManager.NewButton(d2ui.ButtonTypeGoldCoin, "")
|
||||||
|
|
||||||
|
g.panel, err = g.uiManager.NewSprite(d2resource.InventoryCharacterPanel, d2resource.PaletteSky)
|
||||||
|
if err != nil {
|
||||||
|
g.Error(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
g.panelGroup.SetVisible(false)
|
||||||
|
|
||||||
// https://github.com/OpenDiablo2/OpenDiablo2/issues/795
|
// https://github.com/OpenDiablo2/OpenDiablo2/issues/795
|
||||||
testInventoryCodes := [][]string{
|
testInventoryCodes := [][]string{
|
||||||
|
@ -128,8 +142,8 @@ func (g *Inventory) Load() {
|
||||||
inventoryItems := make([]InventoryItem, 0)
|
inventoryItems := make([]InventoryItem, 0)
|
||||||
|
|
||||||
for idx := range testInventoryCodes {
|
for idx := range testInventoryCodes {
|
||||||
item, err := g.item.NewItem(testInventoryCodes[idx]...)
|
item, itemErr := g.item.NewItem(testInventoryCodes[idx]...)
|
||||||
if err != nil {
|
if itemErr != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,26 +166,55 @@ func (g *Inventory) Load() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for slot := range testEquippedItemCodes {
|
for slot := range testEquippedItemCodes {
|
||||||
item, err := g.item.NewItem(testEquippedItemCodes[slot]...)
|
item, itemErr := g.item.NewItem(testEquippedItemCodes[slot]...)
|
||||||
if err != nil {
|
if itemErr != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
g.grid.ChangeEquippedSlot(slot, item)
|
g.grid.ChangeEquippedSlot(slot, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := g.grid.Add(inventoryItems...)
|
_, err = g.grid.Add(inventoryItems...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Errorf("could not add items to the inventory, err: %v", err.Error())
|
g.Errorf("could not add items to the inventory, err: %v", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.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("Gold action clicked")
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsOpen returns true if the inventory is open
|
||||||
|
func (g *Inventory) IsOpen() bool {
|
||||||
|
return g.isOpen
|
||||||
|
}
|
||||||
|
|
||||||
// Render draws the inventory onto the given surface
|
// Render draws the inventory onto the given surface
|
||||||
func (g *Inventory) Render(target d2interface.Surface) {
|
func (g *Inventory) Render(target d2interface.Surface) {
|
||||||
if !g.isOpen {
|
if !g.isOpen {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g.goldLabel.Render(target)
|
||||||
|
|
||||||
err := g.renderFrame(target)
|
err := g.renderFrame(target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Error(err.Error())
|
g.Error(err.Error())
|
||||||
|
|
|
@ -220,7 +220,7 @@ func (g *GameClient) handleAddPlayerPacket(packet d2netpacket.NetPacket) error {
|
||||||
d2hero.HydrateSkills(player.Skills, g.asset)
|
d2hero.HydrateSkills(player.Skills, g.asset)
|
||||||
|
|
||||||
newPlayer := g.MapEngine.NewPlayer(player.ID, player.Name, player.X, player.Y, 0,
|
newPlayer := g.MapEngine.NewPlayer(player.ID, player.Name, player.X, player.Y, 0,
|
||||||
player.HeroType, player.Stats, player.Skills, &player.Equipment, player.LeftSkill, player.RightSkill)
|
player.HeroType, player.Stats, player.Skills, &player.Equipment, player.LeftSkill, player.RightSkill, player.Gold)
|
||||||
|
|
||||||
g.Players[newPlayer.ID()] = newPlayer
|
g.Players[newPlayer.ID()] = newPlayer
|
||||||
g.MapEngine.AddEntity(newPlayer)
|
g.MapEngine.AddEntity(newPlayer)
|
||||||
|
|
|
@ -24,13 +24,20 @@ type AddPlayerPacket struct {
|
||||||
Skills map[int]*d2hero.HeroSkill `json:"heroSkills"`
|
Skills map[int]*d2hero.HeroSkill `json:"heroSkills"`
|
||||||
LeftSkill int `json:"leftSkill"`
|
LeftSkill int `json:"leftSkill"`
|
||||||
RightSkill int `json:"rightSkill"`
|
RightSkill int `json:"rightSkill"`
|
||||||
|
Gold int
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateAddPlayerPacket returns a NetPacket which declares an
|
// CreateAddPlayerPacket returns a NetPacket which declares an
|
||||||
// AddPlayerPacket with the data in given parameters.
|
// AddPlayerPacket with the data in given parameters.
|
||||||
func CreateAddPlayerPacket(id, name string, x, y int, heroType d2enum.Hero,
|
func CreateAddPlayerPacket(
|
||||||
stats *d2hero.HeroStatsState, skills map[int]*d2hero.HeroSkill, equipment d2inventory.CharacterEquipment,
|
id, name string,
|
||||||
leftSkill, rightSkill int) NetPacket {
|
x, y int,
|
||||||
|
heroType d2enum.Hero,
|
||||||
|
stats *d2hero.HeroStatsState,
|
||||||
|
skills map[int]*d2hero.HeroSkill,
|
||||||
|
equipment d2inventory.CharacterEquipment,
|
||||||
|
leftSkill, rightSkill int,
|
||||||
|
gold int) NetPacket {
|
||||||
addPlayerPacket := AddPlayerPacket{
|
addPlayerPacket := AddPlayerPacket{
|
||||||
ID: id,
|
ID: id,
|
||||||
Name: name,
|
Name: name,
|
||||||
|
@ -42,6 +49,7 @@ func CreateAddPlayerPacket(id, name string, x, y int, heroType d2enum.Hero,
|
||||||
Skills: skills,
|
Skills: skills,
|
||||||
LeftSkill: leftSkill,
|
LeftSkill: leftSkill,
|
||||||
RightSkill: rightSkill,
|
RightSkill: rightSkill,
|
||||||
|
Gold: gold,
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := json.Marshal(addPlayerPacket)
|
b, err := json.Marshal(addPlayerPacket)
|
||||||
|
|
|
@ -376,6 +376,7 @@ func (g *GameServer) handleClientConnection(client ClientConnection, x, y float6
|
||||||
playerState.Equipment,
|
playerState.Equipment,
|
||||||
playerState.LeftSkill,
|
playerState.LeftSkill,
|
||||||
playerState.RightSkill,
|
playerState.RightSkill,
|
||||||
|
playerState.Gold,
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, connection := range g.connections {
|
for _, connection := range g.connections {
|
||||||
|
@ -403,6 +404,7 @@ func (g *GameServer) handleClientConnection(client ClientConnection, x, y float6
|
||||||
conPlayerState.Equipment,
|
conPlayerState.Equipment,
|
||||||
conPlayerState.LeftSkill,
|
conPlayerState.LeftSkill,
|
||||||
conPlayerState.RightSkill,
|
conPlayerState.RightSkill,
|
||||||
|
conPlayerState.Gold,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user