2020-10-22 12:54:45 -04:00
|
|
|
package d2player
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2tbl"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
|
|
|
|
"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
|
|
|
|
|
|
|
|
skillIconXOff = 346
|
|
|
|
skillIconYOff = 59
|
|
|
|
skillIconDistX = 69
|
|
|
|
skillIconDistY = 68
|
2020-10-22 12:54:45 -04:00
|
|
|
)
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
const (
|
|
|
|
firstTab = iota
|
|
|
|
secondTab
|
|
|
|
thirdTab
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
skillTreePanelX = 401
|
|
|
|
skillTreePanelY = 64
|
|
|
|
)
|
|
|
|
|
|
|
|
type skillTreeTab struct {
|
|
|
|
buttonText string
|
|
|
|
button *d2ui.Button
|
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.SetVisible(false)
|
|
|
|
st.button.SetPosition(x, y)
|
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
type skillTreeHeroTypeResources struct {
|
|
|
|
skillIcon *d2ui.Sprite
|
|
|
|
skillIconPath string
|
|
|
|
skillPanel *d2ui.Sprite
|
2020-10-22 12:54:45 -04:00
|
|
|
skillPanelPath string
|
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
type skillTree struct {
|
|
|
|
resources *skillTreeHeroTypeResources
|
2020-10-22 12:54:45 -04:00
|
|
|
asset *d2asset.AssetManager
|
|
|
|
renderer d2interface.Renderer
|
|
|
|
guiManager *d2gui.GuiManager
|
|
|
|
uiManager *d2ui.UIManager
|
|
|
|
layout *d2gui.Layout
|
|
|
|
skills map[int]*d2hero.HeroSkill
|
|
|
|
heroClass d2enum.Hero
|
|
|
|
frame *d2ui.UIFrame
|
|
|
|
availSPLabel *d2ui.Label
|
2020-10-25 03:42:31 -04:00
|
|
|
tab [3]*skillTreeTab
|
2020-10-22 12:54:45 -04:00
|
|
|
isOpen bool
|
|
|
|
originX int
|
|
|
|
originY int
|
|
|
|
selectedTab int
|
|
|
|
}
|
|
|
|
|
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-10-22 12:54:45 -04:00
|
|
|
asset *d2asset.AssetManager,
|
|
|
|
renderer d2interface.Renderer,
|
|
|
|
ui *d2ui.UIManager,
|
|
|
|
guiManager *d2gui.GuiManager,
|
2020-10-25 03:42:31 -04:00
|
|
|
) *skillTree {
|
|
|
|
st := &skillTree{
|
|
|
|
skills: skills,
|
|
|
|
heroClass: heroClass,
|
|
|
|
asset: asset,
|
|
|
|
renderer: renderer,
|
|
|
|
uiManager: ui,
|
2020-10-22 12:54:45 -04:00
|
|
|
guiManager: guiManager,
|
2020-10-25 03:42:31 -04:00
|
|
|
originX: skillTreePanelX,
|
|
|
|
originY: skillTreePanelY,
|
|
|
|
tab: [3]*skillTreeTab{
|
2020-10-22 12:54:45 -04:00
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
},
|
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
return st
|
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
func (s *skillTree) load() {
|
2020-10-22 12:54:45 -04:00
|
|
|
s.frame = d2ui.NewUIFrame(s.asset, s.uiManager, d2ui.FrameRight)
|
|
|
|
|
|
|
|
s.setHeroTypeResourcePath()
|
2020-10-25 03:42:31 -04:00
|
|
|
s.loadForHeroType()
|
2020-10-22 12:54:45 -04:00
|
|
|
s.setTab(0)
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
log.Print(err)
|
|
|
|
}
|
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 {
|
|
|
|
log.Print(err)
|
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
s.resources.skillIcon = si
|
|
|
|
|
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) })
|
|
|
|
|
|
|
|
s.tab[secondTab].createButton(s.uiManager, tabButtonX, tabButton1Y)
|
|
|
|
s.tab[secondTab].button.OnActivated(func() { s.setTab(secondTab) })
|
|
|
|
|
|
|
|
s.tab[thirdTab].createButton(s.uiManager, tabButtonX, tabButton2Y)
|
|
|
|
s.tab[thirdTab].button.OnActivated(func() { s.setTab(thirdTab) })
|
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-10-22 12:54:45 -04:00
|
|
|
s.availSPLabel.Alignment = d2gui.HorizontalAlignCenter
|
2020-10-25 03:42:31 -04:00
|
|
|
s.availSPLabel.SetText(makeTabString("StrSklTree1", "StrSklTree2", "StrSklTree3"))
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeTabString(keys ...interface{}) string {
|
|
|
|
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-10-25 03:42:31 -04:00
|
|
|
translations[idx] = d2tbl.TranslateString(key.(string))
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf(format, translations...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *skillTree) getTab(class d2enum.Hero) (heroTabData, bool) {
|
|
|
|
tabMap := map[d2enum.Hero]heroTabData{
|
|
|
|
d2enum.HeroBarbarian: {
|
|
|
|
&skillTreeHeroTypeResources{
|
|
|
|
skillPanelPath: d2resource.SkillsPanelBarbarian,
|
|
|
|
skillIconPath: d2resource.BarbarianSkills,
|
|
|
|
},
|
|
|
|
makeTabString("StrSklTree21", "StrSklTree4"),
|
|
|
|
makeTabString("StrSklTree21", "StrSklTree22"),
|
|
|
|
makeTabString("StrSklTree20"),
|
|
|
|
},
|
|
|
|
d2enum.HeroNecromancer: {
|
|
|
|
&skillTreeHeroTypeResources{
|
|
|
|
skillPanelPath: d2resource.SkillsPanelNecromancer,
|
|
|
|
skillIconPath: d2resource.NecromancerSkills,
|
|
|
|
},
|
|
|
|
makeTabString("StrSklTree19"),
|
|
|
|
makeTabString("StrSklTree17", "StrSklTree18", "StrSklTree5"),
|
|
|
|
makeTabString("StrSklTree16", "StrSklTree5"),
|
|
|
|
},
|
|
|
|
d2enum.HeroPaladin: {
|
|
|
|
&skillTreeHeroTypeResources{
|
|
|
|
skillPanelPath: d2resource.SkillsPanelPaladin,
|
|
|
|
skillIconPath: d2resource.PaladinSkills,
|
|
|
|
},
|
|
|
|
makeTabString("StrSklTree15", "StrSklTree4"),
|
|
|
|
makeTabString("StrSklTree14", "StrSklTree13"),
|
|
|
|
makeTabString("StrSklTree12", "StrSklTree13"),
|
|
|
|
},
|
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
|
|
|
|
makeTabString("StrSklTree30"),
|
|
|
|
makeTabString("StrSklTree31", "StrSklTree32"),
|
|
|
|
makeTabString("StrSklTree33", "StrSklTree34"),
|
|
|
|
},
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
makeTabString("StrSklTree25", "StrSklTree5"),
|
|
|
|
makeTabString("StrSklTree24", "StrSklTree5"),
|
|
|
|
makeTabString("StrSklTree23", "StrSklTree5"),
|
|
|
|
},
|
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
makeTabString("StrSklTree10", "StrSklTree11", "StrSklTree4"),
|
|
|
|
makeTabString("StrSklTree8", "StrSklTree9", "StrSklTree4"),
|
|
|
|
makeTabString("StrSklTree6", "StrSklTree7", "StrSklTree4"),
|
|
|
|
},
|
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
makeTabString("StrSklTree26"),
|
|
|
|
makeTabString("StrSklTree27", "StrSklTree28"),
|
|
|
|
makeTabString("StrSklTree29"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
entry, found := tabMap[class]
|
|
|
|
|
|
|
|
return entry, found
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *skillTree) setHeroTypeResourcePath() {
|
|
|
|
entry, found := s.getTab(s.heroClass)
|
|
|
|
if !found {
|
2020-10-22 12:54:45 -04:00
|
|
|
log.Fatal("Unknown Hero Type")
|
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
s.resources = entry.resources
|
|
|
|
s.tab[firstTab].buttonText = entry.str1
|
|
|
|
s.tab[secondTab].buttonText = entry.str1
|
|
|
|
s.tab[thirdTab].buttonText = entry.str1
|
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-10-22 12:54:45 -04:00
|
|
|
fmt.Println("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
|
|
|
|
s.guiManager.SetLayout(nil)
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
for i := 0; i < 3; i++ {
|
2020-10-22 12:54:45 -04:00
|
|
|
s.tab[i].button.SetVisible(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
if s.layout == nil {
|
|
|
|
s.layout = d2gui.CreateLayout(s.renderer, d2gui.PositionTypeHorizontal, s.asset)
|
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
for i := 0; i < 3; i++ {
|
2020-10-22 12:54:45 -04:00
|
|
|
s.tab[i].button.SetVisible(true)
|
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
s.guiManager.SetLayout(s.layout)
|
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 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 03:42:31 -04:00
|
|
|
func (s *skillTree) renderPanelSegment(
|
2020-10-22 12:54:45 -04:00
|
|
|
target d2interface.Surface,
|
|
|
|
frame int) error {
|
|
|
|
if err := s.resources.skillPanel.SetCurrentFrame(frame); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
if err := s.resources.skillPanel.Render(target); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
func (s *skillTree) renderTabCommon(target d2interface.Surface) error {
|
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 {
|
|
|
|
return err
|
|
|
|
}
|
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-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
err = s.renderPanelSegment(target, frameCommonTabTopLeft)
|
|
|
|
if err != nil {
|
2020-10-22 12:54:45 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
skillPanel.SetPosition(x+w, y)
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
err = s.renderPanelSegment(target, frameCommonTabTopRight)
|
|
|
|
if err != nil {
|
2020-10-22 12:54:45 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
return err
|
|
|
|
}
|
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-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
err = s.renderPanelSegment(target, frameCommonTabBottomLeft)
|
|
|
|
if err != nil {
|
2020-10-22 12:54:45 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
skillPanel.SetPosition(x+w, y)
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
err = s.renderPanelSegment(target, frameCommonTabBottomRight)
|
|
|
|
if err != nil {
|
2020-10-22 12:54:45 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// available skill points label
|
|
|
|
s.availSPLabel.Render(target)
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
func (s *skillTree) renderTab(target d2interface.Surface, tab int) error {
|
|
|
|
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 {
|
|
|
|
return err
|
|
|
|
}
|
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-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
err = s.renderPanelSegment(target, topFrame)
|
|
|
|
if err != nil {
|
2020-10-22 12:54:45 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
return err
|
|
|
|
}
|
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
|
|
|
|
|
|
|
if err := s.renderPanelSegment(target, bottomFrame); err != nil {
|
2020-10-22 12:54:45 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
if err := s.renderPanelSegment(target, frameSelectedTab1Full); err != nil {
|
2020-10-22 12:54:45 -04:00
|
|
|
return err
|
|
|
|
}
|
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)
|
|
|
|
|
|
|
|
if err := s.renderPanelSegment(target, frameSelectedTab2Top); err != nil {
|
2020-10-22 12:54:45 -04:00
|
|
|
return err
|
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
skillPanel.SetPosition(x, y+h1)
|
|
|
|
|
|
|
|
if err := s.renderPanelSegment(target, frameSelectedTab2Bottom); err != nil {
|
2020-10-22 12:54:45 -04:00
|
|
|
return err
|
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
case thirdTab:
|
2020-10-22 12:54:45 -04:00
|
|
|
skillPanel.SetPosition(x+w, y)
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
if err := s.renderPanelSegment(target, frameSelectedTab3Full); err != nil {
|
2020-10-22 12:54:45 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
func (s *skillTree) renderSkillIcons(target d2interface.Surface, tab int) error {
|
2020-10-22 12:54:45 -04:00
|
|
|
skillIcon := s.resources.skillIcon
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
for idx := range s.skills {
|
2020-10-22 12:54:45 -04:00
|
|
|
skill := s.skills[idx]
|
2020-10-25 03:42:31 -04:00
|
|
|
if skill.SkillPage != tab+1 {
|
2020-10-22 12:54:45 -04:00
|
|
|
continue
|
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
if err := skillIcon.SetCurrentFrame(skill.IconCel); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
x := skillIconXOff + skill.SkillColumn*skillIconDistX
|
|
|
|
y := skillIconYOff + skill.SkillRow*skillIconDistY
|
|
|
|
|
|
|
|
skillIcon.SetPosition(x, y)
|
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
if err := skillIcon.Render(target); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
return nil
|
2020-10-22 12:54:45 -04:00
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
// Render the skill tree panel
|
|
|
|
func (s *skillTree) Render(target d2interface.Surface) error {
|
2020-10-22 12:54:45 -04:00
|
|
|
if !s.isOpen {
|
|
|
|
return nil
|
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
if err := s.frame.Render(target); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := s.renderTabCommon(target); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := s.renderTab(target, s.selectedTab); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := s.renderSkillIcons(target, s.selectedTab); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-10-22 12:54:45 -04:00
|
|
|
return nil
|
|
|
|
}
|