Separate menu_list, working pause menu
This commit is contained in:
parent
0288abeb63
commit
4c6a476a49
|
@ -59,6 +59,10 @@ game_update :: proc(state: ^GameState, delta: f32) {
|
||||||
|
|
||||||
using game
|
using game
|
||||||
|
|
||||||
|
if rl.IsKeyPressed(rl.KeyboardKey.ESCAPE) {
|
||||||
|
pause := pause_init(game)
|
||||||
|
stack_push(pause)
|
||||||
|
}
|
||||||
pad_update(&game.pad, delta)
|
pad_update(&game.pad, delta)
|
||||||
if rl.IsKeyPressed(rl.KeyboardKey.SPACE) {
|
if rl.IsKeyPressed(rl.KeyboardKey.SPACE) {
|
||||||
for &ball, i in balls {
|
for &ball, i in balls {
|
||||||
|
|
70
menu.odin
70
menu.odin
|
@ -21,19 +21,21 @@ menu_strings := [Menu_Buttons]cstring {
|
||||||
Menu :: struct {
|
Menu :: struct {
|
||||||
using state: GameState,
|
using state: GameState,
|
||||||
|
|
||||||
menu_pos: Vec2,
|
list: MenuList(Menu_Buttons),
|
||||||
menu_element_offset: f32,
|
|
||||||
active_element: Menu_Buttons,
|
|
||||||
active_marker: Vec2,
|
|
||||||
marker_tween: ^Tween,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
menu_init :: proc(prev: ^GameState = nil) -> ^GameState {
|
menu_init :: proc(prev: ^GameState = nil) -> ^GameState {
|
||||||
state := new(Menu)
|
state := new(Menu)
|
||||||
state.variant = state
|
state.variant = state
|
||||||
state.menu_pos = {300, 300}
|
state.list = MenuList(Menu_Buttons){
|
||||||
state.menu_element_offset = 60
|
state = state,
|
||||||
state.active_marker = state.menu_pos + Vec2{0, f32(state.active_element) * state.menu_element_offset}
|
position = {300, 300},
|
||||||
|
line_size = 60,
|
||||||
|
font_size = 42,
|
||||||
|
elements = &menu_strings,
|
||||||
|
menu_pressed = menu_button_pressed
|
||||||
|
}
|
||||||
state.update = menu_update
|
state.update = menu_update
|
||||||
state.draw = menu_draw
|
state.draw = menu_draw
|
||||||
state.free = menu_free
|
state.free = menu_free
|
||||||
|
@ -45,40 +47,19 @@ menu_init :: proc(prev: ^GameState = nil) -> ^GameState {
|
||||||
menu_update :: proc(state: ^GameState, delta: f32) {
|
menu_update :: proc(state: ^GameState, delta: f32) {
|
||||||
menu := transmute(^Menu)state
|
menu := transmute(^Menu)state
|
||||||
|
|
||||||
prev_element := cast(i8)menu.active_element
|
menu_list_update(&menu.list)
|
||||||
cur_element := prev_element
|
}
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyboardKey.DOWN) {
|
menu_button_pressed :: proc(state: ^GameState, el: Menu_Buttons) {
|
||||||
cur_element += 1
|
switch el {
|
||||||
}
|
case .START:
|
||||||
if rl.IsKeyPressed(rl.KeyboardKey.UP) {
|
game := game_init(state)
|
||||||
cur_element -= 1
|
stack_push(game)
|
||||||
}
|
case .FULLSCREEN:
|
||||||
if prev_element != cur_element {
|
case .HOW_TO_PLAY:
|
||||||
if cur_element < 0 { cur_element = len(Menu_Buttons) -1 }
|
case .EXIT:
|
||||||
if cur_element == len(Menu_Buttons) { cur_element = 0 }
|
WindowShouldExit = true
|
||||||
menu.active_element = cast(Menu_Buttons)cur_element
|
return
|
||||||
if menu.marker_tween != nil {
|
|
||||||
tween_cancel(menu.marker_tween)
|
|
||||||
}
|
|
||||||
menu.marker_tween = tween_to(
|
|
||||||
&menu.active_marker.y,
|
|
||||||
menu.menu_pos.y + f32(menu.active_element) * menu.menu_element_offset,
|
|
||||||
0.5,
|
|
||||||
ease.Ease.Back_Out,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if rl.IsKeyPressed(rl.KeyboardKey.ENTER) || rl.IsKeyPressed(rl.KeyboardKey.SPACE) {
|
|
||||||
switch menu.active_element {
|
|
||||||
case .START:
|
|
||||||
game := game_init(state)
|
|
||||||
stack_push(game)
|
|
||||||
case .FULLSCREEN:
|
|
||||||
case .HOW_TO_PLAY:
|
|
||||||
case .EXIT:
|
|
||||||
WindowShouldExit = true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,11 +72,8 @@ menu_draw :: proc(state: ^GameState) {
|
||||||
TitleSize := rl.MeasureTextEx(FontTitle, TitleText, TitleFontSize, TitleSpacing)
|
TitleSize := rl.MeasureTextEx(FontTitle, TitleText, TitleFontSize, TitleSpacing)
|
||||||
rl.DrawTextPro(FontTitle, "ARKADODGE", {WINDOWF.x - 50, 50}, {TitleSize.x, 0}, 0, 96, 3, rl.WHITE)
|
rl.DrawTextPro(FontTitle, "ARKADODGE", {WINDOWF.x - 50, 50}, {TitleSize.x, 0}, 0, 96, 3, rl.WHITE)
|
||||||
|
|
||||||
rl.DrawTextEx(FontUI, ">", menu.active_marker + {-30, 0}, 48, 2, rl.WHITE)
|
menu_list_draw(&menu.list)
|
||||||
for el, i in menu_strings {
|
|
||||||
pos := menu.menu_pos + {0, f32(i) * menu.menu_element_offset}
|
|
||||||
rl.DrawTextEx(FontUI, el, pos, 48, 2, rl.WHITE)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
menu_free :: proc(state: ^GameState) {
|
menu_free :: proc(state: ^GameState) {
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import rl "vendor:raylib"
|
||||||
|
import "core:math/ease"
|
||||||
|
|
||||||
|
MenuList :: struct($T: typeid) {
|
||||||
|
state: ^GameState,
|
||||||
|
position: Vec2,
|
||||||
|
line_size: f32,
|
||||||
|
font_size: f32,
|
||||||
|
active_element: T,
|
||||||
|
active_marker: Vec2,
|
||||||
|
tween: ^Tween,
|
||||||
|
elements: ^[T]cstring,
|
||||||
|
menu_pressed: proc(state: ^GameState, element: T),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
menu_list_update :: proc(list: ^MenuList($T)) {
|
||||||
|
prev_element := cast(i8)list.active_element
|
||||||
|
cur_element := prev_element
|
||||||
|
|
||||||
|
|
||||||
|
if rl.IsKeyPressed(rl.KeyboardKey.DOWN) {
|
||||||
|
cur_element += 1
|
||||||
|
}
|
||||||
|
if rl.IsKeyPressed(rl.KeyboardKey.UP) {
|
||||||
|
cur_element -= 1
|
||||||
|
}
|
||||||
|
if prev_element != cur_element {
|
||||||
|
if cur_element < 0 { cur_element = len(T) -1 }
|
||||||
|
if cur_element == len(T) { cur_element = 0 }
|
||||||
|
list.active_element = cast(T)cur_element
|
||||||
|
if list.tween != nil {
|
||||||
|
tween_cancel(list.tween)
|
||||||
|
}
|
||||||
|
list.tween = tween_to(
|
||||||
|
&list.active_marker.y,
|
||||||
|
f32(list.active_element) * list.line_size,
|
||||||
|
0.5,
|
||||||
|
ease.Ease.Back_Out,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if rl.IsKeyPressed(rl.KeyboardKey.ENTER) || rl.IsKeyPressed(rl.KeyboardKey.SPACE) {
|
||||||
|
list.menu_pressed(list.state, list.active_element)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
menu_list_draw :: proc(list: ^MenuList($T)) {
|
||||||
|
rl.DrawTextEx(FontUI, ">", list.position + list.active_marker + {-30, 0}, 48, 2, rl.WHITE)
|
||||||
|
for el, i in list.elements {
|
||||||
|
pos := list.position + {0, f32(i) * list.line_size}
|
||||||
|
rl.DrawTextEx(FontUI, el, pos, 48, 2, rl.WHITE)
|
||||||
|
}
|
||||||
|
}
|
78
pause.odin
78
pause.odin
|
@ -11,7 +11,7 @@ Pause_Buttons :: enum {
|
||||||
}
|
}
|
||||||
|
|
||||||
pause_strings := [Pause_Buttons]cstring {
|
pause_strings := [Pause_Buttons]cstring {
|
||||||
.RESUME = "Старт",
|
.RESUME = "Продолжить",
|
||||||
.FULLSCREEN = "Полный экран",
|
.FULLSCREEN = "Полный экран",
|
||||||
.EXIT = "Выход"
|
.EXIT = "Выход"
|
||||||
}
|
}
|
||||||
|
@ -19,23 +19,24 @@ pause_strings := [Pause_Buttons]cstring {
|
||||||
Pause :: struct {
|
Pause :: struct {
|
||||||
using state: GameState,
|
using state: GameState,
|
||||||
|
|
||||||
menu_pos: Vec2,
|
list: MenuList(Pause_Buttons)
|
||||||
menu_element_offset: f32,
|
|
||||||
active_element: Pause_Buttons,
|
|
||||||
active_marker: Vec2,
|
|
||||||
marker_tween: ^Tween,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pause_init :: proc(prev: ^GameState = nil) -> ^GameState {
|
pause_init :: proc(prev: ^GameState = nil) -> ^GameState {
|
||||||
state := new(Pause)
|
state := new(Pause)
|
||||||
state.variant = state
|
state.variant = state
|
||||||
state.menu_pos = {300, 300}
|
state.list = MenuList(Pause_Buttons){
|
||||||
state.menu_element_offset = 60
|
position = {-300, 300},
|
||||||
state.active_marker = state.menu_pos + Vec2{0, f32(state.active_element) * state.menu_element_offset}
|
line_size = 60,
|
||||||
state.update = menu_update
|
font_size = 42,
|
||||||
state.draw = menu_draw
|
elements = &pause_strings,
|
||||||
state.free = menu_free
|
menu_pressed = pause_button_pressed
|
||||||
|
}
|
||||||
|
state.update = pause_update
|
||||||
|
state.draw = pause_draw
|
||||||
|
state.free = pause_free
|
||||||
state.previous = prev
|
state.previous = prev
|
||||||
|
tween_to(&state.list.position.x, 300, 1, ease.Ease.Back_Out)
|
||||||
|
|
||||||
|
|
||||||
return state
|
return state
|
||||||
|
@ -44,55 +45,34 @@ pause_init :: proc(prev: ^GameState = nil) -> ^GameState {
|
||||||
pause_update :: proc(state: ^GameState, delta: f32) {
|
pause_update :: proc(state: ^GameState, delta: f32) {
|
||||||
menu := transmute(^Pause)state
|
menu := transmute(^Pause)state
|
||||||
|
|
||||||
prev_element := cast(i8)menu.active_element
|
menu_list_update(&menu.list)
|
||||||
cur_element := prev_element
|
}
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyboardKey.DOWN) {
|
pause_button_pressed :: proc(state: ^GameState, el: Pause_Buttons) {
|
||||||
cur_element += 1
|
switch el {
|
||||||
}
|
case .RESUME:
|
||||||
if rl.IsKeyPressed(rl.KeyboardKey.UP) {
|
stack_pop()
|
||||||
cur_element -= 1
|
case .FULLSCREEN:
|
||||||
}
|
case .EXIT:
|
||||||
if prev_element != cur_element {
|
stack_pop()
|
||||||
if cur_element < 0 { cur_element = len(Pause_Buttons) -1 }
|
stack_pop()
|
||||||
if cur_element == len(Pause_Buttons) { cur_element = 0 }
|
|
||||||
menu.active_element = cast(Pause_Buttons)cur_element
|
|
||||||
if menu.marker_tween != nil {
|
|
||||||
tween_cancel(menu.marker_tween)
|
|
||||||
}
|
|
||||||
menu.marker_tween = tween_to(
|
|
||||||
&menu.active_marker.y,
|
|
||||||
menu.menu_pos.y + f32(menu.active_element) * menu.menu_element_offset,
|
|
||||||
0.5,
|
|
||||||
ease.Ease.Back_Out,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if rl.IsKeyPressed(rl.KeyboardKey.ENTER) || rl.IsKeyPressed(rl.KeyboardKey.SPACE) {
|
|
||||||
switch menu.active_element {
|
|
||||||
case .RESUME:
|
|
||||||
stack_pop()
|
|
||||||
case .FULLSCREEN:
|
|
||||||
case .EXIT:
|
|
||||||
stack_pop()
|
|
||||||
stack_pop()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pause_draw :: proc(state: ^GameState) {
|
pause_draw :: proc(state: ^GameState) {
|
||||||
menu := transmute(^Pause)state
|
menu := transmute(^Pause)state
|
||||||
|
|
||||||
|
if state.previous != nil {
|
||||||
|
state.previous->draw()
|
||||||
|
}
|
||||||
|
|
||||||
TitleFontSize :: 96
|
TitleFontSize :: 96
|
||||||
TitleSpacing :: 3
|
TitleSpacing :: 3
|
||||||
TitleText :: "ПАУЗА"
|
TitleText :: "ПАУЗА"
|
||||||
TitleSize := rl.MeasureTextEx(FontTitle, TitleText, TitleFontSize, TitleSpacing)
|
TitleSize := rl.MeasureTextEx(FontTitle, TitleText, TitleFontSize, TitleSpacing)
|
||||||
rl.DrawTextPro(FontTitle, "ARKADODGE", {WINDOWF.x - 50, 50}, {TitleSize.x, 0}, 0, 96, 3, rl.WHITE)
|
rl.DrawTextPro(FontTitle, "ПАУЗА", {WINDOWF.x - 50, 50}, {TitleSize.x, 0}, 0, 96, 3, rl.WHITE)
|
||||||
|
|
||||||
rl.DrawTextEx(FontUI, ">", menu.active_marker + {-30, 0}, 48, 2, rl.WHITE)
|
menu_list_draw(&menu.list)
|
||||||
for el, i in menu_strings {
|
|
||||||
pos := menu.menu_pos + {0, f32(i) * menu.menu_element_offset}
|
|
||||||
rl.DrawTextEx(FontUI, el, pos, 48, 2, rl.WHITE)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pause_free :: proc(state: ^GameState) {
|
pause_free :: proc(state: ^GameState) {
|
||||||
|
|
Loading…
Reference in New Issue