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
},
29 { "Player", k_addon_type_player
},
33 * Close the form and discard UGC query result
35 VG_STATIC
void workshop_quit_form(void){
36 player_board_unload( &workshop_form
.board_model
);
37 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
39 if( workshop_form
.ugc_query
.result
== k_EResultOK
){
40 workshop_form
.ugc_query
.result
= k_EResultNone
;
42 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
43 SteamAPI_ISteamUGC_ReleaseQueryUGCRequest(
44 hSteamUGC
, workshop_form
.ugc_query
.handle
);
47 workshop_form
.page
= k_workshop_form_hidden
;
48 workshop_form
.op
= k_workshop_op_none
;
52 * Delete all information about the submission
54 VG_STATIC
void workshop_reset_submission_data(void)
56 workshop_form
.submission
.file_id
= 0; /* assuming id of 0 is none/invalid */
57 workshop_form
.submission
.description
[0] = '\0';
58 workshop_form
.submission
.title
[0] = '\0';
59 workshop_form
.submission
.author
[0] = '\0';
60 workshop_form
.submission
.submission_type_selection
.value
=
62 workshop_form
.submission
.submission_type_selection
.index
= 0;
63 workshop_form
.submission
.type
= k_addon_type_none
;
65 workshop_form
.submission
.visibility
.value
=
66 k_ERemoteStoragePublishedFileVisibilityPublic
;
67 workshop_form
.submission
.visibility
.index
= 0;
69 workshop_form
.addon_folder
[0] = '\0';
70 player_board_unload( &workshop_form
.board_model
);
71 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
76 * Mostly copies of what it sais on the Steam API documentation
78 VG_STATIC
const char *workshop_EResult_user_string( EResult result
)
81 case k_EResultInsufficientPrivilege
:
82 return "Your account is currently restricted from uploading content "
83 "due to a hub ban, account lock, or community ban. You need to "
84 "contact Steam Support to resolve the issue.";
86 return "You do not have permission to upload content to this hub "
87 "because you have an active VAC or Game ban.";
88 case k_EResultTimeout
:
89 return "The operation took longer than expected, so it was discarded. "
91 case k_EResultNotLoggedOn
:
92 return "You are currently not logged into Steam.";
93 case k_EResultServiceUnavailable
:
94 return "The workshop server is having issues or is unavailable, "
96 case k_EResultInvalidParam
:
97 return "One of the submission fields contains something not being "
98 "accepted by that field.";
99 case k_EResultAccessDenied
:
100 return "There was a problem trying to save the title and description. "
101 "Access was denied.";
102 case k_EResultLimitExceeded
:
103 return "You have exceeded your Steam Cloud quota. If you wish to "
104 "upload this file, you must remove some published items.";
105 case k_EResultFileNotFound
:
106 return "The uploaded file could not be found.";
107 case k_EResultDuplicateRequest
:
108 return "The file was already successfully uploaded.";
109 case k_EResultDuplicateName
:
110 return "You already have a Steam Workshop item with that name.";
111 case k_EResultServiceReadOnly
:
112 return "Due to a recent password or email change, you are not allowed "
113 "to upload new content. Usually this restriction will expire in"
114 " 5 days, but can last up to 30 days if the account has been "
115 "inactive recently.";
117 return "Operation failed for an error which has not been accounted for "
118 "by the programmer. Try again, sorry :)";
123 * op: k_workshop_form_op_publishing_update
124 * ----------------------------------------------------------------------------
128 * The endpoint of this operation
130 VG_STATIC
void on_workshop_update_result( void *data
, void *user
)
132 vg_info( "Recieved workshop update result\n" );
133 SubmitItemUpdateResult_t
*result
= data
;
135 /* this seems to be set here, but my account definitely has accepted it */
136 if( result
->m_bUserNeedsToAcceptWorkshopLegalAgreement
){
137 vg_warn( "Workshop agreement currently not accepted\n" );
140 if( result
->m_eResult
== k_EResultOK
){
141 workshop_form
.page
= k_workshop_form_closing_good
;
142 workshop_form
.failure_or_success_string
= "Uploaded workshop file!";
143 vg_success( "file uploaded\n" );
146 workshop_form
.page
= k_workshop_form_closing_bad
;
147 workshop_form
.failure_or_success_string
=
148 workshop_EResult_user_string( result
->m_eResult
);
150 vg_error( "Error with the submitted file (%d)\n", result
->m_eResult
);
152 workshop_form
.op
= k_workshop_op_none
;
155 VG_STATIC
const char *workshop_filetype_folder(void){
156 enum addon_type type
= workshop_form
.submission
.type
;
157 if ( type
== k_addon_type_board
) return "boards/";
158 else if( type
== k_addon_type_player
) return "playermodels/";
159 else if( type
== k_addon_type_world
) return "maps/";
161 return "unknown_addon_type/";
165 * reciever on completion of packaging the files, it will then start the item
166 * update with Steam API
168 VG_STATIC
void workshop_form_upload_submission( PublishedFileId_t file_id
,
171 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
172 UGCUpdateHandle_t handle
173 = SteamAPI_ISteamUGC_StartItemUpdate( hSteamUGC
, SKATERIFT_APPID
,
176 /* TODO: Handle failure cases for these */
178 SteamAPI_ISteamUGC_SetItemMetadata( hSteamUGC
, handle
, metadata
);
180 if( workshop_form
.submission
.submit_title
){
181 vg_info( "Setting title\n" );
182 SteamAPI_ISteamUGC_SetItemTitle( hSteamUGC
, handle
,
183 workshop_form
.submission
.title
);
186 if( workshop_form
.submission
.submit_description
){
187 vg_info( "Setting description\n" );
188 SteamAPI_ISteamUGC_SetItemDescription( hSteamUGC
, handle
,
189 workshop_form
.submission
.description
);
192 if( workshop_form
.submission
.submit_file_and_image
){
195 vg_strnull( &folder
, path_buf
, 4096 );
196 vg_strcat( &folder
, vg
.base_path
);
198 vg_strcat( &folder
, workshop_filetype_folder() );
199 vg_strcat( &folder
, workshop_form
.addon_folder
);
201 vg_info( "Setting item content\n" );
202 SteamAPI_ISteamUGC_SetItemContent( hSteamUGC
, handle
, folder
.buffer
);
204 vg_str preview
= folder
;
205 vg_strcat( &preview
, "/preview.jpg" );
207 vg_info( "Setting preview image\n" );
208 SteamAPI_ISteamUGC_SetItemPreview( hSteamUGC
, handle
, preview
.buffer
);
211 vg_info( "Setting visibility\n" );
212 SteamAPI_ISteamUGC_SetItemVisibility( hSteamUGC
, handle
,
213 workshop_form
.submission
.visibility
.value
);
215 vg_info( "Submitting updates\n" );
216 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
217 call
->userdata
= NULL
;
218 call
->p_handler
= on_workshop_update_result
;
219 call
->id
= SteamAPI_ISteamUGC_SubmitItemUpdate( hSteamUGC
, handle
, "" );
223 * Steam API call result for when we've created a new item on their network, or
224 * not, if it has failed
226 VG_STATIC
void on_workshop_createitem( void *data
, void *user
)
228 CreateItemResult_t
*result
= data
;
230 if( result
->m_eResult
== k_EResultOK
){
231 vg_info( "Created workshop file with id: %lu\n",
232 result
->m_nPublishedFileId
);
234 if( result
->m_bUserNeedsToAcceptWorkshopLegalAgreement
){
235 vg_warn( "Workshop agreement currently not accepted\n" );
238 workshop_form_upload_submission( result
->m_nPublishedFileId
, user
);
241 const char *errstr
= workshop_EResult_user_string( result
->m_eResult
);
244 vg_error( "ISteamUGC_CreateItem() failed(%d): '%s' \n",
245 result
->m_eResult
, errstr
);
248 workshop_form
.page
= k_workshop_form_closing_bad
;
249 workshop_form
.failure_or_success_string
= errstr
;
254 * Starts the workshop upload process through Steam API
256 VG_STATIC
void workshop_form_async_submit_begin( void *payload
, u32 size
)
259 /* use existing file */
260 if( workshop_form
.submission
.file_id
){
261 workshop_form_upload_submission( workshop_form
.submission
.file_id
,
265 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
266 call
->userdata
= payload
;
267 call
->p_handler
= on_workshop_createitem
;
268 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
269 call
->id
= SteamAPI_ISteamUGC_CreateItem( hSteamUGC
, SKATERIFT_APPID
,
270 k_EWorkshopFileTypeCommunity
);
275 * Downloads the framebuffer into scratch memory
277 VG_STATIC
void workshop_form_async_download_image( void *payload
, u32 size
)
280 render_fb_get_current_res( gpipeline
.fb_workshop_preview
, &w
, &h
);
281 vg_linear_clear( vg_mem
.scratch
);
282 workshop_form
.img_buffer
= vg_linear_alloc( vg_mem
.scratch
, w
*h
*3 );
284 vg_info( "read framebuffer: glReadPixels( %dx%d )\n", w
,h
);
286 glBindFramebuffer( GL_READ_FRAMEBUFFER
, gpipeline
.fb_workshop_preview
->fb
);
287 glReadBuffer( GL_COLOR_ATTACHMENT0
);
288 glReadPixels( 0,0, w
,h
, GL_RGB
, GL_UNSIGNED_BYTE
, workshop_form
.img_buffer
);
290 workshop_form
.img_w
= w
;
291 workshop_form
.img_h
= h
;
295 * Thread which kicks off the upload process
297 VG_STATIC
void _workshop_form_submit_thread( void *data
)
299 vg_async_call( workshop_form_async_download_image
, NULL
, 0 );
304 vg_strnull( &folder
, path_buf
, 4096 );
306 vg_strcat( &folder
, workshop_filetype_folder() );
307 vg_strcat( &folder
, workshop_form
.addon_folder
);
309 if( !vg_strgood(&folder
) ){
310 vg_error( "addon folder path too long\n" );
311 workshop_form
.op
= k_workshop_op_none
;
316 * Create the metadata file
317 * -----------------------------------------------------------------------*/
318 u8 descriptor_buf
[ 512 ];
319 vg_msg descriptor
= {0};
320 descriptor
.buf
= descriptor_buf
;
321 descriptor
.max
= sizeof(descriptor_buf
);
323 vg_linear_clear( vg_mem
.scratch
);
325 /* short description */
326 vg_msg_frame( &descriptor
, "workshop" );
327 vg_msg_wkvstr( &descriptor
, "title", workshop_form
.submission
.title
);
328 //vg_msg_wkvstr( &descriptor, "author", "unknown" );
329 vg_msg_wkvu32( &descriptor
, "type", workshop_form
.submission
.type
);
330 vg_msg_wkvstr( &descriptor
, "folder", workshop_form
.addon_folder
);
331 vg_msg_end_frame( &descriptor
);
332 //vg_msg_wkvstr( &descriptor, "location", "USA" );
334 char *short_descriptor_str
= vg_linear_alloc( vg_mem
.scratch
,
335 vg_align8(descriptor
.cur
*2+1));
336 vg_bin_str( descriptor_buf
, short_descriptor_str
, descriptor
.cur
);
337 short_descriptor_str
[descriptor
.cur
*2] = '\0';
338 vg_info( "binstr: %s\n", short_descriptor_str
);
341 if( !vg_dir_open( &dir
, folder
.buffer
) ){
342 vg_error( "could not open addon folder '%s'\n", folder
.buffer
);
343 workshop_form
.op
= k_workshop_op_none
;
347 while( vg_dir_next_entry(&dir
) ){
348 if( vg_dir_entry_type(&dir
) == k_vg_entry_type_file
){
349 const char *d_name
= vg_dir_entry_name(&dir
);
350 if( d_name
[0] == '.' ) continue;
352 vg_str file
= folder
;
353 vg_strcat( &file
, "/" );
354 vg_strcat( &file
, d_name
);
355 if( !vg_strgood( &file
) ) continue;
357 char *ext
= vg_strch( &file
, '.' );
359 if( strcmp(ext
,".mdl") ) continue;
361 vg_msg_wkvstr( &descriptor
, "content", d_name
);
367 vg_str descriptor_file
= folder
;
368 vg_strcat( &descriptor_file
, "/addon.inf" );
369 if( !vg_strgood(&descriptor_file
) ){
370 vg_error( "Addon info path too long\n" );
371 workshop_form
.op
= k_workshop_op_none
;
375 FILE *fp
= fopen( descriptor_file
.buffer
, "wb" );
377 vg_error( "Could not open addon info file '%s'\n",
378 descriptor_file
.buffer
);
379 workshop_form
.op
= k_workshop_op_none
;
382 fwrite( descriptor_buf
, descriptor
.cur
, 1, fp
);
386 * -----------------------------------------------------------------------*/
387 vg_str preview
= folder
;
388 vg_strcat( &preview
, "/preview.jpg" );
390 if( !vg_strgood(&preview
) ){
391 vg_error( "preview image path too long\n" );
392 workshop_form
.op
= k_workshop_op_none
;
396 int w
= workshop_form
.img_w
,
397 h
= workshop_form
.img_h
;
399 vg_info( "writing: %s (%dx%d @90%%)\n", preview
.buffer
, w
,h
);
400 stbi_flip_vertically_on_write(1);
401 stbi_write_jpg( preview
.buffer
, w
,h
, 3, workshop_form
.img_buffer
, 90 );
403 vg_async_call( workshop_form_async_submit_begin
, short_descriptor_str
, 0 );
407 * Entry point for the publishing submission operation
409 VG_STATIC
void workshop_op_submit(void){
410 /* TODO: Show these errors to the user */
411 if( workshop_form
.submission
.submit_title
){
412 if( !workshop_form
.submission
.title
[0] ){
413 ui_start_modal( "Cannot submit because a title is required\n",
415 workshop_form
.op
= k_workshop_op_none
;
420 if( workshop_form
.submission
.submit_description
){
421 if( !workshop_form
.submission
.description
[0] ){
422 ui_start_modal( "Cannot submit because a description is required\n",
424 workshop_form
.op
= k_workshop_op_none
;
429 if( workshop_form
.submission
.submit_file_and_image
){
430 if( workshop_form
.file_intent
== k_workshop_form_file_intent_none
){
431 ui_start_modal( "Cannot submit because the file is "
432 "empty or unspecified\n", UI_MODAL_WARN
);
433 workshop_form
.op
= k_workshop_op_none
;
438 player_board_unload( &workshop_form
.board_model
);
439 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
440 workshop_form
.op
= k_workshop_op_publishing_update
;
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" );
462 workshop_form
.op
= k_workshop_op_none
;
466 * Reciever for failure to load
468 VG_STATIC
void workshop_form_loadmodel_async_error( void *payload
, u32 size
){
472 * Thread which loads the model from the disk
474 VG_STATIC
void _workshop_form_load_thread( void *data
)
478 vg_strnull( &folder
, path_buf
, 4096 );
480 vg_strcat( &folder
, workshop_filetype_folder() );
481 vg_strcat( &folder
, workshop_form
.addon_folder
);
483 if( !vg_strgood(&folder
) ){
484 vg_error( "workshop async load failed: path too long\n" );
485 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
486 workshop_form
.op
= k_workshop_op_none
;
491 if( !vg_dir_open( &dir
, folder
.buffer
) ){
492 vg_error( "workshop async load failed: could not open folder\n" );
493 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
494 workshop_form
.op
= k_workshop_op_none
;
498 vg_info( "Searching %s for model files\n", folder
.buffer
);
501 while( vg_dir_next_entry(&dir
) ){
502 if( vg_dir_entry_type(&dir
) == k_vg_entry_type_file
){
503 const char *d_name
= vg_dir_entry_name(&dir
);
504 if( d_name
[0] == '.' ) continue;
506 vg_str file
= folder
;
507 vg_strcat( &file
, "/" );
508 vg_strcat( &file
, d_name
);
509 if( !vg_strgood( &file
) ) continue;
511 char *ext
= vg_strch( &file
, '.' );
513 if( strcmp(ext
,".mdl") ) continue;
521 vg_error( "workshop async load failed: no model files found\n" );
522 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
523 workshop_form
.op
= k_workshop_op_none
;
527 if( workshop_form
.submission
.type
== k_addon_type_board
)
528 player_board_load( &workshop_form
.board_model
, path_buf
);
529 else if( workshop_form
.submission
.type
== k_addon_type_player
)
530 player_model_load( &workshop_form
.player_model
, path_buf
);
532 vg_async_call( workshop_form_loadmodel_async_complete
, NULL
, 0 );
536 * Entry point for load model operation
538 VG_STATIC
void workshop_op_load_model(void){
539 world_instance
*world
= world_current_instance();
540 workshop_form
.view_world
= world
;
542 if( workshop_form
.submission
.type
== k_addon_type_board
){
543 if( mdl_arrcount( &world
->ent_swspreview
) ){
544 workshop_form
.ptr_ent
=
545 mdl_arritm( &world
->ent_swspreview
, 0 );
548 ui_start_modal( "There is no ent_swspreview in the level. \n"
549 "Cannot publish here\n", UI_MODAL_BAD
);
550 workshop_form
.op
= k_workshop_op_none
;
554 else if( workshop_form
.submission
.type
== k_addon_type_player
){}
556 ui_start_modal( "Don't know how to prepare for this item type. \n"
557 "Please contact the developers.\n", UI_MODAL_BAD
);
558 workshop_form
.op
= k_workshop_op_none
;
562 workshop_form
.op
= k_workshop_op_loading_model
;
563 vg_loader_start( _workshop_form_load_thread
, NULL
);
567 * op: k_workshop_form_op_downloading_submission
568 * -----------------------------------------------------------------------------
572 * The image has been decoded and is ready to slap into the framebuffer
574 VG_STATIC
void workshop_form_async_imageload( void *data
, u32 len
)
577 struct framebuffer_attachment
*a
=
578 &gpipeline
.fb_workshop_preview
->attachments
[0];
580 glBindTexture( GL_TEXTURE_2D
, a
->id
);
581 glTexSubImage2D( GL_TEXTURE_2D
, 0,0,0,
582 WORKSHOP_PREVIEW_WIDTH
, WORKSHOP_PREVIEW_HEIGHT
,
583 a
->format
, a
->type
, data
);
584 stbi_image_free( data
);
585 vg_success( "Loaded workshop preview image\n" );
588 snprintf( workshop_form
.error_msg
, sizeof(workshop_form
.error_msg
),
589 "Preview image could not be loaded. Reason: %s\n",
590 stbi_failure_reason() );
591 ui_start_modal( workshop_form
.error_msg
, UI_MODAL_BAD
);
593 workshop_form
.op
= k_workshop_op_none
;
597 * Load the image located at ./workshop_preview.jpg into our framebuffer
599 VG_STATIC
void _workshop_load_preview_thread( void *data
){
600 char path_buf
[ 4096 ];
602 vg_strnull( &path
, path_buf
, 4096 );
603 vg_strcat( &path
, workshop_filetype_folder() );
604 vg_strcat( &path
, workshop_form
.addon_folder
);
605 vg_strcat( &path
, "/preview.jpg" );
607 if( vg_strgood( &path
) ){
608 stbi_set_flip_vertically_on_load(1);
610 u8
*rgb
= stbi_load( path
.buffer
, &x
, &y
, &nc
, 3 );
613 if( (x
== WORKSHOP_PREVIEW_WIDTH
) && (y
== WORKSHOP_PREVIEW_HEIGHT
) ){
614 vg_async_call( workshop_form_async_imageload
, rgb
, x
*y
*3 );
617 vg_error( "Resolution does not match framebuffer, so we can't"
619 stbi_image_free( rgb
);
620 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
624 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
628 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
633 * Entry point to view operation
635 VG_STATIC
void workshop_op_download_and_view_submission( int result_index
)
637 workshop_form
.op
= k_workshop_op_downloading_submission
;
638 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
639 ISteamRemoteStorage
*hSteamRemoteStorage
= SteamAPI_SteamRemoteStorage();
640 SteamUGCDetails_t details
;
641 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC
,
642 workshop_form
.ugc_query
.handle
,
646 workshop_reset_submission_data();
647 workshop_form
.submission
.submit_description
= 0;
648 workshop_form
.submission
.submit_file_and_image
= 0;
649 workshop_form
.submission
.submit_title
= 0;
651 u8 metadata_buf
[512];
652 char metadata_str
[1024+1];
653 int have_meta
= SteamAPI_ISteamUGC_GetQueryUGCMetadata( hSteamUGC
,
654 workshop_form
.ugc_query
.handle
,
655 result_index
, metadata_str
,
658 vg_strncpy( details
.m_rgchDescription
,
659 workshop_form
.submission
.description
,
660 vg_list_size( workshop_form
.submission
.description
),
661 k_strncpy_always_add_null
);
663 vg_strncpy( details
.m_rgchTitle
,
664 workshop_form
.submission
.title
,
665 vg_list_size( workshop_form
.submission
.title
),
666 k_strncpy_always_add_null
);
668 snprintf( workshop_form
.addon_folder
,
669 vg_list_size( workshop_form
.addon_folder
),
670 "Steam Cloud ("PRINTF_U64
")", details
.m_nPublishedFileId
);
672 workshop_form
.submission
.file_id
= details
.m_nPublishedFileId
;
673 workshop_form
.file_intent
= k_workshop_form_file_intent_keep_old
;
674 workshop_form
.page
= k_workshop_form_edit
;
675 workshop_form
.submission
.visibility
.value
= details
.m_eVisibility
;
676 workshop_form
.submission
.type
= k_addon_type_none
;
677 workshop_form
.submission
.submission_type_selection
.index
= 0;
678 workshop_form
.submission
.submission_type_selection
.value
=
682 u32 len
= strlen(metadata_str
);
683 vg_info( "Metadata: %s\n", metadata_str
);
684 vg_str_bin( metadata_str
, metadata_buf
, len
);
686 root
.buf
= metadata_buf
;
690 vg_msg workshop
= root
;
691 if( vg_msg_seekframe( &workshop
, "workshop", k_vg_msg_first
)){
692 u32 type
= vg_msg_seekkvu32( &workshop
, "type", k_vg_msg_first
);
693 workshop_form
.submission
.type
= type
;
694 workshop_form
.submission
.submission_type_selection
.value
= type
;
696 const char *kv_folder
= vg_msg_seekkvstr( &workshop
, "folder",
699 vg_strncpy( kv_folder
, workshop_form
.addon_folder
,
700 sizeof(workshop_form
.addon_folder
),
701 k_strncpy_always_add_null
);
706 vg_error( "No metadata was returned with this item.\n" );
710 for( i32 i
=0; i
<vg_list_size(workshop_form_visibility_opts
); i
++ ){
711 if( workshop_form_visibility_opts
[i
].value
== details
.m_eVisibility
){
712 workshop_form
.submission
.visibility
.index
= i
;
716 for( i32 i
=0; i
<vg_list_size(workshop_form_type_opts
); i
++ ){
717 if( workshop_form_type_opts
[i
].value
==
718 workshop_form
.submission
.submission_type_selection
.value
){
719 workshop_form
.submission
.submission_type_selection
.index
= i
;
724 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
725 glClearColor( 0.2f
, 0.0f
, 0.0f
, 1.0f
);
726 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
727 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
728 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
730 vg_loader_start( _workshop_load_preview_thread
, NULL
);
733 vg_error( "GetQueryUGCResult: Index out of range\n" );
734 workshop_form
.op
= k_workshop_op_none
;
740 * -----------------------------------------------------------------------------
744 * View a page of results on the sidebar
746 VG_STATIC
void workshop_view_page( int req
)
748 if( workshop_form
.ugc_query
.result
!= k_EResultOK
){
749 vg_error( "Tried to change page without complete data\n" );
750 workshop_form
.op
= k_workshop_op_none
;
754 int page
= VG_MAX(VG_MIN(req
, workshop_form
.view_published_page_count
-1),0),
755 start
= page
* WORKSHOP_VIEW_PER_PAGE
,
756 end
= VG_MIN( (page
+1) * WORKSHOP_VIEW_PER_PAGE
,
757 workshop_form
.ugc_query
.returned_item_count
),
760 vg_info( "View page %d\n", page
);
762 workshop_form
.view_published_page_id
= page
;
763 workshop_form
.published_files_list_length
= count
;
764 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
766 for( int i
=0; i
<count
; i
++ ){
767 struct published_file
*pfile
= &workshop_form
.published_files_list
[i
];
769 SteamUGCDetails_t details
;
770 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC
,
771 workshop_form
.ugc_query
.handle
,
775 if( details
.m_eResult
!= k_EResultOK
){
776 snprintf( pfile
->title
, 80, "Error (%d)", details
.m_eResult
);
779 vg_strncpy( details
.m_rgchTitle
, pfile
->title
, 80,
780 k_strncpy_always_add_null
);
783 pfile
->result
= details
.m_eResult
;
784 pfile
->result_index
= start
+i
;
787 pfile
->result
= k_EResultValueOutOfRange
;
788 pfile
->result_index
= -1;
789 snprintf( pfile
->title
, 80, "Error (invalid index)" );
795 * Steam API result for when we recieve submitted UGC information about the user
797 VG_STATIC
void on_workshop_UGCQueryComplete( void *data
, void *userdata
)
799 SteamUGCQueryCompleted_t
*query
= data
;
800 workshop_form
.ugc_query
.result
= query
->m_eResult
;
802 if( query
->m_eResult
== k_EResultOK
){
803 if( query
->m_unTotalMatchingResults
> 50 ){
804 vg_warn( "You have %d items submitted, "
805 "we can only view the last 50\n" );
808 workshop_form
.ugc_query
.all_item_count
= query
->m_unTotalMatchingResults
;
809 workshop_form
.ugc_query
.returned_item_count
=
810 query
->m_unNumResultsReturned
;
812 workshop_form
.ugc_query
.handle
= query
->m_handle
;
813 workshop_form
.view_published_page_count
=
814 (query
->m_unNumResultsReturned
+WORKSHOP_VIEW_PER_PAGE
-1)/
815 WORKSHOP_VIEW_PER_PAGE
;
816 workshop_form
.view_published_page_id
= 0;
817 workshop_form
.published_files_list_length
= 0;
819 workshop_view_page( 0 );
822 vg_error( "Steam UGCQuery failed (%d)\n", query
->m_eResult
);
823 workshop_form
.view_published_page_count
= 0;
824 workshop_form
.view_published_page_id
= 0;
825 workshop_form
.published_files_list_length
= 0;
827 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
828 SteamAPI_ISteamUGC_ReleaseQueryUGCRequest( hSteamUGC
, query
->m_handle
);
833 * Console command to open the workshop publisher
835 VG_STATIC
int workshop_submit_command( int argc
, const char *argv
[] )
838 ui_start_modal( "Steam API is not initialized\n", UI_MODAL_BAD
);
842 workshop_form
.page
= k_workshop_form_open
;
843 workshop_form
.view_published_page_count
= 0;
844 workshop_form
.view_published_page_id
= 0;
845 workshop_form
.published_files_list_length
= 0;
846 workshop_form
.ugc_query
.result
= k_EResultNone
;
848 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
850 ISteamUser
*hSteamUser
= SteamAPI_SteamUser();
852 steamid
.m_unAll64Bits
= SteamAPI_ISteamUser_GetSteamID( hSteamUser
);
854 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
855 call
->p_handler
= on_workshop_UGCQueryComplete
;
856 call
->userdata
= NULL
;
857 UGCQueryHandle_t handle
= SteamAPI_ISteamUGC_CreateQueryUserUGCRequest
860 steamid
.m_comp
.m_unAccountID
,
861 k_EUserUGCList_Published
,
862 k_EUGCMatchingUGCType_Items
,
863 k_EUserUGCListSortOrder_CreationOrderDesc
,
864 SKATERIFT_APPID
, SKATERIFT_APPID
,
866 SteamAPI_ISteamUGC_SetReturnMetadata( hSteamUGC
, handle
, 1 );
867 call
->id
= SteamAPI_ISteamUGC_SendQueryUGCRequest( hSteamUGC
, handle
);
871 VG_STATIC
void workshop_init(void)
873 vg_console_reg_cmd( "workshop_submit", workshop_submit_command
, NULL
);
876 VG_STATIC
void workshop_render_world_preview(void){
877 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
879 glClearColor( 0.0f
, 0.0f
, 0.3f
, 1.0f
);
880 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
881 glEnable( GL_DEPTH_TEST
);
882 glDisable( GL_BLEND
);
884 render_world( localplayer
.viewable_world
, &skaterift
.cam
, 1 );
886 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
887 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
891 * Redraw the playermodel into the workshop framebuffer
893 VG_STATIC
void workshop_render_player_preview(void){
894 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
895 glClearColor( 0.16f
, 0.15f
, 0.15f
, 1.0f
);
896 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
897 glEnable( GL_DEPTH_TEST
);
898 glDisable( GL_BLEND
);
900 struct skeleton
*sk
= &localplayer
.playeravatar
->sk
;
903 res
.type
= k_player_pose_type_ik
;
905 struct skeleton_anim
*anim
= skeleton_get_anim( sk
, "idle_cycle+y" );
906 skeleton_sample_anim( sk
, anim
, vg
.time
*0.1f
, res
.keyframes
);
907 q_axis_angle( res
.root_q
, (v3f
){0.0f
,1.0f
,0.0f
}, VG_PIf
);
908 v3_zero( res
.root_co
);
909 res
.root_co
[1] = 200.0f
;
912 q_m3x3( res
.root_q
, transform
);
913 v3_copy( res
.root_co
, transform
[3] );
915 /* TODO: Function. */
916 skeleton_apply_pose( sk
, res
.keyframes
, k_anim_apply_defer_ik
);
917 skeleton_apply_ik_pass( sk
);
918 skeleton_apply_pose( sk
, res
.keyframes
, k_anim_apply_deffered_only
);
919 skeleton_apply_inverses( sk
);
920 skeleton_apply_transform( sk
, transform
);
923 v3_copy( (v3f
){ 0.0f
, 201.7f
, 1.2f
}, cam
.pos
);
928 v3_zero( cam
.angles
);
930 camera_update_transform( &cam
);
931 camera_update_view( &cam
);
932 camera_update_projection( &cam
);
933 camera_finalize( &cam
);
935 world_instance
*world
= localplayer
.viewable_world
;
936 render_playermodel( &cam
, world
, 0, &workshop_form
.player_model
, sk
);
938 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
939 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
943 * Redraw the model file into the workshop framebuffer
945 VG_STATIC
void workshop_render_board_preview(void){
946 if( !workshop_form
.ptr_ent
){
950 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
952 glClearColor( 0.0f
, 0.0f
, 0.3f
, 1.0f
);
953 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
954 glEnable( GL_DEPTH_TEST
);
955 glDisable( GL_BLEND
);
957 ent_swspreview
*swsprev
= workshop_form
.ptr_ent
;
958 world_instance
*world
= workshop_form
.view_world
;
960 ent_camera
*ref
= mdl_arritm( &world
->ent_camera
,
961 mdl_entity_id_id(swsprev
->id_camera
) );
962 ent_marker
*display
= mdl_arritm( &world
->ent_marker
,
963 mdl_entity_id_id(swsprev
->id_display
) ),
964 *display1
= mdl_arritm( &world
->ent_marker
,
965 mdl_entity_id_id(swsprev
->id_display1
) );
968 v3_add( display
->transform
.co
, display1
->transform
.co
, baseco
);
969 v3_muls( baseco
, 0.5f
, baseco
);
973 v3_sub( display
->transform
.co
, ref
->transform
.co
, basevector
);
974 float dist
= v3_length( basevector
);
977 player_vector_angles( baseangles
, basevector
, 1.0f
, 0.0f
);
979 v2_add( workshop_form
.view_angles
, baseangles
, cam
.angles
);
980 cam
.angles
[2] = 0.0f
;
982 float sX
= sinf( cam
.angles
[0] ),
983 cX
= cosf( cam
.angles
[0] ),
984 sY
= sinf( cam
.angles
[1] ),
985 cY
= cosf( cam
.angles
[1] );
987 v3f offset
= { -sX
* cY
, sY
, cX
* cY
};
989 v3_muladds( display
->transform
.co
, offset
,
990 dist
*workshop_form
.view_dist
, cam
.pos
);
992 cam
.pos
[0] += -sX
*workshop_form
.view_offset
[2];
993 cam
.pos
[2] += cX
*workshop_form
.view_offset
[2];
994 cam
.pos
[0] += cX
*workshop_form
.view_offset
[0];
995 cam
.pos
[2] += sX
*workshop_form
.view_offset
[0];
996 cam
.pos
[1] += workshop_form
.view_offset
[1];
1002 camera_update_transform( &cam
);
1003 camera_update_view( &cam
);
1004 camera_update_projection( &cam
);
1005 camera_finalize( &cam
);
1008 mdl_transform_m4x3( &display
->transform
, mmdl
);
1009 mdl_transform_m4x3( &display1
->transform
, mmdl1
);
1011 /* force update this for nice shadows. its usually set in the world
1012 * pre-render step, but that includes timer stuff
1014 struct player_board
*board
= &workshop_form
.board_model
;
1015 struct ub_world_lighting
*ubo
= &world
->ub_lighting
;
1017 v3_copy((v3f
){0.0f
,0.1f
, board
->truck_positions
[0][2]}, vp0
);
1018 v3_copy((v3f
){0.0f
,0.1f
, board
->truck_positions
[1][2]}, vp1
);
1019 m4x3_mulv( mmdl1
, vp0
, ubo
->g_board_0
);
1020 m4x3_mulv( mmdl1
, vp1
, ubo
->g_board_1
);
1021 glBindBuffer( GL_UNIFORM_BUFFER
, world
->ubo_lighting
);
1022 glBufferSubData( GL_UNIFORM_BUFFER
, 0,
1023 sizeof(struct ub_world_lighting
), &world
->ub_lighting
);
1025 render_world( world
, &cam
, 1 );
1026 struct player_board_pose pose
= {0};
1027 render_board( &cam
, world
, board
, mmdl
, &pose
, k_board_shader_entity
);
1028 render_board( &cam
, world
, board
, mmdl1
, &pose
, k_board_shader_entity
);
1030 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
1031 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
1035 * ImGUI section for workshop form
1036 * -----------------------------------------------------------------------------
1039 VG_STATIC
void workshop_changed_model_path( char *buf
, u32 len
){
1040 workshop_form
.submission
.submit_file_and_image
= 1;
1043 VG_STATIC
void workshop_changed_title( char *buf
, u32 len
){
1044 workshop_form
.submission
.submit_title
= 1;
1047 VG_STATIC
void workshop_changed_description( char *buf
, u32 len
){
1048 workshop_form
.submission
.submit_description
= 1;
1051 VG_STATIC
void workshop_form_gui_page_undecided( ui_rect content
){
1053 rect_copy( content
, box
);
1055 box
[2] = (box
[2]*2)/3;
1056 ui_rect_center( content
, box
);
1059 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1060 ui_text( row
, "Select the type of item\n", 1, k_ui_align_middle_center
,0);
1061 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1062 ui_enum( row
, "Type:", workshop_form_type_opts
,
1063 4, &workshop_form
.submission
.submission_type_selection
);
1064 ui_split( box
, k_ui_axis_h
, 8, 0, row
, box
);
1065 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1067 ui_rect button_l
, button_r
;
1068 rect_copy( row
, button_l
);
1069 button_l
[2] = 128*2;
1070 ui_rect_center( row
, button_l
);
1071 ui_split_ratio( button_l
, k_ui_axis_v
, 0.5f
, 2, button_l
, button_r
);
1073 if( workshop_form
.submission
.submission_type_selection
.value
!=
1074 k_addon_type_none
){
1075 if( ui_button_text( button_l
, "OK", 1 ) ){
1076 enum addon_type type
=
1077 workshop_form
.submission
.submission_type_selection
.value
;
1078 workshop_form
.submission
.type
= type
;
1080 if( type
== k_addon_type_world
){
1081 workshop_form
.view_changed
= 1;
1082 workshop_form
.file_intent
= k_workshop_form_file_intent_new
;
1087 ui_fill( button_l
, ui_colour(k_ui_bg
) );
1088 ui_text( button_l
, "OK", 1, k_ui_align_middle_center
,
1089 ui_colour(k_ui_bg
+4) );
1092 if( ui_button_text( button_r
, "Cancel", 1 ) ){
1093 workshop_form
.page
= k_workshop_form_open
;
1094 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1098 VG_STATIC
void workshop_form_gui_draw_preview( ui_rect img_box
){
1099 enum addon_type type
= workshop_form
.submission
.type
;
1100 if( workshop_form
.file_intent
== k_workshop_form_file_intent_keep_old
){
1101 ui_image( img_box
, gpipeline
.fb_workshop_preview
->attachments
[0].id
);
1103 else if( workshop_form
.file_intent
== k_workshop_form_file_intent_new
){
1104 ui_image( img_box
, gpipeline
.fb_workshop_preview
->attachments
[0].id
);
1106 if( type
== k_addon_type_world
){
1110 int hover
= ui_inside_rect( img_box
, vg_ui
.mouse
),
1111 target
= ui_inside_rect( img_box
, vg_ui
.mouse_click
);
1113 if( ui_click_down(UI_MOUSE_MIDDLE
) && target
){
1114 v3_copy( workshop_form
.view_offset
,
1115 workshop_form
.view_offset_begin
);
1117 else if( ui_click_down(UI_MOUSE_LEFT
) && target
){
1118 v2_copy( workshop_form
.view_angles
,
1119 workshop_form
.view_angles_begin
);
1122 if( ui_clicking(UI_MOUSE_MIDDLE
) && target
){
1123 v2f delta
= { vg_ui
.mouse
[0]-vg_ui
.mouse_click
[0],
1124 vg_ui
.mouse
[1]-vg_ui
.mouse_click
[1] };
1126 float *begin
= workshop_form
.view_offset_begin
,
1127 *offset
= workshop_form
.view_offset
;
1128 offset
[0] = vg_clampf( begin
[0]-delta
[0]*0.002f
, -1.0f
, 1.0f
);
1129 offset
[2] = vg_clampf( begin
[2]-delta
[1]*0.002f
, -1.0f
, 1.0f
);
1130 workshop_form
.view_changed
= 1;
1132 else if( ui_clicking(UI_MOUSE_LEFT
) && target
){
1133 v2f delta
= { vg_ui
.mouse
[0]-vg_ui
.mouse_click
[0],
1134 vg_ui
.mouse
[1]-vg_ui
.mouse_click
[1] };
1137 v2_muladds( workshop_form
.view_angles_begin
, delta
, 0.002f
, angles
);
1139 float limit
= VG_PIf
*0.2f
;
1141 angles
[0] = vg_clampf( angles
[0], -limit
, limit
);
1142 angles
[1] = vg_clampf( angles
[1], -limit
, limit
);
1144 v2_copy( angles
, workshop_form
.view_angles
);
1145 workshop_form
.view_changed
= 1;
1148 if( !ui_clicking(UI_MOUSE_LEFT
) && hover
){
1149 float zoom
= workshop_form
.view_dist
;
1150 zoom
+= vg
.mouse_wheel
[1] * -0.07f
;
1151 zoom
= vg_clampf( zoom
, 0.4f
, 2.0f
);
1153 if( zoom
!= workshop_form
.view_dist
){
1154 workshop_form
.view_changed
= 1;
1155 workshop_form
.view_dist
= zoom
;
1160 ui_text( img_box
, "No image", 1, k_ui_align_middle_center
,
1161 ui_colour( k_ui_orange
) );
1165 VG_STATIC
void workshop_form_gui_edit_page( ui_rect content
){
1166 enum addon_type type
= workshop_form
.submission
.type
;
1168 if( type
== k_addon_type_none
){
1169 workshop_form_gui_page_undecided( content
);
1173 ui_rect image_plane
;
1174 ui_split( content
, k_ui_axis_h
, 300, 0, image_plane
, content
);
1175 ui_fill( image_plane
, ui_colour( k_ui_bg
+0 ) );
1178 ui_fit_item( image_plane
, (ui_px
[2]){ 3, 2 }, img_box
);
1179 workshop_form_gui_draw_preview( img_box
);
1182 ui_rect null
, file_entry
, file_button
, file_label
;
1183 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1184 ui_split( content
, k_ui_axis_h
, 28, 0, file_entry
, content
);
1187 snprintf( buf
, 128, "Addon folder: skaterift/%s",
1188 workshop_filetype_folder() );
1190 ui_label( file_entry
, buf
, 1, 8, file_entry
);
1192 if( type
== k_addon_type_world
){
1193 struct ui_textbox_callbacks callbacks
= {
1194 .change
= workshop_changed_model_path
1196 ui_textbox( file_entry
, workshop_form
.addon_folder
,
1197 vg_list_size(workshop_form
.addon_folder
), 0, &callbacks
);
1200 ui_split( file_entry
, k_ui_axis_v
, -128, 0, file_entry
, file_button
);
1201 if( workshop_form
.file_intent
!= k_workshop_form_file_intent_none
){
1202 ui_text( file_entry
, workshop_form
.addon_folder
, 1,
1203 k_ui_align_middle_left
, ui_colour( k_ui_fg
+4 ) );
1205 if( ui_button_text( file_button
, "Remove", 1 ) ){
1206 if( type
== k_addon_type_board
)
1207 player_board_unload( &workshop_form
.board_model
);
1208 else if( type
== k_addon_type_player
)
1209 player_model_unload( &workshop_form
.player_model
);
1211 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1212 workshop_form
.addon_folder
[0] = '\0';
1216 struct ui_textbox_callbacks callbacks
= {
1217 .change
= workshop_changed_model_path
1220 ui_textbox( file_entry
, workshop_form
.addon_folder
,
1221 vg_list_size(workshop_form
.addon_folder
), 0, &callbacks
);
1223 if( ui_button_text( file_button
, "Load", 1 ) ){
1224 workshop_op_load_model();
1229 ui_rect title_entry
, label
;
1230 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1231 ui_split( content
, k_ui_axis_h
, 28, 0, title_entry
, content
);
1233 const char *str_title
= "Title:", *str_desc
= "Description:";
1234 ui_split( title_entry
, k_ui_axis_v
,
1235 ui_text_line_width(str_title
)+8, 0, label
, title_entry
);
1237 ui_rect vis_dropdown
;
1238 ui_split_ratio( title_entry
, k_ui_axis_v
, 0.6f
, 16,
1239 title_entry
, vis_dropdown
);
1243 struct ui_textbox_callbacks callbacks
= {
1244 .change
= workshop_changed_title
1246 ui_text( label
, str_title
, 1, k_ui_align_middle_left
, 0 );
1247 ui_textbox( title_entry
, workshop_form
.submission
.title
,
1248 vg_list_size(workshop_form
.submission
.title
), 0, &callbacks
);
1251 /* visibility option */
1253 ui_enum( vis_dropdown
, "Visibility:", workshop_form_visibility_opts
,
1254 4, &workshop_form
.submission
.visibility
);
1257 /* description box */
1259 struct ui_textbox_callbacks callbacks
= {
1260 .change
= workshop_changed_description
1263 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1264 ui_split( content
, k_ui_axis_h
, 28, 0, label
, content
);
1265 ui_split( content
, k_ui_axis_h
, 28*4, 0, desc_entry
, content
);
1266 ui_text( label
, str_desc
, 1, k_ui_align_middle_left
, 0 );
1267 ui_textbox( desc_entry
, workshop_form
.submission
.description
,
1268 vg_list_size(workshop_form
.submission
.description
),
1269 UI_TEXTBOX_MULTILINE
|UI_TEXTBOX_WRAP
, &callbacks
);
1272 /* submissionable */
1273 ui_rect submission_row
;
1274 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1275 ui_split( content
, k_ui_axis_h
, content
[3]-32-8, 0, content
,
1278 ui_rect submission_center
;
1279 rect_copy( submission_row
, submission_center
);
1280 submission_center
[2] = 256;
1281 ui_rect_center( submission_row
, submission_center
);
1283 ui_rect btn_left
, btn_right
;
1284 ui_split_ratio( submission_center
, k_ui_axis_v
, 0.5f
, 8,
1285 btn_left
, btn_right
);
1287 if( ui_button_text( btn_left
, "Publish", 1 ) ){
1288 workshop_op_submit();
1290 if( ui_button_text( btn_right
, "Cancel", 1 ) ){
1291 workshop_form
.page
= k_workshop_form_open
;
1292 player_board_unload( &workshop_form
.board_model
);
1293 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1297 const char *disclaimer_text
=
1298 "By submitting this item, you agree to the workshop terms of service";
1300 ui_rect disclaimer_row
, inner
, link
;
1301 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1302 ui_split( content
, k_ui_axis_h
, content
[3]-32, 0, content
,
1305 ui_px btn_width
= 32;
1307 rect_copy( disclaimer_row
, inner
);
1308 inner
[2] = ui_text_line_width( disclaimer_text
) + btn_width
+8;
1310 ui_rect_center( disclaimer_row
, inner
);
1311 ui_split( inner
, k_ui_axis_v
, inner
[2]-btn_width
, 0, label
, btn_right
);
1312 ui_rect_pad( btn_right
, (ui_px
[2]){2,2} );
1314 if( ui_button_text( btn_right
, "\xbf", 2 ) ){
1315 ISteamFriends
*hSteamFriends
= SteamAPI_SteamFriends();
1316 SteamAPI_ISteamFriends_ActivateGameOverlayToWebPage( hSteamFriends
,
1317 "https://steamcommunity.com/sharedfiles/workshoplegalagreement",
1318 k_EActivateGameOverlayToWebPageMode_Default
);
1321 ui_text( label
, disclaimer_text
, 1, k_ui_align_middle_left
,
1322 ui_colour( k_ui_fg
+4 ) );
1325 VG_STATIC
void workshop_form_gui_sidebar( ui_rect sidebar
)
1327 ui_fill( sidebar
, ui_colour( k_ui_bg
+2 ) );
1330 ui_split( sidebar
, k_ui_axis_h
, 28, 0, title
, sidebar
);
1332 if( workshop_form
.page
== k_workshop_form_edit
){
1333 ui_text( title
, "Editing", 1, k_ui_align_middle_center
, 0 );
1334 ui_split( sidebar
, k_ui_axis_h
, 28, 0, title
, sidebar
);
1336 if( workshop_form
.submission
.type
!= k_addon_type_none
){
1339 vg_strnull( &str
, buf
, 512 );
1341 if( workshop_form
.submission
.file_id
)
1342 vg_strcat( &str
, "Editing an existing " );
1344 vg_strcat( &str
, "Creating a new " );
1346 if( workshop_form
.submission
.type
== k_addon_type_board
)
1347 vg_strcat( &str
, "skateboard." );
1348 else if( workshop_form
.submission
.type
== k_addon_type_world
)
1349 vg_strcat( &str
, "world." );
1350 else if( workshop_form
.submission
.type
== k_addon_type_player
)
1351 vg_strcat( &str
, "playermodel." );
1353 vg_strcat( &str
, "???." );
1355 ui_text( title
, buf
, 1, k_ui_align_middle_center
,
1356 ui_colour(k_ui_fg
+4) );
1362 * sidebar existing entries panel
1364 ui_text( title
, "Your submissions", 1, k_ui_align_middle_center
, 0 );
1366 ui_rect controls
, btn_create_new
;
1367 ui_split( sidebar
, k_ui_axis_h
, 32, 0, controls
, sidebar
);
1368 ui_split( sidebar
, k_ui_axis_h
, -32, 0, sidebar
, btn_create_new
);
1369 ui_fill( controls
, ui_colour( k_ui_bg
+1 ) );
1372 strcpy( buf
, "page " );
1374 i
+= highscore_intl( buf
+i
, workshop_form
.view_published_page_id
+1, 4 );
1376 i
+= highscore_intl( buf
+i
, workshop_form
.view_published_page_count
, 4 );
1379 ui_rect_pad( controls
, (ui_px
[2]){0,4} );
1381 ui_split_ratio( controls
, k_ui_axis_v
, 0.25f
, 0, info
, controls
);
1382 ui_text( info
, buf
, 1, k_ui_align_middle_center
, 0 );
1384 ui_rect btn_left
, btn_right
;
1385 ui_split_ratio( controls
, k_ui_axis_v
, 0.5f
, 2, btn_left
, btn_right
);
1387 if( ui_button_text( btn_left
, "newer", 1 ) ){
1388 workshop_view_page( workshop_form
.view_published_page_id
-1 );
1391 if( ui_button_text( btn_right
, "older", 1 ) ){
1392 workshop_view_page( workshop_form
.view_published_page_count
+1 );
1395 if( ui_button_text( btn_create_new
, "Create New Item", 1 ) ){
1396 workshop_reset_submission_data();
1397 workshop_form
.submission
.submit_title
= 1;
1398 workshop_form
.submission
.submit_description
= 1;
1399 workshop_form
.submission
.submit_file_and_image
= 1;
1400 workshop_form
.page
= k_workshop_form_edit
;
1403 for( int i
=0; i
<workshop_form
.published_files_list_length
; i
++ ){
1405 ui_split( sidebar
, k_ui_axis_h
, 28, 0, item
, sidebar
);
1406 ui_rect_pad( item
, (ui_px
[2]){4,4} );
1408 struct published_file
*pfile
= &workshop_form
.published_files_list
[i
];
1409 if( ui_button_text( item
, pfile
->title
, 1 ) ){
1410 if( pfile
->result
== k_EResultOK
){
1411 vg_info( "Select index: %d\n", pfile
->result_index
);
1412 workshop_op_download_and_view_submission( pfile
->result_index
);
1415 vg_warn( "Cannot select that item, result not OK\n" );
1421 VG_STATIC
void workshop_form_gui(void)
1423 enum workshop_form_page stable_page
= workshop_form
.page
;
1424 if( stable_page
== k_workshop_form_hidden
) return;
1427 ui_rect screen
= { 0, 0, vg
.window_x
, vg
.window_y
};
1428 ui_rect window
= { 0, 0, 1000, 700 };
1429 ui_rect_center( screen
, window
);
1430 vg_ui
.wants_mouse
= 1;
1432 ui_fill( window
, ui_colour( k_ui_bg
+1 ) );
1433 ui_outline( window
, 1, ui_colour( k_ui_bg
+7 ) );
1435 ui_rect title
, panel
;
1436 ui_split( window
, k_ui_axis_h
, 28, 0, title
, panel
);
1437 ui_fill( title
, ui_colour( k_ui_bg
+7 ) );
1438 ui_text( title
, "Workshop tool", 1, k_ui_align_middle_center
,
1439 ui_colourcont(k_ui_bg
+7) );
1441 ui_rect quit_button
;
1442 ui_split( title
, k_ui_axis_v
, title
[2]-title
[3], 2, title
, quit_button
);
1444 if( vg_loader_availible() ){
1445 if( ui_button_text( quit_button
, "X", 1 ) ){
1446 workshop_quit_form();
1452 * temporary operation blinders, we don't yet have a nice way to show the
1453 * user that we're doing something uninterruptable, so the code just
1454 * escapes here and we show them a basic string
1457 if( workshop_form
.op
!= k_workshop_op_none
){
1458 const char *op_string
= "The programmer has not bothered to describe "
1459 "the current operation that is running.";
1461 switch( workshop_form
.op
){
1462 case k_workshop_op_loading_model
:
1463 op_string
= "Operation in progress: Loading model file.";
1465 case k_workshop_op_publishing_update
:
1466 op_string
= "Operation in progress: publishing submission update "
1469 case k_workshop_op_downloading_submission
:
1470 op_string
= "Operation in progress: downloading existing submission"
1471 " from Steam services.";
1476 ui_text( panel
, op_string
, 1, k_ui_align_middle_center
, 0 );
1480 /* re draw board preview if need to */
1481 if( (stable_page
== k_workshop_form_edit
) &&
1482 workshop_form
.view_changed
&&
1483 workshop_form
.file_intent
== k_workshop_form_file_intent_new
)
1485 enum addon_type type
= workshop_form
.submission
.type
;
1486 if( type
== k_addon_type_board
){
1487 workshop_render_board_preview();
1489 else if( type
== k_addon_type_world
){
1490 vg_success( "Renders world preview\n" );
1491 workshop_render_world_preview();
1493 else if( type
== k_addon_type_player
){
1494 workshop_render_player_preview();
1497 workshop_form
.view_changed
= 0;
1500 struct workshop_form
*form
= &workshop_form
;
1502 ui_rect sidebar
, content
;
1503 ui_split_ratio( panel
, k_ui_axis_v
, 0.3f
, 1, sidebar
, content
);
1506 ui_rect_pad( content
, (ui_px
[2]){8,8} );
1508 if( stable_page
== k_workshop_form_edit
){
1509 workshop_form_gui_edit_page( content
);
1511 else if( stable_page
== k_workshop_form_open
){
1512 ui_text( content
, "Nothing selected.", 1, k_ui_align_middle_center
,
1513 ui_colour( k_ui_fg
+4 ) );
1515 else if( stable_page
>= k_workshop_form_cclosing
){
1516 ui_rect submission_row
;
1517 ui_split( content
, k_ui_axis_h
, content
[3]-32-8, 0, content
,
1522 if( stable_page
== k_workshop_form_closing_bad
)
1523 colour
= ui_colour( k_ui_red
+k_ui_brighter
);
1525 colour
= ui_colour( k_ui_green
+k_ui_brighter
);
1527 ui_text( content
, workshop_form
.failure_or_success_string
, 1,
1528 k_ui_align_middle_center
, colour
);
1530 ui_rect submission_center
;
1531 rect_copy( submission_row
, submission_center
);
1532 submission_center
[2] = 128;
1533 ui_rect_center( submission_row
, submission_center
);
1534 ui_rect_pad( submission_center
, (ui_px
[2]){8,8} );
1536 if( ui_button_text( submission_center
, "OK", 1 ) ){
1537 workshop_form
.page
= k_workshop_form_open
;
1541 workshop_form_gui_sidebar( sidebar
);
1545 * Some async api stuff
1546 * -----------------------------------------------------------------------------
1549 VG_STATIC
void async_workshop_get_filepath( void *data
, u32 len
)
1551 struct async_workshop_filepath_info
*info
= data
;
1556 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
1557 if( !SteamAPI_ISteamUGC_GetItemInstallInfo( hSteamUGC
, info
->id
, &_size
,
1558 info
->buf
, info
->len
, &_ts
))
1560 vg_error( "GetItemInstallInfo failed\n" );
1561 info
->buf
[0] = '\0';
1565 VG_STATIC
void async_workshop_get_installed_files( void *data
, u32 len
)
1567 struct async_workshop_installed_files_info
*info
= data
;
1569 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
1570 u32 count
= SteamAPI_ISteamUGC_GetSubscribedItems( hSteamUGC
, info
->buffer
,
1573 vg_info( "Found %u subscribed items\n", count
);
1576 for( u32 i
=0; i
<count
; i
++ ){
1577 u32 state
= SteamAPI_ISteamUGC_GetItemState( hSteamUGC
, info
->buffer
[i
] );
1578 if( state
& k_EItemStateInstalled
){
1579 info
->buffer
[j
++] = info
->buffer
[i
];
1586 #endif /* WORKSHOP_C */