|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
/* $Id: menu.c,v 1.8 2003/05/06 21:45:08 stpohle Exp $ */
|
|
|
|
|
/* $Id: menu.c,v 1.9 2003/05/07 00:21:38 stpohle Exp $ */
|
|
|
|
|
/* menu's for the game */
|
|
|
|
|
|
|
|
|
|
#include <SDL.h>
|
|
|
|
@ -8,7 +8,7 @@
|
|
|
|
|
#define MENU_BG_SHADE_DARK -64
|
|
|
|
|
#define MENU_BG_SHADE_BRIGHT 64
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* draws a box size (x,y) */
|
|
|
|
|
void
|
|
|
|
|
draw_menubox (int x, int y)
|
|
|
|
|
{
|
|
|
|
@ -356,4 +356,104 @@ menu_displaymessage (char *title, char *text)
|
|
|
|
|
#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
|
|
|
|
|
selected - Selected file in the list
|
|
|
|
|
*/
|
|
|
|
|
int menu_dir_draw (char *title, _direntry *dirstart, int start, int selected) {
|
|
|
|
|
_direntry *de = dirstart;
|
|
|
|
|
int maxlen = 0;
|
|
|
|
|
SDL_Rect wnd;
|
|
|
|
|
|
|
|
|
|
/* look for the longest name */
|
|
|
|
|
for (; de != NULL; de = de->next)
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
draw_menubox (wnd.w, wnd.h);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/* get the directory list and count the numbers */
|
|
|
|
|
destart = s_getdir (path);
|
|
|
|
|
destart = s_dirfilter (destart, dirflags);
|
|
|
|
|
for (max = 0, de = destart; de != NULL; de = de->next)
|
|
|
|
|
max++;
|
|
|
|
|
if (max <= 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
while (done == 0 || (done == 1 && keypressed == 1)) {
|
|
|
|
|
/* do the network loop if we have to */
|
|
|
|
|
listend = menu_dir_draw (title, destart, liststart, sel);
|
|
|
|
|
|
|
|
|
|
if (bman.gametype == GT_multi && bman.sock != -1)
|
|
|
|
|
network_loop ();
|
|
|
|
|
|
|
|
|
|
if (SDL_PollEvent (&event) != 0)
|
|
|
|
|
switch (event.type) {
|
|
|
|
|
case (SDL_QUIT):
|
|
|
|
|
sel = -1;
|
|
|
|
|
bman.state = GS_quit;
|
|
|
|
|
done = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* keyboard handling */
|
|
|
|
|
keys = SDL_GetKeyState (NULL);
|
|
|
|
|
if (keys[SDLK_DOWN] && event.type == SDL_KEYDOWN && keypressed == 0) {
|
|
|
|
|
keypressed = 1;
|
|
|
|
|
sel++;
|
|
|
|
|
if (!(listend)) /* if we can move this list down */
|
|
|
|
|
liststart++;
|
|
|
|
|
if (sel >= max) {
|
|
|
|
|
liststart = 0;
|
|
|
|
|
sel = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (keys[SDLK_UP] && event.type == SDL_KEYDOWN && keypressed == 0) {
|
|
|
|
|
keypressed = 1;
|
|
|
|
|
sel--;
|
|
|
|
|
if (liststart > 0)
|
|
|
|
|
liststart--;
|
|
|
|
|
if (sel < 0) {
|
|
|
|
|
sel = max - 1;
|
|
|
|
|
if (sel > (DIRSCRMAX/2))
|
|
|
|
|
liststart = sel - (DIRSCRMAX/2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (keys[SDLK_ESCAPE] && event.type == SDL_KEYDOWN) {
|
|
|
|
|
keypressed = 1;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (!keys[SDLK_ESCAPE] && event.type == SDL_KEYUP)
|
|
|
|
|
keypressed = 0;
|
|
|
|
|
|
|
|
|
|
if (keys[SDLK_RETURN] && event.type == SDL_KEYDOWN) {
|
|
|
|
|
done = 1;
|
|
|
|
|
keypressed = 1;
|
|
|
|
|
}
|
|
|
|
|
if (!keys[SDLK_RETURN] && event.type == SDL_KEYUP)
|
|
|
|
|
keypressed = 0;
|
|
|
|
|
|
|
|
|
|
s_delay (100);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
#undef DIRSCRMAX
|
|
|
|
|