From: Holger Schemel Date: Thu, 14 Mar 2019 01:15:36 +0000 (+0100) Subject: added several new event types that can trigger global animations X-Git-Tag: 4.1.3.0~36 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=f4d75550969f97716de4b9f5340b8fcf835ab7fc;p=rocksndiamonds.git added several new event types that can trigger global animations This change adds the following new global animations event types, which can be used like the already existing "click:anim_X.part_Y": * init:anim_X.part_Y - triggers when animation is initialized * start:anim_X.part_Y - triggers when animation is started * end:anim_X.part_Y - triggers when animation ends * post:anim_X.part_Y - triggers when animation post delay ends The second part ".part_Y" is optional; if missing, events for every animation part will trigger the animation for which this event is defined. The "init" event will trigger even if the animation is not yet displayed, but starts waiting for its "init_delay" or "init_event", while the "start" event will trigger when the first frame of the animation is displayed. The "end" event will trigger when the last frame of the animation is displayed (either because the animation has stopped due to a click event, due to the "anim_delay" being finished or because the animation has completely moved off the screen), while the "post" event will trigger when the "post_delay" is completely finished. --- diff --git a/src/anim.c b/src/anim.c index cb2dc881..fcf7ef36 100644 --- a/src/anim.c +++ b/src/anim.c @@ -1133,6 +1133,21 @@ static void InitGlobalAnim_Triggered(struct GlobalAnimPartControlInfo *part, } } +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) { @@ -1249,7 +1264,15 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, 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 && @@ -1282,6 +1305,8 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, part->init_event_state = FALSE; PlayGlobalAnimSoundAndMusic(part); + + HandleGlobalAnimEvent(part, ANIM_EVENT_START, "START [ANIM]"); } return ANIM_STATE_WAITING; @@ -1308,6 +1333,8 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, { StopGlobalAnimSoundAndMusic(part); + HandleGlobalAnimEvent(part, ANIM_EVENT_END, "END [ANIM/OFF-SCREEN]"); + part->post_delay_counter = (c->post_delay_fixed + GetSimpleRandom(c->post_delay_random)); @@ -1329,6 +1356,8 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, StopGlobalAnimSoundAndMusic(part); + HandleGlobalAnimEvent(part, ANIM_EVENT_END, "END [ANIM_DELAY/EVENT]"); + part->post_delay_counter = (c->post_delay_fixed + GetSimpleRandom(c->post_delay_random)); @@ -1345,7 +1374,11 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, 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; } diff --git a/src/files.c b/src/files.c index 9f20487f..5ec5f7f0 100644 --- a/src/files.c +++ b/src/files.c @@ -10066,11 +10066,19 @@ static int get_anim_parameter_value(char *s) { int event_value[] = { - ANIM_EVENT_CLICK + ANIM_EVENT_CLICK, + ANIM_EVENT_INIT, + ANIM_EVENT_START, + ANIM_EVENT_END, + ANIM_EVENT_POST }; char *pattern_1[] = { - "click:anim_" + "click:anim_", + "init:anim_", + "start:anim_", + "end:anim_", + "post:anim_" }; char *pattern_2 = ".part_"; char *matching_char = NULL; diff --git a/src/libgame/system.h b/src/libgame/system.h index d0584d4b..8bcafb82 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -358,6 +358,10 @@ #define ANIM_EVENT_SELF (1 << 16) #define ANIM_EVENT_ANY (1 << 17) #define ANIM_EVENT_CLICK (1 << 18) +#define ANIM_EVENT_INIT (1 << 19) +#define ANIM_EVENT_START (1 << 20) +#define ANIM_EVENT_END (1 << 21) +#define ANIM_EVENT_POST (1 << 22) // anim number: bits 0-7 // part number: bits 8-15