From 8d164d38a0b3c52b03ece3888e124965d3c5242d Mon Sep 17 00:00:00 2001 From: stpohle Date: Sun, 4 Jan 2004 19:45:56 +0000 Subject: [PATCH] changed menu handling so you can focus your own element. network server selection changed, so the serverlist will be focused first and after the selection of an server the OK Button will be focused. --- src/menu.c | 41 +++++++++++++++++++++++++++-------------- src/netsrvlist.c | 4 +++- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/menu.c b/src/menu.c index d64a265..4f0e469 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.34 2004/01/04 03:22:49 stpohle Exp $ +/* $Id: menu.c,v 1.35 2004/01/04 19:45:56 stpohle Exp $ * Menuhandling */ #include "basic.h" @@ -10,7 +10,7 @@ _menuitem menuitems[MENU_MAXENTRYS]; _menu menu; - +int menu_looprunning = 0; /* delete all informations and create a totally new menuscreen */ void menu_new (char *title, int x, int y) { @@ -35,6 +35,8 @@ void menu_new (char *title, int x, int y) { menu.oldscreenpos.w = x + 2*menu.images[0]->w; menu.oldscreenpos.h = y + 2*menu.images[0]->h; menu.oldscreen = gfx_copyscreen (&menu.oldscreenpos); + menu.focus = NULL; + menu_looprunning = 0; }; @@ -47,7 +49,7 @@ void menu_delete () { menuitems[0].next = NULL; menu.items = NULL; - + menu_looprunning = 0; if (GS_RUNNING) draw_field (); }; @@ -165,7 +167,8 @@ void menu_draw_border () { * to be called before the menu is drawed on the screen */ void menu_draw () { _menuitem *m; - + if (!menu_looprunning) return; + menu_draw_border (); for (m = menu.items; m != NULL; m = m->next) @@ -176,6 +179,7 @@ void menu_draw () { /* draw an item on the screen */ inline void menu_draw_menuitem (_menuitem *m) { + if (!menu_looprunning) return; switch (m->type) { case (MENU_label): menu_draw_label (m); @@ -266,19 +270,22 @@ void menu_change_focus (_menuitem *newfocus) { return; /* lose focus */ - switch (menu.focus->type) { - case (MENU_entryfloat): - case (MENU_entryint16): - case (MENU_entryint32): - case (MENU_entrytext): - menu_entry_lose_focus (menu.focus); - break; + if (menu.focus != NULL) { + switch (menu.focus->type) { + case (MENU_entryfloat): + case (MENU_entryint16): + case (MENU_entryint32): + case (MENU_entrytext): + menu_entry_lose_focus (menu.focus); + break; + } } /* draw the old and the new element */ oldmi = menu.focus; menu.focus = newfocus; - menu_draw_menuitem (oldmi); + if (oldmi != NULL) + menu_draw_menuitem (oldmi); menu_draw_menuitem (menu.focus); /* get focus ... no function yet */ @@ -336,15 +343,19 @@ int menu_loop () { Uint8 *keys; int keypressed = 0, done = 0, eventstate = 0, reorder = 0; + menu_looprunning = 1; + /* check if the focus is set to something, if not * set the focus to the first item */ - if (menu.focus == NULL) + if (menu.focus == NULL) { menu.focus = menu.items; + menu_focus_id (0); + } if (menu.focus == NULL) { d_fatal ("menu_loop: focus == NULL, something went wrong\n"); + menu_looprunning = 0; return -1; } - menu_focus_id (0); keys = SDL_GetKeyState (NULL); if (keys[SDLK_RETURN] || keys[SDLK_ESCAPE]) @@ -420,6 +431,8 @@ int menu_loop () { s_calctimesync (); } + menu_looprunning = 0; + if (reorder) return -2; diff --git a/src/netsrvlist.c b/src/netsrvlist.c index 142eaac..8ca95a0 100644 --- a/src/netsrvlist.c +++ b/src/netsrvlist.c @@ -1,4 +1,4 @@ -/* $Id: netsrvlist.c,v 1.6 2004/01/04 03:22:49 stpohle Exp $ +/* $Id: netsrvlist.c,v 1.7 2004/01/04 19:45:56 stpohle Exp $ * netsrvlist.c - shows a list of possible servers.*/ #include "basic.h" @@ -94,6 +94,7 @@ void net_getserver () { menu_create_list ("Host a Game", -1, 50, 475, 250, srvlst_text, &sel_entry, 1); menu_create_entry ("IP :", -1, 320, 475, bman.servername, LEN_SERVERNAME+LEN_PORT + 2, MENU_entrytext, 2); menu_create_button ("OK", -1, 350, 150, 0); + menu_focus_id (1); while (menuselect != -1 && bman.state != GS_quit) { srvlist_rebuildlist (); @@ -112,6 +113,7 @@ void net_getserver () { && srvlst_dat[entry].gamename[0] != 0) { /* test if there was a selection */ bman.net_ai_family = srvlst_dat[entry].ai_family; sprintf (bman.servername, "%s:%s", srvlst_dat[entry].host, srvlst_dat[entry].port); + menu_focus_id (0); } break; }