simplified crosshair setup - only default, teammate, scope crosshairs

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@3457 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lee Salzman
2008-11-08 21:02:47 +00:00
parent c86bec4250
commit 6f98fe644e
7 changed files with 52 additions and 25 deletions
+2 -1
View File
@@ -3,7 +3,8 @@
name "unarmed" // Change your name!
loadcrosshair default.png // Choose another crosshair, see packages/misc/crosshairs/
loadcrosshair red_dot.png 4 // scope crosshair
loadcrosshair teammate.png teammate // teammate crosshair
loadcrosshair red_dot.png scope // scope crosshair
skin 0 // Change your look.
autoreload 1 // Reload the guns automatically by default.
+4
View File
@@ -356,7 +356,11 @@ menuitemcheckbox " Crosshair team-sign " "$crosshairteamsign" "crosshairteamsi
menuitem "" -1
menuitemslider "Crosshair size: " 0 50 "$crosshairsize" 5 "" "crosshairsize $arg1"
menuitem "Change crosshair... " "showmenu Crosshairs"
menuitem "Change scope crosshair... " "showmenu [Scope crosshairs]"
newmenu "Crosshairs"
menudirlist "packages/misc/crosshairs" "png" "loadcrosshair (concatword $arg1 .png)" 1
newmenu "Scope crosshairs"
menudirlist "packages/misc/crosshairs" "png" "loadcrosshair (concatword $arg1 .png) scope" 1

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

+8 -3
View File
@@ -858,9 +858,14 @@ void writecfg()
if(!f) return;
fprintf(f, "// 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");
fprintf(f, "name %s\n", player1->name);
extern Texture *defaultcrosshair, *crosshairs[NUMGUNS];
fprintf(f, "loadcrosshair %s\n", defaultcrosshair->name+strlen("packages/misc/crosshairs/"));
loopi(NUMGUNS) if(crosshairs[i]) fprintf(f, "loadcrosshair %s %d\n", crosshairs[i]->name+strlen("packages/misc/crosshairs/"), i);
extern const char *crosshairnames[CROSSHAIR_NUM];
extern Texture *crosshairs[CROSSHAIR_NUM];
loopi(CROSSHAIR_NUM) if(crosshairs[i] && crosshairs[i]!=notexture)
{
const char *fname = crosshairs[i]->name+strlen("packages/misc/crosshairs/");
if(i==CROSSHAIR_DEFAULT) fprintf(f, "loadcrosshair %s\n", fname);
else fprintf(f, "loadcrosshair %s %s\n", fname, crosshairnames[i]);
}
extern int lowfps, highfps;
fprintf(f, "fpsrange %d %d\n", lowfps, highfps);
fprintf(f, "\n");
+10 -1
View File
@@ -231,11 +231,20 @@ extern void gl_drawframe(int w, int h, float changelod, float curfps);
extern void clearminimap();
extern void rendercursor(int x, int y, int w);
extern void renderaboveheadicon(playerent *p);
extern void drawcrosshair(playerent *p, bool showteamwarning, int weaponspecific = -1, struct color *c = NULL, float size = -1.0f);
extern void drawscope();
extern float dynfov();
extern void damageblend(int n);
enum
{
CROSSHAIR_DEFAULT = 0,
CROSSHAIR_TEAMMATE,
CROSSHAIR_SCOPE,
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();
+21 -16
View File
@@ -123,8 +123,8 @@ void drawscope()
glEnd();
}
Texture *defaultcrosshair = NULL;
Texture *crosshairs[NUMGUNS] = { NULL }; // weapon specific crosshairs
const char *crosshairnames[CROSSHAIR_NUM] = { "default", "teammate", "scope" };
Texture *crosshairs[CROSSHAIR_NUM] = { NULL }; // weapon specific crosshairs
Texture *loadcrosshairtexture(const char *c)
{
@@ -134,32 +134,37 @@ Texture *loadcrosshairtexture(const char *c)
return crosshair;
}
void loadcrosshair(char *c, char *w)
void loadcrosshair(char *c, char *name)
{
int weapon = atoi(w);
if(weapon>NUMGUNS) return;
if(weapon<0 || !w[0]) defaultcrosshair = loadcrosshairtexture(c);
else crosshairs[weapon] = loadcrosshairtexture(c);
int n = -1;
loopi(CROSSHAIR_NUM) if(!strcmp(crosshairnames[i], name)) { n = i; break; }
if(n<0)
{
n = atoi(name);
if(n<0 || n>=CROSSHAIR_NUM) return;
}
crosshairs[n] = loadcrosshairtexture(c);
}
COMMAND(loadcrosshair, ARG_2STR);
void drawcrosshair(playerent *p, bool showteamwarning, int weaponspecific, color *c, float size)
void drawcrosshair(playerent *p, int n, color *c, float size)
{
static Texture *teammatetex = NULL;
if(!teammatetex) teammatetex = textureload("packages/misc/teammate.png", 3);
if(!defaultcrosshair) defaultcrosshair = loadcrosshairtexture("default.png");
Texture *crosshair = weaponspecific>=0 && crosshairs[weaponspecific] ? crosshairs[weaponspecific] : defaultcrosshair;
Texture *crosshair = crosshairs[n];
if(!crosshair)
{
crosshair = crosshairs[CROSSHAIR_DEFAULT];
if(!crosshair) crosshair = crosshairs[CROSSHAIR_DEFAULT] = loadcrosshairtexture("default.png");
}
if(crosshair->bpp==32) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
else glBlendFunc(GL_ONE, GL_ONE);
glBindTexture(GL_TEXTURE_2D, showteamwarning ? teammatetex->id : crosshair->id);
glBindTexture(GL_TEXTURE_2D, crosshair->id);
glColor3ub(255,255,255);
if(c) glColor3f(c->r, c->g, c->b);
else if(crosshairfx)
{
if(showteamwarning) glColor3ub(255, 0, 0);
if(n==CROSSHAIR_TEAMMATE) glColor3ub(255, 0, 0);
else if(!m_osok)
{
if(p->health<=25) glColor3ub(255,0,0);
@@ -167,7 +172,7 @@ void drawcrosshair(playerent *p, bool showteamwarning, int weaponspecific, color
}
}
float s = size>0 ? size : (float)crosshairsize;
float chsize = s * (p->weaponsel->type==GUN_ASSAULT && p->weaponsel->shots > 3 ? 1.4f : 1.0f) * (showteamwarning ? 2.0f : 1.0f);
float chsize = s * (p->weaponsel->type==GUN_ASSAULT && p->weaponsel->shots > 3 ? 1.4f : 1.0f) * (n==CROSSHAIR_TEAMMATE ? 2.0f : 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2f(VIRTW/2 - chsize, VIRTH/2 - chsize);
glTexCoord2f(1, 0); glVertex2f(VIRTW/2 + chsize, VIRTH/2 - chsize);
+7 -4
View File
@@ -643,7 +643,7 @@ void weapon::onselecting()
}
void weapon::renderhudmodel() { renderhudmodel(owner->lastaction); }
void weapon::renderaimhelp(bool teamwarning) { drawcrosshair(owner, teamwarning, type); }
void weapon::renderaimhelp(bool teamwarning) { drawcrosshair(owner, teamwarning ? CROSSHAIR_TEAMMATE : CROSSHAIR_DEFAULT); }
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; }
@@ -1029,9 +1029,12 @@ void sniperrifle::renderhudmodel() { if(!scoped) weapon::renderhudmodel(); }
void sniperrifle::renderaimhelp(bool teamwarning)
{
if(scoped) drawscope();
/*if(scoped || teamwarning) */
drawcrosshair(owner, teamwarning, type, NULL, 24.0f);
if(scoped)
{
drawscope();
drawcrosshair(owner, teamwarning ? CROSSHAIR_TEAMMATE : CROSSHAIR_SCOPE, NULL, 24.0f);
}
else weapon::renderaimhelp(teamwarning);
}
void sniperrifle::setscope(bool enable) { if(this == owner->weaponsel && !reloading && owner->state == CS_ALIVE) scoped = enable; }