#include "screens.h"
+#define DEBUG_ANIM_EVENTS 0
+
+
// values for global toon animation definition
#define NUM_GLOBAL_TOON_ANIMS 1
#define NUM_GLOBAL_TOON_PARTS MAX_NUM_TOONS
boolean init_event_state;
boolean anim_event_state;
+ boolean triggered;
boolean clickable;
boolean clicked;
};
// forward declaration for internal use
+static boolean DoGlobalAnim_EventAction(struct GlobalAnimPartControlInfo *);
static void HandleGlobalAnim(int, int);
static void DoAnimationExt(void);
static void ResetGlobalAnim_Clickable(void);
static boolean checkGlobalAnimEvent(int anim_event, int mask)
{
- int trigger_mask = ANIM_EVENT_ANIM_MASK | ANIM_EVENT_PART_MASK;
- int mask_anim_only = mask & ANIM_EVENT_ANIM_MASK;
+ int mask_anim_only = mask & ~ANIM_EVENT_PART_MASK;
if (mask & ANIM_EVENT_ANY)
return (anim_event & ANIM_EVENT_ANY);
else if (mask & ANIM_EVENT_SELF)
return (anim_event & ANIM_EVENT_SELF);
else
- return ((anim_event & trigger_mask) == mask ||
- (anim_event & trigger_mask) == mask_anim_only);
+ return (anim_event == mask ||
+ anim_event == mask_anim_only);
}
static boolean isClickablePart(struct GlobalAnimPartControlInfo *part, int mask)
return (part->control_info.style & STYLE_PASSTHROUGH ? FALSE : TRUE);
}
+static void InitGlobalAnim_Triggered(struct GlobalAnimPartControlInfo *part,
+ boolean *anything_clicked,
+ boolean *any_event_action,
+ int event_value)
+{
+ struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[part->mode_nr];
+
+ int gic_anim_nr = part->old_anim_nr + 1; // X as in "anim_X"
+ int gic_part_nr = part->old_nr + 1; // Y as in "part_Y"
+ int mask = event_value | (gic_anim_nr << ANIM_EVENT_ANIM_BIT);
+
+ if (!part->is_base)
+ mask |= gic_part_nr << ANIM_EVENT_PART_BIT;
+
+ int anim2_nr;
+
+ for (anim2_nr = 0; anim2_nr < ctrl->num_anims; anim2_nr++)
+ {
+ struct GlobalAnimMainControlInfo *anim2 = &ctrl->anim[anim2_nr];
+ int part2_nr;
+
+ for (part2_nr = 0; part2_nr < anim2->num_parts_all; part2_nr++)
+ {
+ struct GlobalAnimPartControlInfo *part2 = &anim2->part[part2_nr];
+
+ if (part2->state != ANIM_STATE_RUNNING)
+ continue;
+
+ if (isClickablePart(part2, mask))
+ {
+ part2->triggered = TRUE;
+ *anything_clicked = clickConsumed(part); // click was on "part"!
+
+#if DEBUG_ANIM_EVENTS
+ printf("::: => %d.%d TRIGGERED BY %d.%d\n",
+ part2->old_anim_nr + 1, part2->old_nr + 1,
+ part->old_anim_nr + 1, part->old_nr + 1);
+#endif
+#if 0
+ printf("::: %d.%d TRIGGER CLICKED [%d]\n", anim2_nr, part2_nr,
+ part2->control_info.anim_event_action);
+#endif
+
+ // after executing event action, ignore any further actions
+ if (!*any_event_action && DoGlobalAnim_EventAction(part2))
+ *any_event_action = TRUE;
+ }
+
+#if 0
+ struct GraphicInfo *c = &part2->control_info;
+
+ printf("::: - %d.%d: 0x%08x, 0x%08x [0x%08x]",
+ anim2_nr, part2_nr, c->init_event, c->anim_event, mask);
+
+ if (isClickablePart(part2, mask))
+ printf(" <--- TRIGGERED BY %d.%d",
+ anim_nr, part_nr);
+
+ printf("\n");
+#endif
+ }
+ }
+}
+
+static void HandleGlobalAnimEvent(struct GlobalAnimPartControlInfo *part,
+ int event_value, char *info_text)
+{
+#if DEBUG_ANIM_EVENTS
+ printf("::: %d.%d %s\n", part->old_anim_nr + 1, part->old_nr + 1, info_text);
+#endif
+
+ boolean anything_clicked = FALSE;
+ boolean any_event_action = FALSE;
+
+ // check if this event is defined to trigger other animations
+ InitGlobalAnim_Triggered(part, &anything_clicked, &any_event_action,
+ event_value);
+}
+
static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part,
int state)
{
if (part->init_delay_counter == 0 &&
!part->init_event_state)
+ {
PlayGlobalAnimSoundAndMusic(part);
+
+ HandleGlobalAnimEvent(part, ANIM_EVENT_START, "START [ANIM]");
+ }
+ else
+ {
+ HandleGlobalAnimEvent(part, ANIM_EVENT_INIT, "START [INIT_DELAY/EVENT]");
+ }
}
if (part->clicked &&
part->init_event_state = FALSE;
PlayGlobalAnimSoundAndMusic(part);
+
+ HandleGlobalAnimEvent(part, ANIM_EVENT_START, "START [ANIM]");
}
return ANIM_STATE_WAITING;
{
StopGlobalAnimSoundAndMusic(part);
+ HandleGlobalAnimEvent(part, ANIM_EVENT_END, "END [ANIM/OFF-SCREEN]");
+
part->post_delay_counter =
(c->post_delay_fixed + GetSimpleRandom(c->post_delay_random));
StopGlobalAnimSoundAndMusic(part);
+ HandleGlobalAnimEvent(part, ANIM_EVENT_END, "END [ANIM_DELAY/EVENT]");
+
part->post_delay_counter =
(c->post_delay_fixed + GetSimpleRandom(c->post_delay_random));
part->post_delay_counter--;
if (part->post_delay_counter == 0)
+ {
+ HandleGlobalAnimEvent(part, ANIM_EVENT_POST, "END [POST_DELAY]");
+
return ANIM_STATE_RESTART;
+ }
return ANIM_STATE_WAITING;
}
{
struct GlobalAnimPartControlInfo *part = &anim->part[part_nr];
+ if (part->triggered)
+ part->clicked = TRUE;
+
+ part->triggered = FALSE;
part->clickable = FALSE;
}
}
// always handle "any" click events (clicking anywhere on screen) ...
if (isClickablePart(part, ANIM_EVENT_ANY))
{
+#if DEBUG_ANIM_EVENTS
+ printf("::: => %d.%d TRIGGERED BY ANY\n",
+ part->old_anim_nr + 1, part->old_nr + 1);
+#endif
+
part->clicked = TRUE;
anything_clicked = clickConsumed(part);
}
if (isClickablePart(part, ANIM_EVENT_SELF))
{
+#if DEBUG_ANIM_EVENTS
+ printf("::: => %d.%d TRIGGERED BY SELF\n",
+ part->old_anim_nr + 1, part->old_nr + 1);
+#endif
+
part->clicked = TRUE;
anything_clicked = clickConsumed(part);
}
// check if this click is defined to trigger other animations
- int gic_anim_nr = part->old_anim_nr + 1; // X as in "anim_X"
- int gic_part_nr = part->old_nr + 1; // Y as in "part_Y"
- int mask = gic_anim_nr << ANIM_EVENT_ANIM_BIT;
-
- if (!part->is_base)
- mask |= gic_part_nr << ANIM_EVENT_PART_BIT;
-
- int anim2_nr;
-
- for (anim2_nr = 0; anim2_nr < ctrl->num_anims; anim2_nr++)
- {
- struct GlobalAnimMainControlInfo *anim2 = &ctrl->anim[anim2_nr];
- int part2_nr;
-
- for (part2_nr = 0; part2_nr < anim2->num_parts_all; part2_nr++)
- {
- struct GlobalAnimPartControlInfo *part2 = &anim2->part[part2_nr];
-
- if (part2->state != ANIM_STATE_RUNNING)
- continue;
-
- if (isClickablePart(part2, mask))
- {
- part2->clicked = TRUE;
- anything_clicked = clickConsumed(part); // click was on "part"!
-
-#if 0
- printf("::: %d.%d TRIGGER CLICKED [%d]\n", anim2_nr, part2_nr,
- part2->control_info.anim_event_action);
-#endif
-
- // after executing event action, ignore any further actions
- if (!any_event_action && DoGlobalAnim_EventAction(part2))
- any_event_action = TRUE;
- }
-
-#if 0
- struct GraphicInfo *c = &part2->control_info;
-
- printf("::: - %d.%d: 0x%08x, 0x%08x [0x%08x]",
- anim2_nr, part2_nr, c->init_event, c->anim_event, mask);
-
- if (isClickablePart(part2, mask))
- printf(" <--- TRIGGERED BY %d.%d",
- anim_nr, part_nr);
-
- printf("\n");
-#endif
- }
- }
+ InitGlobalAnim_Triggered(part, &anything_clicked, &any_event_action,
+ ANIM_EVENT_CLICK);
}
}
}