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,
}
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? */
}
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
}
workshop_form.page = k_workshop_form_hidden;
+ workshop_end_op();
}
/*
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;
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();
*/
struct workshop_package_thread_args{
PublishedFileId_t file_id;
+
+ u64_steamid steamid;
+ char username[32];
};
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 );
}
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 );
}
if( result->m_bUserNeedsToAcceptWorkshopLegalAgreement ){
vg_warn( "Workshop agreement currently not accepted\n" );
}
-
+
workshop_package_submission( result->m_nPublishedFileId );
}
else{
{
/* 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();
call->p_handler = on_workshop_createitem;
ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
call->id = SteamAPI_ISteamUGC_CreateItem( hSteamUGC, SKATERIFT_APPID,
- k_EWorkshopFileTypeCommunity );
+ k_EWorkshopFileTypeCommunity );
}
}
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 );
+ }
}
/*
{
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,
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; i<vg_list_size(workshop_form_visibility_opts); i++ ){
+ if( workshop_form_visibility_opts[i].value == details.m_eVisibility ){
+ workshop_form.submission.visibility.index = i;
+ break;
+ }
+ }
if( details.m_hPreviewFile == 0 ){
vg_error( "m_hPreviewFile is 0\n" );
sizeof( struct workshop_loadpreview_info ) );
snprintf( info->abs_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;
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{
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;
}
/* 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,
}
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 = {
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),
/* 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;
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;
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();
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 );
for( int i=0; i<workshop_form.published_files_list_length; i++ ){
ui_rect item;
- ui_split_px( sidebar, k_ui_axis_h, 28, 0, item, sidebar );
- ui_rect_pad( item, 4 );
+ ui_split( sidebar, k_ui_axis_h, 28, 0, item, sidebar );
+ ui_rect_pad( item, (ui_px[2]){4,4} );
struct published_file *pfile = &workshop_form.published_files_list[i];
if( ui_button_text( item, pfile->title, 1 ) ){
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;
* 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;
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 );
}
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;
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;
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; i<count; i++ ){
+ u32 state = SteamAPI_ISteamUGC_GetItemState( hSteamUGC, info->buffer[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<len-1; i ++ ){
+ if( buf[i] == 0 ) return;
+
+ if( buf[i] < 32 || buf[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 */