From aaddacd3cb6785e484957ab62ca635d492873379 Mon Sep 17 00:00:00 2001 From: flowtron Date: Sun, 20 Jun 2021 11:06:39 +0200 Subject: [PATCH] persistent edithideentmask and pointatent (issue #362) --- config/menus_edit.cfg | 67 +++++++++++++++++------ source/src/clientgame.cpp | 1 + source/src/cube.h | 4 ++ source/src/editing.cpp | 110 ++++++++++++++++++++++++++++++++++++-- source/src/entities.cpp | 8 ++- source/src/protos.h | 3 +- source/src/renderhud.cpp | 31 ++++++----- source/src/world.cpp | 6 +-- 8 files changed, 190 insertions(+), 40 deletions(-) diff --git a/config/menus_edit.cfg b/config/menus_edit.cfg index 07afd3a2..cad87fd4 100644 --- a/config/menus_edit.cfg +++ b/config/menus_edit.cfg @@ -219,6 +219,22 @@ menuitem "\f2\t\t [ OK ]" [ newent light $__clight $__clight1 $__clight2 $__c //// Main > Editing > Entities //// newmenu Entities +menuinit [ + resetcurmenu + menuitem "Place Entities" [ showmenu "Place Entities" ] + menuitem "Entity Configuration" [ showmenu "Entity Configuration" ] + menuitem "Show list of TODO entities\i\3" [ showmenu "TODO entities" ] + menuitem "Show list of deleted entities\i\3" [ showmenu "Deleted entities" ] + ][ + menuitem "menu only available in edit mode" -1 + ] +] +tempalias __resetpickedents [ delmenu [Paste entity]; newmenu [Paste entity]; menuitem "\f7[Clear the list of copied entities from this menu]" __resetpickedents ; menuitem "" -1 ] +__resetpickedents + +//// Main > Editing > Entities > Place Entities //// + +newmenu [Place Entities] menuinit [ resetcurmenu if $editing [ @@ -238,15 +254,45 @@ menuinit [ menuitem "Copy closest entity" copyent [] (format "\fs\f4current closest entity:\n\fr%1\f4\n%2" (pop n) (pop d)) menuitem "Paste entity\i\3" [ showmenu [Paste entity] ] menuitem "Paste last copied entity" pasteent - menuitem "" -1 - menuitem "Show list of TODO entities\i\3" [ showmenu "TODO entities" ] - menuitem "Show list of deleted entities\i\3" [ showmenu "Deleted entities" ] ][ menuitem "menu only available in edit mode" -1 ] ] -tempalias __resetpickedents [ delmenu [Paste entity]; newmenu [Paste entity]; menuitem "\f7[Clear the list of copied entities from this menu]" __resetpickedents ; menuitem "" -1 ] -__resetpickedents + +//// Main > Editing > Entities > Entity Configuration //// + +tempalias __edset_durations [750 1000 1500 2000 2500 5000 7500 10000 15000 30000 60000 75000] +tempalias __rebuild_esvt_slider_value [ + _LE_ESVT = 0 + loop presetidx (listlen $__edset_durations) [ + if (<= (at $__edset_durations $presetidx) $editingsettingsvisibletime) [ + _LE_ESVT = $presetidx; + ] + ] + result $_LE_ESVT +] + +newmenu [Entity Configuration] +menuinit [ + resetcurmenu + if $editing [ + menuitem "Print entity stats" entstats + menuitem "Cycle through multiple closest entities" nextclosestent + menuitemslider "Select only entities of this type: " 0 -1 "(closestenttype -)" (concat all (listoptions ents)) [ if $arg1 [ closestenttype $arg1 ] [ closestenttype ] ] 1 + menuitemslider "GUI for hidemask setting: " 0 3 "$showeditingsettings" ["almost entirely off" "all off after duration" "text off after duration" "permanent"] [ showeditingsettings $arg1 ] 1 + menuitemslider "GUI for hidemask duration (presets): " 0 (- (listlen $__edset_durations) 1) "(__rebuild_esvt_slider_value)" 1 [ editingsettingsvisibletime (at $__edset_durations $arg1); echo "\f9will show \f1editinsettings\f9 for" (concatword "\f8" $editingsettingsvisibletime "\f9") "milliseconds"; ] 1 + menuitem "Hide entity sparklies\i\3" [ showmenu [Hide entity sparklies] ] + ][ + menuitem "menu only available in edit mode" -1 + ] +] + +//// Main > Editing > Entities > Entity Configuration > Hide entity sparklies //// + +newmenu [Hide entity sparklies] +looplisti (listoptions ents) e [ + menuitemcheckbox (concat Hide $e sparklies:) (concat "(&b $edithideentmask" (+ 0 (powf 2 $i)) ")") (concat "edithideentmask (^b $edithideentmask" (+ 0 (powf 2 $i)) ")") +] //// Main > Editing > Entities > Clips //// @@ -683,19 +729,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 "Print entity stats" entstats -menuitem "Cycle through multiple closest entities" nextclosestent -menuitemslider "Select only entities of this type: " 0 -1 "(closestenttype -)" (concat all (listoptions ents)) [ if $arg1 [ closestenttype $arg1 ] [ closestenttype ] ] 1 -menuitem "Hide entity sparklies\i\3" [ showmenu [Hide entity sparklies] ] menuitem "Multiple map buffers (xmaps)\i\3" [ showmenu xmaps ] -//// Main > Editing > Map operations > Hide entity sparklies //// - -newmenu [Hide entity sparklies] -looplisti (listoptions ents) e [ - menuitemcheckbox (concat Hide $e sparklies:) (concat "(&b $edithideentmask" (+ 0 (powf 2 $i)) ")") (concat "edithideentmask (^b $edithideentmask" (+ 0 (powf 2 $i)) ")") -] - //// Main > Editing > Map operations > xmaps //// newmenu xmaps diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 01381b63..278d2477 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -1166,6 +1166,7 @@ void startmap(const char *name, bool reset, bool norespawn) // called just aft lasthit = 0; if(m_valid(gamemode) && !m_mp(gamemode)) respawnself(); else findplayerstart(player1); + editingsettingsshowminimal = true; if(!reset) return; diff --git a/source/src/cube.h b/source/src/cube.h index 88e1bd84..90b961ea 100644 --- a/source/src/cube.h +++ b/source/src/cube.h @@ -38,6 +38,10 @@ extern playerent *player1; // special client ent that receives inpu extern vector players; // all the other clients (in multiplayer) extern vector bounceents; extern bool editmode; +extern bool editingsettingsshowminimal; +extern int keepshowingeditingsettingsfrom; +extern int keepshowingeditingsettingstill; +extern int editingsettingsvisibletime; extern int unsavededits; extern vector ents; // map entities extern vec worldpos, camup, camright, camdir; // current target of the crosshair in the world diff --git a/source/src/editing.cpp b/source/src/editing.cpp index 2e2472ab..f001619d 100644 --- a/source/src/editing.cpp +++ b/source/src/editing.cpp @@ -33,6 +33,12 @@ COMMANDF(editmeta, "d", (bool on) { editmetakeydown = on ? 1 : 0; } ); VAR(cleanedit, 0, 0, 1); // hides everything in edit mode you can't see in regular mode COMMANDF(togglecleanedit, "", () { cleanedit = !cleanedit; }); +bool editingsettingsshowminimal = false; +int keepshowingeditingsettingsfrom = 0; +int keepshowingeditingsettingstill = 0; +VARFP(editingsettingsvisibletime, 750, 7500, 75000, toucheditingsettings()); +VARFP(showeditingsettings, 0, 1, 3, toucheditingsettings()); // 0:almost entirely off, 1: all off after duration, 2: text off after duration, 3: permanent + void toggleedit(bool force) { if(player1->state==CS_DEAD) return; // do not allow dead players to edit to avoid state confusion @@ -54,8 +60,9 @@ void toggleedit(bool force) } else { - //put call to clear/restart gamemode player1->attacking = false; + if(keepshowingeditingsettingsfrom==0) keepshowingeditingsettingsfrom = lastmillis; + keepshowingeditingsettingstill = lastmillis + editingsettingsvisibletime; } keyrepeat(editmode, KR_EDITMODE); editing = editmode ? 1 : 0; @@ -113,7 +120,8 @@ char *editinfo() { entity &c = ents[e]; int t = c.type < MAXENTTYPES ? c.type : 0; - formatstring(info)("%s entity: %s (%s)", pinnedclosestent ? "\fs\f3pinned\fr" : "closest", entnames[t], formatentityattributes(c, true)); + extern int pointatent; + formatstring(info)("%s entity: %s (%s)", pinnedclosestent ? "\fs\f3pinned\fr" : (pointatent == 1 ? "point at" : "closest"), entnames[t], formatentityattributes(c, true)); const char *unassigned = "unassigned slot", *slotinfo = unassigned; if(t == MAPMODEL) { @@ -122,7 +130,7 @@ char *editinfo() } else if(t == SOUND) { - if(mapconfigdata.mapsoundlines.inrange(c.attr1)) slotinfo = mapconfigdata.mapsoundlines[c.attr1].name; + if(mapconfigdata.mapsoundlines.inrange(c.attr1)) slotinfo = mapconfigdata.mapsoundlines[c.attr1].name; } else slotinfo = ""; if(*slotinfo && (hideeditslotinfo == 0 || (hideeditslotinfo == 1 && slotinfo == unassigned))) concatformatstring(info, " %s", slotinfo); @@ -787,6 +795,7 @@ void renderhudtexturepreview(int slot, int pos, bool highlight) } } + static int lastedittex = 0; VARP(hudtexttl, 0, 2500, 10000); @@ -802,6 +811,101 @@ void renderhudtexturepreviews() } } +// the entity sparklies have RGB information in renderparticles.cpp:struct parttype .. which we keep redundantly here; consolidation may prove annoying :-/ +static struct partcolour{ float r, g, b; } partcolours[MAXENTTYPES] = +{ + { 0.7f, 0.2f, 0.7f }, // NOTUSED + { 1.0f, 1.0f, 1.0f }, // LIGHT + { 0.0f, 1.0f, 0.0f }, // PLAYERSTART + { 1.0f, 0.0f, 0.0f }, // I_CLIPS + { 1.0f, 0.0f, 0.0f }, // I_AMMO + { 1.0f, 0.0f, 0.0f }, // I_GRENADE + { 1.0f, 1.0f, 0.0f }, // I_HEALTH + { 1.0f, 1.0f, 0.0f }, // I_HELMET + { 1.0f, 1.0f, 0.0f }, // I_ARMOUR + { 1.0f, 1.0f, 0.0f }, // I_AKIMBO + { 1.0f, 0.0f, 1.0f }, // MAPMODEL + { 1.0f, 0.5f, 0.2f }, // CARROT + { 0.5f, 0.5f, 0.5f }, // LADDER + { 0.0f, 1.0f, 1.0f }, // CTF_FLAG + { 1.0f, 0.0f, 1.0f }, // SOUND + { 0.5f, 0.5f, 0.5f }, // CLIP + { 0.5f, 0.5f, 0.5f }, // PLCLIP + { 0.7f, 0.2f, 0.7f } // DUMMYENT +}; + +void rendereditingsettings() +{ + if(showeditingsettings > 0 || (edithideentmask != 0 && editingsettingsshowminimal)) + { + bool showing = ((showeditingsettings >= 2) || (keepshowingeditingsettingstill > 0)); + int deltax = 0; + if(keepshowingeditingsettingstill > 0) + { + int deltat = keepshowingeditingsettingstill - lastmillis; + if(deltat < 0) + { + keepshowingeditingsettingstill = 0; + keepshowingeditingsettingsfrom = 0; + editingsettingsshowminimal = false; + showing = (showeditingsettings >= 2); + }else{ + int pulldist = VIRTW/4; + float edgedist = 0.2f; + deltat = deltat > keepshowingeditingsettingstill/2 ? deltat : ( lastmillis - keepshowingeditingsettingsfrom ); // "from" is only set once per slide, "till" may be pushed outward … + // … if someone takes a long(>(1-edgedist)) time to trigger the push it out some more .. there'll be a jump in the sliding. can't be helped. + float elapsedfrac = deltat/(1.0f * editingsettingsvisibletime); + bool slideout = elapsedfrac(1-edgedist); + if(slidein||slideout) + { + deltax = (slideout?pulldist:0) + (slideout?-1:+1) * (elapsedfrac-(slidein?(1-edgedist):0))/edgedist * pulldist; + } + } + } + if(showing) + { + glDepthMask(GL_FALSE); + glDisable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + int boxsize = VIRTW/32, boxline = 3*boxsize/2, x = FONTH/2 - (showeditingsettings==1?deltax:0), y = 3 * VIRTH/8, x2 = x + boxsize, border = FONTH/8; + loopi(MAXENTTYPES) + { + if(i>NOTUSED && i<=DUMMYENT) + { + y = 3 * VIRTH/8 + (i-1) * boxline; + int y2 = y + boxsize; + bool ishidden = (edithideentmask & (1 << (i - 1))); + // text first makes it slide in/out behind the boxes + if(showeditingsettings==3||keepshowingeditingsettingsfrom) // 3:all,always || ( 2:text,at first, 1:all,at first ) + { + glEnable(GL_TEXTURE_2D); + defformatstring(entlabel)("\f%d%s", ishidden?4:5, entnames[i]); + draw_text(entlabel, x + boxline -(showeditingsettings==2?deltax:0), y ); + glDisable(GL_TEXTURE_2D); + } + // now the box + partcolour &pc = partcolours[i]; + glColor4f(pc.r, pc.g, pc.b, .5); + glBegin(GL_TRIANGLE_STRIP); + glVertex2f(x , y ); + glVertex2f(x2, y ); + glVertex2f(x , y2); + glVertex2f(x2, y2); + glEnd(); + // and the border + glDisable(GL_BLEND); + box2d(x-border, y-border, x2+border, y2+border, ishidden?0:200); + glEnable(GL_BLEND); + } + } + glEnable(GL_TEXTURE_2D); + glDepthMask(GL_TRUE); + } + } +} + void edittexxy(int type, int t, block &sel) { loopselxy(sel, switch(type) diff --git a/source/src/entities.cpp b/source/src/entities.cpp index cf751d55..432474fe 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -2,11 +2,15 @@ #include "cube.h" -VAR(showclips, 0, 1, 1); +VARP(showclips, 0, 1, 1); VARP(showmodelclipping, 0, 0, 1); VARP(showladderentities, 0, 0, 1); VARP(showplayerstarts, 0, 0, 1); -VAR(edithideentmask, 0, 0, INT_MAX); +void toucheditingsettings(){ + if(keepshowingeditingsettingsfrom == 0) keepshowingeditingsettingsfrom = lastmillis; + keepshowingeditingsettingstill = lastmillis + editingsettingsvisibletime; +} +VARFP(edithideentmask, 0, 0, INT_MAX, toucheditingsettings()); vector ents; diff --git a/source/src/protos.h b/source/src/protos.h index c9ecbc7d..2d9c9a40 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -927,7 +927,8 @@ extern void tryreload(playerent *p); extern void checkweaponstate(); extern int burstshotssettings[NUMGUNS]; -// entities +// entities: +extern void toucheditingsettings(); extern int edithideentmask; extern void pickupeffects(int n, playerent *d); extern void rendereditentities(); diff --git a/source/src/renderhud.cpp b/source/src/renderhud.cpp index 48694d26..b5e57a9a 100644 --- a/source/src/renderhud.cpp +++ b/source/src/renderhud.cpp @@ -337,7 +337,7 @@ void drawequipicons(playerent *p) // health & armor if(p->armour) drawequipicon(HUDPOS_ARMOUR*2, 1650, (p->armour-1)/25, 2); drawequipicon(HUDPOS_HEALTH*2, 1650, 2, 3); - if(p->mag[GUN_GRENADE]) drawequipicon(oldfashionedgunstats ? (HUDPOS_GRENADE + (((float)screenw / (float)screenh > 1.5f) ? 75 : 25)) * 2 : HUDPOS_GRENADE*2, 1650, 3, 1); + if(p->mag[GUN_GRENADE]) drawequipicon(oldfashionedgunstats ? (HUDPOS_GRENADE + (((float)screenw / (float)screenh > 1.5f) ? 75 : 25)) * 2 : HUDPOS_GRENADE*2, 1650, 3, 1); // weapons int c = p->weaponsel->type != GUN_GRENADE ? p->weaponsel->type : getprevweaponsel(p), r = 0; @@ -824,17 +824,15 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat if(command) commandh -= rendercommand(-1, HUDPOS_Y_BOTTOMLEFT, VIRTW - FONTH); // dryrun to get height else if(infostr) { - if(cleanedit) // smaller text - { - glPushMatrix(); - glLoadIdentity(); - glOrtho(0, VIRTW * 2, VIRTH * 2, 0, -1, 1); - glScalef(1.0, 1.0, 1.0); //set scale - draw_text(infostr, 48, VIRTH * 2 - 3 * FONTH); - glPopMatrix(); - } - else - draw_text(infostr, HUDPOS_X_BOTTOMLEFT, HUDPOS_Y_BOTTOMLEFT); + // I wanted to make the very large pinned/closest/point-at entity text smaller .. now I see this .. isn't "cleanedit" supposed to *hide* everything usually seen in edit mode, not make stuff smaller? + // .. so .. this must be some "hide by obscurity during development" thing .. *grin*: go-go-gadgeto improvement + //if(cleanedit){}else draw_text(infostr, HUDPOS_X_BOTTOMLEFT, HUDPOS_Y_BOTTOMLEFT);// smaller text + glPushMatrix(); + glLoadIdentity(); + glOrtho(0, VIRTW * 2, VIRTH * 2, 0, -1, 1); + glScalef(1.0, 1.0, 1.0); //set scale + draw_text(infostr, 48, VIRTH * 2 - 3 * FONTH); + glPopMatrix(); } else if(targetplayer && showtargetname) draw_text(colorname(targetplayer), HUDPOS_X_BOTTOMLEFT, HUDPOS_Y_BOTTOMLEFT); glLoadIdentity(); @@ -977,8 +975,13 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat if(multiplayer(NULL) || watchingdemo) draw_textf("SCROLL to change player", left - (text_width("SCROLL to change player") + FONTH/2), top+80); } - extern void renderhudtexturepreviews(); - if(editmode) renderhudtexturepreviews(); + if(editmode) + { + extern void renderhudtexturepreviews(); + extern void rendereditingsettings(); + renderhudtexturepreviews(); + rendereditingsettings(); + } if(ispaused) { diff --git a/source/src/world.cpp b/source/src/world.cpp index d72856a6..23ad17b0 100644 --- a/source/src/world.cpp +++ b/source/src/world.cpp @@ -140,9 +140,8 @@ COMMAND(closestenttype, "s"); COMMANDF(toggleclosestentpin, "", () { pinnedclosestent = ents.inrange((pinnedent = pinnedclosestent ? -1 : closestent())); }); -void pointatent(int *_on) +void _pointatent(bool on) { - bool on = *_on != 0; if(pointingatents != on) { if(on) pinnedclosestent = false; @@ -154,8 +153,7 @@ void pointatent(int *_on) pointingatents = on; } } -COMMAND(pointatent, "i"); - +VARFP(pointatent, 0, 0, 1, _pointatent(pointatent==1)); FVARP(pointatentmaxangle, 0.01f, 2.0f, 180.0f); bool intersectangular(const vec &from, vec ray, vec ent, float maxangle, float &dist)