changeset 3:7817e13d25ea

Find items by their type. Patch by Barry Mead. Pressing 'f' lets you find a thing, linedef or sector by its type. If an object is currently highlighted, it finds the next one.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 21 Sep 2011 04:38:23 +0300
parents 70951bfb02b1
children db8b4f975bad
files src/editloop.cc src/editloop.h src/l_prop.cc src/s_prop.cc src/t_prop.cc
diffstat 5 files changed, 92 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/editloop.cc	Wed Sep 21 04:34:50 2011 +0300
+++ b/src/editloop.cc	Wed Sep 21 04:38:23 2011 +0300
@@ -342,6 +342,7 @@
    "~Next object",       'n',   0,
    "~Prev object",       'p',   0,
    "~Jump to object...", 'j',   0,
+   "~Find by type",	 'f',	0,
    NULL);
 
 e.mb_menu[MBM_MISC_L] = new Menu ("Misc. operations",
@@ -1834,6 +1835,56 @@
 	 RedrawMap = 1;
 	 }
 
+      // [f]: find object by type
+      else if (is.key == 'f' && (! e.global || e.highlighted ())) 
+	 {
+	 Objid find_obj;
+	 int otype;
+	 obj_no_t omax,onum;
+	 find_obj.type = e.highlighted () ? e.highlighted.type : e.obj_type;
+	 onum = find_obj.num  = e.highlighted () ? e.highlighted.num  : 0;
+	 omax = GetMaxObjectNum(find_obj.type);
+         switch (find_obj.type)
+            {
+	    case OBJ_SECTORS:
+               if ( ! InputSectorType( 84, 21, &otype))
+		  {
+	          for (onum = e.highlighted () ? onum + 1 : onum; onum <= omax; onum++)
+	             if (Sectors[onum].special == (wad_stype_t) otype)
+			{
+		        find_obj.num = onum;
+	                GoToObject(find_obj);
+		        break;
+		        }
+		  }
+	    break;
+	    case OBJ_THINGS:
+	       if ( ! InputThingType( 42, 21, &otype))
+	 	  {
+                  for (onum = e.highlighted () ? onum + 1 : onum; onum <= omax; onum++)
+	             if (Things[onum].type == (wad_ttype_t) otype)
+                        {
+		        find_obj.num = onum;
+	                GoToObject(find_obj);
+		        break;
+		        }
+		  }
+	    break;
+	    case OBJ_LINEDEFS:
+	       if ( ! InputLinedefType( 0, 21, &otype))
+		  {
+	          for (onum = e.highlighted () ? onum + 1 : onum; onum <= omax; onum++)
+		     if (LineDefs[onum].type == (wad_ldtype_t) otype)
+			{
+		        find_obj.num = onum;
+	                GoToObject(find_obj);
+			break;
+		        }
+		  }
+	    break;
+	    }
+         RedrawMap = 1;
+         }
 #if 0
       // [c]: clear selection and redraw the map
       else if (is.key == 'c')
--- a/src/editloop.h	Wed Sep 21 04:34:50 2011 +0300
+++ b/src/editloop.h	Wed Sep 21 04:38:23 2011 +0300
@@ -6,6 +6,9 @@
 
 void EditorLoop (const char *); /* SWAP! */
 const char *SelectLevel (int levelno);
+int InputSectorType(int x0, int y0, int *number);
+int InputLinedefType(int x0, int y0, int *number);
+int InputThingType(int x0, int y0, int *number);
 
 
 
--- a/src/l_prop.cc	Wed Sep 21 04:34:50 2011 +0300
+++ b/src/l_prop.cc	Wed Sep 21 04:38:23 2011 +0300
@@ -105,7 +105,7 @@
  *	Prototypes of private functions
  */
 static char *GetTaggedLineDefFlag (int linedefnum, int flagndx);
-static int InputLinedefType (int x0, int y0, int *number);
+int InputLinedefType (int x0, int y0, int *number);
 static const char *PrintLdtgroup (void *ptr);
 
 
@@ -475,7 +475,7 @@
  *	Let the user select a linedef type number and return it.
  *	Returns 0 if OK, <>0 if cancelled
  */
-static int InputLinedefType (int x0, int y0, int *number)
+int InputLinedefType (int x0, int y0, int *number)
 {
   int         r;
   int         ldtgno = 0;
--- a/src/s_prop.cc	Wed Sep 21 04:34:50 2011 +0300
+++ b/src/s_prop.cc	Wed Sep 21 04:38:23 2011 +0300
@@ -259,4 +259,37 @@
   }
 }
 
-
+/*
+ * 	InputSectorType
+ * 	Let the user select a sector type number and return it
+ * 	Returns 0 if OK, <>0 if cancelled
+ */
+int InputSectorType (int x0, int y0, int *number)
+{
+  int	val;
+  val = 0;
+  *number = 0;
+  Menu_data_st menudata (stdef);
+	if (DisplayMenuList (x0 , y0, "Select type", menudata, &val)
+	  < 0)
+	  return 1;
+  // KLUDGE last element of stdef means "enter value"
+  if (val == al_lcount (stdef) - 1)
+  	{
+	  val = InputIntegerValue (x0 + 84,
+	    y0 + BOX_BORDER + (3 + val) * FONTH,
+	    -32768, 32767, 0);
+	  if (val == IIV_CANCEL)  // [Esc]
+	    return 1;
+	}
+	else
+	{
+	  if (al_lseek (stdef, val, SEEK_SET))
+	    fatal_error ("%s SP1 (%s)\n",
+	      msg_unexpected, al_astrerror (al_aerrno));
+	  val = CUR_STDEF->number;
+	}
+  if (val < 0) return 1;  //unsuccessful
+  *number = val;
+  return 0;               //successful
+}
--- a/src/t_prop.cc	Wed Sep 21 04:34:50 2011 +0300
+++ b/src/t_prop.cc	Wed Sep 21 04:38:23 2011 +0300
@@ -43,7 +43,7 @@
 /*
  *	Private functions prototypes
  */
-static int InputThingType (int x0, int y0, int *number);
+int InputThingType (int x0, int y0, int *number);
 static const char *PrintThinggroup (void *ptr);
 static const char *PrintThingdef (void *ptr);
 
@@ -250,7 +250,7 @@
  *	Let the user select a thing number and return it.
  *	Returns 0 if OK, <>0 if cancelled
  */
-static int InputThingType (int x0, int y0, int *number)
+int InputThingType (int x0, int y0, int *number)
 {
 int         r;
 int         tgno = 0;