10 #include "ent_skateshop.h"
12 #include "vg/vg_steam_auth.h"
13 #include "vg/vg_steam_ugc.h"
14 #include "vg/vg_steam_friends.h"
16 #include "highscores.h"
18 static struct ui_dropdown_opt workshop_form_visibility_opts
[] = {
19 { "Public", k_ERemoteStoragePublishedFileVisibilityPublic
},
20 { "Unlisted", k_ERemoteStoragePublishedFileVisibilityUnlisted
},
21 { "Friends Only", k_ERemoteStoragePublishedFileVisibilityFriendsOnly
},
22 { "Private", k_ERemoteStoragePublishedFileVisibilityPrivate
},
25 static struct ui_dropdown_opt workshop_form_type_opts
[] = {
26 { "None", k_addon_type_none
},
27 { "Board", k_addon_type_board
},
28 { "World", k_addon_type_world
},
32 * Close the form and discard UGC query result
34 VG_STATIC
void workshop_quit_form(void)
36 skaterift_begin_op( k_async_op_none
); /* safeguard */
37 player_board_unload( &workshop_form
.board_model
);
38 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
40 if( workshop_form
.ugc_query
.result
== k_EResultOK
){
41 workshop_form
.ugc_query
.result
= k_EResultNone
;
43 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
44 SteamAPI_ISteamUGC_ReleaseQueryUGCRequest(
45 hSteamUGC
, workshop_form
.ugc_query
.handle
);
48 workshop_form
.page
= k_workshop_form_hidden
;
53 * Delete all information about the submission
55 VG_STATIC
void workshop_reset_submission_data(void)
57 workshop_form
.submission
.file_id
= 0; /* assuming id of 0 is none/invalid */
58 workshop_form
.submission
.description
[0] = '\0';
59 workshop_form
.submission
.title
[0] = '\0';
60 workshop_form
.submission
.author
[0] = '\0';
61 workshop_form
.submission
.submission_type_selection
.value
=
63 workshop_form
.submission
.submission_type_selection
.index
= 0;
64 workshop_form
.submission
.type
= k_addon_type_none
;
66 workshop_form
.submission
.visibility
.value
=
67 k_ERemoteStoragePublishedFileVisibilityPublic
;
68 workshop_form
.submission
.visibility
.index
= 0;
70 workshop_form
.addon_folder
[0] = '\0';
71 player_board_unload( &workshop_form
.board_model
);
72 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
77 * Mostly copies of what it sais on the Steam API documentation
79 VG_STATIC
const char *workshop_EResult_user_string( EResult result
)
82 case k_EResultInsufficientPrivilege
:
83 return "Your account is currently restricted from uploading content "
84 "due to a hub ban, account lock, or community ban. You need to "
85 "contact Steam Support to resolve the issue.";
87 return "You do not have permission to upload content to this hub "
88 "because you have an active VAC or Game ban.";
89 case k_EResultTimeout
:
90 return "The operation took longer than expected, so it was discarded. "
92 case k_EResultNotLoggedOn
:
93 return "You are currently not logged into Steam.";
94 case k_EResultServiceUnavailable
:
95 return "The workshop server is having issues or is unavailable, "
97 case k_EResultInvalidParam
:
98 return "One of the submission fields contains something not being "
99 "accepted by that field.";
100 case k_EResultAccessDenied
:
101 return "There was a problem trying to save the title and description. "
102 "Access was denied.";
103 case k_EResultLimitExceeded
:
104 return "You have exceeded your Steam Cloud quota. If you wish to "
105 "upload this file, you must remove some published items.";
106 case k_EResultFileNotFound
:
107 return "The uploaded file could not be found.";
108 case k_EResultDuplicateRequest
:
109 return "The file was already successfully uploaded.";
110 case k_EResultDuplicateName
:
111 return "You already have a Steam Workshop item with that name.";
112 case k_EResultServiceReadOnly
:
113 return "Due to a recent password or email change, you are not allowed "
114 "to upload new content. Usually this restriction will expire in"
115 " 5 days, but can last up to 30 days if the account has been "
116 "inactive recently.";
118 return "Operation failed for an error which has not been accounted for "
119 "by the programmer. Try again, sorry :)";
124 * op: k_workshop_form_op_publishing_update
125 * ----------------------------------------------------------------------------
129 * The endpoint of this operation
131 VG_STATIC
void on_workshop_update_result( void *data
, void *user
)
133 vg_info( "Recieved workshop update result\n" );
134 SubmitItemUpdateResult_t
*result
= data
;
136 /* this seems to be set here, but my account definitely has accepted it */
137 if( result
->m_bUserNeedsToAcceptWorkshopLegalAgreement
){
138 vg_warn( "Workshop agreement currently not accepted\n" );
141 if( result
->m_eResult
== k_EResultOK
){
142 workshop_form
.page
= k_workshop_form_closing_good
;
143 workshop_form
.failure_or_success_string
= "Uploaded workshop file!";
144 vg_success( "file uploaded\n" );
147 workshop_form
.page
= k_workshop_form_closing_bad
;
148 workshop_form
.failure_or_success_string
=
149 workshop_EResult_user_string( result
->m_eResult
);
151 vg_error( "Error with the submitted file (%d)\n", result
->m_eResult
);
158 * reciever on completion of packaging the files, it will then start the item
159 * update with Steam API
161 VG_STATIC
void workshop_form_upload_submission( PublishedFileId_t file_id
,
164 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
165 UGCUpdateHandle_t handle
166 = SteamAPI_ISteamUGC_StartItemUpdate( hSteamUGC
, SKATERIFT_APPID
,
169 /* TODO: Handle failure cases for these */
171 SteamAPI_ISteamUGC_SetItemMetadata( hSteamUGC
, handle
, metadata
);
173 if( workshop_form
.submission
.submit_title
){
174 vg_info( "Setting title\n" );
175 SteamAPI_ISteamUGC_SetItemTitle( hSteamUGC
, handle
,
176 workshop_form
.submission
.title
);
179 if( workshop_form
.submission
.submit_description
){
180 vg_info( "Setting description\n" );
181 SteamAPI_ISteamUGC_SetItemDescription( hSteamUGC
, handle
,
182 workshop_form
.submission
.description
);
185 if( workshop_form
.submission
.submit_file_and_image
){
188 vg_strnull( &folder
, path_buf
, 4096 );
189 vg_strcat( &folder
, vg
.base_path
);
191 if( workshop_form
.submission
.type
== k_addon_type_board
){
192 vg_strcat( &folder
, "boards/" );
194 else if( workshop_form
.submission
.type
== k_addon_type_world
){
195 vg_strcat( &folder
, "maps/" );
197 vg_strcat( &folder
, workshop_form
.addon_folder
);
199 vg_info( "Setting item content\n" );
200 SteamAPI_ISteamUGC_SetItemContent( hSteamUGC
, handle
, folder
.buffer
);
202 vg_str preview
= folder
;
203 vg_strcat( &preview
, "/preview.jpg" );
205 vg_info( "Setting preview image\n" );
206 SteamAPI_ISteamUGC_SetItemPreview( hSteamUGC
, handle
, preview
.buffer
);
209 vg_info( "Setting visibility\n" );
210 SteamAPI_ISteamUGC_SetItemVisibility( hSteamUGC
, handle
,
211 workshop_form
.submission
.visibility
.value
);
213 vg_info( "Submitting updates\n" );
214 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
215 call
->userdata
= NULL
;
216 call
->p_handler
= on_workshop_update_result
;
217 call
->id
= SteamAPI_ISteamUGC_SubmitItemUpdate( hSteamUGC
, handle
, "" );
221 * Steam API call result for when we've created a new item on their network, or
222 * not, if it has failed
224 VG_STATIC
void on_workshop_createitem( void *data
, void *user
)
226 CreateItemResult_t
*result
= data
;
228 if( result
->m_eResult
== k_EResultOK
){
229 vg_info( "Created workshop file with id: %lu\n",
230 result
->m_nPublishedFileId
);
232 if( result
->m_bUserNeedsToAcceptWorkshopLegalAgreement
){
233 vg_warn( "Workshop agreement currently not accepted\n" );
236 workshop_form_upload_submission( result
->m_nPublishedFileId
, user
);
239 const char *errstr
= workshop_EResult_user_string( result
->m_eResult
);
242 vg_error( "ISteamUGC_CreateItem() failed(%d): '%s' \n",
243 result
->m_eResult
, errstr
);
246 workshop_form
.page
= k_workshop_form_closing_bad
;
247 workshop_form
.failure_or_success_string
= errstr
;
253 * Starts the workshop upload process through Steam API
255 VG_STATIC
void workshop_form_async_submit_begin( void *payload
, u32 size
)
258 /* use existing file */
259 if( workshop_form
.submission
.file_id
){
260 workshop_form_upload_submission( workshop_form
.submission
.file_id
,
264 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
265 call
->userdata
= payload
;
266 call
->p_handler
= on_workshop_createitem
;
267 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
268 call
->id
= SteamAPI_ISteamUGC_CreateItem( hSteamUGC
, SKATERIFT_APPID
,
269 k_EWorkshopFileTypeCommunity
);
274 * Downloads the framebuffer into scratch memory
276 VG_STATIC
void workshop_form_async_download_image( void *payload
, u32 size
)
279 render_fb_get_current_res( gpipeline
.fb_workshop_preview
, &w
, &h
);
280 vg_linear_clear( vg_mem
.scratch
);
281 workshop_form
.img_buffer
= vg_linear_alloc( vg_mem
.scratch
, w
*h
*3 );
283 vg_info( "read framebuffer: glReadPixels( %dx%d )\n", w
,h
);
285 glBindFramebuffer( GL_READ_FRAMEBUFFER
, gpipeline
.fb_workshop_preview
->fb
);
286 glReadBuffer( GL_COLOR_ATTACHMENT0
);
287 glReadPixels( 0,0, w
,h
, GL_RGB
, GL_UNSIGNED_BYTE
, workshop_form
.img_buffer
);
289 workshop_form
.img_w
= w
;
290 workshop_form
.img_h
= h
;
294 * Thread which kicks off the upload process
296 VG_STATIC
void _workshop_form_submit_thread( void *data
)
298 vg_async_call( workshop_form_async_download_image
, NULL
, 0 );
303 vg_strnull( &folder
, path_buf
, 4096 );
305 if( workshop_form
.submission
.type
== k_addon_type_board
){
306 vg_strcat( &folder
, "boards/" );
308 else if( workshop_form
.submission
.type
== k_addon_type_world
){
309 vg_strcat( &folder
, "maps/" );
311 vg_strcat( &folder
, workshop_form
.addon_folder
);
313 if( !vg_strgood(&folder
) ){
314 vg_error( "addon folder path too long\n" );
315 vg_async_call( workshop_async_any_complete
, NULL
, 0 );
320 * Create the metadata file
321 * -----------------------------------------------------------------------*/
322 u8 descriptor_buf
[ 512 ];
323 vg_msg descriptor
= {0};
324 descriptor
.buf
= descriptor_buf
;
325 descriptor
.max
= sizeof(descriptor_buf
);
327 vg_linear_clear( vg_mem
.scratch
);
329 /* short description */
330 vg_msg_frame( &descriptor
, "workshop" );
331 vg_msg_wkvstr( &descriptor
, "title", workshop_form
.submission
.title
);
332 //vg_msg_wkvstr( &descriptor, "author", "unknown" );
333 vg_msg_wkvu32( &descriptor
, "type", workshop_form
.submission
.type
);
334 vg_msg_wkvstr( &descriptor
, "folder", workshop_form
.addon_folder
);
335 vg_msg_end_frame( &descriptor
);
336 //vg_msg_wkvstr( &descriptor, "location", "USA" );
338 char *short_descriptor_str
= vg_linear_alloc( vg_mem
.scratch
,
339 vg_align8(descriptor
.cur
*2+1));
340 vg_bin_str( descriptor_buf
, short_descriptor_str
, descriptor
.cur
);
341 short_descriptor_str
[descriptor
.cur
*2] = '\0';
342 vg_info( "binstr: %s\n", short_descriptor_str
);
345 if( !vg_dir_open( &dir
, folder
.buffer
) ){
346 vg_error( "could not open addon folder '%s'\n", folder
.buffer
);
347 vg_async_call( workshop_async_any_complete
, NULL
, 0 );
351 while( vg_dir_next_entry(&dir
) ){
352 if( vg_dir_entry_type(&dir
) == k_vg_entry_type_file
){
353 const char *d_name
= vg_dir_entry_name(&dir
);
354 if( d_name
[0] == '.' ) continue;
356 vg_str file
= folder
;
357 vg_strcat( &file
, "/" );
358 vg_strcat( &file
, d_name
);
359 if( !vg_strgood( &file
) ) continue;
361 char *ext
= vg_strch( &file
, '.' );
363 if( strcmp(ext
,".mdl") ) continue;
365 vg_msg_wkvstr( &descriptor
, "content", d_name
);
371 vg_str descriptor_file
= folder
;
372 vg_strcat( &descriptor_file
, "/addon.inf" );
373 if( !vg_strgood(&descriptor_file
) ){
374 vg_error( "Addon info path too long\n" );
375 vg_async_call( workshop_async_any_complete
, NULL
, 0 );
379 FILE *fp
= fopen( descriptor_file
.buffer
, "wb" );
381 vg_error( "Could not open addon info file '%s'\n",
382 descriptor_file
.buffer
);
383 vg_async_call( workshop_async_any_complete
, NULL
, 0 );
386 fwrite( descriptor_buf
, descriptor
.cur
, 1, fp
);
390 * -----------------------------------------------------------------------*/
391 vg_str preview
= folder
;
392 vg_strcat( &preview
, "/preview.jpg" );
394 if( !vg_strgood(&preview
) ){
395 vg_error( "preview image path too long\n" );
396 vg_async_call( workshop_async_any_complete
, NULL
, 0 );
400 int w
= workshop_form
.img_w
,
401 h
= workshop_form
.img_h
;
403 vg_info( "writing: %s (%dx%d @90%%)\n", preview
.buffer
, w
,h
);
404 stbi_flip_vertically_on_write(1);
405 stbi_write_jpg( preview
.buffer
, w
,h
, 3, workshop_form
.img_buffer
, 90 );
407 vg_async_call( workshop_form_async_submit_begin
, short_descriptor_str
, 0 );
411 * Entry point for the publishing submission operation
413 VG_STATIC
void workshop_op_submit(void)
415 /* TODO: Show these errors to the user */
416 if( workshop_form
.submission
.submit_title
){
417 if( !workshop_form
.submission
.title
[0] ){
418 vg_error( "Cannot submit because a title is required\n" );
423 if( workshop_form
.submission
.submit_description
){
424 if( !workshop_form
.submission
.description
[0] ){
425 vg_error( "Cannot submit because a description is required\n" );
430 if( workshop_form
.submission
.submit_file_and_image
){
431 if( workshop_form
.file_intent
== k_workshop_form_file_intent_none
){
432 vg_error( "Cannot submit because the file is empty or unspecified\n" );
437 skaterift_begin_op( k_workshop_form_op_publishing_update
);
439 player_board_unload( &workshop_form
.board_model
);
440 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
442 vg_loader_start( _workshop_form_submit_thread
, NULL
);
446 * op: k_workshop_form_op_loading_model
447 * -----------------------------------------------------------------------------
451 * Reciever for completion of the model file load
453 VG_STATIC
void workshop_form_loadmodel_async_complete( void *payload
, u32 size
)
455 v2_zero( workshop_form
.view_angles
);
456 v3_zero( workshop_form
.view_offset
);
457 workshop_form
.view_dist
= 1.0f
;
458 workshop_form
.view_changed
= 1;
459 workshop_form
.file_intent
= k_workshop_form_file_intent_new
;
461 vg_success( "workshop async load complete\n" );
466 * Reciever for failure to load
468 VG_STATIC
void workshop_form_loadmodel_async_error( void *payload
, u32 size
)
474 * Thread which loads the model from the disk
476 VG_STATIC
void _workshop_form_load_thread( void *data
)
480 vg_strnull( &folder
, path_buf
, 4096 );
482 if( workshop_form
.submission
.type
== k_addon_type_world
)
483 vg_strcat( &folder
, "maps/" );
484 else vg_strcat( &folder
, "boards/" );
486 vg_strcat( &folder
, workshop_form
.addon_folder
);
488 if( !vg_strgood(&folder
) ){
489 vg_error( "workshop async load failed: path too long\n" );
490 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
495 if( !vg_dir_open( &dir
, folder
.buffer
) ){
496 vg_error( "workshop async load failed: could not open folder\n" );
497 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
501 vg_info( "Searching %s for model files\n", folder
.buffer
);
504 while( vg_dir_next_entry(&dir
) ){
505 if( vg_dir_entry_type(&dir
) == k_vg_entry_type_file
){
506 const char *d_name
= vg_dir_entry_name(&dir
);
507 if( d_name
[0] == '.' ) continue;
509 vg_str file
= folder
;
510 vg_strcat( &file
, "/" );
511 vg_strcat( &file
, d_name
);
512 if( !vg_strgood( &file
) ) continue;
514 char *ext
= vg_strch( &file
, '.' );
516 if( strcmp(ext
,".mdl") ) continue;
524 vg_error( "workshop async load failed: no model files found\n" );
525 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
529 player_board_load( &workshop_form
.board_model
, path_buf
);
530 vg_async_call( workshop_form_loadmodel_async_complete
, NULL
, 0 );
534 * Entry point for load model operation
536 VG_STATIC
void workshop_op_load_model(void)
538 if( workshop_form
.submission
.type
== k_addon_type_world
){
539 vg_warn( "WORLD LOAD INFO Currently unsupported\n" );
543 workshop_form
.view_world
= world_current_instance();
545 if( mdl_arrcount( &workshop_form
.view_world
->ent_swspreview
) ){
546 workshop_form
.ptr_ent
=
547 mdl_arritm( &workshop_form
.view_world
->ent_swspreview
, 0 );
550 vg_error( "There is no ent_swspreview in the level. "
551 "Cannot publish here\n" );
555 skaterift_begin_op( k_workshop_form_op_loading_model
);
556 vg_loader_start( _workshop_form_load_thread
, NULL
);
560 * op: k_workshop_form_op_downloading_submission
561 * -----------------------------------------------------------------------------
565 * The image has been decoded and is ready to slap into the framebuffer
567 VG_STATIC
void workshop_form_async_imageload( void *data
, u32 len
)
570 struct framebuffer_attachment
*a
=
571 &gpipeline
.fb_workshop_preview
->attachments
[0];
573 glBindTexture( GL_TEXTURE_2D
, a
->id
);
574 glTexSubImage2D( GL_TEXTURE_2D
, 0,0,0,
575 WORKSHOP_PREVIEW_WIDTH
, WORKSHOP_PREVIEW_HEIGHT
,
576 a
->format
, a
->type
, data
);
577 stbi_image_free( data
);
578 vg_success( "Loaded workshop preview image\n" );
581 snprintf( workshop_form
.error_msg
, sizeof(workshop_form
.error_msg
),
582 "Preview image could not be loaded. Reason: %s\n",
583 stbi_failure_reason() );
584 ui_start_modal( workshop_form
.error_msg
, UI_MODAL_BAD
);
591 * Load the image located at ./workshop_preview.jpg into our framebuffer
593 VG_STATIC
void _workshop_load_preview_thread( void *data
)
595 char path_buf
[ 4096 ];
597 vg_strnull( &path
, path_buf
, 4096 );
598 vg_strcat( &path
, "boards/" );
599 vg_strcat( &path
, workshop_form
.addon_folder
);
600 vg_strcat( &path
, "/preview.jpg" );
602 if( vg_strgood( &path
) ){
603 stbi_set_flip_vertically_on_load(1);
605 u8
*rgb
= stbi_load( path
.buffer
, &x
, &y
, &nc
, 3 );
608 if( (x
== WORKSHOP_PREVIEW_WIDTH
) && (y
== WORKSHOP_PREVIEW_HEIGHT
) ){
609 vg_async_call( workshop_form_async_imageload
, rgb
, x
*y
*3 );
612 vg_error( "Resolution does not match framebuffer, so we can't"
614 stbi_image_free( rgb
);
615 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
619 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
623 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
629 * Reciever for the preview download result
631 VG_STATIC
void on_workshop_download_ugcpreview( void *data
, void *user
)
633 struct workshop_loadpreview_info
*info
= user
;
634 RemoteStorageDownloadUGCResult_t
*result
= data
;
636 if( result
->m_eResult
== k_EResultOK
){
637 ISteamRemoteStorage
*hSteamRemoteStorage
= SteamAPI_SteamRemoteStorage();
638 vg_loader_start( _workshop_load_preview_thread
, info
);
641 vg_error( "Error while donwloading UGC preview( %d )\n",
649 * Entry point to view operation
651 VG_STATIC
void workshop_op_download_and_view_submission( int result_index
)
653 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
654 ISteamRemoteStorage
*hSteamRemoteStorage
= SteamAPI_SteamRemoteStorage();
655 SteamUGCDetails_t details
;
656 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC
,
657 workshop_form
.ugc_query
.handle
,
661 skaterift_begin_op( k_workshop_form_op_downloading_submission
);
662 workshop_reset_submission_data();
663 workshop_form
.submission
.submit_description
= 0;
664 workshop_form
.submission
.submit_file_and_image
= 0;
665 workshop_form
.submission
.submit_title
= 0;
667 u8 metadata_buf
[512];
668 char metadata_str
[1024+1];
669 int have_meta
= SteamAPI_ISteamUGC_GetQueryUGCMetadata( hSteamUGC
,
670 workshop_form
.ugc_query
.handle
,
671 result_index
, metadata_str
,
674 vg_strncpy( details
.m_rgchDescription
,
675 workshop_form
.submission
.description
,
676 vg_list_size( workshop_form
.submission
.description
),
677 k_strncpy_always_add_null
);
679 vg_strncpy( details
.m_rgchTitle
,
680 workshop_form
.submission
.title
,
681 vg_list_size( workshop_form
.submission
.title
),
682 k_strncpy_always_add_null
);
684 snprintf( workshop_form
.addon_folder
,
685 vg_list_size( workshop_form
.addon_folder
),
686 "Steam Cloud ("PRINTF_U64
")", details
.m_nPublishedFileId
);
688 workshop_form
.submission
.file_id
= details
.m_nPublishedFileId
;
689 workshop_form
.file_intent
= k_workshop_form_file_intent_keep_old
;
690 workshop_form
.page
= k_workshop_form_edit
;
691 workshop_form
.submission
.visibility
.value
= details
.m_eVisibility
;
692 workshop_form
.submission
.type
= k_addon_type_none
;
693 workshop_form
.submission
.submission_type_selection
.index
= 0;
694 workshop_form
.submission
.submission_type_selection
.value
=
698 u32 len
= strlen(metadata_str
);
699 vg_info( "Metadata: %s\n", metadata_str
);
700 vg_str_bin( metadata_str
, metadata_buf
, len
);
702 root
.buf
= metadata_buf
;
706 vg_msg workshop
= root
;
707 if( vg_msg_seekframe( &workshop
, "workshop", k_vg_msg_first
)){
708 u32 type
= vg_msg_seekkvu32( &workshop
, "type", k_vg_msg_first
);
709 workshop_form
.submission
.type
= type
;
710 workshop_form
.submission
.submission_type_selection
.value
= type
;
712 const char *kv_folder
= vg_msg_seekkvstr( &workshop
, "folder",
715 vg_strncpy( kv_folder
, workshop_form
.addon_folder
,
716 sizeof(workshop_form
.addon_folder
),
717 k_strncpy_always_add_null
);
722 vg_error( "No metadata was returned with this item.\n" );
726 for( i32 i
=0; i
<vg_list_size(workshop_form_visibility_opts
); i
++ ){
727 if( workshop_form_visibility_opts
[i
].value
== details
.m_eVisibility
){
728 workshop_form
.submission
.visibility
.index
= i
;
732 for( i32 i
=0; i
<vg_list_size(workshop_form_type_opts
); i
++ ){
733 if( workshop_form_type_opts
[i
].value
==
734 workshop_form
.submission
.submission_type_selection
.value
){
735 workshop_form
.submission
.submission_type_selection
.index
= i
;
740 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
741 glClearColor( 0.2f
, 0.0f
, 0.0f
, 1.0f
);
742 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
743 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
744 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
746 vg_loader_start( _workshop_load_preview_thread
, NULL
);
749 if( details
.m_hPreviewFile
== 0 ){
750 vg_error( "m_hPreviewFile is 0\n" );
754 /* Now need to begin downloading the image so we can display it */
755 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
757 struct workshop_loadpreview_info
*info
=
758 vg_linear_alloc( vg_mem
.scratch
,
759 sizeof( struct workshop_loadpreview_info
) );
761 snprintf( info
->abs_preview_image
, 1024,
762 "%smodels/boards/workshop/" PRINTF_U64
".jpg",
763 vg
.base_path
, details
.m_hPreviewFile
);
765 call
->p_handler
= on_workshop_download_ugcpreview
;
766 call
->userdata
= info
;
767 call
->id
= SteamAPI_ISteamRemoteStorage_UGCDownloadToLocation(
769 details
.m_hPreviewFile
, info
->abs_preview_image
, 1 );
771 vg_info( "preview file id: " PRINTF_U64
"\n",
772 details
.m_hPreviewFile
);
777 vg_error( "GetQueryUGCResult: Index out of range\n" );
784 * -----------------------------------------------------------------------------
788 * View a page of results on the sidebar
790 VG_STATIC
void workshop_view_page( int req
)
792 if( workshop_form
.ugc_query
.result
!= k_EResultOK
){
793 vg_error( "Tried to change page without complete data\n" );
797 int page
= VG_MAX(VG_MIN(req
, workshop_form
.view_published_page_count
-1),0),
798 start
= page
* WORKSHOP_VIEW_PER_PAGE
,
799 end
= VG_MIN( (page
+1) * WORKSHOP_VIEW_PER_PAGE
,
800 workshop_form
.ugc_query
.returned_item_count
),
803 vg_info( "View page %d\n", page
);
805 workshop_form
.view_published_page_id
= page
;
806 workshop_form
.published_files_list_length
= count
;
807 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
809 for( int i
=0; i
<count
; i
++ ){
810 struct published_file
*pfile
= &workshop_form
.published_files_list
[i
];
812 SteamUGCDetails_t details
;
813 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC
,
814 workshop_form
.ugc_query
.handle
,
818 if( details
.m_eResult
!= k_EResultOK
){
819 snprintf( pfile
->title
, 80, "Error (%d)", details
.m_eResult
);
822 vg_strncpy( details
.m_rgchTitle
, pfile
->title
, 80,
823 k_strncpy_always_add_null
);
826 pfile
->result
= details
.m_eResult
;
827 pfile
->result_index
= start
+i
;
830 pfile
->result
= k_EResultValueOutOfRange
;
831 pfile
->result_index
= -1;
832 snprintf( pfile
->title
, 80, "Error (invalid index)" );
838 * Steam API result for when we recieve submitted UGC information about the user
840 VG_STATIC
void on_workshop_UGCQueryComplete( void *data
, void *userdata
)
842 SteamUGCQueryCompleted_t
*query
= data
;
843 workshop_form
.ugc_query
.result
= query
->m_eResult
;
845 if( query
->m_eResult
== k_EResultOK
){
846 if( query
->m_unTotalMatchingResults
> 50 ){
847 vg_warn( "You have %d items submitted, "
848 "we can only view the last 50\n" );
851 workshop_form
.ugc_query
.all_item_count
= query
->m_unTotalMatchingResults
;
852 workshop_form
.ugc_query
.returned_item_count
=
853 query
->m_unNumResultsReturned
;
855 workshop_form
.ugc_query
.handle
= query
->m_handle
;
856 workshop_form
.view_published_page_count
=
857 (query
->m_unNumResultsReturned
+WORKSHOP_VIEW_PER_PAGE
-1)/
858 WORKSHOP_VIEW_PER_PAGE
;
859 workshop_form
.view_published_page_id
= 0;
860 workshop_form
.published_files_list_length
= 0;
862 workshop_view_page( 0 );
865 vg_error( "Steam UGCQuery failed (%d)\n", query
->m_eResult
);
866 workshop_form
.view_published_page_count
= 0;
867 workshop_form
.view_published_page_id
= 0;
868 workshop_form
.published_files_list_length
= 0;
870 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
871 SteamAPI_ISteamUGC_ReleaseQueryUGCRequest( hSteamUGC
, query
->m_handle
);
876 * Console command to open the workshop publisher
878 VG_STATIC
int workshop_submit_command( int argc
, const char *argv
[] )
881 ui_start_modal( "Steam API is not initialized\n", UI_MODAL_BAD
);
885 workshop_form
.page
= k_workshop_form_open
;
886 workshop_form
.view_published_page_count
= 0;
887 workshop_form
.view_published_page_id
= 0;
888 workshop_form
.published_files_list_length
= 0;
889 workshop_form
.ugc_query
.result
= k_EResultNone
;
891 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
893 ISteamUser
*hSteamUser
= SteamAPI_SteamUser();
895 steamid
.m_unAll64Bits
= SteamAPI_ISteamUser_GetSteamID( hSteamUser
);
897 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
898 call
->p_handler
= on_workshop_UGCQueryComplete
;
899 call
->userdata
= NULL
;
900 UGCQueryHandle_t handle
= SteamAPI_ISteamUGC_CreateQueryUserUGCRequest
903 steamid
.m_comp
.m_unAccountID
,
904 k_EUserUGCList_Published
,
905 k_EUGCMatchingUGCType_Items
,
906 k_EUserUGCListSortOrder_CreationOrderDesc
,
907 SKATERIFT_APPID
, SKATERIFT_APPID
,
909 SteamAPI_ISteamUGC_SetReturnMetadata( hSteamUGC
, handle
, 1 );
910 call
->id
= SteamAPI_ISteamUGC_SendQueryUGCRequest( hSteamUGC
, handle
);
914 VG_STATIC
void workshop_init(void)
916 vg_console_reg_cmd( "workshop_submit", workshop_submit_command
, NULL
);
919 VG_STATIC
void workshop_render_world_preview(void){
920 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
922 glClearColor( 0.0f
, 0.0f
, 0.3f
, 1.0f
);
923 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
924 glEnable( GL_DEPTH_TEST
);
925 glDisable( GL_BLEND
);
927 render_world( localplayer
.viewable_world
, &main_camera
, 1 );
929 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
930 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
934 * Redraw the model file into the workshop framebuffer
936 VG_STATIC
void workshop_render_board_preview(void){
937 if( !workshop_form
.ptr_ent
){
941 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
943 glClearColor( 0.0f
, 0.0f
, 0.3f
, 1.0f
);
944 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
945 glEnable( GL_DEPTH_TEST
);
946 glDisable( GL_BLEND
);
948 ent_swspreview
*swsprev
= workshop_form
.ptr_ent
;
949 world_instance
*world
= workshop_form
.view_world
;
951 ent_camera
*ref
= mdl_arritm( &world
->ent_camera
,
952 mdl_entity_id_id(swsprev
->id_camera
) );
953 ent_marker
*display
= mdl_arritm( &world
->ent_marker
,
954 mdl_entity_id_id(swsprev
->id_display
) ),
955 *display1
= mdl_arritm( &world
->ent_marker
,
956 mdl_entity_id_id(swsprev
->id_display1
) );
959 v3_add( display
->transform
.co
, display1
->transform
.co
, baseco
);
960 v3_muls( baseco
, 0.5f
, baseco
);
964 v3_sub( display
->transform
.co
, ref
->transform
.co
, basevector
);
965 float dist
= v3_length( basevector
);
968 player_vector_angles( baseangles
, basevector
, 1.0f
, 0.0f
);
970 v2_add( workshop_form
.view_angles
, baseangles
, cam
.angles
);
971 cam
.angles
[2] = 0.0f
;
973 float sX
= sinf( cam
.angles
[0] ),
974 cX
= cosf( cam
.angles
[0] ),
975 sY
= sinf( cam
.angles
[1] ),
976 cY
= cosf( cam
.angles
[1] );
978 v3f offset
= { -sX
* cY
, sY
, cX
* cY
};
980 v3_muladds( display
->transform
.co
, offset
,
981 dist
*workshop_form
.view_dist
, cam
.pos
);
983 cam
.pos
[0] += -sX
*workshop_form
.view_offset
[2];
984 cam
.pos
[2] += cX
*workshop_form
.view_offset
[2];
985 cam
.pos
[0] += cX
*workshop_form
.view_offset
[0];
986 cam
.pos
[2] += sX
*workshop_form
.view_offset
[0];
987 cam
.pos
[1] += workshop_form
.view_offset
[1];
993 camera_update_transform( &cam
);
994 camera_update_view( &cam
);
995 camera_update_projection( &cam
);
996 camera_finalize( &cam
);
999 mdl_transform_m4x3( &display
->transform
, mmdl
);
1000 mdl_transform_m4x3( &display1
->transform
, mmdl1
);
1002 /* force update this for nice shadows. its usually set in the world
1003 * pre-render step, but that includes timer stuff
1005 struct player_board
*board
= &workshop_form
.board_model
;
1006 struct ub_world_lighting
*ubo
= &world
->ub_lighting
;
1008 v3_copy((v3f
){0.0f
,0.1f
, board
->truck_positions
[0][2]}, vp0
);
1009 v3_copy((v3f
){0.0f
,0.1f
, board
->truck_positions
[1][2]}, vp1
);
1010 m4x3_mulv( mmdl1
, vp0
, ubo
->g_board_0
);
1011 m4x3_mulv( mmdl1
, vp1
, ubo
->g_board_1
);
1012 glBindBuffer( GL_UNIFORM_BUFFER
, world
->ubo_lighting
);
1013 glBufferSubData( GL_UNIFORM_BUFFER
, 0,
1014 sizeof(struct ub_world_lighting
), &world
->ub_lighting
);
1016 render_world( world
, &cam
, 1 );
1017 render_board( &cam
, world
, board
, mmdl
, k_board_shader_entity
);
1018 render_board( &cam
, world
, board
, mmdl1
, k_board_shader_entity
);
1020 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
1021 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
1025 * ImGUI section for workshop form
1026 * -----------------------------------------------------------------------------
1029 VG_STATIC
void workshop_changed_model_path( char *buf
, u32 len
){
1030 workshop_form
.submission
.submit_file_and_image
= 1;
1033 VG_STATIC
void workshop_changed_title( char *buf
, u32 len
){
1034 workshop_form
.submission
.submit_title
= 1;
1037 VG_STATIC
void workshop_changed_description( char *buf
, u32 len
){
1038 workshop_form
.submission
.submit_description
= 1;
1041 VG_STATIC
void workshop_form_gui_page_undecided( ui_rect content
){
1043 rect_copy( content
, box
);
1045 box
[2] = (box
[2]*2)/3;
1046 ui_rect_center( content
, box
);
1049 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1050 ui_text( row
, "Select the type of item\n", 1, k_ui_align_middle_center
,0);
1051 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1052 ui_enum( row
, "Type:", workshop_form_type_opts
,
1053 3, &workshop_form
.submission
.submission_type_selection
);
1054 ui_split( box
, k_ui_axis_h
, 8, 0, row
, box
);
1055 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1057 ui_rect button_l
, button_r
;
1058 rect_copy( row
, button_l
);
1059 button_l
[2] = 128*2;
1060 ui_rect_center( row
, button_l
);
1061 ui_split_ratio( button_l
, k_ui_axis_v
, 0.5f
, 2, button_l
, button_r
);
1063 if( workshop_form
.submission
.submission_type_selection
.value
!=
1064 k_addon_type_none
){
1065 if( ui_button_text( button_l
, "OK", 1 ) ){
1066 enum addon_type type
=
1067 workshop_form
.submission
.submission_type_selection
.value
;
1068 workshop_form
.submission
.type
= type
;
1070 if( type
== k_addon_type_world
){
1071 workshop_form
.view_changed
= 1;
1072 workshop_form
.file_intent
= k_workshop_form_file_intent_new
;
1077 ui_fill( button_l
, ui_colour(k_ui_bg
) );
1078 ui_text( button_l
, "OK", 1, k_ui_align_middle_center
,
1079 ui_colour(k_ui_bg
+4) );
1082 if( ui_button_text( button_r
, "Cancel", 1 ) ){
1083 workshop_form
.page
= k_workshop_form_open
;
1084 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1088 VG_STATIC
void workshop_form_gui_draw_preview( ui_rect img_box
){
1089 enum addon_type type
= workshop_form
.submission
.type
;
1090 if( workshop_form
.file_intent
== k_workshop_form_file_intent_keep_old
){
1091 ui_image( img_box
, gpipeline
.fb_workshop_preview
->attachments
[0].id
);
1093 else if( workshop_form
.file_intent
== k_workshop_form_file_intent_new
){
1094 ui_image( img_box
, gpipeline
.fb_workshop_preview
->attachments
[0].id
);
1096 if( type
== k_addon_type_world
){
1100 int hover
= ui_inside_rect( img_box
, vg_ui
.mouse
),
1101 target
= ui_inside_rect( img_box
, vg_ui
.mouse_click
);
1103 if( ui_click_down(UI_MOUSE_MIDDLE
) && target
){
1104 v3_copy( workshop_form
.view_offset
,
1105 workshop_form
.view_offset_begin
);
1107 else if( ui_click_down(UI_MOUSE_LEFT
) && target
){
1108 v2_copy( workshop_form
.view_angles
,
1109 workshop_form
.view_angles_begin
);
1112 if( ui_clicking(UI_MOUSE_MIDDLE
) && target
){
1113 v2f delta
= { vg_ui
.mouse
[0]-vg_ui
.mouse_click
[0],
1114 vg_ui
.mouse
[1]-vg_ui
.mouse_click
[1] };
1116 float *begin
= workshop_form
.view_offset_begin
,
1117 *offset
= workshop_form
.view_offset
;
1118 offset
[0] = vg_clampf( begin
[0]-delta
[0]*0.002f
, -1.0f
, 1.0f
);
1119 offset
[2] = vg_clampf( begin
[2]-delta
[1]*0.002f
, -1.0f
, 1.0f
);
1120 workshop_form
.view_changed
= 1;
1122 else if( ui_clicking(UI_MOUSE_LEFT
) && target
){
1123 v2f delta
= { vg_ui
.mouse
[0]-vg_ui
.mouse_click
[0],
1124 vg_ui
.mouse
[1]-vg_ui
.mouse_click
[1] };
1127 v2_muladds( workshop_form
.view_angles_begin
, delta
, 0.002f
, angles
);
1129 float limit
= VG_PIf
*0.2f
;
1131 angles
[0] = vg_clampf( angles
[0], -limit
, limit
);
1132 angles
[1] = vg_clampf( angles
[1], -limit
, limit
);
1134 v2_copy( angles
, workshop_form
.view_angles
);
1135 workshop_form
.view_changed
= 1;
1138 if( !ui_clicking(UI_MOUSE_LEFT
) && hover
){
1139 float zoom
= workshop_form
.view_dist
;
1140 zoom
+= vg
.mouse_wheel
[1] * -0.07f
;
1141 zoom
= vg_clampf( zoom
, 0.4f
, 2.0f
);
1143 if( zoom
!= workshop_form
.view_dist
){
1144 workshop_form
.view_changed
= 1;
1145 workshop_form
.view_dist
= zoom
;
1150 ui_text( img_box
, "No image", 1, k_ui_align_middle_center
,
1151 ui_colour( k_ui_orange
) );
1155 VG_STATIC
void workshop_form_gui_edit_page( ui_rect content
){
1156 enum addon_type type
= workshop_form
.submission
.type
;
1158 if( type
== k_addon_type_none
){
1159 workshop_form_gui_page_undecided( content
);
1163 ui_rect image_plane
;
1164 ui_split( content
, k_ui_axis_h
, 300, 0, image_plane
, content
);
1165 ui_fill( image_plane
, ui_colour( k_ui_bg
+0 ) );
1168 ui_fit_item( image_plane
, (ui_px
[2]){ 3, 2 }, img_box
);
1169 workshop_form_gui_draw_preview( img_box
);
1172 ui_rect null
, file_entry
, file_button
, file_label
;
1173 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1174 ui_split( content
, k_ui_axis_h
, 28, 0, file_entry
, content
);
1176 if( workshop_form
.submission
.type
== k_addon_type_board
){
1177 ui_label( file_entry
, "Addon folder: skaterift/boards/",
1181 ui_label( file_entry
, "Addon folder: skaterift/maps/",
1185 if( type
== k_addon_type_world
){
1186 struct ui_textbox_callbacks callbacks
= {
1187 .change
= workshop_changed_model_path
1189 ui_textbox( file_entry
, workshop_form
.addon_folder
,
1190 vg_list_size(workshop_form
.addon_folder
), 0, &callbacks
);
1193 ui_split( file_entry
, k_ui_axis_v
, -128, 0, file_entry
, file_button
);
1194 if( workshop_form
.file_intent
!= k_workshop_form_file_intent_none
){
1195 ui_text( file_entry
, workshop_form
.addon_folder
, 1,
1196 k_ui_align_middle_left
, ui_colour( k_ui_fg
+4 ) );
1198 if( ui_button_text( file_button
, "Remove", 1 ) ){
1199 player_board_unload( &workshop_form
.board_model
);
1200 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1201 workshop_form
.addon_folder
[0] = '\0';
1205 struct ui_textbox_callbacks callbacks
= {
1206 .change
= workshop_changed_model_path
1209 ui_textbox( file_entry
, workshop_form
.addon_folder
,
1210 vg_list_size(workshop_form
.addon_folder
), 0, &callbacks
);
1212 if( ui_button_text( file_button
, "Load", 1 ) ){
1213 workshop_op_load_model();
1218 ui_rect title_entry
, label
;
1219 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1220 ui_split( content
, k_ui_axis_h
, 28, 0, title_entry
, content
);
1222 const char *str_title
= "Title:", *str_desc
= "Description:";
1223 ui_split( title_entry
, k_ui_axis_v
,
1224 ui_text_line_width(str_title
)+8, 0, label
, title_entry
);
1226 ui_rect vis_dropdown
;
1227 ui_split_ratio( title_entry
, k_ui_axis_v
, 0.6f
, 16,
1228 title_entry
, vis_dropdown
);
1232 struct ui_textbox_callbacks callbacks
= {
1233 .change
= workshop_changed_title
1235 ui_text( label
, str_title
, 1, k_ui_align_middle_left
, 0 );
1236 ui_textbox( title_entry
, workshop_form
.submission
.title
,
1237 vg_list_size(workshop_form
.submission
.title
), 0, &callbacks
);
1240 /* visibility option */
1242 ui_enum( vis_dropdown
, "Visibility:", workshop_form_visibility_opts
,
1243 4, &workshop_form
.submission
.visibility
);
1246 /* description box */
1248 struct ui_textbox_callbacks callbacks
= {
1249 .change
= workshop_changed_description
1252 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1253 ui_split( content
, k_ui_axis_h
, 28, 0, label
, content
);
1254 ui_split( content
, k_ui_axis_h
, 28*4, 0, desc_entry
, content
);
1255 ui_text( label
, str_desc
, 1, k_ui_align_middle_left
, 0 );
1256 ui_textbox( desc_entry
, workshop_form
.submission
.description
,
1257 vg_list_size(workshop_form
.submission
.description
),
1258 UI_TEXTBOX_MULTILINE
|UI_TEXTBOX_WRAP
, &callbacks
);
1261 /* submissionable */
1262 ui_rect submission_row
;
1263 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1264 ui_split( content
, k_ui_axis_h
, content
[3]-32-8, 0, content
,
1267 ui_rect submission_center
;
1268 rect_copy( submission_row
, submission_center
);
1269 submission_center
[2] = 256;
1270 ui_rect_center( submission_row
, submission_center
);
1272 ui_rect btn_left
, btn_right
;
1273 ui_split_ratio( submission_center
, k_ui_axis_v
, 0.5f
, 8,
1274 btn_left
, btn_right
);
1276 if( ui_button_text( btn_left
, "Publish", 1 ) ){
1277 workshop_op_submit();
1279 if( ui_button_text( btn_right
, "Cancel", 1 ) ){
1280 workshop_form
.page
= k_workshop_form_open
;
1281 player_board_unload( &workshop_form
.board_model
);
1282 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1286 const char *disclaimer_text
=
1287 "By submitting this item, you agree to the workshop terms of service";
1289 ui_rect disclaimer_row
, inner
, link
;
1290 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1291 ui_split( content
, k_ui_axis_h
, content
[3]-32, 0, content
,
1294 ui_px btn_width
= 32;
1296 rect_copy( disclaimer_row
, inner
);
1297 inner
[2] = ui_text_line_width( disclaimer_text
) + btn_width
+8;
1299 ui_rect_center( disclaimer_row
, inner
);
1300 ui_split( inner
, k_ui_axis_v
, inner
[2]-btn_width
, 0, label
, btn_right
);
1301 ui_rect_pad( btn_right
, (ui_px
[2]){2,2} );
1303 if( ui_button_text( btn_right
, "\x91", 2 ) ){
1304 ISteamFriends
*hSteamFriends
= SteamAPI_SteamFriends();
1305 SteamAPI_ISteamFriends_ActivateGameOverlayToWebPage( hSteamFriends
,
1306 "https://steamcommunity.com/sharedfiles/workshoplegalagreement",
1307 k_EActivateGameOverlayToWebPageMode_Default
);
1310 ui_text( label
, disclaimer_text
, 1, k_ui_align_middle_left
,
1311 ui_colour( k_ui_fg
+4 ) );
1314 VG_STATIC
void workshop_form_gui_sidebar( ui_rect sidebar
)
1316 ui_fill( sidebar
, ui_colour( k_ui_bg
+2 ) );
1319 ui_split( sidebar
, k_ui_axis_h
, 28, 0, title
, sidebar
);
1321 if( workshop_form
.page
== k_workshop_form_edit
){
1322 ui_text( title
, "Editing", 1, k_ui_align_middle_center
, 0 );
1323 ui_split( sidebar
, k_ui_axis_h
, 28, 0, title
, sidebar
);
1325 if( workshop_form
.submission
.type
!= k_addon_type_none
){
1328 vg_strnull( &str
, buf
, 512 );
1330 if( workshop_form
.submission
.file_id
)
1331 vg_strcat( &str
, "Editing an existing " );
1333 vg_strcat( &str
, "Creating a new " );
1335 if( workshop_form
.submission
.type
== k_addon_type_board
)
1336 vg_strcat( &str
, "skateboard." );
1337 else if( workshop_form
.submission
.type
== k_addon_type_world
)
1338 vg_strcat( &str
, "world." );
1340 vg_strcat( &str
, "???." );
1342 ui_text( title
, buf
, 1, k_ui_align_middle_center
,
1343 ui_colour(k_ui_fg
+4) );
1349 * sidebar existing entries panel
1351 ui_text( title
, "Your submissions", 1, k_ui_align_middle_center
, 0 );
1353 ui_rect controls
, btn_create_new
;
1354 ui_split( sidebar
, k_ui_axis_h
, 32, 0, controls
, sidebar
);
1355 ui_split( sidebar
, k_ui_axis_h
, -32, 0, sidebar
, btn_create_new
);
1356 ui_fill( controls
, ui_colour( k_ui_bg
+1 ) );
1359 strcpy( buf
, "page " );
1361 i
+= highscore_intl( buf
+i
, workshop_form
.view_published_page_id
+1, 4 );
1363 i
+= highscore_intl( buf
+i
, workshop_form
.view_published_page_count
, 4 );
1366 ui_rect_pad( controls
, (ui_px
[2]){0,4} );
1368 ui_split_ratio( controls
, k_ui_axis_v
, 0.25f
, 0, info
, controls
);
1369 ui_text( info
, buf
, 1, k_ui_align_middle_center
, 0 );
1371 ui_rect btn_left
, btn_right
;
1372 ui_split_ratio( controls
, k_ui_axis_v
, 0.5f
, 2, btn_left
, btn_right
);
1374 if( ui_button_text( btn_left
, "newer", 1 ) ){
1375 workshop_view_page( workshop_form
.view_published_page_id
-1 );
1378 if( ui_button_text( btn_right
, "older", 1 ) ){
1379 workshop_view_page( workshop_form
.view_published_page_count
+1 );
1382 if( ui_button_text( btn_create_new
, "Create New Item", 1 ) ){
1383 workshop_reset_submission_data();
1384 workshop_form
.submission
.submit_title
= 1;
1385 workshop_form
.submission
.submit_description
= 1;
1386 workshop_form
.submission
.submit_file_and_image
= 1;
1387 workshop_form
.page
= k_workshop_form_edit
;
1390 for( int i
=0; i
<workshop_form
.published_files_list_length
; i
++ ){
1392 ui_split( sidebar
, k_ui_axis_h
, 28, 0, item
, sidebar
);
1393 ui_rect_pad( item
, (ui_px
[2]){4,4} );
1395 struct published_file
*pfile
= &workshop_form
.published_files_list
[i
];
1396 if( ui_button_text( item
, pfile
->title
, 1 ) ){
1397 if( pfile
->result
== k_EResultOK
){
1398 vg_info( "Select index: %d\n", pfile
->result_index
);
1399 workshop_op_download_and_view_submission( pfile
->result_index
);
1402 vg_warn( "Cannot select that item, result not OK\n" );
1408 VG_STATIC
void workshop_form_gui(void)
1410 enum workshop_form_page stable_page
= workshop_form
.page
;
1411 if( stable_page
== k_workshop_form_hidden
) return;
1414 ui_rect screen
= { 0, 0, vg
.window_x
, vg
.window_y
};
1415 ui_rect window
= { 0, 0, 1000, 700 };
1416 ui_rect_center( screen
, window
);
1417 vg_ui
.wants_mouse
= 1;
1419 ui_fill( window
, ui_colour( k_ui_bg
+1 ) );
1420 ui_outline( window
, 1, ui_colour( k_ui_bg
+7 ) );
1422 ui_rect title
, panel
;
1423 ui_split( window
, k_ui_axis_h
, 28, 0, title
, panel
);
1424 ui_fill( title
, ui_colour( k_ui_bg
+7 ) );
1425 ui_text( title
, "Workshop tool", 1, k_ui_align_middle_center
,
1426 ui_colourcont(k_ui_bg
+7) );
1428 ui_rect quit_button
;
1429 ui_split( title
, k_ui_axis_v
, title
[2]-title
[3], 2, title
, quit_button
);
1431 if( skaterift
.async_op
== k_async_op_none
){
1432 if( ui_button_text( quit_button
, "X", 1 ) ){
1433 workshop_quit_form();
1439 * temporary operation blinders, we don't yet have a nice way to show the
1440 * user that we're doing something uninterruptable, so the code just
1441 * escapes here and we show them a basic string
1444 if( skaterift
.async_op
!= k_async_op_none
){
1445 const char *op_string
= "The programmer has not bothered to describe "
1446 "the current operation that is running.";
1448 switch( skaterift
.async_op
){
1449 case k_workshop_form_op_loading_model
:
1450 op_string
= "Operation in progress: Loading model file.";
1452 case k_workshop_form_op_publishing_update
:
1453 op_string
= "Operation in progress: publishing submission update "
1456 case k_workshop_form_op_downloading_submission
:
1457 op_string
= "Operation in progress: downloading existing submission"
1458 " from Steam services.";
1463 ui_text( panel
, op_string
, 1, k_ui_align_middle_center
, 0 );
1467 /* re draw board preview if need to */
1468 if( (stable_page
== k_workshop_form_edit
) &&
1469 workshop_form
.view_changed
&&
1470 workshop_form
.file_intent
== k_workshop_form_file_intent_new
)
1472 enum addon_type type
= workshop_form
.submission
.type
;
1473 if( type
== k_addon_type_board
){
1474 workshop_render_board_preview();
1476 else if( type
== k_addon_type_world
){
1477 vg_success( "Renders world preview\n" );
1478 workshop_render_world_preview();
1480 workshop_form
.view_changed
= 0;
1483 struct workshop_form
*form
= &workshop_form
;
1485 ui_rect sidebar
, content
;
1486 ui_split_ratio( panel
, k_ui_axis_v
, 0.3f
, 1, sidebar
, content
);
1489 ui_rect_pad( content
, (ui_px
[2]){8,8} );
1491 if( stable_page
== k_workshop_form_edit
){
1492 workshop_form_gui_edit_page( content
);
1494 else if( stable_page
== k_workshop_form_open
){
1495 ui_text( content
, "Nothing selected.", 1, k_ui_align_middle_center
,
1496 ui_colour( k_ui_fg
+4 ) );
1498 else if( stable_page
>= k_workshop_form_cclosing
){
1499 ui_rect submission_row
;
1500 ui_split( content
, k_ui_axis_h
, content
[3]-32-8, 0, content
,
1505 if( stable_page
== k_workshop_form_closing_bad
)
1506 colour
= ui_colour( k_ui_red
+k_ui_brighter
);
1508 colour
= ui_colour( k_ui_green
+k_ui_brighter
);
1510 ui_text( content
, workshop_form
.failure_or_success_string
, 1,
1511 k_ui_align_middle_center
, colour
);
1513 ui_rect submission_center
;
1514 rect_copy( submission_row
, submission_center
);
1515 submission_center
[2] = 128;
1516 ui_rect_center( submission_row
, submission_center
);
1517 ui_rect_pad( submission_center
, (ui_px
[2]){8,8} );
1519 if( ui_button_text( submission_center
, "OK", 1 ) ){
1520 workshop_form
.page
= k_workshop_form_open
;
1524 workshop_form_gui_sidebar( sidebar
);
1528 * Some async api stuff
1529 * -----------------------------------------------------------------------------
1532 VG_STATIC
void async_workshop_get_filepath( void *data
, u32 len
)
1534 struct async_workshop_filepath_info
*info
= data
;
1539 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
1540 if( !SteamAPI_ISteamUGC_GetItemInstallInfo( hSteamUGC
, info
->id
, &_size
,
1541 info
->buf
, info
->len
, &_ts
))
1543 vg_error( "GetItemInstallInfo failed\n" );
1544 info
->buf
[0] = '\0';
1548 VG_STATIC
void async_workshop_get_installed_files( void *data
, u32 len
)
1550 struct async_workshop_installed_files_info
*info
= data
;
1552 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
1553 u32 count
= SteamAPI_ISteamUGC_GetSubscribedItems( hSteamUGC
, info
->buffer
,
1556 vg_info( "Found %u subscribed items\n", count
);
1559 for( u32 i
=0; i
<count
; i
++ ){
1560 u32 state
= SteamAPI_ISteamUGC_GetItemState( hSteamUGC
, info
->buffer
[i
] );
1561 if( state
& k_EItemStateInstalled
){
1562 info
->buffer
[j
++] = info
->buffer
[i
];
1569 #endif /* WORKSHOP_C */