mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-09-16 00:08:29 -04:00
12821147ce
* d2ui/skilltree: Don't render availSPLabel this is handled by the ui_manager now. * d2ui/custom_widget: Allow them to be cached into static images * d2player/hero_stats_panel: Remove render() function from game_controls all ui elements are now grouped into a WidgetGroup, thus rendering is done by the ui manager. * d2player/hero_stats_panel: Remove unnecessary widgets from struct we don't need to store them in the HeroStatsPanel struct anymore as they are completly handled by the uiManager. * d2ui/widget_group: Remove priority member this is already defined by the BaseWidget. * d2ui/widget: Move uiManager.contains() to the baseWidgets this method makes more sense on a widget anyways. * d2ui/widget: Add methods to handle widget hovering * d2ui/custom_widget: Require define width/height since the custom render() method can do whatever, we need the user to specify the width/height such that GetSize() calls are meaningful. * d2ui/widget: Allow widgets to return the uiManager * d2player/HUD: Refactor health/mana globe into its own widget * d2player/hud: Refactor load() seperate each type of loading into its own method. * d2player/HUD: Move stamina/exp bar into widgets * d2player/HUD: Refactor left/right skills into widget * d2ui/custom_widget: cached custom widgets should use widget.x/y since we render to an image, we use widget.x/y to position the cached image. * d2player/HUD: User cached custom widget for all static images
57 lines
1.5 KiB
Go
57 lines
1.5 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
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
}
|
|
|
|
// Advance is a no-op
|
|
func (c *CustomWidget) Advance(elapsed float64) error {
|
|
return nil
|
|
}
|