1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-02 09:17:19 -04:00
OpenDiablo2/SceneMainMenu.go

132 lines
3.7 KiB
Go
Raw Normal View History

2019-10-24 09:31:59 -04:00
package OpenDiablo2
import (
"image/color"
2019-10-25 19:12:42 -04:00
"github.com/essial/OpenDiablo2/Common"
"github.com/essial/OpenDiablo2/Palettes"
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"
)
// MainMenu represents the main menu
2019-10-24 09:31:59 -04:00
type MainMenu struct {
engine *Engine
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
copyrightLabel *UILabel
copyrightLabel2 *UILabel
showTrademarkScreen bool
leftButtonHeld bool
2019-10-24 09:31:59 -04:00
}
// CreateMainMenu creates an instance of MainMenu
2019-10-24 09:31:59 -04:00
func CreateMainMenu(engine *Engine) *MainMenu {
result := &MainMenu{
engine: engine,
showTrademarkScreen: true,
2019-10-24 09:31:59 -04:00
}
return result
}
// Load is called to load the resources for the main menu
2019-10-24 09:31:59 -04:00
func (v *MainMenu) Load() {
v.engine.PlayBGM(ResourcePaths.BGMTitle)
2019-10-24 09:31:59 -04:00
go func() {
loadStep := 1.0 / 8.0
v.engine.LoadingProgress = 0
{
v.copyrightLabel = CreateUILabel(v.engine, ResourcePaths.FontFormal12, Palettes.Static)
v.copyrightLabel.Alignment = UILabelAlignCenter
v.copyrightLabel.SetText("Diablo 2 is © Copyright 2000-2016 Blizzard Entertainment")
v.copyrightLabel.ColorMod = color.RGBA{188, 168, 140, 255}
v.copyrightLabel.MoveTo(400, 500)
v.engine.LoadingProgress += loadStep
}
{
v.copyrightLabel2 = CreateUILabel(v.engine, ResourcePaths.FontFormal12, Palettes.Static)
v.copyrightLabel2.Alignment = UILabelAlignCenter
v.copyrightLabel2.SetText("All Rights Reserved.")
v.copyrightLabel2.ColorMod = color.RGBA{188, 168, 140, 255}
v.copyrightLabel2.MoveTo(400, 525)
v.engine.LoadingProgress += loadStep
}
{
v.background = v.engine.LoadSprite(ResourcePaths.GameSelectScreen, Palettes.Sky)
v.background.MoveTo(0, 0)
v.engine.LoadingProgress += loadStep
}
{
v.trademarkBackground = v.engine.LoadSprite(ResourcePaths.TrademarkScreen, Palettes.Sky)
v.trademarkBackground.MoveTo(0, 0)
v.engine.LoadingProgress += loadStep
}
{
v.diabloLogoLeft = v.engine.LoadSprite(ResourcePaths.Diablo2LogoFireLeft, Palettes.Units)
v.diabloLogoLeft.Blend = true
v.diabloLogoLeft.Animate = true
v.diabloLogoLeft.MoveTo(400, 120)
v.engine.LoadingProgress += loadStep
}
{
v.diabloLogoRight = v.engine.LoadSprite(ResourcePaths.Diablo2LogoFireRight, Palettes.Units)
v.diabloLogoRight.Blend = true
v.diabloLogoRight.Animate = true
v.diabloLogoRight.MoveTo(400, 120)
v.engine.LoadingProgress += loadStep
}
{
v.diabloLogoLeftBack = v.engine.LoadSprite(ResourcePaths.Diablo2LogoBlackLeft, Palettes.Units)
v.diabloLogoLeftBack.MoveTo(400, 120)
v.engine.LoadingProgress += loadStep
}
{
v.diabloLogoRightBack = v.engine.LoadSprite(ResourcePaths.Diablo2LogoBlackRight, Palettes.Units)
v.diabloLogoRightBack.MoveTo(400, 120)
v.engine.LoadingProgress = 1.0
}
2019-10-24 09:31:59 -04:00
}()
}
// Unload unloads the data for the main menu
2019-10-24 09:31:59 -04:00
func (v *MainMenu) Unload() {
}
// Render renders the main menu
2019-10-24 09:31:59 -04:00
func (v *MainMenu) Render(screen *ebiten.Image) {
if v.showTrademarkScreen {
v.trademarkBackground.DrawSegments(screen, 4, 3, 0)
2019-10-24 09:31:59 -04:00
} else {
v.background.DrawSegments(screen, 4, 3, 0)
2019-10-24 09:31:59 -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
if v.showTrademarkScreen {
v.copyrightLabel.Draw(screen)
v.copyrightLabel2.Draw(screen)
2019-10-24 09:31:59 -04:00
} else {
}
}
// Update runs the update logic on the main menu
2019-10-24 09:31:59 -04:00
func (v *MainMenu) Update() {
if v.showTrademarkScreen {
if v.engine.CursorButtonPressed(CursorButtonLeft) {
v.leftButtonHeld = true
v.showTrademarkScreen = false
2019-10-25 15:06:47 -04:00
}
return
}
2019-10-24 09:31:59 -04:00
}