mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-01-12 04:17:25 -05:00
Renamed scene to screen to avoid confusion of intent. (#334)
This commit is contained in:
parent
a25e42518d
commit
16dc775be1
@ -1,88 +0,0 @@
|
||||
package d2scene
|
||||
|
||||
import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
||||
)
|
||||
|
||||
type Scene interface{}
|
||||
|
||||
type SceneLoadHandler interface {
|
||||
OnLoad() error
|
||||
}
|
||||
|
||||
type SceneUnloadHandler interface {
|
||||
OnUnload() error
|
||||
}
|
||||
|
||||
type SceneRenderHandler interface {
|
||||
Render(target d2render.Surface) error
|
||||
}
|
||||
|
||||
type SceneAdvanceHandler interface {
|
||||
Advance(elapsed float64) error
|
||||
}
|
||||
|
||||
var singleton struct {
|
||||
nextScene Scene
|
||||
loadingScene Scene
|
||||
currentScene Scene
|
||||
}
|
||||
|
||||
func SetNextScene(scene Scene) {
|
||||
singleton.nextScene = scene
|
||||
}
|
||||
|
||||
func Advance(elapsed float64) error {
|
||||
if singleton.nextScene != nil {
|
||||
if handler, ok := singleton.currentScene.(SceneUnloadHandler); ok {
|
||||
if err := handler.OnUnload(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
d2ui.Reset()
|
||||
d2gui.SetLayout(nil)
|
||||
|
||||
if _, ok := singleton.nextScene.(SceneLoadHandler); ok {
|
||||
d2gui.ShowLoadScreen(0)
|
||||
d2gui.HideCursor()
|
||||
singleton.currentScene = nil
|
||||
singleton.loadingScene = singleton.nextScene
|
||||
} else {
|
||||
singleton.currentScene = singleton.nextScene
|
||||
singleton.loadingScene = nil
|
||||
}
|
||||
|
||||
singleton.nextScene = nil
|
||||
} else if singleton.loadingScene != nil {
|
||||
handler := singleton.loadingScene.(SceneLoadHandler)
|
||||
if err := handler.OnLoad(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
singleton.currentScene = singleton.loadingScene
|
||||
singleton.loadingScene = nil
|
||||
d2gui.ShowCursor()
|
||||
d2gui.HideLoadScreen()
|
||||
} else if singleton.currentScene != nil {
|
||||
if handler, ok := singleton.currentScene.(SceneAdvanceHandler); ok {
|
||||
if err := handler.Advance(elapsed); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Render(surface d2render.Surface) error {
|
||||
if handler, ok := singleton.currentScene.(SceneRenderHandler); ok {
|
||||
if err := handler.Render(surface); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
88
d2core/d2screen/d2screen.go
Normal file
88
d2core/d2screen/d2screen.go
Normal file
@ -0,0 +1,88 @@
|
||||
package d2screen
|
||||
|
||||
import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
||||
)
|
||||
|
||||
type Screen interface{}
|
||||
|
||||
type ScreenLoadHandler interface {
|
||||
OnLoad() error
|
||||
}
|
||||
|
||||
type ScreenUnloadHandler interface {
|
||||
OnUnload() error
|
||||
}
|
||||
|
||||
type ScreenRenderHandler interface {
|
||||
Render(target d2render.Surface) error
|
||||
}
|
||||
|
||||
type ScreenAdvanceHandler interface {
|
||||
Advance(elapsed float64) error
|
||||
}
|
||||
|
||||
var singleton struct {
|
||||
nextScreen Screen
|
||||
loadingScreen Screen
|
||||
currentScreen Screen
|
||||
}
|
||||
|
||||
func SetNextScreen(screen Screen) {
|
||||
singleton.nextScreen = screen
|
||||
}
|
||||
|
||||
func Advance(elapsed float64) error {
|
||||
if singleton.nextScreen != nil {
|
||||
if handler, ok := singleton.currentScreen.(ScreenUnloadHandler); ok {
|
||||
if err := handler.OnUnload(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
d2ui.Reset()
|
||||
d2gui.SetLayout(nil)
|
||||
|
||||
if _, ok := singleton.nextScreen.(ScreenLoadHandler); ok {
|
||||
d2gui.ShowLoadScreen(0)
|
||||
d2gui.HideCursor()
|
||||
singleton.currentScreen = nil
|
||||
singleton.loadingScreen = singleton.nextScreen
|
||||
} else {
|
||||
singleton.currentScreen = singleton.nextScreen
|
||||
singleton.loadingScreen = nil
|
||||
}
|
||||
|
||||
singleton.nextScreen = nil
|
||||
} else if singleton.loadingScreen != nil {
|
||||
handler := singleton.loadingScreen.(ScreenLoadHandler)
|
||||
if err := handler.OnLoad(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
singleton.currentScreen = singleton.loadingScreen
|
||||
singleton.loadingScreen = nil
|
||||
d2gui.ShowCursor()
|
||||
d2gui.HideLoadScreen()
|
||||
} else if singleton.currentScreen != nil {
|
||||
if handler, ok := singleton.currentScreen.(ScreenAdvanceHandler); ok {
|
||||
if err := handler.Advance(elapsed); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Render(surface d2render.Surface) error {
|
||||
if handler, ok := singleton.currentScreen.(ScreenRenderHandler); ok {
|
||||
if err := handler.Render(surface); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -31,7 +31,7 @@ func Initialize() {
|
||||
waitForLeftMouseUp = false
|
||||
}
|
||||
|
||||
// Reset resets the state of the UI manager. Typically called for new scenes
|
||||
// Reset resets the state of the UI manager. Typically called for new screens
|
||||
func Reset() {
|
||||
widgets = make([]Widget, 0)
|
||||
pressedIndex = -1
|
||||
|
@ -1,4 +1,4 @@
|
||||
package d2gamescene
|
||||
package d2gamescreen
|
||||
|
||||
import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2video"
|
@ -1,4 +1,4 @@
|
||||
package d2gamescene
|
||||
package d2gamescreen
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
@ -21,7 +21,7 @@ import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2inventory"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2screen"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
||||
)
|
||||
|
||||
@ -166,13 +166,13 @@ func (v *CharacterSelect) updateCharacterBoxes() {
|
||||
}
|
||||
|
||||
func (v *CharacterSelect) onNewCharButtonClicked() {
|
||||
d2scene.SetNextScene(CreateSelectHeroClass())
|
||||
d2screen.SetNextScreen(CreateSelectHeroClass())
|
||||
}
|
||||
|
||||
func (v *CharacterSelect) onExitButtonClicked() {
|
||||
mainMenu := CreateMainMenu()
|
||||
mainMenu.ShowTrademarkScreen = false
|
||||
d2scene.SetNextScene(mainMenu)
|
||||
d2screen.SetNextScreen(mainMenu)
|
||||
}
|
||||
|
||||
func (v *CharacterSelect) Render(screen d2render.Surface) error {
|
||||
@ -295,5 +295,5 @@ func (v *CharacterSelect) refreshGameStates() {
|
||||
func (v *CharacterSelect) onOkButtonClicked() {
|
||||
gameClient, _ := d2client.Create(d2clientconnectiontype.Local)
|
||||
gameClient.Open(v.gameStates[v.selectedCharacter].FilePath)
|
||||
d2scene.SetNextScene(CreateGame(gameClient))
|
||||
d2screen.SetNextScreen(CreateGame(gameClient))
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package d2gamescene
|
||||
package d2gamescreen
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
@ -14,7 +14,7 @@ import (
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2screen"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
||||
)
|
||||
|
||||
@ -24,7 +24,7 @@ type labelItem struct {
|
||||
Available bool
|
||||
}
|
||||
|
||||
// Credits represents the credits scene
|
||||
// Credits represents the credits screen
|
||||
type Credits struct {
|
||||
creditsBackground *d2ui.Sprite
|
||||
exitButton d2ui.Button
|
||||
@ -35,7 +35,7 @@ type Credits struct {
|
||||
doneWithCredits bool
|
||||
}
|
||||
|
||||
// CreateCredits creates an instance of the credits scene
|
||||
// CreateCredits creates an instance of the credits screen
|
||||
func CreateCredits() *Credits {
|
||||
result := &Credits{
|
||||
labels: make([]*labelItem, 0),
|
||||
@ -64,7 +64,7 @@ func (v *Credits) LoadContributors() []string {
|
||||
return contributors
|
||||
}
|
||||
|
||||
// Load is called to load the resources for the credits scene
|
||||
// Load is called to load the resources for the credits screen
|
||||
func (v *Credits) OnLoad() error {
|
||||
animation, _ := d2asset.LoadAnimation(d2resource.CreditsBackground, d2resource.PaletteSky)
|
||||
v.creditsBackground, _ = d2ui.LoadSprite(animation)
|
||||
@ -88,7 +88,7 @@ func (v *Credits) OnLoad() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Render renders the credits scene
|
||||
// Render renders the credits screen
|
||||
func (v *Credits) Render(screen d2render.Surface) error {
|
||||
v.creditsBackground.RenderSegmented(screen, 4, 3, 0)
|
||||
for _, label := range v.labels {
|
||||
@ -103,7 +103,7 @@ func (v *Credits) Render(screen d2render.Surface) error {
|
||||
|
||||
const secondsPerCycle = float64(0.02)
|
||||
|
||||
// Update runs the update logic on the credits scene
|
||||
// Update runs the update logic on the credits screen
|
||||
func (v *Credits) Advance(tickTime float64) error {
|
||||
v.cycleTime += tickTime
|
||||
for v.cycleTime >= secondsPerCycle {
|
||||
@ -131,7 +131,7 @@ func (v *Credits) Advance(tickTime float64) error {
|
||||
func (v *Credits) onExitButtonClicked() {
|
||||
mainMenu := CreateMainMenu()
|
||||
mainMenu.ShowTrademarkScreen = false
|
||||
d2scene.SetNextScene(mainMenu)
|
||||
d2screen.SetNextScreen(mainMenu)
|
||||
}
|
||||
|
||||
func (v *Credits) addNextItem() {
|
@ -1,4 +1,4 @@
|
||||
package d2gamescene
|
||||
package d2gamescreen
|
||||
|
||||
import (
|
||||
"image/color"
|
@ -1,4 +1,4 @@
|
||||
package d2gamescene
|
||||
package d2gamescreen
|
||||
|
||||
import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
|
@ -1,4 +1,4 @@
|
||||
package d2gamescene
|
||||
package d2gamescreen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -15,7 +15,7 @@ import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2audio"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gamestate"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2screen"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
||||
)
|
||||
|
||||
@ -152,7 +152,7 @@ func (v *MainMenu) OnLoad() error {
|
||||
}
|
||||
|
||||
func (v *MainMenu) onMapTestClicked() {
|
||||
d2scene.SetNextScene(CreateMapEngineTest(0, 1))
|
||||
d2screen.SetNextScreen(CreateMapEngineTest(0, 1))
|
||||
}
|
||||
|
||||
func openbrowser(url string) {
|
||||
@ -177,10 +177,10 @@ func openbrowser(url string) {
|
||||
func (v *MainMenu) onSinglePlayerClicked() {
|
||||
// Go here only if existing characters are available to select
|
||||
if d2gamestate.HasGameStates() {
|
||||
d2scene.SetNextScene(CreateCharacterSelect())
|
||||
d2screen.SetNextScreen(CreateCharacterSelect())
|
||||
return
|
||||
}
|
||||
d2scene.SetNextScene(CreateSelectHeroClass())
|
||||
d2screen.SetNextScreen(CreateSelectHeroClass())
|
||||
}
|
||||
|
||||
func (v *MainMenu) onGithubButtonClicked() {
|
||||
@ -192,7 +192,7 @@ func (v *MainMenu) onExitButtonClicked() {
|
||||
}
|
||||
|
||||
func (v *MainMenu) onCreditsButtonClicked() {
|
||||
d2scene.SetNextScene(CreateCredits())
|
||||
d2screen.SetNextScreen(CreateCredits())
|
||||
}
|
||||
|
||||
// Render renders the main menu
|
@ -1,4 +1,4 @@
|
||||
package d2gamescene
|
||||
package d2gamescreen
|
||||
|
||||
import (
|
||||
"math"
|
||||
@ -11,7 +11,7 @@ import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2screen"
|
||||
)
|
||||
|
||||
type RegionSpec struct {
|
||||
@ -311,13 +311,13 @@ func (met *MapEngineTest) OnKeyDown(event d2input.KeyEvent) bool {
|
||||
if event.Key == d2input.KeyN {
|
||||
if event.KeyMod == d2input.KeyModControl {
|
||||
met.fileIndex = increment(met.fileIndex, 0, met.filesCount-1)
|
||||
d2scene.SetNextScene(met)
|
||||
d2screen.SetNextScreen(met)
|
||||
} else if event.KeyMod == d2input.KeyModShift {
|
||||
met.levelPreset = increment(met.levelPreset, met.regionSpec.startPresetIndex, met.regionSpec.endPresetIndex)
|
||||
d2scene.SetNextScene(met)
|
||||
d2screen.SetNextScreen(met)
|
||||
} else {
|
||||
met.currentRegion = increment(met.currentRegion, 0, len(regions))
|
||||
d2scene.SetNextScene(met)
|
||||
d2screen.SetNextScreen(met)
|
||||
}
|
||||
|
||||
return true
|
||||
@ -326,13 +326,13 @@ func (met *MapEngineTest) OnKeyDown(event d2input.KeyEvent) bool {
|
||||
if event.Key == d2input.KeyP {
|
||||
if event.KeyMod == d2input.KeyModControl {
|
||||
met.fileIndex = decrement(met.fileIndex, 0, met.filesCount-1)
|
||||
d2scene.SetNextScene(met)
|
||||
d2screen.SetNextScreen(met)
|
||||
} else if event.KeyMod == d2input.KeyModShift {
|
||||
met.levelPreset = decrement(met.levelPreset, met.regionSpec.startPresetIndex, met.regionSpec.endPresetIndex)
|
||||
d2scene.SetNextScene(met)
|
||||
d2screen.SetNextScreen(met)
|
||||
} else {
|
||||
met.currentRegion = decrement(met.currentRegion, 0, len(regions))
|
||||
d2scene.SetNextScene(met)
|
||||
d2screen.SetNextScreen(met)
|
||||
}
|
||||
|
||||
return true
|
@ -1,4 +1,4 @@
|
||||
package d2gamescene
|
||||
package d2gamescreen
|
||||
|
||||
import (
|
||||
"image"
|
||||
@ -16,7 +16,7 @@ import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2audio"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gamestate"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2screen"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
||||
)
|
||||
|
||||
@ -420,14 +420,14 @@ func (v *SelectHeroClass) OnUnload() error {
|
||||
}
|
||||
|
||||
func (v SelectHeroClass) onExitButtonClicked() {
|
||||
d2scene.SetNextScene(CreateCharacterSelect())
|
||||
d2screen.SetNextScreen(CreateCharacterSelect())
|
||||
}
|
||||
|
||||
func (v SelectHeroClass) onOkButtonClicked() {
|
||||
gameState := d2gamestate.CreateGameState(v.heroNameTextbox.GetText(), v.selectedHero, v.hardcoreCheckbox.GetCheckState())
|
||||
gameClient, _ := d2client.Create(d2clientconnectiontype.Local)
|
||||
gameClient.Open(gameState.FilePath)
|
||||
d2scene.SetNextScene(CreateGame(gameClient))
|
||||
d2screen.SetNextScreen(CreateGame(gameClient))
|
||||
}
|
||||
|
||||
func (v *SelectHeroClass) Render(screen d2render.Surface) error {
|
19
main.go
19
main.go
@ -13,6 +13,10 @@ import (
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2screen"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2game/d2gamescreen"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2inventory"
|
||||
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
@ -21,7 +25,6 @@ import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2game/d2gamescene"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2audio"
|
||||
@ -31,7 +34,6 @@ import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render/ebiten"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2term"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
||||
)
|
||||
@ -79,9 +81,9 @@ func main() {
|
||||
}
|
||||
|
||||
if *region == 0 {
|
||||
d2scene.SetNextScene(d2gamescene.CreateMainMenu())
|
||||
d2screen.SetNextScreen(d2gamescreen.CreateMainMenu())
|
||||
} else {
|
||||
d2scene.SetNextScene(d2gamescene.CreateMapEngineTest(*region, *preset))
|
||||
d2screen.SetNextScreen(d2gamescreen.CreateMapEngineTest(*region, *preset))
|
||||
}
|
||||
|
||||
windowTitle := fmt.Sprintf("OpenDiablo2 (%s)", GitBranch)
|
||||
@ -154,8 +156,8 @@ func initialize() error {
|
||||
d2term.BindAction("quit", "exits the game", func() {
|
||||
os.Exit(0)
|
||||
})
|
||||
d2term.BindAction("scene-gui", "enters the gui playground scene", func() {
|
||||
d2scene.SetNextScene(d2gamescene.CreateGuiTestMain())
|
||||
d2term.BindAction("screen-gui", "enters the gui playground screen", func() {
|
||||
d2screen.SetNextScreen(d2gamescreen.CreateGuiTestMain())
|
||||
})
|
||||
|
||||
if err := d2asset.Initialize(); err != nil {
|
||||
@ -212,7 +214,7 @@ func update(target d2render.Surface) error {
|
||||
}
|
||||
|
||||
func advance(elapsed float64) error {
|
||||
if err := d2scene.Advance(elapsed); err != nil {
|
||||
if err := d2screen.Advance(elapsed); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -234,7 +236,7 @@ func advance(elapsed float64) error {
|
||||
}
|
||||
|
||||
func render(target d2render.Surface) error {
|
||||
if err := d2scene.Render(target); err != nil {
|
||||
if err := d2screen.Render(target); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -390,7 +392,6 @@ func loadDataDict() error {
|
||||
{d2resource.MagicPrefix, d2datadict.LoadMagicPrefix},
|
||||
{d2resource.MagicSuffix, d2datadict.LoadMagicSuffix},
|
||||
{d2resource.ItemStatCost, d2datadict.LoadItemStatCosts},
|
||||
|
||||
}
|
||||
|
||||
for _, entry := range entries {
|
||||
|
Loading…
Reference in New Issue
Block a user