2019-10-25 20:28:14 -04:00
|
|
|
package Scenes
|
2019-10-24 09:31:59 -04:00
|
|
|
|
|
|
|
import (
|
2019-10-24 19:13:30 -04:00
|
|
|
"image/color"
|
2019-10-25 23:41:54 -04:00
|
|
|
"os"
|
2019-10-24 19:13:30 -04:00
|
|
|
|
2019-10-25 19:12:42 -04:00
|
|
|
"github.com/essial/OpenDiablo2/Common"
|
2019-10-25 18:40:27 -04:00
|
|
|
"github.com/essial/OpenDiablo2/Palettes"
|
2019-10-25 20:28:14 -04:00
|
|
|
"github.com/essial/OpenDiablo2/Sound"
|
2019-10-25 19:37:04 -04:00
|
|
|
"github.com/essial/OpenDiablo2/UI"
|
2019-10-25 18:40:27 -04:00
|
|
|
|
2019-10-24 11:26:07 -04:00
|
|
|
"github.com/essial/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-10-25 20:28:14 -04:00
|
|
|
uiManager *UI.Manager
|
|
|
|
soundManager *Sound.Manager
|
|
|
|
fileProvider Common.FileProvider
|
2019-10-26 00:26:48 -04:00
|
|
|
sceneProvider SceneProvider
|
2019-10-25 19:12:42 -04:00
|
|
|
trademarkBackground *Common.Sprite
|
|
|
|
background *Common.Sprite
|
|
|
|
diabloLogoLeft *Common.Sprite
|
|
|
|
diabloLogoRight *Common.Sprite
|
|
|
|
diabloLogoLeftBack *Common.Sprite
|
|
|
|
diabloLogoRightBack *Common.Sprite
|
2019-10-25 22:20:36 -04:00
|
|
|
exitDiabloButton *UI.Button
|
2019-10-26 00:06:54 -04:00
|
|
|
creditsButton *UI.Button
|
2019-10-25 19:37:04 -04:00
|
|
|
copyrightLabel *UI.Label
|
|
|
|
copyrightLabel2 *UI.Label
|
2019-10-25 18:40:27 -04:00
|
|
|
showTrademarkScreen bool
|
|
|
|
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-10-26 00:26:48 -04: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-25 18:40:27 -04:00
|
|
|
showTrademarkScreen: 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() {
|
|
|
|
v.soundManager.PlayBGM(ResourcePaths.BGMTitle)
|
|
|
|
return []func(){
|
|
|
|
func() {
|
|
|
|
v.copyrightLabel = UI.CreateLabel(v.fileProvider, ResourcePaths.FontFormal12, Palettes.Static)
|
2019-10-25 19:37:04 -04:00
|
|
|
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() {
|
|
|
|
v.copyrightLabel2 = UI.CreateLabel(v.fileProvider, ResourcePaths.FontFormal12, Palettes.Static)
|
2019-10-25 19:37:04 -04:00
|
|
|
v.copyrightLabel2.Alignment = UI.LabelAlignCenter
|
2019-10-25 18:40:27 -04:00
|
|
|
v.copyrightLabel2.SetText("All Rights Reserved.")
|
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
|
|
|
},
|
|
|
|
func() {
|
|
|
|
v.background = v.fileProvider.LoadSprite(ResourcePaths.GameSelectScreen, Palettes.Sky)
|
2019-10-25 18:40:27 -04:00
|
|
|
v.background.MoveTo(0, 0)
|
2019-10-25 20:28:14 -04:00
|
|
|
},
|
|
|
|
func() {
|
|
|
|
v.trademarkBackground = v.fileProvider.LoadSprite(ResourcePaths.TrademarkScreen, Palettes.Sky)
|
2019-10-25 18:40:27 -04:00
|
|
|
v.trademarkBackground.MoveTo(0, 0)
|
2019-10-25 20:28:14 -04:00
|
|
|
},
|
|
|
|
func() {
|
|
|
|
v.diabloLogoLeft = v.fileProvider.LoadSprite(ResourcePaths.Diablo2LogoFireLeft, Palettes.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() {
|
|
|
|
v.diabloLogoRight = v.fileProvider.LoadSprite(ResourcePaths.Diablo2LogoFireRight, Palettes.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() {
|
|
|
|
v.diabloLogoLeftBack = v.fileProvider.LoadSprite(ResourcePaths.Diablo2LogoBlackLeft, Palettes.Units)
|
2019-10-25 18:40:27 -04:00
|
|
|
v.diabloLogoLeftBack.MoveTo(400, 120)
|
2019-10-25 20:28:14 -04:00
|
|
|
},
|
|
|
|
func() {
|
|
|
|
v.diabloLogoRightBack = v.fileProvider.LoadSprite(ResourcePaths.Diablo2LogoBlackRight, Palettes.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-10-25 23:41:54 -04:00
|
|
|
v.exitDiabloButton = UI.CreateButton(UI.ButtonTypeWide, v.fileProvider, "EXIT DIABLO II")
|
2019-10-25 22:20:36 -04:00
|
|
|
v.exitDiabloButton.MoveTo(264, 535)
|
|
|
|
v.exitDiabloButton.SetVisible(false)
|
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() {
|
|
|
|
v.creditsButton = UI.CreateButton(UI.ButtonTypeShort, v.fileProvider, "CREDITS")
|
|
|
|
v.creditsButton.MoveTo(264, 505)
|
|
|
|
v.creditsButton.SetVisible(false)
|
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-25 20:28:14 -04:00
|
|
|
}
|
2019-10-24 09:31:59 -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-25 18:40:27 -04:00
|
|
|
if v.showTrademarkScreen {
|
|
|
|
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-25 18:40:27 -04:00
|
|
|
if v.showTrademarkScreen {
|
|
|
|
v.copyrightLabel.Draw(screen)
|
|
|
|
v.copyrightLabel2.Draw(screen)
|
2019-10-24 09:31:59 -04:00
|
|
|
} else {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-25 18:40:27 -04:00
|
|
|
// Update runs the update logic on the main menu
|
2019-10-24 09:31:59 -04:00
|
|
|
func (v *MainMenu) Update() {
|
2019-10-25 18:40:27 -04:00
|
|
|
if v.showTrademarkScreen {
|
2019-10-25 20:28:14 -04:00
|
|
|
if v.uiManager.CursorButtonPressed(UI.CursorButtonLeft) {
|
2019-10-25 18:40:27 -04:00
|
|
|
v.leftButtonHeld = true
|
|
|
|
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-25 15:06:47 -04:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2019-10-24 09:31:59 -04:00
|
|
|
}
|