Better commenting throughout
This commit is contained in:
@@ -8,39 +8,32 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/text/v2"
|
||||
)
|
||||
|
||||
// An interface for managing FPS cap settings.
|
||||
// Settings interface
|
||||
type FPSCapSetting interface {
|
||||
String() string
|
||||
Cycle()
|
||||
}
|
||||
|
||||
// Displays and manages game settings like FPS monitor and FPS cap.
|
||||
// This screen can be accessed from both the title screen and pause menu.
|
||||
type SettingsScreen struct {
|
||||
selectedIndex int
|
||||
fpsMonitorValue *bool
|
||||
fpsCapValue FPSCapSetting
|
||||
}
|
||||
|
||||
// Creates a new settings screen instance.
|
||||
func NewSettingsScreen() *SettingsScreen {
|
||||
return &SettingsScreen{
|
||||
selectedIndex: 0,
|
||||
}
|
||||
}
|
||||
|
||||
// Sets the FPS monitor toggle reference.
|
||||
func (s *SettingsScreen) SetFPSMonitor(enabled *bool) {
|
||||
s.fpsMonitorValue = enabled
|
||||
}
|
||||
|
||||
// Sets the FPS cap setting reference.
|
||||
func (s *SettingsScreen) SetFPSCap(cap FPSCapSetting) {
|
||||
s.fpsCapValue = cap
|
||||
}
|
||||
|
||||
// Processes settings screen input.
|
||||
// Returns true if the user wants to go back.
|
||||
func (s *SettingsScreen) Update() bool {
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
|
||||
return true
|
||||
@@ -71,20 +64,19 @@ func (s *SettingsScreen) Update() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Renders the settings screen.
|
||||
// Rendering
|
||||
|
||||
func (s *SettingsScreen) Draw(screen *ebiten.Image, screenWidth, screenHeight int, title string) {
|
||||
// Draw background
|
||||
screen.Fill(color.RGBA{R: 20, G: 20, B: 30, A: 255})
|
||||
|
||||
// Draw title
|
||||
titleX := (screenWidth / 2) - (len(title) * 7 / 2)
|
||||
titleY := screenHeight/3 - 50
|
||||
s.drawText(screen, title, color.White, titleX, titleY)
|
||||
|
||||
// Draw settings options
|
||||
startY := screenHeight/2 - 20
|
||||
leftMargin := screenWidth/2 - 120
|
||||
|
||||
// FPS monitor toggle
|
||||
fpsMonitorText := "FPS Monitor: "
|
||||
if s.fpsMonitorValue != nil && *s.fpsMonitorValue {
|
||||
fpsMonitorText += "ON"
|
||||
@@ -100,6 +92,7 @@ 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()
|
||||
@@ -116,7 +109,7 @@ func (s *SettingsScreen) Draw(screen *ebiten.Image, screenWidth, screenHeight in
|
||||
s.drawText(screen, fpsCapText, color.RGBA{R: 180, G: 180, B: 200, A: 255}, leftMargin, capY)
|
||||
}
|
||||
|
||||
// Draw hint text
|
||||
// Instructions
|
||||
hintText := "Enter/Space to toggle, ESC to go back"
|
||||
hintX := (screenWidth / 2) - (len(hintText) * 7 / 2)
|
||||
hintY := screenHeight - 50
|
||||
@@ -130,7 +123,6 @@ func (s *SettingsScreen) drawText(screen *ebiten.Image, txt string, clr color.Co
|
||||
text.Draw(screen, txt, basicFace, op)
|
||||
}
|
||||
|
||||
// Resets the settings screen to its initial state.
|
||||
func (s *SettingsScreen) Reset() {
|
||||
s.selectedIndex = 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user