mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-18 02:16:23 -05:00
390f6a1234
Co-authored-by: carrelda@Davids-MacBook-Pro.local <carrelda@Davids-MacBook-Pro.local>
79 lines
1.4 KiB
Go
79 lines
1.4 KiB
Go
package d2gui
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
|
)
|
|
|
|
var (
|
|
ErrWasInit = errors.New("gui system is already initialized")
|
|
ErrNotInit = errors.New("gui system is not initialized")
|
|
)
|
|
|
|
var singleton *manager
|
|
|
|
func Initialize() error {
|
|
verifyNotInit()
|
|
|
|
var err error
|
|
if singleton, err = createGuiManager(); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Render(target d2render.Surface) error {
|
|
verifyWasInit()
|
|
return singleton.render(target)
|
|
}
|
|
|
|
func Advance(elapsed float64) error {
|
|
verifyWasInit()
|
|
return singleton.advance(elapsed)
|
|
}
|
|
|
|
func CreateLayout(positionType PositionType) *Layout {
|
|
verifyWasInit()
|
|
return createLayout(positionType)
|
|
}
|
|
|
|
func SetLayout(layout *Layout) {
|
|
verifyWasInit()
|
|
singleton.SetLayout(layout)
|
|
}
|
|
|
|
// 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
|
|
func ShowLoadScreen(progress float64) {
|
|
verifyWasInit()
|
|
singleton.showLoadScreen(progress)
|
|
}
|
|
|
|
func HideLoadScreen() {
|
|
verifyWasInit()
|
|
singleton.hideLoadScreen()
|
|
}
|
|
|
|
func ShowCursor() {
|
|
verifyWasInit()
|
|
singleton.showCursor()
|
|
}
|
|
|
|
func HideCursor() {
|
|
verifyWasInit()
|
|
singleton.hideCursor()
|
|
}
|
|
|
|
func verifyWasInit() {
|
|
if singleton == nil {
|
|
panic(ErrNotInit)
|
|
}
|
|
}
|
|
|
|
func verifyNotInit() {
|
|
if singleton != nil {
|
|
panic(ErrWasInit)
|
|
}
|
|
}
|