added event actions (by simulating keyboard input) for global animations
authorHolger Schemel <info@artsoft.org>
Tue, 12 Jun 2018 20:03:51 +0000 (22:03 +0200)
committerHolger Schemel <info@artsoft.org>
Sun, 17 Jun 2018 22:02:49 +0000 (00:02 +0200)
This change adds more event actions to the "anim_event_action" option
for clickable global animations, this time adding simulated keyboard
input by specifying a key symbol for the key to be simulated.

For example, you can now use:

global.anim_1.part_1.MAIN.anim_event:            click
global.anim_1.part_1.MAIN.anim_event_action:     XK_Return

When clicking this global animation (on the main menu screen), the
currently selected/highlighted menu item will be chosen/executed.

To get the key symbol/name for the key to be simulated, just choose
the desired key as a keyboard shortcut in the setup menu (temporarily
only) and look at the resulting entry in the file "setup.conf" in the
game's configuration and personal data directory.

src/anim.c
src/events.c
src/events.h
src/libgame/misc.c

index d81a0746edde6052861a2dfa1145b3a7c3c9f6ce..0a278aa35cb36a97983be9ea1cc7b62934bb3799 100644 (file)
@@ -14,6 +14,7 @@
 #include "anim.h"
 #include "main.h"
 #include "tools.h"
+#include "events.h"
 #include "screens.h"
 
 
@@ -1452,7 +1453,8 @@ static boolean DoGlobalAnim_EventAction(struct GlobalAnimPartControlInfo *part)
     return FALSE;
 
   boolean action_executed = (DoGadgetAction(anim_event_action) ||
-                            DoScreenAction(anim_event_action));
+                            DoScreenAction(anim_event_action) ||
+                            DoKeysymAction(anim_event_action));
 
   // check if further actions are allowed to be executed
   if (part->control_info.style & STYLE_MULTIPLE_ACTIONS)
index 146689f614be357b1d1f6687d9bc1d5331103bd7..0e899a5b8f6f9836eff53d7117c8bbe8545b5aec 100644 (file)
@@ -2496,3 +2496,18 @@ void HandleSpecialGameControllerKeys(Key key, int key_status)
 #endif
 #endif
 }
+
+boolean DoKeysymAction(int keysym)
+{
+  if (keysym < 0)
+  {
+    Key key = (Key)(-keysym);
+
+    HandleKey(key, KEY_PRESSED);
+    HandleKey(key, KEY_RELEASED);
+
+    return TRUE;
+  }
+
+  return FALSE;
+}
index 83d869adc14e334c02f627a8021ce569da4ed9f2..9672029fdd4bfc1253edb8812f788ea186807fe6 100644 (file)
@@ -46,4 +46,6 @@ void HandleJoystick();
 void HandleSpecialGameControllerButtons(Event *);
 void HandleSpecialGameControllerKeys(Key, int);
 
+boolean DoKeysymAction(int);
+
 #endif
index fb265fab44a1c633590580a7c81949be7682577b..6432523e41ce5c5755a6e385c28abd30995b5aee 100644 (file)
@@ -2819,6 +2819,14 @@ int get_anim_action_parameter_value(char *token)
     checked_free(gfx_token);
   }
 
+  if (result == -1)
+  {
+    Key key = getKeyFromX11KeyName(token);
+
+    if (key != KSYM_UNDEFINED)
+      result = -(int)key;
+  }
+
   if (result == -1)
     result = ANIM_EVENT_ACTION_NONE;
 
@@ -2909,7 +2917,7 @@ int get_parameter_value(char *value_raw, char *suffix, int type)
   else if (strEqual(suffix, ".init_event_action") ||
           strEqual(suffix, ".anim_event_action"))
   {
-    result = get_anim_action_parameter_value(value);
+    result = get_anim_action_parameter_value(value_raw);
   }
   else if (strEqual(suffix, ".class"))
   {