1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-12-24 11:06:51 -05:00

add-buttons init

This commit is contained in:
M. Sz 2020-12-15 11:32:34 +01:00
parent 9c019afd94
commit 7e346bd039
4 changed files with 44 additions and 3 deletions

View File

@ -15,7 +15,7 @@ type HeroStatsState struct {
Dexterity int `json:"dexterity"`
Vitality int `json:"vitality"`
// there are stats and skills points remaining to add.
StatPoints int `json:"statPoints"`
StatsPoints int `json:"statsPoints"`
SkillPoints int `json:"skillPoints"`
Health int `json:"health"`
@ -39,7 +39,7 @@ func (f *HeroStateFactory) CreateHeroStatsState(heroClass d2enum.Hero, classStat
Dexterity: classStats.InitDex,
Vitality: classStats.InitVit,
Energy: classStats.InitEne,
StatPoints: 0,
StatsPoints: 0,
SkillPoints: 0,
MaxHealth: classStats.InitVit * classStats.LifePerVit,

View File

@ -55,6 +55,7 @@ const (
ButtonTypeSquelchChat ButtonType = 35
ButtonTypeTabBlank ButtonType = 36
ButtonTypeBlankQuestBtn ButtonType = 37
ButtonTypeAddSkill ButtonType = 38
ButtonNoFixedWidth int = -1
ButtonNoFixedHeight int = -1
@ -746,6 +747,19 @@ func getButtonLayouts() map[ButtonType]ButtonLayout {
FixedHeight: ButtonNoFixedHeight,
LabelColor: whiteAlpha100,
},
ButtonTypeAddSkill: {
XSegments: 1,
YSegments: 1,
DisabledColor: whiteAlpha100,
ResourceName: d2resource.AddSkillButton,
PaletteName: d2resource.PaletteSky,
Toggleable: true,
FontPath: d2resource.Font16,
AllowFrameChange: true,
HasImage: true,
FixedWidth: ButtonNoFixedWidth,
FixedHeight: ButtonNoFixedHeight,
},
}
}

View File

@ -224,7 +224,7 @@ func NewGameControls(
}
helpOverlay := NewHelpOverlay(asset, ui, l, keyMap)
hud := NewHUD(asset, ui, hero, miniPanel, actionableRegions, mapEngine, l, mapRenderer)
hud := NewHUD(asset, ui, hero, miniPanel, actionableRegions, mapEngine, hero.Stats, l, mapRenderer)
const blackAlpha50percent = 0x0000007f

View File

@ -10,6 +10,7 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapengine"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapentity"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2maprenderer"
@ -70,6 +71,11 @@ const (
whiteAlpha100 = 0xffffffff
)
const (
addStatsButtonX, addStatsButtonY = 206, 561
addSkillButtonX, addSkillButtonY = 563, 561
)
// HUD represents the always visible user interface of the game
type HUD struct {
actionableRegions []actionableRegion
@ -77,6 +83,7 @@ type HUD struct {
uiManager *d2ui.UIManager
mapEngine *d2mapengine.MapEngine
mapRenderer *d2maprenderer.MapRenderer
heroStats *d2hero.HeroStatsState
lastMouseX int
lastMouseY int
hero *d2mapentity.Player
@ -103,6 +110,8 @@ type HUD struct {
widgetLeftSkill *d2ui.CustomWidget
widgetRightSkill *d2ui.CustomWidget
panelBackground *d2ui.CustomWidget
addStatsButton *d2ui.Button
addSkillButton *d2ui.Button
panelGroup *d2ui.WidgetGroup
*d2util.Logger
}
@ -115,6 +124,7 @@ func NewHUD(
miniPanel *miniPanel,
actionableRegions []actionableRegion,
mapEngine *d2mapengine.MapEngine,
heroStats *d2hero.HeroStatsState,
l d2util.LogLevel,
mapRenderer *d2maprenderer.MapRenderer,
) *HUD {
@ -149,6 +159,7 @@ func NewHUD(
zoneChangeText: zoneLabel,
healthGlobe: healthGlobe,
manaGlobe: manaGlobe,
heroStats: heroStats,
}
hud.Logger = d2util.NewLogger()
@ -177,7 +188,23 @@ func (h *HUD) Load() {
h.loadCustomWidgets()
h.loadUIButtons()
h.addStatsButton = h.uiManager.NewButton(d2ui.ButtonTypeAddSkill, "")
h.addStatsButton.SetPosition(addStatsButtonX, addStatsButtonY)
h.addStatsButton.SetVisible(false)
h.panelGroup.AddWidget(h.addStatsButton)
h.addSkillButton = h.uiManager.NewButton(d2ui.ButtonTypeAddSkill, "")
h.addSkillButton.SetPosition(addSkillButtonX, addSkillButtonY)
h.addSkillButton.SetVisible(false)
h.panelGroup.AddWidget(h.addSkillButton)
h.panelGroup.SetVisible(true)
h.setAddButtonsVisible()
}
func (h *HUD) setAddButtonsVisible() {
h.addStatsButton.SetVisible(h.heroStats.StatsPoints > 0)
h.addSkillButton.SetVisible(h.heroStats.SkillPoints > 0)
}
func (h *HUD) loadCustomWidgets() {