1
1
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:
juander 2020-11-09 18:04:56 +01:00
parent f2a55312e4
commit 77cd538c2f
13 changed files with 39 additions and 30 deletions

View File

@ -227,7 +227,7 @@ func (u *UIFrame) renderFramePiece(sfc d2interface.Surface, x, y, idx int) error
u.frame.SetPosition(x, y)
u.frame.Render(sfc)
u.frame.RenderNoError(sfc)
return nil
}

View File

@ -11,6 +11,9 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
)
// static check that Sprite implements Widget
var _ Widget = &Sprite{}
// Sprite is a positioned visual object.
type Sprite struct {
*BaseWidget
@ -38,7 +41,13 @@ func (ui *UIManager) NewSprite(animationPath, palettePath string) (*Sprite, erro
}
// 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()
target.PushTranslation(s.x, s.y-frameHeight)

View File

@ -61,7 +61,7 @@ func (v *TextBox) Render(target d2interface.Surface) error {
return nil
}
v.bgSprite.Render(target)
v.bgSprite.RenderNoError(target)
v.textLabel.RenderNoError(target)
if (time.Now().UnixNano()/1e6)&(1<<8) > 0 {

View File

@ -452,10 +452,10 @@ func (v *MainMenu) renderBackgrounds(screen d2interface.Surface) {
func (v *MainMenu) renderLogos(screen d2interface.Surface) {
switch v.screenMode {
case ScreenModeTrademark, ScreenModeMainMenu, ScreenModeMultiplayer:
v.diabloLogoLeftBack.Render(screen)
v.diabloLogoRightBack.Render(screen)
v.diabloLogoLeft.Render(screen)
v.diabloLogoRight.Render(screen)
v.diabloLogoLeftBack.RenderNoError(screen)
v.diabloLogoRightBack.RenderNoError(screen)
v.diabloLogoLeft.RenderNoError(screen)
v.diabloLogoRight.RenderNoError(screen)
}
}

View File

@ -536,7 +536,7 @@ func (v *SelectHeroClass) Render(screen d2interface.Surface) {
}
}
v.campfire.Render(screen)
v.campfire.RenderNoError(screen)
if v.heroNameTextbox.GetVisible() {
v.heroNameLabel.RenderNoError(screen)
@ -739,7 +739,7 @@ func setSpriteToFirstFrame(sprite *d2ui.Sprite) {
func drawSprite(sprite *d2ui.Sprite, target d2interface.Surface) {
if sprite != nil {
sprite.Render(target)
sprite.RenderNoError(target)
}
}

View File

@ -620,7 +620,7 @@ func (h *HelpOverlay) Render(target d2interface.Surface) error {
}
for _, f := range h.frames {
f.Render(target)
f.RenderNoError(target)
}
for _, t := range h.text {

View File

@ -242,7 +242,7 @@ func (s *HeroStatsPanel) renderStaticPanelFrames(target d2interface.Surface) err
s.panel.SetPosition(currentX-w, currentY+h)
}
s.panel.Render(target)
s.panel.RenderNoError(target)
}
return nil

View File

@ -391,7 +391,7 @@ func (h *HUD) renderManaGlobe(x, _ int, target d2interface.Surface) error {
h.mainPanel.SetPosition(x, height)
h.mainPanel.Render(target)
h.mainPanel.RenderNoError(target)
// Mana status bar
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.Render(target)
h.globeSprite.Render(target)
h.globeSprite.RenderNoError(target)
h.globeSprite.RenderNoError(target)
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.Render(target)
h.globeSprite.RenderNoError(target)
return nil
}
@ -449,7 +449,7 @@ func (h *HUD) renderPanel(x, y int, target d2interface.Surface) error {
}
h.mainPanel.SetPosition(x, y)
h.mainPanel.Render(target)
h.mainPanel.RenderNoError(target)
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.Render(target)
h.leftSkillResource.SkillIcon.RenderNoError(target)
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.Render(target)
h.rightSkillResource.SkillIcon.RenderNoError(target)
return nil
}
@ -496,7 +496,7 @@ func (h *HUD) renderNewStatsButton(x, y int, target d2interface.Surface) error {
}
h.mainPanel.SetPosition(x, y)
h.mainPanel.Render(target)
h.mainPanel.RenderNoError(target)
return nil
}
@ -507,7 +507,7 @@ func (h *HUD) renderStamina(x, y int, target d2interface.Surface) error {
}
h.mainPanel.SetPosition(x, y)
h.mainPanel.Render(target)
h.mainPanel.RenderNoError(target)
return nil
}
@ -558,7 +558,7 @@ func (h *HUD) renderMiniPanel(target d2interface.Surface) error {
buttonX, buttonY := (width>>1)+miniPanelButtonOffsetX, height+miniPanelButtonOffsetY
h.menuButton.SetPosition(buttonX, buttonY)
h.menuButton.Render(target)
h.menuButton.RenderNoError(target)
h.miniPanel.Render(target)
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.Render(target)
h.mainPanel.RenderNoError(target)
return nil
}
@ -625,7 +625,7 @@ func (h *HUD) renderNewSkillsButton(x, _ int, target d2interface.Surface) error
}
h.mainPanel.SetPosition(x, height)
h.mainPanel.Render(target)
h.mainPanel.RenderNoError(target)
return nil
}

View File

@ -196,7 +196,7 @@ func (g *Inventory) renderFrame(target d2interface.Surface) error {
w, h := g.panel.GetCurrentFrameSize()
g.panel.SetPosition(x, y+h)
g.panel.Render(target)
g.panel.RenderNoError(target)
switch frame {
case frameInventoryTopLeft:

View File

@ -234,7 +234,7 @@ func (g *ItemGrid) renderItem(item InventoryItem, target d2interface.Surface, x,
if itemSprite != nil {
itemSprite.SetPosition(x, y)
itemSprite.GetCurrentFrameSize()
itemSprite.Render(target)
itemSprite.RenderNoError(target)
}
}

View File

@ -104,7 +104,7 @@ func (m *miniPanel) Render(target d2interface.Surface) {
m.container.SetPosition(x, y)
m.container.Render(target)
m.container.RenderNoError(target)
buttonWidth, _ := m.button.GetCurrentFrameSize()
buttonWidth++
@ -122,7 +122,7 @@ func (m *miniPanel) Render(target d2interface.Surface) {
x, y := halfW+offsetX, height+buttonOffsetY
m.button.SetPosition(x, y)
m.button.Render(target)
m.button.RenderNoError(target)
j += 2
}

View File

@ -242,7 +242,7 @@ func (s *SkillPanel) createSkillListImage(skillsListRow *SkillListRow) (d2interf
}
surface.PushTranslation(idx*skillIconWidth, 50)
skillSprite.Render(surface)
skillSprite.RenderNoError(surface)
surface.Pop()
}

View File

@ -387,7 +387,7 @@ func (s *skillTree) renderPanelSegment(
return err
}
s.resources.skillPanel.Render(target)
s.resources.skillPanel.RenderNoError(target)
return nil
}
@ -531,7 +531,7 @@ func (s *skillTree) renderSkillIcon(target d2interface.Surface, skill *d2hero.He
defer target.Pop()
}
skillIcon.Render(target)
skillIcon.RenderNoError(target)
return nil
}