1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-09 09:20:44 +00:00

Add labels for skill levels (#881)

* d2player/skilltree: Add label for skillpoints

this also darkens the skillicon if no skillpoint was invested yet.

* d2player/gamecontrols: learnskills <class> should only learn class
specific skills

the character would learn skills of enemies as well, like DiabWall. I
wasn't expecting the command to do that.
This commit is contained in:
juander-ux 2020-10-29 14:50:15 +01:00 committed by GitHub
parent ce36dec7f8
commit b1058d6085
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 25 deletions

View File

@ -1709,7 +1709,7 @@ func (g *GameControls) bindLearnSkillsCommand(term d2interface.Terminal) error {
learnedSkillsCount := 0
for _, skillDetailRecord := range g.asset.Records.Skill.Details {
if skillDetailRecord.Charclass != classToken && skillDetailRecord.Charclass != "" {
if skillDetailRecord.Charclass != classToken {
continue
}

View File

@ -3,6 +3,7 @@ package d2player
import (
"fmt"
"log"
"strconv"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2tbl"
@ -28,6 +29,9 @@ const (
skillIconDistX = 69
skillIconDistY = 68
skillLabelXOffset = 49
skillLabelYOffset = -4
skillCloseButtonXLeft = 416
skillCloseButtonXMiddle = 501
skillCloseButtonXRight = 572
@ -67,6 +71,11 @@ const (
skillTreePanelY = 64
)
const (
skillIconGreySat = 0.2
skillIconGreyBright = 0.44
)
type skillTreeTab struct {
buttonText string
button *d2ui.Button
@ -87,23 +96,24 @@ type skillTreeHeroTypeResources struct {
}
type skillTree struct {
resources *skillTreeHeroTypeResources
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
closeButton *d2ui.Button
tab [numTabs]*skillTreeTab
isOpen bool
originX int
originY int
selectedTab int
onCloseCb func()
resources *skillTreeHeroTypeResources
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
skillLvlLabel *d2ui.Label
closeButton *d2ui.Button
tab [numTabs]*skillTreeTab
isOpen bool
originX int
originY int
selectedTab int
onCloseCb func()
}
func newSkillTree(
@ -139,6 +149,8 @@ func (s *skillTree) load() {
s.closeButton.SetVisible(false)
s.closeButton.OnActivated(func() { s.Close() })
s.skillLvlLabel = s.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteSky)
s.setHeroTypeResourcePath()
s.loadForHeroType()
s.setTab(0)
@ -501,24 +513,54 @@ func (s *skillTree) renderTab(target d2interface.Surface, tab int) error {
return nil
}
func (s *skillTree) renderSkillIcons(target d2interface.Surface, tab int) error {
func (s *skillTree) renderSkillIcon(target d2interface.Surface, skill *d2hero.HeroSkill) error {
skillIcon := s.resources.skillIcon
if err := skillIcon.SetCurrentFrame(skill.IconCel); err != nil {
return err
}
x := skillIconXOff + skill.SkillColumn*skillIconDistX
y := skillIconYOff + skill.SkillRow*skillIconDistY
skillIcon.SetPosition(x, y)
if skill.SkillPoints == 0 {
target.PushSaturation(skillIconGreySat)
defer target.Pop()
target.PushBrightness(skillIconGreyBright)
defer target.Pop()
}
skillIcon.Render(target)
return nil
}
func (s *skillTree) renderSkillIconLabel(target d2interface.Surface, skill *d2hero.HeroSkill) {
if skill.SkillPoints == 0 {
return
}
s.skillLvlLabel.SetText(strconv.Itoa(skill.SkillPoints))
x := skillIconXOff + skill.SkillColumn*skillIconDistX + skillLabelXOffset
y := skillIconYOff + skill.SkillRow*skillIconDistY + skillLabelYOffset
s.skillLvlLabel.SetPosition(x, y)
s.skillLvlLabel.Render(target)
}
func (s *skillTree) renderSkillIcons(target d2interface.Surface, tab int) error {
for idx := range s.skills {
skill := s.skills[idx]
if skill.SkillPage != tab+1 {
continue
}
if err := skillIcon.SetCurrentFrame(skill.IconCel); err != nil {
if err := s.renderSkillIcon(target, skill); err != nil {
return err
}
x := skillIconXOff + skill.SkillColumn*skillIconDistX
y := skillIconYOff + skill.SkillRow*skillIconDistY
skillIcon.SetPosition(x, y)
skillIcon.Render(target)
s.renderSkillIconLabel(target, skill)
}
return nil