add optional pre-access function for SVARs
allows a SVAR to be assembled when needed also: * mapmsg is now a SVAR * getmapmsg was removed (now: $mapmsg) * new editsvar script to edit any SVAR in the console buffer * nonfunctional menu removed DOCREF mapmsg getmapmsg editsvar
This commit is contained in:
+5
-11
@@ -131,7 +131,8 @@ newmenu [Map operations]
|
||||
menuitem (_ [Newmap (128x128 cubes - recommended)]) [ newmap 7 ]
|
||||
menuitem (_ [Newmap (256x256 cubes)]) [ newmap 8 ]
|
||||
menuitem (_ [Increase mapsize (2x)]) [ mapenlarge; echo The map size has been increased by 2. However, the new space is solid. To utilize it, you will need to turn it into non-solid space, by selecting it and pressing G. ]
|
||||
menuitem (_ [Create/edit a map message]) menumapmsg
|
||||
//menuitem (_ [Edit map message]) [ showmenu [Edit map message] ]
|
||||
menuitem (_ [Edit map message]) editmapmsg
|
||||
menuitem (_ [Change waterlevel]) [ saycommand [/waterlevel ] ]
|
||||
menuitem (_ [Change watercolour]) [ showmenu [Water colour] ]
|
||||
menuitem (_ [Generate a random watercolour]) genwc
|
||||
@@ -146,17 +147,10 @@ menuitemslider (_ [Select only these entities: ]) 0 15 "$_closestenttypestatus"
|
||||
// "closestenttype" slider...
|
||||
_closestentslider = [ closestenttype (at ["" light playerstart pistol ammobox grenades health armour akimbo mapmodel ladder ctf-flag sound clip helmet plclip] $arg1); _closestenttypestatus = $arg1 ]
|
||||
|
||||
// Map-message edit/creation menu
|
||||
const menumapmsg [ if (strcmp (getmapmsg) [Untitled Map by Unknown]) [ showmenu [Create a map message] ] [ showmenu [Edit a map message] ] ]
|
||||
|
||||
newmenu [Create a map message]
|
||||
// FIXME: menu can be removed, if editmapmsg is used
|
||||
newmenu [Edit map message]
|
||||
menuinit [ menumapmsgtext = [] ]
|
||||
menuitemtextinput (_ [Enter your map message: ]) [] [ menumapmsgtext = $arg1 ] [] 256
|
||||
menuitem (concatword (c 2) [ ] "[ OK ]") [ mapmsg $menumapmsgtext ]
|
||||
|
||||
newmenu [Edit a map message]
|
||||
menuinit [ menumapmsgtext = [] ]
|
||||
menuitemtextinput (_ [Edit your map message: ]) getmapmsg [ menumapmsgtext = $arg1 ] [] 256
|
||||
menuitemtextinput (_ [Edit your map message: ]) "result $mapmsg" [ menumapmsgtext = $arg1 ] [] 256
|
||||
menuitem (concatword (c 2) [ ] "[ OK ]") [ mapmsg $menumapmsgtext ]
|
||||
|
||||
redw = 1; greenw = 1; bluew = 1
|
||||
|
||||
+2
-1
@@ -68,7 +68,8 @@ const gibsgore [
|
||||
// "fullscreenscript" command:
|
||||
// This command allows swapping of fullscreen mode to be bound to a key.
|
||||
const fullscreenscript [ fullscreen (! $fullscreen) ]
|
||||
const editmapmsg [ saycommand (concat "/mapmsg" (addpunct (getmapmsg))) ]
|
||||
const editsvar [ inputcommand $$arg1 (concatword $arg1 " $" cmdbuf) (concatword "edit " $arg1 :) ]
|
||||
const editmapmsg [ editsvar mapmsg ]
|
||||
const return [ result $arg1 ]
|
||||
const run [ exec (concatword config/ $arg1 .cfg) ]
|
||||
|
||||
|
||||
+11
-6
@@ -182,10 +182,10 @@ float fvariable(const char *name, float minval, float cur, float maxval, float *
|
||||
return cur;
|
||||
}
|
||||
|
||||
char *svariable(const char *name, const char *cur, char **storage, void (*fun)(), bool persist)
|
||||
char *svariable(const char *name, const char *cur, char **storage, void (*fun)(), void (*getfun)(), bool persist)
|
||||
{
|
||||
if(!idents) idents = new hashtable<const char *, ident>;
|
||||
ident v(ID_SVAR, name, storage, fun, persist, IEXC_CORE);
|
||||
ident v(ID_SVAR, name, storage, fun, getfun, persist, IEXC_CORE);
|
||||
idents->access(name, v);
|
||||
return newstring(cur);
|
||||
}
|
||||
@@ -229,7 +229,7 @@ void modifyvar(const char *name, int arg, char op)
|
||||
{
|
||||
case ID_VAR: val = *id->storage.i; break;
|
||||
case ID_FVAR: val = int(*id->storage.f); break;
|
||||
case ID_SVAR: val = ATOI(*id->storage.s); break;
|
||||
case ID_SVAR: { { if(id->getfun) ((void (__cdecl *)())id->getfun)(); } val = ATOI(*id->storage.s); break; }
|
||||
case ID_ALIAS: val = ATOI(id->action); break;
|
||||
}
|
||||
switch(op)
|
||||
@@ -266,7 +266,7 @@ void modifyfvar(const char *name, float arg, char op)
|
||||
{
|
||||
case ID_VAR: val = *id->storage.i; break;
|
||||
case ID_FVAR: val = *id->storage.f; break;
|
||||
case ID_SVAR: val = atof(*id->storage.s); break;
|
||||
case ID_SVAR: { { if(id->getfun) ((void (__cdecl *)())id->getfun)(); } val = atof(*id->storage.s); break; }
|
||||
case ID_ALIAS: val = atof(id->action); break;
|
||||
}
|
||||
switch(op)
|
||||
@@ -336,6 +336,7 @@ void _getalias(char *name)
|
||||
result(o);
|
||||
break;
|
||||
case ID_SVAR:
|
||||
if(id->getfun) ((void (__cdecl *)())id->getfun)();
|
||||
formatstring(o)("%s", *id->storage.s);
|
||||
result(o);
|
||||
break;
|
||||
@@ -404,7 +405,7 @@ char *lookup(char *n) // find value of ident reference
|
||||
{
|
||||
case ID_VAR: { string t; itoa(t, *id->storage.i); return exchangestr(n, t); }
|
||||
case ID_FVAR: return exchangestr(n, floatstr(*id->storage.f));
|
||||
case ID_SVAR: return exchangestr(n, *id->storage.s);
|
||||
case ID_SVAR: { { if(id->getfun) ((void (__cdecl *)())id->getfun)(); } return exchangestr(n, *id->storage.s); }
|
||||
case ID_ALIAS: return exchangestr(n, id->action);
|
||||
}
|
||||
conoutf("unknown alias lookup: %s", n+1);
|
||||
@@ -666,7 +667,11 @@ char *executeret(const char *p) // all evaluation hap
|
||||
break;
|
||||
|
||||
case ID_SVAR: // game defined variables
|
||||
if(!w[1][0]) conoutf(strchr(*id->storage.s, '"') ? "%s = [%s]" : "%s = \"%s\"", c, *id->storage.s); // var with no value just prints its current value
|
||||
if(!w[1][0])
|
||||
{
|
||||
if(id->getfun) ((void (__cdecl *)())id->getfun)();
|
||||
conoutf(strchr(*id->storage.s, '"') ? "%s = [%s]" : "%s = \"%s\"", c, *id->storage.s); // var with no value just prints its current value
|
||||
}
|
||||
else
|
||||
{
|
||||
*id->storage.s = exchangestr(*id->storage.s, newstring(w[1]));
|
||||
|
||||
+19
-14
@@ -34,42 +34,45 @@ struct ident
|
||||
identstack *stack; // ID_ALIAS
|
||||
};
|
||||
const char *sig; // command signature
|
||||
char *action, *executing; // ID_ALIAS
|
||||
char *action; // ID_ALIAS
|
||||
union
|
||||
{
|
||||
void (*getfun)(); // ID_SVAR (called /before/ reading the value string, as a chance for last-minute updates)
|
||||
char *executing; // ID_ALIAS
|
||||
};
|
||||
short context;
|
||||
bool persist;
|
||||
|
||||
int context;
|
||||
|
||||
|
||||
ident() {}
|
||||
|
||||
// ID_VAR
|
||||
ident(int type, const char *name, int minval, int maxval, int *i, void (*fun)(), bool persist, int context)
|
||||
: type(type), name(name), isconst(false), minval(minval), maxval(maxval), fun(fun),
|
||||
sig(NULL), action(NULL), executing(NULL), persist(persist), context(context)
|
||||
sig(NULL), action(NULL), executing(NULL), context(context), persist(persist)
|
||||
{ storage.i = i; }
|
||||
|
||||
// ID_FVAR
|
||||
ident(int type, const char *name, float minval, float maxval, float *f, void (*fun)(), bool persist, int context)
|
||||
: type(type), name(name), isconst(false), minvalf(minval), maxvalf(maxval), fun(fun),
|
||||
sig(NULL), action(NULL), executing(NULL), persist(persist), context(context)
|
||||
sig(NULL), action(NULL), executing(NULL), context(context), persist(persist)
|
||||
{ storage.f = f; }
|
||||
|
||||
// ID_SVAR
|
||||
ident(int type, const char *name, char **s, void (*fun)(), bool persist, int context)
|
||||
ident(int type, const char *name, char **s, void (*fun)(), void (*getfun)(), bool persist, int context)
|
||||
: type(type), name(name), isconst(false), minval(0), maxval(0), fun(fun),
|
||||
sig(NULL), action(NULL), executing(NULL), persist(persist), context(context)
|
||||
sig(NULL), action(NULL), getfun(getfun), context(context), persist(persist)
|
||||
{ storage.s = s; }
|
||||
|
||||
// ID_ALIAS
|
||||
ident(int type, const char *name, char *action, bool persist, int context)
|
||||
: type(type), name(name), isconst(false), minval(0), maxval(0), stack(0),
|
||||
sig(NULL), action(action), executing(NULL), persist(persist), context(context)
|
||||
sig(NULL), action(action), executing(NULL), context(context), persist(persist)
|
||||
{ storage.i = NULL; }
|
||||
|
||||
// ID_COMMAND
|
||||
ident(int type, const char *name, void (*fun)(), const char *sig, int context)
|
||||
: type(type), name(name), isconst(false), minval(0), maxval(0), fun(fun),
|
||||
sig(sig), action(NULL), executing(NULL), persist(false), context(context)
|
||||
sig(sig), action(NULL), executing(NULL), context(context), persist(false)
|
||||
{ storage.i = NULL; }
|
||||
};
|
||||
|
||||
@@ -92,10 +95,12 @@ enum { IEXC_CORE = 0, IEXC_CFG, IEXC_PROMPT, IEXC_MAPCFG, IEXC_MDLCFG, IEXC_NUM
|
||||
#define FVARF(name, min, cur, max, body) extern float name; void var_##name() { body; } float name = fvariable(#name, min, cur, max, &name, var_##name, false)
|
||||
#define FVARFP(name, min, cur, max, body) extern float name; void var_##name() { body; } float name = fvariable(#name, min, cur, max, &name, var_##name, true)
|
||||
|
||||
#define SVARP(name, cur) char *name = svariable(#name, cur, &name, NULL, true)
|
||||
#define SVAR(name, cur) char *name = svariable(#name, cur, &name, NULL, false)
|
||||
#define SVARF(name, cur, body) extern char *name; void var_##name() { body; } char *name = svariable(#name, cur, &name, var_##name, false)
|
||||
#define SVARFP(name, cur, body) extern char *name; void var_##name() { body; } char *name = svariable(#name, cur, &name, var_##name, true)
|
||||
// SVARs are represented by "char *name" which has to be a valid "newstring()" all the time
|
||||
#define SVARP(name, cur) char *name = svariable(#name, cur, &name, NULL, NULL, true)
|
||||
#define SVAR(name, cur) char *name = svariable(#name, cur, &name, NULL, NULL, false)
|
||||
#define SVARF(name, cur, body) extern char *name; void var_##name() { body; } char *name = svariable(#name, cur, &name, var_##name, NULL, false)
|
||||
#define SVARFP(name, cur, body) extern char *name; void var_##name() { body; } char *name = svariable(#name, cur, &name, var_##name, NULL, true)
|
||||
#define SVARFF(name, getb, checkb) extern char *name; void var_get##name() { getb; } void var_check##name() { checkb; } char *name = svariable(#name, "", &name, var_check##name, var_get##name, false)
|
||||
|
||||
#define ATOI(s) strtol(s, NULL, 0) // supports hexadecimal numbers
|
||||
|
||||
|
||||
+8
-13
@@ -315,23 +315,18 @@ void inputcommand(char *init, char *action, char *prompt)
|
||||
}
|
||||
COMMAND(inputcommand, "sss");
|
||||
|
||||
void mapmsg(char *s)
|
||||
{
|
||||
SVARFF(mapmsg,
|
||||
{ // read mapmsg
|
||||
hdr.maptitle[127] = '\0';
|
||||
mapmsg = exchangestr(mapmsg, hdr.maptitle);
|
||||
},
|
||||
{ // set new mapmsg
|
||||
string text;
|
||||
filterrichtext(text, s);
|
||||
filterrichtext(text, mapmsg);
|
||||
filtertext(text, text, FTXT__MAPMSG);
|
||||
copystring(hdr.maptitle, text, 128);
|
||||
if(editmode) unsavededits++;
|
||||
}
|
||||
COMMAND(mapmsg, "s");
|
||||
|
||||
void getmapmsg(void)
|
||||
{
|
||||
string text;
|
||||
copystring(text, hdr.maptitle, 128);
|
||||
result(text);
|
||||
}
|
||||
COMMAND(getmapmsg, "");
|
||||
});
|
||||
|
||||
#if !defined(WIN32) && !defined(__APPLE__)
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
+2
-1
@@ -815,9 +815,10 @@ extern void conoutf(const char *s, ...);
|
||||
|
||||
// command
|
||||
extern bool per_idents, neverpersist;
|
||||
extern char *exchangestr(char *o, const char *n);
|
||||
extern int variable(const char *name, int min, int cur, int max, int *storage, void (*fun)(), bool persist);
|
||||
extern float fvariable(const char *name, float min, float cur, float max, float *storage, void (*fun)(), bool persist);
|
||||
extern char *svariable(const char *name, const char *cur, char **storage, void (*fun)(), bool persist);
|
||||
extern char *svariable(const char *name, const char *cur, char **storage, void (*fun)(), void (*getfun)(), bool persist);
|
||||
extern void setvar(const char *name, int i, bool dofunc = false);
|
||||
extern void setfvar(const char *name, float f, bool dofunc = false);
|
||||
extern void setsvar(const char *name, const char *str, bool dofunc = false);
|
||||
|
||||
Reference in New Issue
Block a user