+++ /dev/null
-#ifndef WORKSHOP_C
-#define WORKSHOP_C
-
-#include "workshop.h"
-
-#define VG_GAME
-#include "vg/vg.h"
-#include "vg/vg_tex.h"
-#include "vg/vg_msg.h"
-#include "ent_skateshop.h"
-
-#include "vg/vg_steam_auth.h"
-#include "vg/vg_steam_ugc.h"
-#include "vg/vg_steam_friends.h"
-#include "steam.h"
-#include "highscores.h"
-
-static struct ui_enum_opt workshop_form_visibility_opts[] = {
- { k_ERemoteStoragePublishedFileVisibilityPublic, "Public" },
- { k_ERemoteStoragePublishedFileVisibilityUnlisted, "Unlisted" },
- { k_ERemoteStoragePublishedFileVisibilityFriendsOnly, "Friends Only" },
- { k_ERemoteStoragePublishedFileVisibilityPrivate, "Private" },
-};
-
-static struct ui_enum_opt workshop_form_type_opts[] = {
- { k_addon_type_none, "None" },
- { k_addon_type_board, "Board" },
- { k_addon_type_world, "World" },
- { k_addon_type_player, "Player" },
-};
-
-/*
- * Close the form and discard UGC query result
- */
-VG_STATIC void workshop_quit_form(void){
- player_board_unload( &workshop_form.board_model );
- workshop_form.file_intent = k_workshop_form_file_intent_none;
-
- if( workshop_form.ugc_query.result == k_EResultOK ){
- workshop_form.ugc_query.result = k_EResultNone;
-
- ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
- SteamAPI_ISteamUGC_ReleaseQueryUGCRequest(
- hSteamUGC, workshop_form.ugc_query.handle );
- }
-
- workshop_form.page = k_workshop_form_hidden;
- workshop_form.op = k_workshop_op_none;
-}
-
-/*
- * Delete all information about the submission
- */
-VG_STATIC void workshop_reset_submission_data(void)
-{
- workshop_form.submission.file_id = 0; /* assuming id of 0 is none/invalid */
- workshop_form.submission.description[0] = '\0';
- workshop_form.submission.title[0] = '\0';
- workshop_form.submission.author[0] = '\0';
- workshop_form.submission.submission_type_selection =
- k_addon_type_none;
- workshop_form.submission.type = k_addon_type_none;
-
- workshop_form.submission.visibility =
- k_ERemoteStoragePublishedFileVisibilityPublic;
-
- workshop_form.addon_folder[0] = '\0';
- player_board_unload( &workshop_form.board_model );
- workshop_form.file_intent = k_workshop_form_file_intent_none;
-}
-
-
-/*
- * Mostly copies of what it sais on the Steam API documentation
- */
-VG_STATIC const char *workshop_EResult_user_string( EResult result )
-{
- switch( result ){
- case k_EResultInsufficientPrivilege:
- return "Your account is currently restricted from uploading content "
- "due to a hub ban, account lock, or community ban. You need to "
- "contact Steam Support to resolve the issue.";
- case k_EResultBanned:
- return "You do not have permission to upload content to this hub "
- "because you have an active VAC or Game ban.";
- case k_EResultTimeout:
- return "The operation took longer than expected, so it was discarded. "
- "Please try again.";
- case k_EResultNotLoggedOn:
- return "You are currently not logged into Steam.";
- case k_EResultServiceUnavailable:
- return "The workshop server is having issues or is unavailable, "
- "please try again.";
- case k_EResultInvalidParam:
- return "One of the submission fields contains something not being "
- "accepted by that field.";
- case k_EResultAccessDenied:
- return "There was a problem trying to save the title and description. "
- "Access was denied.";
- case k_EResultLimitExceeded:
- return "You have exceeded your Steam Cloud quota. If you wish to "
- "upload this file, you must remove some published items.";
- case k_EResultFileNotFound:
- return "The uploaded file could not be found.";
- case k_EResultDuplicateRequest:
- return "The file was already successfully uploaded.";
- case k_EResultDuplicateName:
- return "You already have a Steam Workshop item with that name.";
- case k_EResultServiceReadOnly:
- return "Due to a recent password or email change, you are not allowed "
- "to upload new content. Usually this restriction will expire in"
- " 5 days, but can last up to 30 days if the account has been "
- "inactive recently.";
- default:
- return "Operation failed for an error which has not been accounted for "
- "by the programmer. Try again, sorry :)";
- }
-}
-
-/*
- * op: k_workshop_form_op_publishing_update
- * ----------------------------------------------------------------------------
- */
-
-/*
- * The endpoint of this operation
- */
-VG_STATIC void on_workshop_update_result( void *data, void *user )
-{
- vg_info( "Recieved workshop update result\n" );
- SubmitItemUpdateResult_t *result = data;
-
- /* this seems to be set here, but my account definitely has accepted it */
- if( result->m_bUserNeedsToAcceptWorkshopLegalAgreement ){
- vg_warn( "Workshop agreement currently not accepted\n" );
- }
-
- if( result->m_eResult == k_EResultOK ){
- workshop_form.page = k_workshop_form_closing_good;
- workshop_form.failure_or_success_string = "Uploaded workshop file!";
- vg_success( "file uploaded\n" );
- }
- else{
- workshop_form.page = k_workshop_form_closing_bad;
- workshop_form.failure_or_success_string =
- workshop_EResult_user_string( result->m_eResult );
-
- vg_error( "Error with the submitted file (%d)\n", result->m_eResult );
- }
- workshop_form.op = k_workshop_op_none;
-}
-
-VG_STATIC const char *workshop_filetype_folder(void){
- enum addon_type type = workshop_form.submission.type;
- if ( type == k_addon_type_board ) return "boards/";
- else if( type == k_addon_type_player ) return "playermodels/";
- else if( type == k_addon_type_world ) return "maps/";
-
- return "unknown_addon_type/";
-}
-
-/*
- * reciever on completion of packaging the files, it will then start the item
- * update with Steam API
- */
-VG_STATIC void workshop_form_upload_submission( PublishedFileId_t file_id,
- char *metadata )
-{
- ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
- UGCUpdateHandle_t handle
- = SteamAPI_ISteamUGC_StartItemUpdate( hSteamUGC, SKATERIFT_APPID,
- file_id );
-
- /* TODO: Handle failure cases for these */
-
- SteamAPI_ISteamUGC_SetItemMetadata( hSteamUGC, handle, metadata );
-
- if( workshop_form.submission.submit_title ){
- vg_info( "Setting title\n" );
- SteamAPI_ISteamUGC_SetItemTitle( hSteamUGC, handle,
- workshop_form.submission.title );
- }
-
- if( workshop_form.submission.submit_description ){
- vg_info( "Setting description\n" );
- SteamAPI_ISteamUGC_SetItemDescription( hSteamUGC, handle,
- workshop_form.submission.description);
- }
-
- if( workshop_form.submission.submit_file_and_image ){
- char path_buf[4096];
- vg_str folder;
- vg_strnull( &folder, path_buf, 4096 );
- vg_strcat( &folder, vg.base_path );
-
- vg_strcat( &folder, workshop_filetype_folder() );
- vg_strcat( &folder, workshop_form.addon_folder );
-
- vg_info( "Setting item content\n" );
- SteamAPI_ISteamUGC_SetItemContent( hSteamUGC, handle, folder.buffer );
-
- vg_str preview = folder;
- vg_strcat( &preview, "/preview.jpg" );
-
- vg_info( "Setting preview image\n" );
- SteamAPI_ISteamUGC_SetItemPreview( hSteamUGC, handle, preview.buffer );
- }
-
- vg_info( "Setting visibility\n" );
- SteamAPI_ISteamUGC_SetItemVisibility( hSteamUGC, handle,
- workshop_form.submission.visibility );
-
- vg_info( "Submitting updates\n" );
- vg_steam_async_call *call = vg_alloc_async_steam_api_call();
- call->userdata = NULL;
- call->p_handler = on_workshop_update_result;
- call->id = SteamAPI_ISteamUGC_SubmitItemUpdate( hSteamUGC, handle, "" );
-}
-
-/*
- * Steam API call result for when we've created a new item on their network, or
- * not, if it has failed
- */
-VG_STATIC void on_workshop_createitem( void *data, void *user )
-{
- CreateItemResult_t *result = data;
-
- if( result->m_eResult == k_EResultOK ){
- vg_info( "Created workshop file with id: %lu\n",
- result->m_nPublishedFileId );
-
- if( result->m_bUserNeedsToAcceptWorkshopLegalAgreement ){
- vg_warn( "Workshop agreement currently not accepted\n" );
- }
-
- workshop_form_upload_submission( result->m_nPublishedFileId, user );
- }
- else{
- const char *errstr = workshop_EResult_user_string( result->m_eResult );
-
- if( errstr ){
- vg_error( "ISteamUGC_CreateItem() failed(%d): '%s' \n",
- result->m_eResult, errstr );
- }
-
- workshop_form.page = k_workshop_form_closing_bad;
- workshop_form.failure_or_success_string = errstr;
- }
-}
-
-/*
- * Starts the workshop upload process through Steam API
- */
-VG_STATIC void workshop_form_async_submit_begin( void *payload, u32 size )
-{
-
- /* use existing file */
- if( workshop_form.submission.file_id ){
- workshop_form_upload_submission( workshop_form.submission.file_id,
- payload );
- }
- else{
- vg_steam_async_call *call = vg_alloc_async_steam_api_call();
- call->userdata = payload;
- call->p_handler = on_workshop_createitem;
- ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
- call->id = SteamAPI_ISteamUGC_CreateItem( hSteamUGC, SKATERIFT_APPID,
- k_EWorkshopFileTypeCommunity );
- }
-}
-
-/*
- * Downloads the framebuffer into scratch memory
- */
-VG_STATIC void workshop_form_async_download_image( void *payload, u32 size )
-{
- int w, h;
- render_fb_get_current_res( gpipeline.fb_workshop_preview, &w, &h );
- vg_linear_clear( vg_mem.scratch );
- workshop_form.img_buffer = vg_linear_alloc( vg_mem.scratch, w*h*3 );
-
- vg_info( "read framebuffer: glReadPixels( %dx%d )\n", w,h );
-
- glBindFramebuffer( GL_READ_FRAMEBUFFER, gpipeline.fb_workshop_preview->fb );
- glReadBuffer( GL_COLOR_ATTACHMENT0 );
- glReadPixels( 0,0, w,h, GL_RGB, GL_UNSIGNED_BYTE, workshop_form.img_buffer );
-
- workshop_form.img_w = w;
- workshop_form.img_h = h;
-}
-
-/*
- * Thread which kicks off the upload process
- */
-VG_STATIC void _workshop_form_submit_thread( void *data )
-{
- vg_async_call( workshop_form_async_download_image, NULL, 0 );
- vg_async_stall();
-
- char path_buf[4096];
- vg_str folder;
- vg_strnull( &folder, path_buf, 4096 );
-
- vg_strcat( &folder, workshop_filetype_folder() );
- vg_strcat( &folder, workshop_form.addon_folder );
-
- if( !vg_strgood(&folder) ){
- vg_error( "addon folder path too long\n" );
- workshop_form.op = k_workshop_op_none;
- return;
- }
-
- /*
- * Create the metadata file
- * -----------------------------------------------------------------------*/
- u8 descriptor_buf[ 512 ];
- vg_msg descriptor = {0};
- descriptor.buf = descriptor_buf;
- descriptor.max = sizeof(descriptor_buf);
-
- vg_linear_clear( vg_mem.scratch );
-
- /* short description */
- vg_msg_frame( &descriptor, "workshop" );
- vg_msg_wkvstr( &descriptor, "title", workshop_form.submission.title );
- //vg_msg_wkvstr( &descriptor, "author", "unknown" );
- vg_msg_wkvu32( &descriptor, "type", workshop_form.submission.type );
- vg_msg_wkvstr( &descriptor, "folder", workshop_form.addon_folder );
- vg_msg_end_frame( &descriptor );
- //vg_msg_wkvstr( &descriptor, "location", "USA" );
-
- char *short_descriptor_str = vg_linear_alloc( vg_mem.scratch,
- vg_align8(descriptor.cur*2+1));
- vg_bin_str( descriptor_buf, short_descriptor_str, descriptor.cur );
- short_descriptor_str[descriptor.cur*2] = '\0';
- vg_info( "binstr: %s\n", short_descriptor_str );
-
- vg_dir dir;
- if( !vg_dir_open( &dir, folder.buffer ) ){
- vg_error( "could not open addon folder '%s'\n", folder.buffer );
- workshop_form.op = k_workshop_op_none;
- return;
- }
-
- while( vg_dir_next_entry(&dir) ){
- if( vg_dir_entry_type(&dir) == k_vg_entry_type_file ){
- const char *d_name = vg_dir_entry_name(&dir);
- if( d_name[0] == '.' ) continue;
-
- vg_str file = folder;
- vg_strcat( &file, "/" );
- vg_strcat( &file, d_name );
- if( !vg_strgood( &file ) ) continue;
-
- char *ext = vg_strch( &file, '.' );
- if( !ext ) continue;
- if( strcmp(ext,".mdl") ) continue;
-
- vg_msg_wkvstr( &descriptor, "content", d_name );
- break;
- }
- }
- vg_dir_close(&dir);
-
- vg_str descriptor_file = folder;
- vg_strcat( &descriptor_file, "/addon.inf" );
- if( !vg_strgood(&descriptor_file) ){
- vg_error( "Addon info path too long\n" );
- workshop_form.op = k_workshop_op_none;
- return;
- }
-
- FILE *fp = fopen( descriptor_file.buffer, "wb" );
- if( !fp ){
- vg_error( "Could not open addon info file '%s'\n",
- descriptor_file.buffer );
- workshop_form.op = k_workshop_op_none;
- return;
- }
- fwrite( descriptor_buf, descriptor.cur, 1, fp );
- fclose( fp );
-
- /* Save the preview
- * -----------------------------------------------------------------------*/
- vg_str preview = folder;
- vg_strcat( &preview, "/preview.jpg" );
-
- if( !vg_strgood(&preview) ){
- vg_error( "preview image path too long\n" );
- workshop_form.op = k_workshop_op_none;
- return;
- }
-
- int w = workshop_form.img_w,
- h = workshop_form.img_h;
-
- vg_info( "writing: %s (%dx%d @90%%)\n", preview.buffer, w,h );
- stbi_flip_vertically_on_write(1);
- stbi_write_jpg( preview.buffer, w,h, 3, workshop_form.img_buffer, 90 );
-
- vg_async_call( workshop_form_async_submit_begin, short_descriptor_str, 0 );
-}
-
-/*
- * Entry point for the publishing submission operation
- */
-VG_STATIC void workshop_op_submit(void){
- /* TODO: Show these errors to the user */
- if( workshop_form.submission.submit_title ){
- if( !workshop_form.submission.title[0] ){
- ui_start_modal( "Cannot submit because a title is required\n",
- UI_MODAL_WARN);
- workshop_form.op = k_workshop_op_none;
- return;
- }
- }
-
- if( workshop_form.submission.submit_description ){
- if( !workshop_form.submission.description[0] ){
- ui_start_modal( "Cannot submit because a description is required\n",
- UI_MODAL_WARN );
- workshop_form.op = k_workshop_op_none;
- return;
- }
- }
-
- if( workshop_form.submission.submit_file_and_image ){
- if( workshop_form.file_intent == k_workshop_form_file_intent_none ){
- ui_start_modal( "Cannot submit because the file is "
- "empty or unspecified\n", UI_MODAL_WARN );
- workshop_form.op = k_workshop_op_none;
- return;
- }
- }
-
- player_board_unload( &workshop_form.board_model );
- workshop_form.file_intent = k_workshop_form_file_intent_none;
- workshop_form.op = k_workshop_op_publishing_update;
-
- vg_loader_start( _workshop_form_submit_thread, NULL );
-}
-
-/*
- * op: k_workshop_form_op_loading_model
- * -----------------------------------------------------------------------------
- */
-
-/*
- * Reciever for completion of the model file load
- */
-VG_STATIC void workshop_form_loadmodel_async_complete( void *payload, u32 size )
-{
- v2_zero( workshop_form.view_angles );
- v3_zero( workshop_form.view_offset );
- workshop_form.view_dist = 1.0f;
- workshop_form.view_changed = 1;
- workshop_form.file_intent = k_workshop_form_file_intent_new;
-
- vg_success( "workshop async load complete\n" );
- workshop_form.op = k_workshop_op_none;
-}
-
-/*
- * Reciever for failure to load
- */
-VG_STATIC void workshop_form_loadmodel_async_error( void *payload, u32 size ){
-}
-
-/*
- * Thread which loads the model from the disk
- */
-VG_STATIC void _workshop_form_load_thread( void *data )
-{
- char path_buf[4096];
- vg_str folder;
- vg_strnull( &folder, path_buf, 4096 );
-
- vg_strcat( &folder, workshop_filetype_folder() );
- vg_strcat( &folder, workshop_form.addon_folder );
-
- if( !vg_strgood(&folder) ){
- vg_error( "workshop async load failed: path too long\n" );
- vg_async_call( workshop_form_loadmodel_async_error, NULL, 0 );
- workshop_form.op = k_workshop_op_none;
- return;
- }
-
- vg_dir dir;
- if( !vg_dir_open( &dir, folder.buffer ) ){
- vg_error( "workshop async load failed: could not open folder\n" );
- vg_async_call( workshop_form_loadmodel_async_error, NULL, 0 );
- workshop_form.op = k_workshop_op_none;
- return;
- }
-
- vg_info( "Searching %s for model files\n", folder.buffer );
-
- int found_mdl = 0;
- while( vg_dir_next_entry(&dir) ){
- if( vg_dir_entry_type(&dir) == k_vg_entry_type_file ){
- const char *d_name = vg_dir_entry_name(&dir);
- if( d_name[0] == '.' ) continue;
-
- vg_str file = folder;
- vg_strcat( &file, "/" );
- vg_strcat( &file, d_name );
- if( !vg_strgood( &file ) ) continue;
-
- char *ext = vg_strch( &file, '.' );
- if( !ext ) continue;
- if( strcmp(ext,".mdl") ) continue;
- found_mdl = 1;
- break;
- }
- }
- vg_dir_close(&dir);
-
- if( !found_mdl ){
- vg_error( "workshop async load failed: no model files found\n" );
- vg_async_call( workshop_form_loadmodel_async_error, NULL, 0 );
- workshop_form.op = k_workshop_op_none;
- return;
- }
-
- if( workshop_form.submission.type == k_addon_type_board )
- player_board_load( &workshop_form.board_model, path_buf );
- else if( workshop_form.submission.type == k_addon_type_player )
- player_model_load( &workshop_form.player_model, path_buf );
-
- vg_async_call( workshop_form_loadmodel_async_complete, NULL, 0 );
-}
-
-/*
- * Entry point for load model operation
- */
-VG_STATIC void workshop_op_load_model(void){
- world_instance *world = world_current_instance();
- workshop_form.view_world = world;
-
- if( workshop_form.submission.type == k_addon_type_board ){
- if( mdl_arrcount( &world->ent_swspreview ) ){
- workshop_form.ptr_ent =
- mdl_arritm( &world->ent_swspreview, 0 );
- }
- else{
- ui_start_modal( "There is no ent_swspreview in the level. \n"
- "Cannot publish here\n", UI_MODAL_BAD );
- workshop_form.op = k_workshop_op_none;
- return;
- }
- }
- else if( workshop_form.submission.type == k_addon_type_player ){}
- else {
- ui_start_modal( "Don't know how to prepare for this item type. \n"
- "Please contact the developers.\n", UI_MODAL_BAD );
- workshop_form.op = k_workshop_op_none;
- return;
- }
-
- workshop_form.op = k_workshop_op_loading_model;
- vg_loader_start( _workshop_form_load_thread, NULL );
-}
-
-/*
- * op: k_workshop_form_op_downloading_submission
- * -----------------------------------------------------------------------------
- */
-
-/*
- * The image has been decoded and is ready to slap into the framebuffer
- */
-VG_STATIC void workshop_form_async_imageload( void *data, u32 len )
-{
- if( data ){
- struct framebuffer_attachment *a =
- &gpipeline.fb_workshop_preview->attachments[0];
-
- glBindTexture( GL_TEXTURE_2D, a->id );
- glTexSubImage2D( GL_TEXTURE_2D, 0,0,0,
- WORKSHOP_PREVIEW_WIDTH, WORKSHOP_PREVIEW_HEIGHT,
- a->format, a->type, data );
- stbi_image_free( data );
- vg_success( "Loaded workshop preview image\n" );
- }
- else{
- snprintf( workshop_form.error_msg, sizeof(workshop_form.error_msg),
- "Preview image could not be loaded. Reason: %s\n",
- stbi_failure_reason() );
- ui_start_modal( workshop_form.error_msg, UI_MODAL_BAD );
- }
- workshop_form.op = k_workshop_op_none;
-}
-
-/*
- * Load the image located at ./workshop_preview.jpg into our framebuffer
- */
-VG_STATIC void _workshop_load_preview_thread( void *data ){
- char path_buf[ 4096 ];
- vg_str path;
- vg_strnull( &path, path_buf, 4096 );
- vg_strcat( &path, workshop_filetype_folder() );
- vg_strcat( &path, workshop_form.addon_folder );
- vg_strcat( &path, "/preview.jpg" );
-
- if( vg_strgood( &path ) ){
- stbi_set_flip_vertically_on_load(1);
- int x, y, nc;
- u8 *rgb = stbi_load( path.buffer, &x, &y, &nc, 3 );
-
- if( rgb ){
- if( (x == WORKSHOP_PREVIEW_WIDTH) && (y == WORKSHOP_PREVIEW_HEIGHT) ){
- vg_async_call( workshop_form_async_imageload, rgb, x*y*3 );
- }
- else{
- vg_error( "Resolution does not match framebuffer, so we can't"
- " show it\n" );
- stbi_image_free( rgb );
- vg_async_call( workshop_form_async_imageload, NULL, 0 );
- }
- }
- else{
- vg_async_call( workshop_form_async_imageload, NULL, 0 );
- }
- }
- else{
- vg_async_call( workshop_form_async_imageload, NULL, 0 );
- }
-}
-
-/*
- * Entry point to view operation
- */
-VG_STATIC void workshop_op_download_and_view_submission( int result_index )
-{
- workshop_form.op = k_workshop_op_downloading_submission;
- ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
- ISteamRemoteStorage *hSteamRemoteStorage = SteamAPI_SteamRemoteStorage();
- SteamUGCDetails_t details;
- if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC,
- workshop_form.ugc_query.handle,
- result_index,
- &details ) )
- {
- workshop_reset_submission_data();
- workshop_form.submission.submit_description = 0;
- workshop_form.submission.submit_file_and_image = 0;
- workshop_form.submission.submit_title = 0;
-
- u8 metadata_buf[512];
- char metadata_str[1024+1];
- int have_meta = SteamAPI_ISteamUGC_GetQueryUGCMetadata( hSteamUGC,
- workshop_form.ugc_query.handle,
- result_index, metadata_str,
- 1024+1 );
-
- vg_strncpy( details.m_rgchDescription,
- workshop_form.submission.description,
- vg_list_size( workshop_form.submission.description ),
- k_strncpy_always_add_null );
-
- vg_strncpy( details.m_rgchTitle,
- workshop_form.submission.title,
- vg_list_size( workshop_form.submission.title ),
- k_strncpy_always_add_null );
-
- snprintf( workshop_form.addon_folder,
- vg_list_size( workshop_form.addon_folder ),
- "Steam Cloud ("PRINTF_U64")", details.m_nPublishedFileId );
-
- workshop_form.submission.file_id = details.m_nPublishedFileId;
- workshop_form.file_intent = k_workshop_form_file_intent_keep_old;
- workshop_form.page = k_workshop_form_edit;
- workshop_form.submission.visibility = details.m_eVisibility;
- workshop_form.submission.type = k_addon_type_none;
- workshop_form.submission.submission_type_selection = k_addon_type_none;
-
- if( have_meta ){
- u32 len = strlen(metadata_str);
- vg_info( "Metadata: %s\n", metadata_str );
- vg_str_bin( metadata_str, metadata_buf, len );
- vg_msg root = {0};
- root.buf = metadata_buf;
- root.len = len/2;
- root.max = len/2;
-
- vg_msg workshop = root;
- if( vg_msg_seekframe( &workshop, "workshop", k_vg_msg_first )){
- u32 type = vg_msg_seekkvu32( &workshop, "type", k_vg_msg_first );
- workshop_form.submission.type = type;
- workshop_form.submission.submission_type_selection = type;
-
- const char *kv_folder = vg_msg_seekkvstr( &workshop, "folder",
- k_vg_msg_first );
- if( kv_folder ){
- vg_strncpy( kv_folder, workshop_form.addon_folder,
- sizeof(workshop_form.addon_folder),
- k_strncpy_always_add_null );
- }
- }
- }
- else{
- vg_error( "No metadata was returned with this item.\n" );
- }
-
- render_fb_bind( gpipeline.fb_workshop_preview, 0 );
- glClearColor( 0.2f, 0.0f, 0.0f, 1.0f );
- glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
- glBindFramebuffer( GL_FRAMEBUFFER, 0 );
- glViewport( 0,0, vg.window_x, vg.window_y );
-
- vg_loader_start( _workshop_load_preview_thread, NULL );
- }
- else{
- vg_error( "GetQueryUGCResult: Index out of range\n" );
- workshop_form.op = k_workshop_op_none;
- }
-}
-
-/*
- * Regular stuff
- * -----------------------------------------------------------------------------
- */
-
-/*
- * View a page of results on the sidebar
- */
-VG_STATIC void workshop_view_page( int req )
-{
- if( workshop_form.ugc_query.result != k_EResultOK ){
- vg_error( "Tried to change page without complete data\n" );
- workshop_form.op = k_workshop_op_none;
- return;
- }
-
- int page = VG_MAX(VG_MIN(req, workshop_form.view_published_page_count-1),0),
- start = page * WORKSHOP_VIEW_PER_PAGE,
- end = VG_MIN( (page+1) * WORKSHOP_VIEW_PER_PAGE,
- workshop_form.ugc_query.returned_item_count ),
- count = end-start;
-
- vg_info( "View page %d\n", page );
-
- workshop_form.view_published_page_id = page;
- workshop_form.published_files_list_length = count;
- ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
-
- for( int i=0; i<count; i ++ ){
- struct published_file *pfile = &workshop_form.published_files_list[i];
-
- SteamUGCDetails_t details;
- if( SteamAPI_ISteamUGC_GetQueryUGCResult( hSteamUGC,
- workshop_form.ugc_query.handle,
- start+i,
- &details ) )
- {
- if( details.m_eResult != k_EResultOK ){
- snprintf( pfile->title, 80, "Error (%d)", details.m_eResult );
- }
- else{
- vg_strncpy( details.m_rgchTitle, pfile->title, 80,
- k_strncpy_always_add_null );
- }
-
- pfile->result = details.m_eResult;
- pfile->result_index = start+i;
- }
- else{
- pfile->result = k_EResultValueOutOfRange;
- pfile->result_index = -1;
- snprintf( pfile->title, 80, "Error (invalid index)" );
- }
- }
-}
-
-/*
- * Steam API result for when we recieve submitted UGC information about the user
- */
-VG_STATIC void on_workshop_UGCQueryComplete( void *data, void *userdata )
-{
- SteamUGCQueryCompleted_t *query = data;
- workshop_form.ugc_query.result = query->m_eResult;
-
- if( query->m_eResult == k_EResultOK ){
- if( query->m_unTotalMatchingResults > 50 ){
- vg_warn( "You have %d items submitted, "
- "we can only view the last 50\n" );
- }
-
- workshop_form.ugc_query.all_item_count = query->m_unTotalMatchingResults;
- workshop_form.ugc_query.returned_item_count =
- query->m_unNumResultsReturned;
-
- workshop_form.ugc_query.handle = query->m_handle;
- workshop_form.view_published_page_count =
- (query->m_unNumResultsReturned+WORKSHOP_VIEW_PER_PAGE-1)/
- WORKSHOP_VIEW_PER_PAGE;
- workshop_form.view_published_page_id = 0;
- workshop_form.published_files_list_length = 0;
-
- workshop_view_page( 0 );
- }
- else{
- vg_error( "Steam UGCQuery failed (%d)\n", query->m_eResult );
- workshop_form.view_published_page_count = 0;
- workshop_form.view_published_page_id = 0;
- workshop_form.published_files_list_length = 0;
-
- ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
- SteamAPI_ISteamUGC_ReleaseQueryUGCRequest( hSteamUGC, query->m_handle );
- }
-}
-
-/*
- * Console command to open the workshop publisher
- */
-VG_STATIC int workshop_submit_command( int argc, const char *argv[] )
-{
- if( !steam_ready ){
- ui_start_modal( "Steam API is not initialized\n", UI_MODAL_BAD );
- return 0;
- }
-
- workshop_form.page = k_workshop_form_open;
- workshop_form.view_published_page_count = 0;
- workshop_form.view_published_page_id = 0;
- workshop_form.published_files_list_length = 0;
- workshop_form.ugc_query.result = k_EResultNone;
-
- vg_steam_async_call *call = vg_alloc_async_steam_api_call();
-
- ISteamUser *hSteamUser = SteamAPI_SteamUser();
- CSteamID steamid;
- steamid.m_unAll64Bits = SteamAPI_ISteamUser_GetSteamID( hSteamUser );
-
- ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
- call->p_handler = on_workshop_UGCQueryComplete;
- call->userdata = NULL;
- UGCQueryHandle_t handle = SteamAPI_ISteamUGC_CreateQueryUserUGCRequest
- (
- hSteamUGC,
- steamid.m_comp.m_unAccountID,
- k_EUserUGCList_Published,
- k_EUGCMatchingUGCType_Items,
- k_EUserUGCListSortOrder_CreationOrderDesc,
- SKATERIFT_APPID, SKATERIFT_APPID,
- 1 );
- SteamAPI_ISteamUGC_SetReturnMetadata( hSteamUGC, handle, 1 );
- call->id = SteamAPI_ISteamUGC_SendQueryUGCRequest( hSteamUGC, handle );
- return 0;
-}
-
-VG_STATIC void workshop_init(void)
-{
- vg_console_reg_cmd( "workshop_submit", workshop_submit_command, NULL );
-}
-
-VG_STATIC void workshop_render_world_preview(void){
- render_fb_bind( gpipeline.fb_workshop_preview, 0 );
-
- glClearColor( 0.0f, 0.0f, 0.3f, 1.0f );
- glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
- glEnable( GL_DEPTH_TEST );
- glDisable( GL_BLEND );
-
- render_world( localplayer.viewable_world, &skaterift.cam, 1 );
-
- glBindFramebuffer( GL_FRAMEBUFFER, 0 );
- glViewport( 0,0, vg.window_x, vg.window_y );
-}
-
-/*
- * Redraw the playermodel into the workshop framebuffer
- */
-VG_STATIC void workshop_render_player_preview(void){
- render_fb_bind( gpipeline.fb_workshop_preview, 0 );
- glClearColor( 0.16f, 0.15f, 0.15f, 1.0f );
- glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
- glEnable( GL_DEPTH_TEST );
- glDisable( GL_BLEND );
-
- struct skeleton *sk = &localplayer.playeravatar->sk;
-
- player_pose res;
- res.type = k_player_pose_type_ik;
-
- struct skeleton_anim *anim = skeleton_get_anim( sk, "idle_cycle+y" );
- skeleton_sample_anim( sk, anim, vg.time*0.1f, res.keyframes );
- q_axis_angle( res.root_q, (v3f){0.0f,1.0f,0.0f}, VG_PIf );
- v3_zero( res.root_co );
- res.root_co[1] = 200.0f;
-
- m4x3f transform;
- q_m3x3( res.root_q, transform );
- v3_copy( res.root_co, transform[3] );
-
- /* TODO: Function. */
- skeleton_apply_pose( sk, res.keyframes, k_anim_apply_defer_ik );
- skeleton_apply_ik_pass( sk );
- skeleton_apply_pose( sk, res.keyframes, k_anim_apply_deffered_only );
- skeleton_apply_inverses( sk );
- skeleton_apply_transform( sk, transform );
-
- camera cam;
- v3_copy( (v3f){ 0.0f, 201.7f, 1.2f }, cam.pos );
-
- cam.nearz = 0.01f;
- cam.farz = 100.0f;
- cam.fov = 57.0f;
- v3_zero( cam.angles );
-
- camera_update_transform( &cam );
- camera_update_view( &cam );
- camera_update_projection( &cam );
- camera_finalize( &cam );
-
- world_instance *world = localplayer.viewable_world;
- render_playermodel( &cam, world, 0, &workshop_form.player_model, sk );
-
- glBindFramebuffer( GL_FRAMEBUFFER, 0 );
- glViewport( 0,0, vg.window_x, vg.window_y );
-}
-
-/*
- * Redraw the model file into the workshop framebuffer
- */
-VG_STATIC void workshop_render_board_preview(void){
- if( !workshop_form.ptr_ent ){
- return;
- }
-
- render_fb_bind( gpipeline.fb_workshop_preview, 0 );
-
- glClearColor( 0.0f, 0.0f, 0.3f, 1.0f );
- glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
- glEnable( GL_DEPTH_TEST );
- glDisable( GL_BLEND );
-
- ent_swspreview *swsprev = workshop_form.ptr_ent;
- world_instance *world = workshop_form.view_world;
-
- ent_camera *ref = mdl_arritm( &world->ent_camera,
- mdl_entity_id_id(swsprev->id_camera) );
- ent_marker *display = mdl_arritm( &world->ent_marker,
- mdl_entity_id_id(swsprev->id_display) ),
- *display1= mdl_arritm( &world->ent_marker,
- mdl_entity_id_id(swsprev->id_display1) );
-
- v3f baseco;
- v3_add( display->transform.co, display1->transform.co, baseco );
- v3_muls( baseco, 0.5f, baseco );
-
- camera cam;
- v3f basevector;
- v3_sub( display->transform.co, ref->transform.co, basevector );
- float dist = v3_length( basevector );
-
- v3f baseangles;
- player_vector_angles( baseangles, basevector, 1.0f, 0.0f );
-
- v2_add( workshop_form.view_angles, baseangles, cam.angles );
- cam.angles[2] = 0.0f;
-
- float sX = sinf( cam.angles[0] ),
- cX = cosf( cam.angles[0] ),
- sY = sinf( cam.angles[1] ),
- cY = cosf( cam.angles[1] );
-
- v3f offset = { -sX * cY, sY, cX * cY };
-
- v3_muladds( display->transform.co, offset,
- dist*workshop_form.view_dist, cam.pos );
-
- cam.pos[0] += -sX*workshop_form.view_offset[2];
- cam.pos[2] += cX*workshop_form.view_offset[2];
- cam.pos[0] += cX*workshop_form.view_offset[0];
- cam.pos[2] += sX*workshop_form.view_offset[0];
- cam.pos[1] += workshop_form.view_offset[1];
-
- cam.nearz = 0.01f;
- cam.farz = 100.0f;
- cam.fov = ref->fov;
-
- camera_update_transform( &cam );
- camera_update_view( &cam );
- camera_update_projection( &cam );
- camera_finalize( &cam );
-
- m4x3f mmdl, mmdl1;
- mdl_transform_m4x3( &display->transform, mmdl );
- mdl_transform_m4x3( &display1->transform, mmdl1 );
-
- /* force update this for nice shadows. its usually set in the world
- * pre-render step, but that includes timer stuff
- */
- struct player_board *board = &workshop_form.board_model;
- struct ub_world_lighting *ubo = &world->ub_lighting;
- v3f vp0, vp1;
- v3_copy((v3f){0.0f,0.1f, board->truck_positions[0][2]}, vp0 );
- v3_copy((v3f){0.0f,0.1f, board->truck_positions[1][2]}, vp1 );
- m4x3_mulv( mmdl1, vp0, ubo->g_board_0 );
- m4x3_mulv( mmdl1, vp1, ubo->g_board_1 );
- glBindBuffer( GL_UNIFORM_BUFFER, world->ubo_lighting );
- glBufferSubData( GL_UNIFORM_BUFFER, 0,
- sizeof(struct ub_world_lighting), &world->ub_lighting );
-
- render_world( world, &cam, 1 );
- struct player_board_pose pose = {0};
- render_board( &cam, world, board, mmdl, &pose, k_board_shader_entity );
- render_board( &cam, world, board, mmdl1, &pose, k_board_shader_entity );
-
- glBindFramebuffer( GL_FRAMEBUFFER, 0 );
- glViewport( 0,0, vg.window_x, vg.window_y );
-}
-
-/*
- * ImGUI section for workshop form
- * -----------------------------------------------------------------------------
- */
-
-VG_STATIC void workshop_changed_model_path( char *buf, u32 len ){
- workshop_form.submission.submit_file_and_image = 1;
-}
-
-VG_STATIC void workshop_changed_title( char *buf, u32 len ){
- workshop_form.submission.submit_title = 1;
-}
-
-VG_STATIC void workshop_changed_description( char *buf, u32 len ){
- workshop_form.submission.submit_description = 1;
-}
-
-VG_STATIC void workshop_form_gui_page_undecided( ui_rect content ){
- ui_rect box;
- rect_copy( content, box );
- box[3] = 128;
- box[2] = (box[2]*2)/3;
- ui_rect_center( content, box );
-
- ui_rect row;
- ui_split( box, k_ui_axis_h, 28, 0, row, box );
- ui_text( row, "Select the type of item\n", 1, k_ui_align_middle_center,0);
- ui_split( box, k_ui_axis_h, 28, 0, row, box );
- ui_enum( row, "Type:", workshop_form_type_opts,
- 4, &workshop_form.submission.submission_type_selection );
- ui_split( box, k_ui_axis_h, 8, 0, row, box );
- ui_split( box, k_ui_axis_h, 28, 0, row, box );
-
- ui_rect button_l, button_r;
- rect_copy( row, button_l );
- button_l[2] = 128*2;
- ui_rect_center( row, button_l );
- ui_split_ratio( button_l, k_ui_axis_v, 0.5f, 2, button_l, button_r );
-
- enum addon_type type = workshop_form.submission.submission_type_selection;
- if( type != k_addon_type_none){
- if( ui_button_text( button_l, "OK", 1 ) == 1 ){
- workshop_form.submission.type = type;
-
- if( type == k_addon_type_world ){
- workshop_form.view_changed = 1;
- workshop_form.file_intent = k_workshop_form_file_intent_new;
- }
- }
- }
- else{
- ui_fill( button_l, ui_colour(k_ui_bg) );
- ui_text( button_l, "OK", 1, k_ui_align_middle_center,
- ui_colour(k_ui_bg+4) );
- }
-
- if( ui_button_text( button_r, "Cancel", 1 ) == 1 ){
- workshop_form.page = k_workshop_form_open;
- workshop_form.file_intent = k_workshop_form_file_intent_none;
- }
-}
-
-VG_STATIC void workshop_form_gui_draw_preview( ui_rect img_box ){
- enum addon_type type = workshop_form.submission.type;
- if( workshop_form.file_intent == k_workshop_form_file_intent_keep_old ){
- ui_image( img_box, gpipeline.fb_workshop_preview->attachments[0].id );
- }
- else if( workshop_form.file_intent == k_workshop_form_file_intent_new ){
- ui_image( img_box, gpipeline.fb_workshop_preview->attachments[0].id );
-
- if( type == k_addon_type_world ){
- return;
- }
-
- int hover = ui_inside_rect( img_box, vg_ui.mouse ),
- target = ui_inside_rect( img_box, vg_ui.mouse_click );
-
- if( ui_click_down(UI_MOUSE_MIDDLE) && target ){
- v3_copy( workshop_form.view_offset,
- workshop_form.view_offset_begin );
- }
- else if( ui_click_down(UI_MOUSE_LEFT) && target ){
- v2_copy( workshop_form.view_angles,
- workshop_form.view_angles_begin );
- }
-
- if( ui_clicking(UI_MOUSE_MIDDLE) && target ){
- v2f delta = { vg_ui.mouse[0]-vg_ui.mouse_click[0],
- vg_ui.mouse[1]-vg_ui.mouse_click[1] };
-
- float *begin = workshop_form.view_offset_begin,
- *offset = workshop_form.view_offset;
- offset[0] = vg_clampf( begin[0]-delta[0]*0.002f, -1.0f, 1.0f );
- offset[2] = vg_clampf( begin[2]-delta[1]*0.002f, -1.0f, 1.0f );
- workshop_form.view_changed = 1;
- }
- else if( ui_clicking(UI_MOUSE_LEFT) && target ){
- v2f delta = { vg_ui.mouse[0]-vg_ui.mouse_click[0],
- vg_ui.mouse[1]-vg_ui.mouse_click[1] };
-
- v2f angles;
- v2_muladds( workshop_form.view_angles_begin, delta, 0.002f, angles);
-
- float limit = VG_PIf*0.2f;
-
- angles[0] = vg_clampf( angles[0], -limit, limit );
- angles[1] = vg_clampf( angles[1], -limit, limit );
-
- v2_copy( angles, workshop_form.view_angles );
- workshop_form.view_changed = 1;
- }
-
- if( !ui_clicking(UI_MOUSE_LEFT) && hover ){
- float zoom = workshop_form.view_dist;
- zoom += vg.mouse_wheel[1] * -0.07f;
- zoom = vg_clampf( zoom, 0.4f, 2.0f );
-
- if( zoom != workshop_form.view_dist ){
- workshop_form.view_changed = 1;
- workshop_form.view_dist = zoom;
- }
- }
- }
- else{
- ui_text( img_box, "No image", 1, k_ui_align_middle_center,
- ui_colour( k_ui_orange ) );
- }
-}
-
-VG_STATIC void workshop_form_gui_edit_page( ui_rect content ){
- enum addon_type type = workshop_form.submission.type;
-
- if( type == k_addon_type_none ){
- workshop_form_gui_page_undecided( content );
- return;
- }
-
- ui_rect image_plane;
- ui_split( content, k_ui_axis_h, 300, 0, image_plane, content );
- ui_fill( image_plane, ui_colour( k_ui_bg+0 ) );
-
- ui_rect img_box;
- ui_fit_item( image_plane, (ui_px[2]){ 3, 2 }, img_box );
- workshop_form_gui_draw_preview( img_box );
-
- /* file path */
- ui_rect file_button, file_label;
-
- char buf[128];
- snprintf( buf, 128,
- "Addon folder: skaterift/%s", workshop_filetype_folder() );
-
- if( type == k_addon_type_world ){
- struct ui_textbox_callbacks callbacks = {
- .change = workshop_changed_model_path
- };
- ui_textbox( content, buf, workshop_form.addon_folder,
- vg_list_size(workshop_form.addon_folder), 1, 0, &callbacks );
- }
- else{
- ui_rect file_entry;
- ui_standard_widget( content, file_entry, 1 );
- ui_split( file_entry, k_ui_axis_v, -128, 0, file_entry, file_button );
-
- if( workshop_form.file_intent != k_workshop_form_file_intent_none ){
- ui_text( file_entry, workshop_form.addon_folder, 1,
- k_ui_align_middle_left, ui_colour( k_ui_fg+4 ) );
-
- if( ui_button_text( file_button, "Remove", 1 ) == 1 ){
- if( type == k_addon_type_board )
- player_board_unload( &workshop_form.board_model );
- else if( type == k_addon_type_player )
- player_model_unload( &workshop_form.player_model );
-
- workshop_form.file_intent = k_workshop_form_file_intent_none;
- workshop_form.addon_folder[0] = '\0';
- }
- }
- else{
- struct ui_textbox_callbacks callbacks = {
- .change = workshop_changed_model_path
- };
-
- ui_textbox( file_entry, buf, workshop_form.addon_folder,
- vg_list_size(workshop_form.addon_folder), 1,
- 0, &callbacks );
-
- if( ui_button_text( file_button, "Load", 1 ) == 1 ){
- workshop_op_load_model();
- }
- }
- }
-
- const char *str_title = "Title:", *str_desc = "Description:";
-
- /* title box */
- {
- struct ui_textbox_callbacks callbacks = {
- .change = workshop_changed_title
- };
- ui_textbox( content, str_title, workshop_form.submission.title,
- vg_list_size(workshop_form.submission.title), 1,
- 0, &callbacks );
- }
-
- /* visibility option */
- {
- ui_enum( content, "Visibility:", workshop_form_visibility_opts,
- 4, &workshop_form.submission.visibility );
- }
-
- /* description box */
- {
- struct ui_textbox_callbacks callbacks = {
- .change = workshop_changed_description
- };
- ui_textbox( content, str_desc, workshop_form.submission.description,
- vg_list_size(workshop_form.submission.description), 4,
- UI_TEXTBOX_MULTILINE|UI_TEXTBOX_WRAP, &callbacks );
- }
-
- /* submissionable */
- ui_rect final_row;
- ui_split( content, k_ui_axis_h, content[3]-32-8, 0, content, final_row );
-
- ui_rect submission_center;
- rect_copy( final_row, submission_center );
- submission_center[2] = 256;
- ui_rect_center( final_row, submission_center );
-
- ui_rect btn_left, btn_right;
- ui_split_ratio( submission_center, k_ui_axis_v, 0.5f, 8,
- btn_left, btn_right );
-
- if( ui_button_text( btn_left, "Publish", 1 ) == 1 ){
- workshop_op_submit();
- }
- if( ui_button_text( btn_right, "Cancel", 1 ) == 1 ){
- workshop_form.page = k_workshop_form_open;
- player_board_unload( &workshop_form.board_model );
- workshop_form.file_intent = k_workshop_form_file_intent_none;
- }
-
- /* disclaimer */
- const char *disclaimer_text =
- "By submitting this item, you agree to the workshop terms of service";
-
- ui_rect disclaimer_row, inner, link;
- ui_split( content, k_ui_axis_h, content[3]-32, 0, content, disclaimer_row );
-
- ui_px btn_width = 32;
-
- rect_copy( disclaimer_row, inner );
- inner[2] = ui_text_line_width( disclaimer_text ) + btn_width+8;
-
- ui_rect label;
- ui_rect_center( disclaimer_row, inner );
- ui_split( inner, k_ui_axis_v, inner[2]-btn_width, 0, label, btn_right);
- ui_rect_pad( btn_right, (ui_px[2]){2,2} );
-
- if( ui_button_text( btn_right, "\xbf", 2 ) == 1 ){
- ISteamFriends *hSteamFriends = SteamAPI_SteamFriends();
- SteamAPI_ISteamFriends_ActivateGameOverlayToWebPage( hSteamFriends,
- "https://steamcommunity.com/sharedfiles/workshoplegalagreement",
- k_EActivateGameOverlayToWebPageMode_Default );
- }
-
- ui_text( label, disclaimer_text, 1, k_ui_align_middle_left,
- ui_colour( k_ui_fg+4 ) );
-}
-
-VG_STATIC void workshop_form_gui_sidebar( ui_rect sidebar )
-{
- ui_fill( sidebar, ui_colour( k_ui_bg+2 ) );
-
- ui_rect title;
- ui_split( sidebar, k_ui_axis_h, 28, 0, title, sidebar );
-
- if( workshop_form.page == k_workshop_form_edit ){
- ui_text( title, "Editing", 1, k_ui_align_middle_center, 0 );
- ui_split( sidebar, k_ui_axis_h, 28, 0, title, sidebar );
-
- if( workshop_form.submission.type != k_addon_type_none ){
- char buf[512];
- vg_str str;
- vg_strnull( &str, buf, 512 );
-
- if( workshop_form.submission.file_id )
- vg_strcat( &str, "Editing an existing " );
- else
- vg_strcat( &str, "Creating a new " );
-
- if( workshop_form.submission.type == k_addon_type_board )
- vg_strcat( &str, "skateboard." );
- else if( workshop_form.submission.type == k_addon_type_world )
- vg_strcat( &str, "world." );
- else if( workshop_form.submission.type == k_addon_type_player )
- vg_strcat( &str, "playermodel." );
- else
- vg_strcat( &str, "???." );
-
- ui_text( title, buf, 1, k_ui_align_middle_center,
- ui_colour(k_ui_fg+4) );
- }
- return;
- }
-
- /*
- * sidebar existing entries panel
- */
- ui_text( title, "Your submissions", 1, k_ui_align_middle_center, 0 );
-
- ui_rect controls, btn_create_new;
- ui_split( sidebar, k_ui_axis_h, 32, 0, controls, sidebar );
- ui_split( sidebar, k_ui_axis_h, -32, 0, sidebar, btn_create_new );
- ui_fill( controls, ui_colour( k_ui_bg+1 ) );
-
- char buf[32];
- strcpy( buf, "page " );
- int i = 5;
- i += highscore_intl( buf+i, workshop_form.view_published_page_id+1, 4 );
- buf[ i ++ ] = '/';
- i += highscore_intl( buf+i, workshop_form.view_published_page_count, 4 );
- buf[ i ++ ] = '\0';
-
- ui_rect_pad( controls, (ui_px[2]){0,4} );
- ui_rect info;
- ui_split_ratio( controls, k_ui_axis_v, 0.25f, 0, info, controls );
- ui_text( info, buf, 1, k_ui_align_middle_center, 0 );
-
- ui_rect btn_left, btn_right;
- ui_split_ratio( controls, k_ui_axis_v, 0.5f, 2, btn_left, btn_right );
-
- if( ui_button_text( btn_left, "newer", 1 ) == 1 ){
- workshop_view_page( workshop_form.view_published_page_id-1 );
- }
-
- if( ui_button_text( btn_right, "older", 1 ) == 1 ){
- workshop_view_page( workshop_form.view_published_page_count+1 );
- }
-
- if( ui_button_text( btn_create_new, "Create New Item", 1 ) == 1 ){
- workshop_reset_submission_data();
- workshop_form.submission.submit_title = 1;
- workshop_form.submission.submit_description = 1;
- workshop_form.submission.submit_file_and_image = 1;
- workshop_form.page = k_workshop_form_edit;
- }
-
- for( int i=0; i<workshop_form.published_files_list_length; i++ ){
- ui_rect item;
- ui_split( sidebar, k_ui_axis_h, 28, 0, item, sidebar );
- ui_rect_pad( item, (ui_px[2]){4,4} );
-
- struct published_file *pfile = &workshop_form.published_files_list[i];
- if( ui_button_text( item, pfile->title, 1 ) == 1 ){
- if( pfile->result == k_EResultOK ){
- vg_info( "Select index: %d\n", pfile->result_index );
- workshop_op_download_and_view_submission( pfile->result_index );
- }
- else{
- vg_warn( "Cannot select that item, result not OK\n" );
- }
- }
- }
-}
-
-VG_STATIC void workshop_form_gui(void)
-{
- enum workshop_form_page stable_page = workshop_form.page;
- if( stable_page == k_workshop_form_hidden ) return;
-
- ui_rect null;
- ui_rect screen = { 0, 0, vg.window_x, vg.window_y };
- ui_rect window = { 0, 0, 1000, 700 };
- ui_rect_center( screen, window );
- vg_ui.wants_mouse = 1;
-
- ui_fill( window, ui_colour( k_ui_bg+1 ) );
- ui_outline( window, 1, ui_colour( k_ui_bg+7 ), 0 );
-
- ui_rect title, panel;
- ui_split( window, k_ui_axis_h, 28, 0, title, panel );
- ui_fill( title, ui_colour( k_ui_bg+7 ) );
- ui_text( title, "Workshop tool", 1, k_ui_align_middle_center,
- ui_colourcont(k_ui_bg+7) );
-
- ui_rect quit_button;
- ui_split( title, k_ui_axis_v, title[2]-title[3], 2, title, quit_button );
-
- if( vg_loader_availible() ){
- if( ui_button_text( quit_button, "X", 1 ) == 1 ){
- workshop_quit_form();
- return;
- }
- }
-
- /*
- * temporary operation blinders, we don't yet have a nice way to show the
- * user that we're doing something uninterruptable, so the code just
- * escapes here and we show them a basic string
- */
-
- if( workshop_form.op != k_workshop_op_none ){
- const char *op_string = "The programmer has not bothered to describe "
- "the current operation that is running.";
-
- switch( workshop_form.op ){
- case k_workshop_op_loading_model:
- op_string = "Operation in progress: Loading model file.";
- break;
- case k_workshop_op_publishing_update:
- op_string = "Operation in progress: publishing submission update "
- "to steam.";
- break;
- case k_workshop_op_downloading_submission:
- op_string = "Operation in progress: downloading existing submission"
- " from Steam services.";
- break;
- default: break;
- }
-
- ui_text( panel, op_string, 1, k_ui_align_middle_center, 0 );
- return;
- }
-
- /* re draw board preview if need to */
- if( (stable_page == k_workshop_form_edit) &&
- workshop_form.view_changed &&
- workshop_form.file_intent == k_workshop_form_file_intent_new )
- {
- enum addon_type type = workshop_form.submission.type;
- if( type == k_addon_type_board ){
- workshop_render_board_preview();
- }
- else if( type == k_addon_type_world ){
- vg_success( "Renders world preview\n" );
- workshop_render_world_preview();
- }
- else if( type == k_addon_type_player ){
- workshop_render_player_preview();
- }
-
- workshop_form.view_changed = 0;
- }
-
- struct workshop_form *form = &workshop_form;
-
- ui_rect sidebar, content;
- ui_split_ratio( panel, k_ui_axis_v, 0.3f, 1, sidebar, content );
-
- /* content page */
- ui_rect_pad( content, (ui_px[2]){8,8} );
-
- if( stable_page == k_workshop_form_edit ){
- workshop_form_gui_edit_page( content );
- }
- else if( stable_page == k_workshop_form_open ){
- ui_text( content, "Nothing selected.", 1, k_ui_align_middle_center,
- ui_colour( k_ui_fg+4 ) );
- }
- else if( stable_page >= k_workshop_form_cclosing ){
- ui_rect submission_row;
- ui_split( content, k_ui_axis_h, content[3]-32-8, 0, content,
- submission_row );
-
- u32 colour;
-
- if( stable_page == k_workshop_form_closing_bad )
- colour = ui_colour( k_ui_red+k_ui_brighter );
- else
- colour = ui_colour( k_ui_green+k_ui_brighter );
-
- ui_text( content, workshop_form.failure_or_success_string, 1,
- k_ui_align_middle_center, colour );
-
- ui_rect submission_center;
- rect_copy( submission_row, submission_center );
- submission_center[2] = 128;
- ui_rect_center( submission_row, submission_center );
- ui_rect_pad( submission_center, (ui_px[2]){8,8} );
-
- if( ui_button_text( submission_center, "OK", 1 ) == 1 ){
- workshop_form.page = k_workshop_form_open;
- }
- }
-
- workshop_form_gui_sidebar( sidebar );
-}
-
-/*
- * Some async api stuff
- * -----------------------------------------------------------------------------
- */
-
-VG_STATIC void async_workshop_get_filepath( void *data, u32 len )
-{
- struct async_workshop_filepath_info *info = data;
-
- u64 _size;
- u32 _ts;
-
- ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
- if( !SteamAPI_ISteamUGC_GetItemInstallInfo( hSteamUGC, info->id, &_size,
- info->buf, info->len, &_ts ))
- {
- vg_error( "GetItemInstallInfo failed\n" );
- info->buf[0] = '\0';
- }
-}
-
-VG_STATIC void async_workshop_get_installed_files( void *data, u32 len )
-{
- struct async_workshop_installed_files_info *info = data;
-
- ISteamUGC *hSteamUGC = SteamAPI_SteamUGC();
- u32 count = SteamAPI_ISteamUGC_GetSubscribedItems( hSteamUGC, info->buffer,
- *info->len );
-
- vg_info( "Found %u subscribed items\n", count );
-
- u32 j=0;
- for( u32 i=0; i<count; i++ ){
- u32 state = SteamAPI_ISteamUGC_GetItemState( hSteamUGC, info->buffer[i] );
- if( state & k_EItemStateInstalled ){
- info->buffer[j ++] = info->buffer[i];
- }
- }
-
- *info->len = j;
-}
-
-#endif /* WORKSHOP_C */