#include "model.h"
#include "world_render.h"
#include "player.h"
-#include "conf.h"
#include "shaders/model_menu.h"
#include "audio.h"
#include "input.h"
+#include "workshop.h"
+#include "respawn.h"
#define MENU_STACK_SIZE 8
struct {
- int active;
- f32 factive;
+ int credits_open;
int disable_open;
u32 page, /* current page index */
- page_depth;
+ page_depth,
+ controls_page_id;
+
+ ent_menuitem *ctr_kbm,
+ *ctr_deck,
+ *ctr_ps,
+ *ctr_steam,
+ *ctr_xbox;
enum menu_input_mode{
- k_menu_input_mode_mouse,
- k_menu_input_mode_keys
+ k_menu_input_mode_keys,
+ k_menu_input_mode_mouse
}
input_mode;
f32 mouse_track, mouse_dist; /* used for waking up mouse */
/*
* Attaches memory locations to the various items in the menu
*/
-static void menu_link(void)
-{
+static void menu_link(void){
/* link data locations */
for( u32 i=0; i<mdl_arrcount(&menu.items); i++ ){
ent_menuitem *item = mdl_arritm( &menu.items, i );
item->pvoid = NULL;
}
}
+
+ /* link controllers */
+ menu.ctr_deck = NULL;
+ menu.ctr_kbm = NULL;
+ menu.ctr_ps = NULL;
+ menu.ctr_steam = NULL;
+ menu.ctr_xbox = NULL;
+
+ for( u32 i=0; i<mdl_arrcount(&menu.items); i++ ){
+ ent_menuitem *item = mdl_arritm( &menu.items, i );
+
+ if( MDL_CONST_PSTREQ( &menu.model, item->visual.pstr_name, "deck" ) )
+ menu.ctr_deck = item;
+ if( MDL_CONST_PSTREQ( &menu.model, item->visual.pstr_name, "kbm" ) )
+ menu.ctr_kbm = item;
+ if( MDL_CONST_PSTREQ( &menu.model, item->visual.pstr_name, "ps" ) )
+ menu.ctr_ps = item;
+ if( MDL_CONST_PSTREQ( &menu.model, item->visual.pstr_name, "steam" ) )
+ menu.ctr_steam = item;
+ if( MDL_CONST_PSTREQ( &menu.model, item->visual.pstr_name, "xbox" ) )
+ menu.ctr_xbox = item;
+ }
}
-static void menu_init(void)
-{
+static void menu_close(void){
+ skaterift.activity = k_skaterift_default;
+ menu.page_depth = 0;
+ menu.page = 0xffffffff;
+ srinput.enabled = 0;
+}
+
+static void menu_init(void){
void *alloc = vg_mem.rtmemory;
mdl_open( &menu.model, "models/rs_menu.mdl", alloc );
/*
* Drop back a page until we're at the bottom which then we jus quit
*/
-static void menu_back_page(void)
-{
+static void menu_back_page(void){
vg_info( "menu_back_page()\n" );
menu.page_depth --;
if( menu.page_depth == 0 ){
- menu.active = 0;
- menu.page = 0xffffffff;
+ menu_close();
}
else{
menu.page = menu.page_stack[ menu.page_depth ].page;
/*
* Open page to the string identifier
*/
-static void menu_open_page( const char *name )
-{
+static void menu_open_page( const char *name ){
if( menu.page_depth >= MENU_STACK_SIZE )
vg_fatal_error( "Stack overflow\n" );
/*
* activate a pressable type
*/
-static void menu_trigger_item( ent_menuitem *item )
-{
+static void menu_trigger_item( ent_menuitem *item ){
if ( item->type == k_ent_menuitem_type_event_button ){
u32 q = item->button.pstr;
if( MDL_CONST_PSTREQ( &menu.model, q, "quit" ) ){
vg.window_should_close = 1;
}
- else if( MDL_CONST_PSTREQ( &menu.model, q, "reset" ) ){
+
+ /* DEPRECATED? */
+ else if( MDL_CONST_PSTREQ( &menu.model, q, "reset_nearest" ) ){
localplayer_cmd_respawn( 0, NULL );
-
- menu.page_depth = 0;
- menu.active = 0;
- menu.page = 0xffffffff;
+ menu_close();
+ }
+ /* DEPRECATED? */
+ else if( MDL_CONST_PSTREQ( &menu.model, q, "reset_home" ) ){
+ world_set_active_instance( 0 );
+ localplayer.viewable_world = world_current_instance();
+ localplayer_cmd_respawn( 1, (const char *[]){"start"} );
+ menu_close();
+ }
+
+ else if( MDL_CONST_PSTREQ( &menu.model, q, "reset" ) ){
+ menu_close();
+ respawn_begin_chooser();
+ }
+
+ else if( MDL_CONST_PSTREQ( &menu.model, q, "credits" ) ){
+ menu.credits_open = 1;
+ }
+ else if( MDL_CONST_PSTREQ( &menu.model, q, "workshop" ) ){
+ workshop_submit_command(0,NULL);
}
}
else if( item->type == k_ent_menuitem_type_page_button ){
}
}
-static f32 menu_slider_snap( f32 value, f32 old, f32 notch )
-{
+static f32 menu_slider_snap( f32 value, f32 old, f32 notch ){
f32 const k_epsilon = 0.0125f;
if( fabsf(notch-value) < k_epsilon ){
return value;
}
+static void menu_setitem_type( ent_menuitem *item,
+ enum ent_menuitem_type type ){
+ if( !item ) return;
+ item->type = type;
+}
+
/*
* Run from vg_gui every frame
*/
-static void menu_update(void)
-{
+static void menu_update(void){
+ if( workshop_form.page != k_workshop_form_hidden ){
+ return;
+ }
+
+ int escape = button_down( k_srbind_mback );
+ if( menu.credits_open ){
+ if( escape ){
+ menu.credits_open = 0;
+ }
+ return;
+ }
+
if( button_down( k_srbind_mopen ) ){
- if( !menu.active && !menu.disable_open ){
- menu.active = 1;
+ if( skaterift.activity == k_skaterift_default ){
+ skaterift.activity = k_skaterift_menu;
menu.page = 0xffffffff;
menu_open_page( "Main Menu" );
return;
}
}
- menu.factive = vg_lerpf( menu.factive, menu.active,
- vg.time_frame_delta * 6.0f );
-
- if( !menu.active ) return;
-
+ if( skaterift.activity != k_skaterift_menu ) return;
enum menu_input_mode prev_mode = menu.input_mode;
/* get buttons inputs
md = button_down( k_srbind_mdown ),
mh = ml-mr,
mv = mu-md,
- enter = button_down( k_srbind_maccept ),
- escape = button_down( k_srbind_mback );
+ enter = button_down( k_srbind_maccept );
if( mh||mv||enter ){
menu.input_mode = k_menu_input_mode_keys;
}
}
}
+
+ menu_setitem_type( menu.ctr_deck, k_ent_menuitem_type_disabled );
+ menu_setitem_type( menu.ctr_ps, k_ent_menuitem_type_disabled );
+ menu_setitem_type( menu.ctr_kbm, k_ent_menuitem_type_disabled );
+ menu_setitem_type( menu.ctr_xbox, k_ent_menuitem_type_disabled );
+ menu_setitem_type( menu.ctr_steam, k_ent_menuitem_type_disabled );
+
+ if( vg_input.display_input_method == k_input_method_kbm )
+ menu_setitem_type( menu.ctr_kbm, k_ent_menuitem_type_visual );
+ else{
+ if( vg_input.display_input_type == SDL_CONTROLLER_TYPE_PS3 ||
+ vg_input.display_input_type == SDL_CONTROLLER_TYPE_PS4 ||
+ vg_input.display_input_type == SDL_CONTROLLER_TYPE_PS5 ){
+ menu_setitem_type( menu.ctr_ps, k_ent_menuitem_type_visual );
+ }
+ else {
+ menu_setitem_type( menu.ctr_xbox, k_ent_menuitem_type_visual );
+ }
+ /* FIXME: Steam/Deck controller detection? */
+ }
}
/*
* Run from vg_gui when active
*/
-VG_STATIC void menu_render(void)
-{
+VG_STATIC void menu_render(void){
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
shader_blitcolour_uColour( colour );
render_fsquad();
+ if( (workshop_form.page != k_workshop_form_hidden) ||
+ (vg_ui.focused_control_type != k_ui_control_none) ){
+ return;
+ }
+
+ if( menu.credits_open ){
+ ui_rect panel = { 0,0, 460, 400 },
+ screen = { 0,0, vg.window_x,vg.window_y };
+ ui_rect_center( screen, panel );
+ ui_fill( panel, ui_colour(k_ui_bg) );
+ ui_outline( panel, 1, ui_colour(k_ui_fg), 0 );
+ ui_rect_pad( panel, (ui_px[]){8,8} );
+
+ ui_rect title;
+ ui_split( panel, k_ui_axis_h, 28*2, 0, title, panel );
+ ui_text( title, "Skate Rift - Credits", 2, k_ui_align_middle_center, 0 );
+ ui_split( panel, k_ui_axis_h, 28, 0, title, panel );
+ ui_text( title, "Mt.Zero Software", 1, k_ui_align_middle_center, 0 );
+
+ ui_split( panel, k_ui_axis_h, 8, 0, title, panel );
+ ui_split( panel, k_ui_axis_h, 28, 0, title, panel );
+ ui_text( title, "A game by Harry Godden", 1,
+ k_ui_align_middle_center, 0 );
+
+ ui_split( panel, k_ui_axis_h, 8, 0, title, panel );
+ ui_split( panel, k_ui_axis_h, 28*2, 0, title, panel );
+ ui_text( title, "Free Software", 2, k_ui_align_middle_center, 0 );
+
+ ui_split( panel, k_ui_axis_h, 8, 0, title, panel );
+ ui_text( panel,
+ "Sam Lantinga - SDL2 - libsdl.org\n"
+ "Hunter WB - Anyascii\n"
+ "David Herberth - GLAD\n"
+ "Dominic Szablewski - QOI - qoiformat.org\n"
+ "Sean Barrett - stb_image,stb_vorbis,stb_include\n"
+ "Khronos Group - OpenGL\n"
+ , 1, k_ui_align_left, 0 );
+ return;
+ }
+
glEnable( GL_DEPTH_TEST );
glDisable( GL_BLEND );
for( u32 i=0; i<mdl_arrcount(&menu.items); i++ ){
ent_menuitem *item = mdl_arritm( &menu.items, i );
+ if( item->type == k_ent_menuitem_type_disabled ) continue;
if( item->type == k_ent_menuitem_type_page ) continue;
if( !(item->groups & (0x1 << menu.page)) ) continue;