mirror of
https://github.com/Polprzewodnikowy/N64FlashcartMenu.git
synced 2024-11-21 18:19:19 +01:00
Improve sub menus
This commit is contained in:
parent
029e1cf638
commit
e46715757f
@ -17,6 +17,8 @@ static void init (void) {
|
||||
assertf(error != FLASHCART_ERROR_OUTDATED, "Outdated flashcart firmware");
|
||||
assertf(error != FLASHCART_ERROR_UNSUPPORTED, "Unsupported flashcart");
|
||||
assertf(error == FLASHCART_OK, "Unknown error while initializing flashcart");
|
||||
|
||||
display_init(RESOLUTION_512x240, DEPTH_16_BPP, 3, GAMMA_NONE, ANTIALIAS_RESAMPLE);
|
||||
}
|
||||
|
||||
static void deinit (void) {
|
||||
|
@ -1,7 +1,98 @@
|
||||
#include <libdragon.h>
|
||||
#include "menu_res_setup.h"
|
||||
#include "menu_fileinfo.h"
|
||||
#include "../utils/str_utils.h"
|
||||
|
||||
|
||||
void menu_fileinfo(void) {
|
||||
static char* get_file_type(FILINFO current_fileinfo) {
|
||||
// TODO: should be at least a switch statement!
|
||||
if (str_endswith(current_fileinfo.fname, ".z64") || str_endswith(current_fileinfo.fname, ".n64") || str_endswith(current_fileinfo.fname, ".v64") || str_endswith(current_fileinfo.fname, ".rom")) {
|
||||
// TODO: check the necessary bytes in the header to ensure!
|
||||
return "N64 ROM";
|
||||
}
|
||||
else if (str_endswith(current_fileinfo.fname, ".txt")) {
|
||||
return "Text File";
|
||||
}
|
||||
else if (str_endswith(current_fileinfo.fname, ".ini")) {
|
||||
return "INI File";
|
||||
}
|
||||
else if (str_endswith(current_fileinfo.fname, ".yml") || str_endswith(current_fileinfo.fname, ".yaml")) {
|
||||
return "YAML File";
|
||||
}
|
||||
else if (str_endswith(current_fileinfo.fname, ".toml")) {
|
||||
return "TOML File";
|
||||
}
|
||||
else if (str_endswith(current_fileinfo.fname, ".sav")) {
|
||||
return "Save File";
|
||||
}
|
||||
else if (str_endswith(current_fileinfo.fname, ".emu")) {
|
||||
return "Emulator File";
|
||||
}
|
||||
else {
|
||||
return "Unknown File";
|
||||
}
|
||||
}
|
||||
|
||||
void menu_fileinfo_draw_header(display_context_t disp) {
|
||||
|
||||
graphics_draw_text(disp, (disp->width / 2) - 64, vertical_start_position, "FILE INFORMATION"); // centre = numchars * font_horizontal_pixels / 2
|
||||
graphics_draw_line(disp,0,30,disp->width,30, 0xff);
|
||||
|
||||
}
|
||||
|
||||
void menu_fileinfo_draw_footer(display_context_t disp) {
|
||||
|
||||
graphics_draw_line(disp,0,disp->height - overscan_vertical_pixels - font_vertical_pixels,disp->width,disp->height - overscan_vertical_pixels - font_vertical_pixels, 0xff);
|
||||
graphics_draw_text(disp, (disp->width / 2) - 80,disp->height - overscan_vertical_pixels, "Press (B) to return!"); // centre = numchars * font_horizontal_pixels / 2
|
||||
|
||||
}
|
||||
|
||||
void menu_fileinfo(FILINFO current_fileinfo) {
|
||||
|
||||
char str_buffer[1024];
|
||||
|
||||
display_context_t disp = display_try_get();
|
||||
graphics_fill_screen(disp, 0x00);
|
||||
menu_fileinfo_draw_header(disp);
|
||||
|
||||
int16_t vertical_position = 40;
|
||||
|
||||
graphics_draw_text(disp, horizontal_start_position, vertical_position, "Name:");
|
||||
graphics_draw_text(disp, horizontal_indent, vertical_position += font_vertical_pixels, current_fileinfo.fname);
|
||||
vertical_position += (font_vertical_pixels * 2);
|
||||
|
||||
graphics_draw_text(disp, horizontal_start_position, vertical_position, "Size:");
|
||||
sprintf(str_buffer, "%10d %s", (int)current_fileinfo.fsize, "Bytes");
|
||||
graphics_draw_text(disp, horizontal_indent, vertical_position += font_vertical_pixels, str_buffer);
|
||||
vertical_position += (font_vertical_pixels * 2);
|
||||
|
||||
graphics_draw_text(disp, horizontal_start_position, vertical_position, "Attributes:");
|
||||
sprintf(str_buffer, "%s%s%s",
|
||||
((current_fileinfo.fattrib & AM_DIR) ? "Directory\n" : "File\n"),
|
||||
((current_fileinfo.fattrib & AM_RDO) ? "Readonly\n" : " "),
|
||||
((current_fileinfo.fattrib & AM_HID) ? "Hidden\n" : " "));
|
||||
|
||||
graphics_draw_text(disp, horizontal_indent, vertical_position += font_vertical_pixels, str_buffer);
|
||||
vertical_position += (font_vertical_pixels * 2);
|
||||
|
||||
graphics_draw_text(disp, horizontal_start_position, vertical_position, "Modified Date:");
|
||||
sprintf(str_buffer, "%d T %d", current_fileinfo.fdate, current_fileinfo.ftime);
|
||||
graphics_draw_text(disp, horizontal_indent, vertical_position += font_vertical_pixels, str_buffer);
|
||||
vertical_position += (font_vertical_pixels * 2);
|
||||
|
||||
graphics_draw_text(disp, horizontal_start_position, vertical_position, "Type:");
|
||||
graphics_draw_text(disp, horizontal_indent, vertical_position += font_vertical_pixels, get_file_type(current_fileinfo));
|
||||
|
||||
menu_fileinfo_draw_footer(disp);
|
||||
|
||||
display_show(disp);
|
||||
|
||||
for (;;) {
|
||||
controller_scan();
|
||||
struct controller_data ckeys = get_keys_down();
|
||||
|
||||
if (ckeys.c[0].B) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
#ifndef MENU_FILEINFO_H__
|
||||
#define MENU_FILEINFO_H__
|
||||
|
||||
void menu_fileinfo(void);
|
||||
#include <fatfs/ff.h>
|
||||
|
||||
void menu_fileinfo(FILINFO current_fileinfo);
|
||||
|
||||
#endif
|
||||
|
@ -1,29 +1,46 @@
|
||||
#include <libdragon.h>
|
||||
#include "menu_info.h"
|
||||
#include "menu_res_setup.h"
|
||||
|
||||
static void draw_header(display_context_t disp) {
|
||||
graphics_draw_text(disp, 200-70, 10, "Menu Information");
|
||||
void menu_info_draw_header(display_context_t disp) {
|
||||
|
||||
graphics_draw_text(disp, (disp->width / 2) - 64, vertical_start_position, "MENU INFORMATION"); // centre = numchars * font_horizontal_pixels / 2
|
||||
graphics_draw_line(disp,0,30,disp->width,30, 0xff);
|
||||
|
||||
}
|
||||
|
||||
void menu_info_draw_footer(display_context_t disp) {
|
||||
|
||||
graphics_draw_line(disp,0,disp->height - overscan_vertical_pixels - font_vertical_pixels,disp->width,disp->height - overscan_vertical_pixels - font_vertical_pixels, 0xff);
|
||||
graphics_draw_text(disp, (disp->width / 2) - 80,disp->height - overscan_vertical_pixels, "Press (B) to return!"); // centre = numchars * font_horizontal_pixels / 2
|
||||
|
||||
}
|
||||
|
||||
void menu_info(void) {
|
||||
display_init(RESOLUTION_512x240, DEPTH_16_BPP, 3, GAMMA_NONE, ANTIALIAS_RESAMPLE);
|
||||
display_context_t disp = display_get();
|
||||
graphics_fill_screen(disp, 0);
|
||||
draw_header(disp);
|
||||
|
||||
display_context_t disp = display_try_get();
|
||||
graphics_fill_screen(disp, 0x00);
|
||||
menu_info_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");
|
||||
int16_t vertical_position = 40;
|
||||
|
||||
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, horizontal_start_position, vertical_position, "Menu Version:");
|
||||
graphics_draw_text(disp, horizontal_indent,vertical_position += font_vertical_pixels, "Vx.x.x.x"); // FIXME: use global setting.
|
||||
vertical_position += (font_vertical_pixels * 2);
|
||||
graphics_draw_text(disp, horizontal_start_position, vertical_position, "Authors:");
|
||||
graphics_draw_text(disp, horizontal_indent, vertical_position += font_vertical_pixels, "JonesAlmighty / NetworkFusion");
|
||||
graphics_draw_text(disp, horizontal_indent, vertical_position += font_vertical_pixels, "korgeaux / Polprzewodnikowy");
|
||||
vertical_position += (font_vertical_pixels * 2);
|
||||
graphics_draw_text(disp, horizontal_start_position, vertical_position += font_vertical_pixels, "Github:");
|
||||
graphics_draw_text(disp, horizontal_indent, vertical_position += font_vertical_pixels, "https://github.com/Polprzewodnikowy/SummerCart64");
|
||||
graphics_draw_text(disp, horizontal_indent, vertical_position += font_vertical_pixels, "https://github.com/Polprzewodnikowy/N64FlashcartMenu");
|
||||
graphics_draw_text(disp, horizontal_indent, vertical_position += font_vertical_pixels, "https://github.com/networkfusion/N64FlashcartMenu");
|
||||
vertical_position += (font_vertical_pixels * 2);
|
||||
graphics_draw_text(disp, horizontal_start_position, vertical_position, "OSS licenses used:");
|
||||
graphics_draw_text(disp, horizontal_indent,vertical_position += font_vertical_pixels, "GPL");
|
||||
graphics_draw_text(disp, horizontal_indent,vertical_position += font_vertical_pixels, "MIT");
|
||||
|
||||
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!");
|
||||
menu_info_draw_footer(disp);
|
||||
|
||||
display_show(disp);
|
||||
|
||||
|
@ -12,18 +12,15 @@
|
||||
#include "menu_info.h"
|
||||
#include "menu_fileinfo.h"
|
||||
#include "rom_database.h"
|
||||
#include "menu_res_setup.h"
|
||||
|
||||
#include "../utils/str_utils.h"
|
||||
|
||||
static int scroll_menu_position = 1;
|
||||
static int items_in_dir = 1;
|
||||
|
||||
static FILINFO current_fileinfo;
|
||||
|
||||
// e.g. if (str_endswith(cur_rom, ".z64") || str_endswith(cur_rom, ".n64"))
|
||||
static bool str_endswith(const char *str, const char *suffix) {
|
||||
char *p = strstr(str, suffix);
|
||||
return p && p[strlen(suffix)] == '\0';
|
||||
}
|
||||
|
||||
// FIXME: use newlib rather than fatfs to do this!
|
||||
FRESULT scan_file_path (char* path) {
|
||||
|
||||
@ -72,6 +69,9 @@ FRESULT scan_file_path (char* path) {
|
||||
}
|
||||
|
||||
void menu_main_refresh (char *dir_path) {
|
||||
// display_context_t disp = display_try_get();
|
||||
// graphics_fill_screen(disp, 0);
|
||||
// graphics_draw_text(disp, 200-70, 10, "SC64 Flashcart Menu Rev: 0.0.2\n\n");
|
||||
console_clear();
|
||||
printf("SC64 Flashcart Menu Rev: 0.0.2\n\n");
|
||||
printf("SD Card Directory list: %s\n\n", dir_path);
|
||||
@ -169,13 +169,11 @@ void menu_main_init (settings_t *settings) {
|
||||
current_dir = last_dir;
|
||||
}
|
||||
if (joypad.c[0].start) { // FIXME: the START button on any controller!
|
||||
//console_clear();
|
||||
menu_info();
|
||||
menu_main_refresh(current_dir);
|
||||
}
|
||||
if (joypad.c[0].Z) {
|
||||
//console_clear();
|
||||
menu_fileinfo();
|
||||
menu_fileinfo(current_fileinfo);
|
||||
menu_main_refresh(current_dir);
|
||||
}
|
||||
}
|
||||
|
15
src/menu/menu_res_setup.h
Normal file
15
src/menu/menu_res_setup.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef MENU_RES_SETUP_H__
|
||||
#define MENU_RES_SETUP_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
static const int16_t font_vertical_pixels = 8;
|
||||
static const int16_t overscan_vertical_pixels = 24;
|
||||
static const int16_t vertical_start_position = overscan_vertical_pixels / 2;
|
||||
|
||||
static const int16_t font_horizontal_pixels = 8;
|
||||
static const int16_t overscan_horizontal_pixels = 32;
|
||||
static const int16_t horizontal_start_position = overscan_horizontal_pixels + font_horizontal_pixels;
|
||||
static const int16_t horizontal_indent = horizontal_start_position + (font_horizontal_pixels * 2);
|
||||
|
||||
#endif
|
15
src/utils/str_utils.h
Normal file
15
src/utils/str_utils.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef STR_UTILS_H__
|
||||
#define STR_UTILS_H__
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
//#include <stdlib.h> // TODO: does this work... will unlock qsort!
|
||||
#include <string.h>
|
||||
|
||||
// e.g. if (str_endswith(cur_rom, ".z64") || str_endswith(cur_rom, ".n64"))
|
||||
static bool str_endswith(const char *str, const char *suffix) {
|
||||
char *p = strstr(str, suffix);
|
||||
return p && p[strlen(suffix)] == '\0';
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user