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.
origin
stpohle 22 years ago
parent ede4215372
commit 8d164d38a0

@ -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 */ * Menuhandling */
#include "basic.h" #include "basic.h"
@ -10,7 +10,7 @@
_menuitem menuitems[MENU_MAXENTRYS]; _menuitem menuitems[MENU_MAXENTRYS];
_menu menu; _menu menu;
int menu_looprunning = 0;
/* delete all informations and create a totally new menuscreen */ /* delete all informations and create a totally new menuscreen */
void menu_new (char *title, int x, int y) { 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.w = x + 2*menu.images[0]->w;
menu.oldscreenpos.h = y + 2*menu.images[0]->h; menu.oldscreenpos.h = y + 2*menu.images[0]->h;
menu.oldscreen = gfx_copyscreen (&menu.oldscreenpos); menu.oldscreen = gfx_copyscreen (&menu.oldscreenpos);
menu.focus = NULL;
menu_looprunning = 0;
}; };
@ -47,7 +49,7 @@ void menu_delete () {
menuitems[0].next = NULL; menuitems[0].next = NULL;
menu.items = NULL; menu.items = NULL;
menu_looprunning = 0;
if (GS_RUNNING) if (GS_RUNNING)
draw_field (); draw_field ();
}; };
@ -165,6 +167,7 @@ void menu_draw_border () {
* to be called before the menu is drawed on the screen */ * to be called before the menu is drawed on the screen */
void menu_draw () { void menu_draw () {
_menuitem *m; _menuitem *m;
if (!menu_looprunning) return;
menu_draw_border (); menu_draw_border ();
@ -176,6 +179,7 @@ void menu_draw () {
/* draw an item on the screen */ /* draw an item on the screen */
inline void menu_draw_menuitem (_menuitem *m) { inline void menu_draw_menuitem (_menuitem *m) {
if (!menu_looprunning) return;
switch (m->type) { switch (m->type) {
case (MENU_label): case (MENU_label):
menu_draw_label (m); menu_draw_label (m);
@ -266,6 +270,7 @@ void menu_change_focus (_menuitem *newfocus) {
return; return;
/* lose focus */ /* lose focus */
if (menu.focus != NULL) {
switch (menu.focus->type) { switch (menu.focus->type) {
case (MENU_entryfloat): case (MENU_entryfloat):
case (MENU_entryint16): case (MENU_entryint16):
@ -274,10 +279,12 @@ void menu_change_focus (_menuitem *newfocus) {
menu_entry_lose_focus (menu.focus); menu_entry_lose_focus (menu.focus);
break; break;
} }
}
/* draw the old and the new element */ /* draw the old and the new element */
oldmi = menu.focus; oldmi = menu.focus;
menu.focus = newfocus; menu.focus = newfocus;
if (oldmi != NULL)
menu_draw_menuitem (oldmi); menu_draw_menuitem (oldmi);
menu_draw_menuitem (menu.focus); menu_draw_menuitem (menu.focus);
@ -336,15 +343,19 @@ int menu_loop () {
Uint8 *keys; Uint8 *keys;
int keypressed = 0, done = 0, eventstate = 0, reorder = 0; int keypressed = 0, done = 0, eventstate = 0, reorder = 0;
menu_looprunning = 1;
/* check if the focus is set to something, if not /* check if the focus is set to something, if not
* set the focus to the first item */ * set the focus to the first item */
if (menu.focus == NULL) if (menu.focus == NULL) {
menu.focus = menu.items; menu.focus = menu.items;
menu_focus_id (0);
}
if (menu.focus == NULL) { if (menu.focus == NULL) {
d_fatal ("menu_loop: focus == NULL, something went wrong\n"); d_fatal ("menu_loop: focus == NULL, something went wrong\n");
menu_looprunning = 0;
return -1; return -1;
} }
menu_focus_id (0);
keys = SDL_GetKeyState (NULL); keys = SDL_GetKeyState (NULL);
if (keys[SDLK_RETURN] || keys[SDLK_ESCAPE]) if (keys[SDLK_RETURN] || keys[SDLK_ESCAPE])
@ -420,6 +431,8 @@ int menu_loop () {
s_calctimesync (); s_calctimesync ();
} }
menu_looprunning = 0;
if (reorder) if (reorder)
return -2; return -2;

@ -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.*/ * netsrvlist.c - shows a list of possible servers.*/
#include "basic.h" #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_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_entry ("IP :", -1, 320, 475, bman.servername, LEN_SERVERNAME+LEN_PORT + 2, MENU_entrytext, 2);
menu_create_button ("OK", -1, 350, 150, 0); menu_create_button ("OK", -1, 350, 150, 0);
menu_focus_id (1);
while (menuselect != -1 && bman.state != GS_quit) { while (menuselect != -1 && bman.state != GS_quit) {
srvlist_rebuildlist (); srvlist_rebuildlist ();
@ -112,6 +113,7 @@ void net_getserver () {
&& srvlst_dat[entry].gamename[0] != 0) { /* test if there was a selection */ && srvlst_dat[entry].gamename[0] != 0) { /* test if there was a selection */
bman.net_ai_family = srvlst_dat[entry].ai_family; bman.net_ai_family = srvlst_dat[entry].ai_family;
sprintf (bman.servername, "%s:%s", srvlst_dat[entry].host, srvlst_dat[entry].port); sprintf (bman.servername, "%s:%s", srvlst_dat[entry].host, srvlst_dat[entry].port);
menu_focus_id (0);
} }
break; break;
} }

Loading…
Cancel
Save