2020-02-08 21:02:37 -05:00
|
|
|
package d2gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2020-06-29 00:41:58 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
2020-02-08 21:02:37 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-07-18 18:06:36 -04:00
|
|
|
errWasInit = errors.New("gui system is already initialized")
|
|
|
|
errNotInit = errors.New("gui system is not initialized")
|
2020-02-08 21:02:37 -05:00
|
|
|
)
|
|
|
|
|
2020-02-17 22:11:52 -05:00
|
|
|
var singleton *manager
|
2020-02-08 21:02:37 -05:00
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
// Initialize creates a singleton gui manager
|
2020-07-13 20:29:17 -04:00
|
|
|
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
|
2020-07-13 20:29:17 -04:00
|
|
|
if singleton, err = createGuiManager(inputManager); err != nil {
|
2020-02-08 21:02:37 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
// Render all of the gui elements
|
2020-06-29 00:41:58 -04:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
// CreateLayout creates a dynamic layout
|
2020-07-03 14:00:56 -04:00
|
|
|
func CreateLayout(renderer d2interface.Renderer, positionType PositionType) *Layout {
|
2020-02-24 22:35:21 -05:00
|
|
|
verifyWasInit()
|
2020-07-03 14:00:56 -04:00
|
|
|
return createLayout(renderer, positionType)
|
2020-02-17 22:11:52 -05:00
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
// SetLayout sets the gui manager's layout
|
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
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04: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)
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
// 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()
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
// 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()
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
// 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 {
|
2020-07-18 18:06:36 -04:00
|
|
|
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 {
|
2020-07-18 18:06:36 -04:00
|
|
|
panic(errWasInit)
|
2020-02-08 21:02:37 -05:00
|
|
|
}
|
|
|
|
}
|