2020-07-06 20:13:55 -04:00
|
|
|
// Package d2gamescreen contains the screens
|
2020-06-13 20:36:20 -04:00
|
|
|
package d2gamescreen
|
2019-10-24 09:31:59 -04:00
|
|
|
|
|
|
|
import (
|
2019-10-26 12:55:36 -04:00
|
|
|
"fmt"
|
2019-10-24 19:13:30 -04:00
|
|
|
"image/color"
|
2019-10-26 12:55:36 -04:00
|
|
|
"log"
|
2019-10-25 23:41:54 -04:00
|
|
|
"os"
|
2019-10-26 12:55:36 -04:00
|
|
|
"os/exec"
|
|
|
|
"runtime"
|
2019-10-24 19:13:30 -04:00
|
|
|
|
2020-02-08 21:02:37 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
2020-07-11 11:24:04 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
2020-02-08 21:02:37 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
2020-07-11 11:24:04 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
|
2020-06-13 20:36:20 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2screen"
|
2020-01-31 23:18:11 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
2020-07-11 11:24:04 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2game/d2player"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2client/d2clientconnectiontype"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2script"
|
2019-10-24 09:31:59 -04:00
|
|
|
)
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
type mainMenuScreenMode int
|
2020-06-18 14:11:04 -04:00
|
|
|
|
|
|
|
const (
|
2020-07-02 13:55:43 -04:00
|
|
|
screenModeUnknown mainMenuScreenMode = iota
|
|
|
|
screenModeTrademark
|
|
|
|
screenModeMainMenu
|
|
|
|
screenModeMultiplayer
|
|
|
|
screenModeTCPIP
|
|
|
|
screenModeServerIP
|
2020-06-18 14:11:04 -04:00
|
|
|
)
|
|
|
|
|
2019-10-25 18:40:27 -04:00
|
|
|
// MainMenu represents the main menu
|
2019-10-24 09:31:59 -04:00
|
|
|
type MainMenu struct {
|
2020-07-02 13:55:43 -04:00
|
|
|
tcpIPBackground *d2ui.Sprite
|
2020-02-01 18:55:56 -05:00
|
|
|
trademarkBackground *d2ui.Sprite
|
|
|
|
background *d2ui.Sprite
|
|
|
|
diabloLogoLeft *d2ui.Sprite
|
|
|
|
diabloLogoRight *d2ui.Sprite
|
|
|
|
diabloLogoLeftBack *d2ui.Sprite
|
|
|
|
diabloLogoRightBack *d2ui.Sprite
|
2020-07-02 13:55:43 -04:00
|
|
|
serverIPBackground *d2ui.Sprite
|
2019-11-10 12:28:41 -05:00
|
|
|
singlePlayerButton d2ui.Button
|
2020-06-18 14:11:04 -04:00
|
|
|
multiplayerButton d2ui.Button
|
2019-11-10 12:28:41 -05:00
|
|
|
githubButton d2ui.Button
|
|
|
|
exitDiabloButton d2ui.Button
|
|
|
|
creditsButton d2ui.Button
|
|
|
|
cinematicsButton d2ui.Button
|
|
|
|
mapTestButton d2ui.Button
|
2020-07-02 13:55:43 -04:00
|
|
|
networkTCPIPButton d2ui.Button
|
2020-06-18 14:11:04 -04:00
|
|
|
networkCancelButton d2ui.Button
|
2020-07-02 13:55:43 -04:00
|
|
|
btnTCPIPCancel d2ui.Button
|
|
|
|
btnTCPIPHostGame d2ui.Button
|
|
|
|
btnTCPIPJoinGame d2ui.Button
|
|
|
|
btnServerIPCancel d2ui.Button
|
|
|
|
btnServerIPOk d2ui.Button
|
2019-11-10 12:28:41 -05:00
|
|
|
copyrightLabel d2ui.Label
|
|
|
|
copyrightLabel2 d2ui.Label
|
|
|
|
openDiabloLabel d2ui.Label
|
|
|
|
versionLabel d2ui.Label
|
|
|
|
commitLabel d2ui.Label
|
2020-07-02 13:55:43 -04:00
|
|
|
tcpIPOptionsLabel d2ui.Label
|
2020-06-18 14:11:04 -04:00
|
|
|
tcpJoinGameLabel d2ui.Label
|
|
|
|
tcpJoinGameEntry d2ui.TextBox
|
2020-07-02 13:55:43 -04:00
|
|
|
screenMode mainMenuScreenMode
|
2019-10-25 18:40:27 -04:00
|
|
|
leftButtonHeld bool
|
2020-07-13 20:29:17 -04:00
|
|
|
inputManager d2interface.InputManager
|
2020-07-03 14:00:56 -04:00
|
|
|
renderer d2interface.Renderer
|
2020-06-28 19:31:10 -04:00
|
|
|
audioProvider d2interface.AudioProvider
|
2020-06-28 21:40:52 -04:00
|
|
|
terminal d2interface.Terminal
|
2020-07-11 11:24:04 -04:00
|
|
|
scriptEngine *d2script.ScriptEngine
|
2019-10-24 09:31:59 -04:00
|
|
|
}
|
|
|
|
|
2019-10-25 18:40:27 -04:00
|
|
|
// CreateMainMenu creates an instance of MainMenu
|
2020-07-13 20:29:17 -04:00
|
|
|
func CreateMainMenu(renderer d2interface.Renderer, inputManager d2interface.InputManager, audioProvider d2interface.AudioProvider, term d2interface.Terminal,
|
2020-07-11 11:24:04 -04:00
|
|
|
scriptEngine *d2script.ScriptEngine) *MainMenu {
|
2020-02-08 21:02:37 -05:00
|
|
|
return &MainMenu{
|
2020-07-02 13:55:43 -04:00
|
|
|
screenMode: screenModeUnknown,
|
2020-06-18 14:11:04 -04:00
|
|
|
leftButtonHeld: true,
|
2020-07-03 14:00:56 -04:00
|
|
|
renderer: renderer,
|
2020-07-13 20:29:17 -04:00
|
|
|
inputManager: inputManager,
|
2020-06-28 19:31:10 -04:00
|
|
|
audioProvider: audioProvider,
|
2020-06-28 21:40:52 -04:00
|
|
|
terminal: term,
|
2020-07-11 11:24:04 -04:00
|
|
|
scriptEngine: scriptEngine,
|
2019-10-24 09:31:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// OnLoad is called to load the resources for the main menu
|
2020-06-24 18:46:03 -04:00
|
|
|
func (v *MainMenu) OnLoad(loading d2screen.LoadingState) {
|
2020-06-28 19:31:10 -04:00
|
|
|
v.audioProvider.PlayBGM(d2resource.BGMTitle)
|
2020-06-24 18:46:03 -04:00
|
|
|
loading.Progress(0.2)
|
2020-02-08 21:02:37 -05:00
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
v.createLabels(loading)
|
|
|
|
v.loadBackgroundSprites()
|
|
|
|
v.createLogos(loading)
|
|
|
|
v.createButtons(loading)
|
|
|
|
|
2020-07-03 14:00:56 -04:00
|
|
|
v.tcpJoinGameEntry = d2ui.CreateTextbox(v.renderer)
|
2020-07-02 13:55:43 -04:00
|
|
|
v.tcpJoinGameEntry.SetPosition(318, 245)
|
|
|
|
v.tcpJoinGameEntry.SetFilter("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890._:")
|
|
|
|
d2ui.AddWidget(&v.tcpJoinGameEntry)
|
|
|
|
loading.Progress(0.9)
|
|
|
|
|
|
|
|
if v.screenMode == screenModeUnknown {
|
|
|
|
v.setScreenMode(screenModeTrademark)
|
|
|
|
} else {
|
|
|
|
v.setScreenMode(screenModeMainMenu)
|
|
|
|
}
|
|
|
|
|
2020-07-13 20:29:17 -04:00
|
|
|
if err := v.inputManager.BindHandler(v); err != nil {
|
2020-07-02 13:55:43 -04:00
|
|
|
fmt.Println("failed to add main menu as event handler")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *MainMenu) loadBackgroundSprites() {
|
|
|
|
animation, _ := d2asset.LoadAnimation(d2resource.GameSelectScreen, d2resource.PaletteSky)
|
|
|
|
v.background, _ = d2ui.LoadSprite(animation)
|
|
|
|
v.background.SetPosition(0, 0)
|
|
|
|
|
|
|
|
animation, _ = d2asset.LoadAnimation(d2resource.TrademarkScreen, d2resource.PaletteSky)
|
|
|
|
v.trademarkBackground, _ = d2ui.LoadSprite(animation)
|
|
|
|
v.trademarkBackground.SetPosition(0, 0)
|
|
|
|
|
|
|
|
animation, _ = d2asset.LoadAnimation(d2resource.TCPIPBackground, d2resource.PaletteSky)
|
|
|
|
v.tcpIPBackground, _ = d2ui.LoadSprite(animation)
|
|
|
|
v.tcpIPBackground.SetPosition(0, 0)
|
|
|
|
|
|
|
|
animation, _ = d2asset.LoadAnimation(d2resource.PopUpOkCancel, d2resource.PaletteFechar)
|
|
|
|
v.serverIPBackground, _ = d2ui.LoadSprite(animation)
|
|
|
|
v.serverIPBackground.SetPosition(270, 175)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *MainMenu) createLabels(loading d2screen.LoadingState) {
|
2020-07-07 20:16:22 -04:00
|
|
|
v.versionLabel = d2ui.CreateLabel(d2resource.FontFormal12, d2resource.PaletteStatic)
|
|
|
|
v.versionLabel.Alignment = d2gui.HorizontalAlignRight
|
2020-02-08 21:02:37 -05:00
|
|
|
v.versionLabel.SetText("OpenDiablo2 - " + d2common.BuildInfo.Branch)
|
|
|
|
v.versionLabel.Color = color.RGBA{R: 255, G: 255, B: 255, A: 255}
|
|
|
|
v.versionLabel.SetPosition(795, -10)
|
|
|
|
|
2020-07-07 20:16:22 -04:00
|
|
|
v.commitLabel = d2ui.CreateLabel(d2resource.FontFormal10, d2resource.PaletteStatic)
|
|
|
|
v.commitLabel.Alignment = d2gui.HorizontalAlignLeft
|
2020-02-08 21:02:37 -05:00
|
|
|
v.commitLabel.SetText(d2common.BuildInfo.Commit)
|
|
|
|
v.commitLabel.Color = color.RGBA{R: 255, G: 255, B: 255, A: 255}
|
|
|
|
v.commitLabel.SetPosition(2, 2)
|
|
|
|
|
2020-07-07 20:16:22 -04:00
|
|
|
v.copyrightLabel = d2ui.CreateLabel(d2resource.FontFormal12, d2resource.PaletteStatic)
|
|
|
|
v.copyrightLabel.Alignment = d2gui.HorizontalAlignCenter
|
2020-02-08 21:02:37 -05:00
|
|
|
v.copyrightLabel.SetText("Diablo 2 is © Copyright 2000-2016 Blizzard Entertainment")
|
|
|
|
v.copyrightLabel.Color = color.RGBA{R: 188, G: 168, B: 140, A: 255}
|
|
|
|
v.copyrightLabel.SetPosition(400, 500)
|
2020-06-24 18:46:03 -04:00
|
|
|
loading.Progress(0.3)
|
2020-02-08 21:02:37 -05:00
|
|
|
|
2020-07-07 20:16:22 -04:00
|
|
|
v.copyrightLabel2 = d2ui.CreateLabel(d2resource.FontFormal12, d2resource.PaletteStatic)
|
2020-07-11 11:24:04 -04:00
|
|
|
v.copyrightLabel2.Alignment = d2gui.HorizontalAlignCenter
|
2020-06-20 15:14:52 -04:00
|
|
|
v.copyrightLabel2.SetText("All Rights Reserved.")
|
2020-02-08 21:02:37 -05:00
|
|
|
v.copyrightLabel2.Color = color.RGBA{R: 188, G: 168, B: 140, A: 255}
|
|
|
|
v.copyrightLabel2.SetPosition(400, 525)
|
|
|
|
|
2020-07-07 20:16:22 -04:00
|
|
|
v.openDiabloLabel = d2ui.CreateLabel(d2resource.FontFormal10, d2resource.PaletteStatic)
|
|
|
|
v.openDiabloLabel.Alignment = d2gui.HorizontalAlignCenter
|
2020-02-08 21:02:37 -05:00
|
|
|
v.openDiabloLabel.SetText("OpenDiablo2 is neither developed by, nor endorsed by Blizzard or its parent company Activision")
|
|
|
|
v.openDiabloLabel.Color = color.RGBA{R: 255, G: 255, B: 140, A: 255}
|
|
|
|
v.openDiabloLabel.SetPosition(400, 580)
|
2020-06-24 18:46:03 -04:00
|
|
|
loading.Progress(0.5)
|
2020-02-08 21:02:37 -05:00
|
|
|
|
2020-07-07 20:16:22 -04:00
|
|
|
v.tcpIPOptionsLabel = d2ui.CreateLabel(d2resource.Font42, d2resource.PaletteUnits)
|
2020-07-02 13:55:43 -04:00
|
|
|
v.tcpIPOptionsLabel.SetPosition(400, 23)
|
2020-07-07 20:16:22 -04:00
|
|
|
v.tcpIPOptionsLabel.Alignment = d2gui.HorizontalAlignCenter
|
2020-07-02 13:55:43 -04:00
|
|
|
v.tcpIPOptionsLabel.SetText("TCP/IP Options")
|
2020-02-08 21:02:37 -05:00
|
|
|
|
2020-07-07 20:16:22 -04:00
|
|
|
v.tcpJoinGameLabel = d2ui.CreateLabel(d2resource.Font16, d2resource.PaletteUnits)
|
|
|
|
v.tcpJoinGameLabel.Alignment = d2gui.HorizontalAlignCenter
|
|
|
|
v.tcpJoinGameLabel.SetText("Enter Host IP Address\nto Join Game")
|
2020-02-08 21:02:37 -05:00
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
v.tcpJoinGameLabel.Color = color.RGBA{R: 216, G: 196, B: 128, A: 255}
|
|
|
|
v.tcpJoinGameLabel.SetPosition(400, 190)
|
|
|
|
}
|
2020-06-18 14:11:04 -04:00
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
func (v *MainMenu) createLogos(loading d2screen.LoadingState) {
|
|
|
|
animation, _ := d2asset.LoadAnimation(d2resource.Diablo2LogoFireLeft, d2resource.PaletteUnits)
|
2020-02-08 21:02:37 -05:00
|
|
|
v.diabloLogoLeft, _ = d2ui.LoadSprite(animation)
|
2020-07-08 21:57:35 -04:00
|
|
|
v.diabloLogoLeft.SetEffect(d2enum.DrawEffectModulate)
|
2020-02-08 21:02:37 -05:00
|
|
|
v.diabloLogoLeft.PlayForward()
|
|
|
|
v.diabloLogoLeft.SetPosition(400, 120)
|
2020-06-24 18:46:03 -04:00
|
|
|
loading.Progress(0.6)
|
2020-02-08 21:02:37 -05:00
|
|
|
|
|
|
|
animation, _ = d2asset.LoadAnimation(d2resource.Diablo2LogoFireRight, d2resource.PaletteUnits)
|
|
|
|
v.diabloLogoRight, _ = d2ui.LoadSprite(animation)
|
2020-07-08 21:57:35 -04:00
|
|
|
v.diabloLogoRight.SetEffect(d2enum.DrawEffectModulate)
|
2020-02-08 21:02:37 -05:00
|
|
|
v.diabloLogoRight.PlayForward()
|
|
|
|
v.diabloLogoRight.SetPosition(400, 120)
|
|
|
|
|
|
|
|
animation, _ = d2asset.LoadAnimation(d2resource.Diablo2LogoBlackLeft, d2resource.PaletteUnits)
|
|
|
|
v.diabloLogoLeftBack, _ = d2ui.LoadSprite(animation)
|
|
|
|
v.diabloLogoLeftBack.SetPosition(400, 120)
|
|
|
|
|
|
|
|
animation, _ = d2asset.LoadAnimation(d2resource.Diablo2LogoBlackRight, d2resource.PaletteUnits)
|
|
|
|
v.diabloLogoRightBack, _ = d2ui.LoadSprite(animation)
|
|
|
|
v.diabloLogoRightBack.SetPosition(400, 120)
|
2020-07-02 13:55:43 -04:00
|
|
|
}
|
2020-02-08 21:02:37 -05:00
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
func (v *MainMenu) createButtons(loading d2screen.LoadingState) {
|
2020-07-03 14:00:56 -04:00
|
|
|
v.exitDiabloButton = d2ui.CreateButton(v.renderer, d2ui.ButtonTypeWide, "EXIT DIABLO II")
|
2020-02-08 21:02:37 -05:00
|
|
|
v.exitDiabloButton.SetPosition(264, 535)
|
|
|
|
v.exitDiabloButton.OnActivated(func() { v.onExitButtonClicked() })
|
|
|
|
d2ui.AddWidget(&v.exitDiabloButton)
|
|
|
|
|
2020-07-03 14:00:56 -04:00
|
|
|
v.creditsButton = d2ui.CreateButton(v.renderer, d2ui.ButtonTypeShort, "CREDITS")
|
2020-02-08 21:02:37 -05:00
|
|
|
v.creditsButton.SetPosition(264, 505)
|
|
|
|
v.creditsButton.OnActivated(func() { v.onCreditsButtonClicked() })
|
|
|
|
d2ui.AddWidget(&v.creditsButton)
|
|
|
|
|
2020-07-03 14:00:56 -04:00
|
|
|
v.cinematicsButton = d2ui.CreateButton(v.renderer, d2ui.ButtonTypeShort, "CINEMATICS")
|
2020-02-08 21:02:37 -05:00
|
|
|
v.cinematicsButton.SetPosition(401, 505)
|
|
|
|
d2ui.AddWidget(&v.cinematicsButton)
|
2020-06-24 18:46:03 -04:00
|
|
|
loading.Progress(0.7)
|
2020-02-08 21:02:37 -05:00
|
|
|
|
2020-07-03 14:00:56 -04:00
|
|
|
v.singlePlayerButton = d2ui.CreateButton(v.renderer, d2ui.ButtonTypeWide, "SINGLE PLAYER")
|
2020-02-08 21:02:37 -05:00
|
|
|
v.singlePlayerButton.SetPosition(264, 290)
|
|
|
|
v.singlePlayerButton.OnActivated(func() { v.onSinglePlayerClicked() })
|
|
|
|
d2ui.AddWidget(&v.singlePlayerButton)
|
|
|
|
|
2020-07-03 14:00:56 -04:00
|
|
|
v.githubButton = d2ui.CreateButton(v.renderer, d2ui.ButtonTypeWide, "PROJECT WEBSITE")
|
2020-06-18 14:11:04 -04:00
|
|
|
v.githubButton.SetPosition(264, 400)
|
2020-02-08 21:02:37 -05:00
|
|
|
v.githubButton.OnActivated(func() { v.onGithubButtonClicked() })
|
|
|
|
d2ui.AddWidget(&v.githubButton)
|
|
|
|
|
2020-07-03 14:00:56 -04:00
|
|
|
v.mapTestButton = d2ui.CreateButton(v.renderer, d2ui.ButtonTypeWide, "MAP ENGINE TEST")
|
2020-06-18 14:11:04 -04:00
|
|
|
v.mapTestButton.SetPosition(264, 440)
|
2020-02-08 21:02:37 -05:00
|
|
|
v.mapTestButton.OnActivated(func() { v.onMapTestClicked() })
|
|
|
|
d2ui.AddWidget(&v.mapTestButton)
|
2020-06-18 14:11:04 -04:00
|
|
|
|
2020-07-03 14:00:56 -04:00
|
|
|
v.btnTCPIPCancel = d2ui.CreateButton(v.renderer, d2ui.ButtonTypeMedium, d2common.TranslateString("cancel"))
|
2020-07-02 13:55:43 -04:00
|
|
|
v.btnTCPIPCancel.SetPosition(33, 543)
|
|
|
|
v.btnTCPIPCancel.OnActivated(func() { v.onTCPIPCancelClicked() })
|
|
|
|
d2ui.AddWidget(&v.btnTCPIPCancel)
|
2020-06-18 14:11:04 -04:00
|
|
|
|
2020-07-03 14:00:56 -04:00
|
|
|
v.btnServerIPCancel = d2ui.CreateButton(v.renderer, d2ui.ButtonTypeOkCancel, "CANCEL")
|
2020-07-02 13:55:43 -04:00
|
|
|
v.btnServerIPCancel.SetPosition(285, 305)
|
|
|
|
v.btnServerIPCancel.OnActivated(func() { v.onBtnTCPIPCancelClicked() })
|
|
|
|
d2ui.AddWidget(&v.btnServerIPCancel)
|
2020-06-18 14:11:04 -04:00
|
|
|
|
2020-07-03 14:00:56 -04:00
|
|
|
v.btnServerIPOk = d2ui.CreateButton(v.renderer, d2ui.ButtonTypeOkCancel, "OK")
|
2020-07-02 13:55:43 -04:00
|
|
|
v.btnServerIPOk.SetPosition(420, 305)
|
|
|
|
v.btnServerIPOk.OnActivated(func() { v.onBtnTCPIPOkClicked() })
|
|
|
|
d2ui.AddWidget(&v.btnServerIPOk)
|
2020-06-18 14:11:04 -04:00
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
v.createMultiplayerMenuButtons()
|
2020-06-24 18:46:03 -04:00
|
|
|
loading.Progress(0.8)
|
2020-07-02 13:55:43 -04:00
|
|
|
}
|
2020-06-18 14:11:04 -04:00
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
func (v *MainMenu) createMultiplayerMenuButtons() {
|
2020-07-03 14:00:56 -04:00
|
|
|
v.multiplayerButton = d2ui.CreateButton(v.renderer, d2ui.ButtonTypeWide, "MULTIPLAYER")
|
2020-07-02 13:55:43 -04:00
|
|
|
v.multiplayerButton.SetPosition(264, 330)
|
|
|
|
v.multiplayerButton.OnActivated(func() { v.onMultiplayerClicked() })
|
|
|
|
d2ui.AddWidget(&v.multiplayerButton)
|
2020-06-18 14:11:04 -04:00
|
|
|
|
2020-07-03 14:00:56 -04:00
|
|
|
v.networkTCPIPButton = d2ui.CreateButton(v.renderer, d2ui.ButtonTypeWide, "TCP/IP GAME")
|
2020-07-02 13:55:43 -04:00
|
|
|
v.networkTCPIPButton.SetPosition(264, 280)
|
|
|
|
v.networkTCPIPButton.OnActivated(func() { v.onNetworkTCPIPClicked() })
|
|
|
|
d2ui.AddWidget(&v.networkTCPIPButton)
|
2020-06-18 14:11:04 -04:00
|
|
|
|
2020-07-03 14:00:56 -04:00
|
|
|
v.networkCancelButton = d2ui.CreateButton(v.renderer, d2ui.ButtonTypeWide, d2common.TranslateString("cancel"))
|
2020-07-02 13:55:43 -04:00
|
|
|
v.networkCancelButton.SetPosition(264, 540)
|
|
|
|
v.networkCancelButton.OnActivated(func() { v.onNetworkCancelClicked() })
|
|
|
|
d2ui.AddWidget(&v.networkCancelButton)
|
2020-06-18 14:11:04 -04:00
|
|
|
|
2020-07-03 14:00:56 -04:00
|
|
|
v.btnTCPIPHostGame = d2ui.CreateButton(v.renderer, d2ui.ButtonTypeWide, "HOST GAME")
|
2020-07-02 13:55:43 -04:00
|
|
|
v.btnTCPIPHostGame.SetPosition(264, 280)
|
|
|
|
v.btnTCPIPHostGame.OnActivated(func() { v.onTCPIPHostGameClicked() })
|
|
|
|
d2ui.AddWidget(&v.btnTCPIPHostGame)
|
2020-06-18 14:11:04 -04:00
|
|
|
|
2020-07-03 14:00:56 -04:00
|
|
|
v.btnTCPIPJoinGame = d2ui.CreateButton(v.renderer, d2ui.ButtonTypeWide, "JOIN GAME")
|
2020-07-02 13:55:43 -04:00
|
|
|
v.btnTCPIPJoinGame.SetPosition(264, 320)
|
|
|
|
v.btnTCPIPJoinGame.OnActivated(func() { v.onTCPIPJoinGameClicked() })
|
|
|
|
d2ui.AddWidget(&v.btnTCPIPJoinGame)
|
|
|
|
}
|
2020-06-18 14:11:04 -04:00
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
func (v *MainMenu) onMapTestClicked() {
|
2020-07-13 20:29:17 -04:00
|
|
|
d2screen.SetNextScreen(CreateMapEngineTest(0, 1, v.terminal, v.renderer, v.inputManager))
|
2020-07-02 13:55:43 -04:00
|
|
|
}
|
2020-06-18 14:11:04 -04:00
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
func (v *MainMenu) onSinglePlayerClicked() {
|
|
|
|
// Go here only if existing characters are available to select
|
|
|
|
if d2player.HasGameStates() {
|
2020-07-13 20:29:17 -04:00
|
|
|
d2screen.SetNextScreen(CreateCharacterSelect(v.renderer, v.inputManager, v.audioProvider, d2clientconnectiontype.Local,
|
2020-07-11 11:24:04 -04:00
|
|
|
v.tcpJoinGameEntry.GetText(), v.terminal, v.scriptEngine))
|
2020-07-02 13:55:43 -04:00
|
|
|
return
|
2020-06-18 14:11:04 -04:00
|
|
|
}
|
2020-06-23 18:12:08 -04:00
|
|
|
|
2020-07-13 20:29:17 -04:00
|
|
|
d2screen.SetNextScreen(CreateSelectHeroClass(v.renderer, v.inputManager, v.audioProvider,
|
2020-07-11 11:24:04 -04:00
|
|
|
d2clientconnectiontype.Local, v.tcpJoinGameEntry.GetText(), v.terminal, v.scriptEngine))
|
2019-10-24 09:31:59 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
func (v *MainMenu) onGithubButtonClicked() {
|
|
|
|
url := "https://www.github.com/OpenDiablo2/OpenDiablo2"
|
2019-10-27 19:00:38 -04:00
|
|
|
|
2019-10-26 12:55:36 -04:00
|
|
|
var err error
|
|
|
|
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "linux":
|
|
|
|
err = exec.Command("xdg-open", url).Start()
|
|
|
|
case "windows":
|
|
|
|
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
|
|
|
|
case "darwin":
|
|
|
|
err = exec.Command("open", url).Start()
|
|
|
|
default:
|
|
|
|
err = fmt.Errorf("unsupported platform")
|
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2019-10-26 12:55:36 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-25 23:41:54 -04:00
|
|
|
func (v *MainMenu) onExitButtonClicked() {
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2019-10-26 00:26:48 -04:00
|
|
|
func (v *MainMenu) onCreditsButtonClicked() {
|
2020-07-13 20:29:17 -04:00
|
|
|
d2screen.SetNextScreen(CreateCredits(v.renderer, v.inputManager, v.audioProvider, v.scriptEngine))
|
2019-10-26 00:26:48 -04:00
|
|
|
}
|
|
|
|
|
2019-10-25 18:40:27 -04:00
|
|
|
// Render renders the main menu
|
2020-06-29 00:41:58 -04:00
|
|
|
func (v *MainMenu) Render(screen d2interface.Surface) error {
|
2020-07-02 13:55:43 -04:00
|
|
|
if err := v.renderBackgrounds(screen); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := v.renderLogos(screen); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := v.renderLabels(screen); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *MainMenu) renderBackgrounds(screen d2interface.Surface) error {
|
2020-06-18 14:11:04 -04:00
|
|
|
switch v.screenMode {
|
2020-07-02 13:55:43 -04:00
|
|
|
case screenModeTrademark:
|
|
|
|
if err := v.trademarkBackground.RenderSegmented(screen, 4, 3, 0); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
case screenModeServerIP:
|
|
|
|
if err := v.serverIPBackground.RenderSegmented(screen, 2, 1, 0); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
case screenModeTCPIP:
|
|
|
|
if err := v.tcpIPBackground.RenderSegmented(screen, 4, 3, 0); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-06-18 14:11:04 -04:00
|
|
|
default:
|
2020-07-02 13:55:43 -04:00
|
|
|
if err := v.background.RenderSegmented(screen, 4, 3, 0); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-10-24 09:31:59 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *MainMenu) renderLogos(screen d2interface.Surface) error {
|
2020-06-18 14:11:04 -04:00
|
|
|
switch v.screenMode {
|
2020-07-02 13:55:43 -04:00
|
|
|
case screenModeTrademark, screenModeMainMenu, screenModeMultiplayer:
|
|
|
|
if err := v.diabloLogoLeftBack.Render(screen); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := v.diabloLogoRightBack.Render(screen); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := v.diabloLogoLeft.Render(screen); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := v.diabloLogoRight.Render(screen); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-06-18 14:11:04 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *MainMenu) renderLabels(screen d2interface.Surface) error {
|
2020-06-18 14:11:04 -04:00
|
|
|
switch v.screenMode {
|
2020-07-02 13:55:43 -04:00
|
|
|
case screenModeServerIP:
|
|
|
|
v.tcpIPOptionsLabel.Render(screen)
|
2020-06-18 14:11:04 -04:00
|
|
|
v.tcpJoinGameLabel.Render(screen)
|
2020-07-02 13:55:43 -04:00
|
|
|
case screenModeTCPIP:
|
|
|
|
v.tcpIPOptionsLabel.Render(screen)
|
|
|
|
case screenModeTrademark:
|
2019-12-21 20:53:18 -05:00
|
|
|
v.copyrightLabel.Render(screen)
|
|
|
|
v.copyrightLabel2.Render(screen)
|
2020-07-02 13:55:43 -04:00
|
|
|
case screenModeMainMenu:
|
2019-12-21 20:53:18 -05:00
|
|
|
v.openDiabloLabel.Render(screen)
|
|
|
|
v.versionLabel.Render(screen)
|
|
|
|
v.commitLabel.Render(screen)
|
2019-10-24 09:31:59 -04:00
|
|
|
}
|
2020-02-08 21:02:37 -05:00
|
|
|
|
|
|
|
return nil
|
2019-10-24 09:31:59 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// Advance runs the update logic on the main menu
|
2020-02-08 21:02:37 -05:00
|
|
|
func (v *MainMenu) Advance(tickTime float64) error {
|
2020-06-18 14:11:04 -04:00
|
|
|
switch v.screenMode {
|
2020-07-02 13:55:43 -04:00
|
|
|
case screenModeMainMenu, screenModeTrademark, screenModeMultiplayer:
|
|
|
|
if err := v.diabloLogoLeftBack.Advance(tickTime); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := v.diabloLogoRightBack.Advance(tickTime); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := v.diabloLogoLeft.Advance(tickTime); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := v.diabloLogoRight.Advance(tickTime); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-06-18 14:11:04 -04:00
|
|
|
}
|
2019-12-28 23:32:24 -05:00
|
|
|
|
2020-02-08 21:02:37 -05:00
|
|
|
return nil
|
2019-10-24 09:31:59 -04:00
|
|
|
}
|
2020-06-18 14:11:04 -04:00
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// OnMouseButtonDown is called when a mouse button is clicked
|
2020-07-03 15:09:16 -04:00
|
|
|
func (v *MainMenu) OnMouseButtonDown(event d2interface.MouseEvent) bool {
|
2020-07-06 21:26:08 -04:00
|
|
|
if v.screenMode == screenModeTrademark && event.Button() == d2enum.MouseButtonLeft {
|
2020-07-02 13:55:43 -04:00
|
|
|
v.setScreenMode(screenModeMainMenu)
|
2020-06-23 18:12:08 -04:00
|
|
|
return true
|
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-06-23 18:12:08 -04:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
func (v *MainMenu) setScreenMode(screenMode mainMenuScreenMode) {
|
2020-06-18 14:11:04 -04:00
|
|
|
v.screenMode = screenMode
|
2020-07-02 13:55:43 -04:00
|
|
|
isMainMenu := screenMode == screenModeMainMenu
|
|
|
|
isMultiplayer := screenMode == screenModeMultiplayer
|
|
|
|
isTCPIP := screenMode == screenModeTCPIP
|
|
|
|
isServerIP := screenMode == screenModeServerIP
|
|
|
|
|
2020-06-18 14:11:04 -04:00
|
|
|
v.exitDiabloButton.SetVisible(isMainMenu)
|
|
|
|
v.creditsButton.SetVisible(isMainMenu)
|
|
|
|
v.cinematicsButton.SetVisible(isMainMenu)
|
|
|
|
v.singlePlayerButton.SetVisible(isMainMenu)
|
|
|
|
v.githubButton.SetVisible(isMainMenu)
|
|
|
|
v.mapTestButton.SetVisible(isMainMenu)
|
|
|
|
v.multiplayerButton.SetVisible(isMainMenu)
|
2020-07-02 13:55:43 -04:00
|
|
|
v.networkTCPIPButton.SetVisible(isMultiplayer)
|
2020-06-18 14:11:04 -04:00
|
|
|
v.networkCancelButton.SetVisible(isMultiplayer)
|
2020-07-02 13:55:43 -04:00
|
|
|
v.btnTCPIPCancel.SetVisible(isTCPIP)
|
|
|
|
v.btnTCPIPHostGame.SetVisible(isTCPIP)
|
|
|
|
v.btnTCPIPJoinGame.SetVisible(isTCPIP)
|
|
|
|
v.tcpJoinGameEntry.SetVisible(isServerIP)
|
|
|
|
|
|
|
|
if isServerIP {
|
2020-06-23 18:12:08 -04:00
|
|
|
v.tcpJoinGameEntry.Activate()
|
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
|
|
|
v.btnServerIPOk.SetVisible(isServerIP)
|
|
|
|
v.btnServerIPCancel.SetVisible(isServerIP)
|
2020-06-18 14:11:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *MainMenu) onNetworkCancelClicked() {
|
2020-07-02 13:55:43 -04:00
|
|
|
v.setScreenMode(screenModeMainMenu)
|
2020-06-18 14:11:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *MainMenu) onMultiplayerClicked() {
|
2020-07-02 13:55:43 -04:00
|
|
|
v.setScreenMode(screenModeMultiplayer)
|
2020-06-18 14:11:04 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
func (v *MainMenu) onNetworkTCPIPClicked() {
|
|
|
|
v.setScreenMode(screenModeTCPIP)
|
2020-06-18 14:11:04 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
func (v *MainMenu) onTCPIPCancelClicked() {
|
|
|
|
v.setScreenMode(screenModeMultiplayer)
|
2020-06-18 14:11:04 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
func (v *MainMenu) onTCPIPHostGameClicked() {
|
2020-07-13 20:29:17 -04:00
|
|
|
d2screen.SetNextScreen(CreateCharacterSelect(v.renderer, v.inputManager, v.audioProvider,
|
2020-07-11 11:24:04 -04:00
|
|
|
d2clientconnectiontype.LANServer, "", v.terminal, v.scriptEngine))
|
2020-06-18 14:11:04 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
func (v *MainMenu) onTCPIPJoinGameClicked() {
|
|
|
|
v.setScreenMode(screenModeServerIP)
|
2020-06-18 14:11:04 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
func (v *MainMenu) onBtnTCPIPCancelClicked() {
|
|
|
|
v.setScreenMode(screenModeTCPIP)
|
2020-06-18 14:11:04 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
func (v *MainMenu) onBtnTCPIPOkClicked() {
|
2020-07-13 20:29:17 -04:00
|
|
|
d2screen.SetNextScreen(CreateCharacterSelect(v.renderer, v.inputManager, v.audioProvider,
|
2020-07-11 11:24:04 -04:00
|
|
|
d2clientconnectiontype.LANClient, v.tcpJoinGameEntry.GetText(), v.terminal, v.scriptEngine))
|
2020-06-18 14:11:04 -04:00
|
|
|
}
|