From bae2ace3767cae636d670dbc1e0b56e154b2ea21 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Wed, 1 Mar 2023 01:45:48 +0000 Subject: [PATCH] about menu improvements --- Makefile | 2 ++ src/menu/menu_info.c | 38 ++++++++++++++++++++++ src/menu/menu_info.h | 6 ++++ src/menu/menu_main.c | 34 +++++++++++++------- src/menu/menu_test.c | 75 ++++++++++++++++++++++++++++++++++++++++++++ src/menu/menu_test.h | 6 ++++ 6 files changed, 150 insertions(+), 11 deletions(-) create mode 100644 src/menu/menu_info.c create mode 100644 src/menu/menu_info.h create mode 100644 src/menu/menu_test.c create mode 100644 src/menu/menu_test.h diff --git a/Makefile b/Makefile index 1bf2aea2..329b72f6 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,8 @@ SRCS = \ flashcart/sc64/sc64_internal.c \ flashcart/sc64/sc64.c \ menu/menu_main.c \ + menu/menu_info.c \ + menu/menu_test.c \ menu/settings.c \ utils/fs.c \ libs/toml/toml.c \ diff --git a/src/menu/menu_info.c b/src/menu/menu_info.c new file mode 100644 index 00000000..dee96d69 --- /dev/null +++ b/src/menu/menu_info.c @@ -0,0 +1,38 @@ +#include + +static void draw_header(display_context_t disp) { + graphics_draw_text(disp, 200-70, 10, "Menu Information"); +} + + +void menu_info(void) { + display_init(RESOLUTION_512x240, DEPTH_16_BPP, 3, GAMMA_NONE, ANTIALIAS_RESAMPLE); + display_context_t disp = display_lock(); + graphics_fill_screen(disp, 0); + draw_header(disp); + + graphics_draw_text(disp, 30, 50, "Authors:"); + graphics_draw_text(disp, 30, 58, "JonesAlmighty / Networkfusion"); + graphics_draw_text(disp, 30, 66, "korgeaux / Polprzewodnikowy"); + + graphics_draw_text(disp, 30, 80, "Github:"); + graphics_draw_text(disp, 30, 88, "https://github.com/Polprzewodnikowy/SummerCart64"); + graphics_draw_text(disp, 30, 96, "https://github.com/Polprzewodnikowy/N64FlashcartMenu"); + + graphics_draw_text(disp, 30,112, "OSS licenses used:"); + graphics_draw_text(disp, 30,120, "GPL"); + graphics_draw_text(disp, 30,128, "MIT"); + + graphics_draw_text(disp, 30,144, "Press B to return!"); + + display_show(disp); + + for (;;) { + controller_scan(); + struct controller_data ckeys = get_keys_down(); + + if (ckeys.c[0].B) { + break; + } + } +} \ No newline at end of file diff --git a/src/menu/menu_info.h b/src/menu/menu_info.h new file mode 100644 index 00000000..5c9872a6 --- /dev/null +++ b/src/menu/menu_info.h @@ -0,0 +1,6 @@ +#ifndef MENU_INFO_H__ +#define MENU_INFO_H__ + +void menu_info(void); + +#endif diff --git a/src/menu/menu_main.c b/src/menu/menu_main.c index a75e0122..86dda2c7 100644 --- a/src/menu/menu_main.c +++ b/src/menu/menu_main.c @@ -10,6 +10,8 @@ #include "settings.h" #include "menu_main.h" +#include "menu_info.h" +#include "menu_test.h" // FIXME: use newlib rather than fatfs to do this! FRESULT scan_file_path (char* path) { @@ -46,7 +48,7 @@ FRESULT scan_file_path (char* path) { void menu_main_refresh (char *dir_path) { console_clear(); - printf("N64 Flashcart Menu\n\n"); + printf("N64 Flashcart Menu V0.0.0\n\n"); printf("SD Card Directory list:\n\n"); scan_file_path(dir_path); } @@ -59,26 +61,26 @@ void menu_main_init (settings_t *settings) { controller_init(); + controller_scan(); + struct controller_data joypad = get_keys_down(); - // TODO: wait for a key input + if ((settings->last_state.auto_load_last_rom) && !(joypad.c[0].B)) { // FIXME: the B button on any controller! + printf("Loading last ROM: %s\n", settings->last_rom.rom_path); + assertf(flashcart_load_rom(settings->last_rom.rom_path) == FLASHCART_OK, "ROM load error"); - if (settings->last_state.auto_load_last_rom) { // TODO: check if there is a button input to cancel. - - printf("Loading last ROM: %s\n", settings->last_rom.rom_path); - assertf(flashcart_load_rom(settings->last_rom.rom_path) == FLASHCART_OK, "ROM load error"); - - printf("Loading save: %s, type: %d, writeback: %d\n", settings->last_rom.save_path, settings->last_rom.save_type, settings->last_rom.save_writeback); - assertf(flashcart_load_save(settings->last_rom.save_path, settings->last_rom.save_type, settings->last_rom.save_writeback) == FLASHCART_OK, "Save load error"); + printf("Loading save: %s, type: %d, writeback: %d\n", settings->last_rom.save_path, settings->last_rom.save_type, settings->last_rom.save_writeback); + assertf(flashcart_load_save(settings->last_rom.save_path, settings->last_rom.save_type, settings->last_rom.save_writeback) == FLASHCART_OK, "Save load error"); } else { + settings->last_state.auto_load_last_rom = false; menu_main_refresh(settings->last_state.current_directory); } for (;;) { controller_scan(); - struct controller_data ckeys = get_keys_down(); + joypad = get_keys_down(); - if (ckeys.c[0].A) { + if (joypad.c[0].A) { console_clear(); printf("TODO: loading ROM...\n"); wait_ms(1000); @@ -86,6 +88,16 @@ void menu_main_init (settings_t *settings) { wait_ms(1000); menu_main_refresh(settings->last_state.current_directory); } + if (joypad.c[0].start) { // FIXME: the START button on any controller! + console_clear(); + menu_info(); + menu_main_refresh(settings->last_state.current_directory); + } + if (joypad.c[0].B) { + console_clear(); + menu_test(); + menu_main_refresh(settings->last_state.current_directory); + } } // TODO: write menu state to SD card diff --git a/src/menu/menu_test.c b/src/menu/menu_test.c new file mode 100644 index 00000000..ecd023ea --- /dev/null +++ b/src/menu/menu_test.c @@ -0,0 +1,75 @@ +#include +#include "libs/menu_utils/include/menu.h" + +#include "menu_test.h" + + +void menu_test(void) { + // display_init(RESOLUTION_512x240, DEPTH_16_BPP, 3, GAMMA_NONE, ANTIALIAS_RESAMPLE); + // display_context_t disp = display_lock(); + // -- initializing global variables used by every menu -- + + // main init function + // (required to set default colors, can omit if setting colors using `menu_global_set_default_colors` or setting colors for items) + // menu_global_init(); + + // // initializes the sprites and offsets used. only required if using them (when creating the menu) + // // !!!menu_global_set_sprites(menu_sprite, hand_sprite, hand_sprite_offset); + + // // optionally overriding the default colors + // //uint32_t selected = graphics_make_color(0, 0, 0, 255); + // //... ommiting the other colors, but you can use the function above to set each color + // // !!!menu_global_set_default_colors(selected, enabled, disabled, background, out_of_bounds, menu_background); + + // // -- now to create the menu... -- + + // // // callback to be used. it's optional, but improves code legibility when using sub-menus. + // // void menu_callback(int option, MenuItem* item); + + // Menu* menu; + // // create a new menu (memory_pool can be NULL if not using it) + // uint8_t total_items = 10; // max items that the menu can have + // uint8_t max_items = 5; // max items that will be displayed at any time (if more than this, there will be scrolling) + // int top = 100, left = 100; // positions on-screen of the menu + // uint8_t item_height = 16; // height in pixels that each item will have (used to calculate background bottom and scrolling) + // menu = menu_init(NULL, total_items, max_items, top, left, item_height, NULL); // not using callbacks + // //menu = menu_init(NULL, total_items, max_items, top, left, item_height, &menu_callback); // using callbacks + + // // add items + // //bool enabled = true; // if the item can be selected or not. color can differ baed on colors set. + // //void *object = &my_custom_object; // this can be held to be retrieved later for custom actions baed on selected item. + + // // adding simple text items + // //menu_add_item(menu, "Item 1", enabled, object); // with object + // menu_add_item(menu, "Item 2", false, NULL); // no object here, forcing disabled + + // // adding colored item (can use different colors for each item) + // //uint32_t color_selected = graphics_make_color(0, 0, 0, 255); + // // omitting other colors... + // //menu_add_item_colored(menu, "Item 3", enabled, color_selected, color_enabled, color_disabled, object); + + // // // adding item as an image instead of text + // // sprite_t *custom_image_sprite; // custom sprite to be used by the item + // // int sprite_index = 2; // index for the custom sprite + // // menu_add_item_image(menu, custom_image_sprite, sprite_index, enabled, object); + + // // ticks the menu to calculate changes to its state. should only be called when the menu is active. + // //struct controller_data keys_down = get_keys_down(); // you should do this only once per frame in your normal code + // //int selected_option = menu_tick(menu, &keys_down); + // // if 'selected_option >= 0' then the corresponding item was selected and you can act accordingly. + // // if using callbacks, 'selected_option' can also be '>= 0', but the function will also be called. + + // // render the menu + // menu_render(menu, disp); + + // // -- optional set-up steps: -- + + // // // add hand cursor + // // int hand_position_x = 105; // X position of the hand. this will never change. + // // int hand_position_y_offset = 5; // offset in pixels to be applied to the sprite when rendering the hand. + // // menu_set_hand(menu, hand_position_x, hand_position_y_offset); + + // // add background + // int menu_width = 200; // width in pixels of the menu. this will be the same regardless of the item width. + // menu_set_background(menu, menu_width); +} \ No newline at end of file diff --git a/src/menu/menu_test.h b/src/menu/menu_test.h new file mode 100644 index 00000000..efae1e67 --- /dev/null +++ b/src/menu/menu_test.h @@ -0,0 +1,6 @@ +#ifndef MENU_TEST_H__ +#define MENU_TEST_H__ + +void menu_test(void); + +#endif