5 #include "vg/vg_binstr.h"
6 #include "vg/vg_loader.h"
7 #include "ent_skateshop.h"
9 #include "vg/vg_steam_auth.h"
10 #include "vg/vg_steam_ugc.h"
11 #include "vg/vg_steam_friends.h"
14 static struct ui_enum_opt workshop_form_visibility_opts
[] = {
15 { k_ERemoteStoragePublishedFileVisibilityPublic
, "Public" },
16 { k_ERemoteStoragePublishedFileVisibilityUnlisted
, "Unlisted" },
17 { k_ERemoteStoragePublishedFileVisibilityFriendsOnly
, "Friends Only" },
18 { k_ERemoteStoragePublishedFileVisibilityPrivate
, "Private" },
21 static struct ui_enum_opt workshop_form_type_opts
[] = {
22 { k_addon_type_none
, "None" },
23 { k_addon_type_board
, "Board" },
24 { k_addon_type_world
, "World" },
25 { k_addon_type_player
, "Player" },
29 * Close the form and discard UGC query result
31 static void workshop_quit_form(void){
32 player_board_unload( &workshop_form
.board_model
);
33 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
35 if( workshop_form
.ugc_query
.result
== k_EResultOK
){
36 workshop_form
.ugc_query
.result
= k_EResultNone
;
38 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
39 SteamAPI_ISteamUGC_ReleaseQueryUGCRequest(
40 hSteamUGC
, workshop_form
.ugc_query
.handle
);
43 workshop_form
.page
= k_workshop_form_hidden
;
44 workshop_form
.op
= k_workshop_op_none
;
48 * Delete all information about the submission
50 static void workshop_reset_submission_data(void)
52 workshop_form
.submission
.file_id
= 0; /* assuming id of 0 is none/invalid */
53 workshop_form
.submission
.description
[0] = '\0';
54 workshop_form
.submission
.title
[0] = '\0';
55 workshop_form
.submission
.author
[0] = '\0';
56 workshop_form
.submission
.submission_type_selection
=
58 workshop_form
.submission
.type
= k_addon_type_none
;
60 workshop_form
.submission
.visibility
=
61 k_ERemoteStoragePublishedFileVisibilityPublic
;
63 workshop_form
.addon_folder
[0] = '\0';
64 player_board_unload( &workshop_form
.board_model
);
65 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
70 * Mostly copies of what it sais on the Steam API documentation
72 static const char *workshop_EResult_user_string( EResult result
)
75 case k_EResultInsufficientPrivilege
:
76 return "Your account is currently restricted from uploading content "
77 "due to a hub ban, account lock, or community ban. You need to "
78 "contact Steam Support to resolve the issue.";
80 return "You do not have permission to upload content to this hub "
81 "because you have an active VAC or Game ban.";
82 case k_EResultTimeout
:
83 return "The operation took longer than expected, so it was discarded. "
85 case k_EResultNotLoggedOn
:
86 return "You are currently not logged into Steam.";
87 case k_EResultServiceUnavailable
:
88 return "The workshop server is having issues or is unavailable, "
90 case k_EResultInvalidParam
:
91 return "One of the submission fields contains something not being "
92 "accepted by that field.";
93 case k_EResultAccessDenied
:
94 return "There was a problem trying to save the title and description. "
96 case k_EResultLimitExceeded
:
97 return "You have exceeded your Steam Cloud quota. If you wish to "
98 "upload this file, you must remove some published items.";
99 case k_EResultFileNotFound
:
100 return "The uploaded file could not be found.";
101 case k_EResultDuplicateRequest
:
102 return "The file was already successfully uploaded.";
103 case k_EResultDuplicateName
:
104 return "You already have a Steam Workshop item with that name.";
105 case k_EResultServiceReadOnly
:
106 return "Due to a recent password or email change, you are not allowed "
107 "to upload new content. Usually this restriction will expire in"
108 " 5 days, but can last up to 30 days if the account has been "
109 "inactive recently.";
111 return "Operation failed for an error which has not been accounted for "
112 "by the programmer. Try again, sorry :)";
117 * op: k_workshop_form_op_publishing_update
118 * ----------------------------------------------------------------------------
122 * The endpoint of this operation
124 static void on_workshop_update_result( void *data
, void *user
)
126 vg_info( "Recieved workshop update result\n" );
127 SubmitItemUpdateResult_t
*result
= data
;
129 /* this seems to be set here, but my account definitely has accepted it */
130 if( result
->m_bUserNeedsToAcceptWorkshopLegalAgreement
){
131 vg_warn( "Workshop agreement currently not accepted\n" );
134 if( result
->m_eResult
== k_EResultOK
){
135 workshop_form
.page
= k_workshop_form_closing_good
;
136 workshop_form
.failure_or_success_string
= "Uploaded workshop file!";
137 vg_success( "file uploaded\n" );
140 workshop_form
.page
= k_workshop_form_closing_bad
;
141 workshop_form
.failure_or_success_string
=
142 workshop_EResult_user_string( result
->m_eResult
);
144 vg_error( "Error with the submitted file (%d)\n", result
->m_eResult
);
146 workshop_form
.op
= k_workshop_op_none
;
149 static const char *workshop_filetype_folder(void){
150 enum addon_type type
= workshop_form
.submission
.type
;
151 if ( type
== k_addon_type_board
) return "boards/";
152 else if( type
== k_addon_type_player
) return "playermodels/";
153 else if( type
== k_addon_type_world
) return "maps/";
155 return "unknown_addon_type/";
159 * reciever on completion of packaging the files, it will then start the item
160 * update with Steam API
162 static void workshop_form_upload_submission( PublishedFileId_t file_id
,
165 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
166 UGCUpdateHandle_t handle
167 = SteamAPI_ISteamUGC_StartItemUpdate( hSteamUGC
, SKATERIFT_APPID
,
170 /* TODO: Handle failure cases for these */
172 SteamAPI_ISteamUGC_SetItemMetadata( hSteamUGC
, handle
, metadata
);
174 if( workshop_form
.submission
.submit_title
){
175 vg_info( "Setting title\n" );
176 SteamAPI_ISteamUGC_SetItemTitle( hSteamUGC
, handle
,
177 workshop_form
.submission
.title
);
180 if( workshop_form
.submission
.submit_description
){
181 vg_info( "Setting description\n" );
182 SteamAPI_ISteamUGC_SetItemDescription( hSteamUGC
, handle
,
183 workshop_form
.submission
.description
);
186 if( workshop_form
.submission
.submit_file_and_image
){
189 vg_strnull( &folder
, path_buf
, 4096 );
190 vg_strcat( &folder
, vg
.base_path
);
192 vg_strcat( &folder
, workshop_filetype_folder() );
193 vg_strcat( &folder
, workshop_form
.addon_folder
);
195 vg_info( "Setting item content\n" );
196 SteamAPI_ISteamUGC_SetItemContent( hSteamUGC
, handle
, folder
.buffer
);
198 vg_str preview
= folder
;
199 vg_strcat( &preview
, "/preview.jpg" );
201 vg_info( "Setting preview image\n" );
202 SteamAPI_ISteamUGC_SetItemPreview( hSteamUGC
, handle
, preview
.buffer
);
205 vg_info( "Setting visibility\n" );
206 SteamAPI_ISteamUGC_SetItemVisibility( hSteamUGC
, handle
,
207 workshop_form
.submission
.visibility
);
209 vg_info( "Submitting updates\n" );
210 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
211 call
->userdata
= NULL
;
212 call
->p_handler
= on_workshop_update_result
;
213 call
->id
= SteamAPI_ISteamUGC_SubmitItemUpdate( hSteamUGC
, handle
, "" );
217 * Steam API call result for when we've created a new item on their network, or
218 * not, if it has failed
220 static void on_workshop_createitem( void *data
, void *user
)
222 CreateItemResult_t
*result
= data
;
224 if( result
->m_eResult
== k_EResultOK
){
225 vg_info( "Created workshop file with id: %lu\n",
226 result
->m_nPublishedFileId
);
228 if( result
->m_bUserNeedsToAcceptWorkshopLegalAgreement
){
229 vg_warn( "Workshop agreement currently not accepted\n" );
232 workshop_form_upload_submission( result
->m_nPublishedFileId
, user
);
235 const char *errstr
= workshop_EResult_user_string( result
->m_eResult
);
238 vg_error( "ISteamUGC_CreateItem() failed(%d): '%s' \n",
239 result
->m_eResult
, errstr
);
242 workshop_form
.page
= k_workshop_form_closing_bad
;
243 workshop_form
.failure_or_success_string
= errstr
;
248 * Starts the workshop upload process through Steam API
250 static void workshop_form_async_submit_begin( void *payload
, u32 size
)
253 /* use existing file */
254 if( workshop_form
.submission
.file_id
){
255 workshop_form_upload_submission( workshop_form
.submission
.file_id
,
259 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
260 call
->userdata
= payload
;
261 call
->p_handler
= on_workshop_createitem
;
262 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
263 call
->id
= SteamAPI_ISteamUGC_CreateItem( hSteamUGC
, SKATERIFT_APPID
,
264 k_EWorkshopFileTypeCommunity
);
269 * Downloads the framebuffer into scratch memory
271 static void workshop_form_async_download_image( void *payload
, u32 size
)
274 render_fb_get_current_res( gpipeline
.fb_workshop_preview
, &w
, &h
);
275 vg_linear_clear( vg_mem
.scratch
);
276 workshop_form
.img_buffer
= vg_linear_alloc( vg_mem
.scratch
, w
*h
*3 );
278 vg_info( "read framebuffer: glReadPixels( %dx%d )\n", w
,h
);
280 glBindFramebuffer( GL_READ_FRAMEBUFFER
, gpipeline
.fb_workshop_preview
->fb
);
281 glReadBuffer( GL_COLOR_ATTACHMENT0
);
282 glReadPixels( 0,0, w
,h
, GL_RGB
, GL_UNSIGNED_BYTE
, workshop_form
.img_buffer
);
284 workshop_form
.img_w
= w
;
285 workshop_form
.img_h
= h
;
289 * Thread which kicks off the upload process
291 static void _workshop_form_submit_thread( void *data
)
293 vg_async_call( workshop_form_async_download_image
, NULL
, 0 );
298 vg_strnull( &folder
, path_buf
, 4096 );
300 vg_strcat( &folder
, workshop_filetype_folder() );
301 vg_strcat( &folder
, workshop_form
.addon_folder
);
303 if( !vg_strgood(&folder
) ){
304 vg_error( "addon folder path too long\n" );
305 workshop_form
.op
= k_workshop_op_none
;
310 * Create the metadata file
311 * -----------------------------------------------------------------------*/
312 u8 descriptor_buf
[ 512 ];
314 vg_msg_init( &descriptor
, descriptor_buf
, sizeof(descriptor_buf
) );
315 vg_linear_clear( vg_mem
.scratch
);
317 /* short description */
318 vg_msg_frame( &descriptor
, "workshop" );
319 vg_msg_wkvstr( &descriptor
, "title", workshop_form
.submission
.title
);
320 //vg_msg_wkvstr( &descriptor, "author", "unknown" );
321 vg_msg_wkvnum( &descriptor
, "type", k_vg_msg_u32
, 1,
322 &workshop_form
.submission
.type
);
323 vg_msg_wkvstr( &descriptor
, "folder", workshop_form
.addon_folder
);
324 vg_msg_end_frame( &descriptor
);
325 //vg_msg_wkvstr( &descriptor, "location", "USA" );
327 char *short_descriptor_str
=
328 vg_linear_alloc( vg_mem
.scratch
, vg_align8(descriptor
.cur
.co
*2+1));
329 vg_bin_str( descriptor_buf
, short_descriptor_str
, descriptor
.cur
.co
);
330 short_descriptor_str
[descriptor
.cur
.co
*2] = '\0';
331 vg_info( "binstr: %s\n", short_descriptor_str
);
334 if( !vg_dir_open( &dir
, folder
.buffer
) ){
335 vg_error( "could not open addon folder '%s'\n", folder
.buffer
);
336 workshop_form
.op
= k_workshop_op_none
;
340 while( vg_dir_next_entry(&dir
) ){
341 if( vg_dir_entry_type(&dir
) == k_vg_entry_type_file
){
342 const char *d_name
= vg_dir_entry_name(&dir
);
343 if( d_name
[0] == '.' ) continue;
345 vg_str file
= folder
;
346 vg_strcat( &file
, "/" );
347 vg_strcat( &file
, d_name
);
348 if( !vg_strgood( &file
) ) continue;
350 char *ext
= vg_strch( &file
, '.' );
352 if( strcmp(ext
,".mdl") ) continue;
354 vg_msg_wkvstr( &descriptor
, "content", d_name
);
360 vg_str descriptor_file
= folder
;
361 vg_strcat( &descriptor_file
, "/addon.inf" );
362 if( !vg_strgood(&descriptor_file
) ){
363 vg_error( "Addon info path too long\n" );
364 workshop_form
.op
= k_workshop_op_none
;
368 FILE *fp
= fopen( descriptor_file
.buffer
, "wb" );
370 vg_error( "Could not open addon info file '%s'\n",
371 descriptor_file
.buffer
);
372 workshop_form
.op
= k_workshop_op_none
;
375 fwrite( descriptor_buf
, descriptor
.cur
.co
, 1, fp
);
379 * -----------------------------------------------------------------------*/
380 vg_str preview
= folder
;
381 vg_strcat( &preview
, "/preview.jpg" );
383 if( !vg_strgood(&preview
) ){
384 vg_error( "preview image path too long\n" );
385 workshop_form
.op
= k_workshop_op_none
;
389 int w
= workshop_form
.img_w
,
390 h
= workshop_form
.img_h
;
392 vg_info( "writing: %s (%dx%d @90%%)\n", preview
.buffer
, w
,h
);
393 stbi_flip_vertically_on_write(1);
394 stbi_write_jpg( preview
.buffer
, w
,h
, 3, workshop_form
.img_buffer
, 90 );
396 vg_async_call( workshop_form_async_submit_begin
, short_descriptor_str
, 0 );
400 * Entry point for the publishing submission operation
402 static void workshop_op_submit(void){
403 /* TODO: Show these errors to the user */
404 if( workshop_form
.submission
.submit_title
){
405 if( !workshop_form
.submission
.title
[0] ){
406 ui_start_modal( "Cannot submit because a title is required\n",
408 workshop_form
.op
= k_workshop_op_none
;
413 if( workshop_form
.submission
.submit_description
){
414 if( !workshop_form
.submission
.description
[0] ){
415 ui_start_modal( "Cannot submit because a description is required\n",
417 workshop_form
.op
= k_workshop_op_none
;
422 if( workshop_form
.submission
.submit_file_and_image
){
423 if( workshop_form
.file_intent
== k_workshop_form_file_intent_none
){
424 ui_start_modal( "Cannot submit because the file is "
425 "empty or unspecified\n", UI_MODAL_WARN
);
426 workshop_form
.op
= k_workshop_op_none
;
431 player_board_unload( &workshop_form
.board_model
);
432 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
433 workshop_form
.op
= k_workshop_op_publishing_update
;
435 vg_loader_start( _workshop_form_submit_thread
, NULL
);
439 * op: k_workshop_form_op_loading_model
440 * -----------------------------------------------------------------------------
444 * Reciever for completion of the model file load
446 static void workshop_form_loadmodel_async_complete( void *payload
, u32 size
)
448 v2_zero( workshop_form
.view_angles
);
449 v3_zero( workshop_form
.view_offset
);
450 workshop_form
.view_dist
= 1.0f
;
451 workshop_form
.view_changed
= 1;
452 workshop_form
.file_intent
= k_workshop_form_file_intent_new
;
454 vg_success( "workshop async load complete\n" );
455 workshop_form
.op
= k_workshop_op_none
;
459 * Reciever for failure to load
461 static void workshop_form_loadmodel_async_error( void *payload
, u32 size
){
465 * Thread which loads the model from the disk
467 static void _workshop_form_load_thread( void *data
)
471 vg_strnull( &folder
, path_buf
, 4096 );
473 vg_strcat( &folder
, workshop_filetype_folder() );
474 vg_strcat( &folder
, workshop_form
.addon_folder
);
476 if( !vg_strgood(&folder
) ){
477 vg_error( "workshop async load failed: path too long\n" );
478 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
479 workshop_form
.op
= k_workshop_op_none
;
484 if( !vg_dir_open( &dir
, folder
.buffer
) ){
485 vg_error( "workshop async load failed: could not open folder\n" );
486 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
487 workshop_form
.op
= k_workshop_op_none
;
491 vg_info( "Searching %s for model files\n", folder
.buffer
);
494 while( vg_dir_next_entry(&dir
) ){
495 if( vg_dir_entry_type(&dir
) == k_vg_entry_type_file
){
496 const char *d_name
= vg_dir_entry_name(&dir
);
497 if( d_name
[0] == '.' ) continue;
499 vg_str file
= folder
;
500 vg_strcat( &file
, "/" );
501 vg_strcat( &file
, d_name
);
502 if( !vg_strgood( &file
) ) continue;
504 char *ext
= vg_strch( &file
, '.' );
506 if( strcmp(ext
,".mdl") ) continue;
514 vg_error( "workshop async load failed: no model files found\n" );
515 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
516 workshop_form
.op
= k_workshop_op_none
;
520 if( workshop_form
.submission
.type
== k_addon_type_board
)
521 player_board_load( &workshop_form
.board_model
, path_buf
);
522 else if( workshop_form
.submission
.type
== k_addon_type_player
)
523 player_model_load( &workshop_form
.player_model
, path_buf
);
525 vg_async_call( workshop_form_loadmodel_async_complete
, NULL
, 0 );
529 * Entry point for load model operation
531 static void workshop_op_load_model(void){
532 world_instance
*world
= world_current_instance();
533 workshop_form
.view_world
= world
;
535 if( workshop_form
.submission
.type
== k_addon_type_board
){
536 if( mdl_arrcount( &world
->ent_swspreview
) ){
537 workshop_form
.ptr_ent
=
538 mdl_arritm( &world
->ent_swspreview
, 0 );
541 ui_start_modal( "There is no ent_swspreview in the level. \n"
542 "Cannot publish here\n", UI_MODAL_BAD
);
543 workshop_form
.op
= k_workshop_op_none
;
547 else if( workshop_form
.submission
.type
== k_addon_type_player
){}
549 ui_start_modal( "Don't know how to prepare for this item type. \n"
550 "Please contact the developers.\n", UI_MODAL_BAD
);
551 workshop_form
.op
= k_workshop_op_none
;
555 workshop_form
.op
= k_workshop_op_loading_model
;
556 vg_loader_start( _workshop_form_load_thread
, NULL
);
560 * op: k_workshop_form_op_downloading_submission
561 * -----------------------------------------------------------------------------
565 * The image has been decoded and is ready to slap into the framebuffer
567 static void workshop_form_async_imageload( void *data
, u32 len
)
570 struct framebuffer_attachment
*a
=
571 &gpipeline
.fb_workshop_preview
->attachments
[0];
573 glBindTexture( GL_TEXTURE_2D
, a
->id
);
574 glTexSubImage2D( GL_TEXTURE_2D
, 0,0,0,
575 WORKSHOP_PREVIEW_WIDTH
, WORKSHOP_PREVIEW_HEIGHT
,
576 a
->format
, a
->type
, data
);
577 stbi_image_free( data
);
578 vg_success( "Loaded workshop preview image\n" );
581 snprintf( workshop_form
.error_msg
, sizeof(workshop_form
.error_msg
),
582 "Preview image could not be loaded. Reason: %s\n",
583 stbi_failure_reason() );
584 ui_start_modal( workshop_form
.error_msg
, UI_MODAL_BAD
);
586 workshop_form
.op
= k_workshop_op_none
;
590 * Load the image located at ./workshop_preview.jpg into our framebuffer
592 static void _workshop_load_preview_thread( void *data
){
593 char path_buf
[ 4096 ];
595 vg_strnull( &path
, path_buf
, 4096 );
596 vg_strcat( &path
, workshop_filetype_folder() );
597 vg_strcat( &path
, workshop_form
.addon_folder
);
598 vg_strcat( &path
, "/preview.jpg" );
600 if( vg_strgood( &path
) ){
601 stbi_set_flip_vertically_on_load(1);
603 u8
*rgb
= stbi_load( path
.buffer
, &x
, &y
, &nc
, 3 );
606 if( (x
== WORKSHOP_PREVIEW_WIDTH
) && (y
== WORKSHOP_PREVIEW_HEIGHT
) ){
607 vg_async_call( workshop_form_async_imageload
, rgb
, x
*y
*3 );
610 vg_error( "Resolution does not match framebuffer, so we can't"
612 stbi_image_free( rgb
);
613 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
617 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
621 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
626 * Entry point to view operation
628 static void workshop_op_download_and_view_submission( int result_index
)
630 workshop_form
.op
= k_workshop_op_downloading_submission
;
631 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
632 ISteamRemoteStorage
*hSteamRemoteStorage
= SteamAPI_SteamRemoteStorage();
633 SteamUGCDetails_t details
;
634 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC
,
635 workshop_form
.ugc_query
.handle
,
639 workshop_reset_submission_data();
640 workshop_form
.submission
.submit_description
= 0;
641 workshop_form
.submission
.submit_file_and_image
= 0;
642 workshop_form
.submission
.submit_title
= 0;
644 u8 metadata_buf
[512];
645 char metadata_str
[1024+1];
646 int have_meta
= SteamAPI_ISteamUGC_GetQueryUGCMetadata( hSteamUGC
,
647 workshop_form
.ugc_query
.handle
,
648 result_index
, metadata_str
,
651 vg_strncpy( details
.m_rgchDescription
,
652 workshop_form
.submission
.description
,
653 vg_list_size( workshop_form
.submission
.description
),
654 k_strncpy_always_add_null
);
656 vg_strncpy( details
.m_rgchTitle
,
657 workshop_form
.submission
.title
,
658 vg_list_size( workshop_form
.submission
.title
),
659 k_strncpy_always_add_null
);
661 snprintf( workshop_form
.addon_folder
,
662 vg_list_size( workshop_form
.addon_folder
),
663 "Steam Cloud ("PRINTF_U64
")", details
.m_nPublishedFileId
);
665 workshop_form
.submission
.file_id
= details
.m_nPublishedFileId
;
666 workshop_form
.file_intent
= k_workshop_form_file_intent_keep_old
;
667 workshop_form
.page
= k_workshop_form_edit
;
668 workshop_form
.submission
.visibility
= details
.m_eVisibility
;
669 workshop_form
.submission
.type
= k_addon_type_none
;
670 workshop_form
.submission
.submission_type_selection
= k_addon_type_none
;
673 u32 len
= strlen(metadata_str
);
674 vg_info( "Metadata: %s\n", metadata_str
);
675 vg_str_bin( metadata_str
, metadata_buf
, len
);
677 vg_msg_init( &msg
, metadata_buf
, len
/2 );
679 if( vg_msg_seekframe( &msg
, "workshop" )){
681 vg_msg_getkvintg( &msg
, "type", k_vg_msg_u32
, &type
);
682 workshop_form
.submission
.type
= type
;
683 workshop_form
.submission
.submission_type_selection
= type
;
685 const char *kv_folder
= vg_msg_getkvstr( &msg
, "folder" );
687 vg_strncpy( kv_folder
, workshop_form
.addon_folder
,
688 sizeof(workshop_form
.addon_folder
),
689 k_strncpy_always_add_null
);
694 vg_error( "No metadata was returned with this item.\n" );
697 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
698 glClearColor( 0.2f
, 0.0f
, 0.0f
, 1.0f
);
699 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
700 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
701 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
703 vg_loader_start( _workshop_load_preview_thread
, NULL
);
706 vg_error( "GetQueryUGCResult: Index out of range\n" );
707 workshop_form
.op
= k_workshop_op_none
;
713 * -----------------------------------------------------------------------------
717 * View a page of results on the sidebar
719 static void workshop_view_page( int req
)
721 if( workshop_form
.ugc_query
.result
!= k_EResultOK
){
722 vg_error( "Tried to change page without complete data\n" );
723 workshop_form
.op
= k_workshop_op_none
;
727 int page
= VG_MAX(VG_MIN(req
, workshop_form
.view_published_page_count
-1),0),
728 start
= page
* WORKSHOP_VIEW_PER_PAGE
,
729 end
= VG_MIN( (page
+1) * WORKSHOP_VIEW_PER_PAGE
,
730 workshop_form
.ugc_query
.returned_item_count
),
733 vg_info( "View page %d\n", page
);
735 workshop_form
.view_published_page_id
= page
;
736 workshop_form
.published_files_list_length
= count
;
737 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
739 for( int i
=0; i
<count
; i
++ ){
740 struct published_file
*pfile
= &workshop_form
.published_files_list
[i
];
742 SteamUGCDetails_t details
;
743 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC
,
744 workshop_form
.ugc_query
.handle
,
748 if( details
.m_eResult
!= k_EResultOK
){
749 snprintf( pfile
->title
, 80, "Error (%d)", details
.m_eResult
);
752 vg_strncpy( details
.m_rgchTitle
, pfile
->title
, 80,
753 k_strncpy_always_add_null
);
756 pfile
->result
= details
.m_eResult
;
757 pfile
->result_index
= start
+i
;
760 pfile
->result
= k_EResultValueOutOfRange
;
761 pfile
->result_index
= -1;
762 snprintf( pfile
->title
, 80, "Error (invalid index)" );
768 * Steam API result for when we recieve submitted UGC information about the user
770 static void on_workshop_UGCQueryComplete( void *data
, void *userdata
)
772 SteamUGCQueryCompleted_t
*query
= data
;
773 workshop_form
.ugc_query
.result
= query
->m_eResult
;
775 if( query
->m_eResult
== k_EResultOK
){
776 if( query
->m_unTotalMatchingResults
> 50 ){
777 vg_warn( "You have %d items submitted, "
778 "we can only view the last 50\n" );
781 workshop_form
.ugc_query
.all_item_count
= query
->m_unTotalMatchingResults
;
782 workshop_form
.ugc_query
.returned_item_count
=
783 query
->m_unNumResultsReturned
;
785 workshop_form
.ugc_query
.handle
= query
->m_handle
;
786 workshop_form
.view_published_page_count
=
787 (query
->m_unNumResultsReturned
+WORKSHOP_VIEW_PER_PAGE
-1)/
788 WORKSHOP_VIEW_PER_PAGE
;
789 workshop_form
.view_published_page_id
= 0;
790 workshop_form
.published_files_list_length
= 0;
792 workshop_view_page( 0 );
795 vg_error( "Steam UGCQuery failed (%d)\n", query
->m_eResult
);
796 workshop_form
.view_published_page_count
= 0;
797 workshop_form
.view_published_page_id
= 0;
798 workshop_form
.published_files_list_length
= 0;
800 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
801 SteamAPI_ISteamUGC_ReleaseQueryUGCRequest( hSteamUGC
, query
->m_handle
);
806 * Console command to open the workshop publisher
808 static int workshop_submit_command( int argc
, const char *argv
[] )
811 ui_start_modal( "Steam API is not initialized\n", UI_MODAL_BAD
);
815 workshop_form
.page
= k_workshop_form_open
;
816 workshop_form
.view_published_page_count
= 0;
817 workshop_form
.view_published_page_id
= 0;
818 workshop_form
.published_files_list_length
= 0;
819 workshop_form
.ugc_query
.result
= k_EResultNone
;
821 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
823 ISteamUser
*hSteamUser
= SteamAPI_SteamUser();
825 steamid
.m_unAll64Bits
= SteamAPI_ISteamUser_GetSteamID( hSteamUser
);
827 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
828 call
->p_handler
= on_workshop_UGCQueryComplete
;
829 call
->userdata
= NULL
;
830 UGCQueryHandle_t handle
= SteamAPI_ISteamUGC_CreateQueryUserUGCRequest
833 steamid
.m_comp
.m_unAccountID
,
834 k_EUserUGCList_Published
,
835 k_EUGCMatchingUGCType_Items
,
836 k_EUserUGCListSortOrder_CreationOrderDesc
,
837 SKATERIFT_APPID
, SKATERIFT_APPID
,
839 SteamAPI_ISteamUGC_SetReturnMetadata( hSteamUGC
, handle
, 1 );
840 call
->id
= SteamAPI_ISteamUGC_SendQueryUGCRequest( hSteamUGC
, handle
);
844 static void workshop_init(void)
846 vg_console_reg_cmd( "workshop_submit", workshop_submit_command
, NULL
);
849 static void workshop_render_world_preview(void){
850 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
852 glClearColor( 0.0f
, 0.0f
, 0.3f
, 1.0f
);
853 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
854 glEnable( GL_DEPTH_TEST
);
855 glDisable( GL_BLEND
);
857 render_world( world_current_instance(), &skaterift
.cam
, 0, 0, 1, 1 );
859 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
860 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
864 * Redraw the playermodel into the workshop framebuffer
866 static void workshop_render_player_preview(void){
867 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
868 glClearColor( 0.16f
, 0.15f
, 0.15f
, 1.0f
);
869 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
870 glEnable( GL_DEPTH_TEST
);
871 glDisable( GL_BLEND
);
873 struct skeleton
*sk
= &localplayer
.skeleton
;
876 res
.type
= k_player_pose_type_ik
;
878 struct skeleton_anim
*anim
= skeleton_get_anim( sk
, "idle_cycle+y" );
879 skeleton_sample_anim( sk
, anim
, vg
.time
*0.1f
, res
.keyframes
);
880 q_axis_angle( res
.root_q
, (v3f
){0.0f
,1.0f
,0.0f
}, VG_PIf
);
881 v3_zero( res
.root_co
);
882 res
.root_co
[1] = 200.0f
;
885 q_m3x3( res
.root_q
, transform
);
886 v3_copy( res
.root_co
, transform
[3] );
888 /* TODO: Function. */
889 skeleton_apply_pose( sk
, res
.keyframes
, k_anim_apply_defer_ik
,
890 localplayer
.final_mtx
);
891 skeleton_apply_ik_pass( sk
, localplayer
.final_mtx
);
892 skeleton_apply_pose( sk
, res
.keyframes
, k_anim_apply_deffered_only
,
893 localplayer
.final_mtx
);
894 skeleton_apply_inverses( sk
, localplayer
.final_mtx
);
895 skeleton_apply_transform( sk
, transform
, localplayer
.final_mtx
);
898 v3_copy( (v3f
){ 0.0f
, 201.7f
, 1.2f
}, cam
.pos
);
903 v3_zero( cam
.angles
);
905 camera_update_transform( &cam
);
906 camera_update_view( &cam
);
907 camera_update_projection( &cam
);
908 camera_finalize( &cam
);
910 render_playermodel( &cam
, world_current_instance(), 0,
911 &workshop_form
.player_model
, sk
, localplayer
.final_mtx
);
913 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
914 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
918 * Redraw the model file into the workshop framebuffer
920 static void workshop_render_board_preview(void){
921 if( !workshop_form
.ptr_ent
){
925 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
927 glClearColor( 0.0f
, 0.0f
, 0.3f
, 1.0f
);
928 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
929 glEnable( GL_DEPTH_TEST
);
930 glDisable( GL_BLEND
);
932 ent_swspreview
*swsprev
= workshop_form
.ptr_ent
;
933 world_instance
*world
= workshop_form
.view_world
;
935 ent_camera
*ref
= mdl_arritm( &world
->ent_camera
,
936 mdl_entity_id_id(swsprev
->id_camera
) );
937 ent_marker
*display
= mdl_arritm( &world
->ent_marker
,
938 mdl_entity_id_id(swsprev
->id_display
) ),
939 *display1
= mdl_arritm( &world
->ent_marker
,
940 mdl_entity_id_id(swsprev
->id_display1
) );
943 v3_add( display
->transform
.co
, display1
->transform
.co
, baseco
);
944 v3_muls( baseco
, 0.5f
, baseco
);
948 v3_sub( display
->transform
.co
, ref
->transform
.co
, basevector
);
949 float dist
= v3_length( basevector
);
952 v3_angles( basevector
, baseangles
);
954 v2_add( workshop_form
.view_angles
, baseangles
, cam
.angles
);
955 cam
.angles
[2] = 0.0f
;
957 float sX
= sinf( cam
.angles
[0] ),
958 cX
= cosf( cam
.angles
[0] ),
959 sY
= sinf( cam
.angles
[1] ),
960 cY
= cosf( cam
.angles
[1] );
962 v3f offset
= { -sX
* cY
, sY
, cX
* cY
};
964 v3_muladds( display
->transform
.co
, offset
,
965 dist
*workshop_form
.view_dist
, cam
.pos
);
967 cam
.pos
[0] += -sX
*workshop_form
.view_offset
[2];
968 cam
.pos
[2] += cX
*workshop_form
.view_offset
[2];
969 cam
.pos
[0] += cX
*workshop_form
.view_offset
[0];
970 cam
.pos
[2] += sX
*workshop_form
.view_offset
[0];
971 cam
.pos
[1] += workshop_form
.view_offset
[1];
977 camera_update_transform( &cam
);
978 camera_update_view( &cam
);
979 camera_update_projection( &cam
);
980 camera_finalize( &cam
);
983 mdl_transform_m4x3( &display
->transform
, mmdl
);
984 mdl_transform_m4x3( &display1
->transform
, mmdl1
);
986 /* force update this for nice shadows. its usually set in the world
987 * pre-render step, but that includes timer stuff
989 struct player_board
*board
= &workshop_form
.board_model
;
990 struct ub_world_lighting
*ubo
= &world
->ub_lighting
;
992 v3_copy((v3f
){0.0f
,0.1f
, board
->truck_positions
[0][2]}, vp0
);
993 v3_copy((v3f
){0.0f
,0.1f
, board
->truck_positions
[1][2]}, vp1
);
994 m4x3_mulv( mmdl1
, vp0
, ubo
->g_board_0
);
995 m4x3_mulv( mmdl1
, vp1
, ubo
->g_board_1
);
996 glBindBuffer( GL_UNIFORM_BUFFER
, world
->ubo_lighting
);
997 glBufferSubData( GL_UNIFORM_BUFFER
, 0,
998 sizeof(struct ub_world_lighting
), &world
->ub_lighting
);
1000 render_world( world
, &cam
, 0, 0, 0, 0 );
1001 struct player_board_pose pose
= {0};
1002 render_board( &cam
, world
, board
, mmdl
, &pose
, k_board_shader_entity
);
1003 render_board( &cam
, world
, board
, mmdl1
, &pose
, k_board_shader_entity
);
1005 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
1006 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
1010 * ImGUI section for workshop form
1011 * -----------------------------------------------------------------------------
1014 static void workshop_changed_model_path( char *buf
, u32 len
){
1015 workshop_form
.submission
.submit_file_and_image
= 1;
1018 static void workshop_changed_title( char *buf
, u32 len
){
1019 workshop_form
.submission
.submit_title
= 1;
1022 static void workshop_changed_description( char *buf
, u32 len
){
1023 workshop_form
.submission
.submit_description
= 1;
1026 static void workshop_form_gui_page_undecided( ui_rect content
){
1028 rect_copy( content
, box
);
1030 box
[2] = (box
[2]*2)/3;
1031 ui_rect_center( content
, box
);
1034 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1035 ui_text( row
, "Select the type of item\n", 1, k_ui_align_middle_center
,0);
1036 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1037 ui_enum( row
, "Type:", workshop_form_type_opts
,
1038 4, &workshop_form
.submission
.submission_type_selection
);
1039 ui_split( box
, k_ui_axis_h
, 8, 0, row
, box
);
1040 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1042 ui_rect button_l
, button_r
;
1043 rect_copy( row
, button_l
);
1044 button_l
[2] = 128*2;
1045 ui_rect_center( row
, button_l
);
1046 ui_split_ratio( button_l
, k_ui_axis_v
, 0.5f
, 2, button_l
, button_r
);
1048 enum addon_type type
= workshop_form
.submission
.submission_type_selection
;
1049 if( type
!= k_addon_type_none
){
1050 if( ui_button_text( button_l
, "OK", 1 ) == 1 ){
1051 workshop_form
.submission
.type
= type
;
1053 if( type
== k_addon_type_world
){
1054 workshop_form
.view_changed
= 1;
1055 workshop_form
.file_intent
= k_workshop_form_file_intent_new
;
1060 ui_fill( button_l
, ui_colour(k_ui_bg
) );
1061 ui_text( button_l
, "OK", 1, k_ui_align_middle_center
,
1062 ui_colour(k_ui_bg
+4) );
1065 if( ui_button_text( button_r
, "Cancel", 1 ) == 1 ){
1066 workshop_form
.page
= k_workshop_form_open
;
1067 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1071 static void workshop_form_gui_draw_preview( ui_rect img_box
){
1072 enum addon_type type
= workshop_form
.submission
.type
;
1073 if( workshop_form
.file_intent
== k_workshop_form_file_intent_keep_old
){
1074 ui_image( img_box
, gpipeline
.fb_workshop_preview
->attachments
[0].id
);
1076 else if( workshop_form
.file_intent
== k_workshop_form_file_intent_new
){
1077 ui_image( img_box
, gpipeline
.fb_workshop_preview
->attachments
[0].id
);
1079 if( type
== k_addon_type_world
){
1083 int hover
= ui_inside_rect( img_box
, vg_ui
.mouse
),
1084 target
= ui_inside_rect( img_box
, vg_ui
.mouse_click
);
1086 if( ui_click_down(UI_MOUSE_MIDDLE
) && target
){
1087 v3_copy( workshop_form
.view_offset
,
1088 workshop_form
.view_offset_begin
);
1090 else if( ui_click_down(UI_MOUSE_LEFT
) && target
){
1091 v2_copy( workshop_form
.view_angles
,
1092 workshop_form
.view_angles_begin
);
1095 if( ui_clicking(UI_MOUSE_MIDDLE
) && target
){
1096 v2f delta
= { vg_ui
.mouse
[0]-vg_ui
.mouse_click
[0],
1097 vg_ui
.mouse
[1]-vg_ui
.mouse_click
[1] };
1099 float *begin
= workshop_form
.view_offset_begin
,
1100 *offset
= workshop_form
.view_offset
;
1101 offset
[0] = vg_clampf( begin
[0]-delta
[0]*0.002f
, -1.0f
, 1.0f
);
1102 offset
[2] = vg_clampf( begin
[2]-delta
[1]*0.002f
, -1.0f
, 1.0f
);
1103 workshop_form
.view_changed
= 1;
1105 else if( ui_clicking(UI_MOUSE_LEFT
) && target
){
1106 v2f delta
= { vg_ui
.mouse
[0]-vg_ui
.mouse_click
[0],
1107 vg_ui
.mouse
[1]-vg_ui
.mouse_click
[1] };
1110 v2_muladds( workshop_form
.view_angles_begin
, delta
, 0.002f
, angles
);
1112 float limit
= VG_PIf
*0.2f
;
1114 angles
[0] = vg_clampf( angles
[0], -limit
, limit
);
1115 angles
[1] = vg_clampf( angles
[1], -limit
, limit
);
1117 v2_copy( angles
, workshop_form
.view_angles
);
1118 workshop_form
.view_changed
= 1;
1121 if( !ui_clicking(UI_MOUSE_LEFT
) && hover
){
1122 float zoom
= workshop_form
.view_dist
;
1123 zoom
+= vg
.mouse_wheel
[1] * -0.07f
;
1124 zoom
= vg_clampf( zoom
, 0.4f
, 2.0f
);
1126 if( zoom
!= workshop_form
.view_dist
){
1127 workshop_form
.view_changed
= 1;
1128 workshop_form
.view_dist
= zoom
;
1133 ui_text( img_box
, "No image", 1, k_ui_align_middle_center
,
1134 ui_colour( k_ui_orange
) );
1138 static void workshop_form_gui_edit_page( ui_rect content
){
1139 enum addon_type type
= workshop_form
.submission
.type
;
1141 if( type
== k_addon_type_none
){
1142 workshop_form_gui_page_undecided( content
);
1146 ui_rect image_plane
;
1147 ui_split( content
, k_ui_axis_h
, 300, 0, image_plane
, content
);
1148 ui_fill( image_plane
, ui_colour( k_ui_bg
+0 ) );
1151 ui_fit_item( image_plane
, (ui_px
[2]){ 3, 2 }, img_box
);
1152 workshop_form_gui_draw_preview( img_box
);
1155 ui_rect file_button
, file_label
;
1159 "Addon folder: skaterift/%s", workshop_filetype_folder() );
1161 if( type
== k_addon_type_world
){
1162 struct ui_textbox_callbacks callbacks
= {
1163 .change
= workshop_changed_model_path
1165 ui_textbox( content
, buf
, workshop_form
.addon_folder
,
1166 vg_list_size(workshop_form
.addon_folder
), 1, 0, &callbacks
);
1170 ui_standard_widget( content
, file_entry
, 1 );
1171 ui_split( file_entry
, k_ui_axis_v
, -128, 0, file_entry
, file_button
);
1173 if( workshop_form
.file_intent
!= k_workshop_form_file_intent_none
){
1174 ui_text( file_entry
, workshop_form
.addon_folder
, 1,
1175 k_ui_align_middle_left
, ui_colour( k_ui_fg
+4 ) );
1177 if( ui_button_text( file_button
, "Remove", 1 ) == 1 ){
1178 if( type
== k_addon_type_board
)
1179 player_board_unload( &workshop_form
.board_model
);
1180 else if( type
== k_addon_type_player
)
1181 player_model_unload( &workshop_form
.player_model
);
1183 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1184 workshop_form
.addon_folder
[0] = '\0';
1188 struct ui_textbox_callbacks callbacks
= {
1189 .change
= workshop_changed_model_path
1192 ui_textbox( file_entry
, buf
, workshop_form
.addon_folder
,
1193 vg_list_size(workshop_form
.addon_folder
), 1,
1196 if( ui_button_text( file_button
, "Load", 1 ) == 1 ){
1197 workshop_op_load_model();
1202 const char *str_title
= "Title:", *str_desc
= "Description:";
1206 struct ui_textbox_callbacks callbacks
= {
1207 .change
= workshop_changed_title
1209 ui_textbox( content
, str_title
, workshop_form
.submission
.title
,
1210 vg_list_size(workshop_form
.submission
.title
), 1,
1214 /* visibility option */
1216 ui_enum( content
, "Visibility:", workshop_form_visibility_opts
,
1217 4, &workshop_form
.submission
.visibility
);
1220 /* description box */
1222 struct ui_textbox_callbacks callbacks
= {
1223 .change
= workshop_changed_description
1225 ui_textbox( content
, str_desc
, workshop_form
.submission
.description
,
1226 vg_list_size(workshop_form
.submission
.description
), 4,
1227 UI_TEXTBOX_MULTILINE
|UI_TEXTBOX_WRAP
, &callbacks
);
1230 /* submissionable */
1232 ui_split( content
, k_ui_axis_h
, content
[3]-32-8, 0, content
, final_row
);
1234 ui_rect submission_center
;
1235 rect_copy( final_row
, submission_center
);
1236 submission_center
[2] = 256;
1237 ui_rect_center( final_row
, submission_center
);
1239 ui_rect btn_left
, btn_right
;
1240 ui_split_ratio( submission_center
, k_ui_axis_v
, 0.5f
, 8,
1241 btn_left
, btn_right
);
1243 if( ui_button_text( btn_left
, "Publish", 1 ) == 1 ){
1244 workshop_op_submit();
1246 if( ui_button_text( btn_right
, "Cancel", 1 ) == 1 ){
1247 workshop_form
.page
= k_workshop_form_open
;
1248 player_board_unload( &workshop_form
.board_model
);
1249 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1253 const char *disclaimer_text
=
1254 "By submitting this item, you agree to the workshop terms of service";
1256 ui_rect disclaimer_row
, inner
, link
;
1257 ui_split( content
, k_ui_axis_h
, content
[3]-32, 0, content
, disclaimer_row
);
1259 ui_px btn_width
= 32;
1261 rect_copy( disclaimer_row
, inner
);
1262 inner
[2] = ui_text_line_width( disclaimer_text
) + btn_width
+8;
1265 ui_rect_center( disclaimer_row
, inner
);
1266 ui_split( inner
, k_ui_axis_v
, inner
[2]-btn_width
, 0, label
, btn_right
);
1267 ui_rect_pad( btn_right
, (ui_px
[2]){2,2} );
1269 if( ui_button_text( btn_right
, "\xbf", 2 ) == 1 ){
1270 ISteamFriends
*hSteamFriends
= SteamAPI_SteamFriends();
1271 SteamAPI_ISteamFriends_ActivateGameOverlayToWebPage( hSteamFriends
,
1272 "https://steamcommunity.com/sharedfiles/workshoplegalagreement",
1273 k_EActivateGameOverlayToWebPageMode_Default
);
1276 ui_text( label
, disclaimer_text
, 1, k_ui_align_middle_left
,
1277 ui_colour( k_ui_fg
+4 ) );
1280 static void workshop_form_gui_sidebar( ui_rect sidebar
)
1282 ui_fill( sidebar
, ui_colour( k_ui_bg
+2 ) );
1285 ui_split( sidebar
, k_ui_axis_h
, 28, 0, title
, sidebar
);
1287 if( workshop_form
.page
== k_workshop_form_edit
){
1288 ui_text( title
, "Editing", 1, k_ui_align_middle_center
, 0 );
1289 ui_split( sidebar
, k_ui_axis_h
, 28, 0, title
, sidebar
);
1291 if( workshop_form
.submission
.type
!= k_addon_type_none
){
1294 vg_strnull( &str
, buf
, 512 );
1296 if( workshop_form
.submission
.file_id
)
1297 vg_strcat( &str
, "Editing an existing " );
1299 vg_strcat( &str
, "Creating a new " );
1301 if( workshop_form
.submission
.type
== k_addon_type_board
)
1302 vg_strcat( &str
, "skateboard." );
1303 else if( workshop_form
.submission
.type
== k_addon_type_world
)
1304 vg_strcat( &str
, "world." );
1305 else if( workshop_form
.submission
.type
== k_addon_type_player
)
1306 vg_strcat( &str
, "playermodel." );
1308 vg_strcat( &str
, "???." );
1310 ui_text( title
, buf
, 1, k_ui_align_middle_center
,
1311 ui_colour(k_ui_fg
+4) );
1317 * sidebar existing entries panel
1319 ui_text( title
, "Your submissions", 1, k_ui_align_middle_center
, 0 );
1321 ui_rect controls
, btn_create_new
;
1322 ui_split( sidebar
, k_ui_axis_h
, 32, 0, controls
, sidebar
);
1323 ui_split( sidebar
, k_ui_axis_h
, -32, 0, sidebar
, btn_create_new
);
1324 ui_fill( controls
, ui_colour( k_ui_bg
+1 ) );
1328 vg_strnull( &str
, buf
, sizeof(buf
) );
1329 vg_strcat( &str
, "page " );
1330 vg_strcati32( &str
, workshop_form
.view_published_page_id
+1 );
1331 vg_strcatch( &str
, '/' );
1332 vg_strcati32( &str
, workshop_form
.view_published_page_count
);
1334 ui_rect_pad( controls
, (ui_px
[2]){0,4} );
1336 ui_split_ratio( controls
, k_ui_axis_v
, 0.25f
, 0, info
, controls
);
1337 ui_text( info
, buf
, 1, k_ui_align_middle_center
, 0 );
1339 ui_rect btn_left
, btn_right
;
1340 ui_split_ratio( controls
, k_ui_axis_v
, 0.5f
, 2, btn_left
, btn_right
);
1342 if( ui_button_text( btn_left
, "newer", 1 ) == 1 ){
1343 workshop_view_page( workshop_form
.view_published_page_id
-1 );
1346 if( ui_button_text( btn_right
, "older", 1 ) == 1 ){
1347 workshop_view_page( workshop_form
.view_published_page_count
+1 );
1350 if( ui_button_text( btn_create_new
, "Create New Item", 1 ) == 1 ){
1351 workshop_reset_submission_data();
1352 workshop_form
.submission
.submit_title
= 1;
1353 workshop_form
.submission
.submit_description
= 1;
1354 workshop_form
.submission
.submit_file_and_image
= 1;
1355 workshop_form
.page
= k_workshop_form_edit
;
1358 for( int i
=0; i
<workshop_form
.published_files_list_length
; i
++ ){
1360 ui_split( sidebar
, k_ui_axis_h
, 28, 0, item
, sidebar
);
1361 ui_rect_pad( item
, (ui_px
[2]){4,4} );
1363 struct published_file
*pfile
= &workshop_form
.published_files_list
[i
];
1364 if( ui_button_text( item
, pfile
->title
, 1 ) == 1 ){
1365 if( pfile
->result
== k_EResultOK
){
1366 vg_info( "Select index: %d\n", pfile
->result_index
);
1367 workshop_op_download_and_view_submission( pfile
->result_index
);
1370 vg_warn( "Cannot select that item, result not OK\n" );
1376 static void workshop_form_gui(void)
1378 enum workshop_form_page stable_page
= workshop_form
.page
;
1379 if( stable_page
== k_workshop_form_hidden
) return;
1382 ui_rect screen
= { 0, 0, vg
.window_x
, vg
.window_y
};
1383 ui_rect window
= { 0, 0, 1000, 700 };
1384 ui_rect_center( screen
, window
);
1385 vg_ui
.wants_mouse
= 1;
1387 ui_fill( window
, ui_colour( k_ui_bg
+1 ) );
1388 ui_outline( window
, 1, ui_colour( k_ui_bg
+7 ), 0 );
1390 ui_rect title
, panel
;
1391 ui_split( window
, k_ui_axis_h
, 28, 0, title
, panel
);
1392 ui_fill( title
, ui_colour( k_ui_bg
+7 ) );
1393 ui_text( title
, "Workshop tool", 1, k_ui_align_middle_center
,
1394 ui_colourcont(k_ui_bg
+7) );
1396 ui_rect quit_button
;
1397 ui_split( title
, k_ui_axis_v
, title
[2]-title
[3], 2, title
, quit_button
);
1399 if( vg_loader_availible() ){
1400 if( ui_button_text( quit_button
, "X", 1 ) == 1 ){
1401 workshop_quit_form();
1407 * temporary operation blinders, we don't yet have a nice way to show the
1408 * user that we're doing something uninterruptable, so the code just
1409 * escapes here and we show them a basic string
1412 if( workshop_form
.op
!= k_workshop_op_none
){
1413 const char *op_string
= "The programmer has not bothered to describe "
1414 "the current operation that is running.";
1416 switch( workshop_form
.op
){
1417 case k_workshop_op_loading_model
:
1418 op_string
= "Operation in progress: Loading model file.";
1420 case k_workshop_op_publishing_update
:
1421 op_string
= "Operation in progress: publishing submission update "
1424 case k_workshop_op_downloading_submission
:
1425 op_string
= "Operation in progress: downloading existing submission"
1426 " from Steam services.";
1431 ui_text( panel
, op_string
, 1, k_ui_align_middle_center
, 0 );
1435 /* re draw board preview if need to */
1436 if( (stable_page
== k_workshop_form_edit
) &&
1437 workshop_form
.view_changed
&&
1438 workshop_form
.file_intent
== k_workshop_form_file_intent_new
)
1440 enum addon_type type
= workshop_form
.submission
.type
;
1441 if( type
== k_addon_type_board
){
1442 workshop_render_board_preview();
1444 else if( type
== k_addon_type_world
){
1445 vg_success( "Renders world preview\n" );
1446 workshop_render_world_preview();
1448 else if( type
== k_addon_type_player
){
1449 workshop_render_player_preview();
1452 workshop_form
.view_changed
= 0;
1455 struct workshop_form
*form
= &workshop_form
;
1457 ui_rect sidebar
, content
;
1458 ui_split_ratio( panel
, k_ui_axis_v
, 0.3f
, 1, sidebar
, content
);
1461 ui_rect_pad( content
, (ui_px
[2]){8,8} );
1463 if( stable_page
== k_workshop_form_edit
){
1464 workshop_form_gui_edit_page( content
);
1466 else if( stable_page
== k_workshop_form_open
){
1467 ui_text( content
, "Nothing selected.", 1, k_ui_align_middle_center
,
1468 ui_colour( k_ui_fg
+4 ) );
1470 else if( stable_page
>= k_workshop_form_cclosing
){
1471 ui_rect submission_row
;
1472 ui_split( content
, k_ui_axis_h
, content
[3]-32-8, 0, content
,
1477 if( stable_page
== k_workshop_form_closing_bad
)
1478 colour
= ui_colour( k_ui_red
+k_ui_brighter
);
1480 colour
= ui_colour( k_ui_green
+k_ui_brighter
);
1482 ui_text( content
, workshop_form
.failure_or_success_string
, 1,
1483 k_ui_align_middle_center
, colour
);
1485 ui_rect submission_center
;
1486 rect_copy( submission_row
, submission_center
);
1487 submission_center
[2] = 128;
1488 ui_rect_center( submission_row
, submission_center
);
1489 ui_rect_pad( submission_center
, (ui_px
[2]){8,8} );
1491 if( ui_button_text( submission_center
, "OK", 1 ) == 1 ){
1492 workshop_form
.page
= k_workshop_form_open
;
1496 workshop_form_gui_sidebar( sidebar
);
1500 * Some async api stuff
1501 * -----------------------------------------------------------------------------
1504 static void async_workshop_get_filepath( void *data
, u32 len
)
1506 struct async_workshop_filepath_info
*info
= data
;
1511 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
1512 if( !SteamAPI_ISteamUGC_GetItemInstallInfo( hSteamUGC
, info
->id
, &_size
,
1513 info
->buf
, info
->len
, &_ts
))
1515 vg_error( "GetItemInstallInfo failed\n" );
1516 info
->buf
[0] = '\0';
1520 static void async_workshop_get_installed_files( void *data
, u32 len
)
1522 struct async_workshop_installed_files_info
*info
= data
;
1524 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
1525 u32 count
= SteamAPI_ISteamUGC_GetSubscribedItems( hSteamUGC
, info
->buffer
,
1528 vg_info( "Found %u subscribed items\n", count
);
1531 for( u32 i
=0; i
<count
; i
++ ){
1532 u32 state
= SteamAPI_ISteamUGC_GetItemState( hSteamUGC
, info
->buffer
[i
] );
1533 if( state
& k_EItemStateInstalled
){
1534 info
->buffer
[j
++] = info
->buffer
[i
];