Better commenting throughout
This commit is contained in:
@@ -17,6 +17,8 @@ var (
|
||||
rectPixel = newRectPixel()
|
||||
)
|
||||
|
||||
// Drawing helpers
|
||||
|
||||
func newRectPixel() *ebiten.Image {
|
||||
img := ebiten.NewImage(1, 1)
|
||||
img.Fill(color.White)
|
||||
@@ -33,12 +35,12 @@ func drawHUDText(screen *ebiten.Image, txt string, clr color.Color, x, y int) {
|
||||
text.Draw(screen, txt, basicFace, op)
|
||||
}
|
||||
|
||||
// Drawable HUD chunk.
|
||||
// HUD elements
|
||||
|
||||
type Element interface {
|
||||
Draw(screen *ebiten.Image, x, y int) (width, height int)
|
||||
}
|
||||
|
||||
// Plain text node.
|
||||
type Label struct {
|
||||
Text string
|
||||
Color color.Color
|
||||
@@ -53,7 +55,6 @@ func (l Label) Draw(screen *ebiten.Image, x, y int) (int, int) {
|
||||
return width, 13
|
||||
}
|
||||
|
||||
// Percent readout node.
|
||||
type PercentageDisplay struct {
|
||||
Meter status.Meter
|
||||
Color color.Color
|
||||
@@ -68,7 +69,6 @@ func (p PercentageDisplay) Draw(screen *ebiten.Image, x, y int) (int, int) {
|
||||
return len(txt) * 7, 13
|
||||
}
|
||||
|
||||
// Combined label and percent.
|
||||
type MeterLabel struct {
|
||||
Meter status.Meter
|
||||
Color color.Color
|
||||
@@ -80,17 +80,14 @@ func (m MeterLabel) Draw(screen *ebiten.Image, x, y int) (int, int) {
|
||||
}
|
||||
var txt string
|
||||
if m.Meter.Base < 0 {
|
||||
// Text-only display without percentage.
|
||||
txt = m.Meter.Label
|
||||
} else {
|
||||
// Standard meter with percentage.
|
||||
txt = fmt.Sprintf("%s: %3.0f%%", m.Meter.Label, m.Meter.Level)
|
||||
}
|
||||
drawHUDText(screen, txt, m.Meter.Color, x, y)
|
||||
return len(txt) * 7, 13
|
||||
}
|
||||
|
||||
// Horizontal meter bar.
|
||||
type Bar struct {
|
||||
Meter status.Meter
|
||||
MaxWidth int
|
||||
@@ -117,23 +114,17 @@ func (b Bar) Draw(screen *ebiten.Image, x, y int) (int, int) {
|
||||
fillWidth = maxWidth
|
||||
}
|
||||
|
||||
// Draw border if requested
|
||||
if b.ShowBorder {
|
||||
borderColor := b.BorderColor
|
||||
if borderColor == nil {
|
||||
borderColor = color.RGBA{R: 80, G: 80, B: 80, A: 255}
|
||||
}
|
||||
// Top border
|
||||
drawRect(screen, x, y, maxWidth, 1, borderColor)
|
||||
// Bottom border
|
||||
drawRect(screen, x, y+height-1, maxWidth, 1, borderColor)
|
||||
// Left border
|
||||
drawRect(screen, x, y, 1, height, borderColor)
|
||||
// Right border
|
||||
drawRect(screen, x+maxWidth-1, y, 1, height, borderColor)
|
||||
}
|
||||
|
||||
// Draw filled portion
|
||||
if fillWidth > 0 {
|
||||
drawRect(screen, x, y, fillWidth, height, b.Meter.Color)
|
||||
}
|
||||
@@ -141,7 +132,8 @@ func (b Bar) Draw(screen *ebiten.Image, x, y int) (int, int) {
|
||||
return maxWidth, height
|
||||
}
|
||||
|
||||
// Helper for filled rectangles.
|
||||
// Rectangle drawing
|
||||
|
||||
func drawRect(screen *ebiten.Image, x, y, width, height int, clr color.Color) {
|
||||
if width <= 0 || height <= 0 {
|
||||
return
|
||||
@@ -158,7 +150,8 @@ func drawRect(screen *ebiten.Image, x, y, width, height int, clr color.Color) {
|
||||
screen.DrawImage(rectPixel, op)
|
||||
}
|
||||
|
||||
// Empty padding block.
|
||||
// Layout elements
|
||||
|
||||
type Spacer struct {
|
||||
Width int
|
||||
Height int
|
||||
@@ -168,7 +161,6 @@ func (s Spacer) Draw(screen *ebiten.Image, x, y int) (int, int) {
|
||||
return s.Width, s.Height
|
||||
}
|
||||
|
||||
// Horizontal layout row.
|
||||
type Row struct {
|
||||
Elements []Element
|
||||
Spacing int
|
||||
@@ -195,7 +187,6 @@ func (r Row) Draw(screen *ebiten.Image, x, y int) (int, int) {
|
||||
return totalWidth, maxHeight
|
||||
}
|
||||
|
||||
// Vertical stack layout.
|
||||
type Column struct {
|
||||
Elements []Element
|
||||
Spacing int
|
||||
|
||||
@@ -8,20 +8,17 @@ import (
|
||||
"github.com/atridad/LilGuy/internal/status"
|
||||
)
|
||||
|
||||
// HUD overlay anchor.
|
||||
type Overlay struct {
|
||||
X int
|
||||
Y int
|
||||
Color color.Color
|
||||
}
|
||||
|
||||
// Paints the HUD overlay.
|
||||
func (o Overlay) Draw(screen *ebiten.Image, meters []status.Meter) {
|
||||
if o.Color == nil {
|
||||
o.Color = color.White
|
||||
}
|
||||
|
||||
// Instruction text
|
||||
instructions := Column{
|
||||
Elements: []Element{
|
||||
Label{Text: "Lil Guy", Color: o.Color},
|
||||
@@ -31,16 +28,13 @@ func (o Overlay) Draw(screen *ebiten.Image, meters []status.Meter) {
|
||||
}
|
||||
instructions.Draw(screen, 16, 16)
|
||||
|
||||
// Meter column
|
||||
meterElements := make([]Element, 0, len(meters))
|
||||
for _, meter := range meters {
|
||||
if meter.Base < 0 {
|
||||
// Text-only display (no bar).
|
||||
meterElements = append(meterElements,
|
||||
MeterLabel{Meter: meter, Color: o.Color},
|
||||
)
|
||||
} else {
|
||||
// Full meter with bar.
|
||||
meterElements = append(meterElements, Column{
|
||||
Elements: []Element{
|
||||
MeterLabel{Meter: meter, Color: o.Color},
|
||||
|
||||
@@ -22,6 +22,8 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// Menu options
|
||||
|
||||
func getOverlayImage(width, height int) *ebiten.Image {
|
||||
if width <= 0 || height <= 0 {
|
||||
return nil
|
||||
@@ -46,6 +48,8 @@ const (
|
||||
optionCount
|
||||
)
|
||||
|
||||
// Screen modes
|
||||
|
||||
type menuScreen int
|
||||
|
||||
const (
|
||||
@@ -80,7 +84,8 @@ func (m *PauseMenu) SetFPSCap(cap FPSCapSetting) {
|
||||
m.settingsScreen.SetFPSCap(cap)
|
||||
}
|
||||
|
||||
// Returns the selected option if one was chosen, nil otherwise
|
||||
// Update logic
|
||||
|
||||
func (m *PauseMenu) Update() *MenuOption {
|
||||
if m.currentScreen == screenSettings {
|
||||
return m.updateSettings()
|
||||
@@ -123,6 +128,8 @@ func (m *PauseMenu) updateSettings() *MenuOption {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Rendering
|
||||
|
||||
func (m *PauseMenu) Draw(screen *ebiten.Image, screenWidth, screenHeight int) {
|
||||
if overlay := getOverlayImage(screenWidth, screenHeight); overlay != nil {
|
||||
screen.DrawImage(overlay, nil)
|
||||
@@ -177,6 +184,7 @@ func (m *PauseMenu) drawMain(screen *ebiten.Image, menuX, menuY, menuWidth, menu
|
||||
}
|
||||
}
|
||||
|
||||
// Instructions
|
||||
hintText := "Use Arrow Keys/WASD to navigate, Enter/Space to select"
|
||||
hintX := menuX + (menuWidth / 2) - (len(hintText) * 7 / 2)
|
||||
hintY := menuY + menuHeight - 30
|
||||
@@ -184,7 +192,6 @@ func (m *PauseMenu) drawMain(screen *ebiten.Image, menuX, menuY, menuWidth, menu
|
||||
}
|
||||
|
||||
func (m *PauseMenu) drawSettings(screen *ebiten.Image, menuX, menuY, menuWidth, menuHeight int) {
|
||||
// Draw menu background and border
|
||||
vector.DrawFilledRect(screen,
|
||||
float32(menuX), float32(menuY),
|
||||
float32(menuWidth), float32(menuHeight),
|
||||
@@ -200,16 +207,12 @@ func (m *PauseMenu) drawSettings(screen *ebiten.Image, menuX, menuY, menuWidth,
|
||||
false,
|
||||
)
|
||||
|
||||
// Create a sub-image for the settings screen to draw within the menu bounds
|
||||
// We'll draw to the full screen and the settings screen will handle positioning
|
||||
screenWidth := menuWidth
|
||||
screenHeight := menuHeight
|
||||
|
||||
// Temporarily adjust the drawing to center within the menu
|
||||
subScreen := ebiten.NewImage(screenWidth, screenHeight)
|
||||
m.settingsScreen.Draw(subScreen, screenWidth, screenHeight, "SETTINGS")
|
||||
|
||||
// Draw the settings content in the menu area
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
op.GeoM.Translate(float64(menuX), float64(menuY))
|
||||
screen.DrawImage(subScreen, op)
|
||||
|
||||
Reference in New Issue
Block a user