X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=workshop.c;h=30aaf7a376b5be2fe1933fb46cb36ed50bcf4bdb;hb=e8a65239f85784e2e596d2622c2baddda9fb5fae;hp=18c7c3c321d0b061f6037afa740a713a7b303314;hpb=1f7014d965883820f984877b8ca15c1e439cf9cf;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/workshop.c b/workshop.c index 18c7c3c..30aaf7a 100644 --- a/workshop.c +++ b/workshop.c @@ -18,7 +18,8 @@ struct workshop_form{ char description[512]; PublishedFileId_t file_id; /* 0 if not published yet */ - ERemoteStoragePublishedFileVisibility visibility; + + struct ui_dropdown_value visibility; int submit_title, /* set if the respective controls are touched */ submit_description, @@ -36,20 +37,11 @@ struct workshop_form{ } page; - enum workshop_form_operation{ - k_workshop_form_op_none, - k_workshop_form_op_loading_model, - k_workshop_form_op_downloading_submission, - k_workshop_form_op_publishing_update, - } - operation; - /* model viewer * ----------------------------- */ char model_path[128]; - struct player_board board_model; /* what does the user want to do with the image preview? */ @@ -107,28 +99,12 @@ struct workshop_form{ } static workshop_form; -/* - * Start a new operation and crash if we are already running one. - */ -VG_STATIC void workshop_begin_op( enum workshop_form_operation op ) -{ - if( workshop_form.operation != k_workshop_form_op_none ){ - vg_fatal_error( "Workshop form currently executing op(%d), tried to " - "start op(%d)\n", workshop_form.operation, op ); - } - - workshop_form.operation = op; - vg_info( "Starting op( %d )\n", op ); -} - -/* - * Finished operation, otheres can now run - */ -VG_STATIC void workshop_end_op(void) -{ - vg_info( "Finishing op( %d )\n", workshop_form.operation ); - workshop_form.operation = k_workshop_form_op_none; -} +static struct ui_dropdown_opt workshop_form_visibility_opts[] = { + { "Public", k_ERemoteStoragePublishedFileVisibilityPublic }, + { "Unlisted", k_ERemoteStoragePublishedFileVisibilityUnlisted }, + { "Friends Only", k_ERemoteStoragePublishedFileVisibilityFriendsOnly }, + { "Private", k_ERemoteStoragePublishedFileVisibilityPrivate }, +}; /* * Close the form and discard UGC query result @@ -148,6 +124,7 @@ VG_STATIC void workshop_quit_form(void) } workshop_form.page = k_workshop_form_hidden; + workshop_end_op(); } /* @@ -158,6 +135,11 @@ VG_STATIC void workshop_reset_submission_data(void) workshop_form.submission.file_id = 0; /* assuming id of 0 is none/invalid */ workshop_form.submission.description[0] = '\0'; workshop_form.submission.title[0] = '\0'; + + workshop_form.submission.visibility.value = + k_ERemoteStoragePublishedFileVisibilityPublic; + workshop_form.submission.visibility.index = 0; + workshop_form.model_path[0] = '\0'; player_board_unload( &workshop_form.board_model ); workshop_form.file_intent = k_workshop_form_file_intent_none; @@ -301,7 +283,7 @@ VG_STATIC void workshop_form_async_package_complete( void *data, u32 size ) vg_info( "Setting visibility\n" ); SteamAPI_ISteamUGC_SetItemVisibility( hSteamUGC, handle, - workshop_form.submission.visibility ); + workshop_form.submission.visibility.value ); vg_info( "Submitting updates\n" ); vg_steam_async_call *call = vg_alloc_async_steam_api_call(); @@ -315,6 +297,9 @@ VG_STATIC void workshop_form_async_package_complete( void *data, u32 size ) */ struct workshop_package_thread_args{ PublishedFileId_t file_id; + + u64_steamid steamid; + char username[32]; }; VG_STATIC void _workshop_package_thread( void *_args ) { @@ -357,6 +342,40 @@ VG_STATIC void _workshop_package_thread( void *_args ) return; } + /* write the metadata file */ + struct workshop_file_info meta; + meta.author = args->steamid; + vg_strncpy( args->username, meta.author_name, vg_list_size(meta.author_name), + k_strncpy_always_add_null ); + vg_strncpy( workshop_form.submission.title, meta.title, + vg_list_size(meta.title), k_strncpy_always_add_null ); + + char _path[1024]; + vg_str path; + vg_strnull( &path, _path, vg_list_size( _path ) ); + vg_strcat( &path, info->abs_content_file ); + vg_strcat( &path, ".inf" ); + + if( vg_strgood( &path ) ){ + FILE *fp = fopen( _path, "wb" ); + + if( fp ){ + fwrite( &meta, sizeof(struct workshop_file_info), 1, fp ); + fclose( fp ); + } + else{ + info->success = 0; + info->failure_reason = "Cant write .inf file"; + vg_async_dispatch( call, workshop_form_async_package_complete ); + } + } + else{ + info->success = 0; + info->failure_reason = "Path too long"; + vg_async_dispatch( call, workshop_form_async_package_complete ); + return; + } + info->success = 1; vg_async_dispatch( call, workshop_form_async_package_complete ); } @@ -371,6 +390,16 @@ VG_STATIC void workshop_package_submission( PublishedFileId_t file_id ) vg_linear_alloc( vg_mem.scratch, sizeof(struct workshop_package_thread_args)); + ISteamFriends *hSteamFriends = SteamAPI_SteamFriends(); + ISteamUser *hSteamUser = SteamAPI_SteamUser(); + + args->steamid = SteamAPI_ISteamUser_GetSteamID( hSteamUser ); + + const char *username = SteamAPI_ISteamFriends_GetPersonaName(hSteamFriends); + str_utf8_collapse( username, args->username, vg_list_size( args->username )); + vg_info( "Steamid: "PRINTF_U64", Name: %s(%s)\n", + args->steamid, username, args->username ); + args->file_id = file_id; vg_loader_start( _workshop_package_thread, args ); } @@ -390,7 +419,7 @@ VG_STATIC void on_workshop_createitem( void *data, void *user ) if( result->m_bUserNeedsToAcceptWorkshopLegalAgreement ){ vg_warn( "Workshop agreement currently not accepted\n" ); } - + workshop_package_submission( result->m_nPublishedFileId ); } else{ @@ -414,7 +443,20 @@ VG_STATIC void workshop_form_async_submit_begin( void *payload, u32 size ) { /* use existing file */ if( workshop_form.submission.file_id ){ - workshop_package_submission( workshop_form.submission.file_id ); + if( workshop_form.submission.submit_file_and_image ){ + workshop_package_submission( workshop_form.submission.file_id ); + } + else{ + struct workshop_package_info info; + info.abs_content_file[0] = '\0'; + info.abs_content_folder[0] = '\0'; + info.abs_preview_image[0] = '\0'; + info.failure_reason = NULL; + info.publishing_file_id = workshop_form.submission.file_id; + info.success = 1; + workshop_form_async_package_complete( &info, + sizeof(struct workshop_package_info) ); + } } else{ vg_steam_async_call *call = vg_alloc_async_steam_api_call(); @@ -422,7 +464,7 @@ VG_STATIC void workshop_form_async_submit_begin( void *payload, u32 size ) call->p_handler = on_workshop_createitem; ISteamUGC *hSteamUGC = SteamAPI_SteamUGC(); call->id = SteamAPI_ISteamUGC_CreateItem( hSteamUGC, SKATERIFT_APPID, - k_EWorkshopFileTypeCommunity ); + k_EWorkshopFileTypeCommunity ); } } @@ -521,13 +563,29 @@ VG_STATIC void workshop_form_loadmodel_async_complete( void *payload, u32 size ) workshop_end_op(); } +/* + * Reciever for failure to load + */ +VG_STATIC void workshop_form_loadmodel_async_error( void *payload, u32 size ) +{ + workshop_end_op(); +} + /* * Thread which loads the model from the disk */ VG_STATIC void _workshop_form_load_thread( void *data ) { - player_board_load( &workshop_form.board_model, workshop_form.model_path ); - vg_async_call( workshop_form_loadmodel_async_complete, NULL, 0 ); + FILE *test = fopen( workshop_form.model_path, "rb" ); + if( test ){ + fclose( test ); + player_board_load( &workshop_form.board_model, workshop_form.model_path ); + vg_async_call( workshop_form_loadmodel_async_complete, NULL, 0 ); + } + else{ + vg_error( "workshop async load failed: file not found\n" ); + vg_async_call( workshop_form_loadmodel_async_error, NULL, 0 ); + } } /* @@ -631,6 +689,9 @@ VG_STATIC void workshop_op_download_and_view_submission( int result_index ) { workshop_begin_op( k_workshop_form_op_downloading_submission ); workshop_reset_submission_data(); + workshop_form.submission.submit_description = 0; + workshop_form.submission.submit_file_and_image = 0; + workshop_form.submission.submit_title = 0; vg_strncpy( details.m_rgchDescription, workshop_form.submission.description, @@ -649,6 +710,14 @@ VG_STATIC void workshop_op_download_and_view_submission( int result_index ) workshop_form.submission.file_id = details.m_nPublishedFileId; workshop_form.file_intent = k_workshop_form_file_intent_keep_old; workshop_form.page = k_workshop_form_edit; + workshop_form.submission.visibility.value = details.m_eVisibility; + + for( i32 i=0; iabs_preview_image, 1024, - "%smodels/boards/workshop/%lu.jpg", + "%smodels/boards/workshop/" PRINTF_U64 ".jpg", vg.base_path, details.m_hPreviewFile ); call->p_handler = on_workshop_download_ugcpreview; @@ -672,7 +741,8 @@ VG_STATIC void workshop_op_download_and_view_submission( int result_index ) hSteamRemoteStorage, details.m_hPreviewFile, info->abs_preview_image, 1 ); - vg_info( "preview file id: %lu\n", details.m_hPreviewFile ); + vg_info( "preview file id: " PRINTF_U64 "\n", + details.m_hPreviewFile ); } } else{ @@ -944,7 +1014,7 @@ VG_STATIC void workshop_changed_description( char *buf, u32 len ){ VG_STATIC void workshop_form_gui_edit_page( ui_rect content ) { ui_rect image_plane; - ui_split_px( content, k_ui_axis_h, 300, 0, image_plane, content ); + ui_split( content, k_ui_axis_h, 300, 0, image_plane, content ); ui_fill( image_plane, ui_colour( k_ui_bg+0 ) ); ui_rect img_box; @@ -1010,11 +1080,12 @@ VG_STATIC void workshop_form_gui_edit_page( ui_rect content ) } /* file path */ - ui_rect null, file_entry, file_button; - ui_split_px( content, k_ui_axis_h, 8, 0, null, content ); - ui_split_px( content, k_ui_axis_h, 28, 0, file_entry, content ); - ui_split_px( file_entry, k_ui_axis_v, file_entry[2]-128, 0, - file_entry, file_button ); + ui_rect null, file_entry, file_button, file_label; + ui_split( content, k_ui_axis_h, 8, 0, null, content ); + ui_split( content, k_ui_axis_h, 28, 0, file_entry, content ); + ui_split( file_entry, k_ui_axis_v, -128, 0, file_entry, file_button ); + ui_split_label( file_entry, "File:", 1, 8, file_label, file_entry ); + ui_text( file_label, "File:", 1, k_ui_align_middle_left, 0 ); if( workshop_form.file_intent != k_workshop_form_file_intent_none ){ ui_text( file_entry, workshop_form.model_path, 1, k_ui_align_middle_left, @@ -1041,13 +1112,17 @@ VG_STATIC void workshop_form_gui_edit_page( ui_rect content ) } ui_rect title_entry, label; - ui_split_px( content, k_ui_axis_h, 8, 0, null, content ); - ui_split_px( content, k_ui_axis_h, 28, 0, title_entry, content ); + ui_split( content, k_ui_axis_h, 8, 0, null, content ); + ui_split( content, k_ui_axis_h, 28, 0, title_entry, content ); const char *str_title = "Title:", *str_desc = "Description:"; - ui_split_px( title_entry, k_ui_axis_v, + ui_split( title_entry, k_ui_axis_v, ui_text_line_width(str_title)+8, 0, label, title_entry ); + ui_rect vis_dropdown; + ui_split_ratio( title_entry, k_ui_axis_v, 0.6f, 16, + title_entry, vis_dropdown ); + /* title box */ { struct ui_textbox_callbacks callbacks = { @@ -1058,15 +1133,21 @@ VG_STATIC void workshop_form_gui_edit_page( ui_rect content ) vg_list_size(workshop_form.submission.title), 0, &callbacks ); } + /* visibility option */ + { + ui_enum( vis_dropdown, "Visibility:", workshop_form_visibility_opts, + 4, &workshop_form.submission.visibility ); + } + /* description box */ { struct ui_textbox_callbacks callbacks = { .change = workshop_changed_description }; ui_rect desc_entry; - ui_split_px( content, k_ui_axis_h, 8, 0, null, content ); - ui_split_px( content, k_ui_axis_h, 28, 0, label, content ); - ui_split_px( content, k_ui_axis_h, 28*4, 0, desc_entry, content ); + ui_split( content, k_ui_axis_h, 8, 0, null, content ); + ui_split( content, k_ui_axis_h, 28, 0, label, content ); + ui_split( content, k_ui_axis_h, 28*4, 0, desc_entry, content ); ui_text( label, str_desc, 1, k_ui_align_middle_left, 0 ); ui_textbox( desc_entry, workshop_form.submission.description, vg_list_size(workshop_form.submission.description), @@ -1075,8 +1156,8 @@ VG_STATIC void workshop_form_gui_edit_page( ui_rect content ) /* submissionable */ ui_rect submission_row; - ui_split_px( content, k_ui_axis_h, 8, 0, null, content ); - ui_split_px( content, k_ui_axis_h, content[3]-32-8, 0, content, + ui_split( content, k_ui_axis_h, 8, 0, null, content ); + ui_split( content, k_ui_axis_h, content[3]-32-8, 0, content, submission_row ); ui_rect submission_center; @@ -1092,17 +1173,18 @@ VG_STATIC void workshop_form_gui_edit_page( ui_rect content ) workshop_op_submit(); } if( ui_button_text( btn_right, "Cancel", 1 ) ){ - vg_info( "left\n" ); + workshop_form.page = k_workshop_form_open; + player_board_unload( &workshop_form.board_model ); + workshop_form.file_intent = k_workshop_form_file_intent_none; } /* disclaimer */ - /* TODO!! OPEN THIS LINK */ const char *disclaimer_text = "By submitting this item, you agree to the workshop terms of service"; ui_rect disclaimer_row, inner, link; - ui_split_px( content, k_ui_axis_h, 8, 0, null, content ); - ui_split_px( content, k_ui_axis_h, content[3]-32, 0, content, + ui_split( content, k_ui_axis_h, 8, 0, null, content ); + ui_split( content, k_ui_axis_h, content[3]-32, 0, content, disclaimer_row ); ui_px btn_width = 32; @@ -1111,8 +1193,8 @@ VG_STATIC void workshop_form_gui_edit_page( ui_rect content ) inner[2] = ui_text_line_width( disclaimer_text ) + btn_width+8; ui_rect_center( disclaimer_row, inner ); - ui_split_px( inner, k_ui_axis_v, inner[2]-btn_width, 0, label, btn_right); - ui_rect_pad( btn_right, 2 ); + ui_split( inner, k_ui_axis_v, inner[2]-btn_width, 0, label, btn_right); + ui_rect_pad( btn_right, (ui_px[2]){2,2} ); if( ui_button_text( btn_right, "\x91", 2 ) ){ ISteamFriends *hSteamFriends = SteamAPI_SteamFriends(); @@ -1133,29 +1215,23 @@ VG_STATIC void workshop_form_gui_sidebar( ui_rect sidebar ) ui_fill( sidebar, ui_colour( k_ui_bg+2 ) ); ui_rect title; - ui_split_px( sidebar, k_ui_axis_h, 28, 0, title, sidebar ); + ui_split( sidebar, k_ui_axis_h, 28, 0, title, sidebar ); ui_text( title, "Your submissions", 1, k_ui_align_middle_center, 0 ); ui_rect controls, btn_create_new; - ui_split_px( sidebar, k_ui_axis_h, 32, 0, controls, sidebar ); - ui_split_px( sidebar, k_ui_axis_h, sidebar[3]-32, 0, - sidebar, btn_create_new ); + ui_split( sidebar, k_ui_axis_h, 32, 0, controls, sidebar ); + ui_split( sidebar, k_ui_axis_h, -32, 0, sidebar, btn_create_new ); ui_fill( controls, ui_colour( k_ui_bg+1 ) ); - ui_outline( controls, -1, ui_colour( k_ui_bg+4 ) ); char buf[32]; strcpy( buf, "page " ); int i = 5; - - /* TODO: for what it is, this code is getting a bit.. special */ - if( workshop_form.view_published_page_id ) - i += highscore_intl( buf+i, workshop_form.view_published_page_id, 4 ); - else buf[ i ++ ] = '0'; - ; + i += highscore_intl( buf+i, workshop_form.view_published_page_id+1, 4 ); buf[ i ++ ] = '/'; i += highscore_intl( buf+i, workshop_form.view_published_page_count, 4 ); buf[ i ++ ] = '\0'; + ui_rect_pad( controls, (ui_px[2]){0,4} ); ui_rect info; ui_split_ratio( controls, k_ui_axis_v, 0.25f, 0, info, controls ); ui_text( info, buf, 1, k_ui_align_middle_center, 0 ); @@ -1182,8 +1258,8 @@ VG_STATIC void workshop_form_gui_sidebar( ui_rect sidebar ) for( int i=0; ititle, 1 ) ){ @@ -1213,15 +1289,15 @@ VG_STATIC void workshop_form_gui(void) ui_outline( window, 1, ui_colour( k_ui_bg+7 ) ); ui_rect title, panel; - ui_split_px( window, k_ui_axis_h, 28, 0, title, panel ); + ui_split( window, k_ui_axis_h, 28, 0, title, panel ); ui_fill( title, ui_colour( k_ui_bg+7 ) ); ui_text( title, "Workshop tool", 1, k_ui_align_middle_center, ui_colourcont(k_ui_bg+7) ); ui_rect quit_button; - ui_split_px( title, k_ui_axis_v, title[2]-title[3], 2, title, quit_button ); + ui_split( title, k_ui_axis_v, title[2]-title[3], 2, title, quit_button ); - if( workshop_form.operation == k_workshop_form_op_none ){ + if( workshop.operation == k_workshop_form_op_none ){ if( ui_button_text( quit_button, "X", 1 ) ){ workshop_quit_form(); return; @@ -1234,11 +1310,11 @@ VG_STATIC void workshop_form_gui(void) * escapes here and we show them a basic string */ - if( workshop_form.operation != k_workshop_form_op_none ){ + if( workshop.operation != k_workshop_form_op_none ){ const char *op_string = "The programmer has not bothered to describe " "the current operation that is running."; - switch(workshop_form.operation){ + switch(workshop.operation){ case k_workshop_form_op_loading_model: op_string = "Operation in progress: Loading model file."; break; @@ -1272,7 +1348,7 @@ VG_STATIC void workshop_form_gui(void) ui_split_ratio( panel, k_ui_axis_v, 0.3f, 1, sidebar, content ); /* content page */ - ui_rect_pad( content, 8 ); + ui_rect_pad( content, (ui_px[2]){8,8} ); if( stable_page == k_workshop_form_edit ){ workshop_form_gui_edit_page( content ); @@ -1283,7 +1359,7 @@ VG_STATIC void workshop_form_gui(void) } else if( stable_page >= k_workshop_form_cclosing ){ ui_rect submission_row; - ui_split_px( content, k_ui_axis_h, content[3]-32-8, 0, content, + ui_split( content, k_ui_axis_h, content[3]-32-8, 0, content, submission_row ); u32 colour; @@ -1300,7 +1376,7 @@ VG_STATIC void workshop_form_gui(void) rect_copy( submission_row, submission_center ); submission_center[2] = 128; ui_rect_center( submission_row, submission_center ); - ui_rect_pad( submission_center, 8 ); + ui_rect_pad( submission_center, (ui_px[2]){8,8} ); if( ui_button_text( submission_center, "OK", 1 ) ){ workshop_form.page = k_workshop_form_open; @@ -1310,4 +1386,73 @@ VG_STATIC void workshop_form_gui(void) workshop_form_gui_sidebar( sidebar ); } +/* + * Some async api stuff + * ----------------------------------------------------------------------------- + */ + +VG_STATIC void async_workshop_get_filepath( void *data, u32 len ) +{ + struct async_workshop_filepath_info *info = data; + + u64 _size; + u32 _ts; + + ISteamUGC *hSteamUGC = SteamAPI_SteamUGC(); + if( !SteamAPI_ISteamUGC_GetItemInstallInfo( hSteamUGC, info->id, &_size, + info->buf, info->len, &_ts )) + { + info->buf[0] = '\0'; + } +} + +VG_STATIC void async_workshop_get_installed_files( void *data, u32 len ) +{ + struct async_workshop_installed_files_info *info = data; + + ISteamUGC *hSteamUGC = SteamAPI_SteamUGC(); + u32 count = SteamAPI_ISteamUGC_GetSubscribedItems( hSteamUGC, info->buffer, + *info->len ); + + vg_info( "Found %u subscribed items\n", count ); + + u32 j=0; + for( u32 i=0; ibuffer[i] ); + if( state & k_EItemStateInstalled ){ + info->buffer[j ++] = info->buffer[i]; + } + } + + *info->len = j; +} + +VG_STATIC void vg_strsan_ascii( char *buf, u32 len ) +{ + for( u32 i=0; i 126 ){ + buf[i] = '?'; + } + } + buf[len-1] = '\0'; +} + +#define VG_STRSAN_ASCII( X ) vg_strsan_ascii( X, vg_list_size(X) ) + +VG_STATIC void workshop_load_metadata( const char *path, + struct workshop_file_info *info ) +{ + FILE *fp = fopen( path, "rb" ); + + if( fp ){ + if( fread( info, sizeof( struct workshop_file_info ), 1, fp ) ){ + VG_STRSAN_ASCII( info->author_name ); + VG_STRSAN_ASCII( info->title ); + } + fclose( fp ); + } +} + #endif /* WORKSHOP_C */