Skip to content
Permalink
Browse files

Add custom description of demos

Custom description is displayed in "Watching demo" and "Play demo" menu.
  • Loading branch information...
aurhat committed Nov 29, 2014
1 parent a957ae4 commit fa483e1fcdf704ff98a0951cef37612d2cbc019b
Showing with 19 additions and 2 deletions.
  1. +1 −0 config/menus.cfg
  2. +8 −1 source/src/command.cpp
  3. +10 −1 source/src/menus.cpp
@@ -59,6 +59,7 @@ newmenu [Watching demo]
menuitem (_ [Stop watching demo]) stopdemo
menuitem (_ [Restart demo]) [ demo $curdemofile ]
menuitem (_ [Watch other demo]) [ stopdemo; closemenu [Watching demo]; showmenu [Play demo] ]
menuitemtextinput (_ [Custom description: ]) [ getalias (concatword "demodesc_" $curdemofile) ] [ alias (concatword "demodesc_" $curdemofile) $arg1 ] [] 50
menuitem [] -1
menuitem (concatword (c 4) (_ [Main menu...])) [ closemenu [Watching demo]; showmenu main ]
menuitem (concatword (c 3) (_ [Quit AssaultCube])) savequit
@@ -1478,7 +1478,14 @@ void writecfg()
writebinds(f);
f->printf("\n// aliases\n\n");
enumerate(*idents, ident, id,
if(id.type==ID_ALIAS && id.persist && id.action[0])
if(id.type==ID_ALIAS && id.persist && id.action[0] && strncmp(id.name, "demodesc_", 9))
{
f->printf("%s = [%s]\n", id.name, id.action);
}
);
f->printf("\n// demo descriptions\n\n");
enumerate(*idents, ident, id,
if(id.type==ID_ALIAS && id.persist && id.action[0] && !strncmp(id.name, "demodesc_", 9) && id.action)
{
f->printf("%s = [%s]\n", id.name, id.action);
}
@@ -15,7 +15,7 @@ char *getfiledesc(const char *dir, const char *name, const char *ext)
if(!browsefiledesc || !dir || !name || !ext) return NULL;
defformatstring(fn)("%s/%s.%s", dir, name, ext);
path(fn);
string text;
string text, demodescalias;
if(!strcmp(ext, "dmo"))
{
stream *f = opengzfile(fn, "rb");
@@ -33,6 +33,15 @@ char *getfiledesc(const char *dir, const char *name, const char *ext)
}
formatstring(text)("%s%s", tag, hdr.desc);
text[DHDR_DESCCHARS - 1] = '\0';
formatstring(demodescalias)("demodesc_%s", name);
const char *customdesc = getalias(demodescalias);
if(customdesc)
{
int textlen = strlen(text);
concatformatstring(text, " \n\f4(Description: \f0%s\f4)", customdesc);
ASSERT(MAXSTRLEN > 2 * DHDR_DESCCHARS);
text[textlen + DHDR_DESCCHARS - 1] = '\0';
}
return newstring(text);
}
else if(!strcmp(ext, "cgz"))

0 comments on commit fa483e1

Please sign in to comment.
You can’t perform that action at this time.