2020-02-08 21:02:37 -05:00
|
|
|
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")
|
|
|
|
)
|
|
|
|
|
2020-02-17 22:11:52 -05:00
|
|
|
var singleton *manager
|
2020-02-08 21:02:37 -05:00
|
|
|
|
|
|
|
func Initialize() 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(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Render(target d2render.Surface) error {
|
2020-02-09 14:12:04 -05:00
|
|
|
verifyWasInit()
|
2020-02-08 21:02:37 -05:00
|
|
|
return singleton.render(target)
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
func CreateLayout(positionType PositionType) *Layout {
|
|
|
|
verifyWasInit()
|
|
|
|
return createLayout(positionType)
|
2020-02-17 22:11:52 -05:00
|
|
|
}
|
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
func SetLayout(layout *Layout) {
|
2020-02-09 14:12:04 -05:00
|
|
|
verifyWasInit()
|
2020-02-24 22:35:21 -05:00
|
|
|
singleton.SetLayout(layout)
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
func HideLoadScreen() {
|
2020-02-09 14:12:04 -05:00
|
|
|
verifyWasInit()
|
2020-02-08 21:02:37 -05:00
|
|
|
singleton.hideLoadScreen()
|
|
|
|
}
|
|
|
|
|
|
|
|
func ShowCursor() {
|
2020-02-09 14:12:04 -05:00
|
|
|
verifyWasInit()
|
2020-02-08 21:02:37 -05:00
|
|
|
singleton.showCursor()
|
|
|
|
}
|
|
|
|
|
|
|
|
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-09 14:12:04 -05:00
|
|
|
func verifyNotInit() {
|
2020-02-08 21:02:37 -05:00
|
|
|
if singleton != nil {
|
|
|
|
panic(ErrWasInit)
|
|
|
|
}
|
|
|
|
}
|