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
);
431 DIR *dir
= opendir( 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 struct dirent
*entry
;
439 while( (entry
= readdir(dir
)) ){
440 if( entry
->d_type
== DT_REG
){
441 if( entry
->d_name
[0] == '.' ) continue;
443 vg_str file
= folder
;
444 vg_strcat( &file
, "/" );
445 vg_strcat( &file
, entry
->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", entry
->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 );
581 DIR *dir
= opendir( 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 struct dirent
*entry
;
592 while( (entry
= readdir(dir
)) ){
593 if( entry
->d_type
== DT_REG
){
594 if( entry
->d_name
[0] == '.' ) continue;
596 vg_str file
= folder
;
597 vg_strcat( &file
, "/" );
598 vg_strcat( &file
, entry
->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" );
659 struct workshop_loadpreview_info
{
660 char abs_preview_image
[ 1024 ];
664 * Load the image located at ./workshop_preview.jpg into our framebuffer
666 VG_STATIC
void _workshop_load_preview_thread( void *data
)
668 struct workshop_loadpreview_info
*info
= data
;
670 stbi_set_flip_vertically_on_load(1);
672 u8
*rgb
= stbi_load( info
->abs_preview_image
, &x
, &y
, &nc
, 3 );
675 if( (x
== WORKSHOP_PREVIEW_WIDTH
) && (y
== WORKSHOP_PREVIEW_HEIGHT
) ){
676 vg_async_call( workshop_form_async_imageload
, rgb
, x
*y
*3 );
679 vg_error( "Resolution does not match framebuffer, so we can't"
681 stbi_image_free( rgb
);
682 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
686 vg_error( "Failed to load workshop_preview.jpg: '%s'\n",
687 stbi_failure_reason() );
688 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
693 * Reciever for the preview download result
695 VG_STATIC
void on_workshop_download_ugcpreview( void *data
, void *user
)
697 struct workshop_loadpreview_info
*info
= user
;
698 RemoteStorageDownloadUGCResult_t
*result
= data
;
700 if( result
->m_eResult
== k_EResultOK
){
701 ISteamRemoteStorage
*hSteamRemoteStorage
= SteamAPI_SteamRemoteStorage();
702 vg_loader_start( _workshop_load_preview_thread
, info
);
705 vg_error( "Error while donwloading UGC preview( %d )\n",
712 * Entry point to view operation
714 VG_STATIC
void workshop_op_download_and_view_submission( int result_index
)
716 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
717 ISteamRemoteStorage
*hSteamRemoteStorage
= SteamAPI_SteamRemoteStorage();
718 SteamUGCDetails_t details
;
719 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC
,
720 workshop_form
.ugc_query
.handle
,
724 skaterift_begin_op( k_workshop_form_op_downloading_submission
);
725 workshop_reset_submission_data();
726 workshop_form
.submission
.submit_description
= 0;
727 workshop_form
.submission
.submit_file_and_image
= 0;
728 workshop_form
.submission
.submit_title
= 0;
730 u8 metadata_buf
[512];
731 char metadata_str
[1024+1];
732 int have_meta
= SteamAPI_ISteamUGC_GetQueryUGCMetadata( hSteamUGC
,
733 workshop_form
.ugc_query
.handle
,
734 result_index
, metadata_str
,
737 vg_strncpy( details
.m_rgchDescription
,
738 workshop_form
.submission
.description
,
739 vg_list_size( workshop_form
.submission
.description
),
740 k_strncpy_always_add_null
);
742 vg_strncpy( details
.m_rgchTitle
,
743 workshop_form
.submission
.title
,
744 vg_list_size( workshop_form
.submission
.title
),
745 k_strncpy_always_add_null
);
747 snprintf( workshop_form
.addon_folder
,
748 vg_list_size( workshop_form
.addon_folder
),
749 "Steam Cloud (%lu)", details
.m_nPublishedFileId
);
751 workshop_form
.submission
.file_id
= details
.m_nPublishedFileId
;
752 workshop_form
.file_intent
= k_workshop_form_file_intent_keep_old
;
753 workshop_form
.page
= k_workshop_form_edit
;
754 workshop_form
.submission
.visibility
.value
= details
.m_eVisibility
;
755 workshop_form
.submission
.type
= k_workshop_file_type_none
;
756 workshop_form
.submission
.submission_type_selection
.index
= 0;
757 workshop_form
.submission
.submission_type_selection
.value
=
758 k_workshop_file_type_none
;
761 u32 len
= strlen(metadata_str
);
762 vg_info( "Metadata: %s\n", metadata_str
);
763 vg_str_bin( metadata_str
, metadata_buf
, len
);
765 vg_msg_init( &msg
, metadata_buf
, len
/2 );
768 while( vg_msg_next( &msg
, &cmd
) ){
769 if( (msg
.depth
== 1) && (cmd
.code
== k_vg_msg_code_frame
) ){
770 if( VG_STRDJB2_EQ( "workshop", cmd
.key
, cmd
.key_djb2
) ){
771 u32 depth
= msg
.depth
;
772 while( (msg
.depth
== depth
) && vg_msg_next( &msg
, &cmd
) ){
773 if( cmd
.code
& k_vg_msg_code_unsigned
){
774 if( VG_STRDJB2_EQ( "type", cmd
.key
, cmd
.key_djb2
) ){
775 workshop_form
.submission
.type
= cmd
.value
._u32
;
776 workshop_form
.submission
.submission_type_selection
.value
= cmd
.value
._u32
;
779 else if( cmd
.code
== k_vg_msg_code_kvstring
){
780 if( VG_STRDJB2_EQ( "folder", cmd
.key
, cmd
.key_djb2
) ){
781 vg_strncpy( cmd
.value
._buf
,
782 workshop_form
.addon_folder
,
783 sizeof(workshop_form
.addon_folder
),
784 k_strncpy_always_add_null
);
793 vg_error( "No metadata was returned with this item.\n" );
797 for( i32 i
=0; i
<vg_list_size(workshop_form_visibility_opts
); i
++ ){
798 if( workshop_form_visibility_opts
[i
].value
== details
.m_eVisibility
){
799 workshop_form
.submission
.visibility
.index
= i
;
803 for( i32 i
=0; i
<vg_list_size(workshop_form_type_opts
); i
++ ){
804 if( workshop_form_type_opts
[i
].value
==
805 workshop_form
.submission
.submission_type_selection
.value
){
806 workshop_form
.submission
.submission_type_selection
.index
= i
;
811 vg_error( "m_hPreviewFile is 0\n" );
812 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
813 glClearColor( 0.2f
, 0.0f
, 0.0f
, 1.0f
);
814 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
815 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
816 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
821 if( details
.m_hPreviewFile
== 0 ){
822 vg_error( "m_hPreviewFile is 0\n" );
826 /* Now need to begin downloading the image so we can display it */
827 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
829 struct workshop_loadpreview_info
*info
=
830 vg_linear_alloc( vg_mem
.scratch
,
831 sizeof( struct workshop_loadpreview_info
) );
833 snprintf( info
->abs_preview_image
, 1024,
834 "%smodels/boards/workshop/" PRINTF_U64
".jpg",
835 vg
.base_path
, details
.m_hPreviewFile
);
837 call
->p_handler
= on_workshop_download_ugcpreview
;
838 call
->userdata
= info
;
839 call
->id
= SteamAPI_ISteamRemoteStorage_UGCDownloadToLocation(
841 details
.m_hPreviewFile
, info
->abs_preview_image
, 1 );
843 vg_info( "preview file id: " PRINTF_U64
"\n",
844 details
.m_hPreviewFile
);
849 vg_error( "GetQueryUGCResult: Index out of range\n" );
856 * -----------------------------------------------------------------------------
860 * View a page of results on the sidebar
862 VG_STATIC
void workshop_view_page( int req
)
864 if( workshop_form
.ugc_query
.result
!= k_EResultOK
){
865 vg_error( "Tried to change page without complete data\n" );
869 int page
= VG_MAX(VG_MIN(req
, workshop_form
.view_published_page_count
-1),0),
870 start
= page
* WORKSHOP_VIEW_PER_PAGE
,
871 end
= VG_MIN( (page
+1) * WORKSHOP_VIEW_PER_PAGE
,
872 workshop_form
.ugc_query
.returned_item_count
),
875 vg_info( "View page %d\n", page
);
877 workshop_form
.view_published_page_id
= page
;
878 workshop_form
.published_files_list_length
= count
;
879 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
881 for( int i
=0; i
<count
; i
++ ){
882 struct published_file
*pfile
= &workshop_form
.published_files_list
[i
];
884 SteamUGCDetails_t details
;
885 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC
,
886 workshop_form
.ugc_query
.handle
,
890 if( details
.m_eResult
!= k_EResultOK
){
891 snprintf( pfile
->title
, 80, "Error (%d)", details
.m_eResult
);
894 vg_strncpy( details
.m_rgchTitle
, pfile
->title
, 80,
895 k_strncpy_always_add_null
);
898 pfile
->result
= details
.m_eResult
;
899 pfile
->result_index
= start
+i
;
902 pfile
->result
= k_EResultValueOutOfRange
;
903 pfile
->result_index
= -1;
904 snprintf( pfile
->title
, 80, "Error (invalid index)" );
910 * Steam API result for when we recieve submitted UGC information about the user
912 VG_STATIC
void on_workshop_UGCQueryComplete( void *data
, void *userdata
)
914 SteamUGCQueryCompleted_t
*query
= data
;
915 workshop_form
.ugc_query
.result
= query
->m_eResult
;
917 if( query
->m_eResult
== k_EResultOK
){
918 if( query
->m_unTotalMatchingResults
> 50 ){
919 vg_warn( "You have %d items submitted, "
920 "we can only view the last 50\n" );
923 workshop_form
.ugc_query
.all_item_count
= query
->m_unTotalMatchingResults
;
924 workshop_form
.ugc_query
.returned_item_count
=
925 query
->m_unNumResultsReturned
;
927 workshop_form
.ugc_query
.handle
= query
->m_handle
;
928 workshop_form
.view_published_page_count
=
929 (query
->m_unNumResultsReturned
+WORKSHOP_VIEW_PER_PAGE
-1)/
930 WORKSHOP_VIEW_PER_PAGE
;
931 workshop_form
.view_published_page_id
= 0;
932 workshop_form
.published_files_list_length
= 0;
934 workshop_view_page( 0 );
937 vg_error( "Steam UGCQuery failed (%d)\n", query
->m_eResult
);
938 workshop_form
.view_published_page_count
= 0;
939 workshop_form
.view_published_page_id
= 0;
940 workshop_form
.published_files_list_length
= 0;
942 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
943 SteamAPI_ISteamUGC_ReleaseQueryUGCRequest( hSteamUGC
, query
->m_handle
);
948 * Console command to open the workshop publisher
950 VG_STATIC
int workshop_submit_command( int argc
, const char *argv
[] )
953 vg_error( "Steam API is not ready or loaded\n" );
957 workshop_form
.page
= k_workshop_form_open
;
958 workshop_form
.view_published_page_count
= 0;
959 workshop_form
.view_published_page_id
= 0;
960 workshop_form
.published_files_list_length
= 0;
961 workshop_form
.ugc_query
.result
= k_EResultNone
;
963 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
965 ISteamUser
*hSteamUser
= SteamAPI_SteamUser();
967 steamid
.m_unAll64Bits
= SteamAPI_ISteamUser_GetSteamID( hSteamUser
);
969 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
970 call
->p_handler
= on_workshop_UGCQueryComplete
;
971 call
->userdata
= NULL
;
972 UGCQueryHandle_t handle
= SteamAPI_ISteamUGC_CreateQueryUserUGCRequest
975 steamid
.m_comp
.m_unAccountID
,
976 k_EUserUGCList_Published
,
977 k_EUGCMatchingUGCType_Items
,
978 k_EUserUGCListSortOrder_CreationOrderDesc
,
979 SKATERIFT_APPID
, SKATERIFT_APPID
,
981 SteamAPI_ISteamUGC_SetReturnMetadata( hSteamUGC
, handle
, 1 );
982 call
->id
= SteamAPI_ISteamUGC_SendQueryUGCRequest( hSteamUGC
, handle
);
986 VG_STATIC
void workshop_init(void)
988 vg_console_reg_cmd( "workshop_submit", workshop_submit_command
, NULL
);
991 VG_STATIC
void workshop_find_preview_entity(void)
993 workshop_form
.view_world
= world_current_instance();
995 if( mdl_arrcount( &workshop_form
.view_world
->ent_swspreview
) ){
996 workshop_form
.ptr_ent
=
997 mdl_arritm( &workshop_form
.view_world
->ent_swspreview
, 0 );
998 workshop_form
.page
= k_workshop_form_edit
;
1001 vg_error( "There is no ent_swspreview in the level. "
1002 "Cannot publish here\n" );
1007 * Redraw the model file into the workshop framebuffer
1009 VG_STATIC
void workshop_render_preview(void)
1011 if( !workshop_form
.ptr_ent
){
1015 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
1017 glClearColor( 0.0f
, 0.0f
, 0.3f
, 1.0f
);
1018 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
1019 glEnable( GL_DEPTH_TEST
);
1020 glDisable( GL_BLEND
);
1022 ent_swspreview
*swsprev
= workshop_form
.ptr_ent
;
1023 world_instance
*world
= workshop_form
.view_world
;
1025 ent_camera
*ref
= mdl_arritm( &world
->ent_camera
,
1026 mdl_entity_id_id(swsprev
->id_camera
) );
1027 ent_marker
*display
= mdl_arritm( &world
->ent_marker
,
1028 mdl_entity_id_id(swsprev
->id_display
) ),
1029 *display1
= mdl_arritm( &world
->ent_marker
,
1030 mdl_entity_id_id(swsprev
->id_display1
) );
1033 v3_add( display
->transform
.co
, display1
->transform
.co
, baseco
);
1034 v3_muls( baseco
, 0.5f
, baseco
);
1038 v3_sub( display
->transform
.co
, ref
->transform
.co
, basevector
);
1039 float dist
= v3_length( basevector
);
1042 player_vector_angles( baseangles
, basevector
, 1.0f
, 0.0f
);
1044 v2_add( workshop_form
.view_angles
, baseangles
, cam
.angles
);
1045 cam
.angles
[2] = 0.0f
;
1047 float sX
= sinf( cam
.angles
[0] ),
1048 cX
= cosf( cam
.angles
[0] ),
1049 sY
= sinf( cam
.angles
[1] ),
1050 cY
= cosf( cam
.angles
[1] );
1052 v3f offset
= { -sX
* cY
, sY
, cX
* cY
};
1054 v3_muladds( display
->transform
.co
, offset
,
1055 dist
*workshop_form
.view_dist
, cam
.pos
);
1057 cam
.pos
[0] += -sX
*workshop_form
.view_offset
[2];
1058 cam
.pos
[2] += cX
*workshop_form
.view_offset
[2];
1059 cam
.pos
[0] += cX
*workshop_form
.view_offset
[0];
1060 cam
.pos
[2] += sX
*workshop_form
.view_offset
[0];
1061 cam
.pos
[1] += workshop_form
.view_offset
[1];
1067 camera_update_transform( &cam
);
1068 camera_update_view( &cam
);
1069 camera_update_projection( &cam
);
1070 camera_finalize( &cam
);
1073 mdl_transform_m4x3( &display
->transform
, mmdl
);
1074 mdl_transform_m4x3( &display1
->transform
, mmdl1
);
1076 /* force update this for nice shadows. its usually set in the world
1077 * pre-render step, but that includes timer stuff
1079 struct player_board
*board
= &workshop_form
.board_model
;
1080 struct ub_world_lighting
*ubo
= &world
->ub_lighting
;
1082 v3_copy((v3f
){0.0f
,0.1f
, board
->truck_positions
[0][2]}, vp0
);
1083 v3_copy((v3f
){0.0f
,0.1f
, board
->truck_positions
[1][2]}, vp1
);
1084 m4x3_mulv( mmdl1
, vp0
, ubo
->g_board_0
);
1085 m4x3_mulv( mmdl1
, vp1
, ubo
->g_board_1
);
1086 glBindBuffer( GL_UNIFORM_BUFFER
, world
->ubo_lighting
);
1087 glBufferSubData( GL_UNIFORM_BUFFER
, 0,
1088 sizeof(struct ub_world_lighting
), &world
->ub_lighting
);
1090 render_world( world
, &cam
, 1 );
1091 render_board( &cam
, world
, board
, mmdl
, k_board_shader_entity
);
1092 render_board( &cam
, world
, board
, mmdl1
, k_board_shader_entity
);
1094 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
1095 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
1099 * ImGUI section for workshop form
1100 * -----------------------------------------------------------------------------
1103 VG_STATIC
void workshop_changed_model_path( char *buf
, u32 len
){
1104 workshop_form
.submission
.submit_file_and_image
= 1;
1107 VG_STATIC
void workshop_changed_title( char *buf
, u32 len
){
1108 workshop_form
.submission
.submit_title
= 1;
1111 VG_STATIC
void workshop_changed_description( char *buf
, u32 len
){
1112 workshop_form
.submission
.submit_description
= 1;
1115 VG_STATIC
void workshop_form_gui_edit_page( ui_rect content
)
1117 if( workshop_form
.submission
.type
== k_workshop_file_type_none
){
1119 rect_copy( content
, box
);
1121 box
[2] = (box
[2]*2)/3;
1122 ui_rect_center( content
, box
);
1125 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1126 ui_text( row
, "Select the type of item\n", 1, k_ui_align_middle_center
,0);
1127 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1128 ui_enum( row
, "Type:", workshop_form_type_opts
,
1129 3, &workshop_form
.submission
.submission_type_selection
);
1130 ui_split( box
, k_ui_axis_h
, 8, 0, row
, box
);
1131 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1133 ui_rect button_l
, button_r
;
1134 rect_copy( row
, button_l
);
1135 button_l
[2] = 128*2;
1136 ui_rect_center( row
, button_l
);
1137 ui_split_ratio( button_l
, k_ui_axis_v
, 0.5f
, 2, button_l
, button_r
);
1139 if( workshop_form
.submission
.submission_type_selection
.value
!=
1140 k_workshop_file_type_none
){
1141 if( ui_button_text( button_l
, "OK", 1 ) ){
1142 workshop_form
.submission
.type
=
1143 workshop_form
.submission
.submission_type_selection
.value
;
1147 ui_fill( button_l
, ui_colour(k_ui_bg
) );
1148 ui_text( button_l
, "OK", 1, k_ui_align_middle_center
,
1149 ui_colour(k_ui_bg
+4) );
1152 if( ui_button_text( button_r
, "Cancel", 1 ) ){
1153 workshop_form
.page
= k_workshop_form_open
;
1154 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1159 ui_rect image_plane
;
1160 ui_split( content
, k_ui_axis_h
, 300, 0, image_plane
, content
);
1161 ui_fill( image_plane
, ui_colour( k_ui_bg
+0 ) );
1164 ui_fit_item( image_plane
, (ui_px
[2]){ 3, 2 }, img_box
);
1166 if( workshop_form
.file_intent
== k_workshop_form_file_intent_keep_old
){
1167 ui_image( img_box
, gpipeline
.fb_workshop_preview
->attachments
[0].id
);
1169 else if( workshop_form
.file_intent
== k_workshop_form_file_intent_new
){
1170 ui_image( img_box
, gpipeline
.fb_workshop_preview
->attachments
[0].id
);
1171 int hover
= ui_inside_rect( img_box
, vg_ui
.mouse
),
1172 target
= ui_inside_rect( img_box
, vg_ui
.mouse_click
);
1174 if( ui_click_down(UI_MOUSE_MIDDLE
) && target
){
1175 v3_copy( workshop_form
.view_offset
,
1176 workshop_form
.view_offset_begin
);
1178 else if( ui_click_down(UI_MOUSE_LEFT
) && target
){
1179 v2_copy( workshop_form
.view_angles
,
1180 workshop_form
.view_angles_begin
);
1183 if( ui_clicking(UI_MOUSE_MIDDLE
) && target
){
1184 v2f delta
= { vg_ui
.mouse
[0]-vg_ui
.mouse_click
[0],
1185 vg_ui
.mouse
[1]-vg_ui
.mouse_click
[1] };
1187 float *begin
= workshop_form
.view_offset_begin
,
1188 *offset
= workshop_form
.view_offset
;
1189 offset
[0] = vg_clampf( begin
[0]-delta
[0]*0.002f
, -1.0f
, 1.0f
);
1190 offset
[2] = vg_clampf( begin
[2]-delta
[1]*0.002f
, -1.0f
, 1.0f
);
1191 workshop_form
.view_changed
= 1;
1193 else if( ui_clicking(UI_MOUSE_LEFT
) && target
){
1194 v2f delta
= { vg_ui
.mouse
[0]-vg_ui
.mouse_click
[0],
1195 vg_ui
.mouse
[1]-vg_ui
.mouse_click
[1] };
1198 v2_muladds( workshop_form
.view_angles_begin
, delta
, 0.002f
, angles
);
1200 float limit
= VG_PIf
*0.2f
;
1202 angles
[0] = vg_clampf( angles
[0], -limit
, limit
);
1203 angles
[1] = vg_clampf( angles
[1], -limit
, limit
);
1205 v2_copy( angles
, workshop_form
.view_angles
);
1206 workshop_form
.view_changed
= 1;
1209 if( !ui_clicking(UI_MOUSE_LEFT
) && hover
){
1210 float zoom
= workshop_form
.view_dist
;
1211 zoom
+= vg
.mouse_wheel
[1] * -0.07f
;
1212 zoom
= vg_clampf( zoom
, 0.4f
, 2.0f
);
1214 if( zoom
!= workshop_form
.view_dist
){
1215 workshop_form
.view_changed
= 1;
1216 workshop_form
.view_dist
= zoom
;
1221 ui_text( img_box
, "No image", 1, k_ui_align_middle_center
,
1222 ui_colour( k_ui_orange
) );
1226 ui_rect null
, file_entry
, file_button
, file_label
;
1227 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1228 ui_split( content
, k_ui_axis_h
, 28, 0, file_entry
, content
);
1229 ui_split( file_entry
, k_ui_axis_v
, -128, 0, file_entry
, file_button
);
1231 if( workshop_form
.submission
.type
== k_workshop_file_type_board
){
1232 ui_label( file_entry
, "Addon folder: skaterift/boards/",
1236 ui_label( file_entry
, "Addon folder: skaterift/maps/",
1240 if( workshop_form
.file_intent
!= k_workshop_form_file_intent_none
){
1241 ui_text( file_entry
, workshop_form
.addon_folder
, 1,
1242 k_ui_align_middle_left
, ui_colour( k_ui_fg
+4 ) );
1244 if( ui_button_text( file_button
, "Remove", 1 ) ){
1245 player_board_unload( &workshop_form
.board_model
);
1246 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1247 workshop_form
.addon_folder
[0] = '\0';
1251 struct ui_textbox_callbacks callbacks
= {
1252 .change
= workshop_changed_model_path
1255 ui_textbox( file_entry
, workshop_form
.addon_folder
,
1256 vg_list_size(workshop_form
.addon_folder
), 0, &callbacks
);
1258 if( ui_button_text( file_button
, "Load", 1 ) ){
1259 workshop_find_preview_entity();
1260 workshop_op_load_model();
1264 ui_rect title_entry
, label
;
1265 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1266 ui_split( content
, k_ui_axis_h
, 28, 0, title_entry
, content
);
1268 const char *str_title
= "Title:", *str_desc
= "Description:";
1269 ui_split( title_entry
, k_ui_axis_v
,
1270 ui_text_line_width(str_title
)+8, 0, label
, title_entry
);
1272 ui_rect vis_dropdown
;
1273 ui_split_ratio( title_entry
, k_ui_axis_v
, 0.6f
, 16,
1274 title_entry
, vis_dropdown
);
1278 struct ui_textbox_callbacks callbacks
= {
1279 .change
= workshop_changed_title
1281 ui_text( label
, str_title
, 1, k_ui_align_middle_left
, 0 );
1282 ui_textbox( title_entry
, workshop_form
.submission
.title
,
1283 vg_list_size(workshop_form
.submission
.title
), 0, &callbacks
);
1286 /* visibility option */
1288 ui_enum( vis_dropdown
, "Visibility:", workshop_form_visibility_opts
,
1289 4, &workshop_form
.submission
.visibility
);
1292 /* description box */
1294 struct ui_textbox_callbacks callbacks
= {
1295 .change
= workshop_changed_description
1298 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1299 ui_split( content
, k_ui_axis_h
, 28, 0, label
, content
);
1300 ui_split( content
, k_ui_axis_h
, 28*4, 0, desc_entry
, content
);
1301 ui_text( label
, str_desc
, 1, k_ui_align_middle_left
, 0 );
1302 ui_textbox( desc_entry
, workshop_form
.submission
.description
,
1303 vg_list_size(workshop_form
.submission
.description
),
1304 UI_TEXTBOX_MULTILINE
|UI_TEXTBOX_WRAP
, &callbacks
);
1307 /* submissionable */
1308 ui_rect submission_row
;
1309 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1310 ui_split( content
, k_ui_axis_h
, content
[3]-32-8, 0, content
,
1313 ui_rect submission_center
;
1314 rect_copy( submission_row
, submission_center
);
1315 submission_center
[2] = 256;
1316 ui_rect_center( submission_row
, submission_center
);
1318 ui_rect btn_left
, btn_right
;
1319 ui_split_ratio( submission_center
, k_ui_axis_v
, 0.5f
, 8,
1320 btn_left
, btn_right
);
1322 if( ui_button_text( btn_left
, "Publish", 1 ) ){
1323 workshop_op_submit();
1325 if( ui_button_text( btn_right
, "Cancel", 1 ) ){
1326 workshop_form
.page
= k_workshop_form_open
;
1327 player_board_unload( &workshop_form
.board_model
);
1328 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1332 const char *disclaimer_text
=
1333 "By submitting this item, you agree to the workshop terms of service";
1335 ui_rect disclaimer_row
, inner
, link
;
1336 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1337 ui_split( content
, k_ui_axis_h
, content
[3]-32, 0, content
,
1340 ui_px btn_width
= 32;
1342 rect_copy( disclaimer_row
, inner
);
1343 inner
[2] = ui_text_line_width( disclaimer_text
) + btn_width
+8;
1345 ui_rect_center( disclaimer_row
, inner
);
1346 ui_split( inner
, k_ui_axis_v
, inner
[2]-btn_width
, 0, label
, btn_right
);
1347 ui_rect_pad( btn_right
, (ui_px
[2]){2,2} );
1349 if( ui_button_text( btn_right
, "\x91", 2 ) ){
1350 ISteamFriends
*hSteamFriends
= SteamAPI_SteamFriends();
1351 SteamAPI_ISteamFriends_ActivateGameOverlayToWebPage( hSteamFriends
,
1352 "https://steamcommunity.com/sharedfiles/workshoplegalagreement",
1353 k_EActivateGameOverlayToWebPageMode_Default
);
1356 ui_text( label
, disclaimer_text
, 1, k_ui_align_middle_left
,
1357 ui_colour( k_ui_fg
+4 ) );
1360 VG_STATIC
void workshop_form_gui_sidebar( ui_rect sidebar
)
1362 ui_fill( sidebar
, ui_colour( k_ui_bg
+2 ) );
1365 ui_split( sidebar
, k_ui_axis_h
, 28, 0, title
, sidebar
);
1367 if( workshop_form
.page
== k_workshop_form_edit
){
1368 ui_text( title
, "Editing", 1, k_ui_align_middle_center
, 0 );
1369 ui_split( sidebar
, k_ui_axis_h
, 28, 0, title
, sidebar
);
1371 if( workshop_form
.submission
.type
!= k_workshop_file_type_none
){
1374 vg_strnull( &str
, buf
, 512 );
1376 if( workshop_form
.submission
.file_id
)
1377 vg_strcat( &str
, "Editing an existing " );
1379 vg_strcat( &str
, "Creating a new " );
1381 if( workshop_form
.submission
.type
== k_workshop_file_type_board
)
1382 vg_strcat( &str
, "skateboard." );
1383 else if( workshop_form
.submission
.type
== k_workshop_file_type_world
)
1384 vg_strcat( &str
, "world." );
1386 vg_strcat( &str
, "???." );
1388 ui_text( title
, buf
, 1, k_ui_align_middle_center
,
1389 ui_colour(k_ui_fg
+4) );
1395 * sidebar existing entries panel
1397 ui_text( title
, "Your submissions", 1, k_ui_align_middle_center
, 0 );
1399 ui_rect controls
, btn_create_new
;
1400 ui_split( sidebar
, k_ui_axis_h
, 32, 0, controls
, sidebar
);
1401 ui_split( sidebar
, k_ui_axis_h
, -32, 0, sidebar
, btn_create_new
);
1402 ui_fill( controls
, ui_colour( k_ui_bg
+1 ) );
1405 strcpy( buf
, "page " );
1407 i
+= highscore_intl( buf
+i
, workshop_form
.view_published_page_id
+1, 4 );
1409 i
+= highscore_intl( buf
+i
, workshop_form
.view_published_page_count
, 4 );
1412 ui_rect_pad( controls
, (ui_px
[2]){0,4} );
1414 ui_split_ratio( controls
, k_ui_axis_v
, 0.25f
, 0, info
, controls
);
1415 ui_text( info
, buf
, 1, k_ui_align_middle_center
, 0 );
1417 ui_rect btn_left
, btn_right
;
1418 ui_split_ratio( controls
, k_ui_axis_v
, 0.5f
, 2, btn_left
, btn_right
);
1420 if( ui_button_text( btn_left
, "newer", 1 ) ){
1421 workshop_view_page( workshop_form
.view_published_page_id
-1 );
1424 if( ui_button_text( btn_right
, "older", 1 ) ){
1425 workshop_view_page( workshop_form
.view_published_page_count
+1 );
1428 if( ui_button_text( btn_create_new
, "Create New Item", 1 ) ){
1429 workshop_reset_submission_data();
1430 workshop_form
.submission
.submit_title
= 1;
1431 workshop_form
.submission
.submit_description
= 1;
1432 workshop_form
.submission
.submit_file_and_image
= 1;
1433 workshop_form
.page
= k_workshop_form_edit
;
1434 workshop_find_preview_entity();
1437 for( int i
=0; i
<workshop_form
.published_files_list_length
; i
++ ){
1439 ui_split( sidebar
, k_ui_axis_h
, 28, 0, item
, sidebar
);
1440 ui_rect_pad( item
, (ui_px
[2]){4,4} );
1442 struct published_file
*pfile
= &workshop_form
.published_files_list
[i
];
1443 if( ui_button_text( item
, pfile
->title
, 1 ) ){
1444 if( pfile
->result
== k_EResultOK
){
1445 vg_info( "Select index: %d\n", pfile
->result_index
);
1446 workshop_op_download_and_view_submission( pfile
->result_index
);
1449 vg_warn( "Cannot select that item, result not OK\n" );
1455 VG_STATIC
void workshop_form_gui(void)
1457 enum workshop_form_page stable_page
= workshop_form
.page
;
1458 if( stable_page
== k_workshop_form_hidden
) return;
1461 ui_rect screen
= { 0, 0, vg
.window_x
, vg
.window_y
};
1462 ui_rect window
= { 0, 0, 1000, 700 };
1463 ui_rect_center( screen
, window
);
1464 vg_ui
.wants_mouse
= 1;
1466 ui_fill( window
, ui_colour( k_ui_bg
+1 ) );
1467 ui_outline( window
, 1, ui_colour( k_ui_bg
+7 ) );
1469 ui_rect title
, panel
;
1470 ui_split( window
, k_ui_axis_h
, 28, 0, title
, panel
);
1471 ui_fill( title
, ui_colour( k_ui_bg
+7 ) );
1472 ui_text( title
, "Workshop tool", 1, k_ui_align_middle_center
,
1473 ui_colourcont(k_ui_bg
+7) );
1475 ui_rect quit_button
;
1476 ui_split( title
, k_ui_axis_v
, title
[2]-title
[3], 2, title
, quit_button
);
1478 if( skaterift
.async_op
== k_async_op_none
){
1479 if( ui_button_text( quit_button
, "X", 1 ) ){
1480 workshop_quit_form();
1486 * temporary operation blinders, we don't yet have a nice way to show the
1487 * user that we're doing something uninterruptable, so the code just
1488 * escapes here and we show them a basic string
1491 if( skaterift
.async_op
!= k_async_op_none
){
1492 const char *op_string
= "The programmer has not bothered to describe "
1493 "the current operation that is running.";
1495 switch( skaterift
.async_op
){
1496 case k_workshop_form_op_loading_model
:
1497 op_string
= "Operation in progress: Loading model file.";
1499 case k_workshop_form_op_publishing_update
:
1500 op_string
= "Operation in progress: publishing submission update "
1503 case k_workshop_form_op_downloading_submission
:
1504 op_string
= "Operation in progress: downloading existing submission"
1505 " from Steam services.";
1510 ui_text( panel
, op_string
, 1, k_ui_align_middle_center
, 0 );
1514 /* re draw board preview if need to */
1515 if( (stable_page
== k_workshop_form_edit
) &&
1516 workshop_form
.view_changed
&&
1517 workshop_form
.file_intent
== k_workshop_form_file_intent_new
)
1519 workshop_render_preview();
1520 workshop_form
.view_changed
= 0;
1523 struct workshop_form
*form
= &workshop_form
;
1525 ui_rect sidebar
, content
;
1526 ui_split_ratio( panel
, k_ui_axis_v
, 0.3f
, 1, sidebar
, content
);
1529 ui_rect_pad( content
, (ui_px
[2]){8,8} );
1531 if( stable_page
== k_workshop_form_edit
){
1532 workshop_form_gui_edit_page( content
);
1534 else if( stable_page
== k_workshop_form_open
){
1535 ui_text( content
, "Nothing selected.", 1, k_ui_align_middle_center
,
1536 ui_colour( k_ui_fg
+4 ) );
1538 else if( stable_page
>= k_workshop_form_cclosing
){
1539 ui_rect submission_row
;
1540 ui_split( content
, k_ui_axis_h
, content
[3]-32-8, 0, content
,
1545 if( stable_page
== k_workshop_form_closing_bad
)
1546 colour
= ui_colour( k_ui_red
+k_ui_brighter
);
1548 colour
= ui_colour( k_ui_green
+k_ui_brighter
);
1550 ui_text( content
, workshop_form
.failure_or_success_string
, 1,
1551 k_ui_align_middle_center
, colour
);
1553 ui_rect submission_center
;
1554 rect_copy( submission_row
, submission_center
);
1555 submission_center
[2] = 128;
1556 ui_rect_center( submission_row
, submission_center
);
1557 ui_rect_pad( submission_center
, (ui_px
[2]){8,8} );
1559 if( ui_button_text( submission_center
, "OK", 1 ) ){
1560 workshop_form
.page
= k_workshop_form_open
;
1564 workshop_form_gui_sidebar( sidebar
);
1568 * Some async api stuff
1569 * -----------------------------------------------------------------------------
1572 VG_STATIC
void async_workshop_get_filepath( void *data
, u32 len
)
1574 struct async_workshop_filepath_info
*info
= data
;
1579 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
1580 if( !SteamAPI_ISteamUGC_GetItemInstallInfo( hSteamUGC
, info
->id
, &_size
,
1581 info
->buf
, info
->len
, &_ts
))
1583 vg_error( "GetItemInstallInfo failed\n" );
1584 info
->buf
[0] = '\0';
1588 VG_STATIC
void async_workshop_get_installed_files( void *data
, u32 len
)
1590 struct async_workshop_installed_files_info
*info
= data
;
1592 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
1593 u32 count
= SteamAPI_ISteamUGC_GetSubscribedItems( hSteamUGC
, info
->buffer
,
1596 vg_info( "Found %u subscribed items\n", count
);
1599 for( u32 i
=0; i
<count
; i
++ ){
1600 u32 state
= SteamAPI_ISteamUGC_GetItemState( hSteamUGC
, info
->buffer
[i
] );
1601 if( state
& k_EItemStateInstalled
){
1602 info
->buffer
[j
++] = info
->buffer
[i
];
1610 VG_STATIC
void vg_strsan_ascii( char *buf
, u32 len
)
1612 for( u32 i
=0; i
<len
-1; i
++ ){
1613 if( buf
[i
] == 0 ) return;
1615 if( buf
[i
] < 32 || buf
[i
] > 126 ){
1622 #define VG_STRSAN_ASCII( X ) vg_strsan_ascii( X, vg_list_size(X) )
1624 VG_STATIC
void workshop_load_metadata( const char *path
,
1625 struct workshop_file_info
*info
)
1627 FILE *fp
= fopen( path
, "rb" );
1630 if( fread( info
, sizeof( struct workshop_file_info
), 1, fp
) ){
1631 VG_STRSAN_ASCII( info
->author_name
);
1632 VG_STRSAN_ASCII( info
->title
);
1639 #endif /* WORKSHOP_C */