diff --git a/d2app/app.go b/d2app/app.go index 2853028b..2048501d 100644 --- a/d2app/app.go +++ b/d2app/app.go @@ -894,10 +894,10 @@ func (a *App) updateInitError(target d2interface.Surface) error { } // ToMainMenu forces the game to transition to the Main Menu -func (a *App) ToMainMenu() { +func (a *App) ToMainMenu(errorMessageOptional ...string) { buildInfo := d2gamescreen.BuildInfo{Branch: a.gitBranch, Commit: a.gitCommit} - mainMenu, err := d2gamescreen.CreateMainMenu(a, a.asset, a.renderer, a.inputManager, a.audio, a.ui, buildInfo) + mainMenu, err := d2gamescreen.CreateMainMenu(a, a.asset, a.renderer, a.inputManager, a.audio, a.ui, buildInfo, errorMessageOptional...) if err != nil { log.Print(err) return @@ -925,12 +925,14 @@ func (a *App) ToCreateGame(filePath string, connType d2clientconnectiontype.Clie } if err = gameClient.Open(host, filePath); err != nil { - // https://github.com/OpenDiablo2/OpenDiablo2/issues/805 - fmt.Printf("can not connect to the host: %s", host) + errorMessage := fmt.Sprintf("can not connect to the host: %s", host) + fmt.Println(errorMessage) + a.ToMainMenu(errorMessage) + } else { + a.screen.SetNextScreen(d2gamescreen.CreateGame( + a, a.asset, a.ui, a.renderer, a.inputManager, a.audio, gameClient, a.terminal, a.guiManager, + )) } - - a.screen.SetNextScreen(d2gamescreen.CreateGame(a, a.asset, a.ui, a.renderer, a.inputManager, - a.audio, gameClient, a.terminal, a.guiManager)) } // ToCharacterSelect forces the game to transition to the Character Select (load character) screen diff --git a/d2common/d2interface/navigate.go b/d2common/d2interface/navigate.go index 72e03538..d30d4c39 100644 --- a/d2common/d2interface/navigate.go +++ b/d2common/d2interface/navigate.go @@ -6,7 +6,7 @@ import ( // Navigator is used for transitioning between game screens type Navigator interface { - ToMainMenu() + ToMainMenu(errorMessageOptional ...string) ToSelectHero(connType d2clientconnectiontype.ClientConnectionType, connHost string) ToCreateGame(filePath string, connType d2clientconnectiontype.ClientConnectionType, connHost string) ToCharacterSelect(connType d2clientconnectiontype.ClientConnectionType, connHost string) diff --git a/d2game/d2gamescreen/main_menu.go b/d2game/d2gamescreen/main_menu.go index 22e006c8..b0d82f55 100644 --- a/d2game/d2gamescreen/main_menu.go +++ b/d2game/d2gamescreen/main_menu.go @@ -59,12 +59,14 @@ const ( networkCancelBtnX, networkCancelBtnY = 264, 540 tcpHostBtnX, tcpHostBtnY = 264, 280 tcpJoinBtnX, tcpJoinBtnY = 264, 320 + errorLabelX, errorLabelY = 400, 250 ) const ( white = 0xffffffff lightYellow = 0xffff8cff gold = 0xd8c480ff + red = 0xff0000ff ) const ( @@ -107,6 +109,7 @@ type MainMenu struct { commitLabel *d2ui.Label tcpIPOptionsLabel *d2ui.Label tcpJoinGameLabel *d2ui.Label + errorLabel *d2ui.Label tcpJoinGameEntry *d2ui.TextBox screenMode mainMenuScreenMode leftButtonHeld bool @@ -132,6 +135,7 @@ func CreateMainMenu( audioProvider d2interface.AudioProvider, ui *d2ui.UIManager, buildInfo BuildInfo, + errorMessageOptional ...string, ) (*MainMenu, error) { heroStateFactory, err := d2hero.NewHeroStateFactory(asset) if err != nil { @@ -151,6 +155,11 @@ func CreateMainMenu( heroState: heroStateFactory, } + if len(errorMessageOptional) != 0 { + mainMenu.errorLabel = ui.NewLabel(d2resource.FontFormal12, d2resource.PaletteUnits) + mainMenu.errorLabel.SetText(errorMessageOptional[0]) + } + return mainMenu, nil } @@ -258,6 +267,12 @@ func (v *MainMenu) createLabels(loading d2screen.LoadingState) { v.tcpJoinGameLabel.Color[0] = rgbaColor(gold) v.tcpJoinGameLabel.SetPosition(joinGameX, joinGameY) + + if v.errorLabel != nil { + v.errorLabel.SetPosition(errorLabelX, errorLabelY) + v.errorLabel.Alignment = d2gui.HorizontalAlignCenter + v.errorLabel.Color[0] = rgbaColor(red) + } } func (v *MainMenu) createLogos(loading d2screen.LoadingState) { @@ -454,6 +469,10 @@ func (v *MainMenu) renderLabels(screen d2interface.Surface) { case ScreenModeTrademark: v.copyrightLabel.Render(screen) v.copyrightLabel2.Render(screen) + + if v.errorLabel != nil { + v.errorLabel.Render(screen) + } case ScreenModeMainMenu: v.openDiabloLabel.Render(screen) v.versionLabel.Render(screen)