115 lines
2.3 KiB
Odin
115 lines
2.3 KiB
Odin
package main
|
|
|
|
import "core:math/ease"
|
|
import "ntween"
|
|
import rl "vendor:raylib"
|
|
|
|
|
|
Pause_Buttons :: enum {
|
|
CONTINUE,
|
|
EXIT,
|
|
}
|
|
|
|
pause_strings := [Pause_Buttons]cstring {
|
|
.CONTINUE = "Продолжить",
|
|
.EXIT = "Прервать игру",
|
|
}
|
|
|
|
pause_items := [Pause_Buttons]MenuItem {
|
|
.CONTINUE = {text = pause_strings[.CONTINUE]},
|
|
.EXIT = {text = pause_strings[.EXIT]},
|
|
}
|
|
|
|
Pause :: struct {
|
|
using state: GameState,
|
|
active: bool,
|
|
list: MenuList(Pause_Buttons),
|
|
}
|
|
|
|
pause_init :: proc(prev: ^GameState = nil) -> ^GameState {
|
|
state := new(Pause)
|
|
state.variant = state
|
|
state.list = MenuList(Pause_Buttons) {
|
|
state = state,
|
|
position = {-300, WSize.y / 2},
|
|
line_size = 60,
|
|
font_size = 48,
|
|
elements = &pause_items,
|
|
menu_pressed = pause_button_pressed,
|
|
background = rl.Color{50, 10, 110, 0},
|
|
}
|
|
state.update = pause_update
|
|
state.draw = pause_draw
|
|
state.free = pause_free
|
|
state.previous = prev
|
|
state.active = true
|
|
|
|
ntween.animate(&f32_tweens, &state.list.position.x, 100, 0.5, ease.Ease.Back_Out)
|
|
|
|
return state
|
|
}
|
|
|
|
pause_update :: proc(state: ^GameState, delta: f32) {
|
|
pause := transmute(^Pause)state
|
|
pause.list.position.y = WSize.y / 2
|
|
|
|
menu_list_update(&pause.list)
|
|
}
|
|
|
|
pause_button_pressed :: proc(state: ^GameState, el: Pause_Buttons) {
|
|
pause := transmute(^Pause)state
|
|
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) {
|
|
state := transmute(^GameState)data
|
|
stack_pop()
|
|
game := transmute(^Game)stack_top()
|
|
game_setup(game)
|
|
menu := menu_init(game)
|
|
stack_push(menu)
|
|
//free(state)
|
|
ntween.animate(&f32_tweens, &Overlay_Opacity, 0, 0.5, ease.Ease.Cubic_Out)
|
|
},
|
|
)
|
|
}
|
|
}
|
|
|
|
pause_draw :: proc(state: ^GameState) {
|
|
pause := transmute(^Pause)state
|
|
|
|
pause.previous.draw(pause.previous)
|
|
|
|
TitleFontSize :: 96
|
|
TitleSpacing :: 3
|
|
TitleText :: "Ragnarøkkr"
|
|
TitleSize := rl.MeasureTextEx(Res.Fonts.Title, TitleText, TitleFontSize, TitleSpacing)
|
|
rl.DrawTextPro(
|
|
Res.Fonts.Title,
|
|
TitleText,
|
|
{WSize.x - 50, 50},
|
|
{TitleSize.x, 0},
|
|
0,
|
|
96,
|
|
3,
|
|
rl.WHITE,
|
|
)
|
|
|
|
menu_list_draw(&pause.list)
|
|
|
|
}
|
|
|
|
pause_free :: proc(state: ^GameState) {
|
|
}
|