2020-10-22 12:54:45 -04:00
|
|
|
package d2player
|
|
|
|
|
|
|
|
import (
|
2020-11-18 16:02:49 -05:00
|
|
|
"errors"
|
2020-10-22 12:54:45 -04:00
|
|
|
"fmt"
|
2020-12-15 14:03:24 -05:00
|
|
|
"strconv"
|
2020-10-22 12:54:45 -04:00
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
2020-11-18 16:02:49 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
2020-10-22 12:54:45 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-10-25 03:42:31 -04:00
|
|
|
tabButtonX = 628
|
|
|
|
tabButton0Y = 385
|
|
|
|
tabButton1Y = 277
|
|
|
|
tabButton2Y = 170
|
|
|
|
|
|
|
|
availSPLabelX = 677
|
|
|
|
availSPLabelY = 72
|
|
|
|
|
2020-10-25 10:54:39 -04:00
|
|
|
skillCloseButtonXLeft = 416
|
|
|
|
skillCloseButtonXMiddle = 501
|
|
|
|
skillCloseButtonXRight = 572
|
|
|
|
skillCloseButtonY = 449
|
2020-10-22 12:54:45 -04:00
|
|
|
)
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
const (
|
|
|
|
firstTab = iota
|
|
|
|
secondTab
|
|
|
|
thirdTab
|
2020-10-25 20:28:40 -04:00
|
|
|
numTabs
|
2020-10-25 03:42:31 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
tabIndexOffset = 4
|
|
|
|
|
|
|
|
frameOffsetTop = 4
|
|
|
|
frameOffsetBottom = 6
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
frameCommonTabTopLeft = iota
|
|
|
|
frameCommonTabTopRight
|
|
|
|
frameCommonTabBottomLeft
|
|
|
|
frameCommonTabBottomRight
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
frameSelectedTab1Full = 7
|
|
|
|
frameSelectedTab2Top = 9 // tab2 top and bottom portions are in 2 frames :(
|
|
|
|
frameSelectedTab2Bottom = 11
|
|
|
|
frameSelectedTab3Full = 13
|
|
|
|
)
|
|
|
|
|
2020-12-15 14:03:24 -05:00
|
|
|
const (
|
|
|
|
remainingPointsLabelX, remainingPointsLabelY = 677, 128
|
|
|
|
)
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
const (
|
|
|
|
skillTreePanelX = 401
|
|
|
|
skillTreePanelY = 64
|
|
|
|
)
|
|
|
|
|
2020-10-29 09:50:15 -04:00
|
|
|
const (
|
|
|
|
skillIconGreySat = 0.2
|
|
|
|
skillIconGreyBright = 0.44
|
|
|
|
)
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
type skillTreeTab struct {
|
2020-10-25 10:54:39 -04:00
|
|
|
buttonText string
|
|
|
|
button *d2ui.Button
|
|
|
|
closeButtonPosX int
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
func (st *skillTreeTab) createButton(uiManager *d2ui.UIManager, x, y int) {
|
2020-10-22 12:54:45 -04:00
|
|
|
st.button = uiManager.NewButton(d2ui.ButtonTypeSkillTreeTab, st.buttonText)
|
|
|
|
st.button.SetPosition(x, y)
|
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
type skillTreeHeroTypeResources struct {
|
2020-11-09 12:09:46 -05:00
|
|
|
skillSprite *d2ui.Sprite
|
2020-10-25 03:42:31 -04:00
|
|
|
skillIconPath string
|
|
|
|
skillPanel *d2ui.Sprite
|
2020-10-22 12:54:45 -04:00
|
|
|
skillPanelPath string
|
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
func newSkillTree(
|
2020-10-22 12:54:45 -04:00
|
|
|
skills map[int]*d2hero.HeroSkill,
|
2020-10-25 03:42:31 -04:00
|
|
|
heroClass d2enum.Hero,
|
2020-12-15 14:03:24 -05:00
|
|
|
hero *d2hero.HeroStatsState,
|
2020-10-22 12:54:45 -04:00
|
|
|
asset *d2asset.AssetManager,
|
2020-11-18 16:02:49 -05:00
|
|
|
l d2util.LogLevel,
|
2020-10-22 12:54:45 -04:00
|
|
|
ui *d2ui.UIManager,
|
2020-10-25 03:42:31 -04:00
|
|
|
) *skillTree {
|
|
|
|
st := &skillTree{
|
2020-11-09 12:09:46 -05:00
|
|
|
skills: skills,
|
|
|
|
heroClass: heroClass,
|
|
|
|
asset: asset,
|
|
|
|
uiManager: ui,
|
|
|
|
originX: skillTreePanelX,
|
|
|
|
originY: skillTreePanelY,
|
2020-12-15 14:03:24 -05:00
|
|
|
stats: hero,
|
2020-10-25 20:28:40 -04:00
|
|
|
tab: [numTabs]*skillTreeTab{
|
2020-10-22 12:54:45 -04:00
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
},
|
2020-11-18 16:02:49 -05:00
|
|
|
l: l,
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-11-22 00:36:59 -05:00
|
|
|
st.Logger = d2util.NewLogger()
|
|
|
|
st.Logger.SetLevel(l)
|
|
|
|
st.Logger.SetPrefix(logPrefix)
|
2020-11-18 16:02:49 -05:00
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
return st
|
|
|
|
}
|
|
|
|
|
2020-11-18 16:02:49 -05:00
|
|
|
type skillTree struct {
|
2020-12-15 14:03:24 -05:00
|
|
|
resources *skillTreeHeroTypeResources
|
|
|
|
asset *d2asset.AssetManager
|
|
|
|
uiManager *d2ui.UIManager
|
|
|
|
skills map[int]*d2hero.HeroSkill
|
|
|
|
skillIcons []*skillIcon
|
|
|
|
heroClass d2enum.Hero
|
|
|
|
availSPLabel *d2ui.Label
|
|
|
|
closeButton *d2ui.Button
|
|
|
|
tab [numTabs]*skillTreeTab
|
|
|
|
remainingPoints *d2ui.Label
|
|
|
|
isOpen bool
|
|
|
|
originX int
|
|
|
|
originY int
|
|
|
|
selectedTab int
|
|
|
|
onCloseCb func()
|
|
|
|
panelGroup *d2ui.WidgetGroup
|
|
|
|
iconGroup *d2ui.WidgetGroup
|
|
|
|
panel *d2ui.CustomWidget
|
|
|
|
stats *d2hero.HeroStatsState
|
2020-11-18 16:02:49 -05:00
|
|
|
|
2020-11-22 00:36:59 -05:00
|
|
|
*d2util.Logger
|
|
|
|
l d2util.LogLevel
|
2020-11-18 16:02:49 -05:00
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
func (s *skillTree) load() {
|
2020-11-09 12:09:46 -05:00
|
|
|
s.panelGroup = s.uiManager.NewWidgetGroup(d2ui.RenderPrioritySkilltree)
|
|
|
|
s.iconGroup = s.uiManager.NewWidgetGroup(d2ui.RenderPrioritySkilltreeIcon)
|
|
|
|
|
2020-11-13 15:08:43 -05:00
|
|
|
s.panel = s.uiManager.NewCustomWidget(s.Render, 400, 600)
|
2020-11-09 12:09:46 -05:00
|
|
|
s.panelGroup.AddWidget(s.panel)
|
|
|
|
|
2021-01-07 00:53:01 -05:00
|
|
|
frame := s.uiManager.NewUIFrame(d2ui.FrameRight)
|
|
|
|
s.panelGroup.AddWidget(frame)
|
2020-11-09 12:09:46 -05:00
|
|
|
|
2020-10-25 10:54:39 -04:00
|
|
|
s.closeButton = s.uiManager.NewButton(d2ui.ButtonTypeSquareClose, "")
|
|
|
|
s.closeButton.SetVisible(false)
|
|
|
|
s.closeButton.OnActivated(func() { s.Close() })
|
2020-11-09 12:09:46 -05:00
|
|
|
s.panelGroup.AddWidget(s.closeButton)
|
2020-10-29 09:50:15 -04:00
|
|
|
|
2020-12-15 14:03:24 -05:00
|
|
|
s.remainingPoints = s.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteSky)
|
|
|
|
s.remainingPoints.SetPosition(remainingPointsLabelX, remainingPointsLabelY)
|
|
|
|
s.remainingPoints.Alignment = d2ui.HorizontalAlignCenter
|
|
|
|
s.remainingPoints.SetText(strconv.Itoa(s.stats.SkillPoints))
|
|
|
|
s.panelGroup.AddWidget(s.remainingPoints)
|
|
|
|
|
2020-11-18 16:02:49 -05:00
|
|
|
if err := s.setHeroTypeResourcePath(); err != nil {
|
2020-11-22 00:36:59 -05:00
|
|
|
s.Error(err.Error())
|
2020-11-18 16:02:49 -05:00
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
s.loadForHeroType()
|
2020-11-09 12:09:46 -05:00
|
|
|
|
|
|
|
for _, skill := range s.skills {
|
2020-11-18 16:02:49 -05:00
|
|
|
si := newSkillIcon(s.uiManager, s.resources.skillSprite, s.l, skill)
|
2020-11-09 12:09:46 -05:00
|
|
|
s.skillIcons = append(s.skillIcons, si)
|
|
|
|
s.iconGroup.AddWidget(si)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.panelGroup.SetVisible(false)
|
2020-10-22 12:54:45 -04:00
|
|
|
s.setTab(0)
|
2020-11-09 12:09:46 -05:00
|
|
|
s.iconGroup.SetVisible(false)
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
func (s *skillTree) loadForHeroType() {
|
2020-10-22 12:54:45 -04:00
|
|
|
sp, err := s.uiManager.NewSprite(s.resources.skillPanelPath, d2resource.PaletteSky)
|
|
|
|
if err != nil {
|
2020-11-22 00:36:59 -05:00
|
|
|
s.Error(err.Error())
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
s.resources.skillPanel = sp
|
|
|
|
|
|
|
|
si, err := s.uiManager.NewSprite(s.resources.skillIconPath, d2resource.PaletteSky)
|
|
|
|
if err != nil {
|
2020-11-22 00:36:59 -05:00
|
|
|
s.Error(err.Error())
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-11-09 12:09:46 -05:00
|
|
|
s.resources.skillSprite = si
|
2020-10-22 12:54:45 -04:00
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
s.tab[firstTab].createButton(s.uiManager, tabButtonX, tabButton0Y)
|
|
|
|
s.tab[firstTab].button.OnActivated(func() { s.setTab(firstTab) })
|
2020-11-09 12:09:46 -05:00
|
|
|
s.panelGroup.AddWidget(s.tab[firstTab].button)
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
s.tab[secondTab].createButton(s.uiManager, tabButtonX, tabButton1Y)
|
|
|
|
s.tab[secondTab].button.OnActivated(func() { s.setTab(secondTab) })
|
2020-11-09 12:09:46 -05:00
|
|
|
s.panelGroup.AddWidget(s.tab[secondTab].button)
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
s.tab[thirdTab].createButton(s.uiManager, tabButtonX, tabButton2Y)
|
|
|
|
s.tab[thirdTab].button.OnActivated(func() { s.setTab(thirdTab) })
|
2020-11-09 12:09:46 -05:00
|
|
|
s.panelGroup.AddWidget(s.tab[thirdTab].button)
|
2020-10-22 12:54:45 -04:00
|
|
|
|
|
|
|
s.availSPLabel = s.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteSky)
|
2020-10-25 03:42:31 -04:00
|
|
|
s.availSPLabel.SetPosition(availSPLabelX, availSPLabelY)
|
2020-11-13 15:03:30 -05:00
|
|
|
s.availSPLabel.Alignment = d2ui.HorizontalAlignCenter
|
2020-11-03 14:10:11 -05:00
|
|
|
s.availSPLabel.SetText(s.makeTabString("StrSklTree1", "StrSklTree2", "StrSklTree3"))
|
2020-11-09 12:09:46 -05:00
|
|
|
s.panelGroup.AddWidget(s.availSPLabel)
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
type heroTabData struct {
|
|
|
|
resources *skillTreeHeroTypeResources
|
|
|
|
str1, str2, str3 string
|
2020-10-25 20:28:40 -04:00
|
|
|
closeButtonPos [numTabs]int
|
2020-10-25 03:42:31 -04:00
|
|
|
}
|
|
|
|
|
2020-11-03 14:10:11 -05:00
|
|
|
func (s *skillTree) makeTabString(keys ...interface{}) string {
|
2020-10-25 03:42:31 -04:00
|
|
|
translations := make([]interface{}, len(keys))
|
|
|
|
|
|
|
|
token := "%s"
|
|
|
|
format := token
|
2020-10-22 12:54:45 -04:00
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
for idx, key := range keys {
|
|
|
|
if idx > 0 {
|
|
|
|
format += "\n" + token
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
|
|
|
|
2020-11-03 14:10:11 -05:00
|
|
|
translations[idx] = s.asset.TranslateString(key.(string))
|
2020-10-25 03:42:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf(format, translations...)
|
|
|
|
}
|
|
|
|
|
2020-10-25 20:28:40 -04:00
|
|
|
func makeCloseButtonPos(close1, close2, close3 int) [numTabs]int {
|
|
|
|
return [numTabs]int{close1, close2, close3}
|
2020-10-25 10:54:39 -04:00
|
|
|
}
|
|
|
|
|
2020-10-26 18:55:13 -04:00
|
|
|
func (s *skillTree) getTab(class d2enum.Hero) *heroTabData {
|
|
|
|
tabMap := map[d2enum.Hero]*heroTabData{
|
2020-10-25 03:42:31 -04:00
|
|
|
d2enum.HeroBarbarian: {
|
|
|
|
&skillTreeHeroTypeResources{
|
|
|
|
skillPanelPath: d2resource.SkillsPanelBarbarian,
|
|
|
|
skillIconPath: d2resource.BarbarianSkills,
|
|
|
|
},
|
2020-11-03 14:10:11 -05:00
|
|
|
s.makeTabString("StrSklTree21", "StrSklTree4"),
|
|
|
|
s.makeTabString("StrSklTree21", "StrSklTree22"),
|
|
|
|
s.makeTabString("StrSklTree20"),
|
2020-10-25 10:54:39 -04:00
|
|
|
makeCloseButtonPos(
|
|
|
|
skillCloseButtonXRight,
|
|
|
|
skillCloseButtonXLeft,
|
|
|
|
skillCloseButtonXRight),
|
2020-10-25 03:42:31 -04:00
|
|
|
},
|
|
|
|
d2enum.HeroNecromancer: {
|
|
|
|
&skillTreeHeroTypeResources{
|
|
|
|
skillPanelPath: d2resource.SkillsPanelNecromancer,
|
|
|
|
skillIconPath: d2resource.NecromancerSkills,
|
|
|
|
},
|
2020-11-03 14:10:11 -05:00
|
|
|
s.makeTabString("StrSklTree19"),
|
|
|
|
s.makeTabString("StrSklTree17", "StrSklTree18", "StrSklTree5"),
|
|
|
|
s.makeTabString("StrSklTree16", "StrSklTree5"),
|
2020-10-25 10:54:39 -04:00
|
|
|
makeCloseButtonPos(
|
|
|
|
skillCloseButtonXLeft,
|
|
|
|
skillCloseButtonXRight,
|
|
|
|
skillCloseButtonXLeft),
|
2020-10-25 03:42:31 -04:00
|
|
|
},
|
|
|
|
d2enum.HeroPaladin: {
|
|
|
|
&skillTreeHeroTypeResources{
|
|
|
|
skillPanelPath: d2resource.SkillsPanelPaladin,
|
|
|
|
skillIconPath: d2resource.PaladinSkills,
|
|
|
|
},
|
2020-11-03 14:10:11 -05:00
|
|
|
s.makeTabString("StrSklTree15", "StrSklTree4"),
|
|
|
|
s.makeTabString("StrSklTree14", "StrSklTree13"),
|
|
|
|
s.makeTabString("StrSklTree12", "StrSklTree13"),
|
2020-10-25 10:54:39 -04:00
|
|
|
makeCloseButtonPos(
|
|
|
|
skillCloseButtonXLeft,
|
|
|
|
skillCloseButtonXMiddle,
|
|
|
|
skillCloseButtonXLeft),
|
2020-10-25 03:42:31 -04:00
|
|
|
},
|
|
|
|
d2enum.HeroAssassin: {
|
|
|
|
&skillTreeHeroTypeResources{
|
2020-10-22 12:54:45 -04:00
|
|
|
skillPanelPath: d2resource.SkillsPanelAssassin,
|
2020-10-25 03:42:31 -04:00
|
|
|
skillIconPath: d2resource.AssassinSkills,
|
|
|
|
},
|
2020-11-03 14:10:11 -05:00
|
|
|
s.makeTabString("StrSklTree30"),
|
|
|
|
s.makeTabString("StrSklTree31", "StrSklTree32"),
|
|
|
|
s.makeTabString("StrSklTree33", "StrSklTree34"),
|
2020-10-25 10:54:39 -04:00
|
|
|
makeCloseButtonPos(
|
|
|
|
skillCloseButtonXMiddle,
|
|
|
|
skillCloseButtonXRight,
|
|
|
|
skillCloseButtonXLeft),
|
2020-10-25 03:42:31 -04:00
|
|
|
},
|
|
|
|
d2enum.HeroSorceress: {
|
|
|
|
&skillTreeHeroTypeResources{
|
2020-10-22 12:54:45 -04:00
|
|
|
skillPanelPath: d2resource.SkillsPanelSorcerer,
|
2020-10-25 03:42:31 -04:00
|
|
|
skillIconPath: d2resource.SorcererSkills,
|
|
|
|
},
|
2020-11-03 14:10:11 -05:00
|
|
|
s.makeTabString("StrSklTree25", "StrSklTree5"),
|
|
|
|
s.makeTabString("StrSklTree24", "StrSklTree5"),
|
|
|
|
s.makeTabString("StrSklTree23", "StrSklTree5"),
|
2020-10-25 10:54:39 -04:00
|
|
|
makeCloseButtonPos(
|
|
|
|
skillCloseButtonXLeft,
|
|
|
|
skillCloseButtonXLeft,
|
|
|
|
skillCloseButtonXRight),
|
2020-10-25 03:42:31 -04:00
|
|
|
},
|
|
|
|
d2enum.HeroAmazon: {
|
|
|
|
&skillTreeHeroTypeResources{
|
2020-10-22 12:54:45 -04:00
|
|
|
skillPanelPath: d2resource.SkillsPanelAmazon,
|
2020-10-25 03:42:31 -04:00
|
|
|
skillIconPath: d2resource.AmazonSkills,
|
|
|
|
},
|
2020-11-03 14:10:11 -05:00
|
|
|
s.makeTabString("StrSklTree10", "StrSklTree11", "StrSklTree4"),
|
|
|
|
s.makeTabString("StrSklTree8", "StrSklTree9", "StrSklTree4"),
|
|
|
|
s.makeTabString("StrSklTree6", "StrSklTree7", "StrSklTree4"),
|
2020-10-25 10:54:39 -04:00
|
|
|
makeCloseButtonPos(
|
|
|
|
skillCloseButtonXRight,
|
|
|
|
skillCloseButtonXMiddle,
|
|
|
|
skillCloseButtonXLeft),
|
2020-10-25 03:42:31 -04:00
|
|
|
},
|
|
|
|
d2enum.HeroDruid: {
|
|
|
|
&skillTreeHeroTypeResources{
|
2020-10-22 12:54:45 -04:00
|
|
|
skillPanelPath: d2resource.SkillsPanelDruid,
|
2020-10-25 03:42:31 -04:00
|
|
|
skillIconPath: d2resource.DruidSkills,
|
|
|
|
},
|
2020-11-03 14:10:11 -05:00
|
|
|
s.makeTabString("StrSklTree26"),
|
|
|
|
s.makeTabString("StrSklTree27", "StrSklTree28"),
|
|
|
|
s.makeTabString("StrSklTree29"),
|
2020-10-25 10:54:39 -04:00
|
|
|
makeCloseButtonPos(
|
|
|
|
skillCloseButtonXRight,
|
|
|
|
skillCloseButtonXRight,
|
|
|
|
skillCloseButtonXRight),
|
2020-10-25 03:42:31 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-10-26 18:55:13 -04:00
|
|
|
return tabMap[class]
|
2020-10-25 03:42:31 -04:00
|
|
|
}
|
|
|
|
|
2020-11-18 16:02:49 -05:00
|
|
|
func (s *skillTree) setHeroTypeResourcePath() error {
|
2020-10-26 18:55:13 -04:00
|
|
|
entry := s.getTab(s.heroClass)
|
2020-11-18 16:02:49 -05:00
|
|
|
|
2020-10-26 18:55:13 -04:00
|
|
|
if entry == nil {
|
2020-11-18 16:02:49 -05:00
|
|
|
return errors.New("unknown hero type")
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
s.resources = entry.resources
|
|
|
|
s.tab[firstTab].buttonText = entry.str1
|
2020-10-25 10:54:39 -04:00
|
|
|
s.tab[secondTab].buttonText = entry.str2
|
|
|
|
s.tab[thirdTab].buttonText = entry.str3
|
|
|
|
|
2020-10-25 20:28:40 -04:00
|
|
|
for i := 0; i < numTabs; i++ {
|
2020-10-25 10:54:39 -04:00
|
|
|
s.tab[i].closeButtonPosX = entry.closeButtonPos[i]
|
|
|
|
}
|
2020-11-18 16:02:49 -05:00
|
|
|
|
|
|
|
return nil
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
// Toggle the skill tree visibility
|
|
|
|
func (s *skillTree) Toggle() {
|
2020-11-22 00:36:59 -05:00
|
|
|
s.Info("SkillTree toggled")
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
if s.isOpen {
|
|
|
|
s.Close()
|
|
|
|
} else {
|
|
|
|
s.Open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
// Close the skill tree
|
|
|
|
func (s *skillTree) Close() {
|
2020-10-22 12:54:45 -04:00
|
|
|
s.isOpen = false
|
2020-10-25 20:28:40 -04:00
|
|
|
|
2020-11-09 12:09:46 -05:00
|
|
|
s.panelGroup.SetVisible(false)
|
|
|
|
s.iconGroup.SetVisible(false)
|
2020-10-25 20:28:40 -04:00
|
|
|
|
2020-10-25 10:54:39 -04:00
|
|
|
s.onCloseCb()
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
// Open the skill tree
|
|
|
|
func (s *skillTree) Open() {
|
2020-10-22 12:54:45 -04:00
|
|
|
s.isOpen = true
|
|
|
|
|
2020-11-09 12:09:46 -05:00
|
|
|
s.panelGroup.SetVisible(true)
|
2020-11-16 04:41:01 -05:00
|
|
|
s.iconGroup.SetVisible(true)
|
2020-10-25 20:28:40 -04:00
|
|
|
|
2020-11-09 12:09:46 -05:00
|
|
|
// we only want to enable the icons of our current tab again
|
|
|
|
s.setTab(s.selectedTab)
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
func (s *skillTree) IsOpen() bool {
|
2020-10-22 12:54:45 -04:00
|
|
|
return s.isOpen
|
|
|
|
}
|
|
|
|
|
2020-10-25 10:54:39 -04:00
|
|
|
// Set the callback run on closing the skilltree
|
|
|
|
func (s *skillTree) SetOnCloseCb(cb func()) {
|
2020-10-25 20:03:23 -04:00
|
|
|
s.onCloseCb = cb
|
2020-10-25 10:54:39 -04:00
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
func (s *skillTree) setTab(tab int) {
|
2020-10-22 12:54:45 -04:00
|
|
|
s.selectedTab = tab
|
2020-10-25 10:54:39 -04:00
|
|
|
s.closeButton.SetPosition(s.tab[tab].closeButtonPosX, skillCloseButtonY)
|
2020-11-09 12:09:46 -05:00
|
|
|
|
|
|
|
for _, si := range s.skillIcons {
|
|
|
|
si.SetVisible(si.skill.SkillPage == tab+1)
|
|
|
|
}
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
func (s *skillTree) renderPanelSegment(
|
2020-10-22 12:54:45 -04:00
|
|
|
target d2interface.Surface,
|
2020-11-11 08:55:59 -05:00
|
|
|
frame int) {
|
2020-10-22 12:54:45 -04:00
|
|
|
if err := s.resources.skillPanel.SetCurrentFrame(frame); err != nil {
|
2020-11-22 00:36:59 -05:00
|
|
|
s.Error(err.Error())
|
2020-11-11 08:55:59 -05:00
|
|
|
return
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-11-11 09:05:04 -05:00
|
|
|
s.resources.skillPanel.Render(target)
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
|
|
|
|
2020-11-11 08:55:59 -05:00
|
|
|
func (s *skillTree) renderTabCommon(target d2interface.Surface) {
|
2020-10-22 12:54:45 -04:00
|
|
|
skillPanel := s.resources.skillPanel
|
|
|
|
x, y := s.originX, s.originY
|
|
|
|
|
|
|
|
// top
|
2020-10-25 03:42:31 -04:00
|
|
|
w, h, err := skillPanel.GetFrameSize(frameCommonTabTopLeft)
|
2020-10-22 12:54:45 -04:00
|
|
|
if err != nil {
|
2020-11-22 00:36:59 -05:00
|
|
|
s.Error(err.Error())
|
2020-11-11 08:55:59 -05:00
|
|
|
return
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
y += h
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
skillPanel.SetPosition(x, y)
|
2020-11-11 08:55:59 -05:00
|
|
|
s.renderPanelSegment(target, frameCommonTabTopLeft)
|
2020-10-22 12:54:45 -04:00
|
|
|
|
|
|
|
skillPanel.SetPosition(x+w, y)
|
2020-11-11 08:55:59 -05:00
|
|
|
s.renderPanelSegment(target, frameCommonTabTopRight)
|
2020-10-22 12:54:45 -04:00
|
|
|
|
|
|
|
// bottom
|
2020-10-25 03:42:31 -04:00
|
|
|
_, h, err = skillPanel.GetFrameSize(frameCommonTabBottomLeft)
|
2020-10-22 12:54:45 -04:00
|
|
|
if err != nil {
|
2020-11-22 00:36:59 -05:00
|
|
|
s.Error(err.Error())
|
2020-11-11 08:55:59 -05:00
|
|
|
return
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
y += h
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
skillPanel.SetPosition(x, y)
|
2020-11-11 08:55:59 -05:00
|
|
|
s.renderPanelSegment(target, frameCommonTabBottomLeft)
|
2020-10-22 12:54:45 -04:00
|
|
|
|
|
|
|
skillPanel.SetPosition(x+w, y)
|
2020-11-11 08:55:59 -05:00
|
|
|
s.renderPanelSegment(target, frameCommonTabBottomRight)
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
|
|
|
|
2020-11-11 08:55:59 -05:00
|
|
|
func (s *skillTree) renderTab(target d2interface.Surface, tab int) {
|
2020-10-25 03:42:31 -04:00
|
|
|
topFrame := frameOffsetTop + (tabIndexOffset * tab)
|
|
|
|
bottomFrame := frameOffsetBottom + (tabIndexOffset * tab)
|
2020-10-22 12:54:45 -04:00
|
|
|
|
|
|
|
skillPanel := s.resources.skillPanel
|
|
|
|
x, y := s.originX, s.originY
|
|
|
|
|
|
|
|
// top
|
2020-10-25 03:42:31 -04:00
|
|
|
_, h0, err := skillPanel.GetFrameSize(topFrame)
|
2020-10-22 12:54:45 -04:00
|
|
|
if err != nil {
|
2020-11-22 00:36:59 -05:00
|
|
|
s.Error(err.Error())
|
2020-11-11 08:55:59 -05:00
|
|
|
return
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
y += h0
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
skillPanel.SetPosition(x, y)
|
2020-11-11 08:55:59 -05:00
|
|
|
s.renderPanelSegment(target, topFrame)
|
2020-10-22 12:54:45 -04:00
|
|
|
|
|
|
|
// bottom
|
2020-10-25 03:42:31 -04:00
|
|
|
w, h1, err := skillPanel.GetFrameSize(bottomFrame)
|
2020-10-22 12:54:45 -04:00
|
|
|
if err != nil {
|
2020-11-22 00:36:59 -05:00
|
|
|
s.Error(err.Error())
|
2020-11-11 08:55:59 -05:00
|
|
|
return
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
skillPanel.SetPosition(x, y+h1)
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-11-11 08:55:59 -05:00
|
|
|
s.renderPanelSegment(target, bottomFrame)
|
2020-10-22 12:54:45 -04:00
|
|
|
|
|
|
|
// tab button highlighted
|
|
|
|
switch tab {
|
2020-10-25 03:42:31 -04:00
|
|
|
case firstTab:
|
2020-10-22 12:54:45 -04:00
|
|
|
skillPanel.SetPosition(x+w, y+h1)
|
2020-11-11 08:55:59 -05:00
|
|
|
s.renderPanelSegment(target, frameSelectedTab1Full)
|
2020-10-25 03:42:31 -04:00
|
|
|
case secondTab:
|
2020-10-22 12:54:45 -04:00
|
|
|
x += w
|
2020-10-25 03:42:31 -04:00
|
|
|
skillPanel.SetPosition(x, s.originY+h0)
|
2020-11-11 08:55:59 -05:00
|
|
|
s.renderPanelSegment(target, frameSelectedTab2Top)
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
skillPanel.SetPosition(x, y+h1)
|
2020-11-11 08:55:59 -05:00
|
|
|
s.renderPanelSegment(target, frameSelectedTab2Bottom)
|
2020-10-25 03:42:31 -04:00
|
|
|
case thirdTab:
|
2020-10-22 12:54:45 -04:00
|
|
|
skillPanel.SetPosition(x+w, y)
|
2020-11-11 08:55:59 -05:00
|
|
|
s.renderPanelSegment(target, frameSelectedTab3Full)
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
// Render the skill tree panel
|
2020-11-11 08:55:59 -05:00
|
|
|
func (s *skillTree) Render(target d2interface.Surface) {
|
|
|
|
s.renderTabCommon(target)
|
|
|
|
s.renderTab(target, s.selectedTab)
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|