Optimizations and debug options
This commit is contained in:
@@ -14,8 +14,16 @@ type FPSCapSetting interface {
|
||||
Cycle()
|
||||
}
|
||||
|
||||
type settingsScreen int
|
||||
|
||||
const (
|
||||
settingsMain settingsScreen = iota
|
||||
settingsDebugOptions
|
||||
)
|
||||
|
||||
type SettingsScreen struct {
|
||||
selectedIndex int
|
||||
currentScreen settingsScreen
|
||||
fpsMonitorValue *bool
|
||||
fpsCapValue FPSCapSetting
|
||||
portalVisibilityValue *bool
|
||||
@@ -24,6 +32,7 @@ type SettingsScreen struct {
|
||||
func NewSettingsScreen() *SettingsScreen {
|
||||
return &SettingsScreen{
|
||||
selectedIndex: 0,
|
||||
currentScreen: settingsMain,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,10 +50,22 @@ func (s *SettingsScreen) SetPortalVisibility(enabled *bool) {
|
||||
|
||||
func (s *SettingsScreen) Update() bool {
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
|
||||
if s.currentScreen == settingsDebugOptions {
|
||||
s.currentScreen = settingsMain
|
||||
s.selectedIndex = 0
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
settingsCount := 3
|
||||
if s.currentScreen == settingsDebugOptions {
|
||||
return s.updateDebugOptions()
|
||||
}
|
||||
return s.updateMain()
|
||||
}
|
||||
|
||||
func (s *SettingsScreen) updateMain() bool {
|
||||
settingsCount := 2
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyArrowUp) || inpututil.IsKeyJustPressed(ebiten.KeyW) {
|
||||
s.selectedIndex--
|
||||
if s.selectedIndex < 0 {
|
||||
@@ -58,13 +79,41 @@ func (s *SettingsScreen) Update() bool {
|
||||
}
|
||||
}
|
||||
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyEnter) || inpututil.IsKeyJustPressed(ebiten.KeySpace) {
|
||||
if s.selectedIndex == 0 && s.fpsCapValue != nil {
|
||||
s.fpsCapValue.Cycle()
|
||||
} else if s.selectedIndex == 1 {
|
||||
s.currentScreen = settingsDebugOptions
|
||||
s.selectedIndex = 0
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *SettingsScreen) updateDebugOptions() bool {
|
||||
debugOptionsCount := 3
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyArrowUp) || inpututil.IsKeyJustPressed(ebiten.KeyW) {
|
||||
s.selectedIndex--
|
||||
if s.selectedIndex < 0 {
|
||||
s.selectedIndex = 0
|
||||
}
|
||||
}
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyArrowDown) || inpututil.IsKeyJustPressed(ebiten.KeyS) {
|
||||
s.selectedIndex++
|
||||
if s.selectedIndex >= debugOptionsCount {
|
||||
s.selectedIndex = debugOptionsCount - 1
|
||||
}
|
||||
}
|
||||
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyEnter) || inpututil.IsKeyJustPressed(ebiten.KeySpace) {
|
||||
if s.selectedIndex == 0 && s.fpsMonitorValue != nil {
|
||||
*s.fpsMonitorValue = !*s.fpsMonitorValue
|
||||
} else if s.selectedIndex == 1 && s.fpsCapValue != nil {
|
||||
s.fpsCapValue.Cycle()
|
||||
} else if s.selectedIndex == 2 && s.portalVisibilityValue != nil {
|
||||
} else if s.selectedIndex == 1 && s.portalVisibilityValue != nil {
|
||||
*s.portalVisibilityValue = !*s.portalVisibilityValue
|
||||
} else if s.selectedIndex == 2 {
|
||||
s.currentScreen = settingsMain
|
||||
s.selectedIndex = 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +129,52 @@ func (s *SettingsScreen) Draw(screen *ebiten.Image, screenWidth, screenHeight in
|
||||
titleY := screenHeight/3 - 50
|
||||
s.drawText(screen, title, color.White, titleX, titleY)
|
||||
|
||||
if s.currentScreen == settingsDebugOptions {
|
||||
s.drawDebugOptions(screen, screenWidth, screenHeight)
|
||||
} else {
|
||||
s.drawMain(screen, screenWidth, screenHeight)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SettingsScreen) drawMain(screen *ebiten.Image, screenWidth, screenHeight int) {
|
||||
startY := screenHeight/2 - 20
|
||||
leftMargin := screenWidth/2 - 120
|
||||
|
||||
// FPS cap setting
|
||||
fpsCapText := "FPS Cap: "
|
||||
if s.fpsCapValue != nil {
|
||||
fpsCapText += s.fpsCapValue.String()
|
||||
} else {
|
||||
fpsCapText += "60 FPS"
|
||||
}
|
||||
|
||||
if s.selectedIndex == 0 {
|
||||
indicatorX := leftMargin - 20
|
||||
s.drawText(screen, ">", color.RGBA{R: 255, G: 200, B: 0, A: 255}, indicatorX, startY)
|
||||
s.drawText(screen, fpsCapText, color.RGBA{R: 255, G: 255, B: 100, A: 255}, leftMargin, startY)
|
||||
} else {
|
||||
s.drawText(screen, fpsCapText, color.RGBA{R: 180, G: 180, B: 200, A: 255}, leftMargin, startY)
|
||||
}
|
||||
|
||||
// debug options submenu
|
||||
debugOptionsText := "Debug Options >"
|
||||
debugY := startY + 40
|
||||
if s.selectedIndex == 1 {
|
||||
indicatorX := leftMargin - 20
|
||||
s.drawText(screen, ">", color.RGBA{R: 255, G: 200, B: 0, A: 255}, indicatorX, debugY)
|
||||
s.drawText(screen, debugOptionsText, color.RGBA{R: 255, G: 255, B: 100, A: 255}, leftMargin, debugY)
|
||||
} else {
|
||||
s.drawText(screen, debugOptionsText, color.RGBA{R: 180, G: 180, B: 200, A: 255}, leftMargin, debugY)
|
||||
}
|
||||
|
||||
// Instructions
|
||||
hintText := "Enter/Space to select, ESC to go back"
|
||||
hintX := (screenWidth / 2) - (len(hintText) * 7 / 2)
|
||||
hintY := screenHeight - 50
|
||||
s.drawText(screen, hintText, color.RGBA{R: 120, G: 120, B: 150, A: 255}, hintX, hintY)
|
||||
}
|
||||
|
||||
func (s *SettingsScreen) drawDebugOptions(screen *ebiten.Image, screenWidth, screenHeight int) {
|
||||
startY := screenHeight/2 - 20
|
||||
leftMargin := screenWidth/2 - 120
|
||||
|
||||
@@ -99,23 +194,6 @@ func (s *SettingsScreen) Draw(screen *ebiten.Image, screenWidth, screenHeight in
|
||||
s.drawText(screen, fpsMonitorText, color.RGBA{R: 180, G: 180, B: 200, A: 255}, leftMargin, startY)
|
||||
}
|
||||
|
||||
// FPS cap setting
|
||||
fpsCapText := "FPS Cap: "
|
||||
if s.fpsCapValue != nil {
|
||||
fpsCapText += s.fpsCapValue.String()
|
||||
} else {
|
||||
fpsCapText += "60 FPS"
|
||||
}
|
||||
|
||||
capY := startY + 40
|
||||
if s.selectedIndex == 1 {
|
||||
indicatorX := leftMargin - 20
|
||||
s.drawText(screen, ">", color.RGBA{R: 255, G: 200, B: 0, A: 255}, indicatorX, capY)
|
||||
s.drawText(screen, fpsCapText, color.RGBA{R: 255, G: 255, B: 100, A: 255}, leftMargin, capY)
|
||||
} else {
|
||||
s.drawText(screen, fpsCapText, color.RGBA{R: 180, G: 180, B: 200, A: 255}, leftMargin, capY)
|
||||
}
|
||||
|
||||
// Portal visibility toggle
|
||||
portalVisText := "Portal Visibility: "
|
||||
if s.portalVisibilityValue != nil && *s.portalVisibilityValue {
|
||||
@@ -124,8 +202,8 @@ func (s *SettingsScreen) Draw(screen *ebiten.Image, screenWidth, screenHeight in
|
||||
portalVisText += "OFF"
|
||||
}
|
||||
|
||||
portalY := startY + 80
|
||||
if s.selectedIndex == 2 {
|
||||
portalY := startY + 40
|
||||
if s.selectedIndex == 1 {
|
||||
indicatorX := leftMargin - 20
|
||||
s.drawText(screen, ">", color.RGBA{R: 255, G: 200, B: 0, A: 255}, indicatorX, portalY)
|
||||
s.drawText(screen, portalVisText, color.RGBA{R: 255, G: 255, B: 100, A: 255}, leftMargin, portalY)
|
||||
@@ -133,8 +211,19 @@ func (s *SettingsScreen) Draw(screen *ebiten.Image, screenWidth, screenHeight in
|
||||
s.drawText(screen, portalVisText, color.RGBA{R: 180, G: 180, B: 200, A: 255}, leftMargin, portalY)
|
||||
}
|
||||
|
||||
// back option
|
||||
backText := "< Back"
|
||||
backY := startY + 80
|
||||
if s.selectedIndex == 2 {
|
||||
indicatorX := leftMargin - 20
|
||||
s.drawText(screen, ">", color.RGBA{R: 255, G: 200, B: 0, A: 255}, indicatorX, backY)
|
||||
s.drawText(screen, backText, color.RGBA{R: 255, G: 255, B: 100, A: 255}, leftMargin, backY)
|
||||
} else {
|
||||
s.drawText(screen, backText, color.RGBA{R: 180, G: 180, B: 200, A: 255}, leftMargin, backY)
|
||||
}
|
||||
|
||||
// Instructions
|
||||
hintText := "Enter/Space to toggle, ESC to go back"
|
||||
hintText := "Enter/Space to select, ESC to go back"
|
||||
hintX := (screenWidth / 2) - (len(hintText) * 7 / 2)
|
||||
hintY := screenHeight - 50
|
||||
s.drawText(screen, hintText, color.RGBA{R: 120, G: 120, B: 150, A: 255}, hintX, hintY)
|
||||
@@ -149,4 +238,5 @@ func (s *SettingsScreen) drawText(screen *ebiten.Image, txt string, clr color.Co
|
||||
|
||||
func (s *SettingsScreen) Reset() {
|
||||
s.selectedIndex = 0
|
||||
s.currentScreen = settingsMain
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user