8 #include "ent_skateshop.h"
10 #include "vg/vg_steam_auth.h"
11 #include "vg/vg_steam_ugc.h"
12 #include "vg/vg_steam_friends.h"
15 #include "highscores.h"
17 #define WORKSHOP_VIEW_PER_PAGE 15
22 char description
[512];
24 struct ui_dropdown_value submission_type_selection
;
25 enum workshop_file_type type
;
27 PublishedFileId_t file_id
; /* 0 if not published yet */
29 struct ui_dropdown_value visibility
;
30 int submit_title
, /* set if the respective controls are touched */
32 submit_file_and_image
;
36 enum workshop_form_page
{
37 k_workshop_form_hidden
,
38 k_workshop_form_open
, /* open but not looking at anything */
39 k_workshop_form_edit
, /* editing a submission */
40 k_workshop_form_cclosing
,
41 k_workshop_form_closing_good
, /* post upload screen */
42 k_workshop_form_closing_bad
,
47 * -----------------------------
50 char addon_folder
[128];
51 struct player_board board_model
;
53 /* what does the user want to do with the image preview? */
54 enum workshop_form_file_intent
{
55 k_workshop_form_file_intent_none
, /* loading probably */
56 k_workshop_form_file_intent_new
, /* board_model is valid */
57 k_workshop_form_file_intent_keep_old
/* just browsing */
61 world_instance
*view_world
;
62 ent_swspreview
*ptr_ent
;
72 * published UGC request
73 * ------------------------------
77 UGCQueryHandle_t handle
;
87 * ------------------------------------------
90 const char *failure_or_success_string
;
95 int view_published_page_count
,
96 view_published_page_id
;
98 struct published_file
{
103 published_files_list
[WORKSHOP_VIEW_PER_PAGE
];
104 int published_files_list_length
;
106 static workshop_form
;
108 static struct ui_dropdown_opt workshop_form_visibility_opts
[] = {
109 { "Public", k_ERemoteStoragePublishedFileVisibilityPublic
},
110 { "Unlisted", k_ERemoteStoragePublishedFileVisibilityUnlisted
},
111 { "Friends Only", k_ERemoteStoragePublishedFileVisibilityFriendsOnly
},
112 { "Private", k_ERemoteStoragePublishedFileVisibilityPrivate
},
115 static struct ui_dropdown_opt workshop_form_type_opts
[] = {
116 { "None", k_workshop_file_type_none
},
117 { "Board", k_workshop_file_type_board
},
118 { "World", k_workshop_file_type_world
},
122 * Close the form and discard UGC query result
124 VG_STATIC
void workshop_quit_form(void)
126 skaterift_begin_op( k_async_op_none
); /* safeguard */
127 player_board_unload( &workshop_form
.board_model
);
128 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
130 if( workshop_form
.ugc_query
.result
== k_EResultOK
){
131 workshop_form
.ugc_query
.result
= k_EResultNone
;
133 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
134 SteamAPI_ISteamUGC_ReleaseQueryUGCRequest(
135 hSteamUGC
, workshop_form
.ugc_query
.handle
);
138 workshop_form
.page
= k_workshop_form_hidden
;
143 * Delete all information about the submission
145 VG_STATIC
void workshop_reset_submission_data(void)
147 workshop_form
.submission
.file_id
= 0; /* assuming id of 0 is none/invalid */
148 workshop_form
.submission
.description
[0] = '\0';
149 workshop_form
.submission
.title
[0] = '\0';
150 workshop_form
.submission
.author
[0] = '\0';
151 workshop_form
.submission
.submission_type_selection
.value
=
152 k_workshop_file_type_none
;
153 workshop_form
.submission
.submission_type_selection
.index
= 0;
154 workshop_form
.submission
.type
= k_workshop_file_type_none
;
156 workshop_form
.submission
.visibility
.value
=
157 k_ERemoteStoragePublishedFileVisibilityPublic
;
158 workshop_form
.submission
.visibility
.index
= 0;
160 workshop_form
.addon_folder
[0] = '\0';
161 player_board_unload( &workshop_form
.board_model
);
162 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
167 * Mostly copies of what it sais on the Steam API documentation
169 VG_STATIC
const char *workshop_EResult_user_string( EResult result
)
172 case k_EResultInsufficientPrivilege
:
173 return "Your account is currently restricted from uploading content "
174 "due to a hub ban, account lock, or community ban. You need to "
175 "contact Steam Support to resolve the issue.";
176 case k_EResultBanned
:
177 return "You do not have permission to upload content to this hub "
178 "because you have an active VAC or Game ban.";
179 case k_EResultTimeout
:
180 return "The operation took longer than expected, so it was discarded. "
182 case k_EResultNotLoggedOn
:
183 return "You are currently not logged into Steam.";
184 case k_EResultServiceUnavailable
:
185 return "The workshop server is having issues or is unavailable, "
187 case k_EResultInvalidParam
:
188 return "One of the submission fields contains something not being "
189 "accepted by that field.";
190 case k_EResultAccessDenied
:
191 return "There was a problem trying to save the title and description. "
192 "Access was denied.";
193 case k_EResultLimitExceeded
:
194 return "You have exceeded your Steam Cloud quota. If you wish to "
195 "upload this file, you must remove some published items.";
196 case k_EResultFileNotFound
:
197 return "The uploaded file could not be found.";
198 case k_EResultDuplicateRequest
:
199 return "The file was already successfully uploaded.";
200 case k_EResultDuplicateName
:
201 return "You already have a Steam Workshop item with that name.";
202 case k_EResultServiceReadOnly
:
203 return "Due to a recent password or email change, you are not allowed "
204 "to upload new content. Usually this restriction will expire in"
205 " 5 days, but can last up to 30 days if the account has been "
206 "inactive recently.";
208 return "Operation failed for an error which has not been accounted for "
209 "by the programmer. Try again, sorry :)";
214 * op: k_workshop_form_op_publishing_update
215 * ----------------------------------------------------------------------------
219 * The endpoint of this operation
221 VG_STATIC
void on_workshop_update_result( void *data
, void *user
)
223 vg_info( "Recieved workshop update result\n" );
224 SubmitItemUpdateResult_t
*result
= data
;
226 /* this seems to be set here, but my account definitely has accepted it */
227 if( result
->m_bUserNeedsToAcceptWorkshopLegalAgreement
){
228 vg_warn( "Workshop agreement currently not accepted\n" );
231 if( result
->m_eResult
== k_EResultOK
){
232 workshop_form
.page
= k_workshop_form_closing_good
;
233 workshop_form
.failure_or_success_string
= "Uploaded workshop file!";
234 vg_success( "file uploaded\n" );
237 workshop_form
.page
= k_workshop_form_closing_bad
;
238 workshop_form
.failure_or_success_string
=
239 workshop_EResult_user_string( result
->m_eResult
);
241 vg_error( "Error with the submitted file (%d)\n", result
->m_eResult
);
248 * reciever on completion of packaging the files, it will then start the item
249 * update with Steam API
251 VG_STATIC
void workshop_form_upload_submission( PublishedFileId_t file_id
,
254 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
255 UGCUpdateHandle_t handle
256 = SteamAPI_ISteamUGC_StartItemUpdate( hSteamUGC
, SKATERIFT_APPID
,
259 /* TODO: Handle failure cases for these */
261 SteamAPI_ISteamUGC_SetItemMetadata( hSteamUGC
, handle
, metadata
);
263 if( workshop_form
.submission
.submit_title
){
264 vg_info( "Setting title\n" );
265 SteamAPI_ISteamUGC_SetItemTitle( hSteamUGC
, handle
,
266 workshop_form
.submission
.title
);
269 if( workshop_form
.submission
.submit_description
){
270 vg_info( "Setting description\n" );
271 SteamAPI_ISteamUGC_SetItemDescription( hSteamUGC
, handle
,
272 workshop_form
.submission
.description
);
275 if( workshop_form
.submission
.submit_file_and_image
){
278 vg_strnull( &folder
, path_buf
, 4096 );
279 vg_strcat( &folder
, vg
.base_path
);
281 if( workshop_form
.submission
.type
== k_workshop_file_type_board
){
282 vg_strcat( &folder
, "boards/" );
284 else if( workshop_form
.submission
.type
== k_workshop_file_type_world
){
285 vg_strcat( &folder
, "maps/" );
287 vg_strcat( &folder
, workshop_form
.addon_folder
);
289 vg_info( "Setting item content\n" );
290 SteamAPI_ISteamUGC_SetItemContent( hSteamUGC
, handle
, folder
.buffer
);
292 vg_str preview
= folder
;
293 vg_strcat( &preview
, "/preview.jpg" );
295 vg_info( "Setting preview image\n" );
296 SteamAPI_ISteamUGC_SetItemPreview( hSteamUGC
, handle
, preview
.buffer
);
299 vg_info( "Setting visibility\n" );
300 SteamAPI_ISteamUGC_SetItemVisibility( hSteamUGC
, handle
,
301 workshop_form
.submission
.visibility
.value
);
303 vg_info( "Submitting updates\n" );
304 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
305 call
->userdata
= NULL
;
306 call
->p_handler
= on_workshop_update_result
;
307 call
->id
= SteamAPI_ISteamUGC_SubmitItemUpdate( hSteamUGC
, handle
, "" );
311 * Steam API call result for when we've created a new item on their network, or
312 * not, if it has failed
314 VG_STATIC
void on_workshop_createitem( void *data
, void *user
)
316 CreateItemResult_t
*result
= data
;
318 if( result
->m_eResult
== k_EResultOK
){
319 vg_info( "Created workshop file with id: %lu\n",
320 result
->m_nPublishedFileId
);
322 if( result
->m_bUserNeedsToAcceptWorkshopLegalAgreement
){
323 vg_warn( "Workshop agreement currently not accepted\n" );
326 workshop_form_upload_submission( result
->m_nPublishedFileId
, user
);
329 const char *errstr
= workshop_EResult_user_string( result
->m_eResult
);
332 vg_error( "ISteamUGC_CreateItem() failed(%d): '%s' \n",
333 result
->m_eResult
, errstr
);
336 workshop_form
.page
= k_workshop_form_closing_bad
;
337 workshop_form
.failure_or_success_string
= errstr
;
343 * Starts the workshop upload process through Steam API
345 VG_STATIC
void workshop_form_async_submit_begin( void *payload
, u32 size
)
348 /* use existing file */
349 if( workshop_form
.submission
.file_id
){
350 workshop_form_upload_submission( workshop_form
.submission
.file_id
,
354 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
355 call
->userdata
= payload
;
356 call
->p_handler
= on_workshop_createitem
;
357 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
358 call
->id
= SteamAPI_ISteamUGC_CreateItem( hSteamUGC
, SKATERIFT_APPID
,
359 k_EWorkshopFileTypeCommunity
);
364 * Downloads the framebuffer into scratch memory
366 VG_STATIC
void workshop_form_async_download_image( void *payload
, u32 size
)
369 render_fb_get_current_res( gpipeline
.fb_workshop_preview
, &w
, &h
);
370 vg_linear_clear( vg_mem
.scratch
);
371 workshop_form
.img_buffer
= vg_linear_alloc( vg_mem
.scratch
, w
*h
*3 );
373 vg_info( "read framebuffer: glReadPixels( %dx%d )\n", w
,h
);
375 glBindFramebuffer( GL_READ_FRAMEBUFFER
, gpipeline
.fb_workshop_preview
->fb
);
376 glReadBuffer( GL_COLOR_ATTACHMENT0
);
377 glReadPixels( 0,0, w
,h
, GL_RGB
, GL_UNSIGNED_BYTE
, workshop_form
.img_buffer
);
379 workshop_form
.img_w
= w
;
380 workshop_form
.img_h
= h
;
384 * Thread which kicks off the upload process
386 VG_STATIC
void _workshop_form_submit_thread( void *data
)
388 vg_async_call( workshop_form_async_download_image
, NULL
, 0 );
393 vg_strnull( &folder
, path_buf
, 4096 );
395 if( workshop_form
.submission
.type
== k_workshop_file_type_board
){
396 vg_strcat( &folder
, "boards/" );
398 else if( workshop_form
.submission
.type
== k_workshop_file_type_world
){
399 vg_strcat( &folder
, "maps/" );
401 vg_strcat( &folder
, workshop_form
.addon_folder
);
403 if( !vg_strgood(&folder
) ){
404 vg_error( "addon folder path too long\n" );
405 vg_async_call( workshop_async_any_complete
, NULL
, 0 );
410 * Create the metadata file
411 * -----------------------------------------------------------------------*/
412 u8 descriptor_buf
[ 512 ];
414 vg_msg_init( &descriptor
, descriptor_buf
, 512 );
415 vg_msg_frame( &descriptor
, "workshop" );
416 vg_msg_wkvstr( &descriptor
, "title", workshop_form
.submission
.title
);
417 //vg_msg_wkvstr( &descriptor, "author", "unknown" );
418 vg_msg_wkvuint( &descriptor
, "type",
419 u32 value
=workshop_form
.submission
.type
);
420 vg_msg_wkvstr( &descriptor
, "folder", workshop_form
.addon_folder
);
421 vg_msg_end_frame( &descriptor
);
422 //vg_msg_wkvstr( &descriptor, "location", "USA" );
424 vg_linear_clear( vg_mem
.scratch
);
425 char *descriptor_str
= vg_linear_alloc( vg_mem
.scratch
,
426 vg_align8(descriptor
.cur
*2+1) );
427 vg_bin_str( descriptor_buf
, descriptor_str
, descriptor
.cur
);
428 descriptor_str
[descriptor
.cur
*2] = '\0';
429 vg_info( "binstr: %s\n", descriptor_str
);
432 if( !vg_dir_open( &dir
, folder
.buffer
) ){
433 vg_error( "could not open addon folder '%s'\n", folder
.buffer
);
434 vg_async_call( workshop_async_any_complete
, NULL
, 0 );
438 while( vg_dir_next_entry(&dir
) ){
439 if( vg_dir_entry_type(&dir
) == k_vg_entry_type_file
){
440 const char *d_name
= vg_dir_entry_name(&dir
);
441 if( d_name
[0] == '.' ) continue;
443 vg_str file
= folder
;
444 vg_strcat( &file
, "/" );
445 vg_strcat( &file
, d_name
);
446 if( !vg_strgood( &file
) ) continue;
448 char *ext
= vg_strch( &file
, '.' );
450 if( strcmp(ext
,".mdl") ) continue;
452 vg_msg_wkvstr( &descriptor
, "content", d_name
);
458 vg_str descriptor_file
= folder
;
459 vg_strcat( &descriptor_file
, "/addon.inf" );
460 if( !vg_strgood(&descriptor_file
) ){
461 vg_error( "Addon info path too long\n" );
462 vg_async_call( workshop_async_any_complete
, NULL
, 0 );
466 FILE *fp
= fopen( descriptor_file
.buffer
, "wb" );
468 vg_error( "Could not open addon info file '%s'\n",
469 descriptor_file
.buffer
);
470 vg_async_call( workshop_async_any_complete
, NULL
, 0 );
473 fwrite( descriptor_buf
, descriptor
.cur
, 1, fp
);
477 * -----------------------------------------------------------------------*/
478 vg_str preview
= folder
;
479 vg_strcat( &preview
, "/preview.jpg" );
481 if( !vg_strgood(&preview
) ){
482 vg_error( "preview image path too long\n" );
483 vg_async_call( workshop_async_any_complete
, NULL
, 0 );
487 int w
= workshop_form
.img_w
,
488 h
= workshop_form
.img_h
;
490 vg_info( "writing: %s (%dx%d @90%%)\n", preview
.buffer
, w
,h
);
491 stbi_flip_vertically_on_write(1);
492 stbi_write_jpg( preview
.buffer
, w
,h
, 3, workshop_form
.img_buffer
, 90 );
494 vg_async_call( workshop_form_async_submit_begin
, descriptor_str
, 0 );
498 * Entry point for the publishing submission operation
500 VG_STATIC
void workshop_op_submit(void)
502 /* TODO: Show these errors to the user */
503 if( workshop_form
.submission
.submit_title
){
504 if( !workshop_form
.submission
.title
[0] ){
505 vg_error( "Cannot submit because a title is required\n" );
510 if( workshop_form
.submission
.submit_description
){
511 if( !workshop_form
.submission
.description
[0] ){
512 vg_error( "Cannot submit because a description is required\n" );
517 if( workshop_form
.submission
.submit_file_and_image
){
518 if( workshop_form
.file_intent
== k_workshop_form_file_intent_none
){
519 vg_error( "Cannot submit because the file is empty or unspecified\n" );
524 skaterift_begin_op( k_workshop_form_op_publishing_update
);
526 player_board_unload( &workshop_form
.board_model
);
527 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
529 vg_loader_start( _workshop_form_submit_thread
, NULL
);
533 * op: k_workshop_form_op_loading_model
534 * -----------------------------------------------------------------------------
538 * Reciever for completion of the model file load
540 VG_STATIC
void workshop_form_loadmodel_async_complete( void *payload
, u32 size
)
542 v2_zero( workshop_form
.view_angles
);
543 v3_zero( workshop_form
.view_offset
);
544 workshop_form
.view_dist
= 1.0f
;
545 workshop_form
.view_changed
= 1;
546 workshop_form
.file_intent
= k_workshop_form_file_intent_new
;
548 vg_success( "workshop async load complete\n" );
553 * Reciever for failure to load
555 VG_STATIC
void workshop_form_loadmodel_async_error( void *payload
, u32 size
)
561 * Thread which loads the model from the disk
563 VG_STATIC
void _workshop_form_load_thread( void *data
)
567 vg_strnull( &folder
, path_buf
, 4096 );
569 if( workshop_form
.submission
.type
== k_workshop_file_type_world
)
570 vg_strcat( &folder
, "maps/" );
571 else vg_strcat( &folder
, "boards/" );
573 vg_strcat( &folder
, workshop_form
.addon_folder
);
575 if( !vg_strgood(&folder
) ){
576 vg_error( "workshop async load failed: path too long\n" );
577 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
582 if( !vg_dir_open( &dir
, folder
.buffer
) ){
583 vg_error( "workshop async load failed: could not open folder\n" );
584 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
588 vg_info( "Searching %s for model files\n", folder
.buffer
);
591 while( vg_dir_next_entry(&dir
) ){
592 if( vg_dir_entry_type(&dir
) == k_vg_entry_type_file
){
593 const char *d_name
= vg_dir_entry_name(&dir
);
594 if( d_name
[0] == '.' ) continue;
596 vg_str file
= folder
;
597 vg_strcat( &file
, "/" );
598 vg_strcat( &file
, d_name
);
599 if( !vg_strgood( &file
) ) continue;
601 char *ext
= vg_strch( &file
, '.' );
603 if( strcmp(ext
,".mdl") ) continue;
611 vg_error( "workshop async load failed: no model files found\n" );
612 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
616 player_board_load( &workshop_form
.board_model
, path_buf
);
617 vg_async_call( workshop_form_loadmodel_async_complete
, NULL
, 0 );
621 * Entry point for load model operation
623 VG_STATIC
void workshop_op_load_model(void)
625 if( workshop_form
.submission
.type
== k_workshop_file_type_world
){
626 vg_error( "Currently unsupported\n" );
630 skaterift_begin_op( k_workshop_form_op_loading_model
);
631 vg_loader_start( _workshop_form_load_thread
, NULL
);
635 * op: k_workshop_form_op_downloading_submission
636 * -----------------------------------------------------------------------------
640 * The image has been decoded and is ready to slap into the framebuffer
642 VG_STATIC
void workshop_form_async_imageload( void *data
, u32 len
)
645 struct framebuffer_attachment
*a
=
646 &gpipeline
.fb_workshop_preview
->attachments
[0];
648 glBindTexture( GL_TEXTURE_2D
, a
->id
);
649 glTexSubImage2D( GL_TEXTURE_2D
, 0,0,0,
650 WORKSHOP_PREVIEW_WIDTH
, WORKSHOP_PREVIEW_HEIGHT
,
651 a
->format
, a
->type
, data
);
652 stbi_image_free( data
);
653 vg_success( "Loaded workshop preview image\n" );
660 * Load the image located at ./workshop_preview.jpg into our framebuffer
662 VG_STATIC
void _workshop_load_preview_thread( void *data
)
664 char path_buf
[ 4096 ];
666 vg_strnull( &path
, path_buf
, 4096 );
667 vg_strcat( &path
, "boards/" );
668 vg_strcat( &path
, workshop_form
.addon_folder
);
669 vg_strcat( &path
, "/preview.jpg" );
671 if( vg_strgood( &path
) ){
672 stbi_set_flip_vertically_on_load(1);
674 u8
*rgb
= stbi_load( path
.buffer
, &x
, &y
, &nc
, 3 );
677 if( (x
== WORKSHOP_PREVIEW_WIDTH
) && (y
== WORKSHOP_PREVIEW_HEIGHT
) ){
678 vg_async_call( workshop_form_async_imageload
, rgb
, x
*y
*3 );
681 vg_error( "Resolution does not match framebuffer, so we can't"
683 stbi_image_free( rgb
);
684 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
688 vg_error( "Failed to load workshop_preview.jpg: '%s'\n",
689 stbi_failure_reason() );
690 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
694 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
700 * Reciever for the preview download result
702 VG_STATIC
void on_workshop_download_ugcpreview( void *data
, void *user
)
704 struct workshop_loadpreview_info
*info
= user
;
705 RemoteStorageDownloadUGCResult_t
*result
= data
;
707 if( result
->m_eResult
== k_EResultOK
){
708 ISteamRemoteStorage
*hSteamRemoteStorage
= SteamAPI_SteamRemoteStorage();
709 vg_loader_start( _workshop_load_preview_thread
, info
);
712 vg_error( "Error while donwloading UGC preview( %d )\n",
720 * Entry point to view operation
722 VG_STATIC
void workshop_op_download_and_view_submission( int result_index
)
724 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
725 ISteamRemoteStorage
*hSteamRemoteStorage
= SteamAPI_SteamRemoteStorage();
726 SteamUGCDetails_t details
;
727 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC
,
728 workshop_form
.ugc_query
.handle
,
732 skaterift_begin_op( k_workshop_form_op_downloading_submission
);
733 workshop_reset_submission_data();
734 workshop_form
.submission
.submit_description
= 0;
735 workshop_form
.submission
.submit_file_and_image
= 0;
736 workshop_form
.submission
.submit_title
= 0;
738 u8 metadata_buf
[512];
739 char metadata_str
[1024+1];
740 int have_meta
= SteamAPI_ISteamUGC_GetQueryUGCMetadata( hSteamUGC
,
741 workshop_form
.ugc_query
.handle
,
742 result_index
, metadata_str
,
745 vg_strncpy( details
.m_rgchDescription
,
746 workshop_form
.submission
.description
,
747 vg_list_size( workshop_form
.submission
.description
),
748 k_strncpy_always_add_null
);
750 vg_strncpy( details
.m_rgchTitle
,
751 workshop_form
.submission
.title
,
752 vg_list_size( workshop_form
.submission
.title
),
753 k_strncpy_always_add_null
);
755 snprintf( workshop_form
.addon_folder
,
756 vg_list_size( workshop_form
.addon_folder
),
757 "Steam Cloud ("PRINTF_U64
")", details
.m_nPublishedFileId
);
759 workshop_form
.submission
.file_id
= details
.m_nPublishedFileId
;
760 workshop_form
.file_intent
= k_workshop_form_file_intent_keep_old
;
761 workshop_form
.page
= k_workshop_form_edit
;
762 workshop_form
.submission
.visibility
.value
= details
.m_eVisibility
;
763 workshop_form
.submission
.type
= k_workshop_file_type_none
;
764 workshop_form
.submission
.submission_type_selection
.index
= 0;
765 workshop_form
.submission
.submission_type_selection
.value
=
766 k_workshop_file_type_none
;
769 u32 len
= strlen(metadata_str
);
770 vg_info( "Metadata: %s\n", metadata_str
);
771 vg_str_bin( metadata_str
, metadata_buf
, len
);
773 vg_msg_init( &root
, metadata_buf
, len
/2 );
776 if( vg_msg_seekframe( &workshop
, "workshop", k_vg_msg_first
)){
777 vg_msg_cmd kv_type
= vg_msg_seekkv( &workshop
, "type",
779 if( kv_type
.code
& k_vg_msg_code_integer
){
780 u32 u
= kv_type
.value
._u32
;
781 workshop_form
.submission
.type
= u
;
782 workshop_form
.submission
.submission_type_selection
.value
= u
;
785 const char *kv_folder
= vg_msg_seekkvstr( &workshop
, "folder",
788 vg_strncpy( kv_folder
, workshop_form
.addon_folder
,
789 sizeof(workshop_form
.addon_folder
),
790 k_strncpy_always_add_null
);
795 vg_error( "No metadata was returned with this item.\n" );
799 for( i32 i
=0; i
<vg_list_size(workshop_form_visibility_opts
); i
++ ){
800 if( workshop_form_visibility_opts
[i
].value
== details
.m_eVisibility
){
801 workshop_form
.submission
.visibility
.index
= i
;
805 for( i32 i
=0; i
<vg_list_size(workshop_form_type_opts
); i
++ ){
806 if( workshop_form_type_opts
[i
].value
==
807 workshop_form
.submission
.submission_type_selection
.value
){
808 workshop_form
.submission
.submission_type_selection
.index
= i
;
813 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
814 glClearColor( 0.2f
, 0.0f
, 0.0f
, 1.0f
);
815 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
816 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
817 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
819 vg_loader_start( _workshop_load_preview_thread
, NULL
);
822 if( details
.m_hPreviewFile
== 0 ){
823 vg_error( "m_hPreviewFile is 0\n" );
827 /* Now need to begin downloading the image so we can display it */
828 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
830 struct workshop_loadpreview_info
*info
=
831 vg_linear_alloc( vg_mem
.scratch
,
832 sizeof( struct workshop_loadpreview_info
) );
834 snprintf( info
->abs_preview_image
, 1024,
835 "%smodels/boards/workshop/" PRINTF_U64
".jpg",
836 vg
.base_path
, details
.m_hPreviewFile
);
838 call
->p_handler
= on_workshop_download_ugcpreview
;
839 call
->userdata
= info
;
840 call
->id
= SteamAPI_ISteamRemoteStorage_UGCDownloadToLocation(
842 details
.m_hPreviewFile
, info
->abs_preview_image
, 1 );
844 vg_info( "preview file id: " PRINTF_U64
"\n",
845 details
.m_hPreviewFile
);
850 vg_error( "GetQueryUGCResult: Index out of range\n" );
857 * -----------------------------------------------------------------------------
861 * View a page of results on the sidebar
863 VG_STATIC
void workshop_view_page( int req
)
865 if( workshop_form
.ugc_query
.result
!= k_EResultOK
){
866 vg_error( "Tried to change page without complete data\n" );
870 int page
= VG_MAX(VG_MIN(req
, workshop_form
.view_published_page_count
-1),0),
871 start
= page
* WORKSHOP_VIEW_PER_PAGE
,
872 end
= VG_MIN( (page
+1) * WORKSHOP_VIEW_PER_PAGE
,
873 workshop_form
.ugc_query
.returned_item_count
),
876 vg_info( "View page %d\n", page
);
878 workshop_form
.view_published_page_id
= page
;
879 workshop_form
.published_files_list_length
= count
;
880 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
882 for( int i
=0; i
<count
; i
++ ){
883 struct published_file
*pfile
= &workshop_form
.published_files_list
[i
];
885 SteamUGCDetails_t details
;
886 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC
,
887 workshop_form
.ugc_query
.handle
,
891 if( details
.m_eResult
!= k_EResultOK
){
892 snprintf( pfile
->title
, 80, "Error (%d)", details
.m_eResult
);
895 vg_strncpy( details
.m_rgchTitle
, pfile
->title
, 80,
896 k_strncpy_always_add_null
);
899 pfile
->result
= details
.m_eResult
;
900 pfile
->result_index
= start
+i
;
903 pfile
->result
= k_EResultValueOutOfRange
;
904 pfile
->result_index
= -1;
905 snprintf( pfile
->title
, 80, "Error (invalid index)" );
911 * Steam API result for when we recieve submitted UGC information about the user
913 VG_STATIC
void on_workshop_UGCQueryComplete( void *data
, void *userdata
)
915 SteamUGCQueryCompleted_t
*query
= data
;
916 workshop_form
.ugc_query
.result
= query
->m_eResult
;
918 if( query
->m_eResult
== k_EResultOK
){
919 if( query
->m_unTotalMatchingResults
> 50 ){
920 vg_warn( "You have %d items submitted, "
921 "we can only view the last 50\n" );
924 workshop_form
.ugc_query
.all_item_count
= query
->m_unTotalMatchingResults
;
925 workshop_form
.ugc_query
.returned_item_count
=
926 query
->m_unNumResultsReturned
;
928 workshop_form
.ugc_query
.handle
= query
->m_handle
;
929 workshop_form
.view_published_page_count
=
930 (query
->m_unNumResultsReturned
+WORKSHOP_VIEW_PER_PAGE
-1)/
931 WORKSHOP_VIEW_PER_PAGE
;
932 workshop_form
.view_published_page_id
= 0;
933 workshop_form
.published_files_list_length
= 0;
935 workshop_view_page( 0 );
938 vg_error( "Steam UGCQuery failed (%d)\n", query
->m_eResult
);
939 workshop_form
.view_published_page_count
= 0;
940 workshop_form
.view_published_page_id
= 0;
941 workshop_form
.published_files_list_length
= 0;
943 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
944 SteamAPI_ISteamUGC_ReleaseQueryUGCRequest( hSteamUGC
, query
->m_handle
);
949 * Console command to open the workshop publisher
951 VG_STATIC
int workshop_submit_command( int argc
, const char *argv
[] )
954 vg_error( "Steam API is not ready or loaded\n" );
958 workshop_form
.page
= k_workshop_form_open
;
959 workshop_form
.view_published_page_count
= 0;
960 workshop_form
.view_published_page_id
= 0;
961 workshop_form
.published_files_list_length
= 0;
962 workshop_form
.ugc_query
.result
= k_EResultNone
;
964 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
966 ISteamUser
*hSteamUser
= SteamAPI_SteamUser();
968 steamid
.m_unAll64Bits
= SteamAPI_ISteamUser_GetSteamID( hSteamUser
);
970 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
971 call
->p_handler
= on_workshop_UGCQueryComplete
;
972 call
->userdata
= NULL
;
973 UGCQueryHandle_t handle
= SteamAPI_ISteamUGC_CreateQueryUserUGCRequest
976 steamid
.m_comp
.m_unAccountID
,
977 k_EUserUGCList_Published
,
978 k_EUGCMatchingUGCType_Items
,
979 k_EUserUGCListSortOrder_CreationOrderDesc
,
980 SKATERIFT_APPID
, SKATERIFT_APPID
,
982 SteamAPI_ISteamUGC_SetReturnMetadata( hSteamUGC
, handle
, 1 );
983 call
->id
= SteamAPI_ISteamUGC_SendQueryUGCRequest( hSteamUGC
, handle
);
987 VG_STATIC
void workshop_init(void)
989 vg_console_reg_cmd( "workshop_submit", workshop_submit_command
, NULL
);
992 VG_STATIC
void workshop_find_preview_entity(void)
994 workshop_form
.view_world
= world_current_instance();
996 if( mdl_arrcount( &workshop_form
.view_world
->ent_swspreview
) ){
997 workshop_form
.ptr_ent
=
998 mdl_arritm( &workshop_form
.view_world
->ent_swspreview
, 0 );
999 workshop_form
.page
= k_workshop_form_edit
;
1002 vg_error( "There is no ent_swspreview in the level. "
1003 "Cannot publish here\n" );
1008 * Redraw the model file into the workshop framebuffer
1010 VG_STATIC
void workshop_render_preview(void)
1012 if( !workshop_form
.ptr_ent
){
1016 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
1018 glClearColor( 0.0f
, 0.0f
, 0.3f
, 1.0f
);
1019 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
1020 glEnable( GL_DEPTH_TEST
);
1021 glDisable( GL_BLEND
);
1023 ent_swspreview
*swsprev
= workshop_form
.ptr_ent
;
1024 world_instance
*world
= workshop_form
.view_world
;
1026 ent_camera
*ref
= mdl_arritm( &world
->ent_camera
,
1027 mdl_entity_id_id(swsprev
->id_camera
) );
1028 ent_marker
*display
= mdl_arritm( &world
->ent_marker
,
1029 mdl_entity_id_id(swsprev
->id_display
) ),
1030 *display1
= mdl_arritm( &world
->ent_marker
,
1031 mdl_entity_id_id(swsprev
->id_display1
) );
1034 v3_add( display
->transform
.co
, display1
->transform
.co
, baseco
);
1035 v3_muls( baseco
, 0.5f
, baseco
);
1039 v3_sub( display
->transform
.co
, ref
->transform
.co
, basevector
);
1040 float dist
= v3_length( basevector
);
1043 player_vector_angles( baseangles
, basevector
, 1.0f
, 0.0f
);
1045 v2_add( workshop_form
.view_angles
, baseangles
, cam
.angles
);
1046 cam
.angles
[2] = 0.0f
;
1048 float sX
= sinf( cam
.angles
[0] ),
1049 cX
= cosf( cam
.angles
[0] ),
1050 sY
= sinf( cam
.angles
[1] ),
1051 cY
= cosf( cam
.angles
[1] );
1053 v3f offset
= { -sX
* cY
, sY
, cX
* cY
};
1055 v3_muladds( display
->transform
.co
, offset
,
1056 dist
*workshop_form
.view_dist
, cam
.pos
);
1058 cam
.pos
[0] += -sX
*workshop_form
.view_offset
[2];
1059 cam
.pos
[2] += cX
*workshop_form
.view_offset
[2];
1060 cam
.pos
[0] += cX
*workshop_form
.view_offset
[0];
1061 cam
.pos
[2] += sX
*workshop_form
.view_offset
[0];
1062 cam
.pos
[1] += workshop_form
.view_offset
[1];
1068 camera_update_transform( &cam
);
1069 camera_update_view( &cam
);
1070 camera_update_projection( &cam
);
1071 camera_finalize( &cam
);
1074 mdl_transform_m4x3( &display
->transform
, mmdl
);
1075 mdl_transform_m4x3( &display1
->transform
, mmdl1
);
1077 /* force update this for nice shadows. its usually set in the world
1078 * pre-render step, but that includes timer stuff
1080 struct player_board
*board
= &workshop_form
.board_model
;
1081 struct ub_world_lighting
*ubo
= &world
->ub_lighting
;
1083 v3_copy((v3f
){0.0f
,0.1f
, board
->truck_positions
[0][2]}, vp0
);
1084 v3_copy((v3f
){0.0f
,0.1f
, board
->truck_positions
[1][2]}, vp1
);
1085 m4x3_mulv( mmdl1
, vp0
, ubo
->g_board_0
);
1086 m4x3_mulv( mmdl1
, vp1
, ubo
->g_board_1
);
1087 glBindBuffer( GL_UNIFORM_BUFFER
, world
->ubo_lighting
);
1088 glBufferSubData( GL_UNIFORM_BUFFER
, 0,
1089 sizeof(struct ub_world_lighting
), &world
->ub_lighting
);
1091 render_world( world
, &cam
, 1 );
1092 render_board( &cam
, world
, board
, mmdl
, k_board_shader_entity
);
1093 render_board( &cam
, world
, board
, mmdl1
, k_board_shader_entity
);
1095 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
1096 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
1100 * ImGUI section for workshop form
1101 * -----------------------------------------------------------------------------
1104 VG_STATIC
void workshop_changed_model_path( char *buf
, u32 len
){
1105 workshop_form
.submission
.submit_file_and_image
= 1;
1108 VG_STATIC
void workshop_changed_title( char *buf
, u32 len
){
1109 workshop_form
.submission
.submit_title
= 1;
1112 VG_STATIC
void workshop_changed_description( char *buf
, u32 len
){
1113 workshop_form
.submission
.submit_description
= 1;
1116 VG_STATIC
void workshop_form_gui_edit_page( ui_rect content
)
1118 if( workshop_form
.submission
.type
== k_workshop_file_type_none
){
1120 rect_copy( content
, box
);
1122 box
[2] = (box
[2]*2)/3;
1123 ui_rect_center( content
, box
);
1126 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1127 ui_text( row
, "Select the type of item\n", 1, k_ui_align_middle_center
,0);
1128 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1129 ui_enum( row
, "Type:", workshop_form_type_opts
,
1130 3, &workshop_form
.submission
.submission_type_selection
);
1131 ui_split( box
, k_ui_axis_h
, 8, 0, row
, box
);
1132 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1134 ui_rect button_l
, button_r
;
1135 rect_copy( row
, button_l
);
1136 button_l
[2] = 128*2;
1137 ui_rect_center( row
, button_l
);
1138 ui_split_ratio( button_l
, k_ui_axis_v
, 0.5f
, 2, button_l
, button_r
);
1140 if( workshop_form
.submission
.submission_type_selection
.value
!=
1141 k_workshop_file_type_none
){
1142 if( ui_button_text( button_l
, "OK", 1 ) ){
1143 workshop_form
.submission
.type
=
1144 workshop_form
.submission
.submission_type_selection
.value
;
1148 ui_fill( button_l
, ui_colour(k_ui_bg
) );
1149 ui_text( button_l
, "OK", 1, k_ui_align_middle_center
,
1150 ui_colour(k_ui_bg
+4) );
1153 if( ui_button_text( button_r
, "Cancel", 1 ) ){
1154 workshop_form
.page
= k_workshop_form_open
;
1155 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1160 if( workshop_form
.submission
.type
== k_workshop_file_type_world
){
1162 rect_copy( content
, box
);
1164 box
[2] = (box
[2]*2)/3;
1165 ui_rect_center( content
, box
);
1168 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1169 ui_text( row
, "World submissions are currently not ready, sorry.",
1170 1, k_ui_align_middle_center
,0);
1171 ui_split( box
, k_ui_axis_h
, 8, 0, row
, box
);
1172 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1175 rect_copy( row
, button
);
1177 ui_rect_center( row
, button
);
1178 if( ui_button_text( button
, "OK", 1 ) ){
1179 workshop_form
.page
= k_workshop_form_open
;
1180 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1186 ui_rect image_plane
;
1187 ui_split( content
, k_ui_axis_h
, 300, 0, image_plane
, content
);
1188 ui_fill( image_plane
, ui_colour( k_ui_bg
+0 ) );
1191 ui_fit_item( image_plane
, (ui_px
[2]){ 3, 2 }, img_box
);
1193 if( workshop_form
.file_intent
== k_workshop_form_file_intent_keep_old
){
1194 ui_image( img_box
, gpipeline
.fb_workshop_preview
->attachments
[0].id
);
1196 else if( workshop_form
.file_intent
== k_workshop_form_file_intent_new
){
1197 ui_image( img_box
, gpipeline
.fb_workshop_preview
->attachments
[0].id
);
1198 int hover
= ui_inside_rect( img_box
, vg_ui
.mouse
),
1199 target
= ui_inside_rect( img_box
, vg_ui
.mouse_click
);
1201 if( ui_click_down(UI_MOUSE_MIDDLE
) && target
){
1202 v3_copy( workshop_form
.view_offset
,
1203 workshop_form
.view_offset_begin
);
1205 else if( ui_click_down(UI_MOUSE_LEFT
) && target
){
1206 v2_copy( workshop_form
.view_angles
,
1207 workshop_form
.view_angles_begin
);
1210 if( ui_clicking(UI_MOUSE_MIDDLE
) && target
){
1211 v2f delta
= { vg_ui
.mouse
[0]-vg_ui
.mouse_click
[0],
1212 vg_ui
.mouse
[1]-vg_ui
.mouse_click
[1] };
1214 float *begin
= workshop_form
.view_offset_begin
,
1215 *offset
= workshop_form
.view_offset
;
1216 offset
[0] = vg_clampf( begin
[0]-delta
[0]*0.002f
, -1.0f
, 1.0f
);
1217 offset
[2] = vg_clampf( begin
[2]-delta
[1]*0.002f
, -1.0f
, 1.0f
);
1218 workshop_form
.view_changed
= 1;
1220 else if( ui_clicking(UI_MOUSE_LEFT
) && target
){
1221 v2f delta
= { vg_ui
.mouse
[0]-vg_ui
.mouse_click
[0],
1222 vg_ui
.mouse
[1]-vg_ui
.mouse_click
[1] };
1225 v2_muladds( workshop_form
.view_angles_begin
, delta
, 0.002f
, angles
);
1227 float limit
= VG_PIf
*0.2f
;
1229 angles
[0] = vg_clampf( angles
[0], -limit
, limit
);
1230 angles
[1] = vg_clampf( angles
[1], -limit
, limit
);
1232 v2_copy( angles
, workshop_form
.view_angles
);
1233 workshop_form
.view_changed
= 1;
1236 if( !ui_clicking(UI_MOUSE_LEFT
) && hover
){
1237 float zoom
= workshop_form
.view_dist
;
1238 zoom
+= vg
.mouse_wheel
[1] * -0.07f
;
1239 zoom
= vg_clampf( zoom
, 0.4f
, 2.0f
);
1241 if( zoom
!= workshop_form
.view_dist
){
1242 workshop_form
.view_changed
= 1;
1243 workshop_form
.view_dist
= zoom
;
1248 ui_text( img_box
, "No image", 1, k_ui_align_middle_center
,
1249 ui_colour( k_ui_orange
) );
1253 ui_rect null
, file_entry
, file_button
, file_label
;
1254 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1255 ui_split( content
, k_ui_axis_h
, 28, 0, file_entry
, content
);
1256 ui_split( file_entry
, k_ui_axis_v
, -128, 0, file_entry
, file_button
);
1258 if( workshop_form
.submission
.type
== k_workshop_file_type_board
){
1259 ui_label( file_entry
, "Addon folder: skaterift/boards/",
1263 ui_label( file_entry
, "Addon folder: skaterift/maps/",
1267 if( workshop_form
.file_intent
!= k_workshop_form_file_intent_none
){
1268 ui_text( file_entry
, workshop_form
.addon_folder
, 1,
1269 k_ui_align_middle_left
, ui_colour( k_ui_fg
+4 ) );
1271 if( ui_button_text( file_button
, "Remove", 1 ) ){
1272 player_board_unload( &workshop_form
.board_model
);
1273 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1274 workshop_form
.addon_folder
[0] = '\0';
1278 struct ui_textbox_callbacks callbacks
= {
1279 .change
= workshop_changed_model_path
1282 ui_textbox( file_entry
, workshop_form
.addon_folder
,
1283 vg_list_size(workshop_form
.addon_folder
), 0, &callbacks
);
1285 if( ui_button_text( file_button
, "Load", 1 ) ){
1286 workshop_find_preview_entity();
1287 workshop_op_load_model();
1291 ui_rect title_entry
, label
;
1292 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1293 ui_split( content
, k_ui_axis_h
, 28, 0, title_entry
, content
);
1295 const char *str_title
= "Title:", *str_desc
= "Description:";
1296 ui_split( title_entry
, k_ui_axis_v
,
1297 ui_text_line_width(str_title
)+8, 0, label
, title_entry
);
1299 ui_rect vis_dropdown
;
1300 ui_split_ratio( title_entry
, k_ui_axis_v
, 0.6f
, 16,
1301 title_entry
, vis_dropdown
);
1305 struct ui_textbox_callbacks callbacks
= {
1306 .change
= workshop_changed_title
1308 ui_text( label
, str_title
, 1, k_ui_align_middle_left
, 0 );
1309 ui_textbox( title_entry
, workshop_form
.submission
.title
,
1310 vg_list_size(workshop_form
.submission
.title
), 0, &callbacks
);
1313 /* visibility option */
1315 ui_enum( vis_dropdown
, "Visibility:", workshop_form_visibility_opts
,
1316 4, &workshop_form
.submission
.visibility
);
1319 /* description box */
1321 struct ui_textbox_callbacks callbacks
= {
1322 .change
= workshop_changed_description
1325 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1326 ui_split( content
, k_ui_axis_h
, 28, 0, label
, content
);
1327 ui_split( content
, k_ui_axis_h
, 28*4, 0, desc_entry
, content
);
1328 ui_text( label
, str_desc
, 1, k_ui_align_middle_left
, 0 );
1329 ui_textbox( desc_entry
, workshop_form
.submission
.description
,
1330 vg_list_size(workshop_form
.submission
.description
),
1331 UI_TEXTBOX_MULTILINE
|UI_TEXTBOX_WRAP
, &callbacks
);
1334 /* submissionable */
1335 ui_rect submission_row
;
1336 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1337 ui_split( content
, k_ui_axis_h
, content
[3]-32-8, 0, content
,
1340 ui_rect submission_center
;
1341 rect_copy( submission_row
, submission_center
);
1342 submission_center
[2] = 256;
1343 ui_rect_center( submission_row
, submission_center
);
1345 ui_rect btn_left
, btn_right
;
1346 ui_split_ratio( submission_center
, k_ui_axis_v
, 0.5f
, 8,
1347 btn_left
, btn_right
);
1349 if( ui_button_text( btn_left
, "Publish", 1 ) ){
1350 workshop_op_submit();
1352 if( ui_button_text( btn_right
, "Cancel", 1 ) ){
1353 workshop_form
.page
= k_workshop_form_open
;
1354 player_board_unload( &workshop_form
.board_model
);
1355 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1359 const char *disclaimer_text
=
1360 "By submitting this item, you agree to the workshop terms of service";
1362 ui_rect disclaimer_row
, inner
, link
;
1363 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1364 ui_split( content
, k_ui_axis_h
, content
[3]-32, 0, content
,
1367 ui_px btn_width
= 32;
1369 rect_copy( disclaimer_row
, inner
);
1370 inner
[2] = ui_text_line_width( disclaimer_text
) + btn_width
+8;
1372 ui_rect_center( disclaimer_row
, inner
);
1373 ui_split( inner
, k_ui_axis_v
, inner
[2]-btn_width
, 0, label
, btn_right
);
1374 ui_rect_pad( btn_right
, (ui_px
[2]){2,2} );
1376 if( ui_button_text( btn_right
, "\x91", 2 ) ){
1377 ISteamFriends
*hSteamFriends
= SteamAPI_SteamFriends();
1378 SteamAPI_ISteamFriends_ActivateGameOverlayToWebPage( hSteamFriends
,
1379 "https://steamcommunity.com/sharedfiles/workshoplegalagreement",
1380 k_EActivateGameOverlayToWebPageMode_Default
);
1383 ui_text( label
, disclaimer_text
, 1, k_ui_align_middle_left
,
1384 ui_colour( k_ui_fg
+4 ) );
1387 VG_STATIC
void workshop_form_gui_sidebar( ui_rect sidebar
)
1389 ui_fill( sidebar
, ui_colour( k_ui_bg
+2 ) );
1392 ui_split( sidebar
, k_ui_axis_h
, 28, 0, title
, sidebar
);
1394 if( workshop_form
.page
== k_workshop_form_edit
){
1395 ui_text( title
, "Editing", 1, k_ui_align_middle_center
, 0 );
1396 ui_split( sidebar
, k_ui_axis_h
, 28, 0, title
, sidebar
);
1398 if( workshop_form
.submission
.type
!= k_workshop_file_type_none
){
1401 vg_strnull( &str
, buf
, 512 );
1403 if( workshop_form
.submission
.file_id
)
1404 vg_strcat( &str
, "Editing an existing " );
1406 vg_strcat( &str
, "Creating a new " );
1408 if( workshop_form
.submission
.type
== k_workshop_file_type_board
)
1409 vg_strcat( &str
, "skateboard." );
1410 else if( workshop_form
.submission
.type
== k_workshop_file_type_world
)
1411 vg_strcat( &str
, "world." );
1413 vg_strcat( &str
, "???." );
1415 ui_text( title
, buf
, 1, k_ui_align_middle_center
,
1416 ui_colour(k_ui_fg
+4) );
1422 * sidebar existing entries panel
1424 ui_text( title
, "Your submissions", 1, k_ui_align_middle_center
, 0 );
1426 ui_rect controls
, btn_create_new
;
1427 ui_split( sidebar
, k_ui_axis_h
, 32, 0, controls
, sidebar
);
1428 ui_split( sidebar
, k_ui_axis_h
, -32, 0, sidebar
, btn_create_new
);
1429 ui_fill( controls
, ui_colour( k_ui_bg
+1 ) );
1432 strcpy( buf
, "page " );
1434 i
+= highscore_intl( buf
+i
, workshop_form
.view_published_page_id
+1, 4 );
1436 i
+= highscore_intl( buf
+i
, workshop_form
.view_published_page_count
, 4 );
1439 ui_rect_pad( controls
, (ui_px
[2]){0,4} );
1441 ui_split_ratio( controls
, k_ui_axis_v
, 0.25f
, 0, info
, controls
);
1442 ui_text( info
, buf
, 1, k_ui_align_middle_center
, 0 );
1444 ui_rect btn_left
, btn_right
;
1445 ui_split_ratio( controls
, k_ui_axis_v
, 0.5f
, 2, btn_left
, btn_right
);
1447 if( ui_button_text( btn_left
, "newer", 1 ) ){
1448 workshop_view_page( workshop_form
.view_published_page_id
-1 );
1451 if( ui_button_text( btn_right
, "older", 1 ) ){
1452 workshop_view_page( workshop_form
.view_published_page_count
+1 );
1455 if( ui_button_text( btn_create_new
, "Create New Item", 1 ) ){
1456 workshop_reset_submission_data();
1457 workshop_form
.submission
.submit_title
= 1;
1458 workshop_form
.submission
.submit_description
= 1;
1459 workshop_form
.submission
.submit_file_and_image
= 1;
1460 workshop_form
.page
= k_workshop_form_edit
;
1461 workshop_find_preview_entity();
1464 for( int i
=0; i
<workshop_form
.published_files_list_length
; i
++ ){
1466 ui_split( sidebar
, k_ui_axis_h
, 28, 0, item
, sidebar
);
1467 ui_rect_pad( item
, (ui_px
[2]){4,4} );
1469 struct published_file
*pfile
= &workshop_form
.published_files_list
[i
];
1470 if( ui_button_text( item
, pfile
->title
, 1 ) ){
1471 if( pfile
->result
== k_EResultOK
){
1472 vg_info( "Select index: %d\n", pfile
->result_index
);
1473 workshop_op_download_and_view_submission( pfile
->result_index
);
1476 vg_warn( "Cannot select that item, result not OK\n" );
1482 VG_STATIC
void workshop_form_gui(void)
1484 enum workshop_form_page stable_page
= workshop_form
.page
;
1485 if( stable_page
== k_workshop_form_hidden
) return;
1488 ui_rect screen
= { 0, 0, vg
.window_x
, vg
.window_y
};
1489 ui_rect window
= { 0, 0, 1000, 700 };
1490 ui_rect_center( screen
, window
);
1491 vg_ui
.wants_mouse
= 1;
1493 ui_fill( window
, ui_colour( k_ui_bg
+1 ) );
1494 ui_outline( window
, 1, ui_colour( k_ui_bg
+7 ) );
1496 ui_rect title
, panel
;
1497 ui_split( window
, k_ui_axis_h
, 28, 0, title
, panel
);
1498 ui_fill( title
, ui_colour( k_ui_bg
+7 ) );
1499 ui_text( title
, "Workshop tool", 1, k_ui_align_middle_center
,
1500 ui_colourcont(k_ui_bg
+7) );
1502 ui_rect quit_button
;
1503 ui_split( title
, k_ui_axis_v
, title
[2]-title
[3], 2, title
, quit_button
);
1505 if( skaterift
.async_op
== k_async_op_none
){
1506 if( ui_button_text( quit_button
, "X", 1 ) ){
1507 workshop_quit_form();
1513 * temporary operation blinders, we don't yet have a nice way to show the
1514 * user that we're doing something uninterruptable, so the code just
1515 * escapes here and we show them a basic string
1518 if( skaterift
.async_op
!= k_async_op_none
){
1519 const char *op_string
= "The programmer has not bothered to describe "
1520 "the current operation that is running.";
1522 switch( skaterift
.async_op
){
1523 case k_workshop_form_op_loading_model
:
1524 op_string
= "Operation in progress: Loading model file.";
1526 case k_workshop_form_op_publishing_update
:
1527 op_string
= "Operation in progress: publishing submission update "
1530 case k_workshop_form_op_downloading_submission
:
1531 op_string
= "Operation in progress: downloading existing submission"
1532 " from Steam services.";
1537 ui_text( panel
, op_string
, 1, k_ui_align_middle_center
, 0 );
1541 /* re draw board preview if need to */
1542 if( (stable_page
== k_workshop_form_edit
) &&
1543 workshop_form
.view_changed
&&
1544 workshop_form
.file_intent
== k_workshop_form_file_intent_new
)
1546 workshop_render_preview();
1547 workshop_form
.view_changed
= 0;
1550 struct workshop_form
*form
= &workshop_form
;
1552 ui_rect sidebar
, content
;
1553 ui_split_ratio( panel
, k_ui_axis_v
, 0.3f
, 1, sidebar
, content
);
1556 ui_rect_pad( content
, (ui_px
[2]){8,8} );
1558 if( stable_page
== k_workshop_form_edit
){
1559 workshop_form_gui_edit_page( content
);
1561 else if( stable_page
== k_workshop_form_open
){
1562 ui_text( content
, "Nothing selected.", 1, k_ui_align_middle_center
,
1563 ui_colour( k_ui_fg
+4 ) );
1565 else if( stable_page
>= k_workshop_form_cclosing
){
1566 ui_rect submission_row
;
1567 ui_split( content
, k_ui_axis_h
, content
[3]-32-8, 0, content
,
1572 if( stable_page
== k_workshop_form_closing_bad
)
1573 colour
= ui_colour( k_ui_red
+k_ui_brighter
);
1575 colour
= ui_colour( k_ui_green
+k_ui_brighter
);
1577 ui_text( content
, workshop_form
.failure_or_success_string
, 1,
1578 k_ui_align_middle_center
, colour
);
1580 ui_rect submission_center
;
1581 rect_copy( submission_row
, submission_center
);
1582 submission_center
[2] = 128;
1583 ui_rect_center( submission_row
, submission_center
);
1584 ui_rect_pad( submission_center
, (ui_px
[2]){8,8} );
1586 if( ui_button_text( submission_center
, "OK", 1 ) ){
1587 workshop_form
.page
= k_workshop_form_open
;
1591 workshop_form_gui_sidebar( sidebar
);
1595 * Some async api stuff
1596 * -----------------------------------------------------------------------------
1599 VG_STATIC
void async_workshop_get_filepath( void *data
, u32 len
)
1601 struct async_workshop_filepath_info
*info
= data
;
1606 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
1607 if( !SteamAPI_ISteamUGC_GetItemInstallInfo( hSteamUGC
, info
->id
, &_size
,
1608 info
->buf
, info
->len
, &_ts
))
1610 vg_error( "GetItemInstallInfo failed\n" );
1611 info
->buf
[0] = '\0';
1615 VG_STATIC
void async_workshop_get_installed_files( void *data
, u32 len
)
1617 struct async_workshop_installed_files_info
*info
= data
;
1619 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
1620 u32 count
= SteamAPI_ISteamUGC_GetSubscribedItems( hSteamUGC
, info
->buffer
,
1623 vg_info( "Found %u subscribed items\n", count
);
1626 for( u32 i
=0; i
<count
; i
++ ){
1627 u32 state
= SteamAPI_ISteamUGC_GetItemState( hSteamUGC
, info
->buffer
[i
] );
1628 if( state
& k_EItemStateInstalled
){
1629 info
->buffer
[j
++] = info
->buffer
[i
];
1637 VG_STATIC
void vg_strsan_ascii( char *buf
, u32 len
)
1639 for( u32 i
=0; i
<len
-1; i
++ ){
1640 if( buf
[i
] == 0 ) return;
1642 if( buf
[i
] < 32 || buf
[i
] > 126 ){
1649 #define VG_STRSAN_ASCII( X ) vg_strsan_ascii( X, vg_list_size(X) )
1651 VG_STATIC
void workshop_load_metadata( const char *path
,
1652 struct workshop_file_info
*info
)
1654 FILE *fp
= fopen( path
, "rb" );
1657 if( fread( info
, sizeof( struct workshop_file_info
), 1, fp
) ){
1658 VG_STRSAN_ASCII( info
->author_name
);
1659 VG_STRSAN_ASCII( info
->title
);
1666 #endif /* WORKSHOP_C */