diff --git a/CHANGES.WII b/CHANGES.WII index f289554..951917f 100644 --- a/CHANGES.WII +++ b/CHANGES.WII @@ -6,13 +6,17 @@ TODO: Crash on + in "Other" menu version 7: + * Wiimote direction keys and "fire" can now be bound to keyboard + keys + * Allow binding 1 and other extra buttons to joystick directions - and fire + and fire + + * Simplify menu code even more -- Simon Kagstrom , version 6: - TODO: Multiple frodo versions, switch between * Handle reset button (back to menu) * General code cleanup, e.g., simplified menu system and reduced the diff --git a/Src/C64_SDL.h b/Src/C64_SDL.h index a287e7d..35fe2ea 100644 --- a/Src/C64_SDL.h +++ b/Src/C64_SDL.h @@ -72,28 +72,6 @@ void C64::c64_ctor1(void) memset(this->save_game_name, 0, sizeof(this->save_game_name)); 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); strncpy(this->server_hostname, "localhost", @@ -109,7 +87,7 @@ void C64::c64_ctor1(void) for (i = 0; i < 20; i++) { printf("Waiting for connection, try %d of 20\n", i+1); - if (this->peer->WaitForConnection() == true) + if (this->peer->Connect() == true) break; } if (i == 20) @@ -124,7 +102,7 @@ void C64::c64_ctor1(void) strcpy(this->server_hostname, fixme_tmp_network_client); this->peer = new Network(this->server_hostname, this->server_port, false); 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) return; - int opt = menu_select(real_screen, this->menu_font, - file_list, NULL); + int opt = menu_select(file_list, NULL); if (opt >= 0) { 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++) bind_key_messages[i] = this->bind_one_key(np, i); - int opt = menu_select(real_screen, this->menu_font, - bind_key_messages, NULL); + int opt = menu_select(bind_key_messages, NULL); if (opt >= 0) { int key; @@ -346,8 +322,7 @@ void C64::networking_menu(Prefs *np) this->server_hostname); snprintf(buf[1], 255, "Port (now %d)", this->server_port); - opt = menu_select(real_screen, this->menu_font, - network_client_messages, NULL); + opt = menu_select(network_client_messages, NULL); if (opt == 1 || opt == 2) { @@ -403,8 +378,7 @@ void C64::other_options(Prefs *np) /* If it has some other value... */ submenus[1] = 1; break; } - int opt = menu_select(real_screen, this->menu_font, - other_options_messages, submenus); + int opt = menu_select(other_options_messages, submenus); if (opt >= 0) { np->DisplayOption = submenus[0]; @@ -472,8 +446,7 @@ void C64::select_fake_key_sequence(Prefs *np) NULL}; int opt; - opt = menu_select(real_screen, this->menu_font, - fake_key_messages, NULL); + opt = menu_select(fake_key_messages, NULL); if (opt < 0) return; @@ -490,8 +463,7 @@ void C64::select_fake_key_sequence(Prefs *np) void C64::save_load_state(Prefs *np) { - int opt = menu_select(real_screen, this->menu_font, - save_load_state_messages, NULL); + int opt = menu_select(save_load_state_messages, NULL); switch(opt) { case 1: /* save */ @@ -513,8 +485,7 @@ void C64::save_load_state(Prefs *np) if (file_list == NULL) break; - int save = menu_select(real_screen, this->menu_font, - file_list, NULL); + int save = menu_select(file_list, NULL); if (save >= 0) { char save_buf[255]; @@ -722,8 +693,7 @@ void C64::VBlank(bool draw_frame) TheSID->PauseSound(); submenus[0] = old_swap; - opt = menu_select(real_screen, this->menu_font, - main_menu_messages, submenus); + opt = menu_select(main_menu_messages, submenus); switch(opt) { diff --git a/Src/NetworkUnix.h b/Src/NetworkUnix.h index fd6e696..90c801f 100644 --- a/Src/NetworkUnix.h +++ b/Src/NetworkUnix.h @@ -47,7 +47,7 @@ static int make_socket (uint16_t port) return sock; } -bool init_sockaddr (struct sockaddr_in *name, +bool Network::InitSockaddr (struct sockaddr_in *name, const char *hostname, uint16_t port) { struct hostent *hostinfo; diff --git a/Src/main_wii.h b/Src/main_wii.h index 7a7cd9f..c9818a2 100644 --- a/Src/main_wii.h +++ b/Src/main_wii.h @@ -10,6 +10,8 @@ #include #include +#include "menu.h" + 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() ); return 0; } + menu_init(); if (WPAD_Init() != WPAD_ERR_NONE) { diff --git a/Src/main_x.h b/Src/main_x.h index 2fa9808..8f8f83b 100644 --- a/Src/main_x.h +++ b/Src/main_x.h @@ -33,6 +33,8 @@ extern "C" int main(int argc, char *argv[]); #include #endif +#include "menu.h" + 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() ); return 1; } + menu_init(); #endif if (!init_graphics()) return 1; diff --git a/Src/menu.cpp b/Src/menu.cpp index ba9d8cd..cb1c6de 100644 --- a/Src/menu.cpp +++ b/Src/menu.cpp @@ -47,6 +47,8 @@ typedef struct #define IS_SUBMENU(p_msg) ( (p_msg)[0] == '^' ) +static TTF_Font *menu_font; + static submenu_t *find_submenu(menu_t *p_menu, int index) { int i; @@ -60,7 +62,7 @@ static submenu_t *find_submenu(menu_t *p_menu, int index) 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) { SDL_Surface *font_surf; @@ -434,8 +436,7 @@ static int menu_select_internal(SDL_Surface *screen, return ret; } -int menu_select(SDL_Surface *screen, TTF_Font *font, const char **msgs, - int *submenus) +int menu_select(const char **msgs, int *submenus) { menu_t menu; int out; @@ -443,12 +444,36 @@ int menu_select(SDL_Surface *screen, TTF_Font *font, const char **msgs, menu_init(&menu, font, msgs, 32, 32, FULL_DISPLAY_X - FULL_DISPLAY_X / 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); 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) char *main_menu[] = { diff --git a/Src/menu.h b/Src/menu.h index 3cfcb58..758f7e8 100644 --- a/Src/menu.h +++ b/Src/menu.h @@ -32,11 +32,12 @@ extern "C" { void menu_print_font(SDL_Surface *screen, TTF_Font *font, int r, int g, int b, int x, int y, const char *msg); -int menu_select(SDL_Surface *screen, TTF_Font *font, const char **pp_msgs, - int *p_submenus); +int menu_select(const char **pp_msgs, int *p_submenus); uint32_t menu_wait_key_press(void); +void menu_init(); + #if defined(__cplusplus) }; #endif /* __cplusplus */