From 2179a91415c4d0726fd134ad942acfc0515844eb Mon Sep 17 00:00:00 2001 From: hgn Date: Fri, 10 Nov 2023 22:04:06 +0000 Subject: [PATCH] initial gui for remote players lobby --- input.h | 9 +++++-- player_remote.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ player_remote.h | 3 +++ skaterift.c | 28 ++++++++++++++++++- steam.h | 2 +- 5 files changed, 110 insertions(+), 4 deletions(-) diff --git a/input.h b/input.h index 7e1e6aa..aa546c9 100644 --- a/input.h +++ b/input.h @@ -32,6 +32,7 @@ enum sr_bind{ k_srbind_world_left, k_srbind_world_right, k_srbind_home, + k_srbind_lobby, k_srbind_max, }; @@ -125,7 +126,8 @@ static const char *button_display_string( enum sr_bind button ) [k_srbind_replay_play]= controller_glyph( SDL_CONTROLLER_BUTTON_X ), [k_srbind_replay_freecam]=controller_glyph(SDL_CONTROLLER_BUTTON_Y ), [k_srbind_replay_resume]=controller_glyph( SDL_CONTROLLER_BUTTON_A ), - [k_srbind_sit] = controller_glyph( SDL_CONTROLLER_BUTTON_B ) + [k_srbind_sit] = controller_glyph( SDL_CONTROLLER_BUTTON_B ), + [k_srbind_lobby] = controller_glyph( SDL_CONTROLLER_BUTTON_DPAD_LEFT ) }; const char *keyboard_table[ k_srbind_max ] = { @@ -150,7 +152,8 @@ static const char *button_display_string( enum sr_bind button ) [k_srbind_replay_play]= KEYBOARD_GLYPH( "G" ), [k_srbind_replay_freecam] = KEYBOARD_GLYPH( "F" ), [k_srbind_replay_resume]= "\xa1", - [k_srbind_sit] = KEYBOARD_GLYPH( "Z" ) + [k_srbind_sit] = KEYBOARD_GLYPH( "Z" ), + [k_srbind_lobby] = KEYBOARD_GLYPH( "" ) // FIXME: what is tab? }; if( vg_input.display_input_method == k_input_method_controller ) @@ -315,6 +318,7 @@ static void skaterift_preupdate_inputs(void) setbtn( k_srbind_replay_freecam, vg_getkey(SDLK_f) ); setbtn( k_srbind_replay_resume, vg_getkey(SDLK_SPACE) ); setbtn( k_srbind_sit, vg_getkey(SDLK_z) ); + setbtn( k_srbind_lobby, vg_getkey(SDLK_TAB) ); /* axis * --------------------------------------------*/ @@ -376,6 +380,7 @@ static void skaterift_preupdate_inputs(void) setbtn( k_srbind_replay_play, buttons[ SDL_CONTROLLER_BUTTON_X ] ); setbtn( k_srbind_replay_freecam, buttons[ SDL_CONTROLLER_BUTTON_Y ] ); setbtn( k_srbind_sit, buttons[ SDL_CONTROLLER_BUTTON_B ] ); + setbtn( k_srbind_lobby, buttons[ SDL_CONTROLLER_BUTTON_DPAD_LEFT ] ); float *axis = controller->axises; float *steer = srinput.joystick_states[ k_srjoystick_steer ][0], diff --git a/player_remote.c b/player_remote.c index fac5ea7..6358daa 100644 --- a/player_remote.c +++ b/player_remote.c @@ -682,3 +682,75 @@ static void remote_sfx_pre_update(void){ } } } + +enum remote_player_gui_type { + k_remote_player_gui_type_stranger, + k_remote_player_gui_type_you, + k_remote_player_gui_type_friend +}; + +static void remote_player_gui_info( ui_rect box, + const char *username, + const char *activity, + enum remote_player_gui_type type, + int in_world ){ + + f32 opacity = in_world? 0.6f: 0.3f; + + if( type == k_remote_player_gui_type_you ) + ui_fill( box, ui_opacity( 0xff555555, opacity ) ); + else + ui_fill( box, ui_opacity( 0xff000000, opacity ) ); + + if( type == k_remote_player_gui_type_friend ) + ui_outline( box, -1, ui_opacity( 0xff00c4f0, opacity ), 0 ); + + ui_rect top, bottom; + ui_split_ratio( box, k_ui_axis_h, 0.6666f, 1, top, bottom ); + + u32 fg = ui_colour( in_world? k_ui_fg: k_ui_fg+4 ); + + vg_ui.font = &vg_ui_font_big; + ui_text( top, username, 1, k_ui_align_middle_center, fg ); + vg_ui.font = &vg_ui_font_small; + + ui_text( bottom, activity, 1, k_ui_align_middle_center, fg ); +} + +static void remote_players_imgui(void){ + /* TODO: or if respawning, override show this and disable input + * if in menu dont render. */ + + if( button_down(k_srbind_lobby) ) + netplayers.view_lobby ^= 0x1; + + vg_slewf( &netplayers.fview_lobby, netplayers.view_lobby, + vg.time_frame_delta / 0.5f ); + + ui_px y = 50, width = 200, height = 42, gap = 2, + x = vg.window_x - ((f32)width*netplayers.fview_lobby); + + int type = vg.time, + in_world = vg.time / 3.0; + + + vg_ui.font = &vg_ui_font_big; + ui_text( (ui_rect){ x, 0, width, height }, + "In World", 1, k_ui_align_middle_center, 0 ); + vg_ui.font = &vg_ui_font_small; + + + ui_rect us = { x, y, width, height }; + remote_player_gui_info( us, steam_username_at_startup, "1300 meters away", + type % 3, in_world % 2 ); + y += height + gap; + + for( u32 i=0; iactive || !player->isfriend ) continue; + + ui_rect box = { x, y, width, height }; + remote_player_gui_info( box, player->username, "", 0, 0 ); + y += height + gap; + } +} diff --git a/player_remote.h b/player_remote.h index 4df9c32..580a726 100644 --- a/player_remote.h +++ b/player_remote.h @@ -58,6 +58,9 @@ struct { u32 up_bytes; f32 up_kbs, down_kbs; f64 last_data_measurement; + + int view_lobby; + f32 fview_lobby; } static netplayers; diff --git a/skaterift.c b/skaterift.c index 34e42f3..0e1f852 100644 --- a/skaterift.c +++ b/skaterift.c @@ -58,6 +58,7 @@ #include "vg/vg_audio_dsp.h" static struct player_avatar localplayer_avatar; +static int k_tools_mode = 0; int main( int argc, char *argv[] ){ vg_mem.use_libc_malloc = 0; @@ -76,6 +77,10 @@ static void vg_launch_opt(void){ vg_strncpy( arg, network_client.server_adress, 64, k_strncpy_overflow_fatal ); } + + if( vg_long_opt( "tools" ) ){ + k_tools_mode = 1; + } } static void vg_preload(void){ @@ -89,6 +94,9 @@ vg_info(" | \\/ | | / | | \\ | / | \n" ); vg_info(" ' ' '--' [] '----- '----- ' ' '---' " "SOFTWARE\n" ); + if( k_tools_mode ) + return; + steam_init(); vg_loader_step( NULL, steam_end ); vg_loader_step( remote_players_init, NULL ); @@ -177,6 +185,11 @@ static void skaterift_restore_state(void){ } static void vg_load(void){ + if( k_tools_mode ){ + vg_async_call( async_call_ready, NULL, 0 ); + return; + } + vg_console_reg_cmd( "changeworld", skaterift_change_world_command, NULL ); vg_loader_step( render_init, NULL ); @@ -303,9 +316,11 @@ static void skaterift_change_client_world_preupdate(void); static void vg_pre_update(void){ srinput.enabled = 1; + skaterift_preupdate_inputs(); + + if( k_tools_mode ) return; steam_update(); - skaterift_preupdate_inputs(); if( skaterift.op == k_async_op_clientloading ) return; if( world_static.load_state == k_world_loader_preload ) skaterift_change_client_world_preupdate(); @@ -335,6 +350,7 @@ static void vg_pre_update(void){ } static void vg_fixed_update(void){ + if( k_tools_mode ) return; if( skaterift.op == k_async_op_clientloading ) return; world_routes_fixedupdate( world_current_instance() ); @@ -343,6 +359,7 @@ static void vg_fixed_update(void){ } static void vg_post_update(void){ + if( k_tools_mode ) return; if( skaterift.op == k_async_op_clientloading ) return; player__post_update(); @@ -612,6 +629,14 @@ static void render_main_game(void){ } static void vg_render(void){ + if( k_tools_mode ){ + glBindFramebuffer( GL_FRAMEBUFFER, 0 ); + glViewport( 0,0, vg.window_x, vg.window_y ); + glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); + glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT ); + return; + } + if( skaterift.op == k_async_op_clientloading ){ _vg_loader_render(); return; @@ -653,6 +678,7 @@ static void vg_gui(void){ workshop_form_gui(); render_view_framebuffer_ui(); remote_player_network_imgui( vg.pv ); + remote_players_imgui(); } diff --git a/steam.h b/steam.h index 2c8bd2d..cbe88ee 100644 --- a/steam.h +++ b/steam.h @@ -27,7 +27,7 @@ * nothing. */ -static char steam_username_at_startup[128]; +static char steam_username_at_startup[128] = "Unassigned"; static void recv_steam_warning( int severity, const char *msg ) { -- 2.25.1