diff --git a/d2core/d2ui/button.go b/d2core/d2ui/button.go index b9a647ba..3cd8c371 100644 --- a/d2core/d2ui/button.go +++ b/d2core/d2ui/button.go @@ -344,7 +344,7 @@ func (v *Button) prerenderStates(btnSprite *Sprite, btnLayout *ButtonLayout, lab xOffset := half(v.width) label.SetPosition(xOffset, textY) - label.Render(v.normalSurface) + label.RenderNoError(v.normalSurface) if !btnLayout.HasImage || !btnLayout.AllowFrameChange { return @@ -418,7 +418,7 @@ func (v *Button) prerenderStates(btnSprite *Sprite, btnLayout *ButtonLayout, lab } label.SetPosition(state.offsetX, state.offsetY) - label.Render(*state.prerenderdestination) + label.RenderNoError(*state.prerenderdestination) } } diff --git a/d2core/d2ui/label.go b/d2core/d2ui/label.go index aa768ee1..32bd3409 100644 --- a/d2core/d2ui/label.go +++ b/d2core/d2ui/label.go @@ -13,6 +13,9 @@ import ( "github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui" ) +// static check that UIFrame implements Widget +var _ Widget = &Label{} + // Label represents a user interface label type Label struct { *BaseWidget @@ -45,8 +48,14 @@ func (ui *UIManager) NewLabel(fontPath, palettePath string) *Label { return result } -// Render draws the label on the screen, respliting the lines to allow for other alignments. -func (v *Label) Render(target d2interface.Surface) { +// Render draws the label on the screen +func (v *Label) Render(target d2interface.Surface) error { + v.RenderNoError(target) + return nil +} + +// RenderNoError draws the label on the screen, respliting the lines to allow for other alignments. +func (v *Label) RenderNoError(target d2interface.Surface) { target.PushTranslation(v.GetPosition()) lines := strings.Split(v.text, "\n") diff --git a/d2core/d2ui/textbox.go b/d2core/d2ui/textbox.go index 256ac2f7..a63327d2 100644 --- a/d2core/d2ui/textbox.go +++ b/d2core/d2ui/textbox.go @@ -62,10 +62,10 @@ func (v *TextBox) Render(target d2interface.Surface) error { } v.bgSprite.Render(target) - v.textLabel.Render(target) + v.textLabel.RenderNoError(target) if (time.Now().UnixNano()/1e6)&(1<<8) > 0 { - v.lineBar.Render(target) + v.lineBar.RenderNoError(target) } return nil diff --git a/d2core/d2ui/tooltip.go b/d2core/d2ui/tooltip.go index 0cb4fc89..fc27818a 100644 --- a/d2core/d2ui/tooltip.go +++ b/d2core/d2ui/tooltip.go @@ -187,7 +187,7 @@ func (t *Tooltip) Render(target d2interface.Surface) error { for i := range t.lines { t.label.SetText(t.lines[i]) _, h := t.label.GetTextMetrics(t.lines[i]) - t.label.Render(target) + t.label.RenderNoError(target) target.PushTranslation(0, h) } diff --git a/d2game/d2gamescreen/character_select.go b/d2game/d2gamescreen/character_select.go index 76b74b65..76832383 100644 --- a/d2game/d2gamescreen/character_select.go +++ b/d2game/d2gamescreen/character_select.go @@ -373,7 +373,7 @@ func (v *CharacterSelect) Render(screen d2interface.Surface) { return } - v.d2HeroTitle.Render(screen) + v.d2HeroTitle.RenderNoError(screen) actualSelectionIndex := v.selectedCharacter - (v.charScrollbar.GetCurrentOffset() * 2) if v.selectedCharacter > -1 && actualSelectionIndex >= 0 && actualSelectionIndex < 8 { @@ -388,9 +388,9 @@ func (v *CharacterSelect) Render(screen d2interface.Surface) { continue } - v.characterNameLabel[i].Render(screen) - v.characterStatsLabel[i].Render(screen) - v.characterExpLabel[i].Render(screen) + v.characterNameLabel[i].RenderNoError(screen) + v.characterStatsLabel[i].RenderNoError(screen) + v.characterExpLabel[i].RenderNoError(screen) x, y := v.characterNameLabel[i].GetPosition() charImgX := x - selectionBoxImageOffsetX @@ -407,7 +407,7 @@ func (v *CharacterSelect) Render(screen d2interface.Surface) { return } - v.deleteCharConfirmLabel.Render(screen) + v.deleteCharConfirmLabel.RenderNoError(screen) } } diff --git a/d2game/d2gamescreen/credits.go b/d2game/d2gamescreen/credits.go index 3664883a..eb850fcc 100644 --- a/d2game/d2gamescreen/credits.go +++ b/d2game/d2gamescreen/credits.go @@ -139,7 +139,7 @@ func (v *Credits) Render(screen d2interface.Surface) { continue } - label.Label.Render(screen) + label.Label.RenderNoError(screen) } } diff --git a/d2game/d2gamescreen/main_menu.go b/d2game/d2gamescreen/main_menu.go index b0d82f55..b722a5d1 100644 --- a/d2game/d2gamescreen/main_menu.go +++ b/d2game/d2gamescreen/main_menu.go @@ -462,21 +462,21 @@ func (v *MainMenu) renderLogos(screen d2interface.Surface) { func (v *MainMenu) renderLabels(screen d2interface.Surface) { switch v.screenMode { case ScreenModeServerIP: - v.tcpIPOptionsLabel.Render(screen) - v.tcpJoinGameLabel.Render(screen) + v.tcpIPOptionsLabel.RenderNoError(screen) + v.tcpJoinGameLabel.RenderNoError(screen) case ScreenModeTCPIP: - v.tcpIPOptionsLabel.Render(screen) + v.tcpIPOptionsLabel.RenderNoError(screen) case ScreenModeTrademark: - v.copyrightLabel.Render(screen) - v.copyrightLabel2.Render(screen) + v.copyrightLabel.RenderNoError(screen) + v.copyrightLabel2.RenderNoError(screen) if v.errorLabel != nil { - v.errorLabel.Render(screen) + v.errorLabel.RenderNoError(screen) } case ScreenModeMainMenu: - v.openDiabloLabel.Render(screen) - v.versionLabel.Render(screen) - v.commitLabel.Render(screen) + v.openDiabloLabel.RenderNoError(screen) + v.versionLabel.RenderNoError(screen) + v.commitLabel.RenderNoError(screen) } } diff --git a/d2game/d2gamescreen/select_hero_class.go b/d2game/d2gamescreen/select_hero_class.go index 9ec03ece..678c0df1 100644 --- a/d2game/d2gamescreen/select_hero_class.go +++ b/d2game/d2gamescreen/select_hero_class.go @@ -515,13 +515,13 @@ func (v *SelectHeroClass) Render(screen d2interface.Surface) { return } - v.headingLabel.Render(screen) + v.headingLabel.RenderNoError(screen) if v.selectedHero != d2enum.HeroNone { - v.heroClassLabel.Render(screen) - v.heroDesc1Label.Render(screen) - v.heroDesc2Label.Render(screen) - v.heroDesc3Label.Render(screen) + v.heroClassLabel.RenderNoError(screen) + v.heroDesc1Label.RenderNoError(screen) + v.heroDesc2Label.RenderNoError(screen) + v.heroDesc3Label.RenderNoError(screen) } for heroClass, heroInfo := range v.heroRenderInfo { @@ -539,9 +539,9 @@ func (v *SelectHeroClass) Render(screen d2interface.Surface) { v.campfire.Render(screen) if v.heroNameTextbox.GetVisible() { - v.heroNameLabel.Render(screen) - v.expansionCharLabel.Render(screen) - v.hardcoreCharLabel.Render(screen) + v.heroNameLabel.RenderNoError(screen) + v.expansionCharLabel.RenderNoError(screen) + v.hardcoreCharLabel.RenderNoError(screen) } } diff --git a/d2game/d2player/help_overlay.go b/d2game/d2player/help_overlay.go index 8414d3c8..496d9e98 100644 --- a/d2game/d2player/help_overlay.go +++ b/d2game/d2player/help_overlay.go @@ -624,7 +624,7 @@ func (h *HelpOverlay) Render(target d2interface.Surface) error { } for _, t := range h.text { - t.Render(target) + t.RenderNoError(target) } for _, l := range h.lines { diff --git a/d2game/d2player/hero_stats_panel.go b/d2game/d2player/hero_stats_panel.go index 64399af5..b4599910 100644 --- a/d2game/d2player/hero_stats_panel.go +++ b/d2game/d2player/hero_stats_panel.go @@ -295,7 +295,7 @@ func (s *HeroStatsPanel) renderStaticLabels(target d2interface.Surface) { cfg.centerAlign, }) - label.Render(target) + label.RenderNoError(target) } } @@ -348,7 +348,7 @@ func (s *HeroStatsPanel) renderStatValues(target d2interface.Surface) { func (s *HeroStatsPanel) renderStatValueNum(label *d2ui.Label, value int, target d2interface.Surface) { label.SetText(strconv.Itoa(value)) - label.Render(target) + label.RenderNoError(target) } func (s *HeroStatsPanel) createStatValueLabel(stat, x, y int) *d2ui.Label { diff --git a/d2game/d2player/hud.go b/d2game/d2player/hud.go index 390c7c3f..538ee6e1 100644 --- a/d2game/d2player/hud.go +++ b/d2game/d2player/hud.go @@ -772,7 +772,7 @@ func (h *HUD) renderForSelectableEntitiesHovered(target d2interface.Surface) { xLabel, yLabel := entScreenX-xOff, entScreenY-yOff-entityHeight-hoverLabelOuterPad h.nameLabel.SetPosition(xLabel, yLabel) - h.nameLabel.Render(target) + h.nameLabel.RenderNoError(target) entity.Highlight() break @@ -794,7 +794,7 @@ func (h *HUD) Render(target d2interface.Surface) error { if h.isZoneTextShown { h.zoneChangeText.SetPosition(zoneChangeTextX, zoneChangeTextY) - h.zoneChangeText.Render(target) + h.zoneChangeText.RenderNoError(target) } h.renderHealthTooltip(target) diff --git a/d2game/d2player/skilltree.go b/d2game/d2player/skilltree.go index 2616b24e..7f3cf865 100644 --- a/d2game/d2player/skilltree.go +++ b/d2game/d2player/skilltree.go @@ -441,7 +441,7 @@ func (s *skillTree) renderTabCommon(target d2interface.Surface) error { } // available skill points label - s.availSPLabel.Render(target) + s.availSPLabel.RenderNoError(target) return nil } @@ -545,7 +545,7 @@ func (s *skillTree) renderSkillIconLabel(target d2interface.Surface, skill *d2he x := skillIconXOff + skill.SkillColumn*skillIconDistX + skillLabelXOffset y := skillIconYOff + skill.SkillRow*skillIconDistY + skillLabelYOffset s.skillLvlLabel.SetPosition(x, y) - s.skillLvlLabel.Render(target) + s.skillLvlLabel.RenderNoError(target) } func (s *skillTree) renderSkillIcons(target d2interface.Surface, tab int) error {