1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-18 02:16:23 -05:00
OpenDiablo2/d2game/d2gamescreen/cinematics.go

192 lines
5.9 KiB
Go
Raw Normal View History

2020-11-09 12:51:38 -05:00
package d2gamescreen
import (
2020-11-10 01:59:17 -05:00
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2video"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
2020-11-09 12:51:38 -05:00
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
2020-11-09 12:51:38 -05:00
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2screen"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
)
const (
2020-11-10 01:59:17 -05:00
cinematicsX, cinematicsY = 240, 90
2020-11-10 05:40:39 -05:00
cinematicsLabelX, cinematicsLabelY = 400, 110
2020-11-10 01:59:17 -05:00
a1BtnX, a1BtnY = 264, 160
a2BtnX, a2BtnY = 264, 205
a3BtnX, a3BtnY = 264, 250
a4BtnX, a4BtnY = 264, 295
2020-11-09 14:42:13 -05:00
endCreditClassBtnX, endCreditClassBtnY = 264, 340
2020-11-10 01:59:17 -05:00
a5BtnX, a5BtnY = 264, 385
endCreditExpBtnX, endCreditExpBtnY = 264, 430
cinematicsExitBtnX, cinematicsExitBtnY = 340, 470
2020-11-09 12:51:38 -05:00
)
// CreateCinematics creates an instance of the credits screen
func CreateCinematics(
navigator d2interface.Navigator,
asset *d2asset.AssetManager,
renderer d2interface.Renderer,
aup d2interface.AudioProvider,
l d2util.LogLevel,
ui *d2ui.UIManager) *Cinematics {
cinematics := &Cinematics{
asset: asset,
renderer: renderer,
navigator: navigator,
uiManager: ui,
audioProvider: aup,
}
cinematics.Logger = d2util.NewLogger()
cinematics.Logger.SetPrefix(logPrefix)
cinematics.Logger.SetLevel(l)
return cinematics
}
2020-11-09 12:51:38 -05:00
// Cinematics represents the cinematics screen
type Cinematics struct {
cinematicsBackground *d2ui.Sprite
2020-11-10 08:17:34 -05:00
background *d2ui.Sprite
2020-11-09 14:42:13 -05:00
a1Btn *d2ui.Button
a2Btn *d2ui.Button
a3Btn *d2ui.Button
a4Btn *d2ui.Button
a5Btn *d2ui.Button
endCreditClassBtn *d2ui.Button
endCreditExpBtn *d2ui.Button
2020-11-09 12:51:38 -05:00
cinematicsExitBtn *d2ui.Button
2020-11-10 05:40:39 -05:00
cinematicsLabel *d2ui.Label
2020-11-09 12:51:38 -05:00
2020-11-10 06:05:35 -05:00
asset *d2asset.AssetManager
renderer d2interface.Renderer
navigator d2interface.Navigator
uiManager *d2ui.UIManager
videoDecoder *d2video.BinkDecoder
audioProvider d2interface.AudioProvider
*d2util.Logger
2020-11-09 12:51:38 -05:00
}
// OnLoad is called to load the resources for the credits screen
2020-11-10 08:17:34 -05:00
func (v *Cinematics) OnLoad(_ d2screen.LoadingState) {
2020-11-09 12:51:38 -05:00
var err error
2020-11-10 06:05:35 -05:00
v.audioProvider.PlayBGM("")
2020-11-10 08:17:34 -05:00
v.background, err = v.uiManager.NewSprite(d2resource.GameSelectScreen, d2resource.PaletteSky)
if err != nil {
v.Error(err.Error())
2020-11-10 08:17:34 -05:00
}
v.background.SetPosition(backgroundX, backgroundY)
2020-11-09 12:51:38 -05:00
v.cinematicsBackground, err = v.uiManager.NewSprite(d2resource.CinematicsBackground, d2resource.PaletteSky)
2020-11-10 05:40:39 -05:00
2020-11-09 12:51:38 -05:00
if err != nil {
v.Error(err.Error())
2020-11-09 12:51:38 -05:00
}
2020-11-10 01:59:17 -05:00
v.cinematicsBackground.SetPosition(cinematicsX, cinematicsY)
2020-11-09 12:51:38 -05:00
2020-11-09 14:42:13 -05:00
v.createButtons()
2020-11-10 05:40:39 -05:00
v.cinematicsLabel = v.uiManager.NewLabel(d2resource.Font30, d2resource.PaletteStatic)
v.cinematicsLabel.Alignment = d2ui.HorizontalAlignCenter
v.cinematicsLabel.SetText(v.asset.TranslateLabel(d2enum.SelectCinematicLabel))
2020-12-14 05:25:37 -05:00
v.cinematicsLabel.Color[0] = d2util.Color(lightBrown)
2020-11-10 05:40:39 -05:00
v.cinematicsLabel.SetPosition(cinematicsLabelX, cinematicsLabelY)
2020-11-09 12:51:38 -05:00
}
2020-11-09 14:42:13 -05:00
func (v *Cinematics) createButtons() {
2020-11-25 13:25:19 -05:00
v.cinematicsExitBtn = v.uiManager.NewButton(d2ui.ButtonTypeMedium,
v.asset.TranslateString(v.asset.TranslateLabel(d2enum.CancelLabel)))
2020-11-09 14:42:13 -05:00
v.cinematicsExitBtn.SetPosition(cinematicsExitBtnX, cinematicsExitBtnY)
v.cinematicsExitBtn.OnActivated(func() { v.onCinematicsExitBtnClicked() })
v.a1Btn = v.uiManager.NewButton(d2ui.ButtonTypeWide, v.asset.TranslateString("act1X"))
2020-11-09 14:42:13 -05:00
v.a1Btn.SetPosition(a1BtnX, a1BtnY)
v.a1Btn.OnActivated(func() { v.onA1BtnClicked() })
v.a2Btn = v.uiManager.NewButton(d2ui.ButtonTypeWide, v.asset.TranslateString("act2X"))
2020-11-09 14:42:13 -05:00
v.a2Btn.SetPosition(a2BtnX, a2BtnY)
v.a2Btn.OnActivated(func() { v.onA2BtnClicked() })
v.a3Btn = v.uiManager.NewButton(d2ui.ButtonTypeWide, v.asset.TranslateString("act3X"))
2020-11-09 14:42:13 -05:00
v.a3Btn.SetPosition(a3BtnX, a3BtnY)
v.a3Btn.OnActivated(func() { v.onA3BtnClicked() })
v.a4Btn = v.uiManager.NewButton(d2ui.ButtonTypeWide, v.asset.TranslateString("act4X"))
2020-11-09 14:42:13 -05:00
v.a4Btn.SetPosition(a4BtnX, a4BtnY)
v.a4Btn.OnActivated(func() { v.onA4BtnClicked() })
v.endCreditClassBtn = v.uiManager.NewButton(d2ui.ButtonTypeWide, v.asset.TranslateString("strepilogueX"))
2020-11-09 14:42:13 -05:00
v.endCreditClassBtn.SetPosition(endCreditClassBtnX, endCreditClassBtnY)
v.endCreditClassBtn.OnActivated(func() { v.onEndCreditClassBtnClicked() })
v.a5Btn = v.uiManager.NewButton(d2ui.ButtonTypeWide, v.asset.TranslateString("act5X"))
2020-11-09 14:42:13 -05:00
v.a5Btn.SetPosition(a5BtnX, a5BtnY)
v.a5Btn.OnActivated(func() { v.onA5BtnClicked() })
v.endCreditExpBtn = v.uiManager.NewButton(d2ui.ButtonTypeWide, v.asset.TranslateString("strlastcinematic"))
2020-11-09 14:42:13 -05:00
v.endCreditExpBtn.SetPosition(endCreditExpBtnX, endCreditExpBtnY)
v.endCreditExpBtn.OnActivated(func() { v.onEndCreditExpBtnClicked() })
}
func (v *Cinematics) onCinematicsExitBtnClicked() {
v.navigator.ToMainMenu()
}
func (v *Cinematics) onA1BtnClicked() {
v.playVideo(d2resource.Act1Intro)
}
func (v *Cinematics) onA2BtnClicked() {
v.playVideo(d2resource.Act2Intro)
}
func (v *Cinematics) onA3BtnClicked() {
v.playVideo(d2resource.Act3Intro)
}
func (v *Cinematics) onA4BtnClicked() {
v.playVideo(d2resource.Act4Intro)
}
func (v *Cinematics) onEndCreditClassBtnClicked() {
v.playVideo(d2resource.Act4Outro)
}
func (v *Cinematics) onA5BtnClicked() {
v.playVideo(d2resource.Act5Intro)
}
func (v *Cinematics) onEndCreditExpBtnClicked() {
v.playVideo(d2resource.Act5Outro)
}
func (v *Cinematics) playVideo(path string) {
videoBytes, err := v.asset.LoadFile(path)
if err != nil {
v.Error(err.Error())
2020-11-09 14:42:13 -05:00
return
}
2020-11-10 01:59:17 -05:00
v.videoDecoder, err = d2video.CreateBinkDecoder(videoBytes)
if err != nil {
v.Error(err.Error())
return
}
2020-11-09 14:42:13 -05:00
}
2020-11-09 12:51:38 -05:00
// Render renders the credits screen
2020-11-10 01:59:17 -05:00
func (v *Cinematics) Render(screen d2interface.Surface) {
v.background.RenderSegmented(screen, 4, 3, 0)
v.cinematicsBackground.RenderSegmented(screen, 2, 2, 0)
v.cinematicsLabel.Render(screen)
2020-11-09 12:51:38 -05:00
}