1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-07 10:47:19 -05: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
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

View File

@ -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)

View File

@ -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)