mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-18 02:16:23 -05:00
d2ui/sprite: Refactor Render() to RenderNoError()
this allows us to create a Render() method that implements the Widget interface without killing us with linter warnings.
This commit is contained in:
parent
f2a55312e4
commit
77cd538c2f
@ -227,7 +227,7 @@ func (u *UIFrame) renderFramePiece(sfc d2interface.Surface, x, y, idx int) error
|
|||||||
|
|
||||||
u.frame.SetPosition(x, y)
|
u.frame.SetPosition(x, y)
|
||||||
|
|
||||||
u.frame.Render(sfc)
|
u.frame.RenderNoError(sfc)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,9 @@ import (
|
|||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// static check that Sprite implements Widget
|
||||||
|
var _ Widget = &Sprite{}
|
||||||
|
|
||||||
// Sprite is a positioned visual object.
|
// Sprite is a positioned visual object.
|
||||||
type Sprite struct {
|
type Sprite struct {
|
||||||
*BaseWidget
|
*BaseWidget
|
||||||
@ -38,7 +41,13 @@ func (ui *UIManager) NewSprite(animationPath, palettePath string) (*Sprite, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render renders the sprite on the given surface
|
// Render renders the sprite on the given surface
|
||||||
func (s *Sprite) Render(target d2interface.Surface) {
|
func (s *Sprite) Render(target d2interface.Surface) error {
|
||||||
|
s.RenderNoError(target)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RenderNoError renders the sprite on the given surface
|
||||||
|
func (s *Sprite) RenderNoError(target d2interface.Surface) {
|
||||||
_, frameHeight := s.animation.GetCurrentFrameSize()
|
_, frameHeight := s.animation.GetCurrentFrameSize()
|
||||||
|
|
||||||
target.PushTranslation(s.x, s.y-frameHeight)
|
target.PushTranslation(s.x, s.y-frameHeight)
|
||||||
|
@ -61,7 +61,7 @@ func (v *TextBox) Render(target d2interface.Surface) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
v.bgSprite.Render(target)
|
v.bgSprite.RenderNoError(target)
|
||||||
v.textLabel.RenderNoError(target)
|
v.textLabel.RenderNoError(target)
|
||||||
|
|
||||||
if (time.Now().UnixNano()/1e6)&(1<<8) > 0 {
|
if (time.Now().UnixNano()/1e6)&(1<<8) > 0 {
|
||||||
|
@ -452,10 +452,10 @@ func (v *MainMenu) renderBackgrounds(screen d2interface.Surface) {
|
|||||||
func (v *MainMenu) renderLogos(screen d2interface.Surface) {
|
func (v *MainMenu) renderLogos(screen d2interface.Surface) {
|
||||||
switch v.screenMode {
|
switch v.screenMode {
|
||||||
case ScreenModeTrademark, ScreenModeMainMenu, ScreenModeMultiplayer:
|
case ScreenModeTrademark, ScreenModeMainMenu, ScreenModeMultiplayer:
|
||||||
v.diabloLogoLeftBack.Render(screen)
|
v.diabloLogoLeftBack.RenderNoError(screen)
|
||||||
v.diabloLogoRightBack.Render(screen)
|
v.diabloLogoRightBack.RenderNoError(screen)
|
||||||
v.diabloLogoLeft.Render(screen)
|
v.diabloLogoLeft.RenderNoError(screen)
|
||||||
v.diabloLogoRight.Render(screen)
|
v.diabloLogoRight.RenderNoError(screen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,7 +536,7 @@ func (v *SelectHeroClass) Render(screen d2interface.Surface) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v.campfire.Render(screen)
|
v.campfire.RenderNoError(screen)
|
||||||
|
|
||||||
if v.heroNameTextbox.GetVisible() {
|
if v.heroNameTextbox.GetVisible() {
|
||||||
v.heroNameLabel.RenderNoError(screen)
|
v.heroNameLabel.RenderNoError(screen)
|
||||||
@ -739,7 +739,7 @@ func setSpriteToFirstFrame(sprite *d2ui.Sprite) {
|
|||||||
|
|
||||||
func drawSprite(sprite *d2ui.Sprite, target d2interface.Surface) {
|
func drawSprite(sprite *d2ui.Sprite, target d2interface.Surface) {
|
||||||
if sprite != nil {
|
if sprite != nil {
|
||||||
sprite.Render(target)
|
sprite.RenderNoError(target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,7 +620,7 @@ func (h *HelpOverlay) Render(target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range h.frames {
|
for _, f := range h.frames {
|
||||||
f.Render(target)
|
f.RenderNoError(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, t := range h.text {
|
for _, t := range h.text {
|
||||||
|
@ -242,7 +242,7 @@ func (s *HeroStatsPanel) renderStaticPanelFrames(target d2interface.Surface) err
|
|||||||
s.panel.SetPosition(currentX-w, currentY+h)
|
s.panel.SetPosition(currentX-w, currentY+h)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.panel.Render(target)
|
s.panel.RenderNoError(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -391,7 +391,7 @@ func (h *HUD) renderManaGlobe(x, _ int, target d2interface.Surface) error {
|
|||||||
|
|
||||||
h.mainPanel.SetPosition(x, height)
|
h.mainPanel.SetPosition(x, height)
|
||||||
|
|
||||||
h.mainPanel.Render(target)
|
h.mainPanel.RenderNoError(target)
|
||||||
|
|
||||||
// Mana status bar
|
// Mana status bar
|
||||||
manaPercent := float64(h.hero.Stats.Mana) / float64(h.hero.Stats.MaxMana)
|
manaPercent := float64(h.hero.Stats.Mana) / float64(h.hero.Stats.MaxMana)
|
||||||
@ -413,8 +413,8 @@ func (h *HUD) renderManaGlobe(x, _ int, target d2interface.Surface) error {
|
|||||||
|
|
||||||
h.globeSprite.SetPosition(x+rightGlobeOffsetX, height+rightGlobeOffsetY)
|
h.globeSprite.SetPosition(x+rightGlobeOffsetX, height+rightGlobeOffsetY)
|
||||||
|
|
||||||
h.globeSprite.Render(target)
|
h.globeSprite.RenderNoError(target)
|
||||||
h.globeSprite.Render(target)
|
h.globeSprite.RenderNoError(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -438,7 +438,7 @@ func (h *HUD) renderHealthGlobe(x, y int, target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.globeSprite.SetPosition(x+globeSpriteOffsetX, y+globeSpriteOffsetY)
|
h.globeSprite.SetPosition(x+globeSpriteOffsetX, y+globeSpriteOffsetY)
|
||||||
h.globeSprite.Render(target)
|
h.globeSprite.RenderNoError(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -449,7 +449,7 @@ func (h *HUD) renderPanel(x, y int, target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.mainPanel.SetPosition(x, y)
|
h.mainPanel.SetPosition(x, y)
|
||||||
h.mainPanel.Render(target)
|
h.mainPanel.RenderNoError(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -466,7 +466,7 @@ func (h *HUD) renderLeftSkill(x, y int, target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.leftSkillResource.SkillIcon.SetPosition(x, y)
|
h.leftSkillResource.SkillIcon.SetPosition(x, y)
|
||||||
h.leftSkillResource.SkillIcon.Render(target)
|
h.leftSkillResource.SkillIcon.RenderNoError(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -485,7 +485,7 @@ func (h *HUD) renderRightSkill(x, _ int, target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.rightSkillResource.SkillIcon.SetPosition(x, height)
|
h.rightSkillResource.SkillIcon.SetPosition(x, height)
|
||||||
h.rightSkillResource.SkillIcon.Render(target)
|
h.rightSkillResource.SkillIcon.RenderNoError(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -496,7 +496,7 @@ func (h *HUD) renderNewStatsButton(x, y int, target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.mainPanel.SetPosition(x, y)
|
h.mainPanel.SetPosition(x, y)
|
||||||
h.mainPanel.Render(target)
|
h.mainPanel.RenderNoError(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -507,7 +507,7 @@ func (h *HUD) renderStamina(x, y int, target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.mainPanel.SetPosition(x, y)
|
h.mainPanel.SetPosition(x, y)
|
||||||
h.mainPanel.Render(target)
|
h.mainPanel.RenderNoError(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -558,7 +558,7 @@ func (h *HUD) renderMiniPanel(target d2interface.Surface) error {
|
|||||||
buttonX, buttonY := (width>>1)+miniPanelButtonOffsetX, height+miniPanelButtonOffsetY
|
buttonX, buttonY := (width>>1)+miniPanelButtonOffsetX, height+miniPanelButtonOffsetY
|
||||||
|
|
||||||
h.menuButton.SetPosition(buttonX, buttonY)
|
h.menuButton.SetPosition(buttonX, buttonY)
|
||||||
h.menuButton.Render(target)
|
h.menuButton.RenderNoError(target)
|
||||||
h.miniPanel.Render(target)
|
h.miniPanel.Render(target)
|
||||||
|
|
||||||
miniPanelButtons := map[actionableType]string{
|
miniPanelButtons := map[actionableType]string{
|
||||||
@ -612,7 +612,7 @@ func (h *HUD) renderPotions(x, _ int, target d2interface.Surface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.mainPanel.SetPosition(x, height)
|
h.mainPanel.SetPosition(x, height)
|
||||||
h.mainPanel.Render(target)
|
h.mainPanel.RenderNoError(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -625,7 +625,7 @@ func (h *HUD) renderNewSkillsButton(x, _ int, target d2interface.Surface) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.mainPanel.SetPosition(x, height)
|
h.mainPanel.SetPosition(x, height)
|
||||||
h.mainPanel.Render(target)
|
h.mainPanel.RenderNoError(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ func (g *Inventory) renderFrame(target d2interface.Surface) error {
|
|||||||
w, h := g.panel.GetCurrentFrameSize()
|
w, h := g.panel.GetCurrentFrameSize()
|
||||||
|
|
||||||
g.panel.SetPosition(x, y+h)
|
g.panel.SetPosition(x, y+h)
|
||||||
g.panel.Render(target)
|
g.panel.RenderNoError(target)
|
||||||
|
|
||||||
switch frame {
|
switch frame {
|
||||||
case frameInventoryTopLeft:
|
case frameInventoryTopLeft:
|
||||||
|
@ -234,7 +234,7 @@ func (g *ItemGrid) renderItem(item InventoryItem, target d2interface.Surface, x,
|
|||||||
if itemSprite != nil {
|
if itemSprite != nil {
|
||||||
itemSprite.SetPosition(x, y)
|
itemSprite.SetPosition(x, y)
|
||||||
itemSprite.GetCurrentFrameSize()
|
itemSprite.GetCurrentFrameSize()
|
||||||
itemSprite.Render(target)
|
itemSprite.RenderNoError(target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ func (m *miniPanel) Render(target d2interface.Surface) {
|
|||||||
|
|
||||||
m.container.SetPosition(x, y)
|
m.container.SetPosition(x, y)
|
||||||
|
|
||||||
m.container.Render(target)
|
m.container.RenderNoError(target)
|
||||||
|
|
||||||
buttonWidth, _ := m.button.GetCurrentFrameSize()
|
buttonWidth, _ := m.button.GetCurrentFrameSize()
|
||||||
buttonWidth++
|
buttonWidth++
|
||||||
@ -122,7 +122,7 @@ func (m *miniPanel) Render(target d2interface.Surface) {
|
|||||||
x, y := halfW+offsetX, height+buttonOffsetY
|
x, y := halfW+offsetX, height+buttonOffsetY
|
||||||
|
|
||||||
m.button.SetPosition(x, y)
|
m.button.SetPosition(x, y)
|
||||||
m.button.Render(target)
|
m.button.RenderNoError(target)
|
||||||
|
|
||||||
j += 2
|
j += 2
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ func (s *SkillPanel) createSkillListImage(skillsListRow *SkillListRow) (d2interf
|
|||||||
}
|
}
|
||||||
|
|
||||||
surface.PushTranslation(idx*skillIconWidth, 50)
|
surface.PushTranslation(idx*skillIconWidth, 50)
|
||||||
skillSprite.Render(surface)
|
skillSprite.RenderNoError(surface)
|
||||||
surface.Pop()
|
surface.Pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,7 +387,7 @@ func (s *skillTree) renderPanelSegment(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
s.resources.skillPanel.Render(target)
|
s.resources.skillPanel.RenderNoError(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -531,7 +531,7 @@ func (s *skillTree) renderSkillIcon(target d2interface.Surface, skill *d2hero.He
|
|||||||
defer target.Pop()
|
defer target.Pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
skillIcon.Render(target)
|
skillIcon.RenderNoError(target)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user