threading fixes for skateshop
[carveJwlIkooP6JGAAIwe30JlM.git] / workshop.c
1 #ifndef WORKSHOP_C
2 #define WORKSHOP_C
3
4 #define VG_GAME
5 #include "vg/vg.h"
6 #include "vg/vg_tex.h"
7 #include "ent_skateshop.h"
8
9 #include "vg/vg_steam_auth.h"
10 #include "vg/vg_steam_ugc.h"
11 #include "vg/vg_steam_friends.h"
12
13 #define WORKSHOP_VIEW_PER_PAGE 15
14
15 struct workshop_form{
16 struct {
17 char title[80];
18 char description[512];
19
20 PublishedFileId_t file_id; /* 0 if not published yet */
21
22 struct ui_dropdown_value visibility;
23
24 int submit_title, /* set if the respective controls are touched */
25 submit_description,
26 submit_file_and_image;
27 }
28 submission;
29
30 enum workshop_form_page{
31 k_workshop_form_hidden,
32 k_workshop_form_open, /* open but not looking at anything */
33 k_workshop_form_edit, /* editing a submission */
34 k_workshop_form_cclosing,
35 k_workshop_form_closing_good, /* post upload screen */
36 k_workshop_form_closing_bad,
37 }
38 page;
39
40 /* model viewer
41 * -----------------------------
42 */
43
44 char model_path[128];
45
46 struct player_board board_model;
47
48 /* what does the user want to do with the image preview? */
49 enum workshop_form_file_intent{
50 k_workshop_form_file_intent_none, /* loading probably */
51 k_workshop_form_file_intent_new, /* board_model is valid */
52 k_workshop_form_file_intent_keep_old /* just browsing */
53 }
54 file_intent;
55
56 world_instance *view_world;
57 ent_swspreview *ptr_ent;
58 v2f view_angles,
59 view_angles_begin;
60 v3f view_offset,
61 view_offset_begin;
62
63 float view_dist;
64 int view_changed;
65
66 /*
67 * published UGC request
68 * ------------------------------
69 */
70
71 struct {
72 UGCQueryHandle_t handle;
73 EResult result;
74
75 int all_item_count,
76 returned_item_count;
77 }
78 ugc_query;
79
80 /*
81 * UI information
82 * ------------------------------------------
83 */
84
85 const char *failure_or_success_string;
86
87 int img_w, img_h;
88 u8 *img_buffer;
89
90 int view_published_page_count,
91 view_published_page_id;
92
93 struct published_file{
94 EResult result;
95 int result_index;
96 char title[80];
97 }
98 published_files_list[WORKSHOP_VIEW_PER_PAGE];
99 int published_files_list_length;
100 }
101 static workshop_form;
102
103 static struct ui_dropdown_opt workshop_form_visibility_opts[] = {
104 { "Public", k_ERemoteStoragePublishedFileVisibilityPublic },
105 { "Unlisted", k_ERemoteStoragePublishedFileVisibilityUnlisted },
106 { "Friends Only", k_ERemoteStoragePublishedFileVisibilityFriendsOnly },
107 { "Private", k_ERemoteStoragePublishedFileVisibilityPrivate },
108 };
109
110 /*
111 * Close the form and discard UGC query result
112 */
113 VG_STATIC void workshop_quit_form(void)
114 {
115 workshop_begin_op( k_workshop_form_op_none ); /* safeguard */
116 player_board_unload( &workshop_form.board_model );
117 workshop_form.file_intent = k_workshop_form_file_intent_none;
118
119 if( workshop_form.ugc_query.result == k_EResultOK ){
120 workshop_form.ugc_query.result = k_EResultNone;
121
122 ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
123 SteamAPI_ISteamUGC_ReleaseQueryUGCRequest(
124 hSteamUGC, workshop_form.ugc_query.handle );
125 }
126
127 workshop_form.page = k_workshop_form_hidden;
128 workshop_end_op();
129 }
130
131 /*
132 * Delete all information about the submission
133 */
134 VG_STATIC void workshop_reset_submission_data(void)
135 {
136 workshop_form.submission.file_id = 0; /* assuming id of 0 is none/invalid */
137 workshop_form.submission.description[0] = '\0';
138 workshop_form.submission.title[0] = '\0';
139
140 workshop_form.submission.visibility.value =
141 k_ERemoteStoragePublishedFileVisibilityPublic;
142 workshop_form.submission.visibility.index = 0;
143
144 workshop_form.model_path[0] = '\0';
145 player_board_unload( &workshop_form.board_model );
146 workshop_form.file_intent = k_workshop_form_file_intent_none;
147 }
148
149
150 /*
151 * Mostly copies of what it sais on the Steam API documentation
152 */
153 VG_STATIC const char *workshop_EResult_user_string( EResult result )
154 {
155 switch( result ){
156 case k_EResultInsufficientPrivilege:
157 return "Your account is currently restricted from uploading content "
158 "due to a hub ban, account lock, or community ban. You need to "
159 "contact Steam Support to resolve the issue.";
160 case k_EResultBanned:
161 return "You do not have permission to upload content to this hub "
162 "because you have an active VAC or Game ban.";
163 case k_EResultTimeout:
164 return "The operation took longer than expected, so it was discarded. "
165 "Please try again.";
166 case k_EResultNotLoggedOn:
167 return "You are currently not logged into Steam.";
168 case k_EResultServiceUnavailable:
169 return "The workshop server is having issues or is unavailable, "
170 "please try again.";
171 case k_EResultInvalidParam:
172 return "One of the submission fields contains something not being "
173 "accepted by that field.";
174 case k_EResultAccessDenied:
175 return "There was a problem trying to save the title and description. "
176 "Access was denied.";
177 case k_EResultLimitExceeded:
178 return "You have exceeded your Steam Cloud quota. If you wish to "
179 "upload this file, you must remove some published items.";
180 case k_EResultFileNotFound:
181 return "The uploaded file could not be found.";
182 case k_EResultDuplicateRequest:
183 return "The file was already successfully uploaded.";
184 case k_EResultDuplicateName:
185 return "You already have a Steam Workshop item with that name.";
186 case k_EResultServiceReadOnly:
187 return "Due to a recent password or email change, you are not allowed "
188 "to upload new content. Usually this restriction will expire in"
189 " 5 days, but can last up to 30 days if the account has been "
190 "inactive recently.";
191 default:
192 return "Operation failed for an error which has not been accounted for "
193 "by the programmer. Try again, sorry :)";
194 }
195 }
196
197 /*
198 * op: k_workshop_form_op_publishing_update
199 * ----------------------------------------------------------------------------
200 */
201
202 /*
203 * The endpoint of this operation
204 */
205 VG_STATIC void on_workshop_update_result( void *data, void *user )
206 {
207 vg_info( "Recieved workshop update result\n" );
208 SubmitItemUpdateResult_t *result = data;
209
210 /* this seems to be set here, but my account definitely has accepted it */
211 if( result->m_bUserNeedsToAcceptWorkshopLegalAgreement ){
212 vg_warn( "Workshop agreement currently not accepted\n" );
213 }
214
215 if( result->m_eResult == k_EResultOK ){
216 workshop_form.page = k_workshop_form_closing_good;
217 workshop_form.failure_or_success_string = "Uploaded workshop file!";
218 vg_success( "file uploaded\n" );
219 }
220 else{
221 workshop_form.page = k_workshop_form_closing_bad;
222 workshop_form.failure_or_success_string =
223 workshop_EResult_user_string( result->m_eResult );
224
225 vg_error( "Error with the submitted file (%d)\n", result->m_eResult );
226 }
227
228 workshop_end_op();
229 }
230
231 struct workshop_package_info {
232 PublishedFileId_t publishing_file_id;
233
234 int success;
235 char abs_preview_image[ 1024 ];
236 char abs_content_folder[ 1024 ];
237 char abs_content_file[ 1024 ];
238
239 const char *failure_reason;
240 };
241
242 /*
243 * reciever on completion of packaging the files, it will then start the item
244 * update with Steam API
245 */
246 VG_STATIC void workshop_form_async_package_complete( void *data, u32 size )
247 {
248 struct workshop_package_info *info = data;
249 if( !info->success ){
250 workshop_form.page = k_workshop_form_closing_bad;
251 workshop_form.failure_or_success_string = info->failure_reason;
252 workshop_end_op();
253 return;
254 }
255
256 ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
257 UGCUpdateHandle_t handle
258 = SteamAPI_ISteamUGC_StartItemUpdate( hSteamUGC, SKATERIFT_APPID,
259 info->publishing_file_id );
260
261 /* TODO: Handle failure cases for these */
262
263 if( workshop_form.submission.submit_title ){
264 vg_info( "Setting title\n" );
265 SteamAPI_ISteamUGC_SetItemTitle( hSteamUGC, handle,
266 workshop_form.submission.title );
267 }
268
269 if( workshop_form.submission.submit_description ){
270 vg_info( "Setting description\n" );
271 SteamAPI_ISteamUGC_SetItemDescription( hSteamUGC, handle,
272 workshop_form.submission.description);
273 }
274
275 if( workshop_form.submission.submit_file_and_image ){
276 vg_info( "Setting preview image\n" );
277 SteamAPI_ISteamUGC_SetItemPreview( hSteamUGC,
278 handle, info->abs_preview_image );
279
280 vg_info( "Setting item content\n" );
281 SteamAPI_ISteamUGC_SetItemContent( hSteamUGC, handle,
282 info->abs_content_folder );
283 }
284
285 vg_info( "Setting visibility\n" );
286 SteamAPI_ISteamUGC_SetItemVisibility( hSteamUGC, handle,
287 workshop_form.submission.visibility.value );
288
289 vg_info( "Submitting updates\n" );
290 vg_steam_async_call *call = vg_alloc_async_steam_api_call();
291 call->userdata = NULL;
292 call->p_handler = on_workshop_update_result;
293 call->id = SteamAPI_ISteamUGC_SubmitItemUpdate( hSteamUGC, handle, "" );
294 }
295
296 /*
297 * Async thread for rearranging files into a reasonable workshop folder
298 */
299 struct workshop_package_thread_args{
300 PublishedFileId_t file_id;
301 };
302 VG_STATIC void _workshop_package_thread( void *_args )
303 {
304 struct workshop_package_thread_args *args = _args;
305 PublishedFileId_t file_id = args->file_id;
306
307 vg_info( "Packaging workshop content folder\n" );
308
309 vg_async_item *call = vg_async_alloc( sizeof(struct workshop_package_info) );
310 struct workshop_package_info *info = call->payload;
311 info->publishing_file_id = file_id;
312 info->failure_reason = "Unknown failure reason";
313
314 /* build content folder path */
315 snprintf( info->abs_content_folder, 1024, "%smodels/boards/workshop/%lu",
316 vg.base_path, file_id );
317
318 /* build content file path */
319 snprintf( info->abs_content_file, 1024, "%s/%s", info->abs_content_folder,
320 "board.mdl" );
321
322 /* build workshop preview file path */
323 snprintf( info->abs_preview_image, 1024, "%sworkshop_preview.jpg",
324 vg.base_path );
325
326 /* arange files */
327 if( !vg_mkdir( info->abs_content_folder ) ){
328 info->success = 0;
329 info->failure_reason = "Could not make directory.";
330 vg_async_dispatch( call, workshop_form_async_package_complete );
331 return;
332 }
333
334 vg_linear_clear( vg_mem.scratch );
335 if( !vg_file_copy( workshop_form.model_path, info->abs_content_file,
336 vg_mem.scratch ) ){
337 info->success = 0;
338 info->failure_reason = "Copy file failed.";
339 vg_async_dispatch( call, workshop_form_async_package_complete );
340 return;
341 }
342
343 info->success = 1;
344 vg_async_dispatch( call, workshop_form_async_package_complete );
345 }
346
347 /*
348 * Begins the packaging thread using file_id. Thread definition above.
349 */
350 VG_STATIC void workshop_package_submission( PublishedFileId_t file_id )
351 {
352 vg_linear_clear( vg_mem.scratch );
353 struct workshop_package_thread_args *args =
354 vg_linear_alloc( vg_mem.scratch,
355 sizeof(struct workshop_package_thread_args));
356
357 args->file_id = file_id;
358 vg_loader_start( _workshop_package_thread, args );
359 }
360
361 /*
362 * Steam API call result for when we've created a new item on their network, or
363 * not, if it has failed
364 */
365 VG_STATIC void on_workshop_createitem( void *data, void *user )
366 {
367 CreateItemResult_t *result = data;
368
369 if( result->m_eResult == k_EResultOK ){
370 vg_info( "Created workshop file with id: %lu\n",
371 result->m_nPublishedFileId );
372
373 if( result->m_bUserNeedsToAcceptWorkshopLegalAgreement ){
374 vg_warn( "Workshop agreement currently not accepted\n" );
375 }
376
377 workshop_package_submission( result->m_nPublishedFileId );
378 }
379 else{
380 const char *errstr = workshop_EResult_user_string( result->m_eResult );
381
382 if( errstr ){
383 vg_error( "ISteamUGC_CreateItem() failed(%d): '%s' \n",
384 result->m_eResult, errstr );
385 }
386
387 workshop_form.page = k_workshop_form_closing_bad;
388 workshop_form.failure_or_success_string = errstr;
389 workshop_end_op();
390 }
391 }
392
393 /*
394 * Starts the workshop upload process through Steam API
395 */
396 VG_STATIC void workshop_form_async_submit_begin( void *payload, u32 size )
397 {
398 /* use existing file */
399 if( workshop_form.submission.file_id ){
400 if( workshop_form.submission.submit_file_and_image ){
401 workshop_package_submission( workshop_form.submission.file_id );
402 }
403 else{
404 struct workshop_package_info info;
405 info.abs_content_file[0] = '\0';
406 info.abs_content_folder[0] = '\0';
407 info.abs_preview_image[0] = '\0';
408 info.failure_reason = NULL;
409 info.publishing_file_id = workshop_form.submission.file_id;
410 info.success = 1;
411 workshop_form_async_package_complete( &info,
412 sizeof(struct workshop_package_info) );
413 }
414 }
415 else{
416 vg_steam_async_call *call = vg_alloc_async_steam_api_call();
417 call->userdata = NULL;
418 call->p_handler = on_workshop_createitem;
419 ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
420 call->id = SteamAPI_ISteamUGC_CreateItem( hSteamUGC, SKATERIFT_APPID,
421 k_EWorkshopFileTypeCommunity );
422 }
423 }
424
425 /*
426 * Downloads the framebuffer into scratch memory
427 */
428 VG_STATIC void workshop_form_async_download_image( void *payload, u32 size )
429 {
430 int w, h;
431 render_fb_get_current_res( gpipeline.fb_workshop_preview, &w, &h );
432 vg_linear_clear( vg_mem.scratch );
433 workshop_form.img_buffer = vg_linear_alloc( vg_mem.scratch, w*h*3 );
434
435 vg_info( "read framebuffer: glReadPixels( %dx%d )\n", w,h );
436
437 glBindFramebuffer( GL_READ_FRAMEBUFFER, gpipeline.fb_workshop_preview->fb );
438 glReadBuffer( GL_COLOR_ATTACHMENT0 );
439 glReadPixels( 0,0, w,h, GL_RGB, GL_UNSIGNED_BYTE, workshop_form.img_buffer );
440
441 workshop_form.img_w = w;
442 workshop_form.img_h = h;
443 }
444
445 /*
446 * Thread which kicks off the upload process
447 */
448 VG_STATIC void _workshop_form_submit_thread( void *data )
449 {
450 vg_async_call( workshop_form_async_download_image, NULL, 0 );
451 vg_async_stall();
452
453 int w = workshop_form.img_w,
454 h = workshop_form.img_h;
455
456 vg_info( "writing: workshop_preview.jpg (%dx%d @90%%)\n", w,h );
457 stbi_flip_vertically_on_write(1);
458 stbi_write_jpg( "workshop_preview.jpg", w,h, 3,
459 workshop_form.img_buffer, 90 );
460
461 vg_async_call( workshop_form_async_submit_begin, NULL, 0 );
462 }
463
464 /*
465 * Entry point for the publishing submission operation
466 */
467 VG_STATIC void workshop_op_submit(void)
468 {
469 /* TODO: Show these errors to the user */
470
471 if( workshop_form.submission.submit_title ){
472 if( !workshop_form.submission.title[0] ){
473 vg_error( "Cannot submit because a title is required\n" );
474 return;
475 }
476 }
477
478 if( workshop_form.submission.submit_description ){
479 if( !workshop_form.submission.description[0] ){
480 vg_error( "Cannot submit because a description is required\n" );
481 return;
482 }
483 }
484
485 if( workshop_form.submission.submit_file_and_image ){
486 if( workshop_form.file_intent == k_workshop_form_file_intent_none ){
487 vg_error( "Cannot submit because the file is empty or unspecified\n" );
488 return;
489 }
490 }
491
492 workshop_begin_op( k_workshop_form_op_publishing_update );
493
494 player_board_unload( &workshop_form.board_model );
495 workshop_form.file_intent = k_workshop_form_file_intent_none;
496
497 vg_loader_start( _workshop_form_submit_thread, NULL );
498 }
499
500 /*
501 * op: k_workshop_form_op_loading_model
502 * -----------------------------------------------------------------------------
503 */
504
505 /*
506 * Reciever for completion of the model file load
507 */
508 VG_STATIC void workshop_form_loadmodel_async_complete( void *payload, u32 size )
509 {
510 v2_zero( workshop_form.view_angles );
511 v3_zero( workshop_form.view_offset );
512 workshop_form.view_dist = 1.0f;
513 workshop_form.view_changed = 1;
514 workshop_form.file_intent = k_workshop_form_file_intent_new;
515
516 vg_success( "workshop async load complete\n" );
517 workshop_end_op();
518 }
519
520 /*
521 * Thread which loads the model from the disk
522 */
523 VG_STATIC void _workshop_form_load_thread( void *data )
524 {
525 player_board_load( &workshop_form.board_model, workshop_form.model_path );
526 vg_async_call( workshop_form_loadmodel_async_complete, NULL, 0 );
527 }
528
529 /*
530 * Entry point for load model operation
531 */
532 VG_STATIC void workshop_op_load_model(void)
533 {
534 workshop_begin_op( k_workshop_form_op_loading_model );
535 vg_loader_start( _workshop_form_load_thread, NULL );
536 }
537
538 /*
539 * op: k_workshop_form_op_downloading_submission
540 * -----------------------------------------------------------------------------
541 */
542
543 /*
544 * The image has been decoded and is ready to slap into the framebuffer
545 */
546 VG_STATIC void workshop_form_async_imageload( void *data, u32 len )
547 {
548 if( data ){
549 struct framebuffer_attachment *a =
550 &gpipeline.fb_workshop_preview->attachments[0];
551
552 glBindTexture( GL_TEXTURE_2D, a->id );
553 glTexSubImage2D( GL_TEXTURE_2D, 0,0,0,
554 WORKSHOP_PREVIEW_WIDTH, WORKSHOP_PREVIEW_HEIGHT,
555 a->format, a->type, data );
556 stbi_image_free( data );
557 vg_success( "Loaded workshop preview image\n" );
558 }
559
560 workshop_end_op();
561 }
562
563 struct workshop_loadpreview_info {
564 char abs_preview_image[ 1024 ];
565 };
566
567 /*
568 * Load the image located at ./workshop_preview.jpg into our framebuffer
569 */
570 VG_STATIC void _workshop_load_preview_thread( void *data )
571 {
572 struct workshop_loadpreview_info *info = data;
573
574 stbi_set_flip_vertically_on_load(1);
575 int x, y, nc;
576 u8 *rgb = stbi_load( info->abs_preview_image, &x, &y, &nc, 3 );
577
578 if( rgb ){
579 if( (x == WORKSHOP_PREVIEW_WIDTH) && (y == WORKSHOP_PREVIEW_HEIGHT) ){
580 vg_async_call( workshop_form_async_imageload, rgb, x*y*3 );
581 }
582 else{
583 vg_error( "Resolution does not match framebuffer, so we can't"
584 " show it\n" );
585 stbi_image_free( rgb );
586 vg_async_call( workshop_form_async_imageload, NULL, 0 );
587 }
588 }
589 else{
590 vg_error( "Failed to load workshop_preview.jpg: '%s'\n",
591 stbi_failure_reason() );
592 vg_async_call( workshop_form_async_imageload, NULL, 0 );
593 }
594 }
595
596 /*
597 * Reciever for the preview download result
598 */
599 VG_STATIC void on_workshop_download_ugcpreview( void *data, void *user )
600 {
601 struct workshop_loadpreview_info *info = user;
602 RemoteStorageDownloadUGCResult_t *result = data;
603
604 if( result->m_eResult == k_EResultOK ){
605 ISteamRemoteStorage *hSteamRemoteStorage = SteamAPI_SteamRemoteStorage();
606 vg_loader_start( _workshop_load_preview_thread, info );
607 }
608 else{
609 vg_error( "Error while donwloading UGC preview( %d )\n",
610 result->m_eResult );
611 workshop_end_op();
612 }
613 }
614
615 /*
616 * Entry point to view operation
617 */
618 VG_STATIC void workshop_op_download_and_view_submission( int result_index )
619 {
620 ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
621 ISteamRemoteStorage *hSteamRemoteStorage = SteamAPI_SteamRemoteStorage();
622 SteamUGCDetails_t details;
623 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC,
624 workshop_form.ugc_query.handle,
625 result_index,
626 &details ) )
627 {
628 workshop_begin_op( k_workshop_form_op_downloading_submission );
629 workshop_reset_submission_data();
630 workshop_form.submission.submit_description = 0;
631 workshop_form.submission.submit_file_and_image = 0;
632 workshop_form.submission.submit_title = 0;
633
634 vg_strncpy( details.m_rgchDescription,
635 workshop_form.submission.description,
636 vg_list_size( workshop_form.submission.description ),
637 k_strncpy_always_add_null );
638
639 vg_strncpy( details.m_rgchTitle,
640 workshop_form.submission.title,
641 vg_list_size( workshop_form.submission.title ),
642 k_strncpy_always_add_null );
643
644 snprintf( workshop_form.model_path,
645 vg_list_size( workshop_form.model_path ),
646 "Steam Cloud (%lu)", details.m_nPublishedFileId );
647
648 workshop_form.submission.file_id = details.m_nPublishedFileId;
649 workshop_form.file_intent = k_workshop_form_file_intent_keep_old;
650 workshop_form.page = k_workshop_form_edit;
651 workshop_form.submission.visibility.value = details.m_eVisibility;
652
653 for( i32 i=0; i<vg_list_size(workshop_form_visibility_opts); i++ ){
654 if( workshop_form_visibility_opts[i].value == details.m_eVisibility ){
655 workshop_form.submission.visibility.index = i;
656 break;
657 }
658 }
659
660 if( details.m_hPreviewFile == 0 ){
661 vg_error( "m_hPreviewFile is 0\n" );
662 workshop_end_op();
663 }
664 else{
665 /* Now need to begin downloading the image so we can display it */
666 vg_steam_async_call *call = vg_alloc_async_steam_api_call();
667
668 struct workshop_loadpreview_info *info =
669 vg_linear_alloc( vg_mem.scratch,
670 sizeof( struct workshop_loadpreview_info ) );
671
672 snprintf( info->abs_preview_image, 1024,
673 "%smodels/boards/workshop/" PRINTF_U64 ".jpg",
674 vg.base_path, details.m_hPreviewFile );
675
676 call->p_handler = on_workshop_download_ugcpreview;
677 call->userdata = info;
678 call->id = SteamAPI_ISteamRemoteStorage_UGCDownloadToLocation(
679 hSteamRemoteStorage,
680 details.m_hPreviewFile, info->abs_preview_image, 1 );
681
682 vg_info( "preview file id: " PRINTF_U64 "\n",
683 details.m_hPreviewFile );
684 }
685 }
686 else{
687 vg_error( "GetQueryUGCResult: Index out of range\n" );
688 workshop_end_op();
689 }
690 }
691
692 /*
693 * Regular stuff
694 * -----------------------------------------------------------------------------
695 */
696
697 /*
698 * View a page of results on the sidebar
699 */
700 VG_STATIC void workshop_view_page( int req )
701 {
702 if( workshop_form.ugc_query.result != k_EResultOK ){
703 vg_error( "Tried to change page without complete data\n" );
704 return;
705 }
706
707 int page = VG_MAX(VG_MIN(req, workshop_form.view_published_page_count-1),0),
708 start = page * WORKSHOP_VIEW_PER_PAGE,
709 end = VG_MIN( (page+1) * WORKSHOP_VIEW_PER_PAGE,
710 workshop_form.ugc_query.returned_item_count ),
711 count = end-start;
712
713 vg_info( "View page %d\n", page );
714
715 workshop_form.view_published_page_id = page;
716 workshop_form.published_files_list_length = count;
717 ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
718
719 for( int i=0; i<count; i ++ ){
720 struct published_file *pfile = &workshop_form.published_files_list[i];
721
722 SteamUGCDetails_t details;
723 if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC,
724 workshop_form.ugc_query.handle,
725 start+i,
726 &details ) )
727 {
728 if( details.m_eResult != k_EResultOK ){
729 snprintf( pfile->title, 80, "Error (%d)", details.m_eResult );
730 }
731 else{
732 vg_strncpy( details.m_rgchTitle, pfile->title, 80,
733 k_strncpy_always_add_null );
734 }
735
736 pfile->result = details.m_eResult;
737 pfile->result_index = start+i;
738 }
739 else{
740 pfile->result = k_EResultValueOutOfRange;
741 pfile->result_index = -1;
742 snprintf( pfile->title, 80, "Error (invalid index)" );
743 }
744 }
745 }
746
747 /*
748 * Steam API result for when we recieve submitted UGC information about the user
749 */
750 VG_STATIC void on_workshop_UGCQueryComplete( void *data, void *userdata )
751 {
752 SteamUGCQueryCompleted_t *query = data;
753 workshop_form.ugc_query.result = query->m_eResult;
754
755 if( query->m_eResult == k_EResultOK ){
756 if( query->m_unTotalMatchingResults > 50 ){
757 vg_warn( "You have %d items submitted, "
758 "we can only view the last 50\n" );
759 }
760
761 workshop_form.ugc_query.all_item_count = query->m_unTotalMatchingResults;
762 workshop_form.ugc_query.returned_item_count =
763 query->m_unNumResultsReturned;
764
765 workshop_form.ugc_query.handle = query->m_handle;
766 workshop_form.view_published_page_count =
767 (query->m_unNumResultsReturned+WORKSHOP_VIEW_PER_PAGE-1)/
768 WORKSHOP_VIEW_PER_PAGE;
769 workshop_form.view_published_page_id = 0;
770 workshop_form.published_files_list_length = 0;
771
772 workshop_view_page( 0 );
773 }
774 else{
775 vg_error( "Steam UGCQuery failed (%d)\n", query->m_eResult );
776 workshop_form.view_published_page_count = 0;
777 workshop_form.view_published_page_id = 0;
778 workshop_form.published_files_list_length = 0;
779
780 ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
781 SteamAPI_ISteamUGC_ReleaseQueryUGCRequest( hSteamUGC, query->m_handle );
782 }
783 }
784
785 /*
786 * Console command to open the workshop publisher
787 */
788 VG_STATIC int workshop_submit_command( int argc, const char *argv[] )
789 {
790 if( !steam_ready ){
791 vg_error( "Steam API is not ready or loaded\n" );
792 return 0;
793 }
794
795 workshop_form.page = k_workshop_form_open;
796 workshop_form.view_published_page_count = 0;
797 workshop_form.view_published_page_id = 0;
798 workshop_form.published_files_list_length = 0;
799 workshop_form.ugc_query.result = k_EResultNone;
800
801 vg_steam_async_call *call = vg_alloc_async_steam_api_call();
802
803 ISteamUser *hSteamUser = SteamAPI_SteamUser();
804 CSteamID steamid;
805 steamid.m_unAll64Bits = SteamAPI_ISteamUser_GetSteamID( hSteamUser );
806
807 ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
808 call->p_handler = on_workshop_UGCQueryComplete;
809 call->userdata = NULL;
810 UGCQueryHandle_t handle = SteamAPI_ISteamUGC_CreateQueryUserUGCRequest
811 (
812 hSteamUGC,
813 steamid.m_comp.m_unAccountID,
814 k_EUserUGCList_Published,
815 k_EUGCMatchingUGCType_Items,
816 k_EUserUGCListSortOrder_CreationOrderDesc,
817 SKATERIFT_APPID, SKATERIFT_APPID,
818 1 );
819 call->id = SteamAPI_ISteamUGC_SendQueryUGCRequest( hSteamUGC, handle );
820 return 0;
821 }
822
823 VG_STATIC void workshop_init(void)
824 {
825 vg_console_reg_cmd( "workshop_submit", workshop_submit_command, NULL );
826 }
827
828 VG_STATIC void workshop_find_preview_entity(void)
829 {
830 workshop_form.view_world = get_active_world();
831
832 if( mdl_arrcount( &workshop_form.view_world->ent_swspreview ) ){
833 workshop_form.ptr_ent =
834 mdl_arritm( &workshop_form.view_world->ent_swspreview, 0 );
835 workshop_form.page = k_workshop_form_edit;
836 }
837 else{
838 vg_error( "There is no ent_swspreview in the level. "
839 "Cannot publish here\n" );
840 }
841 }
842
843 /*
844 * Redraw the model file into the workshop framebuffer
845 */
846 VG_STATIC void workshop_render_preview(void)
847 {
848 if( !workshop_form.ptr_ent ){
849 return;
850 }
851
852 render_fb_bind( gpipeline.fb_workshop_preview, 0 );
853
854 glClearColor( 0.0f, 0.0f, 0.3f, 1.0f );
855 glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
856 glEnable( GL_DEPTH_TEST );
857 glDisable( GL_BLEND );
858
859 ent_swspreview *swsprev = workshop_form.ptr_ent;
860 world_instance *world = workshop_form.view_world;
861
862 ent_camera *ref = mdl_arritm( &world->ent_camera,
863 mdl_entity_id_id(swsprev->id_camera) );
864 ent_marker *display = mdl_arritm( &world->ent_marker,
865 mdl_entity_id_id(swsprev->id_display) ),
866 *display1= mdl_arritm( &world->ent_marker,
867 mdl_entity_id_id(swsprev->id_display1) );
868
869 v3f baseco;
870 v3_add( display->transform.co, display1->transform.co, baseco );
871 v3_muls( baseco, 0.5f, baseco );
872
873 camera cam;
874 v3f basevector;
875 v3_sub( display->transform.co, ref->transform.co, basevector );
876 float dist = v3_length( basevector );
877
878 v3f baseangles;
879 player_vector_angles( baseangles, basevector, 1.0f, 0.0f );
880
881 v2_add( workshop_form.view_angles, baseangles, cam.angles );
882 cam.angles[2] = 0.0f;
883
884 float sX = sinf( cam.angles[0] ),
885 cX = cosf( cam.angles[0] ),
886 sY = sinf( cam.angles[1] ),
887 cY = cosf( cam.angles[1] );
888
889 v3f offset = { -sX * cY, sY, cX * cY };
890
891 v3_muladds( display->transform.co, offset,
892 dist*workshop_form.view_dist, cam.pos );
893
894 cam.pos[0] += -sX*workshop_form.view_offset[2];
895 cam.pos[2] += cX*workshop_form.view_offset[2];
896 cam.pos[0] += cX*workshop_form.view_offset[0];
897 cam.pos[2] += sX*workshop_form.view_offset[0];
898 cam.pos[1] += workshop_form.view_offset[1];
899
900 cam.nearz = 0.01f;
901 cam.farz = 100.0f;
902 cam.fov = ref->fov;
903
904 camera_update_transform( &cam );
905 camera_update_view( &cam );
906 camera_update_projection( &cam );
907 camera_finalize( &cam );
908
909 m4x3f mmdl, mmdl1;
910 mdl_transform_m4x3( &display->transform, mmdl );
911 mdl_transform_m4x3( &display1->transform, mmdl1 );
912
913 /* force update this for nice shadows. its usually set in the world
914 * pre-render step, but that includes timer stuff
915 */
916 struct player_board *board = &workshop_form.board_model;
917 struct ub_world_lighting *ubo = &world->ub_lighting;
918 v3f vp0, vp1;
919 v3_copy((v3f){0.0f,0.1f, board->truck_positions[0][2]}, vp0 );
920 v3_copy((v3f){0.0f,0.1f, board->truck_positions[1][2]}, vp1 );
921 m4x3_mulv( mmdl1, vp0, ubo->g_board_0 );
922 m4x3_mulv( mmdl1, vp1, ubo->g_board_1 );
923 glBindBuffer( GL_UNIFORM_BUFFER, world->ubo_lighting );
924 glBufferSubData( GL_UNIFORM_BUFFER, 0,
925 sizeof(struct ub_world_lighting), &world->ub_lighting );
926
927 render_world( world, &cam, 1 );
928 render_board( &cam, world, board, mmdl, k_board_shader_entity );
929 render_board( &cam, world, board, mmdl1, k_board_shader_entity );
930
931 glBindFramebuffer( GL_FRAMEBUFFER, 0 );
932 glViewport( 0,0, vg.window_x, vg.window_y );
933 }
934
935 /*
936 * ImGUI section for workshop form
937 * -----------------------------------------------------------------------------
938 */
939
940 VG_STATIC void workshop_changed_model_path( char *buf, u32 len ){
941 workshop_form.submission.submit_file_and_image = 1;
942 }
943
944 VG_STATIC void workshop_changed_title( char *buf, u32 len ){
945 workshop_form.submission.submit_title = 1;
946 }
947
948 VG_STATIC void workshop_changed_description( char *buf, u32 len ){
949 workshop_form.submission.submit_description = 1;
950 }
951
952 VG_STATIC void workshop_form_gui_edit_page( ui_rect content )
953 {
954 ui_rect image_plane;
955 ui_split( content, k_ui_axis_h, 300, 0, image_plane, content );
956 ui_fill( image_plane, ui_colour( k_ui_bg+0 ) );
957
958 ui_rect img_box;
959 ui_fit_item( image_plane, (ui_px[2]){ 3, 2 }, img_box );
960
961 if( workshop_form.file_intent == k_workshop_form_file_intent_keep_old ){
962 ui_image( img_box, gpipeline.fb_workshop_preview->attachments[0].id );
963 }
964 else if( workshop_form.file_intent == k_workshop_form_file_intent_new ){
965 ui_image( img_box, gpipeline.fb_workshop_preview->attachments[0].id );
966 int hover = ui_inside_rect( img_box, vg_ui.mouse ),
967 target = ui_inside_rect( img_box, vg_ui.mouse_click );
968
969 if( ui_click_down(UI_MOUSE_MIDDLE) && target ){
970 v3_copy( workshop_form.view_offset,
971 workshop_form.view_offset_begin );
972 }
973 else if( ui_click_down(UI_MOUSE_LEFT) && target ){
974 v2_copy( workshop_form.view_angles,
975 workshop_form.view_angles_begin );
976 }
977
978 if( ui_clicking(UI_MOUSE_MIDDLE) && target ){
979 v2f delta = { vg_ui.mouse[0]-vg_ui.mouse_click[0],
980 vg_ui.mouse[1]-vg_ui.mouse_click[1] };
981
982 float *begin = workshop_form.view_offset_begin,
983 *offset = workshop_form.view_offset;
984 offset[0] = vg_clampf( begin[0]-delta[0]*0.002f, -1.0f, 1.0f );
985 offset[2] = vg_clampf( begin[2]-delta[1]*0.002f, -1.0f, 1.0f );
986 workshop_form.view_changed = 1;
987 }
988 else if( ui_clicking(UI_MOUSE_LEFT) && target ){
989 v2f delta = { vg_ui.mouse[0]-vg_ui.mouse_click[0],
990 vg_ui.mouse[1]-vg_ui.mouse_click[1] };
991
992 v2f angles;
993 v2_muladds( workshop_form.view_angles_begin, delta, 0.002f, angles);
994
995 float limit = VG_PIf*0.2f;
996
997 angles[0] = vg_clampf( angles[0], -limit, limit );
998 angles[1] = vg_clampf( angles[1], -limit, limit );
999
1000 v2_copy( angles, workshop_form.view_angles );
1001 workshop_form.view_changed = 1;
1002 }
1003
1004 if( !ui_clicking(UI_MOUSE_LEFT) && hover ){
1005 float zoom = workshop_form.view_dist;
1006 zoom += vg.mouse_wheel[1] * -0.07f;
1007 zoom = vg_clampf( zoom, 0.4f, 2.0f );
1008
1009 if( zoom != workshop_form.view_dist ){
1010 workshop_form.view_changed = 1;
1011 workshop_form.view_dist = zoom;
1012 }
1013 }
1014 }
1015 else{
1016 ui_text( img_box, "No image", 1, k_ui_align_middle_center,
1017 ui_colour( k_ui_orange ) );
1018 }
1019
1020 /* file path */
1021 ui_rect null, file_entry, file_button, file_label;
1022 ui_split( content, k_ui_axis_h, 8, 0, null, content );
1023 ui_split( content, k_ui_axis_h, 28, 0, file_entry, content );
1024 ui_split( file_entry, k_ui_axis_v, -128, 0, file_entry, file_button );
1025 ui_split_label( file_entry, "File:", 1, 8, file_label, file_entry );
1026 ui_text( file_label, "File:", 1, k_ui_align_middle_left, 0 );
1027
1028 if( workshop_form.file_intent != k_workshop_form_file_intent_none ){
1029 ui_text( file_entry, workshop_form.model_path, 1, k_ui_align_middle_left,
1030 ui_colour( k_ui_fg+4 ) );
1031
1032 if( ui_button_text( file_button, "Remove", 1 ) ){
1033 player_board_unload( &workshop_form.board_model );
1034 workshop_form.file_intent = k_workshop_form_file_intent_none;
1035 workshop_form.model_path[0] = '\0';
1036 }
1037 }
1038 else{
1039 struct ui_textbox_callbacks callbacks = {
1040 .change = workshop_changed_model_path
1041 };
1042
1043 ui_textbox( file_entry, workshop_form.model_path,
1044 vg_list_size(workshop_form.model_path), 0, &callbacks );
1045
1046 if( ui_button_text( file_button, "Load", 1 ) ){
1047 workshop_find_preview_entity();
1048 workshop_op_load_model();
1049 }
1050 }
1051
1052 ui_rect title_entry, label;
1053 ui_split( content, k_ui_axis_h, 8, 0, null, content );
1054 ui_split( content, k_ui_axis_h, 28, 0, title_entry, content );
1055
1056 const char *str_title = "Title:", *str_desc = "Description:";
1057 ui_split( title_entry, k_ui_axis_v,
1058 ui_text_line_width(str_title)+8, 0, label, title_entry );
1059
1060 ui_rect vis_dropdown;
1061 ui_split_ratio( title_entry, k_ui_axis_v, 0.6f, 16,
1062 title_entry, vis_dropdown );
1063
1064 /* title box */
1065 {
1066 struct ui_textbox_callbacks callbacks = {
1067 .change = workshop_changed_title
1068 };
1069 ui_text( label, str_title, 1, k_ui_align_middle_left, 0 );
1070 ui_textbox( title_entry, workshop_form.submission.title,
1071 vg_list_size(workshop_form.submission.title), 0, &callbacks );
1072 }
1073
1074 /* visibility option */
1075 {
1076 ui_enum( vis_dropdown, "Visibility:", workshop_form_visibility_opts,
1077 4, &workshop_form.submission.visibility );
1078 }
1079
1080 /* description box */
1081 {
1082 struct ui_textbox_callbacks callbacks = {
1083 .change = workshop_changed_description
1084 };
1085 ui_rect desc_entry;
1086 /* TODO: Tommora, new split_px_gap and split_px() */
1087 ui_split( content, k_ui_axis_h, 8, 0, null, content );
1088 ui_split( content, k_ui_axis_h, 28, 0, label, content );
1089 ui_split( content, k_ui_axis_h, 28*4, 0, desc_entry, content );
1090 ui_text( label, str_desc, 1, k_ui_align_middle_left, 0 );
1091 ui_textbox( desc_entry, workshop_form.submission.description,
1092 vg_list_size(workshop_form.submission.description),
1093 UI_TEXTBOX_MULTILINE|UI_TEXTBOX_WRAP, &callbacks );
1094 }
1095
1096 /* submissionable */
1097 ui_rect submission_row;
1098 ui_split( content, k_ui_axis_h, 8, 0, null, content );
1099 ui_split( content, k_ui_axis_h, content[3]-32-8, 0, content,
1100 submission_row );
1101
1102 ui_rect submission_center;
1103 rect_copy( submission_row, submission_center );
1104 submission_center[2] = 256;
1105 ui_rect_center( submission_row, submission_center );
1106
1107 ui_rect btn_left, btn_right;
1108 ui_split_ratio( submission_center, k_ui_axis_v, 0.5f, 8,
1109 btn_left, btn_right );
1110
1111 if( ui_button_text( btn_left, "Publish", 1 ) ){
1112 workshop_op_submit();
1113 }
1114 if( ui_button_text( btn_right, "Cancel", 1 ) ){
1115 workshop_form.page = k_workshop_form_open;
1116 player_board_unload( &workshop_form.board_model );
1117 workshop_form.file_intent = k_workshop_form_file_intent_none;
1118 }
1119
1120 /* disclaimer */
1121 const char *disclaimer_text =
1122 "By submitting this item, you agree to the workshop terms of service";
1123
1124 ui_rect disclaimer_row, inner, link;
1125 ui_split( content, k_ui_axis_h, 8, 0, null, content );
1126 ui_split( content, k_ui_axis_h, content[3]-32, 0, content,
1127 disclaimer_row );
1128
1129 ui_px btn_width = 32;
1130
1131 rect_copy( disclaimer_row, inner );
1132 inner[2] = ui_text_line_width( disclaimer_text ) + btn_width+8;
1133
1134 ui_rect_center( disclaimer_row, inner );
1135 ui_split( inner, k_ui_axis_v, inner[2]-btn_width, 0, label, btn_right);
1136 ui_rect_pad( btn_right, (ui_px[2]){2,2} );
1137
1138 if( ui_button_text( btn_right, "\x91", 2 ) ){
1139 ISteamFriends *hSteamFriends = SteamAPI_SteamFriends();
1140 SteamAPI_ISteamFriends_ActivateGameOverlayToWebPage( hSteamFriends,
1141 "https://steamcommunity.com/sharedfiles/workshoplegalagreement",
1142 k_EActivateGameOverlayToWebPageMode_Default );
1143 }
1144
1145 ui_text( label, disclaimer_text, 1, k_ui_align_middle_left,
1146 ui_colour( k_ui_fg+4 ) );
1147 }
1148
1149 VG_STATIC void workshop_form_gui_sidebar( ui_rect sidebar )
1150 {
1151 /*
1152 * sidebar existing entries panel
1153 */
1154 ui_fill( sidebar, ui_colour( k_ui_bg+2 ) );
1155
1156 ui_rect title;
1157 ui_split( sidebar, k_ui_axis_h, 28, 0, title, sidebar );
1158 ui_text( title, "Your submissions", 1, k_ui_align_middle_center, 0 );
1159
1160 ui_rect controls, btn_create_new;
1161 ui_split( sidebar, k_ui_axis_h, 32, 0, controls, sidebar );
1162 ui_split( sidebar, k_ui_axis_h, -32, 0, sidebar, btn_create_new );
1163 ui_fill( controls, ui_colour( k_ui_bg+1 ) );
1164
1165 char buf[32];
1166 strcpy( buf, "page " );
1167 int i = 5;
1168
1169 /* TODO: for what it is, this code is getting a bit.. special */
1170 i += highscore_intl( buf+i, workshop_form.view_published_page_id+1, 4 );
1171 buf[ i ++ ] = '/';
1172 i += highscore_intl( buf+i, workshop_form.view_published_page_count, 4 );
1173 buf[ i ++ ] = '\0';
1174
1175 ui_rect_pad( controls, (ui_px[2]){0,4} );
1176 ui_rect info;
1177 ui_split_ratio( controls, k_ui_axis_v, 0.25f, 0, info, controls );
1178 ui_text( info, buf, 1, k_ui_align_middle_center, 0 );
1179
1180 ui_rect btn_left, btn_right;
1181 ui_split_ratio( controls, k_ui_axis_v, 0.5f, 2, btn_left, btn_right );
1182
1183 if( ui_button_text( btn_left, "newer", 1 ) ){
1184 workshop_view_page( workshop_form.view_published_page_id-1 );
1185 }
1186
1187 if( ui_button_text( btn_right, "older", 1 ) ){
1188 workshop_view_page( workshop_form.view_published_page_count+1 );
1189 }
1190
1191 if( ui_button_text( btn_create_new, "Create New Item", 1 ) ){
1192 workshop_reset_submission_data();
1193 workshop_form.submission.submit_title = 1;
1194 workshop_form.submission.submit_description = 1;
1195 workshop_form.submission.submit_file_and_image = 1;
1196 workshop_form.page = k_workshop_form_edit;
1197 workshop_find_preview_entity();
1198 }
1199
1200 for( int i=0; i<workshop_form.published_files_list_length; i++ ){
1201 ui_rect item;
1202 ui_split( sidebar, k_ui_axis_h, 28, 0, item, sidebar );
1203 ui_rect_pad( item, (ui_px[2]){4,4} );
1204
1205 struct published_file *pfile = &workshop_form.published_files_list[i];
1206 if( ui_button_text( item, pfile->title, 1 ) ){
1207 if( pfile->result == k_EResultOK ){
1208 vg_info( "Select index: %d\n", pfile->result_index );
1209 workshop_op_download_and_view_submission( pfile->result_index );
1210 }
1211 else{
1212 vg_warn( "Cannot select that item, result not OK\n" );
1213 }
1214 }
1215 }
1216 }
1217
1218 VG_STATIC void workshop_form_gui(void)
1219 {
1220 enum workshop_form_page stable_page = workshop_form.page;
1221 if( stable_page == k_workshop_form_hidden ) return;
1222
1223 ui_rect null;
1224 ui_rect screen = { 0, 0, vg.window_x, vg.window_y };
1225 ui_rect window = { 0, 0, 1000, 700 };
1226 ui_rect_center( screen, window );
1227 vg_ui.wants_mouse = 1;
1228
1229 ui_fill( window, ui_colour( k_ui_bg+1 ) );
1230 ui_outline( window, 1, ui_colour( k_ui_bg+7 ) );
1231
1232 ui_rect title, panel;
1233 ui_split( window, k_ui_axis_h, 28, 0, title, panel );
1234 ui_fill( title, ui_colour( k_ui_bg+7 ) );
1235 ui_text( title, "Workshop tool", 1, k_ui_align_middle_center,
1236 ui_colourcont(k_ui_bg+7) );
1237
1238 ui_rect quit_button;
1239 ui_split( title, k_ui_axis_v, title[2]-title[3], 2, title, quit_button );
1240
1241 if( workshop.operation == k_workshop_form_op_none ){
1242 if( ui_button_text( quit_button, "X", 1 ) ){
1243 workshop_quit_form();
1244 return;
1245 }
1246 }
1247
1248 /*
1249 * temporary operation blinders, we don't yet have a nice way to show the
1250 * user that we're doing something uninterruptable, so the code just
1251 * escapes here and we show them a basic string
1252 */
1253
1254 if( workshop.operation != k_workshop_form_op_none ){
1255 const char *op_string = "The programmer has not bothered to describe "
1256 "the current operation that is running.";
1257
1258 switch(workshop.operation){
1259 case k_workshop_form_op_loading_model:
1260 op_string = "Operation in progress: Loading model file.";
1261 break;
1262 case k_workshop_form_op_publishing_update:
1263 op_string = "Operation in progress: publishing submission update "
1264 "to steam.";
1265 break;
1266 case k_workshop_form_op_downloading_submission:
1267 op_string = "Operation in progress: downloading existing submission"
1268 " from Steam services.";
1269 break;
1270 default: break;
1271 }
1272
1273 ui_text( panel, op_string, 1, k_ui_align_middle_center, 0 );
1274 return;
1275 }
1276
1277 /* re draw board preview if need to */
1278 if( (stable_page == k_workshop_form_edit) &&
1279 workshop_form.view_changed &&
1280 workshop_form.file_intent == k_workshop_form_file_intent_new )
1281 {
1282 workshop_render_preview();
1283 workshop_form.view_changed = 0;
1284 }
1285
1286 struct workshop_form *form = &workshop_form;
1287
1288 ui_rect sidebar, content;
1289 ui_split_ratio( panel, k_ui_axis_v, 0.3f, 1, sidebar, content );
1290
1291 /* content page */
1292 ui_rect_pad( content, (ui_px[2]){8,8} );
1293
1294 if( stable_page == k_workshop_form_edit ){
1295 workshop_form_gui_edit_page( content );
1296 }
1297 else if( stable_page == k_workshop_form_open ){
1298 ui_text( content, "Nothing selected.", 1, k_ui_align_middle_center,
1299 ui_colour( k_ui_fg+4 ) );
1300 }
1301 else if( stable_page >= k_workshop_form_cclosing ){
1302 ui_rect submission_row;
1303 ui_split( content, k_ui_axis_h, content[3]-32-8, 0, content,
1304 submission_row );
1305
1306 u32 colour;
1307
1308 if( stable_page == k_workshop_form_closing_bad )
1309 colour = ui_colour( k_ui_red+k_ui_brighter );
1310 else
1311 colour = ui_colour( k_ui_green+k_ui_brighter );
1312
1313 ui_text( content, workshop_form.failure_or_success_string, 1,
1314 k_ui_align_middle_center, colour );
1315
1316 ui_rect submission_center;
1317 rect_copy( submission_row, submission_center );
1318 submission_center[2] = 128;
1319 ui_rect_center( submission_row, submission_center );
1320 ui_rect_pad( submission_center, (ui_px[2]){8,8} );
1321
1322 if( ui_button_text( submission_center, "OK", 1 ) ){
1323 workshop_form.page = k_workshop_form_open;
1324 }
1325 }
1326
1327 workshop_form_gui_sidebar( sidebar );
1328 }
1329
1330 /*
1331 * Some async api stuff
1332 * -----------------------------------------------------------------------------
1333 */
1334
1335 VG_STATIC void async_workshop_get_filepath( void *data, u32 len )
1336 {
1337 struct async_workshop_filepath_info *info = data;
1338
1339 u64 _size;
1340 u32 _ts;
1341
1342 ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
1343 if( !SteamAPI_ISteamUGC_GetItemInstallInfo( hSteamUGC, info->id, &_size,
1344 info->buf, info->len, &_ts ))
1345 {
1346 info->buf[0] = '\0';
1347 }
1348 }
1349
1350 VG_STATIC void async_workshop_get_installed_files( void *data, u32 len )
1351 {
1352 struct async_workshop_installed_files_info *info = data;
1353
1354 ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
1355 u32 count = SteamAPI_ISteamUGC_GetSubscribedItems( hSteamUGC, info->buffer,
1356 *info->len );
1357
1358 vg_info( "Found %u subscribed items\n", count );
1359
1360 u32 j=0;
1361 for( u32 i=0; i<count; i++ ){
1362 u32 state = SteamAPI_ISteamUGC_GetItemState( hSteamUGC, info->buffer[i] );
1363 if( state & k_EItemStateInstalled ){
1364 info->buffer[j ++] = info->buffer[i];
1365 }
1366 }
1367
1368 *info->len = j;
1369 }
1370
1371 #endif /* WORKSHOP_C */