Even more menu simplification

This commit is contained in:
simon.kagstrom 2009-02-13 07:58:33 +00:00
parent b2ca587041
commit 18b0f333f5
7 changed files with 55 additions and 49 deletions

View File

@ -6,13 +6,17 @@
TODO: Crash on + in "Other" menu TODO: Crash on + in "Other" menu
version 7: version 7:
* Wiimote direction keys and "fire" can now be bound to keyboard
keys
* Allow binding 1 and other extra buttons to joystick directions * Allow binding 1 and other extra buttons to joystick directions
and fire and fire
* Simplify menu code even more
-- Simon Kagstrom <simon.kagstrom@gmail.com>, -- Simon Kagstrom <simon.kagstrom@gmail.com>,
version 6: version 6:
TODO: Multiple frodo versions, switch between
* Handle reset button (back to menu) * Handle reset button (back to menu)
* General code cleanup, e.g., simplified menu system and reduced the * General code cleanup, e.g., simplified menu system and reduced the

View File

@ -72,28 +72,6 @@ void C64::c64_ctor1(void)
memset(this->save_game_name, 0, sizeof(this->save_game_name)); memset(this->save_game_name, 0, sizeof(this->save_game_name));
strcpy(this->save_game_name, "unknown"); strcpy(this->save_game_name, "unknown");
SDL_RWops *rw;
Uint8 *data = (Uint8*)malloc(1 * 1024*1024);
FILE *fp = fopen(FONT_PATH, "r");
if (!fp) {
fprintf(stderr, "Could not open font\n");
exit(1);
}
fread(data, 1, 1 * 1024 * 1024, fp);
rw = SDL_RWFromMem(data, 1 * 1024 * 1024);
if (!rw) {
fprintf(stderr, "Could not create RW: %s\n", SDL_GetError());
exit(1);
}
this->menu_font = TTF_OpenFontRW(rw, 1, 20);
if (!this->menu_font)
{
fprintf(stderr, "Unable to open font\n" );
exit(1);
}
this->virtual_keyboard = new VirtualKeyboard(real_screen, this->menu_font); this->virtual_keyboard = new VirtualKeyboard(real_screen, this->menu_font);
strncpy(this->server_hostname, "localhost", strncpy(this->server_hostname, "localhost",
@ -109,7 +87,7 @@ void C64::c64_ctor1(void)
for (i = 0; i < 20; i++) for (i = 0; i < 20; i++)
{ {
printf("Waiting for connection, try %d of 20\n", i+1); printf("Waiting for connection, try %d of 20\n", i+1);
if (this->peer->WaitForConnection() == true) if (this->peer->Connect() == true)
break; break;
} }
if (i == 20) if (i == 20)
@ -124,7 +102,7 @@ void C64::c64_ctor1(void)
strcpy(this->server_hostname, fixme_tmp_network_client); strcpy(this->server_hostname, fixme_tmp_network_client);
this->peer = new Network(this->server_hostname, this->server_port, false); this->peer = new Network(this->server_hostname, this->server_port, false);
this->network_connection_type = CLIENT; this->network_connection_type = CLIENT;
this->peer->ConnectToPeer(); this->peer->Connect();
} }
} }
@ -212,8 +190,7 @@ void C64::select_disc(Prefs *np)
if (file_list == NULL) if (file_list == NULL)
return; return;
int opt = menu_select(real_screen, this->menu_font, int opt = menu_select(file_list, NULL);
file_list, NULL);
if (opt >= 0) if (opt >= 0)
{ {
const char *name = file_list[opt]; const char *name = file_list[opt];
@ -310,8 +287,7 @@ void C64::bind_keys(Prefs *np)
for (int i = 0; i < (has_classic_controller ? N_WIIMOTE_BINDINGS : WIIMOTE_2); i++) for (int i = 0; i < (has_classic_controller ? N_WIIMOTE_BINDINGS : WIIMOTE_2); i++)
bind_key_messages[i] = this->bind_one_key(np, i); bind_key_messages[i] = this->bind_one_key(np, i);
int opt = menu_select(real_screen, this->menu_font, int opt = menu_select(bind_key_messages, NULL);
bind_key_messages, NULL);
if (opt >= 0) if (opt >= 0)
{ {
int key; int key;
@ -346,8 +322,7 @@ void C64::networking_menu(Prefs *np)
this->server_hostname); this->server_hostname);
snprintf(buf[1], 255, "Port (now %d)", snprintf(buf[1], 255, "Port (now %d)",
this->server_port); this->server_port);
opt = menu_select(real_screen, this->menu_font, opt = menu_select(network_client_messages, NULL);
network_client_messages, NULL);
if (opt == 1 || opt == 2) if (opt == 1 || opt == 2)
{ {
@ -403,8 +378,7 @@ void C64::other_options(Prefs *np)
/* If it has some other value... */ /* If it has some other value... */
submenus[1] = 1; break; submenus[1] = 1; break;
} }
int opt = menu_select(real_screen, this->menu_font, int opt = menu_select(other_options_messages, submenus);
other_options_messages, submenus);
if (opt >= 0) if (opt >= 0)
{ {
np->DisplayOption = submenus[0]; np->DisplayOption = submenus[0];
@ -472,8 +446,7 @@ void C64::select_fake_key_sequence(Prefs *np)
NULL}; NULL};
int opt; int opt;
opt = menu_select(real_screen, this->menu_font, opt = menu_select(fake_key_messages, NULL);
fake_key_messages, NULL);
if (opt < 0) if (opt < 0)
return; return;
@ -490,8 +463,7 @@ void C64::select_fake_key_sequence(Prefs *np)
void C64::save_load_state(Prefs *np) void C64::save_load_state(Prefs *np)
{ {
int opt = menu_select(real_screen, this->menu_font, int opt = menu_select(save_load_state_messages, NULL);
save_load_state_messages, NULL);
switch(opt) switch(opt)
{ {
case 1: /* save */ case 1: /* save */
@ -513,8 +485,7 @@ void C64::save_load_state(Prefs *np)
if (file_list == NULL) if (file_list == NULL)
break; break;
int save = menu_select(real_screen, this->menu_font, int save = menu_select(file_list, NULL);
file_list, NULL);
if (save >= 0) if (save >= 0)
{ {
char save_buf[255]; char save_buf[255];
@ -722,8 +693,7 @@ void C64::VBlank(bool draw_frame)
TheSID->PauseSound(); TheSID->PauseSound();
submenus[0] = old_swap; submenus[0] = old_swap;
opt = menu_select(real_screen, this->menu_font, opt = menu_select(main_menu_messages, submenus);
main_menu_messages, submenus);
switch(opt) switch(opt)
{ {

View File

@ -47,7 +47,7 @@ static int make_socket (uint16_t port)
return sock; return sock;
} }
bool init_sockaddr (struct sockaddr_in *name, bool Network::InitSockaddr (struct sockaddr_in *name,
const char *hostname, uint16_t port) const char *hostname, uint16_t port)
{ {
struct hostent *hostinfo; struct hostent *hostinfo;

View File

@ -10,6 +10,8 @@
#include <fat.h> #include <fat.h>
#include <wiiuse/wpad.h> #include <wiiuse/wpad.h>
#include "menu.h"
extern int init_graphics(void); extern int init_graphics(void);
/* /*
@ -46,6 +48,7 @@ extern "C" int main(int argc, char **argv)
fprintf(stderr, "Unable to init TTF: %s\n", TTF_GetError() ); fprintf(stderr, "Unable to init TTF: %s\n", TTF_GetError() );
return 0; return 0;
} }
menu_init();
if (WPAD_Init() != WPAD_ERR_NONE) if (WPAD_Init() != WPAD_ERR_NONE)
{ {

View File

@ -33,6 +33,8 @@ extern "C" int main(int argc, char *argv[]);
#include <SDL.h> #include <SDL.h>
#endif #endif
#include "menu.h"
extern int init_graphics(void); extern int init_graphics(void);
@ -73,6 +75,7 @@ int main(int argc, char **argv)
fprintf(stderr, "Unable to init TTF: %s\n", TTF_GetError() ); fprintf(stderr, "Unable to init TTF: %s\n", TTF_GetError() );
return 1; return 1;
} }
menu_init();
#endif #endif
if (!init_graphics()) if (!init_graphics())
return 1; return 1;

View File

@ -47,6 +47,8 @@ typedef struct
#define IS_SUBMENU(p_msg) ( (p_msg)[0] == '^' ) #define IS_SUBMENU(p_msg) ( (p_msg)[0] == '^' )
static TTF_Font *menu_font;
static submenu_t *find_submenu(menu_t *p_menu, int index) static submenu_t *find_submenu(menu_t *p_menu, int index)
{ {
int i; int i;
@ -60,7 +62,7 @@ static submenu_t *find_submenu(menu_t *p_menu, int index)
return NULL; return NULL;
} }
void menu_print_font(SDL_Surface *screen, TTF_Font *font, int r, int g, int b, void menu_print_font(SDL_Surface *screen, int r, int g, int b,
int x, int y, const char *msg) int x, int y, const char *msg)
{ {
SDL_Surface *font_surf; SDL_Surface *font_surf;
@ -434,8 +436,7 @@ static int menu_select_internal(SDL_Surface *screen,
return ret; return ret;
} }
int menu_select(SDL_Surface *screen, TTF_Font *font, const char **msgs, int menu_select(const char **msgs, int *submenus)
int *submenus)
{ {
menu_t menu; menu_t menu;
int out; int out;
@ -443,12 +444,36 @@ int menu_select(SDL_Surface *screen, TTF_Font *font, const char **msgs,
menu_init(&menu, font, msgs, menu_init(&menu, font, msgs,
32, 32, FULL_DISPLAY_X - FULL_DISPLAY_X / 4, 32, 32, FULL_DISPLAY_X - FULL_DISPLAY_X / 4,
FULL_DISPLAY_Y - FULL_DISPLAY_Y / 4); FULL_DISPLAY_Y - FULL_DISPLAY_Y / 4);
out = menu_select_internal(screen, &menu, submenus); out = menu_select_internal(real_screen, &menu, submenus);
menu_fini(&menu); menu_fini(&menu);
return out; return out;
} }
void menu_init()
{
SDL_RWops *rw;
Uint8 *data = (Uint8*)malloc(1 * 1024*1024);
FILE *fp = fopen(FONT_PATH, "r");
if (!fp) {
fprintf(stderr, "Could not open font\n");
exit(1);
}
fread(data, 1, 1 * 1024 * 1024, fp);
rw = SDL_RWFromMem(data, 1 * 1024 * 1024);
if (!rw) {
fprintf(stderr, "Could not create RW: %s\n", SDL_GetError());
exit(1);
}
menu_font = TTF_OpenFontRW(rw, 1, 20);
if (!menu_font)
{
fprintf(stderr, "Unable to open font\n" );
exit(1);
}
}
#if defined(TEST_MENU) #if defined(TEST_MENU)
char *main_menu[] = { char *main_menu[] = {

View File

@ -32,11 +32,12 @@ extern "C" {
void menu_print_font(SDL_Surface *screen, TTF_Font *font, int r, int g, int b, void menu_print_font(SDL_Surface *screen, TTF_Font *font, int r, int g, int b,
int x, int y, const char *msg); int x, int y, const char *msg);
int menu_select(SDL_Surface *screen, TTF_Font *font, const char **pp_msgs, int menu_select(const char **pp_msgs, int *p_submenus);
int *p_submenus);
uint32_t menu_wait_key_press(void); uint32_t menu_wait_key_press(void);
void menu_init();
#if defined(__cplusplus) #if defined(__cplusplus)
}; };
#endif /* __cplusplus */ #endif /* __cplusplus */