static void _board_maker_export(void)
{
+ char folder[ 128 ];
+ vg_str folder_str;
+ vg_strnull( &folder_str, folder, sizeof(folder) );
+ vg_strcat( &folder_str, _board_maker.export_path );
+ char *slash = vg_strch( &folder_str, '/' );
+ if( slash )
+ slash[0] = '\0';
+ else
+ {
+ _board_maker.export_success = 0;
+ _board_maker.export_message = "???";
+ _board_maker.ui_state = k_board_maker_ui_state_export_signal_done;
+ return;
+ }
+ vg_make_directory( folder );
+
mdl_compiler compiler;
mdl_compiler_init( &compiler );
{
free( raw_data );
free( qoi_data );
+
+ _board_maker.export_success = 0;
+ _board_maker.export_message = "Texture failed to compress";
+ _board_maker.ui_state = k_board_maker_ui_state_export_signal_done;
return;
}
ref_submesh->indice_count );
}
- af_write( &compiler.af, "/tmp/hello.mdl", MDL_VERSION_NR );
+ af_write( &compiler.af, _board_maker.export_path, MDL_VERSION_NR );
mdl_compiler_free( &compiler );
+
+ _board_maker.export_success = 1;
+ _board_maker.export_message = "Export done!";
+ _board_maker.ui_state = k_board_maker_ui_state_export_signal_done;
}
/* update loop */
{ 1, "Repeat" }
};
+static void _board_maker_exit_modal_close( u32 args )
+{
+ if( args & UI_MODAL_CANCEL ) {}
+ else
+ {
+ if( world_clear_event( k_world_event_board_maker ) )
+ _board_maker_close();
+ }
+}
+
+static void _board_maker_confirm_overwrite( u32 args )
+{
+ if( args & UI_MODAL_CANCEL ) {}
+ else
+ {
+ _board_maker.state = k_board_maker_state_export;
+ }
+}
+
+static void _board_maker_export_path_changed( ui_context *ctx, char *buf, u32 len, void *userdata )
+{
+ if( strlen(buf) < 3 )
+ _board_maker.can_export = 0;
+ else
+ _board_maker.can_export = 1;
+
+ for( u32 i=0; i<len; i ++ )
+ {
+ if( buf[i] == '\0' )
+ break;
+
+ if( buf[i] == '/' || buf[i] == '\\' )
+ {
+ _board_maker.can_export = 0;
+ break;
+ }
+ }
+}
+
void _board_maker_ui( ui_context *ctx )
{
if( _world.event != k_world_event_board_maker )
ui_capture_mouse( ctx, 1 );
+ if( _board_maker.ui_state == k_board_maker_ui_state_export_signal_done )
+ {
+ if( _board_maker.export_success )
+ ui_start_modal( ctx, _board_maker.export_message, NULL, UI_MODAL_GOOD, NULL );
+ else
+ ui_start_modal( ctx, _board_maker.export_message, NULL, UI_MODAL_BAD, NULL );
+
+ _board_maker.ui_state = k_board_maker_ui_state_default;
+ return;
+ }
+
+ if( _board_maker.ui_state == k_board_maker_ui_state_export )
+ {
+ ui_rect export_rect = { 0,0, 400, 300 };
+ ui_rect_center( (ui_rect){0,0,vg.window_x,vg.window_y}, export_rect );
+ ui_panel( ctx, export_rect, export_rect );
+
+ /* title */
+ ui_rect title_row;
+ ctx->font = &vgf_default_large;
+ ui_standard_widget( ctx, export_rect, title_row, 1 );
+ ui_text( ctx, title_row, "Export board", 1, k_ui_align_middle_center, 0 );
+ ctx->font = &vgf_default_small;
+ ui_info( ctx, export_rect, "This will export your board to disk." );
+ ui_info( ctx, export_rect, "It will appear to use in skate shops!" );
+
+ /* export name */
+ struct ui_textbox_callbacks callbacks =
+ {
+ .change = _board_maker_export_path_changed
+ };
+ ui_textbox( ctx, export_rect, "File name:",
+ _board_maker.export_name, sizeof(_board_maker.export_name), 1, 0, &callbacks );
+
+ /* options buttons */
+ ui_rect bottom_row;
+ ui_split( export_rect, k_ui_axis_h, -32, 8, export_rect, bottom_row );
+
+ ui_rect ok_box, cancel_box;
+ ui_split( bottom_row, k_ui_axis_v, -120, 8, bottom_row, ok_box );
+ ui_split( bottom_row, k_ui_axis_v, -120, 8, bottom_row, cancel_box );
+
+ if( _board_maker.can_export )
+ {
+ if( ui_button_text( ctx, ok_box, "Export", 1 ) == k_ui_button_click )
+ {
+ strcpy( _board_maker.export_path, "boards/" );
+ strcat( _board_maker.export_path, _board_maker.export_name );
+ strcat( _board_maker.export_path, "/board.mdl" );
+
+ if( vg_path_exists( _board_maker.export_path ) )
+ {
+ const struct ui_modal_callbacks callbacks =
+ {
+ .close = _board_maker_confirm_overwrite
+ };
+ ui_start_modal( ctx, "Overwrite existing file?", "Overwrite", UI_MODAL_OK|UI_MODAL_CANCEL, &callbacks );
+ }
+ else
+ {
+ _board_maker.state = k_board_maker_state_export;
+ }
+ }
+ }
+ else
+ {
+ // TODO: standardize me
+ ui_fill( ctx, ok_box, ui_colour( ctx, k_ui_bg ) );
+ ui_text( ctx, ok_box, "Export", 1, k_ui_align_middle_center, ui_colour( ctx, k_ui_bg+3 ) );
+ }
+
+ if( ui_button_text( ctx, cancel_box, "Cancel", 1 ) == k_ui_button_click )
+ {
+ _board_maker.ui_state = k_board_maker_ui_state_default;
+ }
+
+ return;
+ }
+
ui_rect root = { 8, 8, 200, 600 }, panel;
ui_panel( ctx, root, panel );
bool main_clickable = clickable;
-#if 0
- if( _board_maker.ui_state != k_board_maker_ui_state_default )
- main_clickable = 0;
-#endif
-
ui_info( ctx, panel, "Wheels" );
ui_rect w1, w2, w3, w4, wheel_row;
ui_standard_widget( ctx, panel, wheel_row, 1 );
ui_fill( ctx, bib, colour );
}
+ ui_rect export_box;
+ ui_standard_widget( ctx, panel, export_box, 2 );
+ if( ui_button_text( ctx, export_box, "Export", 1 ) == k_ui_button_click )
+ {
+ _board_maker.ui_state = k_board_maker_ui_state_export;
+ }
+
ui_rect quit_box;
ui_split( panel, k_ui_axis_h, -24, 0, panel, quit_box );
if( quit_me )
{
- _board_maker.state = k_board_maker_state_export;
-
- //if( world_clear_event( k_world_event_board_maker ) )
- // _board_maker_close();
+ const struct ui_modal_callbacks callbacks =
+ {
+ .close = _board_maker_exit_modal_close
+ };
+ ui_start_modal( ctx, "Exit board maker?", "EXIT", UI_MODAL_OK|UI_MODAL_CANCEL, &callbacks );
}
}
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.submission_type_selection = k_addon_type_none;
workshop_form.submission.type = k_addon_type_none;
-
- workshop_form.submission.visibility =
- k_ERemoteStoragePublishedFileVisibilityPublic;
+ workshop_form.submission.visibility = k_ERemoteStoragePublishedFileVisibilityPublic;
workshop_form.addon_folder[0] = '\0';
player_board_unload( &workshop_form.board_model );
{
if( !workshop_form.submission.title[0] )
{
- ui_start_modal( ctx, "Cannot submit because a title is required\n",
- UI_MODAL_WARN );
+ ui_start_modal( ctx, "Cannot submit because a title is required\n", NULL, UI_MODAL_WARN, NULL );
workshop_form.op = k_workshop_op_none;
return;
}
{
if( !workshop_form.submission.description[0] )
{
- ui_start_modal( ctx,
- "Cannot submit because a description is required\n",
- UI_MODAL_WARN );
+ ui_start_modal( ctx, "Cannot submit because a description is required\n", NULL, UI_MODAL_WARN, NULL );
workshop_form.op = k_workshop_op_none;
return;
}
{
if( workshop_form.file_intent == k_workshop_form_file_intent_none )
{
- ui_start_modal( ctx, "Cannot submit because the file is "
- "empty or unspecified\n", UI_MODAL_WARN );
+ ui_start_modal( ctx, "Cannot submit because the file is empty or unspecified\n", NULL, UI_MODAL_WARN, NULL );
workshop_form.op = k_workshop_op_none;
return;
}
else
{
ui_start_modal( ctx, "There is no ent_swspreview in the level. \n"
- "Cannot publish here\n", UI_MODAL_BAD );
+ "Cannot publish here\n", NULL, UI_MODAL_BAD, NULL );
workshop_form.op = k_workshop_op_none;
return;
}
else
{
ui_start_modal( ctx, "Don't know how to prepare for this item type. \n"
- "Please contact the developers.\n", UI_MODAL_BAD );
+ "Please contact the developers.\n", NULL, UI_MODAL_BAD, NULL );
workshop_form.op = k_workshop_op_none;
return;
}
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( &vg_ui.ctx, workshop_form.error_msg, UI_MODAL_BAD );
+ ui_start_modal( &vg_ui.ctx, workshop_form.error_msg, NULL, UI_MODAL_BAD, NULL );
}
workshop_form.op = k_workshop_op_none;
}
{
if( !steam_ready )
{
- ui_start_modal( &vg_ui.ctx,
- "Steam API is not initialized\n", UI_MODAL_BAD );
+ ui_start_modal( &vg_ui.ctx, "Steam API is not initialized\n", NULL, UI_MODAL_BAD, NULL );
return 0;
}