X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=workshop.c;h=baa537ce5a8bca4dbf361c8ae90c9381d28c8ac4;hb=b8ff92a2caafa557608b84f4a037a5b3ce2628f7;hp=c82ca6ef563a12167635daab87db2ab1ae3dbd9c;hpb=ac6288a8951db15eab6c681b8add8f350eb60746;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/workshop.c b/workshop.c index c82ca6e..baa537c 100644 --- a/workshop.c +++ b/workshop.c @@ -4,11 +4,15 @@ #define VG_GAME #include "vg/vg.h" #include "vg/vg_tex.h" +#include "vg/vg_msg.h" #include "ent_skateshop.h" #include "vg/vg_steam_auth.h" #include "vg/vg_steam_ugc.h" #include "vg/vg_steam_friends.h" +#include "conf.h" +#include "steam.h" +#include "highscores.h" #define WORKSHOP_VIEW_PER_PAGE 15 @@ -16,11 +20,13 @@ struct workshop_form{ struct { char title[80]; char description[512]; + char author[32]; + struct ui_dropdown_value submission_type_selection; + enum workshop_file_type type; PublishedFileId_t file_id; /* 0 if not published yet */ struct ui_dropdown_value visibility; - int submit_title, /* set if the respective controls are touched */ submit_description, submit_file_and_image; @@ -41,8 +47,7 @@ struct workshop_form{ * ----------------------------- */ - char model_path[128]; - + char addon_folder[128]; struct player_board board_model; /* what does the user want to do with the image preview? */ @@ -107,12 +112,18 @@ static struct ui_dropdown_opt workshop_form_visibility_opts[] = { { "Private", k_ERemoteStoragePublishedFileVisibilityPrivate }, }; +static struct ui_dropdown_opt workshop_form_type_opts[] = { + { "None", k_workshop_file_type_none }, + { "Board", k_workshop_file_type_board }, + { "World", k_workshop_file_type_world }, +}; + /* * Close the form and discard UGC query result */ VG_STATIC void workshop_quit_form(void) { - workshop_begin_op( k_workshop_form_op_none ); /* safeguard */ + skaterift_begin_op( k_async_op_none ); /* safeguard */ player_board_unload( &workshop_form.board_model ); workshop_form.file_intent = k_workshop_form_file_intent_none; @@ -125,7 +136,7 @@ VG_STATIC void workshop_quit_form(void) } workshop_form.page = k_workshop_form_hidden; - workshop_end_op(); + skaterift_end_op(); } /* @@ -136,12 +147,17 @@ 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.author[0] = '\0'; + workshop_form.submission.submission_type_selection.value = + k_workshop_file_type_none; + workshop_form.submission.submission_type_selection.index = 0; + workshop_form.submission.type = k_workshop_file_type_none; workshop_form.submission.visibility.value = k_ERemoteStoragePublishedFileVisibilityPublic; workshop_form.submission.visibility.index = 0; - workshop_form.model_path[0] = '\0'; + workshop_form.addon_folder[0] = '\0'; player_board_unload( &workshop_form.board_model ); workshop_form.file_intent = k_workshop_form_file_intent_none; } @@ -225,41 +241,25 @@ VG_STATIC void on_workshop_update_result( void *data, void *user ) vg_error( "Error with the submitted file (%d)\n", result->m_eResult ); } - workshop_end_op(); + skaterift_end_op(); } -struct workshop_package_info { - PublishedFileId_t publishing_file_id; - - int success; - char abs_preview_image[ 1024 ]; - char abs_content_folder[ 1024 ]; - char abs_content_file[ 1024 ]; - - const char *failure_reason; -}; - /* * reciever on completion of packaging the files, it will then start the item * update with Steam API */ -VG_STATIC void workshop_form_async_package_complete( void *data, u32 size ) +VG_STATIC void workshop_form_upload_submission( PublishedFileId_t file_id, + char *metadata ) { - struct workshop_package_info *info = data; - if( !info->success ){ - workshop_form.page = k_workshop_form_closing_bad; - workshop_form.failure_or_success_string = info->failure_reason; - workshop_end_op(); - return; - } - ISteamUGC *hSteamUGC = SteamAPI_SteamUGC(); UGCUpdateHandle_t handle = SteamAPI_ISteamUGC_StartItemUpdate( hSteamUGC, SKATERIFT_APPID, - info->publishing_file_id ); + file_id ); /* TODO: Handle failure cases for these */ + SteamAPI_ISteamUGC_SetItemMetadata( hSteamUGC, handle, metadata ); + if( workshop_form.submission.submit_title ){ vg_info( "Setting title\n" ); SteamAPI_ISteamUGC_SetItemTitle( hSteamUGC, handle, @@ -273,13 +273,27 @@ VG_STATIC void workshop_form_async_package_complete( void *data, u32 size ) } if( workshop_form.submission.submit_file_and_image ){ - vg_info( "Setting preview image\n" ); - SteamAPI_ISteamUGC_SetItemPreview( hSteamUGC, - handle, info->abs_preview_image ); + char path_buf[4096]; + vg_str folder; + vg_strnull( &folder, path_buf, 4096 ); + vg_strcat( &folder, vg.base_path ); + + if( workshop_form.submission.type == k_workshop_file_type_board ){ + vg_strcat( &folder, "boards/" ); + } + else if( workshop_form.submission.type == k_workshop_file_type_world ){ + vg_strcat( &folder, "maps/" ); + } + vg_strcat( &folder, workshop_form.addon_folder ); vg_info( "Setting item content\n" ); - SteamAPI_ISteamUGC_SetItemContent( hSteamUGC, handle, - info->abs_content_folder ); + SteamAPI_ISteamUGC_SetItemContent( hSteamUGC, handle, folder.buffer ); + + vg_str preview = folder; + vg_strcat( &preview, "/preview.jpg" ); + + vg_info( "Setting preview image\n" ); + SteamAPI_ISteamUGC_SetItemPreview( hSteamUGC, handle, preview.buffer ); } vg_info( "Setting visibility\n" ); @@ -293,71 +307,6 @@ VG_STATIC void workshop_form_async_package_complete( void *data, u32 size ) call->id = SteamAPI_ISteamUGC_SubmitItemUpdate( hSteamUGC, handle, "" ); } -/* - * Async thread for rearranging files into a reasonable workshop folder - */ -struct workshop_package_thread_args{ - PublishedFileId_t file_id; -}; -VG_STATIC void _workshop_package_thread( void *_args ) -{ - struct workshop_package_thread_args *args = _args; - PublishedFileId_t file_id = args->file_id; - - vg_info( "Packaging workshop content folder\n" ); - - vg_async_item *call = vg_async_alloc( sizeof(struct workshop_package_info) ); - struct workshop_package_info *info = call->payload; - info->publishing_file_id = file_id; - info->failure_reason = "Unknown failure reason"; - - /* build content folder path */ - snprintf( info->abs_content_folder, 1024, "%smodels/boards/workshop/%lu", - vg.base_path, file_id ); - - /* build content file path */ - snprintf( info->abs_content_file, 1024, "%s/%s", info->abs_content_folder, - "board.mdl" ); - - /* build workshop preview file path */ - snprintf( info->abs_preview_image, 1024, "%sworkshop_preview.jpg", - vg.base_path ); - - /* arange files */ - if( !vg_mkdir( info->abs_content_folder ) ){ - info->success = 0; - info->failure_reason = "Could not make directory."; - vg_async_dispatch( call, workshop_form_async_package_complete ); - return; - } - - vg_linear_clear( vg_mem.scratch ); - if( !vg_file_copy( workshop_form.model_path, info->abs_content_file, - vg_mem.scratch ) ){ - info->success = 0; - info->failure_reason = "Copy file failed."; - vg_async_dispatch( call, workshop_form_async_package_complete ); - return; - } - - info->success = 1; - vg_async_dispatch( call, workshop_form_async_package_complete ); -} - -/* - * Begins the packaging thread using file_id. Thread definition above. - */ -VG_STATIC void workshop_package_submission( PublishedFileId_t file_id ) -{ - vg_linear_clear( vg_mem.scratch ); - struct workshop_package_thread_args *args = - vg_linear_alloc( vg_mem.scratch, - sizeof(struct workshop_package_thread_args)); - - args->file_id = file_id; - vg_loader_start( _workshop_package_thread, args ); -} - /* * Steam API call result for when we've created a new item on their network, or * not, if it has failed @@ -374,7 +323,7 @@ VG_STATIC void on_workshop_createitem( void *data, void *user ) vg_warn( "Workshop agreement currently not accepted\n" ); } - workshop_package_submission( result->m_nPublishedFileId ); + workshop_form_upload_submission( result->m_nPublishedFileId, user ); } else{ const char *errstr = workshop_EResult_user_string( result->m_eResult ); @@ -386,7 +335,7 @@ VG_STATIC void on_workshop_createitem( void *data, void *user ) workshop_form.page = k_workshop_form_closing_bad; workshop_form.failure_or_success_string = errstr; - workshop_end_op(); + skaterift_end_op(); } } @@ -395,26 +344,15 @@ VG_STATIC void on_workshop_createitem( void *data, void *user ) */ VG_STATIC void workshop_form_async_submit_begin( void *payload, u32 size ) { + /* use existing file */ if( 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) ); - } + workshop_form_upload_submission( workshop_form.submission.file_id, + payload ); } else{ vg_steam_async_call *call = vg_alloc_async_steam_api_call(); - call->userdata = NULL; + call->userdata = payload; call->p_handler = on_workshop_createitem; ISteamUGC *hSteamUGC = SteamAPI_SteamUGC(); call->id = SteamAPI_ISteamUGC_CreateItem( hSteamUGC, SKATERIFT_APPID, @@ -450,15 +388,110 @@ VG_STATIC void _workshop_form_submit_thread( void *data ) vg_async_call( workshop_form_async_download_image, NULL, 0 ); vg_async_stall(); + char path_buf[4096]; + vg_str folder; + vg_strnull( &folder, path_buf, 4096 ); + + if( workshop_form.submission.type == k_workshop_file_type_board ){ + vg_strcat( &folder, "boards/" ); + } + else if( workshop_form.submission.type == k_workshop_file_type_world ){ + vg_strcat( &folder, "maps/" ); + } + vg_strcat( &folder, workshop_form.addon_folder ); + + if( !vg_strgood(&folder) ){ + vg_error( "addon folder path too long\n" ); + vg_async_call( workshop_async_any_complete, NULL, 0 ); + return; + } + + /* + * Create the metadata file + * -----------------------------------------------------------------------*/ + u8 descriptor_buf[ 512 ]; + vg_msg descriptor; + vg_msg_init( &descriptor, descriptor_buf, 512 ); + vg_msg_frame( &descriptor, "workshop" ); + vg_msg_wkvstr( &descriptor, "title", workshop_form.submission.title ); + //vg_msg_wkvstr( &descriptor, "author", "unknown" ); + vg_msg_wkvuint( &descriptor, "type", + u32 value=workshop_form.submission.type); + vg_msg_wkvstr( &descriptor, "folder", workshop_form.addon_folder ); + vg_msg_end_frame( &descriptor ); + //vg_msg_wkvstr( &descriptor, "location", "USA" ); + // + vg_linear_clear( vg_mem.scratch ); + char *descriptor_str = vg_linear_alloc( vg_mem.scratch, + vg_align8(descriptor.cur*2+1) ); + vg_bin_str( descriptor_buf, descriptor_str, descriptor.cur ); + descriptor_str[descriptor.cur*2] = '\0'; + vg_info( "binstr: %s\n", descriptor_str ); + + DIR *dir = opendir( folder.buffer ); + if( !dir ){ + vg_error( "could not open addon folder '%s'\n", folder.buffer ); + vg_async_call( workshop_async_any_complete, NULL, 0 ); + return; + } + + struct dirent *entry; + while( (entry = readdir(dir)) ){ + if( entry->d_type == DT_REG ){ + if( entry->d_name[0] == '.' ) continue; + + vg_str file = folder; + vg_strcat( &file, "/" ); + vg_strcat( &file, entry->d_name ); + if( !vg_strgood( &file ) ) continue; + + char *ext = vg_strch( &file, '.' ); + if( !ext ) continue; + if( strcmp(ext,".mdl") ) continue; + + vg_msg_wkvstr( &descriptor, "content", entry->d_name ); + break; + } + } + closedir(dir); + + vg_str descriptor_file = folder; + vg_strcat( &descriptor_file, "/addon.inf" ); + if( !vg_strgood(&descriptor_file) ){ + vg_error( "Addon info path too long\n" ); + vg_async_call( workshop_async_any_complete, NULL, 0 ); + return; + } + + FILE *fp = fopen( descriptor_file.buffer, "wb" ); + if( !fp ){ + vg_error( "Could not open addon info file '%s'\n", + descriptor_file.buffer ); + vg_async_call( workshop_async_any_complete, NULL, 0 ); + return; + } + fwrite( descriptor_buf, descriptor.cur, 1, fp ); + fclose( fp ); + + /* Save the preview + * -----------------------------------------------------------------------*/ + vg_str preview = folder; + vg_strcat( &preview, "/preview.jpg" ); + + if( !vg_strgood(&preview) ){ + vg_error( "preview image path too long\n" ); + vg_async_call( workshop_async_any_complete, NULL, 0 ); + return; + } + int w = workshop_form.img_w, h = workshop_form.img_h; - vg_info( "writing: workshop_preview.jpg (%dx%d @90%%)\n", w,h ); + vg_info( "writing: %s (%dx%d @90%%)\n", preview.buffer, w,h ); stbi_flip_vertically_on_write(1); - stbi_write_jpg( "workshop_preview.jpg", w,h, 3, - workshop_form.img_buffer, 90 ); + stbi_write_jpg( preview.buffer, w,h, 3, workshop_form.img_buffer, 90 ); - vg_async_call( workshop_form_async_submit_begin, NULL, 0 ); + vg_async_call( workshop_form_async_submit_begin, descriptor_str, 0 ); } /* @@ -467,7 +500,6 @@ VG_STATIC void _workshop_form_submit_thread( void *data ) VG_STATIC void workshop_op_submit(void) { /* TODO: Show these errors to the user */ - if( workshop_form.submission.submit_title ){ if( !workshop_form.submission.title[0] ){ vg_error( "Cannot submit because a title is required\n" ); @@ -489,7 +521,7 @@ VG_STATIC void workshop_op_submit(void) } } - workshop_begin_op( k_workshop_form_op_publishing_update ); + skaterift_begin_op( k_workshop_form_op_publishing_update ); player_board_unload( &workshop_form.board_model ); workshop_form.file_intent = k_workshop_form_file_intent_none; @@ -514,7 +546,15 @@ VG_STATIC void workshop_form_loadmodel_async_complete( void *payload, u32 size ) workshop_form.file_intent = k_workshop_form_file_intent_new; vg_success( "workshop async load complete\n" ); - workshop_end_op(); + skaterift_end_op(); +} + +/* + * Reciever for failure to load + */ +VG_STATIC void workshop_form_loadmodel_async_error( void *payload, u32 size ) +{ + skaterift_end_op(); } /* @@ -522,7 +562,58 @@ VG_STATIC void workshop_form_loadmodel_async_complete( void *payload, u32 size ) */ VG_STATIC void _workshop_form_load_thread( void *data ) { - player_board_load( &workshop_form.board_model, workshop_form.model_path ); + char path_buf[4096]; + vg_str folder; + vg_strnull( &folder, path_buf, 4096 ); + + if( workshop_form.submission.type == k_workshop_file_type_world ) + vg_strcat( &folder, "maps/" ); + else vg_strcat( &folder, "boards/" ); + + vg_strcat( &folder, workshop_form.addon_folder ); + + if( !vg_strgood(&folder) ){ + vg_error( "workshop async load failed: path too long\n" ); + vg_async_call( workshop_form_loadmodel_async_error, NULL, 0 ); + return; + } + + DIR *dir = opendir( folder.buffer ); + if( !dir ){ + vg_error( "workshop async load failed: could not open folder\n" ); + vg_async_call( workshop_form_loadmodel_async_error, NULL, 0 ); + return; + } + + vg_info( "Searching %s for model files\n", folder.buffer ); + + int found_mdl = 0; + struct dirent *entry; + while( (entry = readdir(dir)) ){ + if( entry->d_type == DT_REG ){ + if( entry->d_name[0] == '.' ) continue; + + vg_str file = folder; + vg_strcat( &file, "/" ); + vg_strcat( &file, entry->d_name ); + if( !vg_strgood( &file ) ) continue; + + char *ext = vg_strch( &file, '.' ); + if( !ext ) continue; + if( strcmp(ext,".mdl") ) continue; + found_mdl = 1; + break; + } + } + closedir(dir); + + if( !found_mdl ){ + vg_error( "workshop async load failed: no model files found\n" ); + vg_async_call( workshop_form_loadmodel_async_error, NULL, 0 ); + return; + } + + player_board_load( &workshop_form.board_model, path_buf ); vg_async_call( workshop_form_loadmodel_async_complete, NULL, 0 ); } @@ -531,7 +622,12 @@ VG_STATIC void _workshop_form_load_thread( void *data ) */ VG_STATIC void workshop_op_load_model(void) { - workshop_begin_op( k_workshop_form_op_loading_model ); + if( workshop_form.submission.type == k_workshop_file_type_world ){ + vg_error( "Currently unsupported\n" ); + return; + } + + skaterift_begin_op( k_workshop_form_op_loading_model ); vg_loader_start( _workshop_form_load_thread, NULL ); } @@ -557,42 +653,49 @@ VG_STATIC void workshop_form_async_imageload( void *data, u32 len ) vg_success( "Loaded workshop preview image\n" ); } - workshop_end_op(); + skaterift_end_op(); } -struct workshop_loadpreview_info { - char abs_preview_image[ 1024 ]; -}; - /* * Load the image located at ./workshop_preview.jpg into our framebuffer */ VG_STATIC void _workshop_load_preview_thread( void *data ) { - struct workshop_loadpreview_info *info = data; - - stbi_set_flip_vertically_on_load(1); - int x, y, nc; - u8 *rgb = stbi_load( info->abs_preview_image, &x, &y, &nc, 3 ); - - if( rgb ){ - if( (x == WORKSHOP_PREVIEW_WIDTH) && (y == WORKSHOP_PREVIEW_HEIGHT) ){ - vg_async_call( workshop_form_async_imageload, rgb, x*y*3 ); + char path_buf[ 4096 ]; + vg_str path; + vg_strnull( &path, path_buf, 4096 ); + vg_strcat( &path, "boards/" ); + vg_strcat( &path, workshop_form.addon_folder ); + vg_strcat( &path, "/preview.jpg" ); + + if( vg_strgood( &path ) ){ + stbi_set_flip_vertically_on_load(1); + int x, y, nc; + u8 *rgb = stbi_load( path.buffer, &x, &y, &nc, 3 ); + + if( rgb ){ + if( (x == WORKSHOP_PREVIEW_WIDTH) && (y == WORKSHOP_PREVIEW_HEIGHT) ){ + vg_async_call( workshop_form_async_imageload, rgb, x*y*3 ); + } + else{ + vg_error( "Resolution does not match framebuffer, so we can't" + " show it\n" ); + stbi_image_free( rgb ); + vg_async_call( workshop_form_async_imageload, NULL, 0 ); + } } else{ - vg_error( "Resolution does not match framebuffer, so we can't" - " show it\n" ); - stbi_image_free( rgb ); + vg_error( "Failed to load workshop_preview.jpg: '%s'\n", + stbi_failure_reason() ); vg_async_call( workshop_form_async_imageload, NULL, 0 ); } } else{ - vg_error( "Failed to load workshop_preview.jpg: '%s'\n", - stbi_failure_reason() ); vg_async_call( workshop_form_async_imageload, NULL, 0 ); } } +#if 0 /* * Reciever for the preview download result */ @@ -608,9 +711,10 @@ VG_STATIC void on_workshop_download_ugcpreview( void *data, void *user ) else{ vg_error( "Error while donwloading UGC preview( %d )\n", result->m_eResult ); - workshop_end_op(); + skaterift_end_op(); } } +#endif /* * Entry point to view operation @@ -625,12 +729,19 @@ VG_STATIC void workshop_op_download_and_view_submission( int result_index ) result_index, &details ) ) { - workshop_begin_op( k_workshop_form_op_downloading_submission ); + skaterift_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; + u8 metadata_buf[512]; + char metadata_str[1024+1]; + int have_meta = SteamAPI_ISteamUGC_GetQueryUGCMetadata( hSteamUGC, + workshop_form.ugc_query.handle, + result_index, metadata_str, + 1024+1 ); + vg_strncpy( details.m_rgchDescription, workshop_form.submission.description, vg_list_size( workshop_form.submission.description ), @@ -641,25 +752,82 @@ VG_STATIC void workshop_op_download_and_view_submission( int result_index ) vg_list_size( workshop_form.submission.title ), k_strncpy_always_add_null ); - snprintf( workshop_form.model_path, - vg_list_size( workshop_form.model_path ), + snprintf( workshop_form.addon_folder, + vg_list_size( workshop_form.addon_folder ), "Steam Cloud (%lu)", details.m_nPublishedFileId ); 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; + workshop_form.submission.type = k_workshop_file_type_none; + workshop_form.submission.submission_type_selection.index = 0; + workshop_form.submission.submission_type_selection.value = + k_workshop_file_type_none; + + if( have_meta ){ + u32 len = strlen(metadata_str); + vg_info( "Metadata: %s\n", metadata_str ); + vg_str_bin( metadata_str, metadata_buf, len ); + vg_msg msg; + vg_msg_init( &msg, metadata_buf, len/2 ); + + vg_msg_cmd cmd; + while( vg_msg_next( &msg, &cmd ) ){ + if( (msg.depth == 1) && (cmd.code == k_vg_msg_code_frame) ){ + if( VG_STRDJB2_EQ( "workshop", cmd.key, cmd.key_djb2 ) ){ + u32 depth = msg.depth; + while( (msg.depth == depth) && vg_msg_next( &msg, &cmd ) ){ + if( cmd.code & k_vg_msg_code_unsigned ){ + if( VG_STRDJB2_EQ( "type", cmd.key, cmd.key_djb2 ) ){ + workshop_form.submission.type = cmd.value._u32; + workshop_form.submission.submission_type_selection.value = cmd.value._u32; + } + } + else if( cmd.code == k_vg_msg_code_kvstring ){ + if( VG_STRDJB2_EQ( "folder", cmd.key, cmd.key_djb2 ) ){ + vg_strncpy( cmd.value._buf, + workshop_form.addon_folder, + sizeof(workshop_form.addon_folder), + k_strncpy_always_add_null ); + } + } + } + } + } + } + } + else{ + vg_error( "No metadata was returned with this item.\n" ); + } + /* TODO.... */ for( i32 i=0; iid = SteamAPI_ISteamUGC_SendQueryUGCRequest( hSteamUGC, handle ); return 0; } @@ -827,7 +997,7 @@ VG_STATIC void workshop_init(void) VG_STATIC void workshop_find_preview_entity(void) { - workshop_form.view_world = get_active_world(); + workshop_form.view_world = world_current_instance(); if( mdl_arrcount( &workshop_form.view_world->ent_swspreview ) ){ workshop_form.ptr_ent = @@ -951,6 +1121,74 @@ VG_STATIC void workshop_changed_description( char *buf, u32 len ){ VG_STATIC void workshop_form_gui_edit_page( ui_rect content ) { + if( workshop_form.submission.type == k_workshop_file_type_none ){ + ui_rect box; + rect_copy( content, box ); + box[3] = 128; + box[2] = (box[2]*2)/3; + ui_rect_center( content, box ); + + ui_rect row; + ui_split( box, k_ui_axis_h, 28, 0, row, box ); + ui_text( row, "Select the type of item\n", 1, k_ui_align_middle_center,0); + ui_split( box, k_ui_axis_h, 28, 0, row, box ); + ui_enum( row, "Type:", workshop_form_type_opts, + 3, &workshop_form.submission.submission_type_selection ); + ui_split( box, k_ui_axis_h, 8, 0, row, box ); + ui_split( box, k_ui_axis_h, 28, 0, row, box ); + + ui_rect button_l, button_r; + rect_copy( row, button_l ); + button_l[2] = 128*2; + ui_rect_center( row, button_l ); + ui_split_ratio( button_l, k_ui_axis_v, 0.5f, 2, button_l, button_r ); + + if( workshop_form.submission.submission_type_selection.value != + k_workshop_file_type_none ){ + if( ui_button_text( button_l, "OK", 1 ) ){ + workshop_form.submission.type = + workshop_form.submission.submission_type_selection.value; + } + } + else{ + ui_fill( button_l, ui_colour(k_ui_bg) ); + ui_text( button_l, "OK", 1, k_ui_align_middle_center, + ui_colour(k_ui_bg+4) ); + } + + if( ui_button_text( button_r, "Cancel", 1 ) ){ + workshop_form.page = k_workshop_form_open; + workshop_form.file_intent = k_workshop_form_file_intent_none; + } + return; + } + + if( workshop_form.submission.type == k_workshop_file_type_world ){ + ui_rect box; + rect_copy( content, box ); + box[3] = 128; + box[2] = (box[2]*2)/3; + ui_rect_center( content, box ); + + ui_rect row; + ui_split( box, k_ui_axis_h, 28, 0, row, box ); + ui_text( row, "World submissions are currently not ready, sorry.", + 1, k_ui_align_middle_center,0); + ui_split( box, k_ui_axis_h, 8, 0, row, box ); + ui_split( box, k_ui_axis_h, 28, 0, row, box ); + + ui_rect button; + rect_copy( row, button ); + button[2] = 128; + ui_rect_center( row, button ); + if( ui_button_text( button, "OK", 1 ) ){ + workshop_form.page = k_workshop_form_open; + workshop_form.file_intent = k_workshop_form_file_intent_none; + } + + return; + } + ui_rect image_plane; ui_split( content, k_ui_axis_h, 300, 0, image_plane, content ); ui_fill( image_plane, ui_colour( k_ui_bg+0 ) ); @@ -1022,17 +1260,24 @@ VG_STATIC void workshop_form_gui_edit_page( ui_rect content ) 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.submission.type == k_workshop_file_type_board ){ + ui_label( file_entry, "Addon folder: skaterift/boards/", + 1, 8, file_entry ); + } + else{ + ui_label( file_entry, "Addon folder: skaterift/maps/", + 1, 8, file_entry ); + } 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, - ui_colour( k_ui_fg+4 ) ); + ui_text( file_entry, workshop_form.addon_folder, 1, + k_ui_align_middle_left, ui_colour( k_ui_fg+4 ) ); if( ui_button_text( file_button, "Remove", 1 ) ){ player_board_unload( &workshop_form.board_model ); workshop_form.file_intent = k_workshop_form_file_intent_none; - workshop_form.model_path[0] = '\0'; + workshop_form.addon_folder[0] = '\0'; } } else{ @@ -1040,8 +1285,8 @@ VG_STATIC void workshop_form_gui_edit_page( ui_rect content ) .change = workshop_changed_model_path }; - ui_textbox( file_entry, workshop_form.model_path, - vg_list_size(workshop_form.model_path), 0, &callbacks ); + ui_textbox( file_entry, workshop_form.addon_folder, + vg_list_size(workshop_form.addon_folder), 0, &callbacks ); if( ui_button_text( file_button, "Load", 1 ) ){ workshop_find_preview_entity(); @@ -1083,7 +1328,6 @@ VG_STATIC void workshop_form_gui_edit_page( ui_rect content ) .change = workshop_changed_description }; ui_rect desc_entry; - /* TODO: Tommora, new split_px_gap and split_px() */ 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 ); @@ -1148,13 +1392,41 @@ VG_STATIC void workshop_form_gui_edit_page( ui_rect content ) VG_STATIC void workshop_form_gui_sidebar( ui_rect sidebar ) { - /* - * sidebar existing entries panel - */ ui_fill( sidebar, ui_colour( k_ui_bg+2 ) ); ui_rect title; ui_split( sidebar, k_ui_axis_h, 28, 0, title, sidebar ); + + if( workshop_form.page == k_workshop_form_edit ){ + ui_text( title, "Editing", 1, k_ui_align_middle_center, 0 ); + ui_split( sidebar, k_ui_axis_h, 28, 0, title, sidebar ); + + if( workshop_form.submission.type != k_workshop_file_type_none ){ + char buf[512]; + vg_str str; + vg_strnull( &str, buf, 512 ); + + if( workshop_form.submission.file_id ) + vg_strcat( &str, "Editing an existing " ); + else + vg_strcat( &str, "Creating a new " ); + + if( workshop_form.submission.type == k_workshop_file_type_board ) + vg_strcat( &str, "skateboard." ); + else if( workshop_form.submission.type == k_workshop_file_type_world ) + vg_strcat( &str, "world." ); + else + vg_strcat( &str, "???." ); + + ui_text( title, buf, 1, k_ui_align_middle_center, + ui_colour(k_ui_fg+4) ); + } + return; + } + + /* + * sidebar existing entries panel + */ ui_text( title, "Your submissions", 1, k_ui_align_middle_center, 0 ); ui_rect controls, btn_create_new; @@ -1165,8 +1437,6 @@ VG_STATIC void workshop_form_gui_sidebar( ui_rect sidebar ) char buf[32]; strcpy( buf, "page " ); int i = 5; - - /* TODO: for what it is, this code is getting a bit.. special */ 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 ); @@ -1238,7 +1508,7 @@ VG_STATIC void workshop_form_gui(void) ui_rect quit_button; ui_split( title, k_ui_axis_v, title[2]-title[3], 2, title, quit_button ); - if( workshop.operation == k_workshop_form_op_none ){ + if( skaterift.async_op == k_async_op_none ){ if( ui_button_text( quit_button, "X", 1 ) ){ workshop_quit_form(); return; @@ -1251,11 +1521,11 @@ VG_STATIC void workshop_form_gui(void) * escapes here and we show them a basic string */ - if( workshop.operation != k_workshop_form_op_none ){ + if( skaterift.async_op != k_async_op_none ){ const char *op_string = "The programmer has not bothered to describe " "the current operation that is running."; - switch(workshop.operation){ + switch( skaterift.async_op ){ case k_workshop_form_op_loading_model: op_string = "Operation in progress: Loading model file."; break; @@ -1343,6 +1613,7 @@ VG_STATIC void async_workshop_get_filepath( void *data, u32 len ) if( !SteamAPI_ISteamUGC_GetItemInstallInfo( hSteamUGC, info->id, &_size, info->buf, info->len, &_ts )) { + vg_error( "GetItemInstallInfo failed\n" ); info->buf[0] = '\0'; } } @@ -1368,4 +1639,34 @@ VG_STATIC void async_workshop_get_installed_files( void *data, u32 len ) *info->len = j; } +#if 0 +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 + #endif /* WORKSHOP_C */