clean up loadcrosshair
* use the same list of gun names for all occasions * switched syntax, so that argument completion will work * support old syntax, so old config files will work * fix path handling by disallowing paths altogether ;) DOCREF loadcrosshair
This commit is contained in:
@@ -86,6 +86,7 @@ looplist [
|
||||
burstshots weapons
|
||||
team teamnames
|
||||
addpunct punctuations // the command addpunct actually wants the punctuation name as second argument, but we can't do that. sry.
|
||||
loadcrosshair crosshairnames
|
||||
] [ cmd options ] [ listcomplete $cmd (listoptions $options)
|
||||
]
|
||||
|
||||
|
||||
@@ -1414,13 +1414,9 @@ void writecfg()
|
||||
f->printf("// automatically written on exit, DO NOT MODIFY\n// delete this file to have defaults.cfg overwrite these settings\n// modify settings in game, or put settings in autoexec.cfg to override anything\n\n");
|
||||
f->printf("// basic settings\n\n");
|
||||
f->printf("name \"%s\"\n", player1->name);
|
||||
extern const char *crosshairnames[CROSSHAIR_NUM];
|
||||
extern Texture *crosshairs[CROSSHAIR_NUM];
|
||||
loopi(CROSSHAIR_NUM) if(crosshairs[i] && crosshairs[i]!=notexture)
|
||||
loopi(CROSSHAIR_NUM) if(crosshairs[i] && crosshairs[i] != notexture)
|
||||
{
|
||||
const char *fname = crosshairs[i]->name+strlen("packages/crosshairs/");
|
||||
if(i==CROSSHAIR_DEFAULT) f->printf("loadcrosshair %s\n", fname);
|
||||
else f->printf("loadcrosshair %s %s\n", fname, crosshairnames[i]);
|
||||
f->printf("loadcrosshair %s %s\n", crosshairnames[i], behindpath(crosshairs[i]->name));
|
||||
}
|
||||
extern int lowfps, highfps;
|
||||
f->printf("fpsrange %d %d\n", lowfps, highfps);
|
||||
@@ -1655,8 +1651,8 @@ COMMAND(getscrext, "");
|
||||
|
||||
void listoptions(char *s)
|
||||
{
|
||||
const char *optionnames[] = { "entities", "ents", "weapons", "teamnames", "teamnames-abbrv", "punctuations", "" };
|
||||
const char **optionlists[] = { optionnames, entnames + 1, entnames + 1, gunnames, teamnames, teamnames_s, punctnames };
|
||||
const char *optionnames[] = { "entities", "ents", "weapons", "teamnames", "teamnames-abbrv", "punctuations", "crosshairnames", "" };
|
||||
const char **optionlists[] = { optionnames, entnames + 1, entnames + 1, gunnames, teamnames, teamnames_s, punctnames, crosshairnames };
|
||||
const char **listp = optionlists[getlistindex(s, optionnames, true, -1) + 1];
|
||||
int num = 0;
|
||||
while(listp[num] && listp[num][0]) num++;
|
||||
|
||||
+5
-2
@@ -1062,9 +1062,12 @@ int main(int argc, char **argv)
|
||||
if(bootclientlog) cvecprintf(*bootclientlog, "######## start logging: %s\n", timestring(true));
|
||||
|
||||
const char *initmap = rndmapname();
|
||||
loopi(NUMGUNS) gunnames[i] = guns[i].modelname;
|
||||
loopi(NUMGUNS) crosshairnames[i] = gunnames[i] = guns[i].modelname;
|
||||
gunnames[GUN_AKIMBO] = "akimbo";
|
||||
gunnames[NUMGUNS] = "";
|
||||
crosshairnames[CROSSHAIR_DEFAULT] = "default";
|
||||
crosshairnames[CROSSHAIR_TEAMMATE] = "teammate";
|
||||
crosshairnames[CROSSHAIR_SCOPE] = "scope";
|
||||
crosshairnames[CROSSHAIR_NUM] = gunnames[NUMGUNS] = "";
|
||||
|
||||
pushscontext(IEXC_CFG);
|
||||
|
||||
|
||||
+14
-20
@@ -275,26 +275,6 @@ extern void drawscope(bool preload = false);
|
||||
extern float dynfov();
|
||||
extern void damageblend(int n);
|
||||
|
||||
enum
|
||||
{
|
||||
CROSSHAIR_DEFAULT = 0,
|
||||
CROSSHAIR_TEAMMATE,
|
||||
CROSSHAIR_SCOPE,
|
||||
CROSSHAIR_KNIFE,
|
||||
CROSSHAIR_PISTOL,
|
||||
CROSSHAIR_CARBINE,
|
||||
CROSSHAIR_SHOTGUN,
|
||||
CROSSHAIR_SMG,
|
||||
CROSSHAIR_SNIPER,
|
||||
CROSSHAIR_AR,
|
||||
CROSSHAIR_CPISTOL,
|
||||
CROSSHAIR_GRENADES,
|
||||
CROSSHAIR_AKIMBO,
|
||||
CROSSHAIR_NUM,
|
||||
};
|
||||
|
||||
extern void drawcrosshair(playerent *p, int n, struct color *c = NULL, float size = -1.0f);
|
||||
|
||||
// shadow
|
||||
extern bool addshadowbox(const vec &bbmin, const vec &bbmax, const vec &extrude, const glmatrixf &mat);
|
||||
extern void drawstencilshadows();
|
||||
@@ -334,6 +314,20 @@ static inline Texture *lookupworldtexture(int tex, bool trydl = true)
|
||||
extern float skyfloor;
|
||||
extern void draw_envbox(int fogdist);
|
||||
|
||||
// renderhud
|
||||
enum
|
||||
{
|
||||
CROSSHAIR_DEFAULT = NUMGUNS,
|
||||
CROSSHAIR_TEAMMATE,
|
||||
CROSSHAIR_SCOPE,
|
||||
CROSSHAIR_NUM
|
||||
};
|
||||
|
||||
extern const char *crosshairnames[];
|
||||
extern Texture *crosshairs[];
|
||||
extern void drawcrosshair(playerent *p, int n, struct color *c = NULL, float size = -1.0f);
|
||||
|
||||
// client
|
||||
extern int autodownload;
|
||||
extern void setupcurl();
|
||||
extern bool requirepackage(int type, const char *path);
|
||||
|
||||
+21
-20
@@ -241,39 +241,40 @@ void drawscope(bool preload)
|
||||
glEnable(GL_BLEND);
|
||||
}
|
||||
|
||||
const char *crosshairnames[CROSSHAIR_NUM] = { "default", "teammate", "scope", "knife", "pistol", "carbine", "shotgun", "smg", "sniper", "ar", "cpistol", "grenades", "akimbo" };
|
||||
const char *crosshairnames[CROSSHAIR_NUM + 1]; // filled in main.cpp
|
||||
Texture *crosshairs[CROSSHAIR_NUM] = { NULL }; // weapon specific crosshairs
|
||||
|
||||
Texture *loadcrosshairtexture(const char *c)
|
||||
{
|
||||
defformatstring(p)("packages/crosshairs/%s", c);
|
||||
defformatstring(p)("packages/crosshairs/%s", behindpath(c));
|
||||
Texture *crosshair = textureload(p, 3);
|
||||
if(crosshair==notexture) crosshair = textureload("packages/crosshairs/default.png", 3);
|
||||
return crosshair;
|
||||
}
|
||||
|
||||
void loadcrosshair(char *c, char *name)
|
||||
void loadcrosshair(char *type, char *filename)
|
||||
{
|
||||
if (strcmp(name, "") == 0 || strcmp(name, "all") == 0)
|
||||
{
|
||||
for (int i = 0; i < CROSSHAIR_NUM; i++)
|
||||
{
|
||||
if (i == CROSSHAIR_TEAMMATE || i == CROSSHAIR_SCOPE) continue;
|
||||
crosshairs[i] = loadcrosshairtexture(c);
|
||||
}
|
||||
return;
|
||||
int index = 0;
|
||||
if(strchr(type, '.'))
|
||||
{ // old syntax "loadcrosshair filename type", remove this in 2020
|
||||
const char *oldcrosshairnames[CROSSHAIR_NUM + 1] = { "default", "teammate", "scope", "knife", "pistol", "carbine", "shotgun", "smg", "sniper", "ar", "cpistol", "grenades", "akimbo", "" };
|
||||
index = getlistindex(filename, oldcrosshairnames, false, 0);
|
||||
if(index > 2) index -= 3;
|
||||
else index += NUMGUNS;
|
||||
filename = type;
|
||||
}
|
||||
|
||||
int n = -1;
|
||||
|
||||
for (int i = 0; i < CROSSHAIR_NUM; i++)
|
||||
else
|
||||
{ // new syntax with proper gun names
|
||||
index = getlistindex(type, crosshairnames, false, CROSSHAIR_DEFAULT);
|
||||
}
|
||||
if(!crosshairs[CROSSHAIR_DEFAULT] && index == CROSSHAIR_DEFAULT)
|
||||
{
|
||||
if(strcmp(crosshairnames[i], name) == 0) { n = i; break; }
|
||||
loopi(CROSSHAIR_NUM) if(!crosshairs[i]) crosshairs[i] = loadcrosshairtexture(filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
crosshairs[index] = loadcrosshairtexture(filename);
|
||||
}
|
||||
|
||||
if (n < 0 || n >= CROSSHAIR_NUM) return;
|
||||
|
||||
crosshairs[n] = loadcrosshairtexture(c);
|
||||
}
|
||||
|
||||
COMMAND(loadcrosshair, "ss");
|
||||
|
||||
@@ -922,7 +922,7 @@ void weapon::onselecting()
|
||||
}
|
||||
|
||||
void weapon::renderhudmodel() { renderhudmodel(owner->lastaction); }
|
||||
void weapon::renderaimhelp(bool teamwarning) { drawcrosshair(owner, teamwarning ? CROSSHAIR_TEAMMATE : owner->weaponsel->type + 3); }
|
||||
void weapon::renderaimhelp(bool teamwarning) { drawcrosshair(owner, teamwarning ? CROSSHAIR_TEAMMATE : owner->weaponsel->type); }
|
||||
int weapon::dynspread() { return info.spread; }
|
||||
float weapon::dynrecoil() { return info.recoil; }
|
||||
bool weapon::selectable() { return this != owner->weaponsel && owner->state == CS_ALIVE && !owner->weaponchanging; }
|
||||
|
||||
Reference in New Issue
Block a user