+ int mode_nr;
+
+ for (mode_nr = 0; mode_nr < NUM_GAME_MODES; mode_nr++)
+ {
+ struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[mode_nr];
+ int anim_nr;
+
+ for (anim_nr = 0; anim_nr < ctrl->num_anims; anim_nr++)
+ {
+ struct GlobalAnimMainControlInfo *anim = &ctrl->anim[anim_nr];
+ int part_nr;
+
+ for (part_nr = 0; part_nr < anim->num_parts_all; part_nr++)
+ {
+ struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
+
+ if (part->triggered)
+ part->clicked = TRUE;
+
+ part->triggered = FALSE;
+ part->clickable = FALSE;
+ }
+ }
+ }
+}
+
+#define ANIM_CLICKED_RESET 0
+#define ANIM_CLICKED_PRESSED 1
+#define ANIM_CLICKED_RELEASED 2
+
+static boolean InitGlobalAnim_Clicked(int mx, int my, int clicked_event)
+{
+ boolean click_consumed = FALSE;
+ boolean anything_clicked = FALSE;
+ boolean any_part_clicked = FALSE;
+ boolean any_event_action = FALSE;
+ int mode_nr;
+ int i;
+
+ // check game modes in reverse draw order (to stop when clicked)
+ for (mode_nr = NUM_GAME_MODES - 1; mode_nr >= 0; mode_nr--)
+ {
+ struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[mode_nr];
+ int anim_nr;
+
+ // check animations in reverse draw order (to stop when clicked)
+ for (anim_nr = ctrl->num_anims - 1; anim_nr >= 0; anim_nr--)
+ {
+ struct GlobalAnimMainControlInfo *anim = &ctrl->anim[anim_nr];
+ int part_nr;
+
+ // check animation parts in reverse draw order (to stop when clicked)
+ for (part_nr = anim->num_parts_all - 1; part_nr >= 0; part_nr--)
+ {
+ struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
+
+ if (clicked_event == ANIM_CLICKED_RESET)
+ {
+ part->clicked = FALSE;
+
+ continue;
+ }
+
+ if (!part->clickable)
+ continue;
+
+ if (!(part->state & ANIM_STATE_RUNNING))
+ continue;
+
+ // always handle "any" click events (clicking anywhere on screen) ...
+ if (clicked_event == ANIM_CLICKED_PRESSED &&
+ isClickablePart(part, ANIM_EVENT_ANY))
+ {
+#if DEBUG_ANIM_EVENTS
+ Debug("anim:InitGlobalAnim_Clicked", "%d.%d TRIGGERED BY ANY",
+ part->old_anim_nr + 1, part->old_nr + 1);
+#endif
+
+ anything_clicked = part->clicked = TRUE;
+ click_consumed |= clickConsumed(part);
+ }
+
+ // always handle "unclick:any" events (releasing anywhere on screen) ...
+ if (clicked_event == ANIM_CLICKED_RELEASED &&
+ isClickablePart(part, ANIM_EVENT_UNCLICK_ANY))
+ {
+#if DEBUG_ANIM_EVENTS
+ Debug("anim:InitGlobalAnim_Clicked", "%d.%d TRIGGERED BY UNCLICK:ANY",
+ part->old_anim_nr + 1, part->old_nr + 1);
+#endif
+
+ anything_clicked = part->clicked = TRUE;
+ click_consumed |= clickConsumed(part);
+ }
+
+ // ... but only handle the first (topmost) clickable animation
+ if (any_part_clicked)
+ continue;
+
+ if (clicked_event == ANIM_CLICKED_PRESSED &&
+ isClickedPart(part, mx, my, TRUE))
+ {
+#if 0
+ Debug("anim:InitGlobalAnim_Clicked", "%d.%d CLICKED [%d]",
+ anim_nr, part_nr, part->control_info.anim_event_action);
+#endif
+
+ // after executing event action, ignore any further actions
+ if (!any_event_action && DoGlobalAnim_EventAction(part))
+ any_event_action = TRUE;
+
+ // determine if mouse clicks should be blocked from other animations
+ any_part_clicked |= clickConsumed(part);
+
+ if (isClickablePart(part, ANIM_EVENT_SELF))
+ {
+#if DEBUG_ANIM_EVENTS
+ Debug("anim:InitGlobalAnim_Clicked", "%d.%d TRIGGERED BY SELF",
+ part->old_anim_nr + 1, part->old_nr + 1);
+#endif
+
+ anything_clicked = part->clicked = TRUE;
+ click_consumed |= clickConsumed(part);
+ }
+
+ // determine if mouse clicks should be blocked by this animation
+ click_consumed |= clickBlocked(part);
+
+ // check if this click is defined to trigger other animations
+ InitGlobalAnim_Triggered(part, &click_consumed, &any_event_action,
+ ANIM_EVENT_CLICK, "CLICK");
+ }
+ }
+ }
+ }
+
+ if (anything_clicked)
+ {
+ handle_click = TRUE;
+
+ for (i = 0; i < NUM_GAME_MODES; i++)
+ HandleGlobalAnim(ANIM_CONTINUE, i);
+
+ handle_click = FALSE;
+
+ // prevent ignoring release event if processed within same game frame
+ StopProcessingEvents();
+ }
+
+ return (click_consumed || any_event_action);
+}
+
+static void ResetGlobalAnim_Clickable(void)
+{
+ InitGlobalAnim_Clickable();
+}
+
+static void ResetGlobalAnim_Clicked(void)
+{
+ InitGlobalAnim_Clicked(-1, -1, ANIM_CLICKED_RESET);
+}
+
+boolean HandleGlobalAnimClicks(int mx, int my, int button, boolean force_click)
+{
+ static boolean click_consumed = FALSE;