From: Holger Schemel Date: Tue, 12 Mar 2019 22:08:53 +0000 (+0100) Subject: added support for handling multiple event definitions for global animations X-Git-Tag: 4.1.3.0~41 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=5945d4cf6b675d43d102a1a2ab7d6ebd43a49ead;p=rocksndiamonds.git added support for handling multiple event definitions for global animations --- diff --git a/src/anim.c b/src/anim.c index 4ea38b41..49f346ee 100644 --- a/src/anim.c +++ b/src/anim.c @@ -990,27 +990,46 @@ static void PlayGlobalAnimSoundIfLoop(struct GlobalAnimPartControlInfo *part) PlayGlobalAnimSound(part); } -static boolean isClickablePart(struct GlobalAnimPartControlInfo *part, int mask) +static boolean checkGlobalAnimEvent(int anim_event, int mask) { - struct GraphicInfo *c = &part->control_info; int trigger_mask = ANIM_EVENT_ANIM_MASK | ANIM_EVENT_PART_MASK; int mask_anim_only = mask & ANIM_EVENT_ANIM_MASK; - int init_event = GetGlobalAnimEventValue(c->init_event, 0); - int anim_event = GetGlobalAnimEventValue(c->anim_event, 0); if (mask & ANIM_EVENT_ANY) - return (init_event & ANIM_EVENT_ANY || - anim_event & ANIM_EVENT_ANY); + return (anim_event & ANIM_EVENT_ANY); else if (mask & ANIM_EVENT_SELF) - return (init_event & ANIM_EVENT_SELF || - anim_event & ANIM_EVENT_SELF); + return (anim_event & ANIM_EVENT_SELF); else - return ((init_event & trigger_mask) == mask || - (anim_event & trigger_mask) == mask || - (init_event & trigger_mask) == mask_anim_only || + return ((anim_event & trigger_mask) == mask || (anim_event & trigger_mask) == mask_anim_only); } +static boolean isClickablePart(struct GlobalAnimPartControlInfo *part, int mask) +{ + struct GraphicInfo *c = &part->control_info; + int num_init_events = GetGlobalAnimEventValueCount(c->init_event); + int num_anim_events = GetGlobalAnimEventValueCount(c->anim_event); + int i; + + for (i = 0; i < num_init_events; i++) + { + int init_event = GetGlobalAnimEventValue(c->init_event, i); + + if (checkGlobalAnimEvent(init_event, mask)) + return TRUE; + } + + for (i = 0; i < num_anim_events; i++) + { + int anim_event = GetGlobalAnimEventValue(c->anim_event, i); + + if (checkGlobalAnimEvent(anim_event, mask)) + return TRUE; + } + + return FALSE; +} + static boolean isClickedPart(struct GlobalAnimPartControlInfo *part, int mx, int my, boolean clicked) { diff --git a/src/files.c b/src/files.c index 18207611..be19967a 100644 --- a/src/files.c +++ b/src/files.c @@ -10014,6 +10014,17 @@ int GetGlobalAnimEventValue(int list_pos, int value_pos) return gaeli->event_value[value_pos]; } +int GetGlobalAnimEventValueCount(int list_pos) +{ + if (list_pos == ANIM_EVENT_UNDEFINED) + return 0; + + struct GlobalAnimEventInfo *gaei = &global_anim_event_info; + struct GlobalAnimEventListInfo *gaeli = gaei->event_list[list_pos]; + + return gaeli->num_event_values; +} + // This function checks if a string of the format "string1, string2, ..." // exactly contains a string . @@ -10118,6 +10129,39 @@ static int get_anim_parameter_value(char *s) return result; } +static int get_anim_parameter_values(char *s) +{ + int list_pos = ANIM_EVENT_UNDEFINED; + int event_value = ANIM_EVENT_DEFAULT; + + if (string_has_parameter(s, "any")) + event_value |= ANIM_EVENT_ANY; + + if (string_has_parameter(s, "click:self") || + string_has_parameter(s, "click") || + string_has_parameter(s, "self")) + event_value |= ANIM_EVENT_SELF; + + // if animation event found, add it to global animation event list + if (event_value != ANIM_EVENT_NONE) + list_pos = AddGlobalAnimEventValue(list_pos, event_value); + + while (s != NULL) + { + // add optional "click:anim_X" or "click:anim_X.part_X" parameter + event_value = get_anim_parameter_value(s); + + // if animation event found, add it to global animation event list + if (event_value != ANIM_EVENT_NONE) + list_pos = AddGlobalAnimEventValue(list_pos, event_value); + + // continue with next part of the string, starting with next comma + s = strchr(s + 1, ','); + } + + return list_pos; +} + static int get_anim_action_parameter_value(char *token) { int result = getImageIDFromToken(token); @@ -10215,19 +10259,7 @@ int get_parameter_value(char *value_raw, char *suffix, int type) else if (strEqual(suffix, ".init_event") || strEqual(suffix, ".anim_event")) { - result = ANIM_EVENT_DEFAULT; - - if (string_has_parameter(value, "any")) - result |= ANIM_EVENT_ANY; - - if (string_has_parameter(value, "click")) - result |= ANIM_EVENT_SELF; - - // add optional "click:anim_X" or "click:anim_X.part_X" parameter - result |= get_anim_parameter_value(value); - - // final result is position in global animation event list - result = AddGlobalAnimEventValue(ANIM_EVENT_UNDEFINED, result); + result = get_anim_parameter_values(value); } else if (strEqual(suffix, ".init_event_action") || strEqual(suffix, ".anim_event_action")) diff --git a/src/files.h b/src/files.h index 6af3a148..60280804 100644 --- a/src/files.h +++ b/src/files.h @@ -88,6 +88,7 @@ void CreateCustomElementImages(char *); void FreeGlobalAnimEventInfo(void); int GetGlobalAnimEventValue(int, int); +int GetGlobalAnimEventValueCount(int); int get_parameter_value(char *, char *, int);