mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-01-11 11:57:44 -05:00
d2core/d2ui: Add checks to all widgets if they implement Widget
this also adds missing methods to elements not implementing widget. Note here that we do not enable sprite and label, as this would produce a crazy amount of linter warnings due to render() requiering error handling then, which non of the callers handle. Since we remove the render calls later anyways, we can postpone this static check for now.
This commit is contained in:
parent
bad07defe8
commit
01927d0f3b
@ -8,6 +8,9 @@ import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||
)
|
||||
|
||||
// static check that Checkbox implements Widget
|
||||
var _ Widget = &Checkbox{}
|
||||
|
||||
// Checkbox represents a checkbox UI element
|
||||
type Checkbox struct {
|
||||
*BaseWidget
|
||||
|
@ -8,6 +8,9 @@ import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
||||
)
|
||||
|
||||
// static check that UIFrame implements Widget
|
||||
var _ Widget = &UIFrame{}
|
||||
|
||||
type frameOrientation = int
|
||||
|
||||
// Frame orientations
|
||||
@ -228,3 +231,8 @@ func (u *UIFrame) renderFramePiece(sfc d2interface.Surface, x, y, idx int) error
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Advance is a no-op
|
||||
func (u *UIFrame) Advance(elapsed float64) error {
|
||||
return nil
|
||||
}
|
||||
|
@ -162,6 +162,11 @@ func (v *Label) getAlignOffset(textWidth int) int {
|
||||
}
|
||||
}
|
||||
|
||||
// Advance is a no-op
|
||||
func (v *Label) Advance(elapsed float64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getColor(token ColorToken) color.Color {
|
||||
// https://github.com/OpenDiablo2/OpenDiablo2/issues/823
|
||||
colors := map[ColorToken]color.Color{
|
||||
|
@ -15,6 +15,9 @@ const (
|
||||
scrollbarWidth = 10
|
||||
)
|
||||
|
||||
// static check that Scrollbar implements widget
|
||||
var _ Widget = &Scrollbar{}
|
||||
|
||||
// Scrollbar is a vertical slider ui element
|
||||
type Scrollbar struct {
|
||||
*BaseWidget
|
||||
|
@ -10,6 +10,9 @@ import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||
)
|
||||
|
||||
// static check that TextBox implements widget
|
||||
var _ Widget = &TextBox{}
|
||||
|
||||
// TextBox represents a text input box
|
||||
type TextBox struct {
|
||||
*BaseWidget
|
||||
|
@ -14,6 +14,9 @@ const (
|
||||
screenHeight = 600
|
||||
)
|
||||
|
||||
// static check that Tooltip implements widget
|
||||
var _ Widget = &Tooltip{}
|
||||
|
||||
// Tooltip contains a label containing text with a transparent, black background
|
||||
type Tooltip struct {
|
||||
*BaseWidget
|
||||
@ -137,7 +140,7 @@ func (t *Tooltip) GetSize() (sx, sy int) {
|
||||
}
|
||||
|
||||
// Render draws the tooltip
|
||||
func (t *Tooltip) Render(target d2interface.Surface) {
|
||||
func (t *Tooltip) Render(target d2interface.Surface) error {
|
||||
maxW, maxH := t.GetSize()
|
||||
|
||||
// nolint:gomnd // no magic numbers, their meaning is obvious
|
||||
@ -189,4 +192,11 @@ func (t *Tooltip) Render(target d2interface.Surface) {
|
||||
}
|
||||
|
||||
target.PopN(len(t.lines))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Advance is a no-op
|
||||
func (t *Tooltip) Advance(elapsed float64) error {
|
||||
return nil
|
||||
}
|
||||
|
@ -595,7 +595,10 @@ func (h *HUD) renderMiniPanel(target d2interface.Surface) error {
|
||||
labelY := centerY - halfButtonHeight - labelHeight
|
||||
|
||||
h.miniPanelTooltip.SetPosition(labelX, labelY)
|
||||
h.miniPanelTooltip.Render(target)
|
||||
|
||||
if err := h.miniPanelTooltip.Render(target); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -627,6 +630,7 @@ func (h *HUD) renderNewSkillsButton(x, _ int, target d2interface.Surface) error
|
||||
return nil
|
||||
}
|
||||
|
||||
//nolint:golint,dupl // we clean this up later
|
||||
func (h *HUD) renderHealthTooltip(target d2interface.Surface) {
|
||||
mx, my := h.lastMouseX, h.lastMouseY
|
||||
|
||||
@ -641,9 +645,13 @@ func (h *HUD) renderHealthTooltip(target d2interface.Surface) {
|
||||
}
|
||||
|
||||
h.healthTooltip.SetText(strPanelHealth)
|
||||
h.healthTooltip.Render(target)
|
||||
|
||||
if err := h.healthTooltip.Render(target); err != nil {
|
||||
log.Printf("Cannot render tooltip, %e", err)
|
||||
}
|
||||
}
|
||||
|
||||
//nolint:golint,dupl // we clean this up later
|
||||
func (h *HUD) renderManaTooltip(target d2interface.Surface) {
|
||||
mx, my := h.lastMouseX, h.lastMouseY
|
||||
|
||||
@ -657,7 +665,10 @@ func (h *HUD) renderManaTooltip(target d2interface.Surface) {
|
||||
}
|
||||
|
||||
h.manaTooltip.SetText(strPanelMana)
|
||||
h.manaTooltip.Render(target)
|
||||
|
||||
if err := h.manaTooltip.Render(target); err != nil {
|
||||
log.Printf("Cannot render tooltip, %e", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *HUD) renderRunWalkTooltip(target d2interface.Surface) {
|
||||
@ -679,7 +690,9 @@ func (h *HUD) renderRunWalkTooltip(target d2interface.Surface) {
|
||||
|
||||
h.runWalkTooltip.SetText(h.asset.TranslateString(stringTableKey))
|
||||
|
||||
h.runWalkTooltip.Render(target)
|
||||
if err := h.runWalkTooltip.Render(target); err != nil {
|
||||
log.Printf("Cannot render tooltip, %e", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *HUD) renderStaminaTooltip(target d2interface.Surface) {
|
||||
@ -696,7 +709,10 @@ func (h *HUD) renderStaminaTooltip(target d2interface.Surface) {
|
||||
strPanelStamina := fmt.Sprintf(fmtStamina, staminaCurr, staminaMax)
|
||||
|
||||
h.staminaTooltip.SetText(strPanelStamina)
|
||||
h.staminaTooltip.Render(target)
|
||||
|
||||
if err := h.staminaTooltip.Render(target); err != nil {
|
||||
log.Printf("Cannot render tooltip, %e", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *HUD) renderExperienceTooltip(target d2interface.Surface) {
|
||||
@ -720,7 +736,10 @@ func (h *HUD) renderExperienceTooltip(target d2interface.Surface) {
|
||||
strPanelExp := fmt.Sprintf(fmtExp, expCurr, expMax)
|
||||
|
||||
h.experienceTooltip.SetText(strPanelExp)
|
||||
h.experienceTooltip.Render(target)
|
||||
|
||||
if err := h.experienceTooltip.Render(target); err != nil {
|
||||
log.Printf("Cannot render tooltip, %e", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *HUD) renderForSelectableEntitiesHovered(target d2interface.Surface) {
|
||||
|
@ -242,5 +242,8 @@ func (g *Inventory) renderItemDescription(target d2interface.Surface, i Inventor
|
||||
g.itemTooltip.SetTextLines(lines)
|
||||
_, y := g.grid.SlotToScreen(i.InventoryGridSlot())
|
||||
g.itemTooltip.SetPosition(g.hoverX, y)
|
||||
g.itemTooltip.Render(target)
|
||||
|
||||
if err := g.itemTooltip.Render(target); err != nil {
|
||||
log.Printf("Cannot render tooltip, %e", err)
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +129,9 @@ func (s *SkillPanel) Render(target d2interface.Surface) error {
|
||||
}
|
||||
|
||||
if s.hoveredSkill != nil {
|
||||
s.hoverTooltip.Render(target)
|
||||
if err := s.hoverTooltip.Render(target); err != nil {
|
||||
log.Printf("Cannot render tooltip, %e", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user