10 #include "ent_skateshop.h"
12 #include "vg/vg_steam_auth.h"
13 #include "vg/vg_steam_ugc.h"
14 #include "vg/vg_steam_friends.h"
16 #include "highscores.h"
18 static struct ui_dropdown_opt workshop_form_visibility_opts
[] = {
19 { "Public", k_ERemoteStoragePublishedFileVisibilityPublic
},
20 { "Unlisted", k_ERemoteStoragePublishedFileVisibilityUnlisted
},
21 { "Friends Only", k_ERemoteStoragePublishedFileVisibilityFriendsOnly
},
22 { "Private", k_ERemoteStoragePublishedFileVisibilityPrivate
},
25 static struct ui_dropdown_opt workshop_form_type_opts
[] = {
26 { "None", k_addon_type_none
},
27 { "Board", k_addon_type_board
},
28 { "World", k_addon_type_world
},
32 * Close the form and discard UGC query result
34 VG_STATIC
void workshop_quit_form(void)
36 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
;
51 * Delete all information about the submission
53 VG_STATIC
void workshop_reset_submission_data(void)
55 workshop_form
.submission
.file_id
= 0; /* assuming id of 0 is none/invalid */
56 workshop_form
.submission
.description
[0] = '\0';
57 workshop_form
.submission
.title
[0] = '\0';
58 workshop_form
.submission
.author
[0] = '\0';
59 workshop_form
.submission
.submission_type_selection
.value
=
61 workshop_form
.submission
.submission_type_selection
.index
= 0;
62 workshop_form
.submission
.type
= k_addon_type_none
;
64 workshop_form
.submission
.visibility
.value
=
65 k_ERemoteStoragePublishedFileVisibilityPublic
;
66 workshop_form
.submission
.visibility
.index
= 0;
68 workshop_form
.addon_folder
[0] = '\0';
69 player_board_unload( &workshop_form
.board_model
);
70 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
75 * Mostly copies of what it sais on the Steam API documentation
77 VG_STATIC
const char *workshop_EResult_user_string( EResult result
)
80 case k_EResultInsufficientPrivilege
:
81 return "Your account is currently restricted from uploading content "
82 "due to a hub ban, account lock, or community ban. You need to "
83 "contact Steam Support to resolve the issue.";
85 return "You do not have permission to upload content to this hub "
86 "because you have an active VAC or Game ban.";
87 case k_EResultTimeout
:
88 return "The operation took longer than expected, so it was discarded. "
90 case k_EResultNotLoggedOn
:
91 return "You are currently not logged into Steam.";
92 case k_EResultServiceUnavailable
:
93 return "The workshop server is having issues or is unavailable, "
95 case k_EResultInvalidParam
:
96 return "One of the submission fields contains something not being "
97 "accepted by that field.";
98 case k_EResultAccessDenied
:
99 return "There was a problem trying to save the title and description. "
100 "Access was denied.";
101 case k_EResultLimitExceeded
:
102 return "You have exceeded your Steam Cloud quota. If you wish to "
103 "upload this file, you must remove some published items.";
104 case k_EResultFileNotFound
:
105 return "The uploaded file could not be found.";
106 case k_EResultDuplicateRequest
:
107 return "The file was already successfully uploaded.";
108 case k_EResultDuplicateName
:
109 return "You already have a Steam Workshop item with that name.";
110 case k_EResultServiceReadOnly
:
111 return "Due to a recent password or email change, you are not allowed "
112 "to upload new content. Usually this restriction will expire in"
113 " 5 days, but can last up to 30 days if the account has been "
114 "inactive recently.";
116 return "Operation failed for an error which has not been accounted for "
117 "by the programmer. Try again, sorry :)";
122 * op: k_workshop_form_op_publishing_update
123 * ----------------------------------------------------------------------------
127 * The endpoint of this operation
129 VG_STATIC
void on_workshop_update_result( void *data
, void *user
)
131 vg_info( "Recieved workshop update result\n" );
132 SubmitItemUpdateResult_t
*result
= data
;
134 /* this seems to be set here, but my account definitely has accepted it */
135 if( result
->m_bUserNeedsToAcceptWorkshopLegalAgreement
){
136 vg_warn( "Workshop agreement currently not accepted\n" );
139 if( result
->m_eResult
== k_EResultOK
){
140 workshop_form
.page
= k_workshop_form_closing_good
;
141 workshop_form
.failure_or_success_string
= "Uploaded workshop file!";
142 vg_success( "file uploaded\n" );
145 workshop_form
.page
= k_workshop_form_closing_bad
;
146 workshop_form
.failure_or_success_string
=
147 workshop_EResult_user_string( result
->m_eResult
);
149 vg_error( "Error with the submitted file (%d)\n", result
->m_eResult
);
154 * reciever on completion of packaging the files, it will then start the item
155 * update with Steam API
157 VG_STATIC
void workshop_form_upload_submission( PublishedFileId_t file_id
,
160 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
161 UGCUpdateHandle_t handle
162 = SteamAPI_ISteamUGC_StartItemUpdate( hSteamUGC
, SKATERIFT_APPID
,
165 /* TODO: Handle failure cases for these */
167 SteamAPI_ISteamUGC_SetItemMetadata( hSteamUGC
, handle
, metadata
);
169 if( workshop_form
.submission
.submit_title
){
170 vg_info( "Setting title\n" );
171 SteamAPI_ISteamUGC_SetItemTitle( hSteamUGC
, handle
,
172 workshop_form
.submission
.title
);
175 if( workshop_form
.submission
.submit_description
){
176 vg_info( "Setting description\n" );
177 SteamAPI_ISteamUGC_SetItemDescription( hSteamUGC
, handle
,
178 workshop_form
.submission
.description
);
181 if( workshop_form
.submission
.submit_file_and_image
){
184 vg_strnull( &folder
, path_buf
, 4096 );
185 vg_strcat( &folder
, vg
.base_path
);
187 if( workshop_form
.submission
.type
== k_addon_type_board
){
188 vg_strcat( &folder
, "boards/" );
190 else if( workshop_form
.submission
.type
== k_addon_type_world
){
191 vg_strcat( &folder
, "maps/" );
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
.value
);
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 VG_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 VG_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 VG_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 VG_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 if( workshop_form
.submission
.type
== k_addon_type_board
){
301 vg_strcat( &folder
, "boards/" );
303 else if( workshop_form
.submission
.type
== k_addon_type_world
){
304 vg_strcat( &folder
, "maps/" );
306 vg_strcat( &folder
, workshop_form
.addon_folder
);
308 if( !vg_strgood(&folder
) ){
309 vg_error( "addon folder path too long\n" );
314 * Create the metadata file
315 * -----------------------------------------------------------------------*/
316 u8 descriptor_buf
[ 512 ];
317 vg_msg descriptor
= {0};
318 descriptor
.buf
= descriptor_buf
;
319 descriptor
.max
= sizeof(descriptor_buf
);
321 vg_linear_clear( vg_mem
.scratch
);
323 /* short description */
324 vg_msg_frame( &descriptor
, "workshop" );
325 vg_msg_wkvstr( &descriptor
, "title", workshop_form
.submission
.title
);
326 //vg_msg_wkvstr( &descriptor, "author", "unknown" );
327 vg_msg_wkvu32( &descriptor
, "type", workshop_form
.submission
.type
);
328 vg_msg_wkvstr( &descriptor
, "folder", workshop_form
.addon_folder
);
329 vg_msg_end_frame( &descriptor
);
330 //vg_msg_wkvstr( &descriptor, "location", "USA" );
332 char *short_descriptor_str
= vg_linear_alloc( vg_mem
.scratch
,
333 vg_align8(descriptor
.cur
*2+1));
334 vg_bin_str( descriptor_buf
, short_descriptor_str
, descriptor
.cur
);
335 short_descriptor_str
[descriptor
.cur
*2] = '\0';
336 vg_info( "binstr: %s\n", short_descriptor_str
);
339 if( !vg_dir_open( &dir
, folder
.buffer
) ){
340 vg_error( "could not open addon folder '%s'\n", folder
.buffer
);
344 while( vg_dir_next_entry(&dir
) ){
345 if( vg_dir_entry_type(&dir
) == k_vg_entry_type_file
){
346 const char *d_name
= vg_dir_entry_name(&dir
);
347 if( d_name
[0] == '.' ) continue;
349 vg_str file
= folder
;
350 vg_strcat( &file
, "/" );
351 vg_strcat( &file
, d_name
);
352 if( !vg_strgood( &file
) ) continue;
354 char *ext
= vg_strch( &file
, '.' );
356 if( strcmp(ext
,".mdl") ) continue;
358 vg_msg_wkvstr( &descriptor
, "content", d_name
);
364 vg_str descriptor_file
= folder
;
365 vg_strcat( &descriptor_file
, "/addon.inf" );
366 if( !vg_strgood(&descriptor_file
) ){
367 vg_error( "Addon info path too long\n" );
371 FILE *fp
= fopen( descriptor_file
.buffer
, "wb" );
373 vg_error( "Could not open addon info file '%s'\n",
374 descriptor_file
.buffer
);
377 fwrite( descriptor_buf
, descriptor
.cur
, 1, fp
);
381 * -----------------------------------------------------------------------*/
382 vg_str preview
= folder
;
383 vg_strcat( &preview
, "/preview.jpg" );
385 if( !vg_strgood(&preview
) ){
386 vg_error( "preview image path too long\n" );
390 int w
= workshop_form
.img_w
,
391 h
= workshop_form
.img_h
;
393 vg_info( "writing: %s (%dx%d @90%%)\n", preview
.buffer
, w
,h
);
394 stbi_flip_vertically_on_write(1);
395 stbi_write_jpg( preview
.buffer
, w
,h
, 3, workshop_form
.img_buffer
, 90 );
397 vg_async_call( workshop_form_async_submit_begin
, short_descriptor_str
, 0 );
401 * Entry point for the publishing submission operation
403 VG_STATIC
void workshop_op_submit(void)
405 /* TODO: Show these errors to the user */
406 if( workshop_form
.submission
.submit_title
){
407 if( !workshop_form
.submission
.title
[0] ){
408 vg_error( "Cannot submit because a title is required\n" );
413 if( workshop_form
.submission
.submit_description
){
414 if( !workshop_form
.submission
.description
[0] ){
415 vg_error( "Cannot submit because a description is required\n" );
420 if( workshop_form
.submission
.submit_file_and_image
){
421 if( workshop_form
.file_intent
== k_workshop_form_file_intent_none
){
422 vg_error( "Cannot submit because the file is empty or unspecified\n" );
427 player_board_unload( &workshop_form
.board_model
);
428 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
430 vg_loader_start( _workshop_form_submit_thread
, NULL
);
434 * op: k_workshop_form_op_loading_model
435 * -----------------------------------------------------------------------------
439 * Reciever for completion of the model file load
441 VG_STATIC
void workshop_form_loadmodel_async_complete( void *payload
, u32 size
)
443 v2_zero( workshop_form
.view_angles
);
444 v3_zero( workshop_form
.view_offset
);
445 workshop_form
.view_dist
= 1.0f
;
446 workshop_form
.view_changed
= 1;
447 workshop_form
.file_intent
= k_workshop_form_file_intent_new
;
449 vg_success( "workshop async load complete\n" );
453 * Reciever for failure to load
455 VG_STATIC
void workshop_form_loadmodel_async_error( void *payload
, u32 size
){
459 * Thread which loads the model from the disk
461 VG_STATIC
void _workshop_form_load_thread( void *data
)
465 vg_strnull( &folder
, path_buf
, 4096 );
467 if( workshop_form
.submission
.type
== k_addon_type_world
)
468 vg_strcat( &folder
, "maps/" );
469 else vg_strcat( &folder
, "boards/" );
471 vg_strcat( &folder
, workshop_form
.addon_folder
);
473 if( !vg_strgood(&folder
) ){
474 vg_error( "workshop async load failed: path too long\n" );
475 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
480 if( !vg_dir_open( &dir
, folder
.buffer
) ){
481 vg_error( "workshop async load failed: could not open folder\n" );
482 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
486 vg_info( "Searching %s for model files\n", folder
.buffer
);
489 while( vg_dir_next_entry(&dir
) ){
490 if( vg_dir_entry_type(&dir
) == k_vg_entry_type_file
){
491 const char *d_name
= vg_dir_entry_name(&dir
);
492 if( d_name
[0] == '.' ) continue;
494 vg_str file
= folder
;
495 vg_strcat( &file
, "/" );
496 vg_strcat( &file
, d_name
);
497 if( !vg_strgood( &file
) ) continue;
499 char *ext
= vg_strch( &file
, '.' );
501 if( strcmp(ext
,".mdl") ) continue;
509 vg_error( "workshop async load failed: no model files found\n" );
510 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
514 player_board_load( &workshop_form
.board_model
, path_buf
);
515 vg_async_call( workshop_form_loadmodel_async_complete
, NULL
, 0 );
519 * Entry point for load model operation
521 VG_STATIC
void workshop_op_load_model(void){
522 if( workshop_form
.submission
.type
== k_addon_type_world
){
523 vg_warn( "WORLD LOAD INFO Currently unsupported\n" );
527 workshop_form
.view_world
= world_current_instance();
529 if( mdl_arrcount( &workshop_form
.view_world
->ent_swspreview
) ){
530 workshop_form
.ptr_ent
=
531 mdl_arritm( &workshop_form
.view_world
->ent_swspreview
, 0 );
534 vg_error( "There is no ent_swspreview in the level. "
535 "Cannot publish here\n" );
539 vg_loader_start( _workshop_form_load_thread
, NULL
);
543 * op: k_workshop_form_op_downloading_submission
544 * -----------------------------------------------------------------------------
548 * The image has been decoded and is ready to slap into the framebuffer
550 VG_STATIC
void workshop_form_async_imageload( void *data
, u32 len
)
553 struct framebuffer_attachment
*a
=
554 &gpipeline
.fb_workshop_preview
->attachments
[0];
556 glBindTexture( GL_TEXTURE_2D
, a
->id
);
557 glTexSubImage2D( GL_TEXTURE_2D
, 0,0,0,
558 WORKSHOP_PREVIEW_WIDTH
, WORKSHOP_PREVIEW_HEIGHT
,
559 a
->format
, a
->type
, data
);
560 stbi_image_free( data
);
561 vg_success( "Loaded workshop preview image\n" );
564 snprintf( workshop_form
.error_msg
, sizeof(workshop_form
.error_msg
),
565 "Preview image could not be loaded. Reason: %s\n",
566 stbi_failure_reason() );
567 ui_start_modal( workshop_form
.error_msg
, UI_MODAL_BAD
);
572 * Load the image located at ./workshop_preview.jpg into our framebuffer
574 VG_STATIC
void _workshop_load_preview_thread( void *data
)
576 char path_buf
[ 4096 ];
578 vg_strnull( &path
, path_buf
, 4096 );
579 vg_strcat( &path
, "boards/" );
580 vg_strcat( &path
, workshop_form
.addon_folder
);
581 vg_strcat( &path
, "/preview.jpg" );
583 if( vg_strgood( &path
) ){
584 stbi_set_flip_vertically_on_load(1);
586 u8
*rgb
= stbi_load( path
.buffer
, &x
, &y
, &nc
, 3 );
589 if( (x
== WORKSHOP_PREVIEW_WIDTH
) && (y
== WORKSHOP_PREVIEW_HEIGHT
) ){
590 vg_async_call( workshop_form_async_imageload
, rgb
, x
*y
*3 );
593 vg_error( "Resolution does not match framebuffer, so we can't"
595 stbi_image_free( rgb
);
596 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
600 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
604 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
610 * Reciever for the preview download result
612 VG_STATIC
void on_workshop_download_ugcpreview( void *data
, void *user
)
614 struct workshop_loadpreview_info
*info
= user
;
615 RemoteStorageDownloadUGCResult_t
*result
= data
;
617 if( result
->m_eResult
== k_EResultOK
){
618 ISteamRemoteStorage
*hSteamRemoteStorage
= SteamAPI_SteamRemoteStorage();
619 vg_loader_start( _workshop_load_preview_thread
, info
);
622 vg_error( "Error while donwloading UGC preview( %d )\n",
630 * Entry point to view operation
632 VG_STATIC
void workshop_op_download_and_view_submission( int result_index
)
634 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
635 ISteamRemoteStorage
*hSteamRemoteStorage
= SteamAPI_SteamRemoteStorage();
636 SteamUGCDetails_t details
;
637 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC
,
638 workshop_form
.ugc_query
.handle
,
642 workshop_reset_submission_data();
643 workshop_form
.submission
.submit_description
= 0;
644 workshop_form
.submission
.submit_file_and_image
= 0;
645 workshop_form
.submission
.submit_title
= 0;
647 u8 metadata_buf
[512];
648 char metadata_str
[1024+1];
649 int have_meta
= SteamAPI_ISteamUGC_GetQueryUGCMetadata( hSteamUGC
,
650 workshop_form
.ugc_query
.handle
,
651 result_index
, metadata_str
,
654 vg_strncpy( details
.m_rgchDescription
,
655 workshop_form
.submission
.description
,
656 vg_list_size( workshop_form
.submission
.description
),
657 k_strncpy_always_add_null
);
659 vg_strncpy( details
.m_rgchTitle
,
660 workshop_form
.submission
.title
,
661 vg_list_size( workshop_form
.submission
.title
),
662 k_strncpy_always_add_null
);
664 snprintf( workshop_form
.addon_folder
,
665 vg_list_size( workshop_form
.addon_folder
),
666 "Steam Cloud ("PRINTF_U64
")", details
.m_nPublishedFileId
);
668 workshop_form
.submission
.file_id
= details
.m_nPublishedFileId
;
669 workshop_form
.file_intent
= k_workshop_form_file_intent_keep_old
;
670 workshop_form
.page
= k_workshop_form_edit
;
671 workshop_form
.submission
.visibility
.value
= details
.m_eVisibility
;
672 workshop_form
.submission
.type
= k_addon_type_none
;
673 workshop_form
.submission
.submission_type_selection
.index
= 0;
674 workshop_form
.submission
.submission_type_selection
.value
=
678 u32 len
= strlen(metadata_str
);
679 vg_info( "Metadata: %s\n", metadata_str
);
680 vg_str_bin( metadata_str
, metadata_buf
, len
);
682 root
.buf
= metadata_buf
;
686 vg_msg workshop
= root
;
687 if( vg_msg_seekframe( &workshop
, "workshop", k_vg_msg_first
)){
688 u32 type
= vg_msg_seekkvu32( &workshop
, "type", k_vg_msg_first
);
689 workshop_form
.submission
.type
= type
;
690 workshop_form
.submission
.submission_type_selection
.value
= type
;
692 const char *kv_folder
= vg_msg_seekkvstr( &workshop
, "folder",
695 vg_strncpy( kv_folder
, workshop_form
.addon_folder
,
696 sizeof(workshop_form
.addon_folder
),
697 k_strncpy_always_add_null
);
702 vg_error( "No metadata was returned with this item.\n" );
706 for( i32 i
=0; i
<vg_list_size(workshop_form_visibility_opts
); i
++ ){
707 if( workshop_form_visibility_opts
[i
].value
== details
.m_eVisibility
){
708 workshop_form
.submission
.visibility
.index
= i
;
712 for( i32 i
=0; i
<vg_list_size(workshop_form_type_opts
); i
++ ){
713 if( workshop_form_type_opts
[i
].value
==
714 workshop_form
.submission
.submission_type_selection
.value
){
715 workshop_form
.submission
.submission_type_selection
.index
= i
;
720 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
721 glClearColor( 0.2f
, 0.0f
, 0.0f
, 1.0f
);
722 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
723 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
724 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
726 vg_loader_start( _workshop_load_preview_thread
, NULL
);
729 if( details
.m_hPreviewFile
== 0 ){
730 vg_error( "m_hPreviewFile is 0\n" );
734 /* Now need to begin downloading the image so we can display it */
735 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
737 struct workshop_loadpreview_info
*info
=
738 vg_linear_alloc( vg_mem
.scratch
,
739 sizeof( struct workshop_loadpreview_info
) );
741 snprintf( info
->abs_preview_image
, 1024,
742 "%smodels/boards/workshop/" PRINTF_U64
".jpg",
743 vg
.base_path
, details
.m_hPreviewFile
);
745 call
->p_handler
= on_workshop_download_ugcpreview
;
746 call
->userdata
= info
;
747 call
->id
= SteamAPI_ISteamRemoteStorage_UGCDownloadToLocation(
749 details
.m_hPreviewFile
, info
->abs_preview_image
, 1 );
751 vg_info( "preview file id: " PRINTF_U64
"\n",
752 details
.m_hPreviewFile
);
757 vg_error( "GetQueryUGCResult: Index out of range\n" );
763 * -----------------------------------------------------------------------------
767 * View a page of results on the sidebar
769 VG_STATIC
void workshop_view_page( int req
)
771 if( workshop_form
.ugc_query
.result
!= k_EResultOK
){
772 vg_error( "Tried to change page without complete data\n" );
776 int page
= VG_MAX(VG_MIN(req
, workshop_form
.view_published_page_count
-1),0),
777 start
= page
* WORKSHOP_VIEW_PER_PAGE
,
778 end
= VG_MIN( (page
+1) * WORKSHOP_VIEW_PER_PAGE
,
779 workshop_form
.ugc_query
.returned_item_count
),
782 vg_info( "View page %d\n", page
);
784 workshop_form
.view_published_page_id
= page
;
785 workshop_form
.published_files_list_length
= count
;
786 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
788 for( int i
=0; i
<count
; i
++ ){
789 struct published_file
*pfile
= &workshop_form
.published_files_list
[i
];
791 SteamUGCDetails_t details
;
792 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC
,
793 workshop_form
.ugc_query
.handle
,
797 if( details
.m_eResult
!= k_EResultOK
){
798 snprintf( pfile
->title
, 80, "Error (%d)", details
.m_eResult
);
801 vg_strncpy( details
.m_rgchTitle
, pfile
->title
, 80,
802 k_strncpy_always_add_null
);
805 pfile
->result
= details
.m_eResult
;
806 pfile
->result_index
= start
+i
;
809 pfile
->result
= k_EResultValueOutOfRange
;
810 pfile
->result_index
= -1;
811 snprintf( pfile
->title
, 80, "Error (invalid index)" );
817 * Steam API result for when we recieve submitted UGC information about the user
819 VG_STATIC
void on_workshop_UGCQueryComplete( void *data
, void *userdata
)
821 SteamUGCQueryCompleted_t
*query
= data
;
822 workshop_form
.ugc_query
.result
= query
->m_eResult
;
824 if( query
->m_eResult
== k_EResultOK
){
825 if( query
->m_unTotalMatchingResults
> 50 ){
826 vg_warn( "You have %d items submitted, "
827 "we can only view the last 50\n" );
830 workshop_form
.ugc_query
.all_item_count
= query
->m_unTotalMatchingResults
;
831 workshop_form
.ugc_query
.returned_item_count
=
832 query
->m_unNumResultsReturned
;
834 workshop_form
.ugc_query
.handle
= query
->m_handle
;
835 workshop_form
.view_published_page_count
=
836 (query
->m_unNumResultsReturned
+WORKSHOP_VIEW_PER_PAGE
-1)/
837 WORKSHOP_VIEW_PER_PAGE
;
838 workshop_form
.view_published_page_id
= 0;
839 workshop_form
.published_files_list_length
= 0;
841 workshop_view_page( 0 );
844 vg_error( "Steam UGCQuery failed (%d)\n", query
->m_eResult
);
845 workshop_form
.view_published_page_count
= 0;
846 workshop_form
.view_published_page_id
= 0;
847 workshop_form
.published_files_list_length
= 0;
849 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
850 SteamAPI_ISteamUGC_ReleaseQueryUGCRequest( hSteamUGC
, query
->m_handle
);
855 * Console command to open the workshop publisher
857 VG_STATIC
int workshop_submit_command( int argc
, const char *argv
[] )
860 ui_start_modal( "Steam API is not initialized\n", UI_MODAL_BAD
);
864 workshop_form
.page
= k_workshop_form_open
;
865 workshop_form
.view_published_page_count
= 0;
866 workshop_form
.view_published_page_id
= 0;
867 workshop_form
.published_files_list_length
= 0;
868 workshop_form
.ugc_query
.result
= k_EResultNone
;
870 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
872 ISteamUser
*hSteamUser
= SteamAPI_SteamUser();
874 steamid
.m_unAll64Bits
= SteamAPI_ISteamUser_GetSteamID( hSteamUser
);
876 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
877 call
->p_handler
= on_workshop_UGCQueryComplete
;
878 call
->userdata
= NULL
;
879 UGCQueryHandle_t handle
= SteamAPI_ISteamUGC_CreateQueryUserUGCRequest
882 steamid
.m_comp
.m_unAccountID
,
883 k_EUserUGCList_Published
,
884 k_EUGCMatchingUGCType_Items
,
885 k_EUserUGCListSortOrder_CreationOrderDesc
,
886 SKATERIFT_APPID
, SKATERIFT_APPID
,
888 SteamAPI_ISteamUGC_SetReturnMetadata( hSteamUGC
, handle
, 1 );
889 call
->id
= SteamAPI_ISteamUGC_SendQueryUGCRequest( hSteamUGC
, handle
);
893 VG_STATIC
void workshop_init(void)
895 vg_console_reg_cmd( "workshop_submit", workshop_submit_command
, NULL
);
898 VG_STATIC
void workshop_render_world_preview(void){
899 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
901 glClearColor( 0.0f
, 0.0f
, 0.3f
, 1.0f
);
902 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
903 glEnable( GL_DEPTH_TEST
);
904 glDisable( GL_BLEND
);
906 render_world( localplayer
.viewable_world
, &main_camera
, 1 );
908 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
909 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
913 * Redraw the model file into the workshop framebuffer
915 VG_STATIC
void workshop_render_board_preview(void){
916 if( !workshop_form
.ptr_ent
){
920 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
922 glClearColor( 0.0f
, 0.0f
, 0.3f
, 1.0f
);
923 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
924 glEnable( GL_DEPTH_TEST
);
925 glDisable( GL_BLEND
);
927 ent_swspreview
*swsprev
= workshop_form
.ptr_ent
;
928 world_instance
*world
= workshop_form
.view_world
;
930 ent_camera
*ref
= mdl_arritm( &world
->ent_camera
,
931 mdl_entity_id_id(swsprev
->id_camera
) );
932 ent_marker
*display
= mdl_arritm( &world
->ent_marker
,
933 mdl_entity_id_id(swsprev
->id_display
) ),
934 *display1
= mdl_arritm( &world
->ent_marker
,
935 mdl_entity_id_id(swsprev
->id_display1
) );
938 v3_add( display
->transform
.co
, display1
->transform
.co
, baseco
);
939 v3_muls( baseco
, 0.5f
, baseco
);
943 v3_sub( display
->transform
.co
, ref
->transform
.co
, basevector
);
944 float dist
= v3_length( basevector
);
947 player_vector_angles( baseangles
, basevector
, 1.0f
, 0.0f
);
949 v2_add( workshop_form
.view_angles
, baseangles
, cam
.angles
);
950 cam
.angles
[2] = 0.0f
;
952 float sX
= sinf( cam
.angles
[0] ),
953 cX
= cosf( cam
.angles
[0] ),
954 sY
= sinf( cam
.angles
[1] ),
955 cY
= cosf( cam
.angles
[1] );
957 v3f offset
= { -sX
* cY
, sY
, cX
* cY
};
959 v3_muladds( display
->transform
.co
, offset
,
960 dist
*workshop_form
.view_dist
, cam
.pos
);
962 cam
.pos
[0] += -sX
*workshop_form
.view_offset
[2];
963 cam
.pos
[2] += cX
*workshop_form
.view_offset
[2];
964 cam
.pos
[0] += cX
*workshop_form
.view_offset
[0];
965 cam
.pos
[2] += sX
*workshop_form
.view_offset
[0];
966 cam
.pos
[1] += workshop_form
.view_offset
[1];
972 camera_update_transform( &cam
);
973 camera_update_view( &cam
);
974 camera_update_projection( &cam
);
975 camera_finalize( &cam
);
978 mdl_transform_m4x3( &display
->transform
, mmdl
);
979 mdl_transform_m4x3( &display1
->transform
, mmdl1
);
981 /* force update this for nice shadows. its usually set in the world
982 * pre-render step, but that includes timer stuff
984 struct player_board
*board
= &workshop_form
.board_model
;
985 struct ub_world_lighting
*ubo
= &world
->ub_lighting
;
987 v3_copy((v3f
){0.0f
,0.1f
, board
->truck_positions
[0][2]}, vp0
);
988 v3_copy((v3f
){0.0f
,0.1f
, board
->truck_positions
[1][2]}, vp1
);
989 m4x3_mulv( mmdl1
, vp0
, ubo
->g_board_0
);
990 m4x3_mulv( mmdl1
, vp1
, ubo
->g_board_1
);
991 glBindBuffer( GL_UNIFORM_BUFFER
, world
->ubo_lighting
);
992 glBufferSubData( GL_UNIFORM_BUFFER
, 0,
993 sizeof(struct ub_world_lighting
), &world
->ub_lighting
);
995 render_world( world
, &cam
, 1 );
996 render_board( &cam
, world
, board
, mmdl
, k_board_shader_entity
);
997 render_board( &cam
, world
, board
, mmdl1
, k_board_shader_entity
);
999 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
1000 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
1004 * ImGUI section for workshop form
1005 * -----------------------------------------------------------------------------
1008 VG_STATIC
void workshop_changed_model_path( char *buf
, u32 len
){
1009 workshop_form
.submission
.submit_file_and_image
= 1;
1012 VG_STATIC
void workshop_changed_title( char *buf
, u32 len
){
1013 workshop_form
.submission
.submit_title
= 1;
1016 VG_STATIC
void workshop_changed_description( char *buf
, u32 len
){
1017 workshop_form
.submission
.submit_description
= 1;
1020 VG_STATIC
void workshop_form_gui_page_undecided( ui_rect content
){
1022 rect_copy( content
, box
);
1024 box
[2] = (box
[2]*2)/3;
1025 ui_rect_center( content
, box
);
1028 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1029 ui_text( row
, "Select the type of item\n", 1, k_ui_align_middle_center
,0);
1030 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1031 ui_enum( row
, "Type:", workshop_form_type_opts
,
1032 3, &workshop_form
.submission
.submission_type_selection
);
1033 ui_split( box
, k_ui_axis_h
, 8, 0, row
, box
);
1034 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1036 ui_rect button_l
, button_r
;
1037 rect_copy( row
, button_l
);
1038 button_l
[2] = 128*2;
1039 ui_rect_center( row
, button_l
);
1040 ui_split_ratio( button_l
, k_ui_axis_v
, 0.5f
, 2, button_l
, button_r
);
1042 if( workshop_form
.submission
.submission_type_selection
.value
!=
1043 k_addon_type_none
){
1044 if( ui_button_text( button_l
, "OK", 1 ) ){
1045 enum addon_type type
=
1046 workshop_form
.submission
.submission_type_selection
.value
;
1047 workshop_form
.submission
.type
= type
;
1049 if( type
== k_addon_type_world
){
1050 workshop_form
.view_changed
= 1;
1051 workshop_form
.file_intent
= k_workshop_form_file_intent_new
;
1056 ui_fill( button_l
, ui_colour(k_ui_bg
) );
1057 ui_text( button_l
, "OK", 1, k_ui_align_middle_center
,
1058 ui_colour(k_ui_bg
+4) );
1061 if( ui_button_text( button_r
, "Cancel", 1 ) ){
1062 workshop_form
.page
= k_workshop_form_open
;
1063 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1067 VG_STATIC
void workshop_form_gui_draw_preview( ui_rect img_box
){
1068 enum addon_type type
= workshop_form
.submission
.type
;
1069 if( workshop_form
.file_intent
== k_workshop_form_file_intent_keep_old
){
1070 ui_image( img_box
, gpipeline
.fb_workshop_preview
->attachments
[0].id
);
1072 else if( workshop_form
.file_intent
== k_workshop_form_file_intent_new
){
1073 ui_image( img_box
, gpipeline
.fb_workshop_preview
->attachments
[0].id
);
1075 if( type
== k_addon_type_world
){
1079 int hover
= ui_inside_rect( img_box
, vg_ui
.mouse
),
1080 target
= ui_inside_rect( img_box
, vg_ui
.mouse_click
);
1082 if( ui_click_down(UI_MOUSE_MIDDLE
) && target
){
1083 v3_copy( workshop_form
.view_offset
,
1084 workshop_form
.view_offset_begin
);
1086 else if( ui_click_down(UI_MOUSE_LEFT
) && target
){
1087 v2_copy( workshop_form
.view_angles
,
1088 workshop_form
.view_angles_begin
);
1091 if( ui_clicking(UI_MOUSE_MIDDLE
) && target
){
1092 v2f delta
= { vg_ui
.mouse
[0]-vg_ui
.mouse_click
[0],
1093 vg_ui
.mouse
[1]-vg_ui
.mouse_click
[1] };
1095 float *begin
= workshop_form
.view_offset_begin
,
1096 *offset
= workshop_form
.view_offset
;
1097 offset
[0] = vg_clampf( begin
[0]-delta
[0]*0.002f
, -1.0f
, 1.0f
);
1098 offset
[2] = vg_clampf( begin
[2]-delta
[1]*0.002f
, -1.0f
, 1.0f
);
1099 workshop_form
.view_changed
= 1;
1101 else if( ui_clicking(UI_MOUSE_LEFT
) && target
){
1102 v2f delta
= { vg_ui
.mouse
[0]-vg_ui
.mouse_click
[0],
1103 vg_ui
.mouse
[1]-vg_ui
.mouse_click
[1] };
1106 v2_muladds( workshop_form
.view_angles_begin
, delta
, 0.002f
, angles
);
1108 float limit
= VG_PIf
*0.2f
;
1110 angles
[0] = vg_clampf( angles
[0], -limit
, limit
);
1111 angles
[1] = vg_clampf( angles
[1], -limit
, limit
);
1113 v2_copy( angles
, workshop_form
.view_angles
);
1114 workshop_form
.view_changed
= 1;
1117 if( !ui_clicking(UI_MOUSE_LEFT
) && hover
){
1118 float zoom
= workshop_form
.view_dist
;
1119 zoom
+= vg
.mouse_wheel
[1] * -0.07f
;
1120 zoom
= vg_clampf( zoom
, 0.4f
, 2.0f
);
1122 if( zoom
!= workshop_form
.view_dist
){
1123 workshop_form
.view_changed
= 1;
1124 workshop_form
.view_dist
= zoom
;
1129 ui_text( img_box
, "No image", 1, k_ui_align_middle_center
,
1130 ui_colour( k_ui_orange
) );
1134 VG_STATIC
void workshop_form_gui_edit_page( ui_rect content
){
1135 enum addon_type type
= workshop_form
.submission
.type
;
1137 if( type
== k_addon_type_none
){
1138 workshop_form_gui_page_undecided( content
);
1142 ui_rect image_plane
;
1143 ui_split( content
, k_ui_axis_h
, 300, 0, image_plane
, content
);
1144 ui_fill( image_plane
, ui_colour( k_ui_bg
+0 ) );
1147 ui_fit_item( image_plane
, (ui_px
[2]){ 3, 2 }, img_box
);
1148 workshop_form_gui_draw_preview( img_box
);
1151 ui_rect null
, file_entry
, file_button
, file_label
;
1152 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1153 ui_split( content
, k_ui_axis_h
, 28, 0, file_entry
, content
);
1155 if( workshop_form
.submission
.type
== k_addon_type_board
){
1156 ui_label( file_entry
, "Addon folder: skaterift/boards/",
1160 ui_label( file_entry
, "Addon folder: skaterift/maps/",
1164 if( type
== k_addon_type_world
){
1165 struct ui_textbox_callbacks callbacks
= {
1166 .change
= workshop_changed_model_path
1168 ui_textbox( file_entry
, workshop_form
.addon_folder
,
1169 vg_list_size(workshop_form
.addon_folder
), 0, &callbacks
);
1172 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 ) ){
1178 player_board_unload( &workshop_form
.board_model
);
1179 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1180 workshop_form
.addon_folder
[0] = '\0';
1184 struct ui_textbox_callbacks callbacks
= {
1185 .change
= workshop_changed_model_path
1188 ui_textbox( file_entry
, workshop_form
.addon_folder
,
1189 vg_list_size(workshop_form
.addon_folder
), 0, &callbacks
);
1191 if( ui_button_text( file_button
, "Load", 1 ) ){
1192 workshop_op_load_model();
1197 ui_rect title_entry
, label
;
1198 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1199 ui_split( content
, k_ui_axis_h
, 28, 0, title_entry
, content
);
1201 const char *str_title
= "Title:", *str_desc
= "Description:";
1202 ui_split( title_entry
, k_ui_axis_v
,
1203 ui_text_line_width(str_title
)+8, 0, label
, title_entry
);
1205 ui_rect vis_dropdown
;
1206 ui_split_ratio( title_entry
, k_ui_axis_v
, 0.6f
, 16,
1207 title_entry
, vis_dropdown
);
1211 struct ui_textbox_callbacks callbacks
= {
1212 .change
= workshop_changed_title
1214 ui_text( label
, str_title
, 1, k_ui_align_middle_left
, 0 );
1215 ui_textbox( title_entry
, workshop_form
.submission
.title
,
1216 vg_list_size(workshop_form
.submission
.title
), 0, &callbacks
);
1219 /* visibility option */
1221 ui_enum( vis_dropdown
, "Visibility:", workshop_form_visibility_opts
,
1222 4, &workshop_form
.submission
.visibility
);
1225 /* description box */
1227 struct ui_textbox_callbacks callbacks
= {
1228 .change
= workshop_changed_description
1231 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1232 ui_split( content
, k_ui_axis_h
, 28, 0, label
, content
);
1233 ui_split( content
, k_ui_axis_h
, 28*4, 0, desc_entry
, content
);
1234 ui_text( label
, str_desc
, 1, k_ui_align_middle_left
, 0 );
1235 ui_textbox( desc_entry
, workshop_form
.submission
.description
,
1236 vg_list_size(workshop_form
.submission
.description
),
1237 UI_TEXTBOX_MULTILINE
|UI_TEXTBOX_WRAP
, &callbacks
);
1240 /* submissionable */
1241 ui_rect submission_row
;
1242 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1243 ui_split( content
, k_ui_axis_h
, content
[3]-32-8, 0, content
,
1246 ui_rect submission_center
;
1247 rect_copy( submission_row
, submission_center
);
1248 submission_center
[2] = 256;
1249 ui_rect_center( submission_row
, submission_center
);
1251 ui_rect btn_left
, btn_right
;
1252 ui_split_ratio( submission_center
, k_ui_axis_v
, 0.5f
, 8,
1253 btn_left
, btn_right
);
1255 if( ui_button_text( btn_left
, "Publish", 1 ) ){
1256 workshop_op_submit();
1258 if( ui_button_text( btn_right
, "Cancel", 1 ) ){
1259 workshop_form
.page
= k_workshop_form_open
;
1260 player_board_unload( &workshop_form
.board_model
);
1261 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1265 const char *disclaimer_text
=
1266 "By submitting this item, you agree to the workshop terms of service";
1268 ui_rect disclaimer_row
, inner
, link
;
1269 ui_split( content
, k_ui_axis_h
, 8, 0, null
, content
);
1270 ui_split( content
, k_ui_axis_h
, content
[3]-32, 0, content
,
1273 ui_px btn_width
= 32;
1275 rect_copy( disclaimer_row
, inner
);
1276 inner
[2] = ui_text_line_width( disclaimer_text
) + btn_width
+8;
1278 ui_rect_center( disclaimer_row
, inner
);
1279 ui_split( inner
, k_ui_axis_v
, inner
[2]-btn_width
, 0, label
, btn_right
);
1280 ui_rect_pad( btn_right
, (ui_px
[2]){2,2} );
1282 if( ui_button_text( btn_right
, "\x91", 2 ) ){
1283 ISteamFriends
*hSteamFriends
= SteamAPI_SteamFriends();
1284 SteamAPI_ISteamFriends_ActivateGameOverlayToWebPage( hSteamFriends
,
1285 "https://steamcommunity.com/sharedfiles/workshoplegalagreement",
1286 k_EActivateGameOverlayToWebPageMode_Default
);
1289 ui_text( label
, disclaimer_text
, 1, k_ui_align_middle_left
,
1290 ui_colour( k_ui_fg
+4 ) );
1293 VG_STATIC
void workshop_form_gui_sidebar( ui_rect sidebar
)
1295 ui_fill( sidebar
, ui_colour( k_ui_bg
+2 ) );
1298 ui_split( sidebar
, k_ui_axis_h
, 28, 0, title
, sidebar
);
1300 if( workshop_form
.page
== k_workshop_form_edit
){
1301 ui_text( title
, "Editing", 1, k_ui_align_middle_center
, 0 );
1302 ui_split( sidebar
, k_ui_axis_h
, 28, 0, title
, sidebar
);
1304 if( workshop_form
.submission
.type
!= k_addon_type_none
){
1307 vg_strnull( &str
, buf
, 512 );
1309 if( workshop_form
.submission
.file_id
)
1310 vg_strcat( &str
, "Editing an existing " );
1312 vg_strcat( &str
, "Creating a new " );
1314 if( workshop_form
.submission
.type
== k_addon_type_board
)
1315 vg_strcat( &str
, "skateboard." );
1316 else if( workshop_form
.submission
.type
== k_addon_type_world
)
1317 vg_strcat( &str
, "world." );
1319 vg_strcat( &str
, "???." );
1321 ui_text( title
, buf
, 1, k_ui_align_middle_center
,
1322 ui_colour(k_ui_fg
+4) );
1328 * sidebar existing entries panel
1330 ui_text( title
, "Your submissions", 1, k_ui_align_middle_center
, 0 );
1332 ui_rect controls
, btn_create_new
;
1333 ui_split( sidebar
, k_ui_axis_h
, 32, 0, controls
, sidebar
);
1334 ui_split( sidebar
, k_ui_axis_h
, -32, 0, sidebar
, btn_create_new
);
1335 ui_fill( controls
, ui_colour( k_ui_bg
+1 ) );
1338 strcpy( buf
, "page " );
1340 i
+= highscore_intl( buf
+i
, workshop_form
.view_published_page_id
+1, 4 );
1342 i
+= highscore_intl( buf
+i
, workshop_form
.view_published_page_count
, 4 );
1345 ui_rect_pad( controls
, (ui_px
[2]){0,4} );
1347 ui_split_ratio( controls
, k_ui_axis_v
, 0.25f
, 0, info
, controls
);
1348 ui_text( info
, buf
, 1, k_ui_align_middle_center
, 0 );
1350 ui_rect btn_left
, btn_right
;
1351 ui_split_ratio( controls
, k_ui_axis_v
, 0.5f
, 2, btn_left
, btn_right
);
1353 if( ui_button_text( btn_left
, "newer", 1 ) ){
1354 workshop_view_page( workshop_form
.view_published_page_id
-1 );
1357 if( ui_button_text( btn_right
, "older", 1 ) ){
1358 workshop_view_page( workshop_form
.view_published_page_count
+1 );
1361 if( ui_button_text( btn_create_new
, "Create New Item", 1 ) ){
1362 workshop_reset_submission_data();
1363 workshop_form
.submission
.submit_title
= 1;
1364 workshop_form
.submission
.submit_description
= 1;
1365 workshop_form
.submission
.submit_file_and_image
= 1;
1366 workshop_form
.page
= k_workshop_form_edit
;
1369 for( int i
=0; i
<workshop_form
.published_files_list_length
; i
++ ){
1371 ui_split( sidebar
, k_ui_axis_h
, 28, 0, item
, sidebar
);
1372 ui_rect_pad( item
, (ui_px
[2]){4,4} );
1374 struct published_file
*pfile
= &workshop_form
.published_files_list
[i
];
1375 if( ui_button_text( item
, pfile
->title
, 1 ) ){
1376 if( pfile
->result
== k_EResultOK
){
1377 vg_info( "Select index: %d\n", pfile
->result_index
);
1378 workshop_op_download_and_view_submission( pfile
->result_index
);
1381 vg_warn( "Cannot select that item, result not OK\n" );
1387 VG_STATIC
void workshop_form_gui(void)
1389 enum workshop_form_page stable_page
= workshop_form
.page
;
1390 if( stable_page
== k_workshop_form_hidden
) return;
1393 ui_rect screen
= { 0, 0, vg
.window_x
, vg
.window_y
};
1394 ui_rect window
= { 0, 0, 1000, 700 };
1395 ui_rect_center( screen
, window
);
1396 vg_ui
.wants_mouse
= 1;
1398 ui_fill( window
, ui_colour( k_ui_bg
+1 ) );
1399 ui_outline( window
, 1, ui_colour( k_ui_bg
+7 ) );
1401 ui_rect title
, panel
;
1402 ui_split( window
, k_ui_axis_h
, 28, 0, title
, panel
);
1403 ui_fill( title
, ui_colour( k_ui_bg
+7 ) );
1404 ui_text( title
, "Workshop tool", 1, k_ui_align_middle_center
,
1405 ui_colourcont(k_ui_bg
+7) );
1407 ui_rect quit_button
;
1408 ui_split( title
, k_ui_axis_v
, title
[2]-title
[3], 2, title
, quit_button
);
1410 if( vg_loader_availible() ){
1411 if( ui_button_text( quit_button
, "X", 1 ) ){
1412 workshop_quit_form();
1418 * temporary operation blinders, we don't yet have a nice way to show the
1419 * user that we're doing something uninterruptable, so the code just
1420 * escapes here and we show them a basic string
1423 if( !vg_loader_availible() ){
1424 const char *op_string
= "The programmer has not bothered to describe "
1425 "the current operation that is running.";
1427 switch( skaterift
.op
){
1428 case k_workshop_form_op_loading_model
:
1429 op_string
= "Operation in progress: Loading model file.";
1431 case k_workshop_form_op_publishing_update
:
1432 op_string
= "Operation in progress: publishing submission update "
1435 case k_workshop_form_op_downloading_submission
:
1436 op_string
= "Operation in progress: downloading existing submission"
1437 " from Steam services.";
1442 ui_text( panel
, op_string
, 1, k_ui_align_middle_center
, 0 );
1446 /* re draw board preview if need to */
1447 if( (stable_page
== k_workshop_form_edit
) &&
1448 workshop_form
.view_changed
&&
1449 workshop_form
.file_intent
== k_workshop_form_file_intent_new
)
1451 enum addon_type type
= workshop_form
.submission
.type
;
1452 if( type
== k_addon_type_board
){
1453 workshop_render_board_preview();
1455 else if( type
== k_addon_type_world
){
1456 vg_success( "Renders world preview\n" );
1457 workshop_render_world_preview();
1459 workshop_form
.view_changed
= 0;
1462 struct workshop_form
*form
= &workshop_form
;
1464 ui_rect sidebar
, content
;
1465 ui_split_ratio( panel
, k_ui_axis_v
, 0.3f
, 1, sidebar
, content
);
1468 ui_rect_pad( content
, (ui_px
[2]){8,8} );
1470 if( stable_page
== k_workshop_form_edit
){
1471 workshop_form_gui_edit_page( content
);
1473 else if( stable_page
== k_workshop_form_open
){
1474 ui_text( content
, "Nothing selected.", 1, k_ui_align_middle_center
,
1475 ui_colour( k_ui_fg
+4 ) );
1477 else if( stable_page
>= k_workshop_form_cclosing
){
1478 ui_rect submission_row
;
1479 ui_split( content
, k_ui_axis_h
, content
[3]-32-8, 0, content
,
1484 if( stable_page
== k_workshop_form_closing_bad
)
1485 colour
= ui_colour( k_ui_red
+k_ui_brighter
);
1487 colour
= ui_colour( k_ui_green
+k_ui_brighter
);
1489 ui_text( content
, workshop_form
.failure_or_success_string
, 1,
1490 k_ui_align_middle_center
, colour
);
1492 ui_rect submission_center
;
1493 rect_copy( submission_row
, submission_center
);
1494 submission_center
[2] = 128;
1495 ui_rect_center( submission_row
, submission_center
);
1496 ui_rect_pad( submission_center
, (ui_px
[2]){8,8} );
1498 if( ui_button_text( submission_center
, "OK", 1 ) ){
1499 workshop_form
.page
= k_workshop_form_open
;
1503 workshop_form_gui_sidebar( sidebar
);
1507 * Some async api stuff
1508 * -----------------------------------------------------------------------------
1511 VG_STATIC
void async_workshop_get_filepath( void *data
, u32 len
)
1513 struct async_workshop_filepath_info
*info
= data
;
1518 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
1519 if( !SteamAPI_ISteamUGC_GetItemInstallInfo( hSteamUGC
, info
->id
, &_size
,
1520 info
->buf
, info
->len
, &_ts
))
1522 vg_error( "GetItemInstallInfo failed\n" );
1523 info
->buf
[0] = '\0';
1527 VG_STATIC
void async_workshop_get_installed_files( void *data
, u32 len
)
1529 struct async_workshop_installed_files_info
*info
= data
;
1531 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
1532 u32 count
= SteamAPI_ISteamUGC_GetSubscribedItems( hSteamUGC
, info
->buffer
,
1535 vg_info( "Found %u subscribed items\n", count
);
1538 for( u32 i
=0; i
<count
; i
++ ){
1539 u32 state
= SteamAPI_ISteamUGC_GetItemState( hSteamUGC
, info
->buffer
[i
] );
1540 if( state
& k_EItemStateInstalled
){
1541 info
->buffer
[j
++] = info
->buffer
[i
];
1548 #endif /* WORKSHOP_C */