Example #1
0
            /// <summary>
            /// Applied after MakeEventList runs.
            /// </summary>
            internal static void Postfix(List <Event> events, ref string __result)
            {
                string result = ModEvents.Describe(events);

                if (!string.IsNullOrEmpty(result))
                {
                    __result = result;
                }
            }
Example #2
0
        /// <summary>
        /// Creates friendly description text for mod events.
        /// </summary>
        /// <param name="events">The events which occurred.</param>
        /// <returns>A textual description of the events.</returns>
        public static string Describe(IList <Event> events)
        {
            var message = new StringBuilder();

            if ((events?.Count ?? 0) > 0)
            {
                var ti        = CultureInfo.CurrentCulture.TextInfo;
                var modEvents = new ModEvents(events);
                // Clean up extraneous events
                modEvents.DedupeEvents();
                message.AppendLine();
                // Determine how many events can be shown per category
                var types   = modEvents.EventTypes;
                int between = types.Count;
                if (between > 0)
                {
                    int leftover = MAX_EVENTS, perType = Math.Max(SMALL_EVENT_THRESHOLD,
                                                                  leftover / between);
                    // If any events have very few items, give their remaining space to others
                    foreach (var type in types)
                    {
                        int count = modEvents.GetEventsOfType(type)?.Count ?? 0;
                        if (count < perType)
                        {
                            between--;
                            leftover -= count;
                        }
                    }
                    if (between < 1)
                    {
                        perType = MAX_EVENTS;
                    }
                    else
                    {
                        perType = Math.Max(1, leftover / between);
                    }
                    // For each event type, list its elements
                    foreach (var type in types)
                    {
                        int count = perType;
                        message.Append("<size=16>");
                        message.Append(GetProperTitle(type, ti));
                        message.AppendLine("</size>:");
                        // Append the events
                        foreach (var evt in modEvents.GetEventsOfType(type))
                        {
                            message.Append(evt.mod.title);
                            // More information for some events
                            if (!string.IsNullOrEmpty(evt.details))
                            {
                                message.Append(" (");
                                message.Append(evt.details);
                                message.Append(")");
                            }
                            message.AppendLine();
                            // ... if too many
                            if (--count <= 0)
                            {
                                message.AppendLine(STRINGS.UI.FRONTEND.MOD_DIALOGS.
                                                   ADDITIONAL_MOD_EVENTS);
                                break;
                            }
                        }
                    }
                }
            }
            return(message.ToString());
        }