mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-12-24 11:06:51 -05:00
d2ui/label: 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
01927d0f3b
commit
f2a55312e4
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ func (v *Credits) Render(screen d2interface.Surface) {
|
||||
continue
|
||||
}
|
||||
|
||||
label.Label.Render(screen)
|
||||
label.Label.RenderNoError(screen)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user