mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-06-09 09:20:44 +00:00
parent
2035a62ec6
commit
40dcd18487
|
@ -4,6 +4,7 @@ package d2gamescreen
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
|
@ -57,9 +58,10 @@ const (
|
|||
multiplayerBtnX, multiplayerBtnY = 264, 330
|
||||
tcpNetBtnX, tcpNetBtnY = 264, 280
|
||||
networkCancelBtnX, networkCancelBtnY = 264, 540
|
||||
tcpHostBtnX, tcpHostBtnY = 264, 280
|
||||
tcpJoinBtnX, tcpJoinBtnY = 264, 320
|
||||
tcpHostBtnX, tcpHostBtnY = 264, 200
|
||||
tcpJoinBtnX, tcpJoinBtnY = 264, 240
|
||||
errorLabelX, errorLabelY = 400, 250
|
||||
machineIPX, machineIPY = 400, 90
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -109,6 +111,7 @@ type MainMenu struct {
|
|||
commitLabel *d2ui.Label
|
||||
tcpIPOptionsLabel *d2ui.Label
|
||||
tcpJoinGameLabel *d2ui.Label
|
||||
machineIP *d2ui.Label
|
||||
errorLabel *d2ui.Label
|
||||
tcpJoinGameEntry *d2ui.TextBox
|
||||
screenMode mainMenuScreenMode
|
||||
|
@ -261,13 +264,16 @@ func (v *MainMenu) createLabels(loading d2screen.LoadingState) {
|
|||
|
||||
v.tcpJoinGameLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits)
|
||||
v.tcpJoinGameLabel.Alignment = d2gui.HorizontalAlignCenter
|
||||
|
||||
v.tcpJoinGameLabel.SetText("Enter Host IP Address\nto Join Game")
|
||||
|
||||
v.tcpJoinGameLabel.Color[0] = rgbaColor(gold)
|
||||
|
||||
v.tcpJoinGameLabel.SetPosition(joinGameX, joinGameY)
|
||||
|
||||
v.machineIP = v.uiManager.NewLabel(d2resource.Font24, d2resource.PaletteUnits)
|
||||
v.machineIP.Alignment = d2gui.HorizontalAlignCenter
|
||||
v.machineIP.SetText("Your IP address is:\n" + v.getLocalIP())
|
||||
v.machineIP.Color[0] = rgbaColor(lightYellow)
|
||||
v.machineIP.SetPosition(machineIPX, machineIPY)
|
||||
|
||||
if v.errorLabel != nil {
|
||||
v.errorLabel.SetPosition(errorLabelX, errorLabelY)
|
||||
v.errorLabel.Alignment = d2gui.HorizontalAlignCenter
|
||||
|
@ -462,8 +468,10 @@ func (v *MainMenu) renderLabels(screen d2interface.Surface) {
|
|||
case ScreenModeServerIP:
|
||||
v.tcpIPOptionsLabel.Render(screen)
|
||||
v.tcpJoinGameLabel.Render(screen)
|
||||
v.machineIP.Render(screen)
|
||||
case ScreenModeTCPIP:
|
||||
v.tcpIPOptionsLabel.Render(screen)
|
||||
v.machineIP.Render(screen)
|
||||
case ScreenModeTrademark:
|
||||
v.copyrightLabel.Render(screen)
|
||||
v.copyrightLabel2.Render(screen)
|
||||
|
@ -612,3 +620,25 @@ func (v *MainMenu) onBtnTCPIPCancelClicked() {
|
|||
func (v *MainMenu) onBtnTCPIPOkClicked() {
|
||||
v.navigator.ToCharacterSelect(d2clientconnectiontype.LANClient, v.tcpJoinGameEntry.GetText())
|
||||
}
|
||||
|
||||
// getLocalIP returns local machine IP address
|
||||
func (v *MainMenu) getLocalIP() string {
|
||||
conn, err := net.Dial("udp", "8.8.8.8:80")
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
||||
return "cannot reach network"
|
||||
}
|
||||
|
||||
err = conn.Close()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
||||
return "unexpected error occurred while closing test connection"
|
||||
}
|
||||
|
||||
localAddr := conn.LocalAddr().(*net.UDPAddr)
|
||||
|
||||
return localAddr.IP.String()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user