1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2025-01-12 20:36:25 -05:00

More credits updates

This commit is contained in:
Tim Sarbin 2019-10-26 00:55:59 -04:00
parent 26b2bee88c
commit bbcb811836
3 changed files with 46 additions and 11 deletions

View File

@ -1,6 +1,11 @@
package Scenes package Scenes
import ( import (
"encoding/binary"
"strings"
"unicode/utf16"
"unicode/utf8"
"github.com/essial/OpenDiablo2/Common" "github.com/essial/OpenDiablo2/Common"
"github.com/essial/OpenDiablo2/Palettes" "github.com/essial/OpenDiablo2/Palettes"
"github.com/essial/OpenDiablo2/ResourcePaths" "github.com/essial/OpenDiablo2/ResourcePaths"
@ -16,6 +21,8 @@ type Credits struct {
fileProvider Common.FileProvider fileProvider Common.FileProvider
sceneProvider SceneProvider sceneProvider SceneProvider
creditsBackground *Common.Sprite creditsBackground *Common.Sprite
exitButton *UI.Button
creditsText []string
} }
// CreateCredits creates an instance of the credits scene // CreateCredits creates an instance of the credits scene
@ -29,11 +36,33 @@ func CreateCredits(fileProvider Common.FileProvider, sceneProvider SceneProvider
return result return result
} }
func utf16BytesToString(b []byte, o binary.ByteOrder) string {
utf := make([]uint16, (len(b)+(2-1))/2)
for i := 0; i+(2-1) < len(b); i += 2 {
utf[i/2] = o.Uint16(b[i:])
}
if len(b)/2 < len(utf) {
utf[len(utf)-1] = utf8.RuneError
}
return string(utf16.Decode(utf))
}
// Load is called to load the resources for the credits scene // Load is called to load the resources for the credits scene
func (v *Credits) Load() []func() { func (v *Credits) Load() []func() {
return []func(){ return []func(){
func() { func() {
v.creditsBackground = v.fileProvider.LoadSprite(ResourcePaths.CreditsBackground, Palettes.Sky) v.creditsBackground = v.fileProvider.LoadSprite(ResourcePaths.CreditsBackground, Palettes.Sky)
v.creditsBackground.MoveTo(0, 0)
},
func() {
v.exitButton = UI.CreateButton(UI.ButtonTypeMedium, v.fileProvider, "EXIT")
v.exitButton.MoveTo(30, 550)
v.exitButton.OnActivated(func() { v.onExitButtonClicked() })
v.uiManager.AddWidget(v.exitButton)
},
func() {
fileData := utf16BytesToString(v.fileProvider.LoadFile(ResourcePaths.CreditsText), binary.LittleEndian)
v.creditsText = strings.Split(fileData, "\r\n")
}, },
} }
} }
@ -52,3 +81,9 @@ func (v *Credits) Render(screen *ebiten.Image) {
func (v *Credits) Update() { func (v *Credits) Update() {
} }
func (v *Credits) onExitButtonClicked() {
mainMenu := CreateMainMenu(v.fileProvider, v.sceneProvider, v.uiManager, v.soundManager)
mainMenu.ShowTrademarkScreen = false
v.sceneProvider.SetNextScene(mainMenu)
}

View File

@ -29,7 +29,7 @@ type MainMenu struct {
creditsButton *UI.Button creditsButton *UI.Button
copyrightLabel *UI.Label copyrightLabel *UI.Label
copyrightLabel2 *UI.Label copyrightLabel2 *UI.Label
showTrademarkScreen bool ShowTrademarkScreen bool
leftButtonHeld bool leftButtonHeld bool
} }
@ -40,7 +40,7 @@ func CreateMainMenu(fileProvider Common.FileProvider, sceneProvider SceneProvide
uiManager: uiManager, uiManager: uiManager,
soundManager: soundManager, soundManager: soundManager,
sceneProvider: sceneProvider, sceneProvider: sceneProvider,
showTrademarkScreen: true, ShowTrademarkScreen: true,
} }
return result return result
} }
@ -94,14 +94,14 @@ func (v *MainMenu) Load() []func() {
func() { func() {
v.exitDiabloButton = UI.CreateButton(UI.ButtonTypeWide, v.fileProvider, "EXIT DIABLO II") v.exitDiabloButton = UI.CreateButton(UI.ButtonTypeWide, v.fileProvider, "EXIT DIABLO II")
v.exitDiabloButton.MoveTo(264, 535) v.exitDiabloButton.MoveTo(264, 535)
v.exitDiabloButton.SetVisible(false) v.exitDiabloButton.SetVisible(!v.ShowTrademarkScreen)
v.exitDiabloButton.OnActivated(func() { v.onExitButtonClicked() }) v.exitDiabloButton.OnActivated(func() { v.onExitButtonClicked() })
v.uiManager.AddWidget(v.exitDiabloButton) v.uiManager.AddWidget(v.exitDiabloButton)
}, },
func() { func() {
v.creditsButton = UI.CreateButton(UI.ButtonTypeShort, v.fileProvider, "CREDITS") v.creditsButton = UI.CreateButton(UI.ButtonTypeShort, v.fileProvider, "CREDITS")
v.creditsButton.MoveTo(264, 505) v.creditsButton.MoveTo(264, 505)
v.creditsButton.SetVisible(false) v.creditsButton.SetVisible(!v.ShowTrademarkScreen)
v.creditsButton.OnActivated(func() { v.onCreditsButtonClicked() }) v.creditsButton.OnActivated(func() { v.onCreditsButtonClicked() })
v.uiManager.AddWidget(v.creditsButton) v.uiManager.AddWidget(v.creditsButton)
}, },
@ -123,7 +123,7 @@ func (v *MainMenu) Unload() {
// Render renders the main menu // Render renders the main menu
func (v *MainMenu) Render(screen *ebiten.Image) { func (v *MainMenu) Render(screen *ebiten.Image) {
if v.showTrademarkScreen { if v.ShowTrademarkScreen {
v.trademarkBackground.DrawSegments(screen, 4, 3, 0) v.trademarkBackground.DrawSegments(screen, 4, 3, 0)
} else { } else {
v.background.DrawSegments(screen, 4, 3, 0) v.background.DrawSegments(screen, 4, 3, 0)
@ -133,7 +133,7 @@ func (v *MainMenu) Render(screen *ebiten.Image) {
v.diabloLogoLeft.Draw(screen) v.diabloLogoLeft.Draw(screen)
v.diabloLogoRight.Draw(screen) v.diabloLogoRight.Draw(screen)
if v.showTrademarkScreen { if v.ShowTrademarkScreen {
v.copyrightLabel.Draw(screen) v.copyrightLabel.Draw(screen)
v.copyrightLabel2.Draw(screen) v.copyrightLabel2.Draw(screen)
} else { } else {
@ -143,10 +143,10 @@ func (v *MainMenu) Render(screen *ebiten.Image) {
// Update runs the update logic on the main menu // Update runs the update logic on the main menu
func (v *MainMenu) Update() { func (v *MainMenu) Update() {
if v.showTrademarkScreen { if v.ShowTrademarkScreen {
if v.uiManager.CursorButtonPressed(UI.CursorButtonLeft) { if v.uiManager.CursorButtonPressed(UI.CursorButtonLeft) {
v.leftButtonHeld = true v.leftButtonHeld = true
v.showTrademarkScreen = false v.ShowTrademarkScreen = false
v.exitDiabloButton.SetVisible(true) v.exitDiabloButton.SetVisible(true)
v.creditsButton.SetVisible(true) v.creditsButton.SetVisible(true)
} }

View File

@ -54,11 +54,11 @@ type ButtonLayout struct {
// ButtonLayouts define the type of buttons you can have // ButtonLayouts define the type of buttons you can have
var ButtonLayouts = map[ButtonType]ButtonLayout{ var ButtonLayouts = map[ButtonType]ButtonLayout{
ButtonTypeWide: {2, 1, ResourcePaths.WideButtonBlank, Palettes.Units, false, 0, -1, ResourcePaths.FontExocet10, nil, true}, ButtonTypeWide: {2, 1, ResourcePaths.WideButtonBlank, Palettes.Units, false, 0, -1, ResourcePaths.FontExocet10, nil, true},
ButtonTypeShort: {1, 1, ResourcePaths.ShortButtonBlank, Palettes.Units, false, 0, -1, ResourcePaths.FontExocet8, nil, true}, ButtonTypeShort: {1, 1, ResourcePaths.ShortButtonBlank, Palettes.Units, false, 0, -1, ResourcePaths.FontExocet8, nil, true},
ButtonTypeMedium: {1, 1, ResourcePaths.MediumButtonBlank, Palettes.Units, false, 0, -1, ResourcePaths.FontExocet10, nil, true},
/* /*
{eButtonType.Wide, new ButtonLayout { XSegments = 2, ResourceName = ResourcePaths.WideButtonBlank, PaletteName = Palettes.Units } }, {eButtonType.Wide, new ButtonLayout { XSegments = 2, ResourceName = ResourcePaths.WideButtonBlank, PaletteName = Palettes.Units } },
{eButtonType.Medium, new ButtonLayout{ ResourceName = ResourcePaths.MediumButtonBlank, PaletteName = Palettes.Units } },
{eButtonType.Narrow, new ButtonLayout { ResourceName = ResourcePaths.NarrowButtonBlank, PaletteName = Palettes.Units } }, {eButtonType.Narrow, new ButtonLayout { ResourceName = ResourcePaths.NarrowButtonBlank, PaletteName = Palettes.Units } },
{eButtonType.Tall, new ButtonLayout { ResourceName = ResourcePaths.TallButtonBlank, PaletteName = Palettes.Units } }, {eButtonType.Tall, new ButtonLayout { ResourceName = ResourcePaths.TallButtonBlank, PaletteName = Palettes.Units } },