2019-11-06 22:12:15 -05:00
|
|
|
package scenes
|
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
|
|
|
|
2019-11-06 22:12:15 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/common"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/palettedefs"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/sound"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/ui"
|
2019-10-25 18:40:27 -04:00
|
|
|
|
2019-11-06 22:12:15 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/resourcepaths"
|
2019-10-24 09:31:59 -04:00
|
|
|
"github.com/hajimehoshi/ebiten"
|
|
|
|
)
|
|
|
|
|
2019-10-25 18:40:27 -04:00
|
|
|
// MainMenu represents the main menu
|
2019-10-24 09:31:59 -04:00
|
|
|
type MainMenu struct {
|
2019-11-06 22:12:15 -05:00
|
|
|
uiManager *ui.Manager
|
|
|
|
soundManager *sound.Manager
|
|
|
|
fileProvider common.FileProvider
|
2019-10-26 00:26:48 -04:00
|
|
|
sceneProvider SceneProvider
|
2019-11-06 22:12:15 -05:00
|
|
|
trademarkBackground *common.Sprite
|
|
|
|
background *common.Sprite
|
|
|
|
diabloLogoLeft *common.Sprite
|
|
|
|
diabloLogoRight *common.Sprite
|
|
|
|
diabloLogoLeftBack *common.Sprite
|
|
|
|
diabloLogoRightBack *common.Sprite
|
|
|
|
singlePlayerButton *ui.Button
|
|
|
|
githubButton *ui.Button
|
|
|
|
exitDiabloButton *ui.Button
|
|
|
|
creditsButton *ui.Button
|
|
|
|
cinematicsButton *ui.Button
|
|
|
|
mapTestButton *ui.Button
|
|
|
|
copyrightLabel *ui.Label
|
|
|
|
copyrightLabel2 *ui.Label
|
|
|
|
openDiabloLabel *ui.Label
|
|
|
|
versionLabel *ui.Label
|
|
|
|
commitLabel *ui.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
|
2019-11-06 22:12:15 -05:00
|
|
|
func CreateMainMenu(fileProvider common.FileProvider, sceneProvider SceneProvider, uiManager *ui.Manager, soundManager *sound.Manager) *MainMenu {
|
2019-10-24 09:31:59 -04:00
|
|
|
result := &MainMenu{
|
2019-10-25 20:28:14 -04:00
|
|
|
fileProvider: fileProvider,
|
|
|
|
uiManager: uiManager,
|
|
|
|
soundManager: soundManager,
|
2019-10-26 00:26:48 -04:00
|
|
|
sceneProvider: sceneProvider,
|
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
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2019-10-25 18:40:27 -04:00
|
|
|
// Load is called to load the resources for the main menu
|
2019-10-25 20:28:14 -04:00
|
|
|
func (v *MainMenu) Load() []func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.soundManager.PlayBGM(resourcepaths.BGMTitle)
|
2019-10-25 20:28:14 -04:00
|
|
|
return []func(){
|
2019-11-02 16:15:16 -04:00
|
|
|
func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.versionLabel = ui.CreateLabel(v.fileProvider, resourcepaths.FontFormal12, palettedefs.Static)
|
|
|
|
v.versionLabel.Alignment = ui.LabelAlignRight
|
|
|
|
v.versionLabel.SetText("OpenDiablo2 - " + common.BuildInfo.Branch)
|
2019-11-02 16:15:16 -04:00
|
|
|
v.versionLabel.Color = color.RGBA{255, 255, 255, 255}
|
|
|
|
v.versionLabel.MoveTo(795, -10)
|
|
|
|
},
|
|
|
|
func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.commitLabel = ui.CreateLabel(v.fileProvider, resourcepaths.FontFormal10, palettedefs.Static)
|
|
|
|
v.commitLabel.Alignment = ui.LabelAlignLeft
|
|
|
|
v.commitLabel.SetText(common.BuildInfo.Commit)
|
2019-11-02 16:15:16 -04:00
|
|
|
v.commitLabel.Color = color.RGBA{255, 255, 255, 255}
|
|
|
|
v.commitLabel.MoveTo(2, 2)
|
|
|
|
},
|
2019-10-25 20:28:14 -04:00
|
|
|
func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.copyrightLabel = ui.CreateLabel(v.fileProvider, resourcepaths.FontFormal12, palettedefs.Static)
|
|
|
|
v.copyrightLabel.Alignment = ui.LabelAlignCenter
|
2019-10-25 18:40:27 -04:00
|
|
|
v.copyrightLabel.SetText("Diablo 2 is © Copyright 2000-2016 Blizzard Entertainment")
|
2019-10-25 22:20:36 -04:00
|
|
|
v.copyrightLabel.Color = color.RGBA{188, 168, 140, 255}
|
2019-10-25 18:40:27 -04:00
|
|
|
v.copyrightLabel.MoveTo(400, 500)
|
2019-10-25 20:28:14 -04:00
|
|
|
},
|
|
|
|
func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.copyrightLabel2 = ui.CreateLabel(v.fileProvider, resourcepaths.FontFormal12, palettedefs.Static)
|
|
|
|
v.copyrightLabel2.Alignment = ui.LabelAlignCenter
|
|
|
|
v.copyrightLabel2.SetText(common.TranslateString("#1614"))
|
2019-10-25 22:20:36 -04:00
|
|
|
v.copyrightLabel2.Color = color.RGBA{188, 168, 140, 255}
|
2019-10-25 18:40:27 -04:00
|
|
|
v.copyrightLabel2.MoveTo(400, 525)
|
2019-10-25 20:28:14 -04:00
|
|
|
},
|
2019-10-26 12:55:36 -04:00
|
|
|
func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.openDiabloLabel = ui.CreateLabel(v.fileProvider, resourcepaths.FontFormal10, palettedefs.Static)
|
|
|
|
v.openDiabloLabel.Alignment = ui.LabelAlignCenter
|
2019-10-26 12:55:36 -04:00
|
|
|
v.openDiabloLabel.SetText("OpenDiablo2 is neither developed by, nor endorsed by Blizzard or its parent company Activision")
|
|
|
|
v.openDiabloLabel.Color = color.RGBA{255, 255, 140, 255}
|
|
|
|
v.openDiabloLabel.MoveTo(400, 580)
|
|
|
|
},
|
2019-10-25 20:28:14 -04:00
|
|
|
func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.background = v.fileProvider.LoadSprite(resourcepaths.GameSelectScreen, palettedefs.Sky)
|
2019-10-25 18:40:27 -04:00
|
|
|
v.background.MoveTo(0, 0)
|
2019-10-25 20:28:14 -04:00
|
|
|
},
|
|
|
|
func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.trademarkBackground = v.fileProvider.LoadSprite(resourcepaths.TrademarkScreen, palettedefs.Sky)
|
2019-10-25 18:40:27 -04:00
|
|
|
v.trademarkBackground.MoveTo(0, 0)
|
2019-10-25 20:28:14 -04:00
|
|
|
},
|
|
|
|
func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.diabloLogoLeft = v.fileProvider.LoadSprite(resourcepaths.Diablo2LogoFireLeft, palettedefs.Units)
|
2019-10-25 18:40:27 -04:00
|
|
|
v.diabloLogoLeft.Blend = true
|
|
|
|
v.diabloLogoLeft.Animate = true
|
|
|
|
v.diabloLogoLeft.MoveTo(400, 120)
|
2019-10-25 20:28:14 -04:00
|
|
|
},
|
|
|
|
func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.diabloLogoRight = v.fileProvider.LoadSprite(resourcepaths.Diablo2LogoFireRight, palettedefs.Units)
|
2019-10-25 18:40:27 -04:00
|
|
|
v.diabloLogoRight.Blend = true
|
|
|
|
v.diabloLogoRight.Animate = true
|
|
|
|
v.diabloLogoRight.MoveTo(400, 120)
|
2019-10-25 20:28:14 -04:00
|
|
|
},
|
|
|
|
func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.diabloLogoLeftBack = v.fileProvider.LoadSprite(resourcepaths.Diablo2LogoBlackLeft, palettedefs.Units)
|
2019-10-25 18:40:27 -04:00
|
|
|
v.diabloLogoLeftBack.MoveTo(400, 120)
|
2019-10-25 20:28:14 -04:00
|
|
|
},
|
|
|
|
func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.diabloLogoRightBack = v.fileProvider.LoadSprite(resourcepaths.Diablo2LogoBlackRight, palettedefs.Units)
|
2019-10-25 18:40:27 -04:00
|
|
|
v.diabloLogoRightBack.MoveTo(400, 120)
|
2019-10-25 20:28:14 -04:00
|
|
|
},
|
2019-10-25 22:20:36 -04:00
|
|
|
func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.exitDiabloButton = ui.CreateButton(ui.ButtonTypeWide, v.fileProvider, common.TranslateString("#1625"))
|
2019-10-25 22:20:36 -04:00
|
|
|
v.exitDiabloButton.MoveTo(264, 535)
|
2019-10-26 00:55:59 -04:00
|
|
|
v.exitDiabloButton.SetVisible(!v.ShowTrademarkScreen)
|
2019-10-25 23:41:54 -04:00
|
|
|
v.exitDiabloButton.OnActivated(func() { v.onExitButtonClicked() })
|
2019-10-25 22:20:36 -04:00
|
|
|
v.uiManager.AddWidget(v.exitDiabloButton)
|
|
|
|
},
|
2019-10-26 00:06:54 -04:00
|
|
|
func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.creditsButton = ui.CreateButton(ui.ButtonTypeShort, v.fileProvider, common.TranslateString("#1627"))
|
2019-10-26 00:06:54 -04:00
|
|
|
v.creditsButton.MoveTo(264, 505)
|
2019-10-26 00:55:59 -04:00
|
|
|
v.creditsButton.SetVisible(!v.ShowTrademarkScreen)
|
2019-10-26 00:26:48 -04:00
|
|
|
v.creditsButton.OnActivated(func() { v.onCreditsButtonClicked() })
|
2019-10-26 00:06:54 -04:00
|
|
|
v.uiManager.AddWidget(v.creditsButton)
|
|
|
|
},
|
2019-10-26 12:55:36 -04:00
|
|
|
func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.cinematicsButton = ui.CreateButton(ui.ButtonTypeShort, v.fileProvider, common.TranslateString("#1639"))
|
2019-10-26 12:55:36 -04:00
|
|
|
v.cinematicsButton.MoveTo(401, 505)
|
|
|
|
v.cinematicsButton.SetVisible(!v.ShowTrademarkScreen)
|
|
|
|
v.uiManager.AddWidget(v.cinematicsButton)
|
|
|
|
},
|
|
|
|
func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.singlePlayerButton = ui.CreateButton(ui.ButtonTypeWide, v.fileProvider, common.TranslateString("#1620"))
|
2019-10-26 12:55:36 -04:00
|
|
|
v.singlePlayerButton.MoveTo(264, 290)
|
|
|
|
v.singlePlayerButton.SetVisible(!v.ShowTrademarkScreen)
|
2019-10-26 23:59:27 -04:00
|
|
|
v.singlePlayerButton.OnActivated(func() { v.onSinglePlayerClicked() })
|
2019-10-26 12:55:36 -04:00
|
|
|
v.uiManager.AddWidget(v.singlePlayerButton)
|
|
|
|
},
|
|
|
|
func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.githubButton = ui.CreateButton(ui.ButtonTypeWide, v.fileProvider, "PROJECT WEBSITE")
|
2019-10-26 12:55:36 -04:00
|
|
|
v.githubButton.MoveTo(264, 330)
|
|
|
|
v.githubButton.SetVisible(!v.ShowTrademarkScreen)
|
|
|
|
v.githubButton.OnActivated(func() { v.onGithubButtonClicked() })
|
|
|
|
v.uiManager.AddWidget(v.githubButton)
|
|
|
|
},
|
2019-10-27 19:00:38 -04:00
|
|
|
func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.mapTestButton = ui.CreateButton(ui.ButtonTypeWide, v.fileProvider, "MAP ENGINE TEST")
|
2019-10-27 19:00:38 -04:00
|
|
|
v.mapTestButton.MoveTo(264, 450)
|
|
|
|
v.mapTestButton.SetVisible(!v.ShowTrademarkScreen)
|
|
|
|
v.mapTestButton.OnActivated(func() { v.onMapTestClicked() })
|
|
|
|
v.uiManager.AddWidget(v.mapTestButton)
|
|
|
|
},
|
2019-10-25 20:28:14 -04:00
|
|
|
}
|
2019-10-24 09:31:59 -04:00
|
|
|
}
|
|
|
|
|
2019-10-27 19:00:38 -04:00
|
|
|
func (v *MainMenu) onMapTestClicked() {
|
|
|
|
v.sceneProvider.SetNextScene(CreateMapEngineTest(v.fileProvider, v.sceneProvider, v.uiManager, v.soundManager))
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
//v.sceneProvider.SetNextScene(CreateCharacterSelect(v.fileProvider, v.sceneProvider, v.uiManager, v.soundManager))
|
|
|
|
v.sceneProvider.SetNextScene(CreateSelectHeroClass(v.fileProvider, v.sceneProvider, v.uiManager, v.soundManager))
|
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() {
|
|
|
|
v.sceneProvider.SetNextScene(CreateCredits(v.fileProvider, v.sceneProvider, v.uiManager, v.soundManager))
|
|
|
|
}
|
|
|
|
|
2019-10-25 18:40:27 -04:00
|
|
|
// Unload unloads the data for the main menu
|
2019-10-24 09:31:59 -04:00
|
|
|
func (v *MainMenu) Unload() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-10-25 18:40:27 -04:00
|
|
|
// Render renders the main menu
|
2019-10-24 09:31:59 -04:00
|
|
|
func (v *MainMenu) Render(screen *ebiten.Image) {
|
2019-10-26 00:55:59 -04:00
|
|
|
if v.ShowTrademarkScreen {
|
2019-10-25 18:40:27 -04:00
|
|
|
v.trademarkBackground.DrawSegments(screen, 4, 3, 0)
|
2019-10-24 09:31:59 -04:00
|
|
|
} else {
|
2019-10-25 18:40:27 -04:00
|
|
|
v.background.DrawSegments(screen, 4, 3, 0)
|
2019-10-24 09:31:59 -04:00
|
|
|
}
|
2019-10-25 18:40:27 -04:00
|
|
|
v.diabloLogoLeftBack.Draw(screen)
|
|
|
|
v.diabloLogoRightBack.Draw(screen)
|
|
|
|
v.diabloLogoLeft.Draw(screen)
|
|
|
|
v.diabloLogoRight.Draw(screen)
|
2019-10-24 09:31:59 -04:00
|
|
|
|
2019-10-26 00:55:59 -04:00
|
|
|
if v.ShowTrademarkScreen {
|
2019-10-25 18:40:27 -04:00
|
|
|
v.copyrightLabel.Draw(screen)
|
|
|
|
v.copyrightLabel2.Draw(screen)
|
2019-10-24 09:31:59 -04:00
|
|
|
} else {
|
2019-10-26 12:55:36 -04:00
|
|
|
v.openDiabloLabel.Draw(screen)
|
2019-11-02 16:15:16 -04:00
|
|
|
v.versionLabel.Draw(screen)
|
|
|
|
v.commitLabel.Draw(screen)
|
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
|
2019-10-26 02:11:28 -04:00
|
|
|
func (v *MainMenu) Update(tickTime float64) {
|
2019-10-26 00:55:59 -04:00
|
|
|
if v.ShowTrademarkScreen {
|
2019-11-06 22:12:15 -05:00
|
|
|
if v.uiManager.CursorButtonPressed(ui.CursorButtonLeft) {
|
2019-10-26 23:59:27 -04:00
|
|
|
if v.leftButtonHeld {
|
|
|
|
return
|
|
|
|
}
|
2019-10-27 19:00:38 -04:00
|
|
|
v.uiManager.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
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2019-10-24 09:31:59 -04:00
|
|
|
}
|