-
Notifications
You must be signed in to change notification settings - Fork 9
Crosshair separation #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robalni
wants to merge
8
commits into
blue-nebula:master
Choose a base branch
from
robalni:crosshair-separation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Crosshair separation #209
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3ab98eb
Make drawpointer easier to read
a4320bc
Separate cursor from crosshair functions
3ea544d
Separate cursor from crosshair variables
aba2642
Always reset crosshair in resetcamera()
32373f9
Draw crosshair behind command background
85c8d34
Don't show crosshair if compass is visible
fd2c8a9
Check pointer type first
88339ea
Remove unused variable
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -893,9 +893,9 @@ namespace hud | |
| POINTER_HAIR, POINTER_TEAM, POINTER_ZOOM, POINTER_HIT, POINTER_MAX | ||
| }; | ||
|
|
||
| const char *getpointer(int index, int weap = -1) | ||
| const char *getpointer(int pointertype, int weap = -1) | ||
| { | ||
| switch(index) | ||
| switch(pointertype) | ||
| { | ||
| case POINTER_RELATIVE: return pointertex; | ||
| case POINTER_GUI: | ||
|
|
@@ -1310,99 +1310,105 @@ namespace hud | |
| } | ||
| } | ||
|
|
||
| void drawpointer(int w, int h, int index) | ||
| static int choose_pointer_type() | ||
| { | ||
| int cs = int((index == POINTER_GUI ? cursorsize : crosshairsize)*hudsize); | ||
| float fade = index == POINTER_GUI ? cursorblend : crosshairblend; | ||
| vec c(1, 1, 1); | ||
| if(game::focus->state == CS_ALIVE && index >= POINTER_HAIR) | ||
| return hasinput() && !(!hasinput(true) || commandmillis > 0) | ||
| ? POINTER_GUI | ||
| : POINTER_NONE; | ||
| } | ||
|
|
||
| static void draw_pointer(int w, int h, int pointertype) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be great if you could use |
||
| { | ||
| if(pointertype == POINTER_NONE) return; | ||
| int size = int(cursorsize * hudsize); | ||
| float fade = cursorblend; | ||
| vec color(1, 1, 1); | ||
| int cx = int(hudwidth * cursorx); | ||
| int cy = int(hudheight * cursory); | ||
|
|
||
| if(ui_cursor_type == 2) | ||
| { | ||
| cy -= size / 2; | ||
| cx -= size / 2; | ||
| } | ||
| drawpointertex(getpointer(pointertype, game::focus->weapselect), cx, cy, size, color.r, color.g, color.b, fade*hudblend); | ||
| } | ||
|
|
||
| static int choose_crosshair_type() | ||
| { | ||
| if(!showhud || !showcrosshair || game::focus->state == CS_DEAD || !gs_playing(game::gamestate) || client::waiting() || (game::thirdpersonview(true) && game::focus != &game::player1)) | ||
| return POINTER_NONE; | ||
| else if(game::focus->state == CS_EDITING) return POINTER_EDIT; | ||
| else if(game::focus->state >= CS_SPECTATOR) return POINTER_SPEC; | ||
| else if(game::inzoom()) return POINTER_ZOOM; | ||
| else if(m_team(game::gamemode, game::mutators)) | ||
| { | ||
| if(crosshairweapons&2) c = vec::hexcolor(W(game::focus->weapselect, colour)); | ||
| if(index == POINTER_ZOOM && game::inzoom()) | ||
| vec pos = game::focus->headpos(); | ||
| gameent *d = game::intersectclosest(pos, worldpos, game::focus); | ||
| if(d && d->actortype < A_ENEMY && d->team == game::focus->team) return POINTER_TEAM; | ||
| else return POINTER_HAIR; | ||
| } | ||
| else return POINTER_HAIR; | ||
| } | ||
|
|
||
| static void draw_crosshair(int w, int h, int pointertype) | ||
| { | ||
| if(pointertype == POINTER_NONE) return; | ||
| int size = int(crosshairsize * hudsize); | ||
| float fade = crosshairblend; | ||
| vec color(1, 1, 1); | ||
| if(game::focus->state == CS_ALIVE) | ||
| { | ||
| if(crosshairweapons&2) color = vec::hexcolor(W(game::focus->weapselect, colour)); | ||
| if(pointertype == POINTER_ZOOM && game::inzoom()) | ||
| { | ||
| int off = int(zoomcrosshairsize*hudsize)-cs; | ||
| int off = int(zoomcrosshairsize*hudsize)-size; | ||
| // Focused zoom ratio | ||
| float zr = game::zoom_ratio(); | ||
| cs += int(off * zr); | ||
| size += int(off * zr); | ||
| fade += (zoomcrosshairblend - fade) * zr; | ||
| } | ||
| if(crosshairtone) skewcolour(c.r, c.g, c.b, crosshairtone); | ||
| int heal = m_health(game::gamemode, game::mutators, game::focus->actortype); | ||
| if(crosshairflash && game::focus->state == CS_ALIVE && game::focus->health < heal) | ||
| if(crosshairtone) skewcolour(color.r, color.g, color.b, crosshairtone); | ||
| int full_health = m_health(game::gamemode, game::mutators, game::focus->actortype); | ||
| if(crosshairflash && game::focus->state == CS_ALIVE && game::focus->health < full_health) | ||
| { | ||
| int millis = lastmillis%1000; | ||
| float amt = (millis <= 500 ? millis/500.f : 1.f-((millis-500)/500.f))*clamp(float(heal-game::focus->health)/float(heal), 0.f, 1.f); | ||
| flashcolour(c.r, c.g, c.b, 1.f, 0.f, 0.f, amt); | ||
| int millis = lastmillis % 1000; | ||
| float amt_ratio = millis <= 500 ? millis / 500.f : 1.f - ((millis - 500) / 500.f); | ||
| float health_ratio = clamp(float(full_health - game::focus->health) / float(full_health), 0.f, 1.f); | ||
| float amt = amt_ratio * health_ratio; | ||
| flashcolour(color.r, color.g, color.b, 1.f, 0.f, 0.f, amt); | ||
| } | ||
| if(crosshairthrob > 0 && regentime && game::focus->lastregen && lastmillis-game::focus->lastregen <= regentime) | ||
| { | ||
| float skew = clamp((lastmillis-game::focus->lastregen)/float(regentime/2), 0.f, 2.f); | ||
| cs += int(cs*(skew > 1.f ? 1.f-skew : skew)*(crosshairthrob*(game::focus->lastregenamt >= 0 ? 1 : -1))); | ||
| float skew = clamp((lastmillis - game::focus->lastregen) / float(regentime / 2), 0.f, 2.f); | ||
| size += int(size*(skew > 1.f ? 1.f-skew : skew)*(crosshairthrob*(game::focus->lastregenamt >= 0 ? 1 : -1))); | ||
| } | ||
| if(showcrosshair >= 2) | ||
| { | ||
| float accskew = weapons::accmod(game::focus, physics::secondaryweap(game::focus))*crosshairaccamt; | ||
| if(accskew > 0) fade /= accskew; | ||
| } | ||
| } | ||
| int cx = int(hudwidth*cursorx), cy = int(hudheight*cursory); | ||
| if(index != POINTER_GUI) | ||
| int cx = int(hudwidth * crosshairx); | ||
| int cy = int(hudheight * crosshairy); | ||
|
|
||
| drawpointertex(getpointer(pointertype, game::focus->weapselect), cx-size/2, cy-size/2, size, color.r, color.g, color.b, fade*hudblend); | ||
| if(pointertype > POINTER_GUI) | ||
| { | ||
| drawpointertex(getpointer(index, game::focus->weapselect), cx-cs/2, cy-cs/2, cs, c.r, c.g, c.b, fade*hudblend); | ||
| if(index > POINTER_GUI) | ||
| if(minimal(showcirclebar)) drawcirclebar(cx, cy, hudsize); | ||
| if(game::focus->state == CS_ALIVE && game::focus->hasweap(game::focus->weapselect, m_weapon(game::focus->actortype, game::gamemode, game::mutators))) | ||
| { | ||
| if(minimal(showcirclebar)) drawcirclebar(cx, cy, hudsize); | ||
| if(game::focus->state == CS_ALIVE && game::focus->hasweap(game::focus->weapselect, m_weapon(game::focus->actortype, game::gamemode, game::mutators))) | ||
| { | ||
| if(minimal(showclips, true)) drawclip(game::focus->weapselect, cx, cy, hudsize); | ||
| if(showindicator) drawindicator(game::focus->weapselect, cx, cy, int(indicatorsize*hudsize), physics::secondaryweap(game::focus)); | ||
| } | ||
| if(crosshairhitspeed && totalmillis-game::focus->lasthit <= crosshairhitspeed) | ||
| { | ||
| vec c2(1, 1, 1); | ||
| if(hitcrosshairtone) skewcolour(c2.r, c2.g, c2.b, hitcrosshairtone); | ||
| else c2 = c; | ||
| drawpointertex(getpointer(POINTER_HIT, game::focus->weapselect), cx-cs/2, cy-cs/2, cs, c2.r, c2.g, c2.b, crosshairblend*hudblend); | ||
| } | ||
| if(crosshairdistance && game::focus->state == CS_EDITING) draw_textf("\fa%.1f\fwm", cx+crosshairdistancex, cy+crosshairdistancey, 0, 0, 255, 255, 255, int(hudblend*255), TEXT_RIGHT_JUSTIFY, -1, -1, 1, game::focus->o.dist(worldpos)/8.f); | ||
| if(minimal(showclips, true)) drawclip(game::focus->weapselect, cx, cy, hudsize); | ||
| if(showindicator) drawindicator(game::focus->weapselect, cx, cy, int(indicatorsize*hudsize), physics::secondaryweap(game::focus)); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if(ui_cursor_type == 2) | ||
| if(crosshairhitspeed && totalmillis-game::focus->lasthit <= crosshairhitspeed) | ||
| { | ||
| cy -= cs/2; | ||
| cx -= cs/2; | ||
| vec color2(1, 1, 1); | ||
| if(hitcrosshairtone) skewcolour(color2.r, color2.g, color2.b, hitcrosshairtone); | ||
| else color2 = color; | ||
| drawpointertex(getpointer(POINTER_HIT, game::focus->weapselect), cx-size/2, cy-size/2, size, color2.r, color2.g, color2.b, crosshairblend*hudblend); | ||
| } | ||
| drawpointertex(getpointer(index, game::focus->weapselect), cx, cy, cs, c.r, c.g, c.b, fade*hudblend); | ||
| } | ||
| } | ||
|
|
||
| void drawpointers(int w, int h) | ||
| { | ||
| int index = POINTER_NONE; | ||
| if(hasinput()) index = !hasinput(true) || commandmillis > 0 ? POINTER_NONE : POINTER_GUI; | ||
| else if(!showhud || !showcrosshair || game::focus->state == CS_DEAD || !gs_playing(game::gamestate) || client::waiting() || (game::thirdpersonview(true) && game::focus != &game::player1)) | ||
| index = POINTER_NONE; | ||
| else if(game::focus->state == CS_EDITING) index = POINTER_EDIT; | ||
| else if(game::focus->state >= CS_SPECTATOR) index = POINTER_SPEC; | ||
| else if(game::inzoom()) index = POINTER_ZOOM; | ||
| else if(m_team(game::gamemode, game::mutators)) | ||
| { | ||
| vec pos = game::focus->headpos(); | ||
| gameent *d = game::intersectclosest(pos, worldpos, game::focus); | ||
| if(d && d->actortype < A_ENEMY && d->team == game::focus->team) index = POINTER_TEAM; | ||
| else index = POINTER_HAIR; | ||
| } | ||
| else index = POINTER_HAIR; | ||
| if(index > POINTER_NONE) | ||
| { | ||
| hudmatrix.ortho(0, hudwidth, hudheight, 0, -1, 1); | ||
| flushhudmatrix(); | ||
| glEnable(GL_BLEND); | ||
| glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||
| drawpointer(w, h, index); | ||
| glDisable(GL_BLEND); | ||
| if(crosshairdistance && game::focus->state == CS_EDITING) draw_textf("\fa%.1f\fwm", cx+crosshairdistancex, cy+crosshairdistancey, 0, 0, 255, 255, 255, int(hudblend*255), TEXT_RIGHT_JUSTIFY, -1, -1, 1, game::focus->o.dist(worldpos)/8.f); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1757,7 +1763,17 @@ namespace hud | |
| glDisable(GL_BLEND); | ||
| } | ||
| if(progressing || (commandmillis <= 0 && !curcompass)) UI::render(); | ||
| if(!progressing) drawpointers(hudwidth, hudheight); | ||
|
|
||
| int pointertype = choose_pointer_type(); | ||
| if(!progressing && pointertype != POINTER_NONE) | ||
| { | ||
| hudmatrix.ortho(0, hudwidth, hudheight, 0, -1, 1); | ||
| flushhudmatrix(); | ||
| glEnable(GL_BLEND); | ||
| glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||
| draw_pointer(hudwidth, hudheight, pointertype); | ||
| glDisable(GL_BLEND); | ||
| } | ||
| } | ||
|
|
||
| void drawconsole(int type, int w, int h, int x, int y, int s, float fade) | ||
|
|
@@ -2604,8 +2620,8 @@ namespace hud | |
| Texture *t = tex && *tex ? textureload(tex, 3, true, false) : NULL; | ||
| if(t == notexture) t = NULL; | ||
| float q = clamp(skew, 0.f, 1.f), cr = left ? r : r*q, cg = left ? g : g*q, cb = left ? b : b*q, s = size*skew, w = t ? float(t->w)/float(t->h)*s : s; | ||
| int heal = m_health(game::gamemode, game::mutators, game::focus->actortype), sy = int(s), cx = x, cy = y, cs = int(s), cw = int(w); | ||
| bool pulse = inventoryflash && game::focus->state == CS_ALIVE && game::focus->health < heal; | ||
| int full_health = m_health(game::gamemode, game::mutators, game::focus->actortype), sy = int(s), cx = x, cy = y, cs = int(s), cw = int(w); | ||
| bool pulse = inventoryflash && game::focus->state == CS_ALIVE && game::focus->health < full_health; | ||
| if(bg && sub == 0 && inventorybg) | ||
| { | ||
| Texture *u = textureload(inventorybg == 2 ? inventorybigtex : inventorytex, 3); | ||
|
|
@@ -2615,7 +2631,7 @@ namespace hud | |
| if(pulse) | ||
| { | ||
| int millis = lastmillis%1000; | ||
| float amt = (millis <= 500 ? millis/500.f : 1.f-((millis-500)/500.f))*clamp(float(heal-game::focus->health)/float(heal), 0.f, 1.f); | ||
| float amt = (millis <= 500 ? millis/500.f : 1.f-((millis-500)/500.f))*clamp(float(full_health-game::focus->health)/float(full_health), 0.f, 1.f); | ||
| flashcolourf(gr, gg, gb, gf, 1.f, 0.f, 0.f, 1.f, amt); | ||
| glow += int(s*inventoryglow*amt); | ||
| } | ||
|
|
@@ -2880,11 +2896,11 @@ namespace hud | |
| if(inventoryhealth) | ||
| { | ||
| float fade = blend*inventoryhealthblend; | ||
| int heal = m_health(game::gamemode, game::mutators, game::focus->actortype); | ||
| float pulse = inventoryhealthflash ? clamp((heal-game::focus->health)/float(heal), 0.f, 1.f) : 0.f, | ||
| int full_health = m_health(game::gamemode, game::mutators, game::focus->actortype); | ||
| float pulse = inventoryhealthflash ? clamp((full_health-game::focus->health)/float(full_health), 0.f, 1.f) : 0.f, | ||
| throb = inventoryhealththrob > 0 && regentime && game::focus->lastregen && lastmillis-game::focus->lastregen <= regentime ? clamp((lastmillis-game::focus->lastregen)/float(regentime), 0.f, 1.f) : -1.f; | ||
| if(inventoryhealth&2) | ||
| sy += drawbar(x, y, s, size, 1, inventoryhealthbartop, inventoryhealthbarbottom, fade, clamp(game::focus->health/float(heal), 0.f, 1.f), healthtex, healthbgtex, inventorytone, inventoryhealthbgglow, inventoryhealthbgblend, pulse, throb, inventoryhealththrob, inventoryhealthflash >= 2 ? (game::focus->lastregenamt <= 0 ? 0xFF0000 : 0x00FF00) : -1, game::focus->lastregenamt <= 0); | ||
| sy += drawbar(x, y, s, size, 1, inventoryhealthbartop, inventoryhealthbarbottom, fade, clamp(game::focus->health/float(full_health), 0.f, 1.f), healthtex, healthbgtex, inventorytone, inventoryhealthbgglow, inventoryhealthbgblend, pulse, throb, inventoryhealththrob, inventoryhealthflash >= 2 ? (game::focus->lastregenamt <= 0 ? 0xFF0000 : 0x00FF00) : -1, game::focus->lastregenamt <= 0); | ||
| if(inventoryhealth&1) | ||
| { | ||
| float gr = 1, gg = 1, gb = 1; | ||
|
|
@@ -3520,6 +3536,14 @@ namespace hud | |
| float fade = hudblend, consolefade = hudblend; | ||
| if(!progressing) | ||
| { | ||
| if(compassmillis <= 0) | ||
| { | ||
| glEnable(GL_BLEND); | ||
| glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||
| draw_crosshair(hudwidth, hudheight, choose_crosshair_type()); | ||
| glDisable(GL_BLEND); | ||
| } | ||
|
|
||
| vec colour = vec(1, 1, 1); | ||
| if(commandfade && (commandmillis > 0 || totalmillis-abs(commandmillis) <= commandfade)) | ||
| { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.