1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-19 21:55:24 +00:00
OpenDiablo2/d2core/d2gui/d2gui.go

91 lines
1.9 KiB
Go
Raw Normal View History

2020-02-09 02:02:37 +00:00
package d2gui
import (
"errors"
remove d2asset singleton (#726) * export d2asset singleton * add *d2asset.AssetManager to d2app - d2app now has a reference to an asset manager which it will use for loading - added asset loader methods to the asset manager - functions in d2asset are now wrappers for asset manager methods * add asset manager reference to audio provider - d2app asset manager reference is now passed to audio provider - asset manager is created in main.go for now to pass into audio provider - CreateSoundEffect is now a method, no longer exported, uses the asset manager reference * d2app passes asset manager refence to map engine test * in d2asset, all calls to LoadFile replaced with call to Singleton.Loadfile * blizzard intro and credits screen - d2app passes reference to the asset manager to these screens * asset manager for d2map - adding MapStampFactory, takes an asset manager reference - embedded MapStampFactory into the MapEngine - LoadStamp is now a method of the MapStampFactory * d2asset: removed LoadFileStream, LoadFile, and FileExists * d2gui changes - singleton now has an asset manager reference - calls to d2asset loader functions removed - createButton is now a method of LayoutManager - moved LayoutEntry to its own file * map entity factory - Map engine has an embedded map entity factory - Map stamp factory gets a reference to the map engine's entity factory - Stamps are given a reference to the map engine entity factory when created - Character select gets a map entity factory - Embedded the stamp factory into the MapEngine * asset manager for d2ui - d2ui is passed an asset manager reference when created - all calls to d2asset loader functions in d2ui now refer to the asset manager - d2gamescreen gets a ui manager when created - help overlay is now passed a ui manager when created * d2gamescreen + d2player: asset manager references added an asset manager reference to - inventory panel + inventory grid - mini panel - game controls - help overlay - character select - main menu - select hero class - hero stats panel * Removed d2asset.LoadAnimation all references to this function have been replaced with calls to the asset manager method * adding asset to help overlay, bugfix for 4d59c91 * Removed d2asset.LoadFont and d2asset.LoadAnimationWithEffect all references to these have been replaced with calls to the asset manager methods * MapRenderer now gets an asset manager reference * removed d2asset.LoadPalette all references have been replaced with calls to an asset manager instance * merged d2object with d2mapentity d2object was only being used to create objects in the map, so the provider function is now a method of the map entity factory. calls to d2asset have been removed. * removed d2asset.LoadComposite all calls are now made to the asset manager method * removed d2asset singleton all singleton references have been removed, a single instance of the asset manager is passed around the entire app * rename Initialize to NewAssetManager
2020-09-12 20:51:30 +00:00
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
2020-02-09 02:02:37 +00:00
)
var (
errWasInit = errors.New("gui system is already initialized")
errNotInit = errors.New("gui system is not initialized")
2020-02-09 02:02:37 +00:00
)
2020-08-05 17:51:19 +00:00
var singleton *manager // nolint:gochecknoglobals // currently global by design
2020-02-09 02:02:37 +00:00
// Initialize creates a singleton gui manager
remove d2asset singleton (#726) * export d2asset singleton * add *d2asset.AssetManager to d2app - d2app now has a reference to an asset manager which it will use for loading - added asset loader methods to the asset manager - functions in d2asset are now wrappers for asset manager methods * add asset manager reference to audio provider - d2app asset manager reference is now passed to audio provider - asset manager is created in main.go for now to pass into audio provider - CreateSoundEffect is now a method, no longer exported, uses the asset manager reference * d2app passes asset manager refence to map engine test * in d2asset, all calls to LoadFile replaced with call to Singleton.Loadfile * blizzard intro and credits screen - d2app passes reference to the asset manager to these screens * asset manager for d2map - adding MapStampFactory, takes an asset manager reference - embedded MapStampFactory into the MapEngine - LoadStamp is now a method of the MapStampFactory * d2asset: removed LoadFileStream, LoadFile, and FileExists * d2gui changes - singleton now has an asset manager reference - calls to d2asset loader functions removed - createButton is now a method of LayoutManager - moved LayoutEntry to its own file * map entity factory - Map engine has an embedded map entity factory - Map stamp factory gets a reference to the map engine's entity factory - Stamps are given a reference to the map engine entity factory when created - Character select gets a map entity factory - Embedded the stamp factory into the MapEngine * asset manager for d2ui - d2ui is passed an asset manager reference when created - all calls to d2asset loader functions in d2ui now refer to the asset manager - d2gamescreen gets a ui manager when created - help overlay is now passed a ui manager when created * d2gamescreen + d2player: asset manager references added an asset manager reference to - inventory panel + inventory grid - mini panel - game controls - help overlay - character select - main menu - select hero class - hero stats panel * Removed d2asset.LoadAnimation all references to this function have been replaced with calls to the asset manager method * adding asset to help overlay, bugfix for 4d59c91 * Removed d2asset.LoadFont and d2asset.LoadAnimationWithEffect all references to these have been replaced with calls to the asset manager methods * MapRenderer now gets an asset manager reference * removed d2asset.LoadPalette all references have been replaced with calls to an asset manager instance * merged d2object with d2mapentity d2object was only being used to create objects in the map, so the provider function is now a method of the map entity factory. calls to d2asset have been removed. * removed d2asset.LoadComposite all calls are now made to the asset manager method * removed d2asset singleton all singleton references have been removed, a single instance of the asset manager is passed around the entire app * rename Initialize to NewAssetManager
2020-09-12 20:51:30 +00:00
func Initialize(asset *d2asset.AssetManager, inputManager d2interface.InputManager) error {
2020-02-09 19:12:04 +00:00
verifyNotInit()
2020-02-09 02:02:37 +00:00
var err error
remove d2asset singleton (#726) * export d2asset singleton * add *d2asset.AssetManager to d2app - d2app now has a reference to an asset manager which it will use for loading - added asset loader methods to the asset manager - functions in d2asset are now wrappers for asset manager methods * add asset manager reference to audio provider - d2app asset manager reference is now passed to audio provider - asset manager is created in main.go for now to pass into audio provider - CreateSoundEffect is now a method, no longer exported, uses the asset manager reference * d2app passes asset manager refence to map engine test * in d2asset, all calls to LoadFile replaced with call to Singleton.Loadfile * blizzard intro and credits screen - d2app passes reference to the asset manager to these screens * asset manager for d2map - adding MapStampFactory, takes an asset manager reference - embedded MapStampFactory into the MapEngine - LoadStamp is now a method of the MapStampFactory * d2asset: removed LoadFileStream, LoadFile, and FileExists * d2gui changes - singleton now has an asset manager reference - calls to d2asset loader functions removed - createButton is now a method of LayoutManager - moved LayoutEntry to its own file * map entity factory - Map engine has an embedded map entity factory - Map stamp factory gets a reference to the map engine's entity factory - Stamps are given a reference to the map engine entity factory when created - Character select gets a map entity factory - Embedded the stamp factory into the MapEngine * asset manager for d2ui - d2ui is passed an asset manager reference when created - all calls to d2asset loader functions in d2ui now refer to the asset manager - d2gamescreen gets a ui manager when created - help overlay is now passed a ui manager when created * d2gamescreen + d2player: asset manager references added an asset manager reference to - inventory panel + inventory grid - mini panel - game controls - help overlay - character select - main menu - select hero class - hero stats panel * Removed d2asset.LoadAnimation all references to this function have been replaced with calls to the asset manager method * adding asset to help overlay, bugfix for 4d59c91 * Removed d2asset.LoadFont and d2asset.LoadAnimationWithEffect all references to these have been replaced with calls to the asset manager methods * MapRenderer now gets an asset manager reference * removed d2asset.LoadPalette all references have been replaced with calls to an asset manager instance * merged d2object with d2mapentity d2object was only being used to create objects in the map, so the provider function is now a method of the map entity factory. calls to d2asset have been removed. * removed d2asset.LoadComposite all calls are now made to the asset manager method * removed d2asset singleton all singleton references have been removed, a single instance of the asset manager is passed around the entire app * rename Initialize to NewAssetManager
2020-09-12 20:51:30 +00:00
if singleton, err = createGuiManager(asset, inputManager); err != nil {
2020-02-09 02:02:37 +00:00
return err
}
return nil
}
// Render all of the gui elements
func Render(target d2interface.Surface) error {
2020-02-09 19:12:04 +00:00
verifyWasInit()
2020-02-09 02:02:37 +00:00
return singleton.render(target)
}
// Advance all of the gui elements
2020-02-09 02:02:37 +00:00
func Advance(elapsed float64) error {
2020-02-09 19:12:04 +00:00
verifyWasInit()
2020-02-09 02:02:37 +00: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 19:12:04 +00:00
verifyWasInit()
singleton.SetLayout(layout)
2020-02-09 02:02:37 +00: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-09 02:02:37 +00:00
func ShowLoadScreen(progress float64) {
2020-02-09 19:12:04 +00:00
verifyWasInit()
2020-02-09 02:02:37 +00:00
singleton.showLoadScreen(progress)
}
// HideLoadScreen hides the loading screen
2020-02-09 02:02:37 +00:00
func HideLoadScreen() {
2020-02-09 19:12:04 +00:00
verifyWasInit()
2020-02-09 02:02:37 +00:00
singleton.hideLoadScreen()
}
// ShowCursor shows the in-game mouse cursor
2020-02-09 02:02:37 +00:00
func ShowCursor() {
2020-02-09 19:12:04 +00:00
verifyWasInit()
2020-02-09 02:02:37 +00:00
singleton.showCursor()
}
// HideCursor hides the in-game mouse cursor
2020-02-09 02:02:37 +00:00
func HideCursor() {
2020-02-09 19:12:04 +00:00
verifyWasInit()
2020-02-09 02:02:37 +00:00
singleton.hideCursor()
}
2020-02-09 19:12:04 +00:00
func verifyWasInit() {
2020-02-09 02:02:37 +00:00
if singleton == nil {
panic(errNotInit)
2020-02-09 02:02:37 +00:00
}
}
2020-02-09 19:12:04 +00:00
func verifyNotInit() {
2020-02-09 02:02:37 +00:00
if singleton != nil {
panic(errWasInit)
2020-02-09 02:02:37 +00:00
}
}