rename hud.odin to overlay.odin, add clay button to start wave
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
package game
|
||||
|
||||
import clay "../clay-odin"
|
||||
import "core:fmt"
|
||||
import rl "vendor:raylib"
|
||||
|
||||
ui_hud_scratch: struct {
|
||||
gold: [64]u8,
|
||||
hp: [64]u8,
|
||||
wave: [64]u8,
|
||||
}
|
||||
|
||||
build_overlay :: proc(world: ^World) {
|
||||
if clay.UI(clay.ID("HudBar"))(
|
||||
{
|
||||
layout = {
|
||||
layoutDirection = .LeftToRight,
|
||||
sizing = {width = clay.SizingGrow({}), height = clay.SizingFixed(28)},
|
||||
padding = clay.PaddingAll(6),
|
||||
childGap = 8,
|
||||
childAlignment = {y = .Center},
|
||||
},
|
||||
backgroundColor = UI_BAR_COLOR,
|
||||
},
|
||||
) {
|
||||
gold_text := fmt.bprintf(ui_hud_scratch.gold[:], "Gold: %d", world.gold)
|
||||
clay.Text(
|
||||
gold_text,
|
||||
clay.TextElementConfig{textColor = UI_GOLD_COLOR, fontId = UI_FONT_ID, fontSize = 18},
|
||||
)
|
||||
|
||||
hp_text := fmt.bprintf(ui_hud_scratch.hp[:], "Base HP: %d", world.base_health)
|
||||
clay.Text(
|
||||
hp_text,
|
||||
clay.TextElementConfig{textColor = UI_TEXT_COLOR, fontId = UI_FONT_ID, fontSize = 18},
|
||||
)
|
||||
|
||||
wave_text := fmt.bprintf(ui_hud_scratch.wave[:], "Wave: %d / %d", world.wave, MAX_WAVES)
|
||||
clay.Text(
|
||||
wave_text,
|
||||
clay.TextElementConfig{textColor = UI_TEXT_COLOR, fontId = UI_FONT_ID, fontSize = 18},
|
||||
)
|
||||
|
||||
if world.phase == .Build {
|
||||
if clay.UI(clay.ID("StartWaveBtn"))(
|
||||
{
|
||||
layout = {
|
||||
sizing = {width = clay.SizingFixed(110), height = clay.SizingFixed(22)},
|
||||
padding = clay.PaddingAll(4),
|
||||
childAlignment = {x = .Center, y = .Center},
|
||||
},
|
||||
backgroundColor = clay.Hovered() ? UI_BUTTON_HOVER : UI_BUTTON_COLOR,
|
||||
},
|
||||
) {
|
||||
clay.Text(
|
||||
"Start Wave",
|
||||
clay.TextElementConfig {
|
||||
textColor = UI_TEXT_COLOR,
|
||||
fontId = UI_FONT_ID,
|
||||
fontSize = 16,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
render_overlay :: proc(world: ^World) {
|
||||
switch world.phase {
|
||||
case .Build:
|
||||
case .Combat:
|
||||
rl.DrawText("Combat!", 10, 98, 22, rl.MAROON)
|
||||
case .Game_Over:
|
||||
rl.DrawText("GAME_OVER", 260, 280, 40, rl.RED)
|
||||
case .Victory:
|
||||
rl.DrawText("Victory!", 260, 280, 40, rl.GREEN)
|
||||
}
|
||||
}
|
||||
|
||||
poll_overlay_command :: proc() -> Command {
|
||||
if clay.PointerOver(clay.ID("StartWaveBtn")) {
|
||||
ptr := clay.GetPointerState()
|
||||
if ptr.state == .PressedThisFrame {
|
||||
return Command{kind = .Start_Wave}
|
||||
}
|
||||
}
|
||||
return Command{kind = .None}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user