The lua file:
There's some fumbling around in there, and I got in the habit of putting the listener for the event that is supposed to cause the notification in that lua file, but that's the complete text of the lua file.
Everything about the notification is working exactly as I expect except the icon.
Code:
include("IconSupport")
-- Data structure about the notification, passed in the LuaEvent below
local Emigration = {
label = "TXT_KEY_EMIGRATION_NOTIFICATION_LABEL",
key = "EMIGRATION_NOTIFICATION",
item = "EmigrationNotification",
show = true,
ui = true,
}
-- This is executed when the notification is issued, build the entry for the list and hook up any events
function OnEmigrationNotification(cbData)
local instance = {}
ContextPtr:BuildInstanceForControl("EmigrationItem", instance, cbData.parent)
cbData.instance = instance
end
Emigration.callback = OnEmigrationNotification
-- We have to get a bit defensive here as Firaxis keep changing the order that events fire.
-- This approach means we don't care if this code executes before or after the "UI - Notifications Options" code
function OnEmigrationNotificationIdRequest()
if (Emigration.id ~= nil) then
LuaEvents.EmigrationNotificationId(Emigration.id)
end
end
LuaEvents.EmigrationNotificationIdRequest.Add(OnEmigrationNotificationIdRequest)
function Register()
LuaEvents.CustomNotificationAddin(Emigration) -- Name of the data structure at the top of the file
OnEmigrationNotificationIdRequest()
end
Register()
function OnEmigrationEvent(pFromPlayer, pToPlayer, pFromCity)
local strToName = Locale.ConvertTextKey(pToPlayer:GetNameKey());
local strFromCity = Locale.ConvertTextKey(pFromCity:GetNameKey());
local heading = Locale.ConvertTextKey("TXT_KEY_EMIGRATION_EVENT_HEADING", strToName);
local text = Locale.ConvertTextKey("TXT_KEY_EMIGRATION_EVENT_TEXT", strFromCity, strToName);
pFromPlayer:AddNotification(g_EmigrationNotificationType, text, heading, -1, -1, 0);
end
LuaEvents.EmigrationEvent.Add( OnEmigrationEvent );
There's some fumbling around in there, and I got in the habit of putting the listener for the event that is supposed to cause the notification in that lua file, but that's the complete text of the lua file.
Everything about the notification is working exactly as I expect except the icon.