1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-10-01 15:46:17 -04:00

showed an error message if the client cannot connect to a host (#910)

This commit is contained in:
Gürkan Kaymak 2020-11-08 22:03:51 +03:00 committed by GitHub
parent be9c29e9d2
commit e99fbf5c4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 8 deletions

View File

@ -894,10 +894,10 @@ func (a *App) updateInitError(target d2interface.Surface) error {
} }
// ToMainMenu forces the game to transition to the Main Menu // 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} 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 { if err != nil {
log.Print(err) log.Print(err)
return return
@ -925,12 +925,14 @@ func (a *App) ToCreateGame(filePath string, connType d2clientconnectiontype.Clie
} }
if err = gameClient.Open(host, filePath); err != nil { if err = gameClient.Open(host, filePath); err != nil {
// https://github.com/OpenDiablo2/OpenDiablo2/issues/805 errorMessage := fmt.Sprintf("can not connect to the host: %s", host)
fmt.Printf("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 // ToCharacterSelect forces the game to transition to the Character Select (load character) screen

View File

@ -6,7 +6,7 @@ import (
// Navigator is used for transitioning between game screens // Navigator is used for transitioning between game screens
type Navigator interface { type Navigator interface {
ToMainMenu() ToMainMenu(errorMessageOptional ...string)
ToSelectHero(connType d2clientconnectiontype.ClientConnectionType, connHost string) ToSelectHero(connType d2clientconnectiontype.ClientConnectionType, connHost string)
ToCreateGame(filePath string, connType d2clientconnectiontype.ClientConnectionType, connHost string) ToCreateGame(filePath string, connType d2clientconnectiontype.ClientConnectionType, connHost string)
ToCharacterSelect(connType d2clientconnectiontype.ClientConnectionType, connHost string) ToCharacterSelect(connType d2clientconnectiontype.ClientConnectionType, connHost string)

View File

@ -59,12 +59,14 @@ const (
networkCancelBtnX, networkCancelBtnY = 264, 540 networkCancelBtnX, networkCancelBtnY = 264, 540
tcpHostBtnX, tcpHostBtnY = 264, 280 tcpHostBtnX, tcpHostBtnY = 264, 280
tcpJoinBtnX, tcpJoinBtnY = 264, 320 tcpJoinBtnX, tcpJoinBtnY = 264, 320
errorLabelX, errorLabelY = 400, 250
) )
const ( const (
white = 0xffffffff white = 0xffffffff
lightYellow = 0xffff8cff lightYellow = 0xffff8cff
gold = 0xd8c480ff gold = 0xd8c480ff
red = 0xff0000ff
) )
const ( const (
@ -107,6 +109,7 @@ type MainMenu struct {
commitLabel *d2ui.Label commitLabel *d2ui.Label
tcpIPOptionsLabel *d2ui.Label tcpIPOptionsLabel *d2ui.Label
tcpJoinGameLabel *d2ui.Label tcpJoinGameLabel *d2ui.Label
errorLabel *d2ui.Label
tcpJoinGameEntry *d2ui.TextBox tcpJoinGameEntry *d2ui.TextBox
screenMode mainMenuScreenMode screenMode mainMenuScreenMode
leftButtonHeld bool leftButtonHeld bool
@ -132,6 +135,7 @@ func CreateMainMenu(
audioProvider d2interface.AudioProvider, audioProvider d2interface.AudioProvider,
ui *d2ui.UIManager, ui *d2ui.UIManager,
buildInfo BuildInfo, buildInfo BuildInfo,
errorMessageOptional ...string,
) (*MainMenu, error) { ) (*MainMenu, error) {
heroStateFactory, err := d2hero.NewHeroStateFactory(asset) heroStateFactory, err := d2hero.NewHeroStateFactory(asset)
if err != nil { if err != nil {
@ -151,6 +155,11 @@ func CreateMainMenu(
heroState: heroStateFactory, heroState: heroStateFactory,
} }
if len(errorMessageOptional) != 0 {
mainMenu.errorLabel = ui.NewLabel(d2resource.FontFormal12, d2resource.PaletteUnits)
mainMenu.errorLabel.SetText(errorMessageOptional[0])
}
return mainMenu, nil return mainMenu, nil
} }
@ -258,6 +267,12 @@ func (v *MainMenu) createLabels(loading d2screen.LoadingState) {
v.tcpJoinGameLabel.Color[0] = rgbaColor(gold) v.tcpJoinGameLabel.Color[0] = rgbaColor(gold)
v.tcpJoinGameLabel.SetPosition(joinGameX, joinGameY) 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) { func (v *MainMenu) createLogos(loading d2screen.LoadingState) {
@ -454,6 +469,10 @@ func (v *MainMenu) renderLabels(screen d2interface.Surface) {
case ScreenModeTrademark: case ScreenModeTrademark:
v.copyrightLabel.Render(screen) v.copyrightLabel.Render(screen)
v.copyrightLabel2.Render(screen) v.copyrightLabel2.Render(screen)
if v.errorLabel != nil {
v.errorLabel.Render(screen)
}
case ScreenModeMainMenu: case ScreenModeMainMenu:
v.openDiabloLabel.Render(screen) v.openDiabloLabel.Render(screen)
v.versionLabel.Render(screen) v.versionLabel.Render(screen)