Allow sorting the watching-screen names by either name or idle-time. (Based slightly on a patch by Dragonizer)
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@369 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
parent
7b437cd518
commit
4c0614da1c
|
@ -325,6 +325,7 @@ void
|
|||
inprogressmenu (int gameid)
|
||||
{
|
||||
int i, menuchoice, len = 20, offset = 0, doresizewin = 0;
|
||||
dg_sortmode sortmode = SORTMODE_NONE;
|
||||
time_t ctime;
|
||||
struct dg_game **games;
|
||||
char ttyrecname[130], *replacestr = NULL, gametype[10];
|
||||
|
@ -332,6 +333,7 @@ inprogressmenu (int gameid)
|
|||
sigset_t oldmask, toblock;
|
||||
|
||||
games = populate_games (gameid, &len);
|
||||
games = sort_games (games, len, sortmode);
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
@ -374,6 +376,8 @@ inprogressmenu (int gameid)
|
|||
(time (&ctime) - games[i + offset]->idle_time) % 60);
|
||||
}
|
||||
|
||||
mvprintw (22, 1, "'s' and 'S' change sort mode (current: %s)", SORTMODE_NAME[sortmode]);
|
||||
|
||||
if (len > 0)
|
||||
mvprintw (21, 1, "(%d-%d of %d)", offset + 1, offset + i, len);
|
||||
mvaddstr (23, 1,
|
||||
|
@ -399,6 +403,13 @@ inprogressmenu (int gameid)
|
|||
case 'q': case 'Q':
|
||||
return;
|
||||
|
||||
case 's':
|
||||
if (sortmode < (NUM_SORTMODES-1)) sortmode++; else sortmode = SORTMODE_NONE;
|
||||
break;
|
||||
case 'S':
|
||||
if (sortmode > SORTMODE_NONE) sortmode--; else sortmode = (NUM_SORTMODES-1);
|
||||
break;
|
||||
|
||||
case 12: case 18: /* ^L, ^R */
|
||||
clear ();
|
||||
break;
|
||||
|
@ -453,6 +464,7 @@ inprogressmenu (int gameid)
|
|||
}
|
||||
|
||||
games = populate_games (gameid, &len);
|
||||
games = sort_games (games, len, sortmode);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,6 +74,28 @@ struct dg_globalconfig
|
|||
int allow_registration; /* allow registering new nicks */
|
||||
};
|
||||
|
||||
|
||||
/* username asc and idletime desc are most important */
|
||||
typedef enum
|
||||
{
|
||||
SORTMODE_NONE = 0,
|
||||
SORTMODE_USERNAME_ASC,
|
||||
SORTMODE_IDLETIME_DESC,
|
||||
SORTMODE_IDLETIME_ASC,
|
||||
SORTMODE_USERNAME_DESC,
|
||||
NUM_SORTMODES
|
||||
} dg_sortmode;
|
||||
|
||||
static const char *SORTMODE_NAME[] = {
|
||||
"Unsorted",
|
||||
"Username, asc",
|
||||
"Idletime, desc",
|
||||
"Idletime, asc",
|
||||
"Username, desc",
|
||||
"",
|
||||
};
|
||||
|
||||
|
||||
/* Global variables */
|
||||
extern char* config; /* file path */
|
||||
extern struct dg_config **myconfig;
|
||||
|
@ -96,6 +118,9 @@ extern void loadbanner(int game, struct dg_banner *ban);
|
|||
extern void drawbanner(unsigned int start_line, unsigned int howmany);
|
||||
extern char *dgl_format_str(int game, struct dg_user *me, char *str);
|
||||
extern struct dg_game **populate_games(int game, int *l);
|
||||
|
||||
extern struct dg_game **sort_games(struct dg_game **games, int len, dg_sortmode sortmode);
|
||||
|
||||
extern void inprogressmenu(int gameid);
|
||||
extern void change_email(void);
|
||||
extern int changepw(int dowrite);
|
||||
|
|
46
dgl-common.c
46
dgl-common.c
|
@ -111,6 +111,52 @@ dgl_format_str(int game, struct dg_user *me, char *str)
|
|||
}
|
||||
|
||||
|
||||
static int
|
||||
sort_game_username_asc(const void *g1, const void *g2)
|
||||
{
|
||||
const struct dg_game *game1 = *(const struct dg_game **)g1;
|
||||
const struct dg_game *game2 = *(const struct dg_game **)g2;
|
||||
return strcmp(game1->name, game2->name);
|
||||
}
|
||||
|
||||
static int
|
||||
sort_game_username_desc(const void *g1, const void *g2)
|
||||
{
|
||||
const struct dg_game *game1 = *(const struct dg_game **)g1;
|
||||
const struct dg_game *game2 = *(const struct dg_game **)g2;
|
||||
return strcmp(game2->name, game1->name);
|
||||
}
|
||||
|
||||
static int
|
||||
sort_game_idletime_asc(const void *g1, const void *g2)
|
||||
{
|
||||
const struct dg_game *game1 = *(const struct dg_game **)g1;
|
||||
const struct dg_game *game2 = *(const struct dg_game **)g2;
|
||||
return difftime(game1->idle_time, game2->idle_time);
|
||||
}
|
||||
|
||||
static int
|
||||
sort_game_idletime_desc(const void *g1, const void *g2)
|
||||
{
|
||||
const struct dg_game *game1 = *(const struct dg_game **)g1;
|
||||
const struct dg_game *game2 = *(const struct dg_game **)g2;
|
||||
return difftime(game2->idle_time, game1->idle_time);
|
||||
}
|
||||
|
||||
|
||||
struct dg_game **
|
||||
sort_games (struct dg_game **games, int len, dg_sortmode sortmode)
|
||||
{
|
||||
switch (sortmode) {
|
||||
case SORTMODE_USERNAME_ASC: qsort(games, len, sizeof(struct dg_game *), sort_game_username_asc); break;
|
||||
case SORTMODE_USERNAME_DESC: qsort(games, len, sizeof(struct dg_game *), sort_game_username_desc); break;
|
||||
case SORTMODE_IDLETIME_ASC: qsort(games, len, sizeof(struct dg_game *), sort_game_idletime_asc); break;
|
||||
case SORTMODE_IDLETIME_DESC: qsort(games, len, sizeof(struct dg_game *), sort_game_idletime_desc); break;
|
||||
default: ;
|
||||
}
|
||||
return games;
|
||||
}
|
||||
|
||||
struct dg_game **
|
||||
populate_games (int xgame, int *l)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue