From 148719c0f7f2e160cf2864729a14233d5731704f Mon Sep 17 00:00:00 2001 From: ac-stef Date: Wed, 10 Jun 2015 14:11:28 +0200 Subject: [PATCH] add script command for menu items with alternate fonts Also: add '\a' to the list of escaped characters and remove storage of unneeded "filename". mitemaltfont Displays a menu line with a text which may contain chars from an alternate font. altfont Name of the alternate font. text Content of menu line. Chars from the alternate font have to be marked with "\a". Alternate font chars have no width and are just rendered above the following text. Use spaces to counter that. action, hoveraction, desc Same function as with other menu lines. DOCREF menuitemaltfont --- source/src/command.cpp | 1 + source/src/menus.cpp | 15 ++++++++++----- source/src/protocol.cpp | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/source/src/command.cpp b/source/src/command.cpp index fe8fe9db..d68bc4d9 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -1464,6 +1464,7 @@ const char *escapestring(const char *s, bool force, bool noquotes) case '\n': buf.put("\\n", 2); break; case '\r': buf.put("\\n", 2); break; case '\t': buf.put("\\t", 2); break; + case '\a': buf.put("\\a", 2); break; case '\f': buf.put("\\f", 2); break; case '"': buf.put("\\\"", 2); break; case '\\': buf.put("\\\\", 2); break; diff --git a/source/src/menus.cpp b/source/src/menus.cpp index 4cf1580e..0f6629ad 100644 --- a/source/src/menus.cpp +++ b/source/src/menus.cpp @@ -291,11 +291,10 @@ VARP(hidebigmenuimages, 0, 0, 1); struct mitemimagemanual : mitemmanual { - const char *filename; Texture *image; font *altfont; - mitemimagemanual(gmenu *parent, const char *filename, const char *altfontname, char *text, char *action, char *hoveraction, color *bgcolor, const char *desc = NULL) : mitemmanual(parent, text, action, hoveraction, bgcolor, desc), filename(filename) + mitemimagemanual(gmenu *parent, const char *filename, const char *altfontname, char *text, char *action, char *hoveraction, color *bgcolor, const char *desc = NULL) : mitemmanual(parent, text, action, hoveraction, bgcolor, desc) { image = filename ? textureload(filename, 3) : NULL; altfont = altfontname ? getfont(altfontname) : NULL; @@ -365,10 +364,9 @@ struct mitemimagemanual : mitemmanual struct mitemimage : mitemimagemanual { - mitemimage(gmenu *parent, const char *filename, char *text, char *action, char *hoveraction, color *bgcolor, const char *desc = NULL) : mitemimagemanual(parent, filename, NULL, text, action, hoveraction, bgcolor, desc) {} + mitemimage(gmenu *parent, const char *filename, char *text, char *action, char *hoveraction, color *bgcolor, const char *desc = NULL, const char *altfont = NULL) : mitemimagemanual(parent, filename, altfont, text, action, hoveraction, bgcolor, desc) {} virtual ~mitemimage() { - DELETEA(filename); DELETEA(text); DELETEA(action); DELETEA(hoveraction); @@ -955,12 +953,19 @@ void menuitemimage(char *name, char *text, char *action, char *hoveraction) { if(!lastmenu) return; if(fileexists(name, "r") || findfile(name, "r") != name) - lastmenu->items.add(new mitemimage(lastmenu, newstring(name), newstring(text), action[0] ? newstring(action) : NULL, hoveraction[0] ? newstring(hoveraction) : NULL, NULL)); + lastmenu->items.add(new mitemimage(lastmenu, name, newstring(text), action[0] ? newstring(action) : NULL, hoveraction[0] ? newstring(hoveraction) : NULL, NULL)); else lastmenu->items.add(new mitemtext(lastmenu, newstring(text), newstring(action[0] ? action : text), hoveraction[0] ? newstring(hoveraction) : NULL, NULL)); } COMMAND(menuitemimage, "ssss"); +void menuitemaltfont(char *altfont, char *text, char *action, char *hoveraction, char *desc) +{ + if(!lastmenu) return; + lastmenu->items.add(new mitemimage(lastmenu, NULL, newstring(text), action[0] ? newstring(action) : NULL, hoveraction[0] ? newstring(hoveraction) : NULL, NULL, desc[0] ? newstring(desc) : NULL, altfont)); +} +COMMAND(menuitemaltfont, "sssss"); + void menuitemmapload(char *name, char *text) { if(!lastmenu) return; diff --git a/source/src/protocol.cpp b/source/src/protocol.cpp index 9efef33e..9c897a81 100644 --- a/source/src/protocol.cpp +++ b/source/src/protocol.cpp @@ -246,6 +246,7 @@ void filterrichtext(char *dst, const char *src, int len) { case '\0': --src; continue; case 'f': c = '\f'; break; + case 'a': c = '\a'; break; case 'n': c = '\n'; break; case 'x': b = 16;