1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-17 18:06:03 -05:00

UI manager fixes. Added map engine test scene.

This commit is contained in:
Tim Sarbin 2019-10-27 19:00:38 -04:00
parent 4c047bf993
commit ccb68f12fd
5 changed files with 97 additions and 15 deletions

View File

@ -82,7 +82,9 @@ func (v *CharacterSelect) onNewCharButtonClicked() {
}
func (v *CharacterSelect) onExitButtonClicked() {
v.sceneProvider.SetNextScene(CreateMainMenu(v.fileProvider, v.sceneProvider, v.uiManager, v.soundManager))
mainMenu := CreateMainMenu(v.fileProvider, v.sceneProvider, v.uiManager, v.soundManager)
mainMenu.ShowTrademarkScreen = false
v.sceneProvider.SetNextScene(mainMenu)
}
func (v *CharacterSelect) Unload() {

View File

@ -34,6 +34,7 @@ type MainMenu struct {
exitDiabloButton *UI.Button
creditsButton *UI.Button
cinematicsButton *UI.Button
mapTestButton *UI.Button
copyrightLabel *UI.Label
copyrightLabel2 *UI.Label
openDiabloLabel *UI.Label
@ -142,9 +143,20 @@ func (v *MainMenu) Load() []func() {
v.githubButton.OnActivated(func() { v.onGithubButtonClicked() })
v.uiManager.AddWidget(v.githubButton)
},
func() {
v.mapTestButton = UI.CreateButton(UI.ButtonTypeWide, v.fileProvider, "MAP ENGINE TEST")
v.mapTestButton.MoveTo(264, 450)
v.mapTestButton.SetVisible(!v.ShowTrademarkScreen)
v.mapTestButton.OnActivated(func() { v.onMapTestClicked() })
v.uiManager.AddWidget(v.mapTestButton)
},
}
}
func (v *MainMenu) onMapTestClicked() {
v.sceneProvider.SetNextScene(CreateMapEngineTest(v.fileProvider, v.sceneProvider, v.uiManager, v.soundManager))
}
func openbrowser(url string) {
var err error
@ -165,7 +177,9 @@ func openbrowser(url string) {
}
func (v *MainMenu) onSinglePlayerClicked() {
v.sceneProvider.SetNextScene(CreateCharacterSelect(v.fileProvider, v.sceneProvider, v.uiManager, v.soundManager))
// 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))
}
func (v *MainMenu) onGithubButtonClicked() {
@ -212,6 +226,7 @@ func (v *MainMenu) Update(tickTime float64) {
if v.leftButtonHeld {
return
}
v.uiManager.WaitForMouseRelease()
v.leftButtonHeld = true
v.ShowTrademarkScreen = false
v.exitDiabloButton.SetVisible(true)
@ -219,6 +234,7 @@ func (v *MainMenu) Update(tickTime float64) {
v.cinematicsButton.SetVisible(true)
v.singlePlayerButton.SetVisible(true)
v.githubButton.SetVisible(true)
v.mapTestButton.SetVisible(true)
} else {
v.leftButtonHeld = false
}

41
Scenes/MapEngineTest.go Normal file
View File

@ -0,0 +1,41 @@
package Scenes
import (
"github.com/essial/OpenDiablo2/Common"
"github.com/essial/OpenDiablo2/Sound"
"github.com/essial/OpenDiablo2/UI"
"github.com/hajimehoshi/ebiten"
)
type MapEngineTest struct {
uiManager *UI.Manager
soundManager *Sound.Manager
fileProvider Common.FileProvider
sceneProvider SceneProvider
}
func CreateMapEngineTest(fileProvider Common.FileProvider, sceneProvider SceneProvider, uiManager *UI.Manager, soundManager *Sound.Manager) *MapEngineTest {
result := &MapEngineTest{
fileProvider: fileProvider,
uiManager: uiManager,
soundManager: soundManager,
sceneProvider: sceneProvider,
}
return result
}
func (v *MapEngineTest) Load() []func() {
return []func(){}
}
func (v *MapEngineTest) Unload() {
}
func (v *MapEngineTest) Render(screen *ebiten.Image) {
}
func (v *MapEngineTest) Update(tickTime float64) {
}

View File

@ -50,6 +50,7 @@ type SelectHeroClass struct {
heroDesc3Label *UI.Label
heroRenderInfo map[Common.Hero]*HeroRenderInfo
selectedHero Common.Hero
exitButton *UI.Button
}
func CreateSelectHeroClass(
@ -107,6 +108,12 @@ func (v *SelectHeroClass) Load() []func() {
v.campfire.MoveTo(380, 335)
v.campfire.Animate = true
},
func() {
v.exitButton = UI.CreateButton(UI.ButtonTypeMedium, v.fileProvider, "EXIT")
v.exitButton.MoveTo(33, 537)
v.exitButton.OnActivated(func() { v.onExitButtonClicked() })
v.uiManager.AddWidget(v.exitButton)
},
func() {
v.heroRenderInfo[Common.HeroBarbarian] = &HeroRenderInfo{
HeroStanceIdle,
@ -358,6 +365,10 @@ func (v *SelectHeroClass) Unload() {
}
func (v *SelectHeroClass) onExitButtonClicked() {
v.sceneProvider.SetNextScene(CreateCharacterSelect(v.fileProvider, v.sceneProvider, v.uiManager, v.soundManager))
}
func (v *SelectHeroClass) Render(screen *ebiten.Image) {
v.bgImage.DrawSegments(screen, 4, 3, 0)
v.headingLabel.Draw(screen)

View File

@ -20,22 +20,24 @@ const (
// Manager represents the UI manager
type Manager struct {
widgets []Widget
cursorSprite *Common.Sprite
cursorButtons CursorButton
pressedIndex int
CursorX int
CursorY int
clickSfx *Sound.SoundEffect
widgets []Widget
cursorSprite *Common.Sprite
cursorButtons CursorButton
pressedIndex int
CursorX int
CursorY int
clickSfx *Sound.SoundEffect
waitForLeftMouseUp bool
}
// CreateManager creates a new instance of a UI manager
func CreateManager(fileProvider Common.FileProvider, soundManager Sound.Manager) *Manager {
result := &Manager{
pressedIndex: -1,
widgets: make([]Widget, 0),
cursorSprite: fileProvider.LoadSprite(ResourcePaths.CursorDefault, Palettes.Units),
clickSfx: soundManager.LoadSoundEffect(ResourcePaths.SFXButtonClick),
pressedIndex: -1,
widgets: make([]Widget, 0),
cursorSprite: fileProvider.LoadSprite(ResourcePaths.CursorDefault, Palettes.Units),
clickSfx: soundManager.LoadSoundEffect(ResourcePaths.SFXButtonClick),
waitForLeftMouseUp: false,
}
return result
}
@ -44,6 +46,7 @@ func CreateManager(fileProvider Common.FileProvider, soundManager Sound.Manager)
func (v *Manager) Reset() {
v.widgets = make([]Widget, 0)
v.pressedIndex = -1
v.waitForLeftMouseUp = true
}
// AddWidget adds a widget to the UI manager
@ -51,6 +54,10 @@ func (v *Manager) AddWidget(widget Widget) {
v.widgets = append(v.widgets, widget)
}
func (v *Manager) WaitForMouseRelease() {
v.waitForLeftMouseUp = true
}
// Draw renders all of the UI elements
func (v *Manager) Draw(screen *ebiten.Image) {
for _, widget := range v.widgets {
@ -69,7 +76,13 @@ func (v *Manager) Draw(screen *ebiten.Image) {
func (v *Manager) Update() {
v.cursorButtons = 0
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
v.cursorButtons |= CursorButtonLeft
if !v.waitForLeftMouseUp {
v.cursorButtons |= CursorButtonLeft
}
} else {
if v.waitForLeftMouseUp {
v.waitForLeftMouseUp = false
}
}
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonRight) {
v.cursorButtons |= CursorButtonRight
@ -92,7 +105,6 @@ func (v *Manager) Update() {
} else if v.pressedIndex > -1 && v.pressedIndex != i {
v.widgets[i].SetPressed(false)
} else {
v.widgets[i].SetPressed(true)
found = true
}
} else {