mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-12-27 04:26:29 -05:00
1f49df62d1
* d2ui/tooltip: Make it invisible by default * d2ui/button: Add GetToggled() method * d2player/HUD: Add tooltip for minipanel button * d2ui/button: Add disabled frame to minipanel buttons * d2ui/widget_group: Add SetEnable method for clickable widgets * d2player/mini_panel: move menu button here from HUD * d2ui/button: toggled buttons take preference over disabled buttons * d2player/help_overlay: Make panel only use widgets * d2player/hud: Group most widgets into widget group * d2ui/custom_widget: Allow tooltip to be attached * d2player/hud: Attach staminaBar tooltip to staminaBar * d2player/hud: Attach experienceBar tooltip to experienceBar widget * d2ui/ui_manager: Always draw tooltips last * d2player/help_overlay: It should be drawn over the HUD * d2player/globeWidget: Move tooltip here from HUD * d2core/tooltip: Automatically add tooltips to the uiManager * d2core/ui_manager: Remove special handling of widgetGroups for rendering * d2player/help_overlay: Add button to widget group * d2player/hud: Attack runwalk tooltip to button * d2player/mini_panel: Add panelButton to its own widget group * d2core/widget_group: When a clickable is added, it's also added to uiManager * d2player/globeWidget: make tooltip un/lock on click * d2player/hud: Add runbutton to widget group * d2player/mini_panel: Add group for tooltips this allows us to move the tooltip with the panelbuttons. They can't be in the general panelGroup as they would all become visible when the panel is opened. * d2core/button: Remove debug log when a button with tooltip is hovered
65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package d2ui
|
|
|
|
import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
|
|
|
// static check that CustomWidget implements widget
|
|
var _ Widget = &CustomWidget{}
|
|
|
|
// CustomWidget is a widget with a fully custom render function
|
|
type CustomWidget struct {
|
|
*BaseWidget
|
|
renderFunc func(target d2interface.Surface)
|
|
cached bool
|
|
cachedImg *d2interface.Surface
|
|
tooltip *Tooltip
|
|
}
|
|
|
|
// NewCustomWidgetCached creates a new widget and caches anything rendered via the
|
|
// renderFunc into a static image to be displayed
|
|
func (ui *UIManager) NewCustomWidgetCached(renderFunc func(target d2interface.Surface), width, height int) *CustomWidget {
|
|
c := ui.NewCustomWidget(renderFunc, width, height)
|
|
c.cached = true
|
|
|
|
// render using the renderFunc to a cache
|
|
surface := ui.Renderer().NewSurface(width, height)
|
|
c.cachedImg = &surface
|
|
renderFunc(*c.cachedImg)
|
|
|
|
return c
|
|
}
|
|
|
|
// NewCustomWidget creates a new widget with custom render function
|
|
func (ui *UIManager) NewCustomWidget(renderFunc func(target d2interface.Surface), width, height int) *CustomWidget {
|
|
base := NewBaseWidget(ui)
|
|
base.width = width
|
|
base.height = height
|
|
|
|
return &CustomWidget{
|
|
BaseWidget: base,
|
|
renderFunc: renderFunc,
|
|
}
|
|
}
|
|
|
|
// Render draws the custom widget
|
|
func (c *CustomWidget) Render(target d2interface.Surface) {
|
|
if c.cached {
|
|
target.PushTranslation(c.GetPosition())
|
|
target.Render(*c.cachedImg)
|
|
target.Pop()
|
|
} else {
|
|
c.renderFunc(target)
|
|
}
|
|
}
|
|
|
|
// SetTooltip gives this widget a Tooltip that is displayed if the widget is hovered
|
|
func (c *CustomWidget) SetTooltip(t *Tooltip) {
|
|
c.tooltip = t
|
|
c.OnHoverStart(func() { c.tooltip.SetVisible(true) })
|
|
c.OnHoverEnd(func() { c.tooltip.SetVisible(false) })
|
|
}
|
|
|
|
// Advance is a no-op
|
|
func (c *CustomWidget) Advance(elapsed float64) error {
|
|
return nil
|
|
}
|