Ragnarokkr/pause.odin

115 lines
2.3 KiB
Odin
Raw Normal View History

2024-10-05 20:44:32 +03:00
package main
import "core:math/ease"
2024-11-04 17:28:34 +03:00
import "ntween"
import rl "vendor:raylib"
2024-10-05 20:44:32 +03:00
Pause_Buttons :: enum {
CONTINUE,
2024-11-04 17:28:34 +03:00
EXIT,
2024-10-05 20:44:32 +03:00
}
pause_strings := [Pause_Buttons]cstring {
.CONTINUE = "Продолжить",
2024-11-04 17:28:34 +03:00
.EXIT = "Прервать игру",
2024-10-05 20:44:32 +03:00
}
pause_items := [Pause_Buttons]MenuItem {
.CONTINUE = {text = pause_strings[.CONTINUE]},
2024-11-04 17:28:34 +03:00
.EXIT = {text = pause_strings[.EXIT]},
}
2024-10-05 20:44:32 +03:00
Pause :: struct {
using state: GameState,
2024-11-04 17:28:34 +03:00
active: bool,
list: MenuList(Pause_Buttons),
2024-10-05 20:44:32 +03:00
}
pause_init :: proc(prev: ^GameState = nil) -> ^GameState {
state := new(Pause)
state.variant = state
2024-11-04 17:28:34 +03:00
state.list = MenuList(Pause_Buttons) {
state = state,
position = {-300, WSize.y / 2},
line_size = 60,
font_size = 48,
elements = &pause_items,
2024-10-05 20:44:32 +03:00
menu_pressed = pause_button_pressed,
2024-11-04 17:28:34 +03:00
background = rl.Color{50, 10, 110, 0},
2024-10-05 20:44:32 +03:00
}
state.update = pause_update
2024-11-04 17:28:34 +03:00
state.draw = pause_draw
2024-10-05 20:44:32 +03:00
state.free = pause_free
state.previous = prev
2024-11-04 17:28:34 +03:00
state.active = true
2024-10-05 20:44:32 +03:00
2024-11-04 17:28:34 +03:00
ntween.animate(&f32_tweens, &state.list.position.x, 100, 0.5, ease.Ease.Back_Out)
2024-10-05 20:44:32 +03:00
return state
}
pause_update :: proc(state: ^GameState, delta: f32) {
pause := transmute(^Pause)state
pause.list.position.y = WSize.y / 2
2024-11-04 17:28:34 +03:00
2024-10-05 20:44:32 +03:00
menu_list_update(&pause.list)
}
pause_button_pressed :: proc(state: ^GameState, el: Pause_Buttons) {
pause := transmute(^Pause)state
2024-11-04 17:28:34 +03:00
if !pause.active {return}
switch el {
case .CONTINUE:
stack_pop()
case .EXIT:
pause.active = false
rl.StopMusicStream(current_music)
ntween.animate(
&f32_tweens,
&Overlay_Opacity,
1.0,
0.5,
ease.Ease.Cubic_Out,
state,
proc(data: rawptr) {
2024-10-12 18:26:14 +03:00
state := transmute(^GameState)data
2024-10-05 20:44:32 +03:00
stack_pop()
game := transmute(^Game)stack_top()
game_setup(game)
menu := menu_init(game)
stack_push(menu)
2024-10-12 18:26:14 +03:00
//free(state)
2024-11-04 17:28:34 +03:00
ntween.animate(&f32_tweens, &Overlay_Opacity, 0, 0.5, ease.Ease.Cubic_Out)
},
)
2024-10-05 20:44:32 +03:00
}
}
pause_draw :: proc(state: ^GameState) {
pause := transmute(^Pause)state
2024-11-04 17:28:34 +03:00
pause.previous.draw(pause.previous)
2024-10-05 20:44:32 +03:00
TitleFontSize :: 96
TitleSpacing :: 3
TitleText :: "Ragnarøkkr"
TitleSize := rl.MeasureTextEx(Res.Fonts.Title, TitleText, TitleFontSize, TitleSpacing)
2024-11-04 17:28:34 +03:00
rl.DrawTextPro(
Res.Fonts.Title,
TitleText,
{WSize.x - 50, 50},
{TitleSize.x, 0},
0,
96,
3,
rl.WHITE,
)
2024-10-05 20:44:32 +03:00
menu_list_draw(&pause.list)
}
pause_free :: proc(state: ^GameState) {
}