2 #include "vg/vg_engine.h"
4 #include "vg/vg_image.h"
6 #include "vg/vg_binstr.h"
7 #include "vg/vg_loader.h"
8 #include "ent_skateshop.h"
10 #include "vg/vg_steam_auth.h"
11 #include "vg/vg_steam_ugc.h"
12 #include "vg/vg_steam_friends.h"
16 struct workshop_form workshop_form
;
18 static struct ui_enum_opt workshop_form_visibility_opts
[] = {
19 { k_ERemoteStoragePublishedFileVisibilityPublic
, "Public" },
20 { k_ERemoteStoragePublishedFileVisibilityUnlisted
, "Unlisted" },
21 { k_ERemoteStoragePublishedFileVisibilityFriendsOnly
, "Friends Only" },
22 { k_ERemoteStoragePublishedFileVisibilityPrivate
, "Private" },
25 static struct ui_enum_opt workshop_form_type_opts
[] = {
26 { k_addon_type_none
, "None" },
27 { k_addon_type_board
, "Board" },
28 { k_addon_type_world
, "World" },
29 { k_addon_type_player
, "Player" },
33 * Close the form and discard UGC query result
35 static void workshop_quit_form(void){
36 player_board_unload( &workshop_form
.board_model
);
37 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
39 if( workshop_form
.ugc_query
.result
== k_EResultOK
){
40 workshop_form
.ugc_query
.result
= k_EResultNone
;
42 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
43 SteamAPI_ISteamUGC_ReleaseQueryUGCRequest(
44 hSteamUGC
, workshop_form
.ugc_query
.handle
);
47 workshop_form
.page
= k_workshop_form_hidden
;
48 workshop_form
.op
= k_workshop_op_none
;
52 * Delete all information about the submission
54 static void workshop_reset_submission_data(void)
56 workshop_form
.submission
.file_id
= 0; /* assuming id of 0 is none/invalid */
57 workshop_form
.submission
.description
[0] = '\0';
58 workshop_form
.submission
.title
[0] = '\0';
59 workshop_form
.submission
.author
[0] = '\0';
60 workshop_form
.submission
.submission_type_selection
=
62 workshop_form
.submission
.type
= k_addon_type_none
;
64 workshop_form
.submission
.visibility
=
65 k_ERemoteStoragePublishedFileVisibilityPublic
;
67 workshop_form
.addon_folder
[0] = '\0';
68 player_board_unload( &workshop_form
.board_model
);
69 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
74 * Mostly copies of what it sais on the Steam API documentation
76 static const char *workshop_EResult_user_string( EResult result
)
79 case k_EResultInsufficientPrivilege
:
80 return "Your account is currently restricted from uploading content "
81 "due to a hub ban, account lock, or community ban. You need to "
82 "contact Steam Support to resolve the issue.";
84 return "You do not have permission to upload content to this hub "
85 "because you have an active VAC or Game ban.";
86 case k_EResultTimeout
:
87 return "The operation took longer than expected, so it was discarded. "
89 case k_EResultNotLoggedOn
:
90 return "You are currently not logged into Steam.";
91 case k_EResultServiceUnavailable
:
92 return "The workshop server is having issues or is unavailable, "
94 case k_EResultInvalidParam
:
95 return "One of the submission fields contains something not being "
96 "accepted by that field.";
97 case k_EResultAccessDenied
:
98 return "There was a problem trying to save the title and description. "
100 case k_EResultLimitExceeded
:
101 return "You have exceeded your Steam Cloud quota. If you wish to "
102 "upload this file, you must remove some published items.";
103 case k_EResultFileNotFound
:
104 return "The uploaded file could not be found.";
105 case k_EResultDuplicateRequest
:
106 return "The file was already successfully uploaded.";
107 case k_EResultDuplicateName
:
108 return "You already have a Steam Workshop item with that name.";
109 case k_EResultServiceReadOnly
:
110 return "Due to a recent password or email change, you are not allowed "
111 "to upload new content. Usually this restriction will expire in"
112 " 5 days, but can last up to 30 days if the account has been "
113 "inactive recently.";
115 return "Operation failed for an error which has not been accounted for "
116 "by the programmer. Try again, sorry :)";
121 * op: k_workshop_form_op_publishing_update
122 * ----------------------------------------------------------------------------
126 * The endpoint of this operation
128 static void on_workshop_update_result( void *data
, void *user
)
130 vg_info( "Recieved workshop update result\n" );
131 SubmitItemUpdateResult_t
*result
= data
;
133 /* this seems to be set here, but my account definitely has accepted it */
134 if( result
->m_bUserNeedsToAcceptWorkshopLegalAgreement
){
135 vg_warn( "Workshop agreement currently not accepted\n" );
138 if( result
->m_eResult
== k_EResultOK
){
139 workshop_form
.page
= k_workshop_form_closing_good
;
140 workshop_form
.failure_or_success_string
= "Uploaded workshop file!";
141 vg_success( "file uploaded\n" );
144 workshop_form
.page
= k_workshop_form_closing_bad
;
145 workshop_form
.failure_or_success_string
=
146 workshop_EResult_user_string( result
->m_eResult
);
148 vg_error( "Error with the submitted file (%d)\n", result
->m_eResult
);
150 workshop_form
.op
= k_workshop_op_none
;
153 static const char *workshop_filetype_folder(void){
154 enum addon_type type
= workshop_form
.submission
.type
;
155 if ( type
== k_addon_type_board
) return "boards/";
156 else if( type
== k_addon_type_player
) return "playermodels/";
157 else if( type
== k_addon_type_world
) return "maps/";
159 return "unknown_addon_type/";
163 * reciever on completion of packaging the files, it will then start the item
164 * update with Steam API
166 static void workshop_form_upload_submission( PublishedFileId_t file_id
,
169 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
170 UGCUpdateHandle_t handle
171 = SteamAPI_ISteamUGC_StartItemUpdate( hSteamUGC
, SKATERIFT_APPID
,
174 /* TODO: Handle failure cases for these */
176 SteamAPI_ISteamUGC_SetItemMetadata( hSteamUGC
, handle
, metadata
);
178 if( workshop_form
.submission
.submit_title
){
179 vg_info( "Setting title\n" );
180 SteamAPI_ISteamUGC_SetItemTitle( hSteamUGC
, handle
,
181 workshop_form
.submission
.title
);
184 if( workshop_form
.submission
.submit_description
){
185 vg_info( "Setting description\n" );
186 SteamAPI_ISteamUGC_SetItemDescription( hSteamUGC
, handle
,
187 workshop_form
.submission
.description
);
190 if( workshop_form
.submission
.submit_file_and_image
){
193 vg_strnull( &folder
, path_buf
, 4096 );
194 vg_strcat( &folder
, vg
.base_path
);
196 vg_strcat( &folder
, workshop_filetype_folder() );
197 vg_strcat( &folder
, workshop_form
.addon_folder
);
199 vg_info( "Setting item content\n" );
200 SteamAPI_ISteamUGC_SetItemContent( hSteamUGC
, handle
, folder
.buffer
);
202 vg_str preview
= folder
;
203 vg_strcat( &preview
, "/preview.jpg" );
205 vg_info( "Setting preview image\n" );
206 SteamAPI_ISteamUGC_SetItemPreview( hSteamUGC
, handle
, preview
.buffer
);
209 vg_info( "Setting visibility\n" );
210 SteamAPI_ISteamUGC_SetItemVisibility( hSteamUGC
, handle
,
211 workshop_form
.submission
.visibility
);
213 vg_info( "Submitting updates\n" );
214 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
215 call
->userdata
= NULL
;
216 call
->p_handler
= on_workshop_update_result
;
217 call
->id
= SteamAPI_ISteamUGC_SubmitItemUpdate( hSteamUGC
, handle
, "" );
221 * Steam API call result for when we've created a new item on their network, or
222 * not, if it has failed
224 static void on_workshop_createitem( void *data
, void *user
)
226 CreateItemResult_t
*result
= data
;
228 if( result
->m_eResult
== k_EResultOK
){
229 vg_info( "Created workshop file with id: %lu\n",
230 result
->m_nPublishedFileId
);
232 if( result
->m_bUserNeedsToAcceptWorkshopLegalAgreement
){
233 vg_warn( "Workshop agreement currently not accepted\n" );
236 workshop_form_upload_submission( result
->m_nPublishedFileId
, user
);
239 const char *errstr
= workshop_EResult_user_string( result
->m_eResult
);
242 vg_error( "ISteamUGC_CreateItem() failed(%d): '%s' \n",
243 result
->m_eResult
, errstr
);
246 workshop_form
.page
= k_workshop_form_closing_bad
;
247 workshop_form
.failure_or_success_string
= errstr
;
252 * Starts the workshop upload process through Steam API
254 static void workshop_form_async_submit_begin( void *payload
, u32 size
)
257 /* use existing file */
258 if( workshop_form
.submission
.file_id
){
259 workshop_form_upload_submission( workshop_form
.submission
.file_id
,
263 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
264 call
->userdata
= payload
;
265 call
->p_handler
= on_workshop_createitem
;
266 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
267 call
->id
= SteamAPI_ISteamUGC_CreateItem( hSteamUGC
, SKATERIFT_APPID
,
268 k_EWorkshopFileTypeCommunity
);
273 * Downloads the framebuffer into scratch memory
275 static void workshop_form_async_download_image( void *payload
, u32 size
)
278 render_fb_get_current_res( gpipeline
.fb_workshop_preview
, &w
, &h
);
279 vg_linear_clear( vg_mem
.scratch
);
280 workshop_form
.img_buffer
= vg_linear_alloc( vg_mem
.scratch
, w
*h
*3 );
282 vg_info( "read framebuffer: glReadPixels( %dx%d )\n", w
,h
);
284 glBindFramebuffer( GL_READ_FRAMEBUFFER
, gpipeline
.fb_workshop_preview
->fb
);
285 glReadBuffer( GL_COLOR_ATTACHMENT0
);
286 glReadPixels( 0,0, w
,h
, GL_RGB
, GL_UNSIGNED_BYTE
, workshop_form
.img_buffer
);
288 workshop_form
.img_w
= w
;
289 workshop_form
.img_h
= h
;
293 * Thread which kicks off the upload process
295 static void _workshop_form_submit_thread( void *data
)
297 vg_async_call( workshop_form_async_download_image
, NULL
, 0 );
302 vg_strnull( &folder
, path_buf
, 4096 );
304 vg_strcat( &folder
, workshop_filetype_folder() );
305 vg_strcat( &folder
, workshop_form
.addon_folder
);
307 if( !vg_strgood(&folder
) ){
308 vg_error( "addon folder path too long\n" );
309 workshop_form
.op
= k_workshop_op_none
;
314 * Create the metadata file
315 * -----------------------------------------------------------------------*/
316 u8 descriptor_buf
[ 512 ];
318 vg_msg_init( &descriptor
, descriptor_buf
, sizeof(descriptor_buf
) );
319 vg_linear_clear( vg_mem
.scratch
);
321 /* short description */
322 vg_msg_frame( &descriptor
, "workshop" );
323 vg_msg_wkvstr( &descriptor
, "title", workshop_form
.submission
.title
);
324 //vg_msg_wkvstr( &descriptor, "author", "unknown" );
325 vg_msg_wkvnum( &descriptor
, "type", k_vg_msg_u32
, 1,
326 &workshop_form
.submission
.type
);
327 vg_msg_wkvstr( &descriptor
, "folder", workshop_form
.addon_folder
);
328 vg_msg_end_frame( &descriptor
);
329 //vg_msg_wkvstr( &descriptor, "location", "USA" );
331 char *short_descriptor_str
=
332 vg_linear_alloc( vg_mem
.scratch
, vg_align8(descriptor
.cur
.co
*2+1));
333 vg_bin_str( descriptor_buf
, short_descriptor_str
, descriptor
.cur
.co
);
334 short_descriptor_str
[descriptor
.cur
.co
*2] = '\0';
335 vg_info( "binstr: %s\n", short_descriptor_str
);
338 if( !vg_dir_open( &dir
, folder
.buffer
) ){
339 vg_error( "could not open addon folder '%s'\n", folder
.buffer
);
340 workshop_form
.op
= k_workshop_op_none
;
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" );
368 workshop_form
.op
= k_workshop_op_none
;
372 FILE *fp
= fopen( descriptor_file
.buffer
, "wb" );
374 vg_error( "Could not open addon info file '%s'\n",
375 descriptor_file
.buffer
);
376 workshop_form
.op
= k_workshop_op_none
;
379 fwrite( descriptor_buf
, descriptor
.cur
.co
, 1, fp
);
383 * -----------------------------------------------------------------------*/
384 vg_str preview
= folder
;
385 vg_strcat( &preview
, "/preview.jpg" );
387 if( !vg_strgood(&preview
) ){
388 vg_error( "preview image path too long\n" );
389 workshop_form
.op
= k_workshop_op_none
;
393 int w
= workshop_form
.img_w
,
394 h
= workshop_form
.img_h
;
396 vg_info( "writing: %s (%dx%d @90%%)\n", preview
.buffer
, w
,h
);
397 stbi_flip_vertically_on_write(1);
398 stbi_write_jpg( preview
.buffer
, w
,h
, 3, workshop_form
.img_buffer
, 90 );
400 vg_async_call( workshop_form_async_submit_begin
, short_descriptor_str
, 0 );
404 * Entry point for the publishing submission operation
406 static void workshop_op_submit(void){
407 /* TODO: Show these errors to the user */
408 if( workshop_form
.submission
.submit_title
){
409 if( !workshop_form
.submission
.title
[0] ){
410 ui_start_modal( "Cannot submit because a title is required\n",
412 workshop_form
.op
= k_workshop_op_none
;
417 if( workshop_form
.submission
.submit_description
){
418 if( !workshop_form
.submission
.description
[0] ){
419 ui_start_modal( "Cannot submit because a description is required\n",
421 workshop_form
.op
= k_workshop_op_none
;
426 if( workshop_form
.submission
.submit_file_and_image
){
427 if( workshop_form
.file_intent
== k_workshop_form_file_intent_none
){
428 ui_start_modal( "Cannot submit because the file is "
429 "empty or unspecified\n", UI_MODAL_WARN
);
430 workshop_form
.op
= k_workshop_op_none
;
435 player_board_unload( &workshop_form
.board_model
);
436 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
437 workshop_form
.op
= k_workshop_op_publishing_update
;
439 vg_loader_start( _workshop_form_submit_thread
, NULL
);
443 * op: k_workshop_form_op_loading_model
444 * -----------------------------------------------------------------------------
448 * Reciever for completion of the model file load
450 static void workshop_form_loadmodel_async_complete( void *payload
, u32 size
)
452 v2_zero( workshop_form
.view_angles
);
453 v3_zero( workshop_form
.view_offset
);
454 workshop_form
.view_dist
= 1.0f
;
455 workshop_form
.view_changed
= 1;
456 workshop_form
.file_intent
= k_workshop_form_file_intent_new
;
458 vg_success( "workshop async load complete\n" );
459 workshop_form
.op
= k_workshop_op_none
;
463 * Reciever for failure to load
465 static void workshop_form_loadmodel_async_error( void *payload
, u32 size
){
469 * Thread which loads the model from the disk
471 static void _workshop_form_load_thread( void *data
)
475 vg_strnull( &folder
, path_buf
, 4096 );
477 vg_strcat( &folder
, workshop_filetype_folder() );
478 vg_strcat( &folder
, workshop_form
.addon_folder
);
480 if( !vg_strgood(&folder
) ){
481 vg_error( "workshop async load failed: path too long\n" );
482 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
483 workshop_form
.op
= k_workshop_op_none
;
488 if( !vg_dir_open( &dir
, folder
.buffer
) ){
489 vg_error( "workshop async load failed: could not open folder\n" );
490 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
491 workshop_form
.op
= k_workshop_op_none
;
495 vg_info( "Searching %s for model files\n", folder
.buffer
);
498 while( vg_dir_next_entry(&dir
) ){
499 if( vg_dir_entry_type(&dir
) == k_vg_entry_type_file
){
500 const char *d_name
= vg_dir_entry_name(&dir
);
501 if( d_name
[0] == '.' ) continue;
503 vg_str file
= folder
;
504 vg_strcat( &file
, "/" );
505 vg_strcat( &file
, d_name
);
506 if( !vg_strgood( &file
) ) continue;
508 char *ext
= vg_strch( &file
, '.' );
510 if( strcmp(ext
,".mdl") ) continue;
518 vg_error( "workshop async load failed: no model files found\n" );
519 vg_async_call( workshop_form_loadmodel_async_error
, NULL
, 0 );
520 workshop_form
.op
= k_workshop_op_none
;
524 if( workshop_form
.submission
.type
== k_addon_type_board
)
525 player_board_load( &workshop_form
.board_model
, path_buf
);
526 else if( workshop_form
.submission
.type
== k_addon_type_player
)
527 player_model_load( &workshop_form
.player_model
, path_buf
);
529 vg_async_call( workshop_form_loadmodel_async_complete
, NULL
, 0 );
533 * Entry point for load model operation
535 static void workshop_op_load_model(void){
536 world_instance
*world
= world_current_instance();
537 workshop_form
.view_world
= world
;
539 if( workshop_form
.submission
.type
== k_addon_type_board
){
540 if( mdl_arrcount( &world
->ent_swspreview
) ){
541 workshop_form
.ptr_ent
=
542 mdl_arritm( &world
->ent_swspreview
, 0 );
545 ui_start_modal( "There is no ent_swspreview in the level. \n"
546 "Cannot publish here\n", UI_MODAL_BAD
);
547 workshop_form
.op
= k_workshop_op_none
;
551 else if( workshop_form
.submission
.type
== k_addon_type_player
){}
553 ui_start_modal( "Don't know how to prepare for this item type. \n"
554 "Please contact the developers.\n", UI_MODAL_BAD
);
555 workshop_form
.op
= k_workshop_op_none
;
559 workshop_form
.op
= k_workshop_op_loading_model
;
560 vg_loader_start( _workshop_form_load_thread
, NULL
);
564 * op: k_workshop_form_op_downloading_submission
565 * -----------------------------------------------------------------------------
569 * The image has been decoded and is ready to slap into the framebuffer
571 static void workshop_form_async_imageload( void *data
, u32 len
)
574 struct framebuffer_attachment
*a
=
575 &gpipeline
.fb_workshop_preview
->attachments
[0];
577 glBindTexture( GL_TEXTURE_2D
, a
->id
);
578 glTexSubImage2D( GL_TEXTURE_2D
, 0,0,0,
579 WORKSHOP_PREVIEW_WIDTH
, WORKSHOP_PREVIEW_HEIGHT
,
580 a
->format
, a
->type
, data
);
581 stbi_image_free( data
);
582 vg_success( "Loaded workshop preview image\n" );
585 snprintf( workshop_form
.error_msg
, sizeof(workshop_form
.error_msg
),
586 "Preview image could not be loaded. Reason: %s\n",
587 stbi_failure_reason() );
588 ui_start_modal( workshop_form
.error_msg
, UI_MODAL_BAD
);
590 workshop_form
.op
= k_workshop_op_none
;
594 * Load the image located at ./workshop_preview.jpg into our framebuffer
596 static void _workshop_load_preview_thread( void *data
){
597 char path_buf
[ 4096 ];
599 vg_strnull( &path
, path_buf
, 4096 );
600 vg_strcat( &path
, workshop_filetype_folder() );
601 vg_strcat( &path
, workshop_form
.addon_folder
);
602 vg_strcat( &path
, "/preview.jpg" );
604 if( vg_strgood( &path
) ){
605 stbi_set_flip_vertically_on_load(1);
607 u8
*rgb
= stbi_load( path
.buffer
, &x
, &y
, &nc
, 3 );
610 if( (x
== WORKSHOP_PREVIEW_WIDTH
) && (y
== WORKSHOP_PREVIEW_HEIGHT
) ){
611 vg_async_call( workshop_form_async_imageload
, rgb
, x
*y
*3 );
614 vg_error( "Resolution does not match framebuffer, so we can't"
616 stbi_image_free( rgb
);
617 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
621 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
625 vg_async_call( workshop_form_async_imageload
, NULL
, 0 );
630 * Entry point to view operation
632 static void workshop_op_download_and_view_submission( int result_index
)
634 workshop_form
.op
= k_workshop_op_downloading_submission
;
635 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
636 ISteamRemoteStorage
*hSteamRemoteStorage
= SteamAPI_SteamRemoteStorage();
637 SteamUGCDetails_t details
;
638 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC
,
639 workshop_form
.ugc_query
.handle
,
643 workshop_reset_submission_data();
644 workshop_form
.submission
.submit_description
= 0;
645 workshop_form
.submission
.submit_file_and_image
= 0;
646 workshop_form
.submission
.submit_title
= 0;
648 u8 metadata_buf
[512];
649 char metadata_str
[1024+1];
650 int have_meta
= SteamAPI_ISteamUGC_GetQueryUGCMetadata( hSteamUGC
,
651 workshop_form
.ugc_query
.handle
,
652 result_index
, metadata_str
,
655 vg_strncpy( details
.m_rgchDescription
,
656 workshop_form
.submission
.description
,
657 vg_list_size( workshop_form
.submission
.description
),
658 k_strncpy_always_add_null
);
660 vg_strncpy( details
.m_rgchTitle
,
661 workshop_form
.submission
.title
,
662 vg_list_size( workshop_form
.submission
.title
),
663 k_strncpy_always_add_null
);
665 snprintf( workshop_form
.addon_folder
,
666 vg_list_size( workshop_form
.addon_folder
),
667 "Steam Cloud ("PRINTF_U64
")", details
.m_nPublishedFileId
);
669 workshop_form
.submission
.file_id
= details
.m_nPublishedFileId
;
670 workshop_form
.file_intent
= k_workshop_form_file_intent_keep_old
;
671 workshop_form
.page
= k_workshop_form_edit
;
672 workshop_form
.submission
.visibility
= details
.m_eVisibility
;
673 workshop_form
.submission
.type
= k_addon_type_none
;
674 workshop_form
.submission
.submission_type_selection
= k_addon_type_none
;
678 u32 len
= strlen(metadata_str
);
679 vg_info( "Metadata: %s\n", metadata_str
);
680 vg_str_bin( metadata_str
, metadata_buf
, len
);
682 vg_msg_init( &msg
, metadata_buf
, len
/2 );
684 if( vg_msg_seekframe( &msg
, "workshop" ))
687 vg_msg_getkvintg( &msg
, "type", k_vg_msg_u32
, &type
, NULL
);
688 workshop_form
.submission
.type
= type
;
689 workshop_form
.submission
.submission_type_selection
= type
;
691 const char *kv_folder
= vg_msg_getkvstr( &msg
, "folder" );
694 vg_strncpy( kv_folder
, workshop_form
.addon_folder
,
695 sizeof(workshop_form
.addon_folder
),
696 k_strncpy_always_add_null
);
702 vg_error( "No metadata was returned with this item.\n" );
705 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
706 glClearColor( 0.2f
, 0.0f
, 0.0f
, 1.0f
);
707 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
708 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
709 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
711 vg_loader_start( _workshop_load_preview_thread
, NULL
);
714 vg_error( "GetQueryUGCResult: Index out of range\n" );
715 workshop_form
.op
= k_workshop_op_none
;
721 * -----------------------------------------------------------------------------
725 * View a page of results on the sidebar
727 static void workshop_view_page( int req
)
729 if( workshop_form
.ugc_query
.result
!= k_EResultOK
){
730 vg_error( "Tried to change page without complete data\n" );
731 workshop_form
.op
= k_workshop_op_none
;
735 int page
= VG_MAX(VG_MIN(req
, workshop_form
.view_published_page_count
-1),0),
736 start
= page
* WORKSHOP_VIEW_PER_PAGE
,
737 end
= VG_MIN( (page
+1) * WORKSHOP_VIEW_PER_PAGE
,
738 workshop_form
.ugc_query
.returned_item_count
),
741 vg_info( "View page %d\n", page
);
743 workshop_form
.view_published_page_id
= page
;
744 workshop_form
.published_files_list_length
= count
;
745 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
747 for( int i
=0; i
<count
; i
++ ){
748 struct published_file
*pfile
= &workshop_form
.published_files_list
[i
];
750 SteamUGCDetails_t details
;
751 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC
,
752 workshop_form
.ugc_query
.handle
,
756 if( details
.m_eResult
!= k_EResultOK
){
757 snprintf( pfile
->title
, 80, "Error (%d)", details
.m_eResult
);
760 vg_strncpy( details
.m_rgchTitle
, pfile
->title
, 80,
761 k_strncpy_always_add_null
);
764 pfile
->result
= details
.m_eResult
;
765 pfile
->result_index
= start
+i
;
768 pfile
->result
= k_EResultValueOutOfRange
;
769 pfile
->result_index
= -1;
770 snprintf( pfile
->title
, 80, "Error (invalid index)" );
776 * Steam API result for when we recieve submitted UGC information about the user
778 static void on_workshop_UGCQueryComplete( void *data
, void *userdata
)
780 SteamUGCQueryCompleted_t
*query
= data
;
781 workshop_form
.ugc_query
.result
= query
->m_eResult
;
783 if( query
->m_eResult
== k_EResultOK
){
784 if( query
->m_unTotalMatchingResults
> 50 ){
785 vg_warn( "You have %d items submitted, "
786 "we can only view the last 50\n" );
789 workshop_form
.ugc_query
.all_item_count
= query
->m_unTotalMatchingResults
;
790 workshop_form
.ugc_query
.returned_item_count
=
791 query
->m_unNumResultsReturned
;
793 workshop_form
.ugc_query
.handle
= query
->m_handle
;
794 workshop_form
.view_published_page_count
=
795 (query
->m_unNumResultsReturned
+WORKSHOP_VIEW_PER_PAGE
-1)/
796 WORKSHOP_VIEW_PER_PAGE
;
797 workshop_form
.view_published_page_id
= 0;
798 workshop_form
.published_files_list_length
= 0;
800 workshop_view_page( 0 );
803 vg_error( "Steam UGCQuery failed (%d)\n", query
->m_eResult
);
804 workshop_form
.view_published_page_count
= 0;
805 workshop_form
.view_published_page_id
= 0;
806 workshop_form
.published_files_list_length
= 0;
808 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
809 SteamAPI_ISteamUGC_ReleaseQueryUGCRequest( hSteamUGC
, query
->m_handle
);
814 * Console command to open the workshop publisher
816 int workshop_submit_command( int argc
, const char *argv
[] )
819 ui_start_modal( "Steam API is not initialized\n", UI_MODAL_BAD
);
823 workshop_form
.page
= k_workshop_form_open
;
824 workshop_form
.view_published_page_count
= 0;
825 workshop_form
.view_published_page_id
= 0;
826 workshop_form
.published_files_list_length
= 0;
827 workshop_form
.ugc_query
.result
= k_EResultNone
;
829 vg_steam_async_call
*call
= vg_alloc_async_steam_api_call();
831 ISteamUser
*hSteamUser
= SteamAPI_SteamUser();
833 steamid
.m_unAll64Bits
= SteamAPI_ISteamUser_GetSteamID( hSteamUser
);
835 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
836 call
->p_handler
= on_workshop_UGCQueryComplete
;
837 call
->userdata
= NULL
;
838 UGCQueryHandle_t handle
= SteamAPI_ISteamUGC_CreateQueryUserUGCRequest
841 steamid
.m_comp
.m_unAccountID
,
842 k_EUserUGCList_Published
,
843 k_EUGCMatchingUGCType_Items
,
844 k_EUserUGCListSortOrder_CreationOrderDesc
,
845 SKATERIFT_APPID
, SKATERIFT_APPID
,
847 SteamAPI_ISteamUGC_SetReturnMetadata( hSteamUGC
, handle
, 1 );
848 call
->id
= SteamAPI_ISteamUGC_SendQueryUGCRequest( hSteamUGC
, handle
);
852 void workshop_init(void)
854 vg_console_reg_cmd( "workshop_submit", workshop_submit_command
, NULL
);
857 static void workshop_render_world_preview(void){
858 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
860 glClearColor( 0.0f
, 0.0f
, 0.3f
, 1.0f
);
861 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
862 glEnable( GL_DEPTH_TEST
);
863 glDisable( GL_BLEND
);
865 render_world( world_current_instance(), &skaterift
.cam
, 0, 0, 1, 1 );
867 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
868 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
872 * Redraw the playermodel into the workshop framebuffer
874 static void workshop_render_player_preview(void){
875 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
876 glClearColor( 0.16f
, 0.15f
, 0.15f
, 1.0f
);
877 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
878 glEnable( GL_DEPTH_TEST
);
879 glDisable( GL_BLEND
);
881 struct skeleton
*sk
= &localplayer
.skeleton
;
884 res
.type
= k_player_pose_type_ik
;
886 struct skeleton_anim
*anim
= skeleton_get_anim( sk
, "idle_cycle+y" );
887 skeleton_sample_anim( sk
, anim
, vg
.time
*0.1f
, res
.keyframes
);
888 q_axis_angle( res
.root_q
, (v3f
){0.0f
,1.0f
,0.0f
}, VG_PIf
);
889 v3_zero( res
.root_co
);
890 res
.root_co
[1] = 200.0f
;
893 q_m3x3( res
.root_q
, transform
);
894 v3_copy( res
.root_co
, transform
[3] );
896 /* TODO: Function. */
897 skeleton_apply_pose( sk
, res
.keyframes
, k_anim_apply_defer_ik
,
898 localplayer
.final_mtx
);
899 skeleton_apply_ik_pass( sk
, localplayer
.final_mtx
);
900 skeleton_apply_pose( sk
, res
.keyframes
, k_anim_apply_deffered_only
,
901 localplayer
.final_mtx
);
902 skeleton_apply_inverses( sk
, localplayer
.final_mtx
);
903 skeleton_apply_transform( sk
, transform
, localplayer
.final_mtx
);
906 v3_copy( (v3f
){ 0.0f
, 201.7f
, 1.2f
}, cam
.pos
);
911 v3_zero( cam
.angles
);
913 vg_camera_update_transform( &cam
);
914 vg_camera_update_view( &cam
);
915 vg_camera_update_projection( &cam
);
916 vg_camera_finalize( &cam
);
918 render_playermodel( &cam
, world_current_instance(), 0,
919 &workshop_form
.player_model
, sk
, localplayer
.final_mtx
);
921 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
922 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
926 * Redraw the model file into the workshop framebuffer
928 static void workshop_render_board_preview(void){
929 if( !workshop_form
.ptr_ent
){
933 render_fb_bind( gpipeline
.fb_workshop_preview
, 0 );
935 glClearColor( 0.0f
, 0.0f
, 0.3f
, 1.0f
);
936 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
937 glEnable( GL_DEPTH_TEST
);
938 glDisable( GL_BLEND
);
940 ent_swspreview
*swsprev
= workshop_form
.ptr_ent
;
941 world_instance
*world
= workshop_form
.view_world
;
943 ent_camera
*ref
= mdl_arritm( &world
->ent_camera
,
944 mdl_entity_id_id(swsprev
->id_camera
) );
945 ent_marker
*display
= mdl_arritm( &world
->ent_marker
,
946 mdl_entity_id_id(swsprev
->id_display
) ),
947 *display1
= mdl_arritm( &world
->ent_marker
,
948 mdl_entity_id_id(swsprev
->id_display1
) );
951 v3_add( display
->transform
.co
, display1
->transform
.co
, baseco
);
952 v3_muls( baseco
, 0.5f
, baseco
);
956 v3_sub( display
->transform
.co
, ref
->transform
.co
, basevector
);
957 float dist
= v3_length( basevector
);
960 v3_angles( basevector
, baseangles
);
962 v2_add( workshop_form
.view_angles
, baseangles
, cam
.angles
);
963 cam
.angles
[2] = 0.0f
;
965 float sX
= sinf( cam
.angles
[0] ),
966 cX
= cosf( cam
.angles
[0] ),
967 sY
= sinf( cam
.angles
[1] ),
968 cY
= cosf( cam
.angles
[1] );
970 v3f offset
= { -sX
* cY
, sY
, cX
* cY
};
972 v3_muladds( display
->transform
.co
, offset
,
973 dist
*workshop_form
.view_dist
, cam
.pos
);
975 cam
.pos
[0] += -sX
*workshop_form
.view_offset
[2];
976 cam
.pos
[2] += cX
*workshop_form
.view_offset
[2];
977 cam
.pos
[0] += cX
*workshop_form
.view_offset
[0];
978 cam
.pos
[2] += sX
*workshop_form
.view_offset
[0];
979 cam
.pos
[1] += workshop_form
.view_offset
[1];
985 vg_camera_update_transform( &cam
);
986 vg_camera_update_view( &cam
);
987 vg_camera_update_projection( &cam
);
988 vg_camera_finalize( &cam
);
991 mdl_transform_m4x3( &display
->transform
, mmdl
);
992 mdl_transform_m4x3( &display1
->transform
, mmdl1
);
994 /* force update this for nice shadows. its usually set in the world
995 * pre-render step, but that includes timer stuff
997 struct player_board
*board
= &workshop_form
.board_model
;
998 struct ub_world_lighting
*ubo
= &world
->ub_lighting
;
1000 v3_copy((v3f
){0.0f
,0.1f
, board
->truck_positions
[0][2]}, vp0
);
1001 v3_copy((v3f
){0.0f
,0.1f
, board
->truck_positions
[1][2]}, vp1
);
1002 m4x3_mulv( mmdl1
, vp0
, ubo
->g_board_0
);
1003 m4x3_mulv( mmdl1
, vp1
, ubo
->g_board_1
);
1004 glBindBuffer( GL_UNIFORM_BUFFER
, world
->ubo_lighting
);
1005 glBufferSubData( GL_UNIFORM_BUFFER
, 0,
1006 sizeof(struct ub_world_lighting
), &world
->ub_lighting
);
1008 render_world( world
, &cam
, 0, 0, 0, 0 );
1009 struct player_board_pose pose
= {0};
1010 render_board( &cam
, world
, board
, mmdl
, &pose
, k_board_shader_entity
);
1011 render_board( &cam
, world
, board
, mmdl1
, &pose
, k_board_shader_entity
);
1013 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
1014 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
1018 * ImGUI section for workshop form
1019 * -----------------------------------------------------------------------------
1022 static void workshop_changed_model_path( char *buf
, u32 len
){
1023 workshop_form
.submission
.submit_file_and_image
= 1;
1026 static void workshop_changed_title( char *buf
, u32 len
){
1027 workshop_form
.submission
.submit_title
= 1;
1030 static void workshop_changed_description( char *buf
, u32 len
){
1031 workshop_form
.submission
.submit_description
= 1;
1034 static void workshop_form_gui_page_undecided( ui_rect content
){
1036 rect_copy( content
, box
);
1038 box
[2] = (box
[2]*2)/3;
1039 ui_rect_center( content
, box
);
1042 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1043 ui_text( row
, "Select the type of item\n", 1, k_ui_align_middle_center
,0);
1044 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1045 ui_enum( row
, "Type:", workshop_form_type_opts
,
1046 4, &workshop_form
.submission
.submission_type_selection
);
1047 ui_split( box
, k_ui_axis_h
, 8, 0, row
, box
);
1048 ui_split( box
, k_ui_axis_h
, 28, 0, row
, box
);
1050 ui_rect button_l
, button_r
;
1051 rect_copy( row
, button_l
);
1052 button_l
[2] = 128*2;
1053 ui_rect_center( row
, button_l
);
1054 ui_split_ratio( button_l
, k_ui_axis_v
, 0.5f
, 2, button_l
, button_r
);
1056 enum addon_type type
= workshop_form
.submission
.submission_type_selection
;
1057 if( type
!= k_addon_type_none
){
1058 if( ui_button_text( button_l
, "OK", 1 ) == 1 ){
1059 workshop_form
.submission
.type
= type
;
1061 if( type
== k_addon_type_world
){
1062 workshop_form
.view_changed
= 1;
1063 workshop_form
.file_intent
= k_workshop_form_file_intent_new
;
1068 ui_fill( button_l
, ui_colour(k_ui_bg
) );
1069 ui_text( button_l
, "OK", 1, k_ui_align_middle_center
,
1070 ui_colour(k_ui_bg
+4) );
1073 if( ui_button_text( button_r
, "Cancel", 1 ) == 1 ){
1074 workshop_form
.page
= k_workshop_form_open
;
1075 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1079 static void workshop_form_gui_draw_preview( ui_rect img_box
){
1080 enum addon_type type
= workshop_form
.submission
.type
;
1081 if( workshop_form
.file_intent
== k_workshop_form_file_intent_keep_old
){
1082 ui_image( img_box
, gpipeline
.fb_workshop_preview
->attachments
[0].id
);
1084 else if( workshop_form
.file_intent
== k_workshop_form_file_intent_new
){
1085 ui_image( img_box
, gpipeline
.fb_workshop_preview
->attachments
[0].id
);
1087 if( type
== k_addon_type_world
){
1091 int hover
= ui_inside_rect( img_box
, vg_ui
.mouse
),
1092 target
= ui_inside_rect( img_box
, vg_ui
.mouse_click
);
1094 if( ui_click_down(UI_MOUSE_MIDDLE
) && target
){
1095 v3_copy( workshop_form
.view_offset
,
1096 workshop_form
.view_offset_begin
);
1098 else if( ui_click_down(UI_MOUSE_LEFT
) && target
){
1099 v2_copy( workshop_form
.view_angles
,
1100 workshop_form
.view_angles_begin
);
1103 if( ui_clicking(UI_MOUSE_MIDDLE
) && target
){
1104 v2f delta
= { vg_ui
.mouse
[0]-vg_ui
.mouse_click
[0],
1105 vg_ui
.mouse
[1]-vg_ui
.mouse_click
[1] };
1107 float *begin
= workshop_form
.view_offset_begin
,
1108 *offset
= workshop_form
.view_offset
;
1109 offset
[0] = vg_clampf( begin
[0]-delta
[0]*0.002f
, -1.0f
, 1.0f
);
1110 offset
[2] = vg_clampf( begin
[2]-delta
[1]*0.002f
, -1.0f
, 1.0f
);
1111 workshop_form
.view_changed
= 1;
1113 else if( ui_clicking(UI_MOUSE_LEFT
) && target
){
1114 v2f delta
= { vg_ui
.mouse
[0]-vg_ui
.mouse_click
[0],
1115 vg_ui
.mouse
[1]-vg_ui
.mouse_click
[1] };
1118 v2_muladds( workshop_form
.view_angles_begin
, delta
, 0.002f
, angles
);
1120 float limit
= VG_PIf
*0.2f
;
1122 angles
[0] = vg_clampf( angles
[0], -limit
, limit
);
1123 angles
[1] = vg_clampf( angles
[1], -limit
, limit
);
1125 v2_copy( angles
, workshop_form
.view_angles
);
1126 workshop_form
.view_changed
= 1;
1129 if( !ui_clicking(UI_MOUSE_LEFT
) && hover
){
1130 float zoom
= workshop_form
.view_dist
;
1131 zoom
+= vg
.mouse_wheel
[1] * -0.07f
;
1132 zoom
= vg_clampf( zoom
, 0.4f
, 2.0f
);
1134 if( zoom
!= workshop_form
.view_dist
){
1135 workshop_form
.view_changed
= 1;
1136 workshop_form
.view_dist
= zoom
;
1141 ui_text( img_box
, "No image", 1, k_ui_align_middle_center
,
1142 ui_colour( k_ui_orange
) );
1146 static void workshop_form_gui_edit_page( ui_rect content
){
1147 enum addon_type type
= workshop_form
.submission
.type
;
1149 if( type
== k_addon_type_none
){
1150 workshop_form_gui_page_undecided( content
);
1154 ui_rect image_plane
;
1155 ui_split( content
, k_ui_axis_h
, 300, 0, image_plane
, content
);
1156 ui_fill( image_plane
, ui_colour( k_ui_bg
+0 ) );
1159 ui_fit_item( image_plane
, (ui_px
[2]){ 3, 2 }, img_box
);
1160 workshop_form_gui_draw_preview( img_box
);
1163 ui_rect file_button
, file_label
;
1167 "Addon folder: skaterift/%s", workshop_filetype_folder() );
1169 if( type
== k_addon_type_world
){
1170 struct ui_textbox_callbacks callbacks
= {
1171 .change
= workshop_changed_model_path
1173 ui_textbox( content
, buf
, workshop_form
.addon_folder
,
1174 vg_list_size(workshop_form
.addon_folder
), 1, 0, &callbacks
);
1178 ui_standard_widget( content
, file_entry
, 1 );
1179 ui_split( file_entry
, k_ui_axis_v
, -128, 0, file_entry
, file_button
);
1181 if( workshop_form
.file_intent
!= k_workshop_form_file_intent_none
){
1182 ui_text( file_entry
, workshop_form
.addon_folder
, 1,
1183 k_ui_align_middle_left
, ui_colour( k_ui_fg
+4 ) );
1185 if( ui_button_text( file_button
, "Remove", 1 ) == 1 ){
1186 if( type
== k_addon_type_board
)
1187 player_board_unload( &workshop_form
.board_model
);
1188 else if( type
== k_addon_type_player
)
1189 player_model_unload( &workshop_form
.player_model
);
1191 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1192 workshop_form
.addon_folder
[0] = '\0';
1196 struct ui_textbox_callbacks callbacks
= {
1197 .change
= workshop_changed_model_path
1200 ui_textbox( file_entry
, buf
, workshop_form
.addon_folder
,
1201 vg_list_size(workshop_form
.addon_folder
), 1,
1204 if( ui_button_text( file_button
, "Load", 1 ) == 1 ){
1205 workshop_op_load_model();
1210 const char *str_title
= "Title:", *str_desc
= "Description:";
1214 struct ui_textbox_callbacks callbacks
= {
1215 .change
= workshop_changed_title
1217 ui_textbox( content
, str_title
, workshop_form
.submission
.title
,
1218 vg_list_size(workshop_form
.submission
.title
), 1,
1222 /* visibility option */
1224 ui_enum( content
, "Visibility:", workshop_form_visibility_opts
,
1225 4, &workshop_form
.submission
.visibility
);
1228 /* description box */
1230 struct ui_textbox_callbacks callbacks
= {
1231 .change
= workshop_changed_description
1233 ui_textbox( content
, str_desc
, workshop_form
.submission
.description
,
1234 vg_list_size(workshop_form
.submission
.description
), 4,
1235 UI_TEXTBOX_MULTILINE
|UI_TEXTBOX_WRAP
, &callbacks
);
1238 /* submissionable */
1240 ui_split( content
, k_ui_axis_h
, content
[3]-32-8, 0, content
, final_row
);
1242 ui_rect submission_center
;
1243 rect_copy( final_row
, submission_center
);
1244 submission_center
[2] = 256;
1245 ui_rect_center( final_row
, submission_center
);
1247 ui_rect btn_left
, btn_right
;
1248 ui_split_ratio( submission_center
, k_ui_axis_v
, 0.5f
, 8,
1249 btn_left
, btn_right
);
1251 if( ui_button_text( btn_left
, "Publish", 1 ) == 1 ){
1252 workshop_op_submit();
1254 if( ui_button_text( btn_right
, "Cancel", 1 ) == 1 ){
1255 workshop_form
.page
= k_workshop_form_open
;
1256 player_board_unload( &workshop_form
.board_model
);
1257 workshop_form
.file_intent
= k_workshop_form_file_intent_none
;
1261 const char *disclaimer_text
=
1262 "By submitting this item, you agree to the workshop terms of service";
1264 ui_rect disclaimer_row
, inner
, link
;
1265 ui_split( content
, k_ui_axis_h
, content
[3]-32, 0, content
, disclaimer_row
);
1267 ui_px btn_width
= 32;
1269 rect_copy( disclaimer_row
, inner
);
1270 inner
[2] = ui_text_line_width( disclaimer_text
) + btn_width
+8;
1273 ui_rect_center( disclaimer_row
, inner
);
1274 ui_split( inner
, k_ui_axis_v
, inner
[2]-btn_width
, 0, label
, btn_right
);
1275 ui_rect_pad( btn_right
, (ui_px
[2]){2,2} );
1277 if( ui_button_text( btn_right
, "\xbf", 2 ) == 1 ){
1278 ISteamFriends
*hSteamFriends
= SteamAPI_SteamFriends();
1279 SteamAPI_ISteamFriends_ActivateGameOverlayToWebPage( hSteamFriends
,
1280 "https://steamcommunity.com/sharedfiles/workshoplegalagreement",
1281 k_EActivateGameOverlayToWebPageMode_Default
);
1284 ui_text( label
, disclaimer_text
, 1, k_ui_align_middle_left
,
1285 ui_colour( k_ui_fg
+4 ) );
1288 static void workshop_form_gui_sidebar( ui_rect sidebar
)
1290 ui_fill( sidebar
, ui_colour( k_ui_bg
+2 ) );
1293 ui_split( sidebar
, k_ui_axis_h
, 28, 0, title
, sidebar
);
1295 if( workshop_form
.page
== k_workshop_form_edit
){
1296 ui_text( title
, "Editing", 1, k_ui_align_middle_center
, 0 );
1297 ui_split( sidebar
, k_ui_axis_h
, 28, 0, title
, sidebar
);
1299 if( workshop_form
.submission
.type
!= k_addon_type_none
){
1302 vg_strnull( &str
, buf
, 512 );
1304 if( workshop_form
.submission
.file_id
)
1305 vg_strcat( &str
, "Editing an existing " );
1307 vg_strcat( &str
, "Creating a new " );
1309 if( workshop_form
.submission
.type
== k_addon_type_board
)
1310 vg_strcat( &str
, "skateboard." );
1311 else if( workshop_form
.submission
.type
== k_addon_type_world
)
1312 vg_strcat( &str
, "world." );
1313 else if( workshop_form
.submission
.type
== k_addon_type_player
)
1314 vg_strcat( &str
, "playermodel." );
1316 vg_strcat( &str
, "???." );
1318 ui_text( title
, buf
, 1, k_ui_align_middle_center
,
1319 ui_colour(k_ui_fg
+4) );
1325 * sidebar existing entries panel
1327 ui_text( title
, "Your submissions", 1, k_ui_align_middle_center
, 0 );
1329 ui_rect controls
, btn_create_new
;
1330 ui_split( sidebar
, k_ui_axis_h
, 32, 0, controls
, sidebar
);
1331 ui_split( sidebar
, k_ui_axis_h
, -32, 0, sidebar
, btn_create_new
);
1332 ui_fill( controls
, ui_colour( k_ui_bg
+1 ) );
1336 vg_strnull( &str
, buf
, sizeof(buf
) );
1337 vg_strcat( &str
, "page " );
1338 vg_strcati32( &str
, workshop_form
.view_published_page_id
+1 );
1339 vg_strcatch( &str
, '/' );
1340 vg_strcati32( &str
, workshop_form
.view_published_page_count
);
1342 ui_rect_pad( controls
, (ui_px
[2]){0,4} );
1344 ui_split_ratio( controls
, k_ui_axis_v
, 0.25f
, 0, info
, controls
);
1345 ui_text( info
, buf
, 1, k_ui_align_middle_center
, 0 );
1347 ui_rect btn_left
, btn_right
;
1348 ui_split_ratio( controls
, k_ui_axis_v
, 0.5f
, 2, btn_left
, btn_right
);
1350 if( ui_button_text( btn_left
, "newer", 1 ) == 1 ){
1351 workshop_view_page( workshop_form
.view_published_page_id
-1 );
1354 if( ui_button_text( btn_right
, "older", 1 ) == 1 ){
1355 workshop_view_page( workshop_form
.view_published_page_count
+1 );
1358 if( ui_button_text( btn_create_new
, "Create New Item", 1 ) == 1 ){
1359 workshop_reset_submission_data();
1360 workshop_form
.submission
.submit_title
= 1;
1361 workshop_form
.submission
.submit_description
= 1;
1362 workshop_form
.submission
.submit_file_and_image
= 1;
1363 workshop_form
.page
= k_workshop_form_edit
;
1366 for( int i
=0; i
<workshop_form
.published_files_list_length
; i
++ ){
1368 ui_split( sidebar
, k_ui_axis_h
, 28, 0, item
, sidebar
);
1369 ui_rect_pad( item
, (ui_px
[2]){4,4} );
1371 struct published_file
*pfile
= &workshop_form
.published_files_list
[i
];
1372 if( ui_button_text( item
, pfile
->title
, 1 ) == 1 ){
1373 if( pfile
->result
== k_EResultOK
){
1374 vg_info( "Select index: %d\n", pfile
->result_index
);
1375 workshop_op_download_and_view_submission( pfile
->result_index
);
1378 vg_warn( "Cannot select that item, result not OK\n" );
1384 void workshop_form_gui(void)
1386 enum workshop_form_page stable_page
= workshop_form
.page
;
1387 if( stable_page
== k_workshop_form_hidden
) return;
1390 ui_rect screen
= { 0, 0, vg
.window_x
, vg
.window_y
};
1391 ui_rect window
= { 0, 0, 1000, 700 };
1392 ui_rect_center( screen
, window
);
1393 vg_ui
.wants_mouse
= 1;
1395 ui_fill( window
, ui_colour( k_ui_bg
+1 ) );
1396 ui_outline( window
, 1, ui_colour( k_ui_bg
+7 ), 0 );
1398 ui_rect title
, panel
;
1399 ui_split( window
, k_ui_axis_h
, 28, 0, title
, panel
);
1400 ui_fill( title
, ui_colour( k_ui_bg
+7 ) );
1401 ui_text( title
, "Workshop tool", 1, k_ui_align_middle_center
,
1402 ui_colourcont(k_ui_bg
+7) );
1404 ui_rect quit_button
;
1405 ui_split( title
, k_ui_axis_v
, title
[2]-title
[3], 2, title
, quit_button
);
1407 if( vg_loader_availible() ){
1408 if( ui_button_text( quit_button
, "X", 1 ) == 1 ){
1409 workshop_quit_form();
1415 * temporary operation blinders, we don't yet have a nice way to show the
1416 * user that we're doing something uninterruptable, so the code just
1417 * escapes here and we show them a basic string
1420 if( workshop_form
.op
!= k_workshop_op_none
){
1421 const char *op_string
= "The programmer has not bothered to describe "
1422 "the current operation that is running.";
1424 switch( workshop_form
.op
){
1425 case k_workshop_op_loading_model
:
1426 op_string
= "Operation in progress: Loading model file.";
1428 case k_workshop_op_publishing_update
:
1429 op_string
= "Operation in progress: publishing submission update "
1432 case k_workshop_op_downloading_submission
:
1433 op_string
= "Operation in progress: downloading existing submission"
1434 " from Steam services.";
1439 ui_text( panel
, op_string
, 1, k_ui_align_middle_center
, 0 );
1443 /* re draw board preview if need to */
1444 if( (stable_page
== k_workshop_form_edit
) &&
1445 workshop_form
.view_changed
&&
1446 workshop_form
.file_intent
== k_workshop_form_file_intent_new
)
1448 enum addon_type type
= workshop_form
.submission
.type
;
1449 if( type
== k_addon_type_board
){
1450 workshop_render_board_preview();
1452 else if( type
== k_addon_type_world
){
1453 vg_success( "Renders world preview\n" );
1454 workshop_render_world_preview();
1456 else if( type
== k_addon_type_player
){
1457 workshop_render_player_preview();
1460 workshop_form
.view_changed
= 0;
1463 struct workshop_form
*form
= &workshop_form
;
1465 ui_rect sidebar
, content
;
1466 ui_split_ratio( panel
, k_ui_axis_v
, 0.3f
, 1, sidebar
, content
);
1469 ui_rect_pad( content
, (ui_px
[2]){8,8} );
1471 if( stable_page
== k_workshop_form_edit
){
1472 workshop_form_gui_edit_page( content
);
1474 else if( stable_page
== k_workshop_form_open
){
1475 ui_text( content
, "Nothing selected.", 1, k_ui_align_middle_center
,
1476 ui_colour( k_ui_fg
+4 ) );
1478 else if( stable_page
>= k_workshop_form_cclosing
){
1479 ui_rect submission_row
;
1480 ui_split( content
, k_ui_axis_h
, content
[3]-32-8, 0, content
,
1485 if( stable_page
== k_workshop_form_closing_bad
)
1486 colour
= ui_colour( k_ui_red
+k_ui_brighter
);
1488 colour
= ui_colour( k_ui_green
+k_ui_brighter
);
1490 ui_text( content
, workshop_form
.failure_or_success_string
, 1,
1491 k_ui_align_middle_center
, colour
);
1493 ui_rect submission_center
;
1494 rect_copy( submission_row
, submission_center
);
1495 submission_center
[2] = 128;
1496 ui_rect_center( submission_row
, submission_center
);
1497 ui_rect_pad( submission_center
, (ui_px
[2]){8,8} );
1499 if( ui_button_text( submission_center
, "OK", 1 ) == 1 ){
1500 workshop_form
.page
= k_workshop_form_open
;
1504 workshop_form_gui_sidebar( sidebar
);
1508 * Some async api stuff
1509 * -----------------------------------------------------------------------------
1512 void async_workshop_get_filepath( void *data
, u32 len
)
1514 struct async_workshop_filepath_info
*info
= data
;
1519 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
1520 if( !SteamAPI_ISteamUGC_GetItemInstallInfo( hSteamUGC
, info
->id
, &_size
,
1521 info
->buf
, info
->len
, &_ts
))
1523 vg_error( "GetItemInstallInfo failed\n" );
1524 info
->buf
[0] = '\0';
1528 void async_workshop_get_installed_files( void *data
, u32 len
)
1530 struct async_workshop_installed_files_info
*info
= data
;
1532 ISteamUGC
*hSteamUGC
= SteamAPI_SteamUGC();
1533 u32 count
= SteamAPI_ISteamUGC_GetSubscribedItems( hSteamUGC
, info
->buffer
,
1536 vg_info( "Found %u subscribed items\n", count
);
1539 for( u32 i
=0; i
<count
; i
++ ){
1540 u32 state
= SteamAPI_ISteamUGC_GetItemState( hSteamUGC
, info
->buffer
[i
] );
1541 if( state
& k_EItemStateInstalled
){
1542 info
->buffer
[j
++] = info
->buffer
[i
];