A simplified way to add Notifications

sman1975

Emperor
Joined
Aug 27, 2016
Messages
1,376
Location
Dallas, TX
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 :

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!
 
Well I've always just created dummy units that are unbuildable and unpurchasable. The game does not actually care that the unit's icon has nothing "unit-y" about it. It could be a red exclamation point if you wanted.

Or, as in this case, I just used the correct icon for the displaced unit:
Code:
		if bNotifyForCivilanDisplacements then
			local iGreatPersonUnit = pCivilian:GetUnitType()
			if pPlayer:IsHuman() then
				local sMessageShort = "Civilian Displaced"
				local sMessageFull = "A civilian " .. Locale.ConvertTextKey(GameInfo.Units[iGreatPersonUnit].Description) .. " unit was displaced to a friendly city"
				pPlayer:AddNotification(NotificationTypes["NOTIFICATION_GREAT_PERSON_ACTIVE_PLAYER"], sMessageFull, sMessageShort, pNearestCity:GetX(), pNearestCity:GetY(), iGreatPersonUnit, -1, false)
			end
		end
I've always found it as flexible as I have needed.

Never tried the dummy wonder approach
 
There's probably some (internal) limit to the maximum amount of buildings that can be active at the same time. (This is however not really an issue if you're only using it for a handful of notifications)
I can't specifically recall if <GreatWorkCount>-1</GreatWorkCount> will also hide the buildings in the Civilopedia, but it might be worth adding that if it does.
 
Thanks, y'all for the input. I believe you're both right - using the dummy "unit" might be a better idea than the dummy/hidden building - in case there are any capacity issues I don't know about out there - like the way Promotions are limited?

Will experiment with that next. Thanks again!
 
Back
Top Bottom