add animated inlined images for console text

Images are stored in packages/misc/igraph/*.png and loaded during game
start. Filenames consist of the image shorthand (mnemonic) and optional
frame times, separated by "_". Keep in mind, media file names may only
contain letters, digits and "_-.()".

All texts displayed in the game console are scanned for mnemonics prefixed
with ":". All found matches are replaced by the image.

The images are displayed as squares with width and height the same as the
regular font height. To create animations, put several square images side
by side into the file. For example, a 128x32 image is interpreted as four
frames. Frame duration is encoded in the filename, so, for example the file
"nop_1000_200_100.png" shows the first frame for 1000 milliseconds, the
second frame for 200 msec and the third (as the rest) for 100 msec.

Igraphs "1" to "9" are hardcoded and can be manually encoded in menu texts.
Use the new escape code "\i" plus the number of the image: "\i\1".."\i\9".
Other images can be used in menus as well, but the codes have to be fetched
by getigraph.

new commands:

  updateigraphs

    Checks for new files in packages/misc/igraph. Only necessary, if new
    files are added during the game - for example, by mod package download.

  getigraph <mnemonic>

    Returns an encoded string to display an image outside the console, or
    an empty string, if the mnemonic was not found.

new parameters:

  igraphsize 80..300 (default 120)

    scales the images (in percent)

  igraphsizehardcoded 80..160 (default 106)

    scales the hardcoded images "1".."9" (in percent)

  igraphanimate 0..1 (default 1)

    if 0, only the first frame of every image is displayed

  igraphdefaultframetime 5..2000 (default 200)

    used for images with multiple frames but no frame duration specified
    in the filename

  hideigraphs 0..1 (default 0)

    if 1, no new images will be shown in the console

DOCREF updateigraphs getigraph igraphsizehardcoded
DOCREF igraphsize igraphanimate igraphdefaultframetime hideigraphs
This commit is contained in:
ac-stef
2017-05-28 23:29:06 +02:00
parent 4e77b91c0e
commit 5e20a2343b
13 changed files with 206 additions and 21 deletions
+6
View File
@@ -287,6 +287,11 @@ char *filtertext(char *dst, const char *src, int flags, int len)
}
pass = true;
}
if(c == '\1')
{ // always filter encoded igraphs
if(src[1]) ++src;
continue;
}
if(mapname && !isalnum(c) && !strchr("_-./\\", c)) continue;
if(isspace(c))
{
@@ -326,6 +331,7 @@ void filterrichtext(char *dst, const char *src, int len)
{
case '\0': --src; continue;
case 'f': c = '\f'; break;
case 'i': c = '\1'; break;
case 'a': c = '\a'; break;
case 't': c = '\t'; break;
case 'n': c = '\n'; break;