sman1975
Emperor
I've been experimenting with a way of adding new Notifications that wouldn't require replacing existing NotificationPanel.lua, CustomNotification.lua, or ClassUtils.lua UIs.
The solution involves using a simple dummy/hidden building, something like this - based primarily from an idea from @LeeS :
The IconAtlas can be any atlas used to define Buildings. I don't care about the building, I just want an easy way to access the icon - to use as a Notification icon, and never a building. It will never be built, ever.
To launch the notification, the code is fairly direct. The notification "system" is going to view this dummy/hidden building as a 'wonder.'
Of course, there would be care taken about using Active Player or not, depending on the situation. Also, if there are multiple instantiations of the building (for multiple notification icons) under the single class, the calling function would have to track which specific building to use in the AddNotification method.
The advantages seem pretty straightforward. For the cost of a truncated building, I can get a brand new Notification icon, and not touch any existing UIs - which could greatly reduce compatibility with a lot of other mods that already do.
My question: Are there any potential downsides to using this approach?
Thanks!
The solution involves using a simple dummy/hidden building, something like this - based primarily from an idea from @LeeS :
Code:
<BuildingClasses>
<Row>
<Type>BUILDINGCLASS_SMAN_NOTIFICATION_DUMMY</Type>
<DefaultBuilding>BUILDING_SMAN_NOTIFICATION_DUMMY_BLUE</DefaultBuilding>
<Description>TXT_KEY_BUILDING_SMAN_NOTIFICATION</Description>
</Row>
</BuildingClasses>
<Buildings>
<Row>
<Type>BUILDING_SMAN_NOTIFICATION_DUMMY_BLUE</Type>
<BuildingClass>BUILDINGCLASS_SMAN_NOTIFICATION_DUMMY</BuildingClass>
<Description>TXT_KEY_BUILDING_SMAN_NOTIFICATION</Description>
<Cost>-1</Cost>
<PrereqTech>NULL</PrereqTech>
<MinAreaSize>-1</MinAreaSize>
<NeverCapture>true</NeverCapture>
<NukeImmune>true</NukeImmune>
<IconAtlas>SMAN_NOTIFICATION_ATLAS</IconAtlas>
<PortraitIndex>15</PortraitIndex>
</Row>
<!-- Insert more Buildings here, all using the same class, but a different Icon -->
</Buildings>
<Language_en_US>
<Row Tag="TXT_KEY_BUILDING_SMAN_NOTIFICATION">
<Text>SMAN Notification Marker</Text>
</Row>
</Language_en_US>
The IconAtlas can be any atlas used to define Buildings. I don't care about the building, I just want an easy way to access the icon - to use as a Notification icon, and never a building. It will never be built, ever.
To launch the notification, the code is fairly direct. The notification "system" is going to view this dummy/hidden building as a 'wonder.'
Code:
-- LUA code...
local iX = Players[Game.GetActivePlayer()]:GetCapitalCity():GetY()
local iY = Players[Game.GetActivePlayer()]:GetCapitalCity():GetY()
local NotificationStringLong = "Message body text..."
local NotificationStringFading = "Message title text..."
Players[Game.GetActivePlayer()]:AddNotification(NotificationTypes.NOTIFICATION_WONDER_COMPLETED, NotificationStringLong, NotificationStringFading, iX, iY, GameInfo.Buildings["BUILDING_SMAN_NOTIFICATION_DUMMY_BLUE"].ID, -1);
-- More LUA code...
Of course, there would be care taken about using Active Player or not, depending on the situation. Also, if there are multiple instantiations of the building (for multiple notification icons) under the single class, the calling function would have to track which specific building to use in the AddNotification method.
The advantages seem pretty straightforward. For the cost of a truncated building, I can get a brand new Notification icon, and not touch any existing UIs - which could greatly reduce compatibility with a lot of other mods that already do.
My question: Are there any potential downsides to using this approach?
Thanks!