Arkadodge/pause.odin

84 lines
1.6 KiB
Odin
Raw Normal View History

2024-09-09 00:18:35 +03:00
package main
import rl "vendor:raylib"
import "core:math/ease"
Pause_Buttons :: enum {
RESUME,
EXIT
}
pause_strings := [Pause_Buttons]cstring {
2024-09-09 17:48:24 +03:00
.RESUME = "Продолжить",
2024-09-09 00:18:35 +03:00
.EXIT = "Выход"
}
Pause :: struct {
using state: GameState,
2024-09-09 17:48:24 +03:00
list: MenuList(Pause_Buttons)
2024-09-09 00:18:35 +03:00
}
pause_init :: proc(prev: ^GameState = nil) -> ^GameState {
state := new(Pause)
state.variant = state
2024-09-09 17:48:24 +03:00
state.list = MenuList(Pause_Buttons){
position = {-300, 300},
line_size = 60,
font_size = 42,
elements = &pause_strings,
menu_pressed = pause_button_pressed,
background = rl.Color{50, 10, 110, 180},
2024-09-09 17:48:24 +03:00
}
state.update = pause_update
state.draw = pause_draw
state.free = pause_free
2024-09-09 00:18:35 +03:00
state.previous = prev
2024-09-09 17:48:24 +03:00
tween_to(&state.list.position.x, 300, 1, ease.Ease.Back_Out)
2024-09-09 00:18:35 +03:00
return state
}
pause_update :: proc(state: ^GameState, delta: f32) {
menu := transmute(^Pause)state
2024-09-09 17:48:24 +03:00
2024-09-09 23:41:16 +03:00
if rl.IsKeyPressed(rl.KeyboardKey.ESCAPE) {
stack_pop()
return
}
2024-09-09 17:48:24 +03:00
menu_list_update(&menu.list)
}
2024-09-09 00:18:35 +03:00
2024-09-09 17:48:24 +03:00
pause_button_pressed :: proc(state: ^GameState, el: Pause_Buttons) {
switch el {
case .RESUME:
stack_pop()
case .EXIT:
stack_pop()
stack_pop()
2024-09-09 00:18:35 +03:00
}
}
pause_draw :: proc(state: ^GameState) {
menu := transmute(^Pause)state
2024-09-09 17:48:24 +03:00
if state.previous != nil {
state.previous->draw()
}
2024-09-09 00:18:35 +03:00
TitleFontSize :: 96
TitleSpacing :: 3
TitleText :: "ПАУЗА"
TitleSize := rl.MeasureTextEx(FontTitle, TitleText, TitleFontSize, TitleSpacing)
2024-09-09 17:48:24 +03:00
rl.DrawTextPro(FontTitle, "ПАУЗА", {WINDOWF.x - 50, 50}, {TitleSize.x, 0}, 0, 96, 3, rl.WHITE)
2024-09-09 00:18:35 +03:00
2024-09-09 17:48:24 +03:00
menu_list_draw(&menu.list)
2024-09-09 00:18:35 +03:00
}
pause_free :: proc(state: ^GameState) {
2024-09-09 23:41:16 +03:00
pause := transmute(^Pause)state
2024-09-09 00:18:35 +03:00
free(state)
}