Single Player Tileselection Test1

origin
stpohle 23 years ago
parent fe8a8c6cfe
commit 83b1d7f012

@ -1,4 +1,4 @@
/* $Id: menu.c,v 1.9 2003/05/07 00:21:38 stpohle Exp $ */
/* $Id: menu.c,v 1.10 2003/05/07 14:30:39 stpohle Exp $ */
/* menu's for the game */
#include <SDL.h>
@ -354,8 +354,6 @@ menu_displaymessage (char *title, char *text)
*** Menu Selection of a file ior a directory
***/
#define DIRSCRMAX 10
static char menu_selectedfile[LEN_PATHFILENAME];
/* draws the selection on the screen..
dirstart - first entry do display
flags - flags what should be shown directorys or files
@ -363,7 +361,7 @@ static char menu_selectedfile[LEN_PATHFILENAME];
*/
int menu_dir_draw (char *title, _direntry *dirstart, int start, int selected) {
_direntry *de = dirstart;
int maxlen = 0;
int maxlen = 0, pos = 0;
SDL_Rect wnd;
/* look for the longest name */
@ -371,25 +369,32 @@ int menu_dir_draw (char *title, _direntry *dirstart, int start, int selected) {
if (maxlen < strlen (de->name))
maxlen = strlen (de->name);
if (maxlen * gfx.font.size.x > gfx.res.x)
maxlen = (gfx.res.x - 8) /gfx.font.size.x;
maxlen = strlen (title);
if (maxlen * gfx.font.size.x > gfx.res.x - 32)
maxlen = (gfx.res.x - 40) /gfx.font.size.x;
wnd.h = DIRSCRMAX * gfx.font.size.y * 2;
wnd.w = maxlen * gfx.font.size.x;
wnd.x = gfx.res.x - wnd.w / 2;
wnd.y = gfx.res.y - wnd.h / 2;
wnd.x = (gfx.res.x - wnd.w) / 2;
wnd.y = (gfx.res.y - wnd.h) / 2;
draw_menubox (wnd.w, wnd.h);
draw_text ((gfx.res.x - (gfx.font.size.x/1.17) * strlen (title)) / 2, wnd.y + 4, title, 1);
return 0;
for (de = dirstart, pos = 0; de != NULL && pos < start + DIRSCRMAX - 1; de=de->next, pos++) {
if (pos >= start && pos < (start + DIRSCRMAX - 1))
draw_text (wnd.x + gfx.menuselect.image->w + 2, 8 + wnd.y + (1+pos-start) * gfx.font.size.y * 2, de->name, (pos == selected));
}
return (de == NULL);
}
char *menu_dir_select (char *title, char *path, signed char dirflags) {
_direntry *destart, *de;
SDL_Event event;
Uint8 *keys;
int max = 0, sel = -1, keypressed = 0, done = 0, listend = 0, liststart = 0;
int max = 0, sel = 0, keypressed = 0, done = 0, listend = 0, liststart = 0;
/* get the directory list and count the numbers */
destart = s_getdir (path);
@ -402,6 +407,7 @@ char *menu_dir_select (char *title, char *path, signed char dirflags) {
while (done == 0 || (done == 1 && keypressed == 1)) {
/* do the network loop if we have to */
listend = menu_dir_draw (title, destart, liststart, sel);
SDL_Flip (gfx.screen);
if (bman.gametype == GT_multi && bman.sock != -1)
network_loop ();
@ -441,7 +447,7 @@ char *menu_dir_select (char *title, char *path, signed char dirflags) {
if (keys[SDLK_ESCAPE] && event.type == SDL_KEYDOWN) {
keypressed = 1;
return -1;
return NULL;
}
if (!keys[SDLK_ESCAPE] && event.type == SDL_KEYUP)
keypressed = 0;
@ -455,5 +461,13 @@ char *menu_dir_select (char *title, char *path, signed char dirflags) {
s_delay (100);
}
for (max = 0, de = destart; max != sel && de != NULL; de = de->next)
max++;
if (de == NULL)
return NULL;
return de->name;
};
#undef DIRSCRMAX

Loading…
Cancel
Save