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 */ /* menu's for the game */
#include <SDL.h> #include <SDL.h>
@ -354,8 +354,6 @@ menu_displaymessage (char *title, char *text)
*** Menu Selection of a file ior a directory *** Menu Selection of a file ior a directory
***/ ***/
#define DIRSCRMAX 10 #define DIRSCRMAX 10
static char menu_selectedfile[LEN_PATHFILENAME];
/* draws the selection on the screen.. /* draws the selection on the screen..
dirstart - first entry do display dirstart - first entry do display
flags - flags what should be shown directorys or files flags - flags what should be shown directorys or files
@ -363,33 +361,40 @@ static char menu_selectedfile[LEN_PATHFILENAME];
*/ */
int menu_dir_draw (char *title, _direntry *dirstart, int start, int selected) { int menu_dir_draw (char *title, _direntry *dirstart, int start, int selected) {
_direntry *de = dirstart; _direntry *de = dirstart;
int maxlen = 0; int maxlen = 0, pos = 0;
SDL_Rect wnd; SDL_Rect wnd;
/* look for the longest name */ /* look for the longest name */
for (; de != NULL; de = de->next) for (; de != NULL; de = de->next)
if (maxlen < strlen (de->name)) if (maxlen < strlen (de->name))
maxlen = strlen (de->name); maxlen = strlen (de->name);
if (maxlen * gfx.font.size.x > gfx.res.x) maxlen = strlen (title);
maxlen = (gfx.res.x - 8) /gfx.font.size.x;
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.h = DIRSCRMAX * gfx.font.size.y * 2;
wnd.w = maxlen * gfx.font.size.x; wnd.w = maxlen * gfx.font.size.x;
wnd.x = gfx.res.x - wnd.w / 2; wnd.x = (gfx.res.x - wnd.w) / 2;
wnd.y = gfx.res.y - wnd.h / 2; wnd.y = (gfx.res.y - wnd.h) / 2;
draw_menubox (wnd.w, wnd.h); 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) { char *menu_dir_select (char *title, char *path, signed char dirflags) {
_direntry *destart, *de; _direntry *destart, *de;
SDL_Event event; SDL_Event event;
Uint8 *keys; 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 */ /* get the directory list and count the numbers */
destart = s_getdir (path); 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)) { while (done == 0 || (done == 1 && keypressed == 1)) {
/* do the network loop if we have to */ /* do the network loop if we have to */
listend = menu_dir_draw (title, destart, liststart, sel); listend = menu_dir_draw (title, destart, liststart, sel);
SDL_Flip (gfx.screen);
if (bman.gametype == GT_multi && bman.sock != -1) if (bman.gametype == GT_multi && bman.sock != -1)
network_loop (); 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) { if (keys[SDLK_ESCAPE] && event.type == SDL_KEYDOWN) {
keypressed = 1; keypressed = 1;
return -1; return NULL;
} }
if (!keys[SDLK_ESCAPE] && event.type == SDL_KEYUP) if (!keys[SDLK_ESCAPE] && event.type == SDL_KEYUP)
keypressed = 0; keypressed = 0;
@ -455,5 +461,13 @@ char *menu_dir_select (char *title, char *path, signed char dirflags) {
s_delay (100); 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 #undef DIRSCRMAX

Loading…
Cancel
Save