2020-02-01 18:55:56 -05:00
|
|
|
package d2gamescene
|
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"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
2019-11-11 23:48:55 -05:00
|
|
|
|
2020-02-08 21:02:37 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2audio"
|
2020-01-31 23:18:11 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gamestate"
|
2020-02-08 21:02:37 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
2020-02-01 18:55:56 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
|
2020-01-31 23:18:11 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
2019-10-24 09:31:59 -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-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
|
2019-11-10 12:28:41 -05:00
|
|
|
singlePlayerButton d2ui.Button
|
|
|
|
githubButton d2ui.Button
|
|
|
|
exitDiabloButton d2ui.Button
|
|
|
|
creditsButton d2ui.Button
|
|
|
|
cinematicsButton d2ui.Button
|
|
|
|
mapTestButton d2ui.Button
|
|
|
|
copyrightLabel d2ui.Label
|
|
|
|
copyrightLabel2 d2ui.Label
|
|
|
|
openDiabloLabel d2ui.Label
|
|
|
|
versionLabel d2ui.Label
|
|
|
|
commitLabel d2ui.Label
|
2019-10-26 20:09:33 -04:00
|
|
|
|
2019-10-26 00:55:59 -04:00
|
|
|
ShowTrademarkScreen bool
|
2019-10-25 18:40:27 -04:00
|
|
|
leftButtonHeld bool
|
2019-10-24 09:31:59 -04:00
|
|
|
}
|
|
|
|
|
2019-10-25 18:40:27 -04:00
|
|
|
// CreateMainMenu creates an instance of MainMenu
|
2020-01-31 23:18:11 -05:00
|
|
|
func CreateMainMenu() *MainMenu {
|
2020-02-08 21:02:37 -05:00
|
|
|
return &MainMenu{
|
2019-10-26 00:55:59 -04:00
|
|
|
ShowTrademarkScreen: true,
|
2019-10-26 23:59:27 -04:00
|
|
|
leftButtonHeld: true,
|
2019-10-24 09:31:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-25 18:40:27 -04:00
|
|
|
// Load is called to load the resources for the main menu
|
2020-02-08 21:02:37 -05:00
|
|
|
func (v *MainMenu) OnLoad() error {
|
2020-01-31 23:18:11 -05:00
|
|
|
d2audio.PlayBGM(d2resource.BGMTitle)
|
2020-02-08 21:02:37 -05:00
|
|
|
|
|
|
|
v.versionLabel = d2ui.CreateLabel(d2resource.FontFormal12, d2resource.PaletteStatic)
|
|
|
|
v.versionLabel.Alignment = d2ui.LabelAlignRight
|
|
|
|
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)
|
|
|
|
|
|
|
|
v.commitLabel = d2ui.CreateLabel(d2resource.FontFormal10, d2resource.PaletteStatic)
|
|
|
|
v.commitLabel.Alignment = d2ui.LabelAlignLeft
|
|
|
|
v.commitLabel.SetText(d2common.BuildInfo.Commit)
|
|
|
|
v.commitLabel.Color = color.RGBA{R: 255, G: 255, B: 255, A: 255}
|
|
|
|
v.commitLabel.SetPosition(2, 2)
|
|
|
|
|
|
|
|
v.copyrightLabel = d2ui.CreateLabel(d2resource.FontFormal12, d2resource.PaletteStatic)
|
|
|
|
v.copyrightLabel.Alignment = d2ui.LabelAlignCenter
|
|
|
|
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)
|
|
|
|
|
|
|
|
v.copyrightLabel2 = d2ui.CreateLabel(d2resource.FontFormal12, d2resource.PaletteStatic)
|
|
|
|
v.copyrightLabel2.Alignment = d2ui.LabelAlignCenter
|
|
|
|
v.copyrightLabel2.SetText(d2common.TranslateString("#1614"))
|
|
|
|
v.copyrightLabel2.Color = color.RGBA{R: 188, G: 168, B: 140, A: 255}
|
|
|
|
v.copyrightLabel2.SetPosition(400, 525)
|
|
|
|
|
|
|
|
v.openDiabloLabel = d2ui.CreateLabel(d2resource.FontFormal10, d2resource.PaletteStatic)
|
|
|
|
v.openDiabloLabel.Alignment = d2ui.LabelAlignCenter
|
|
|
|
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)
|
|
|
|
|
|
|
|
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.Diablo2LogoFireLeft, d2resource.PaletteUnits)
|
|
|
|
v.diabloLogoLeft, _ = d2ui.LoadSprite(animation)
|
|
|
|
v.diabloLogoLeft.SetBlend(true)
|
|
|
|
v.diabloLogoLeft.PlayForward()
|
|
|
|
v.diabloLogoLeft.SetPosition(400, 120)
|
|
|
|
|
|
|
|
animation, _ = d2asset.LoadAnimation(d2resource.Diablo2LogoFireRight, d2resource.PaletteUnits)
|
|
|
|
v.diabloLogoRight, _ = d2ui.LoadSprite(animation)
|
|
|
|
v.diabloLogoRight.SetBlend(true)
|
|
|
|
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)
|
|
|
|
|
|
|
|
v.exitDiabloButton = d2ui.CreateButton(d2ui.ButtonTypeWide, d2common.TranslateString("#1625"))
|
|
|
|
v.exitDiabloButton.SetPosition(264, 535)
|
|
|
|
v.exitDiabloButton.SetVisible(!v.ShowTrademarkScreen)
|
|
|
|
v.exitDiabloButton.OnActivated(func() { v.onExitButtonClicked() })
|
|
|
|
d2ui.AddWidget(&v.exitDiabloButton)
|
|
|
|
|
|
|
|
v.creditsButton = d2ui.CreateButton(d2ui.ButtonTypeShort, d2common.TranslateString("#1627"))
|
|
|
|
v.creditsButton.SetPosition(264, 505)
|
|
|
|
v.creditsButton.SetVisible(!v.ShowTrademarkScreen)
|
|
|
|
v.creditsButton.OnActivated(func() { v.onCreditsButtonClicked() })
|
|
|
|
d2ui.AddWidget(&v.creditsButton)
|
|
|
|
|
|
|
|
v.cinematicsButton = d2ui.CreateButton(d2ui.ButtonTypeShort, d2common.TranslateString("#1639"))
|
|
|
|
v.cinematicsButton.SetPosition(401, 505)
|
|
|
|
v.cinematicsButton.SetVisible(!v.ShowTrademarkScreen)
|
|
|
|
d2ui.AddWidget(&v.cinematicsButton)
|
|
|
|
|
|
|
|
v.singlePlayerButton = d2ui.CreateButton(d2ui.ButtonTypeWide, d2common.TranslateString("#1620"))
|
|
|
|
v.singlePlayerButton.SetPosition(264, 290)
|
|
|
|
v.singlePlayerButton.SetVisible(!v.ShowTrademarkScreen)
|
|
|
|
v.singlePlayerButton.OnActivated(func() { v.onSinglePlayerClicked() })
|
|
|
|
d2ui.AddWidget(&v.singlePlayerButton)
|
|
|
|
|
|
|
|
v.githubButton = d2ui.CreateButton(d2ui.ButtonTypeWide, "PROJECT WEBSITE")
|
|
|
|
v.githubButton.SetPosition(264, 330)
|
|
|
|
v.githubButton.SetVisible(!v.ShowTrademarkScreen)
|
|
|
|
v.githubButton.OnActivated(func() { v.onGithubButtonClicked() })
|
|
|
|
d2ui.AddWidget(&v.githubButton)
|
|
|
|
|
|
|
|
v.mapTestButton = d2ui.CreateButton(d2ui.ButtonTypeWide, "MAP ENGINE TEST")
|
|
|
|
v.mapTestButton.SetPosition(264, 450)
|
|
|
|
v.mapTestButton.SetVisible(!v.ShowTrademarkScreen)
|
|
|
|
v.mapTestButton.OnActivated(func() { v.onMapTestClicked() })
|
|
|
|
|
|
|
|
d2ui.AddWidget(&v.mapTestButton)
|
|
|
|
return nil
|
2019-10-24 09:31:59 -04:00
|
|
|
}
|
|
|
|
|
2019-10-27 19:00:38 -04:00
|
|
|
func (v *MainMenu) onMapTestClicked() {
|
2020-02-01 18:55:56 -05:00
|
|
|
d2scene.SetNextScene(CreateMapEngineTest(0, 1))
|
2019-10-27 19:00:38 -04:00
|
|
|
}
|
|
|
|
|
2019-10-26 12:55:36 -04:00
|
|
|
func openbrowser(url string) {
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-10-26 23:59:27 -04:00
|
|
|
func (v *MainMenu) onSinglePlayerClicked() {
|
2019-10-27 19:00:38 -04:00
|
|
|
// Go here only if existing characters are available to select
|
2020-01-31 23:18:11 -05:00
|
|
|
if d2gamestate.HasGameStates() {
|
2020-02-01 18:55:56 -05:00
|
|
|
d2scene.SetNextScene(CreateCharacterSelect())
|
2019-11-11 23:48:55 -05:00
|
|
|
return
|
|
|
|
}
|
2020-02-01 18:55:56 -05:00
|
|
|
d2scene.SetNextScene(CreateSelectHeroClass())
|
2019-10-26 23:59:27 -04:00
|
|
|
}
|
|
|
|
|
2019-10-26 12:55:36 -04:00
|
|
|
func (v *MainMenu) onGithubButtonClicked() {
|
2019-11-02 17:38:39 -04:00
|
|
|
openbrowser("https://www.github.com/OpenDiablo2/OpenDiablo2")
|
2019-10-26 12:55:36 -04:00
|
|
|
}
|
|
|
|
|
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-02-01 18:55:56 -05:00
|
|
|
d2scene.SetNextScene(CreateCredits())
|
2019-10-26 00:26:48 -04:00
|
|
|
}
|
|
|
|
|
2019-10-25 18:40:27 -04:00
|
|
|
// Render renders the main menu
|
2020-02-08 21:02:37 -05:00
|
|
|
func (v *MainMenu) Render(screen d2render.Surface) error {
|
2019-10-26 00:55:59 -04:00
|
|
|
if v.ShowTrademarkScreen {
|
2019-12-21 20:53:18 -05:00
|
|
|
v.trademarkBackground.RenderSegmented(screen, 4, 3, 0)
|
2019-10-24 09:31:59 -04:00
|
|
|
} else {
|
2019-12-21 20:53:18 -05:00
|
|
|
v.background.RenderSegmented(screen, 4, 3, 0)
|
2019-10-24 09:31:59 -04:00
|
|
|
}
|
2019-12-21 20:53:18 -05:00
|
|
|
v.diabloLogoLeftBack.Render(screen)
|
|
|
|
v.diabloLogoRightBack.Render(screen)
|
|
|
|
v.diabloLogoLeft.Render(screen)
|
|
|
|
v.diabloLogoRight.Render(screen)
|
2019-10-24 09:31:59 -04:00
|
|
|
|
2019-10-26 00:55:59 -04:00
|
|
|
if v.ShowTrademarkScreen {
|
2019-12-21 20:53:18 -05:00
|
|
|
v.copyrightLabel.Render(screen)
|
|
|
|
v.copyrightLabel2.Render(screen)
|
2019-10-24 09:31:59 -04:00
|
|
|
} else {
|
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
|
|
|
}
|
|
|
|
|
2019-10-25 18:40:27 -04:00
|
|
|
// Update runs the update logic on the main menu
|
2020-02-08 21:02:37 -05:00
|
|
|
func (v *MainMenu) Advance(tickTime float64) error {
|
2019-12-28 23:32:24 -05:00
|
|
|
v.diabloLogoLeftBack.Advance(tickTime)
|
|
|
|
v.diabloLogoRightBack.Advance(tickTime)
|
|
|
|
v.diabloLogoLeft.Advance(tickTime)
|
|
|
|
v.diabloLogoRight.Advance(tickTime)
|
|
|
|
|
2019-10-26 00:55:59 -04:00
|
|
|
if v.ShowTrademarkScreen {
|
2020-01-31 23:18:11 -05:00
|
|
|
if d2ui.CursorButtonPressed(d2ui.CursorButtonLeft) {
|
2019-10-26 23:59:27 -04:00
|
|
|
if v.leftButtonHeld {
|
2020-02-08 21:02:37 -05:00
|
|
|
return nil
|
2019-10-26 23:59:27 -04:00
|
|
|
}
|
2020-01-31 23:18:11 -05:00
|
|
|
d2ui.WaitForMouseRelease()
|
2019-10-25 18:40:27 -04:00
|
|
|
v.leftButtonHeld = true
|
2019-10-26 00:55:59 -04:00
|
|
|
v.ShowTrademarkScreen = false
|
2019-10-25 22:20:36 -04:00
|
|
|
v.exitDiabloButton.SetVisible(true)
|
2019-10-26 00:06:54 -04:00
|
|
|
v.creditsButton.SetVisible(true)
|
2019-10-26 12:55:36 -04:00
|
|
|
v.cinematicsButton.SetVisible(true)
|
|
|
|
v.singlePlayerButton.SetVisible(true)
|
|
|
|
v.githubButton.SetVisible(true)
|
2019-10-27 19:00:38 -04:00
|
|
|
v.mapTestButton.SetVisible(true)
|
2019-10-26 23:59:27 -04:00
|
|
|
} else {
|
|
|
|
v.leftButtonHeld = false
|
2019-10-25 15:06:47 -04:00
|
|
|
}
|
|
|
|
}
|
2020-02-08 21:02:37 -05:00
|
|
|
|
|
|
|
return nil
|
2019-10-24 09:31:59 -04:00
|
|
|
}
|