1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-09-27 21:56:19 -04:00
OpenDiablo2/d2core/d2gui/d2gui.go

89 lines
1.8 KiB
Go
Raw Normal View History

2020-02-08 21:02:37 -05:00
package d2gui
import (
"errors"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
2020-02-08 21:02:37 -05:00
)
var (
errWasInit = errors.New("gui system is already initialized")
errNotInit = errors.New("gui system is not initialized")
2020-02-08 21:02:37 -05:00
)
var singleton *manager
2020-02-08 21:02:37 -05:00
// Initialize creates a singleton gui manager
func Initialize(inputManager d2interface.InputManager) error {
2020-02-09 14:12:04 -05:00
verifyNotInit()
2020-02-08 21:02:37 -05:00
var err error
if singleton, err = createGuiManager(inputManager); err != nil {
2020-02-08 21:02:37 -05:00
return err
}
return nil
}
// Render all of the gui elements
func Render(target d2interface.Surface) error {
2020-02-09 14:12:04 -05:00
verifyWasInit()
2020-02-08 21:02:37 -05:00
return singleton.render(target)
}
// Advance all of the gui elements
2020-02-08 21:02:37 -05:00
func Advance(elapsed float64) error {
2020-02-09 14:12:04 -05:00
verifyWasInit()
2020-02-08 21:02:37 -05:00
return singleton.advance(elapsed)
}
// CreateLayout creates a dynamic layout
func CreateLayout(renderer d2interface.Renderer, positionType PositionType) *Layout {
verifyWasInit()
return createLayout(renderer, positionType)
}
// SetLayout sets the gui manager's layout
func SetLayout(layout *Layout) {
2020-02-09 14:12:04 -05:00
verifyWasInit()
singleton.SetLayout(layout)
2020-02-08 21:02:37 -05:00
}
// ShowLoadScreen renders the loading progress screen.
// The provided progress argument defines the loading animation's state in the range `[0, 1]`,
// where `0` is initial frame and `1` is the final frame
2020-02-08 21:02:37 -05:00
func ShowLoadScreen(progress float64) {
2020-02-09 14:12:04 -05:00
verifyWasInit()
2020-02-08 21:02:37 -05:00
singleton.showLoadScreen(progress)
}
// HideLoadScreen hides the loading screen
2020-02-08 21:02:37 -05:00
func HideLoadScreen() {
2020-02-09 14:12:04 -05:00
verifyWasInit()
2020-02-08 21:02:37 -05:00
singleton.hideLoadScreen()
}
// ShowCursor shows the in-game mouse cursor
2020-02-08 21:02:37 -05:00
func ShowCursor() {
2020-02-09 14:12:04 -05:00
verifyWasInit()
2020-02-08 21:02:37 -05:00
singleton.showCursor()
}
// HideCursor hides the in-game mouse cursor
2020-02-08 21:02:37 -05:00
func HideCursor() {
2020-02-09 14:12:04 -05:00
verifyWasInit()
2020-02-08 21:02:37 -05:00
singleton.hideCursor()
}
2020-02-09 14:12:04 -05:00
func verifyWasInit() {
2020-02-08 21:02:37 -05:00
if singleton == nil {
panic(errNotInit)
2020-02-08 21:02:37 -05:00
}
}
2020-02-09 14:12:04 -05:00
func verifyNotInit() {
2020-02-08 21:02:37 -05:00
if singleton != nil {
panic(errWasInit)
2020-02-08 21:02:37 -05:00
}
}