Allow sorting by all of the fields in the watching-menu.
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@507 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
parent
91675def98
commit
ae11d81827
|
@ -440,16 +440,20 @@ inprogressmenu (int gameid)
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
mvaddstr (3, 1, "The following games are in progress:");
|
mvaddstr (3, 1, "The following games are in progress:");
|
||||||
|
|
||||||
|
#define dgl_sortprintw(mode, x, str) \
|
||||||
|
if (sortmode == mode) attron(title_attr); \
|
||||||
|
mvprintw(top_banner_hei,x,str); \
|
||||||
|
if (sortmode == mode) attroff(title_attr);
|
||||||
|
|
||||||
mvprintw(top_banner_hei,1," ");
|
mvprintw(top_banner_hei,1," ");
|
||||||
if (sortmode == SORTMODE_USERNAME) attron(title_attr);
|
|
||||||
mvprintw(top_banner_hei,4,"Username");
|
dgl_sortprintw(SORTMODE_USERNAME, 4, "Username")
|
||||||
if (sortmode == SORTMODE_USERNAME) attroff(title_attr);
|
dgl_sortprintw(SORTMODE_GAMENUM, 21, "Game")
|
||||||
mvprintw(top_banner_hei,21,"Game");
|
dgl_sortprintw(SORTMODE_WINDOWSIZE, 29, "Size")
|
||||||
mvprintw(top_banner_hei,29,"Size");
|
dgl_sortprintw(SORTMODE_STARTTIME, 37, "Start date & time")
|
||||||
mvprintw(top_banner_hei,37,"Start date & time");
|
dgl_sortprintw(SORTMODE_IDLETIME, 58, "Idle time")
|
||||||
if (sortmode == SORTMODE_IDLETIME) attron(title_attr);
|
|
||||||
mvprintw(top_banner_hei,58,"Idle time");
|
#undef dgl_sortprintw
|
||||||
if (sortmode == SORTMODE_IDLETIME) attroff(title_attr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < max_height; i++)
|
for (i = 0; i < max_height; i++)
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
# define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
|
# define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define dglsign(x) (x < 0 ? -1 : (x > 0 ? 1 : 0))
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
@ -146,6 +147,9 @@ typedef enum
|
||||||
{
|
{
|
||||||
SORTMODE_NONE = 0,
|
SORTMODE_NONE = 0,
|
||||||
SORTMODE_USERNAME,
|
SORTMODE_USERNAME,
|
||||||
|
SORTMODE_GAMENUM,
|
||||||
|
SORTMODE_WINDOWSIZE,
|
||||||
|
SORTMODE_STARTTIME,
|
||||||
SORTMODE_IDLETIME,
|
SORTMODE_IDLETIME,
|
||||||
NUM_SORTMODES
|
NUM_SORTMODES
|
||||||
} dg_sortmode;
|
} dg_sortmode;
|
||||||
|
@ -153,6 +157,9 @@ typedef enum
|
||||||
static const char *SORTMODE_NAME[NUM_SORTMODES] = {
|
static const char *SORTMODE_NAME[NUM_SORTMODES] = {
|
||||||
"Unsorted",
|
"Unsorted",
|
||||||
"Username",
|
"Username",
|
||||||
|
"Game",
|
||||||
|
"Windowsize",
|
||||||
|
"Starttime",
|
||||||
"Idletime"
|
"Idletime"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
39
dgl-common.c
39
dgl-common.c
|
@ -379,12 +379,51 @@ sort_game_idletime(const void *g1, const void *g2)
|
||||||
return strcasecmp(game1->name, game2->name);
|
return strcasecmp(game1->name, game2->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
sort_game_gamenum(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;
|
||||||
|
if (game2->gamenum != game1->gamenum)
|
||||||
|
return dglsign(game2->gamenum - game1->gamenum);
|
||||||
|
else
|
||||||
|
return strcasecmp(game1->name, game2->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
sort_game_windowsize(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;
|
||||||
|
if (game2->ws_col != game1->ws_col)
|
||||||
|
return dglsign(game1->ws_col - game2->ws_col);
|
||||||
|
if (game2->ws_row != game1->ws_row)
|
||||||
|
return dglsign(game1->ws_row - game2->ws_row);
|
||||||
|
return strcasecmp(game1->name, game2->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
sort_game_starttime(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;
|
||||||
|
int i = strcmp(game1->date, game2->date);
|
||||||
|
if (!i)
|
||||||
|
i = strcmp(game1->time, game2->time);
|
||||||
|
if (!i)
|
||||||
|
return strcasecmp(game1->name, game2->name);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
struct dg_game **
|
struct dg_game **
|
||||||
sort_games (struct dg_game **games, int len, dg_sortmode sortmode)
|
sort_games (struct dg_game **games, int len, dg_sortmode sortmode)
|
||||||
{
|
{
|
||||||
switch (sortmode) {
|
switch (sortmode) {
|
||||||
case SORTMODE_USERNAME: qsort(games, len, sizeof(struct dg_game *), sort_game_username); break;
|
case SORTMODE_USERNAME: qsort(games, len, sizeof(struct dg_game *), sort_game_username); break;
|
||||||
|
case SORTMODE_GAMENUM: qsort(games, len, sizeof(struct dg_game *), sort_game_gamenum); break;
|
||||||
|
case SORTMODE_WINDOWSIZE: qsort(games, len, sizeof(struct dg_game *), sort_game_windowsize); break;
|
||||||
case SORTMODE_IDLETIME: qsort(games, len, sizeof(struct dg_game *), sort_game_idletime); break;
|
case SORTMODE_IDLETIME: qsort(games, len, sizeof(struct dg_game *), sort_game_idletime); break;
|
||||||
|
case SORTMODE_STARTTIME: qsort(games, len, sizeof(struct dg_game *), sort_game_starttime); break;
|
||||||
default: ;
|
default: ;
|
||||||
}
|
}
|
||||||
return games;
|
return games;
|
||||||
|
|
|
@ -20,7 +20,8 @@ allow_new_nicks = yes
|
||||||
maxnicklen = 10
|
maxnicklen = 10
|
||||||
|
|
||||||
# Set the default watching-screen sorting mode. Can be one of
|
# Set the default watching-screen sorting mode. Can be one of
|
||||||
# "unsorted", "username" or "idletime". Unsorted is the default.
|
# "unsorted", "username", "game", "windowsize", "starttime" or "idletime".
|
||||||
|
# Unsorted is the default.
|
||||||
#sortmode = "username"
|
#sortmode = "username"
|
||||||
|
|
||||||
# Path to a prepared chroot jail.
|
# Path to a prepared chroot jail.
|
||||||
|
|
Loading…
Reference in New Issue