mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-01-12 20:36:25 -05:00
504 - removes input singleton in favor of d2interface.InputManager constructor injection (#584)
Co-authored-by: carrelda <carrelda@git>
This commit is contained in:
parent
894c60f77a
commit
cc893e4dd4
14
d2app/app.go
14
d2app/app.go
@ -25,7 +25,6 @@ import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2config"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2inventory"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2screen"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
||||
@ -47,6 +46,7 @@ type App struct {
|
||||
captureFrames []*image.RGBA
|
||||
gitBranch string
|
||||
gitCommit string
|
||||
inputManager d2interface.InputManager
|
||||
terminal d2interface.Terminal
|
||||
scriptEngine *d2script.ScriptEngine
|
||||
audio d2interface.AudioProvider
|
||||
@ -69,6 +69,7 @@ const (
|
||||
|
||||
// Create creates a new instance of the application
|
||||
func Create(gitBranch, gitCommit string,
|
||||
inputManager d2interface.InputManager,
|
||||
terminal d2interface.Terminal,
|
||||
scriptEngine *d2script.ScriptEngine,
|
||||
audio d2interface.AudioProvider,
|
||||
@ -76,6 +77,7 @@ func Create(gitBranch, gitCommit string,
|
||||
result := &App{
|
||||
gitBranch: gitBranch,
|
||||
gitCommit: gitCommit,
|
||||
inputManager: inputManager,
|
||||
terminal: terminal,
|
||||
scriptEngine: scriptEngine,
|
||||
audio: audio,
|
||||
@ -108,7 +110,7 @@ func (p *App) Run() error {
|
||||
return err
|
||||
}
|
||||
|
||||
d2screen.SetNextScreen(d2gamescreen.CreateMainMenu(p.renderer, p.audio, p.terminal, p.scriptEngine))
|
||||
d2screen.SetNextScreen(d2gamescreen.CreateMainMenu(p.renderer, p.inputManager, p.audio, p.terminal, p.scriptEngine))
|
||||
|
||||
if p.gitBranch == "" {
|
||||
p.gitBranch = "Local Build"
|
||||
@ -160,7 +162,7 @@ func (p *App) initialize() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := d2gui.Initialize(); err != nil {
|
||||
if err := d2gui.Initialize(p.inputManager); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -176,7 +178,7 @@ func (p *App) initialize() error {
|
||||
|
||||
d2inventory.LoadHeroObjects()
|
||||
|
||||
d2ui.Initialize(p.audio)
|
||||
d2ui.Initialize(p.inputManager, p.audio)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -415,7 +417,7 @@ func (p *App) advance(elapsed, current float64) error {
|
||||
|
||||
d2ui.Advance(elapsed)
|
||||
|
||||
if err := d2input.Advance(elapsed, current); err != nil {
|
||||
if err := p.inputManager.Advance(elapsed, current); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -481,7 +483,7 @@ func (p *App) evalJS(code string) {
|
||||
return
|
||||
}
|
||||
|
||||
p.terminal.OutputInfof("%s", val)
|
||||
log.Printf("%s", val)
|
||||
}
|
||||
|
||||
func (p *App) toggleFullScreen() {
|
||||
|
@ -13,11 +13,11 @@ var (
|
||||
|
||||
var singleton *manager
|
||||
|
||||
func Initialize() error {
|
||||
func Initialize(inputManager d2interface.InputManager) error {
|
||||
verifyNotInit()
|
||||
|
||||
var err error
|
||||
if singleton, err = createGuiManager(); err != nil {
|
||||
if singleton, err = createGuiManager(inputManager); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
|
||||
)
|
||||
|
||||
type manager struct {
|
||||
@ -21,7 +20,7 @@ type manager struct {
|
||||
loading bool
|
||||
}
|
||||
|
||||
func createGuiManager() (*manager, error) {
|
||||
func createGuiManager(inputManager d2interface.InputManager) (*manager, error) {
|
||||
cursorAnim, err := d2asset.LoadAnimation(d2resource.CursorDefault, d2resource.PaletteUnits)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -38,7 +37,7 @@ func createGuiManager() (*manager, error) {
|
||||
cursorVisible: true,
|
||||
}
|
||||
|
||||
if err := d2input.BindHandler(manager); err != nil {
|
||||
if err := inputManager.BindHandler(manager); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,6 @@ package d2input
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
|
||||
ebiten_input "github.com/OpenDiablo2/OpenDiablo2/d2core/d2input/ebiten"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -15,34 +10,3 @@ var (
|
||||
// ErrNotReg shows the input system has no registered handler
|
||||
ErrNotReg = errors.New("input system does not have provided handler")
|
||||
)
|
||||
|
||||
var singleton *inputManager // TODO remove this singleton
|
||||
|
||||
// Initialize creates a single global input manager based on a specific input service
|
||||
func Create() (d2interface.InputManager, error) {
|
||||
singleton = &inputManager{
|
||||
inputService: ebiten_input.InputService{},
|
||||
}
|
||||
|
||||
return singleton, nil
|
||||
}
|
||||
|
||||
// Advance moves the input manager with the elapsed number of seconds.
|
||||
func Advance(elapsed, current float64) error {
|
||||
return singleton.Advance(elapsed, current)
|
||||
}
|
||||
|
||||
// BindHandlerWithPriority adds an event handler with a specific call priority
|
||||
func BindHandlerWithPriority(handler d2interface.InputEventHandler, priority d2enum.Priority) error {
|
||||
return singleton.BindHandlerWithPriority(handler, priority)
|
||||
}
|
||||
|
||||
// BindHandler adds an event handler
|
||||
func BindHandler(handler d2interface.InputEventHandler) error {
|
||||
return BindHandlerWithPriority(handler, d2enum.PriorityDefault)
|
||||
}
|
||||
|
||||
// UnbindHandler removes a previously bound event handler
|
||||
func UnbindHandler(handler d2interface.InputEventHandler) error {
|
||||
return singleton.UnbindHandler(handler)
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
package d2input
|
||||
|
||||
import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
"sort"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
ebiten_input "github.com/OpenDiablo2/OpenDiablo2/d2core/d2input/ebiten"
|
||||
)
|
||||
|
||||
type inputManager struct {
|
||||
@ -18,6 +19,12 @@ type inputManager struct {
|
||||
entries handlerEntryList
|
||||
}
|
||||
|
||||
func New() d2interface.InputManager {
|
||||
return &inputManager{
|
||||
inputService: ebiten_input.InputService{},
|
||||
}
|
||||
}
|
||||
|
||||
// Advance advances the inputManager
|
||||
func (im *inputManager) Advance(_, _ float64) error {
|
||||
im.updateKeyMod()
|
||||
@ -211,7 +218,7 @@ func (im *inputManager) updateCursor(cursorX, cursorY int, e HandlerEvent) {
|
||||
func (im *inputManager) BindHandlerWithPriority(
|
||||
h d2interface.InputEventHandler,
|
||||
p d2enum.Priority) error {
|
||||
return singleton.bindHandler(h, p)
|
||||
return im.bindHandler(h, p)
|
||||
}
|
||||
|
||||
// BindHandler adds an event handler
|
||||
|
@ -3,17 +3,16 @@ package d2term
|
||||
import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
|
||||
)
|
||||
|
||||
// Initialize creates and initializes the terminal
|
||||
func Initialize() (d2interface.Terminal, error) {
|
||||
// New creates and initializes the terminal
|
||||
func New(inputManager d2interface.InputManager) (d2interface.Terminal, error) {
|
||||
term, err := createTerminal()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := d2input.BindHandlerWithPriority(term, d2enum.PriorityHigh); err != nil {
|
||||
if err := inputManager.BindHandlerWithPriority(term, d2enum.PriorityHigh); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
package d2ui
|
||||
|
||||
import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
|
||||
)
|
||||
|
||||
// CursorButton represents a mouse button
|
||||
@ -21,6 +21,7 @@ const (
|
||||
)
|
||||
|
||||
type UI struct {
|
||||
inputManager d2interface.InputManager
|
||||
widgets []Widget
|
||||
cursorButtons CursorButton // TODO (carrelld) convert dependent code and remove
|
||||
CursorX int // TODO (carrelld) convert dependent code and remove
|
||||
@ -31,14 +32,17 @@ type UI struct {
|
||||
var singleton UI
|
||||
var clickSfx d2interface.SoundEffect
|
||||
|
||||
func Initialize(audioProvider d2interface.AudioProvider) {
|
||||
func Initialize(inputManager d2interface.InputManager, audioProvider d2interface.AudioProvider) {
|
||||
sfx, err := audioProvider.LoadSoundEffect(d2resource.SFXButtonClick)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to initialize ui: %v", err)
|
||||
}
|
||||
clickSfx = sfx
|
||||
|
||||
d2input.BindHandler(&singleton)
|
||||
singleton.inputManager = inputManager
|
||||
if err := singleton.inputManager.BindHandler(&singleton); err != nil {
|
||||
log.Fatalf("failed to initialize ui: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Reset resets the state of the UI manager. Typically called for new screens
|
||||
@ -49,7 +53,7 @@ func Reset() {
|
||||
|
||||
// AddWidget adds a widget to the UI manager
|
||||
func AddWidget(widget Widget) {
|
||||
d2input.BindHandler(widget)
|
||||
singleton.inputManager.BindHandler(widget)
|
||||
singleton.widgets = append(singleton.widgets, widget)
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2inventory"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapentity"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2screen"
|
||||
@ -46,6 +45,7 @@ type CharacterSelect struct {
|
||||
showDeleteConfirmation bool
|
||||
connectionType d2clientconnectiontype.ClientConnectionType
|
||||
connectionHost string
|
||||
inputManager d2interface.InputManager
|
||||
audioProvider d2interface.AudioProvider
|
||||
terminal d2interface.Terminal
|
||||
scriptEngine *d2script.ScriptEngine
|
||||
@ -55,6 +55,7 @@ type CharacterSelect struct {
|
||||
// CreateCharacterSelect creates the character select screen and returns a pointer to it
|
||||
func CreateCharacterSelect(
|
||||
renderer d2interface.Renderer,
|
||||
inputManager d2interface.InputManager,
|
||||
audioProvider d2interface.AudioProvider,
|
||||
connectionType d2clientconnectiontype.ClientConnectionType,
|
||||
connectionHost string, term d2interface.Terminal, scriptEngine *d2script.ScriptEngine,
|
||||
@ -64,6 +65,7 @@ func CreateCharacterSelect(
|
||||
renderer: renderer,
|
||||
connectionType: connectionType,
|
||||
connectionHost: connectionHost,
|
||||
inputManager: inputManager,
|
||||
audioProvider: audioProvider,
|
||||
terminal: term,
|
||||
scriptEngine: scriptEngine,
|
||||
@ -74,7 +76,7 @@ func CreateCharacterSelect(
|
||||
func (v *CharacterSelect) OnLoad(loading d2screen.LoadingState) {
|
||||
v.audioProvider.PlayBGM(d2resource.BGMTitle)
|
||||
|
||||
if err := d2input.BindHandler(v); err != nil {
|
||||
if err := v.inputManager.BindHandler(v); err != nil {
|
||||
fmt.Println("failed to add Character Select screen as event handler")
|
||||
}
|
||||
|
||||
@ -213,12 +215,12 @@ func (v *CharacterSelect) updateCharacterBoxes() {
|
||||
}
|
||||
|
||||
func (v *CharacterSelect) onNewCharButtonClicked() {
|
||||
d2screen.SetNextScreen(CreateSelectHeroClass(v.renderer, v.audioProvider, v.connectionType, v.connectionHost,
|
||||
d2screen.SetNextScreen(CreateSelectHeroClass(v.renderer, v.inputManager, v.audioProvider, v.connectionType, v.connectionHost,
|
||||
v.terminal, v.scriptEngine))
|
||||
}
|
||||
|
||||
func (v *CharacterSelect) onExitButtonClicked() {
|
||||
mainMenu := CreateMainMenu(v.renderer, v.audioProvider, v.terminal, v.scriptEngine)
|
||||
mainMenu := CreateMainMenu(v.renderer, v.inputManager, v.audioProvider, v.terminal, v.scriptEngine)
|
||||
mainMenu.setScreenMode(screenModeMainMenu)
|
||||
d2screen.SetNextScreen(mainMenu)
|
||||
}
|
||||
@ -376,5 +378,5 @@ func (v *CharacterSelect) onOkButtonClicked() {
|
||||
fmt.Printf("can not connect to the host: %s", host)
|
||||
}
|
||||
|
||||
d2screen.SetNextScreen(CreateGame(v.renderer, v.audioProvider, gameClient, v.terminal, v.scriptEngine))
|
||||
d2screen.SetNextScreen(CreateGame(v.renderer, v.inputManager, v.audioProvider, gameClient, v.terminal, v.scriptEngine))
|
||||
}
|
||||
|
@ -34,19 +34,21 @@ type Credits struct {
|
||||
cyclesTillNextLine int
|
||||
doneWithCredits bool
|
||||
renderer d2interface.Renderer
|
||||
inputManager d2interface.InputManager
|
||||
audioProvider d2interface.AudioProvider
|
||||
terminal d2interface.Terminal
|
||||
scriptEngine *d2script.ScriptEngine
|
||||
}
|
||||
|
||||
// CreateCredits creates an instance of the credits screen
|
||||
func CreateCredits(renderer d2interface.Renderer, audioProvider d2interface.AudioProvider, scriptEngine *d2script.ScriptEngine) *Credits {
|
||||
func CreateCredits(renderer d2interface.Renderer, inputManager d2interface.InputManager, audioProvider d2interface.AudioProvider, scriptEngine *d2script.ScriptEngine) *Credits {
|
||||
result := &Credits{
|
||||
labels: make([]*labelItem, 0),
|
||||
cycleTime: 0,
|
||||
doneWithCredits: false,
|
||||
cyclesTillNextLine: 0,
|
||||
renderer: renderer,
|
||||
inputManager: inputManager,
|
||||
audioProvider: audioProvider,
|
||||
scriptEngine: scriptEngine,
|
||||
}
|
||||
@ -160,7 +162,7 @@ func (v *Credits) Advance(tickTime float64) error {
|
||||
}
|
||||
|
||||
func (v *Credits) onExitButtonClicked() {
|
||||
mainMenu := CreateMainMenu(v.renderer, v.audioProvider, v.terminal, v.scriptEngine)
|
||||
mainMenu := CreateMainMenu(v.renderer, v.inputManager, v.audioProvider, v.terminal, v.scriptEngine)
|
||||
mainMenu.setScreenMode(screenModeMainMenu)
|
||||
d2screen.SetNextScreen(mainMenu)
|
||||
}
|
||||
|
@ -69,6 +69,7 @@ type EscapeMenu struct {
|
||||
layouts []*layout
|
||||
|
||||
renderer d2interface.Renderer
|
||||
inputManager d2interface.InputManager
|
||||
audioProvider d2interface.AudioProvider
|
||||
terminal d2interface.Terminal
|
||||
scriptEngine *d2script.ScriptEngine
|
||||
@ -125,9 +126,10 @@ type actionableElement interface {
|
||||
}
|
||||
|
||||
// NewEscapeMenu creates a new escape menu
|
||||
func NewEscapeMenu(renderer d2interface.Renderer, audioProvider d2interface.AudioProvider, term d2interface.Terminal,
|
||||
func NewEscapeMenu(renderer d2interface.Renderer, inputManager d2interface.InputManager, audioProvider d2interface.AudioProvider, term d2interface.Terminal,
|
||||
scriptEngine *d2script.ScriptEngine) *EscapeMenu {
|
||||
m := &EscapeMenu{
|
||||
inputManager: inputManager,
|
||||
audioProvider: audioProvider,
|
||||
terminal: term,
|
||||
renderer: renderer,
|
||||
@ -371,7 +373,7 @@ func (m *EscapeMenu) showLayout(id layoutID) {
|
||||
}
|
||||
|
||||
if id == saveLayoutID {
|
||||
mainMenu := CreateMainMenu(m.renderer, m.audioProvider, m.terminal, m.scriptEngine)
|
||||
mainMenu := CreateMainMenu(m.renderer, m.inputManager, m.audioProvider, m.terminal, m.scriptEngine)
|
||||
mainMenu.setScreenMode(screenModeMainMenu)
|
||||
d2screen.SetNextScreen(mainMenu)
|
||||
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapentity"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2maprenderer"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2screen"
|
||||
@ -31,12 +30,13 @@ type Game struct {
|
||||
escapeMenu *EscapeMenu
|
||||
|
||||
renderer d2interface.Renderer
|
||||
inputManager d2interface.InputManager
|
||||
audioProvider d2interface.AudioProvider
|
||||
terminal d2interface.Terminal
|
||||
}
|
||||
|
||||
// CreateGame creates the Gameplay screen and returns a pointer to it
|
||||
func CreateGame(renderer d2interface.Renderer, audioProvider d2interface.AudioProvider, gameClient *d2client.GameClient,
|
||||
func CreateGame(renderer d2interface.Renderer, inputManager d2interface.InputManager, audioProvider d2interface.AudioProvider, gameClient *d2client.GameClient,
|
||||
term d2interface.Terminal, scriptEngine *d2script.ScriptEngine) *Game {
|
||||
result := &Game{
|
||||
gameClient: gameClient,
|
||||
@ -45,14 +45,15 @@ func CreateGame(renderer d2interface.Renderer, audioProvider d2interface.AudioPr
|
||||
lastRegionType: d2enum.RegionNone,
|
||||
ticksSinceLevelCheck: 0,
|
||||
mapRenderer: d2maprenderer.CreateMapRenderer(renderer, gameClient.MapEngine, term),
|
||||
escapeMenu: NewEscapeMenu(renderer, audioProvider, term, scriptEngine),
|
||||
escapeMenu: NewEscapeMenu(renderer, inputManager, audioProvider, term, scriptEngine),
|
||||
inputManager: inputManager,
|
||||
audioProvider: audioProvider,
|
||||
renderer: renderer,
|
||||
terminal: term,
|
||||
}
|
||||
result.escapeMenu.onLoad()
|
||||
|
||||
if err := d2input.BindHandler(result.escapeMenu); err != nil {
|
||||
if err := inputManager.BindHandler(result.escapeMenu); err != nil {
|
||||
fmt.Println("failed to add gameplay screen as event handler")
|
||||
}
|
||||
|
||||
@ -66,11 +67,11 @@ func (v *Game) OnLoad(_ d2screen.LoadingState) {
|
||||
|
||||
// OnUnload releases the resources of Gameplay screen
|
||||
func (v *Game) OnUnload() error {
|
||||
if err := d2input.UnbindHandler(v.gameControls); err != nil { // TODO: hack
|
||||
if err := v.inputManager.UnbindHandler(v.gameControls); err != nil { // TODO: hack
|
||||
return err
|
||||
}
|
||||
|
||||
if err := d2input.UnbindHandler(v.escapeMenu); err != nil { // TODO: hack
|
||||
if err := v.inputManager.UnbindHandler(v.escapeMenu); err != nil { // TODO: hack
|
||||
return err
|
||||
}
|
||||
|
||||
@ -162,7 +163,7 @@ func (v *Game) bindGameControls() {
|
||||
v.gameControls = d2player.NewGameControls(v.renderer, player, v.gameClient.MapEngine, v.mapRenderer, v, v.terminal)
|
||||
v.gameControls.Load()
|
||||
|
||||
if err := d2input.BindHandler(v.gameControls); err != nil {
|
||||
if err := v.inputManager.BindHandler(v.gameControls); err != nil {
|
||||
fmt.Printf("failed to add gameControls as input handler for player: %s\n", player.Id)
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@ import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2screen"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2game/d2player"
|
||||
@ -68,6 +67,7 @@ type MainMenu struct {
|
||||
tcpJoinGameEntry d2ui.TextBox
|
||||
screenMode mainMenuScreenMode
|
||||
leftButtonHeld bool
|
||||
inputManager d2interface.InputManager
|
||||
renderer d2interface.Renderer
|
||||
audioProvider d2interface.AudioProvider
|
||||
terminal d2interface.Terminal
|
||||
@ -75,12 +75,13 @@ type MainMenu struct {
|
||||
}
|
||||
|
||||
// CreateMainMenu creates an instance of MainMenu
|
||||
func CreateMainMenu(renderer d2interface.Renderer, audioProvider d2interface.AudioProvider, term d2interface.Terminal,
|
||||
func CreateMainMenu(renderer d2interface.Renderer, inputManager d2interface.InputManager, audioProvider d2interface.AudioProvider, term d2interface.Terminal,
|
||||
scriptEngine *d2script.ScriptEngine) *MainMenu {
|
||||
return &MainMenu{
|
||||
screenMode: screenModeUnknown,
|
||||
leftButtonHeld: true,
|
||||
renderer: renderer,
|
||||
inputManager: inputManager,
|
||||
audioProvider: audioProvider,
|
||||
terminal: term,
|
||||
scriptEngine: scriptEngine,
|
||||
@ -109,7 +110,7 @@ func (v *MainMenu) OnLoad(loading d2screen.LoadingState) {
|
||||
v.setScreenMode(screenModeMainMenu)
|
||||
}
|
||||
|
||||
if err := d2input.BindHandler(v); err != nil {
|
||||
if err := v.inputManager.BindHandler(v); err != nil {
|
||||
fmt.Println("failed to add main menu as event handler")
|
||||
}
|
||||
}
|
||||
@ -279,18 +280,18 @@ func (v *MainMenu) createMultiplayerMenuButtons() {
|
||||
}
|
||||
|
||||
func (v *MainMenu) onMapTestClicked() {
|
||||
d2screen.SetNextScreen(CreateMapEngineTest(0, 1, v.terminal, v.renderer))
|
||||
d2screen.SetNextScreen(CreateMapEngineTest(0, 1, v.terminal, v.renderer, v.inputManager))
|
||||
}
|
||||
|
||||
func (v *MainMenu) onSinglePlayerClicked() {
|
||||
// Go here only if existing characters are available to select
|
||||
if d2player.HasGameStates() {
|
||||
d2screen.SetNextScreen(CreateCharacterSelect(v.renderer, v.audioProvider, d2clientconnectiontype.Local,
|
||||
d2screen.SetNextScreen(CreateCharacterSelect(v.renderer, v.inputManager, v.audioProvider, d2clientconnectiontype.Local,
|
||||
v.tcpJoinGameEntry.GetText(), v.terminal, v.scriptEngine))
|
||||
return
|
||||
}
|
||||
|
||||
d2screen.SetNextScreen(CreateSelectHeroClass(v.renderer, v.audioProvider,
|
||||
d2screen.SetNextScreen(CreateSelectHeroClass(v.renderer, v.inputManager, v.audioProvider,
|
||||
d2clientconnectiontype.Local, v.tcpJoinGameEntry.GetText(), v.terminal, v.scriptEngine))
|
||||
}
|
||||
|
||||
@ -320,7 +321,7 @@ func (v *MainMenu) onExitButtonClicked() {
|
||||
}
|
||||
|
||||
func (v *MainMenu) onCreditsButtonClicked() {
|
||||
d2screen.SetNextScreen(CreateCredits(v.renderer, v.audioProvider, v.scriptEngine))
|
||||
d2screen.SetNextScreen(CreateCredits(v.renderer, v.inputManager, v.audioProvider, v.scriptEngine))
|
||||
}
|
||||
|
||||
// Render renders the main menu
|
||||
@ -485,7 +486,7 @@ func (v *MainMenu) onTCPIPCancelClicked() {
|
||||
}
|
||||
|
||||
func (v *MainMenu) onTCPIPHostGameClicked() {
|
||||
d2screen.SetNextScreen(CreateCharacterSelect(v.renderer, v.audioProvider,
|
||||
d2screen.SetNextScreen(CreateCharacterSelect(v.renderer, v.inputManager, v.audioProvider,
|
||||
d2clientconnectiontype.LANServer, "", v.terminal, v.scriptEngine))
|
||||
}
|
||||
|
||||
@ -498,6 +499,6 @@ func (v *MainMenu) onBtnTCPIPCancelClicked() {
|
||||
}
|
||||
|
||||
func (v *MainMenu) onBtnTCPIPOkClicked() {
|
||||
d2screen.SetNextScreen(CreateCharacterSelect(v.renderer, v.audioProvider,
|
||||
d2screen.SetNextScreen(CreateCharacterSelect(v.renderer, v.inputManager, v.audioProvider,
|
||||
d2clientconnectiontype.LANClient, v.tcpJoinGameEntry.GetText(), v.terminal, v.scriptEngine))
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2screen"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2game/d2player"
|
||||
)
|
||||
@ -81,11 +80,12 @@ var regions = []regionSpec{
|
||||
|
||||
// MapEngineTest represents the MapEngineTest screen
|
||||
type MapEngineTest struct {
|
||||
gameState *d2player.PlayerState
|
||||
mapEngine *d2mapengine.MapEngine
|
||||
mapRenderer *d2maprenderer.MapRenderer
|
||||
terminal d2interface.Terminal
|
||||
renderer d2interface.Renderer
|
||||
gameState *d2player.PlayerState
|
||||
mapEngine *d2mapengine.MapEngine
|
||||
mapRenderer *d2maprenderer.MapRenderer
|
||||
terminal d2interface.Terminal
|
||||
renderer d2interface.Renderer
|
||||
inputManager d2interface.InputManager
|
||||
|
||||
//TODO: this is region specific properties, should be refactored for multi-region rendering
|
||||
currentRegion int
|
||||
@ -97,7 +97,7 @@ type MapEngineTest struct {
|
||||
}
|
||||
|
||||
// CreateMapEngineTest creates the Map Engine Test screen and returns a pointer to it
|
||||
func CreateMapEngineTest(currentRegion, levelPreset int, term d2interface.Terminal, renderer d2interface.Renderer) *MapEngineTest {
|
||||
func CreateMapEngineTest(currentRegion, levelPreset int, term d2interface.Terminal, renderer d2interface.Renderer, inputManager d2interface.InputManager) *MapEngineTest {
|
||||
result := &MapEngineTest{
|
||||
currentRegion: currentRegion,
|
||||
levelPreset: levelPreset,
|
||||
@ -106,6 +106,7 @@ func CreateMapEngineTest(currentRegion, levelPreset int, term d2interface.Termin
|
||||
filesCount: 0,
|
||||
terminal: term,
|
||||
renderer: renderer,
|
||||
inputManager: inputManager,
|
||||
}
|
||||
result.gameState = d2player.CreateTestGameState()
|
||||
|
||||
@ -160,7 +161,7 @@ func (met *MapEngineTest) loadRegionByIndex(n, levelPreset, fileIndex int) {
|
||||
|
||||
// OnLoad loads the resources for the Map Engine Test screen
|
||||
func (met *MapEngineTest) OnLoad(loading d2screen.LoadingState) {
|
||||
if err := d2input.BindHandler(met); err != nil {
|
||||
if err := met.inputManager.BindHandler(met); err != nil {
|
||||
fmt.Printf("could not add MapEngineTest as event handler")
|
||||
}
|
||||
|
||||
@ -178,7 +179,7 @@ func (met *MapEngineTest) OnLoad(loading d2screen.LoadingState) {
|
||||
|
||||
// OnUnload releases the resources for the Map Engine Test screen
|
||||
func (met *MapEngineTest) OnUnload() error {
|
||||
if err := d2input.UnbindHandler(met); err != nil {
|
||||
if err := met.inputManager.UnbindHandler(met); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -181,6 +181,7 @@ type SelectHeroClass struct {
|
||||
hardcoreCharLabel d2ui.Label
|
||||
connectionType d2clientconnectiontype.ClientConnectionType
|
||||
connectionHost string
|
||||
inputManager d2interface.InputManager
|
||||
audioProvider d2interface.AudioProvider
|
||||
terminal d2interface.Terminal
|
||||
renderer d2interface.Renderer
|
||||
@ -190,6 +191,7 @@ type SelectHeroClass struct {
|
||||
// CreateSelectHeroClass creates an instance of a SelectHeroClass
|
||||
func CreateSelectHeroClass(
|
||||
renderer d2interface.Renderer,
|
||||
inputManager d2interface.InputManager,
|
||||
audioProvider d2interface.AudioProvider,
|
||||
connectionType d2clientconnectiontype.ClientConnectionType,
|
||||
connectionHost string,
|
||||
@ -201,6 +203,7 @@ func CreateSelectHeroClass(
|
||||
selectedHero: d2enum.HeroNone,
|
||||
connectionType: connectionType,
|
||||
connectionHost: connectionHost,
|
||||
inputManager: inputManager,
|
||||
audioProvider: audioProvider,
|
||||
terminal: terminal,
|
||||
renderer: renderer,
|
||||
@ -340,7 +343,7 @@ func (v *SelectHeroClass) OnUnload() error {
|
||||
}
|
||||
|
||||
func (v *SelectHeroClass) onExitButtonClicked() {
|
||||
d2screen.SetNextScreen(CreateCharacterSelect(v.renderer, v.audioProvider, v.connectionType,
|
||||
d2screen.SetNextScreen(CreateCharacterSelect(v.renderer, v.inputManager, v.audioProvider, v.connectionType,
|
||||
v.connectionHost, v.terminal, v.scriptEngine))
|
||||
}
|
||||
|
||||
@ -357,7 +360,7 @@ func (v *SelectHeroClass) onOkButtonClicked() {
|
||||
fmt.Printf("can not connect to the host: %s\n", v.connectionHost)
|
||||
}
|
||||
|
||||
d2screen.SetNextScreen(CreateGame(v.renderer, v.audioProvider, gameClient, v.terminal, v.scriptEngine))
|
||||
d2screen.SetNextScreen(CreateGame(v.renderer, v.inputManager, v.audioProvider, gameClient, v.terminal, v.scriptEngine))
|
||||
}
|
||||
|
||||
// Render renders the Select Hero Class screen
|
||||
|
3
go.sum
3
go.sum
@ -29,6 +29,8 @@ github.com/hajimehoshi/ebiten v1.12.0-alpha.5.0.20200627174955-aea4630b5f84 h1:B
|
||||
github.com/hajimehoshi/ebiten v1.12.0-alpha.5.0.20200627174955-aea4630b5f84/go.mod h1:8vzUI4e0fBkbONYOY4WJN/qikY2zv/VG6kFTzJ0B//o=
|
||||
github.com/hajimehoshi/ebiten v1.12.0-alpha.6.0.20200629133528-780465b702ce h1:cEKWqbtxFremkIRhJxz0Z80wXqNNe8ZNk6ra8XASC1I=
|
||||
github.com/hajimehoshi/ebiten v1.12.0-alpha.6.0.20200629133528-780465b702ce/go.mod h1:8vzUI4e0fBkbONYOY4WJN/qikY2zv/VG6kFTzJ0B//o=
|
||||
github.com/hajimehoshi/ebiten v1.12.0-alpha.7.0.20200703165837-6c33ed107f28 h1:su0k5pB/7j3FCoLsXGoPNWMJW7phujO0GC8sViJ07ow=
|
||||
github.com/hajimehoshi/ebiten v1.12.0-alpha.7.0.20200703165837-6c33ed107f28/go.mod h1:vDl2Rhoz8i09Red8XR3B+/Jw+IubfG+V9SDBgQOEI8I=
|
||||
github.com/hajimehoshi/file2byteslice v0.0.0-20190607115218-790acb50cc61 h1:PYZd+KUiq0+ByYlNTMByZz2U/VJ+KmLJ9Q2QAoYb8G0=
|
||||
github.com/hajimehoshi/file2byteslice v0.0.0-20190607115218-790acb50cc61/go.mod h1:CqqAHp7Dk/AqQiwuhV1yT2334qbA/tFWQW0MD2dGqUE=
|
||||
github.com/hajimehoshi/go-mp3 v0.2.1/go.mod h1:Rr+2P46iH6PwTPVgSsEwBkon0CK5DxCAeX/Rp65DCTE=
|
||||
@ -66,6 +68,7 @@ github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdh
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/veandco/go-sdl2 v0.4.4/go.mod h1:FB+kTpX9YTE+urhYiClnRzpOXbiWgaU3+5F2AB78DPg=
|
||||
github.com/walle/lll v1.0.1 h1:lbK8008fOXbQNYt8daBGUrjvElvlwlE7D7N/9dLP5IQ=
|
||||
github.com/walle/lll v1.0.1/go.mod h1:lYxcXzoPhiAHR9eaq+Yv7RYg1nIipLloBCIfPUzfaWQ=
|
||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
|
6
main.go
6
main.go
@ -39,15 +39,15 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
d2input.Create() // TODO d2input singleton must be init before d2term
|
||||
term, err := d2term.Initialize()
|
||||
inputManager := d2input.New()
|
||||
term, err := d2term.New(inputManager)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
scriptEngine := d2script.CreateScriptEngine()
|
||||
|
||||
app := d2app.Create(GitBranch, GitCommit, term, scriptEngine, audio, renderer)
|
||||
app := d2app.Create(GitBranch, GitCommit, inputManager, term, scriptEngine, audio, renderer)
|
||||
if err := app.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user