improved function to dump identifiers for all gadgets on current screen
[rocksndiamonds.git] / src / libgame / gadgets.c
index cba655f874a89a29d9c31d0001c5a75506ef9088..244db6ea8852b4a4df027f3ffbc95848b635210d 100644 (file)
@@ -13,6 +13,7 @@
 #include <string.h>
 
 #include "gadgets.h"
+#include "image.h"
 #include "text.h"
 #include "misc.h"
 
@@ -2272,3 +2273,43 @@ boolean HandleGadgetsKeyInput(Key key)
 
   return TRUE;
 }
+
+void DumpGadgetIdentifiers()
+{
+  struct GadgetInfo *gi;
+
+  Print("Gadgets on current screen:\n");
+
+  for (gi = gadget_list_first_entry; gi != NULL; gi = gi->next)
+  {
+    if (gi->mapped && gi->image_id != -1)
+    {
+      char *token = getTokenFromImageID(gi->image_id);
+      char *prefix = "gfx.";
+
+      if (strPrefix(token, prefix))
+       token = &token[strlen(prefix)];
+
+      Print("- '%s'\n", token);
+    }
+  }
+
+  Print("Done.\n");
+}
+
+boolean DoGadgetAction(int image_id)
+{
+  struct GadgetInfo *gi;
+
+  for (gi = gadget_list_first_entry; gi != NULL; gi = gi->next)
+  {
+    if (gi->mapped && gi->image_id == image_id)
+    {
+      gi->callback_action(gi);
+
+      return TRUE;
+    }
+  }
+
+  return FALSE;
+}