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:
parent
4c047bf993
commit
ccb68f12fd
@ -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() {
|
||||
|
@ -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
41
Scenes/MapEngineTest.go
Normal 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) {
|
||||
|
||||
}
|
@ -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)
|
||||
|
@ -27,6 +27,7 @@ type Manager struct {
|
||||
CursorX int
|
||||
CursorY int
|
||||
clickSfx *Sound.SoundEffect
|
||||
waitForLeftMouseUp bool
|
||||
}
|
||||
|
||||
// CreateManager creates a new instance of a UI manager
|
||||
@ -36,6 +37,7 @@ func CreateManager(fileProvider Common.FileProvider, soundManager Sound.Manager)
|
||||
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,8 +76,14 @@ func (v *Manager) Draw(screen *ebiten.Image) {
|
||||
func (v *Manager) Update() {
|
||||
v.cursorButtons = 0
|
||||
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user