From 107a563e99aea668e2c02b4ea0357ac462fb0596 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Tue, 2 Jun 2015 01:45:00 +0200 Subject: [PATCH] pin selection of closest entity in map editor Pressing the middle mouse button toggles a pin on the "closest entity" selector. The HUD will indicate the lock by showing "pinned" instead of "closest" entity. All actions, that would otherwise affect the closest entity, will affect the pinned entity instead. Deleting the locked entity will unlock it. toggleclosestentpin Toggles the pin on the "closest ent" selector. Bound to MOUSE3 by default. DOCREF togglelockclosestent --- config/resetbinds.cfg | 1 + source/src/clientgame.cpp | 1 + source/src/editing.cpp | 2 +- source/src/protos.h | 1 + source/src/world.cpp | 9 +++++++++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config/resetbinds.cfg b/config/resetbinds.cfg index 342d72f3..b780e513 100644 --- a/config/resetbinds.cfg +++ b/config/resetbinds.cfg @@ -27,6 +27,7 @@ bind MOUSE1 attack bind MOUSE2 altaction editbind MOUSE2 [ showmenu editing ] bind MOUSE3 weapon +editbind MOUSE3 toggleclosestentpin bind MOUSE4 key_universaldelta_plus bind MOUSE5 key_universaldelta_minus bind BACKSPACE dropflag diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 4eb18e59..4cc9e3e7 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -1085,6 +1085,7 @@ void resetmap(bool mrproper) pruneundos(); changedents.setsize(0); deleted_ents.setsize(0); + pinnedclosestent = false; particlereset(); if(mrproper) { diff --git a/source/src/editing.cpp b/source/src/editing.cpp index 57b122c1..eed7afcf 100644 --- a/source/src/editing.cpp +++ b/source/src/editing.cpp @@ -106,7 +106,7 @@ char *editinfo() { entity &c = ents[e]; int t = c.type < MAXENTTYPES ? c.type : 0; - formatstring(info)("closest entity: %s (%s)", entnames[t], formatentityattributes(c, true)); + formatstring(info)("%s entity: %s (%s)", pinnedclosestent ? "\fs\f3pinned\fr" : "closest", entnames[t], formatentityattributes(c, true)); const char *slotinfo = "unassigned slot"; if(t == MAPMODEL) { diff --git a/source/src/protos.h b/source/src/protos.h index b3f04618..87952bc3 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -485,6 +485,7 @@ extern void calcmapdims(); extern bool empty_world(int factor, bool force); extern void remip(const block &b, int level = 0); extern void remipmore(const block &b, int level = 0); +extern bool pinnedclosestent; extern int closestent(); extern void deletesoundentity(entity &e); extern int findtype(const char *what); diff --git a/source/src/world.cpp b/source/src/world.cpp index 7ca8e535..a9c8ab52 100644 --- a/source/src/world.cpp +++ b/source/src/world.cpp @@ -128,9 +128,18 @@ void closestenttype(char *what) COMMAND(nextclosestent, ""); COMMAND(closestenttype, "s"); +bool pinnedclosestent = false; +static int pinnedent = -1; +COMMANDF(toggleclosestentpin, "", () { pinnedclosestent = ents.inrange((pinnedent = pinnedclosestent ? -1 : closestent())); }); + int closestent() // used for delent and edit mode ent display { if(noteditmode("closestent")) return -1; + if(pinnedclosestent) + { + if(ents.inrange(pinnedent) && ents[pinnedent].type != NOTUSED) return pinnedent; + pinnedclosestent = false; // release lock when ent is deleted + } int best = -1, bcnt = 0; float bdist = 99999; loopj(3)