Custom Alerts Framework

KayleeR

Chieftain
Joined
Feb 11, 2025
Messages
42
Custom Alerts Framework implements a manager to intercept calls to Game. Notifications allowing for mods to implement custom alerts.

Custom Alerts Framework:
Framework only - provides the ability for other mods to implement custom alerts. Dependency for all sub-mods.

Purchase Alerts:
Set reminders for when you're able to afford purchasing buildings/units or beginning diplomatic interactions.

PurchaseAlerts-Alert.JPG

PurchaseAlert-Build.JPG

PurchaseAlert-DiplomacyAlerts.JPG


First Settler Alert
Proof of concept with a simple alert when you're first able to produce a settler at 5 population in Antiquity.

first-settler-notification.JPG


Notes:
I've currently only tested this in the antiquity age. It's possible there are bugs with any number of existing alerts or other code. There are some calls to Game.Notifications in the tutorials that I didn't intercept; I believe those should still work fine but haven't tested that either.
 
Last edited:
How to create a custom alert:

Provide an Alert Handler likely using NotificationHandlers.DefaultHandler as the base. Implement getSummaryText and getMessageText to provide localization text for the alert.
JavaScript:
class FirstSettlerAlertHandler extends NotificationHandlers.DefaultHandler {
    activate(notificationId, _activatedBy) {
        const notification = CustomNotificationHandler.find(notificationId);
        if (notification && (notification.Target != undefined) && ComponentID.isValid(notification.Target)) {
            UI.Player.lookAtID(notification.Target);
            UI.Player.selectCity(notification.Target); // This will currently auto-open the production chooser.
            const cityLocation = Cities.get(notification.Target)?.location;
            if (cityLocation) {
                PlotCursor.plotCursorCoords = cityLocation;
            }

            // Dismiss this notification
            CustomNotificationHandler.dismiss(notificationId);
            return true;
        }
        return false;
    }
    getSummaryText(notificationId) {
        return Locale.compose("LOC_NOTIFICATION_CAN_PRODUCE_FIRST_SETTLER_SUMMARY");
    }
    getMessageText(notificationId) {
        return Locale.compose("LOC_NOTIFICATION_CAN_PRODUCE_FIRST_SETTLER_MESSAGE");
    }
}

When you want to fire an alert create a notification object and call CustomNotificationHandler.addCustomNotification. Ensure the Type uses Game.getHash on your notification id string.
JavaScript:
            var notification = {
                Type: Game.getHash("NOTIFICATION_CAN_PRODUCE_FIRST_SETTLER"), // custom notification
                SeverityLevel: 0,
                Location: null,
                Target: foundCity?.id,
                AddedOnTurn: Game.turn,
                ExpireOnTurnDelta: 0,
                CanUserDismiss: true,
                BlocksTurnAdvancement: true,
                Expired: false,
                AutoActivate: false,
                Dismissed: false,
                GroupType: -1225125244,
            };
            CustomNotificationHandler.addCustomNotification(notification);

On startup register your event handler with CustomNotificationHandler:
JavaScript:
engine.whenReady.then(() => {
    CustomNotificationHandler.registerCustomNotification("NOTIFICATION_CAN_PRODUCE_FIRST_SETTLER", new FirstSettlerAlertHandler);
});

You'll likely want a helper class that registers game event handlers to check for conditions to fire the custom alert.

See this thread for information on how to provide optional functionality only if the framework is installed:
 
Last edited:
Finally implementing what I wanted from the start of this work with alerts for purchasing buildings/units and for starting diplomatic interactions. I've played a decent amount of Antiquity using it often but there's likely still some issues especially with validating when you can start some diplomatic interactions. Most likely issues are with interactions that involve more than just spending influence, for example selecting a target. Next I want to look at alerts for when you can afford to turn a town into a city and when you can first declare a formal war or propose peace or form an alliance. If anyone has other ideas for alerts that would be useful let me know and I can take a look at feasibility. I'm not entirely happy with the sepia highlight effect on the chosen item in the purchase/diplomacy screen and want to look into better options but the few others I tried all had issues.

 
Finally implementing what I wanted from the start of this work with alerts for purchasing buildings/units and for starting diplomatic interactions. I've played a decent amount of Antiquity using it often but there's likely still some issues especially with validating when you can start some diplomatic interactions. Most likely issues are with interactions that involve more than just spending influence, for example selecting a target. Next I want to look at alerts for when you can afford to turn a town into a city and when you can first declare a formal war or propose peace or form an alliance. If anyone has other ideas for alerts that would be useful let me know and I can take a look at feasibility. I'm not entirely happy with the sepia highlight effect on the chosen item in the purchase/diplomacy screen and want to look into better options but the few others I tried all had issues.
Great ideas! I love the alerts for things I can’t afford yet (because of gold/influence shortage), and also a “can make peace” alert.
 
Updated the framework to copy over the changes to the base ui that I'm overwriting. Purchase Alerts appear to function just fine but for some reason the button image isn't loading any more; I'll have to spend some time digging into that later.
 
Back
Top Bottom