1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

UI - Notification Options

Discussion in 'Civ5 - Mod Components' started by whoward69, Jun 5, 2012.

  1. Drawmeus

    Drawmeus Emperor

    Joined:
    Jul 25, 2007
    Messages:
    1,213
    The lua file:

    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.
     
  2. trystero49

    trystero49 Prince

    Joined:
    Apr 30, 2012
    Messages:
    515
    Code:
    	<Instance Name="EmigrationItem" >
    		<Container Anchor="R,C" Size="80,80" Offset="0,0"  Hidden="0" ID="EmigrationContainer" ConsumeMouseButton="1" >
    			<SlideAnim Anchor="L,T" Style="NotificationSlide" ID="NotificationSlide" >
    				<AlphaAnim Style="NewFinger" />
    				<Button Anchor="R,C" Size="80,80" Offset="0,0" Texture="assets\UI\Art\Notification\NotificationFrameBase.dds" ID="EmigrationButton"  Hidden="0" >
    					<ShowOnMouseOver>
    						<Image Anchor="C,C" Offset="0,0" Size="80,80" Texture="assets\UI\Art\Notification\NotificationFrameBase.dds" />
    						<AlphaAnim  Anchor="C,C"  AnchorSide="O.O"  Offset="0,0" Size="80,80" Texture="assets\UI\Art\Notification\NotificationCityGrowthRed.dds"  Pause="0" Cycle="Bounce" Speed="1" AlphaStart="1" AlphaEnd="0" Hidden="0"/>
    					</ShowOnMouseOver>
    					<Image Anchor="C,C" Offset="0,0" Size="80,80" Texture="assets\UI\Art\Notification\NotificationCityGrowthRed.dds" />
    					<AlphaAnim Anchor="C,C" Offset="0,0" Size="80.80"  TextureOffset="0.0" Texture="assets\UI\Art\Notification\NotificationCityGrowthRedGlow.dds"  Pause="0" Cycle="Bounce" Speed="1" AlphaStart="0" AlphaEnd="1"/>
    				</Button>
    			</SlideAnim>
    		</Container>
    	</Instance>
    
    This is the code that I have as the Emigration notification. I've managed to get it to work properly with this modcomp. It's slightly different than yours, in terms of what "Texture" is defined as.

    Also, I noticed your lua doesn't have a click event. Mine works like this:

    Code:
    function OnLookAt(pPlot)
      if (pPlot ~= nil) then
        UI.LookAt(pPlot)
      end
    end
    
    function OnEmigrationNotification(cbData)
      local instance = {}
      ContextPtr:BuildInstanceForControl("EmigrationItem", instance, cbData.parent)
      cbData.instance = instance
      pPlot = Map.GetPlot(cbData.iExtra1, cbData.iExtra2)
      -- MUST use a closure (anonymous function) as the click event
      instance.EmigrationButton:RegisterCallback(Mouse.eLClick, function() OnLookAt(pPlot) end) 
    end
    Emigration.callback = OnEmigrationNotification
    
    I don't recognize the OnEmigrationEvent function, but when I call the notification I do this:
    Code:
    fromPlayer:AddNotification(g_EmigrationNotificationType, txt, smr, fromCity:GetX(), fromCity:GetY(), fromCity:GetX(), fromCity:GetY())
    I hope that helps.
     
  3. Drawmeus

    Drawmeus Emperor

    Joined:
    Jul 25, 2007
    Messages:
    1,213
    Would you mind posting your complete lua function, or PMing it to me/zipping it up/w.e. is easiest?
     
  4. EndoConvert

    EndoConvert Warlord

    Joined:
    Dec 17, 2010
    Messages:
    297
    Hmm, how do I make that dialog appear in the game? After downloading, installing (putting the file in the mods folder), and activating (via the Mods menu) the "UI - Notification Options (GK) (v 4)" mod, I don't see any button anywhere in the game interface to make that dialog appear. :confused:
     
  5. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,370
    Location:
    Near Portsmouth, UK
    It's on the "Diplo Corner" menu (scroll icon top right), should be under the standard Notification Log option
     
  6. ww2commander

    ww2commander Emperor

    Joined:
    Aug 23, 2003
    Messages:
    1,243
    Location:
    Australia
    How do you reference an image in a grid based file such as units, buildings?
     
  7. EndoConvert

    EndoConvert Warlord

    Joined:
    Dec 17, 2010
    Messages:
    297
    Yeah, I figured that it would be there because that was where Alpaca's old Improved Notifications mod had them, but there was no such button in that menu.

    I then disabled all other mods and cleared out my cache ("Documents\My Games\Sid Meier's Civilization 5\cache") and tried again.

    But now when I start a game with that mod and NO OTHER MODS, I get the following when the game starts up:

    Spoiler :


    Spoiler :


    Basically, I get an empty Notification Options dialog box, with nothing in it. To make things worse, I can't make the box go away. If I click on the "Close" button at the bottom right, doing so depresses the button, but does NOT make the dialog box go away. Pressing the escape (ESC) key doesn't work either. So I get trapped with that dialog box that won't go away. :(

    Any ideas how to fix this? :confused: Thanks.
     

    Attached Files:

  8. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,370
    Location:
    Near Portsmouth, UK
    What's in Lua.log?
     
  9. EndoConvert

    EndoConvert Warlord

    Joined:
    Dec 17, 2010
    Messages:
    297
    In case it matters, my OS is Win7. Here is the relevant section, as well as a few surrounding lines, of the log, with my username edited out and replaced with %USERNAME% for privacy:

    Code:
    [37661.433] ChoosePantheonPopup: -314
    [37661.433] ChoosePantheonPopup: 963
    [37661.433] ChoosePantheonPopup: 649
    [37663.352] NotificationOptions: This is the 'UI - Notifications Options' mod script.
    [37663.368] Runtime Error: [string "C:\Users\%USERNAME%\Documents\My Games\Sid Mei..."]:133: table index is nil
    stack traceback:
    	[string "C:\Users\%USERNAME%\Documents\My Games\Sid Mei..."]:133: in main chunk
    	[C]: ?
    [37663.368] Runtime Error: Error loading C:\Users\%USERNAME%\Documents\My Games\Sid Meier's Civilization 5\MODS\UI - Notification Options (GK) (v 4)\UI/NotificationOptions.lua.
    [37664.428] Demographics: Dequeuing demographics
    [37664.428] Demographics: Dequeuing demographics
    [37677.533] TechTree: REFRESHING TECH DISPLAY
    
     
  10. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,370
    Location:
    Near Portsmouth, UK
    Obvious questions first

    1) G&K or Vanilla?
    2) PC or Mac
    3) What's the build number (you can find this at the very bottom of the Main Menu)

    And can you confirm that line 133 in that file reads as

    Code:
    g_Notifications[NotificationTypes.NOTIFICATION_REQUEST_RESOURCE] = {item="BonusResource", key="NOTIFICATION_REQUEST_RESOURCE", show=true, ui=true}
    
     
  11. EndoConvert

    EndoConvert Warlord

    Joined:
    Dec 17, 2010
    Messages:
    297
    1) G&K
    2) PC, and for that matter, Win7, as I mentioned in my earlier post
    3) 1.0.1.674

    Line 133 of NotificationOptions.lua indeed exactly reads that.

    I tried commenting just that line out, and, OMG, it looks like now the mod works! :D I now get a non-empty dialog box which actually goes away when I click the "Close" button! :cool: Thanks so much for your help! :goodjob:

    At least I think it works... I haven't really had a chance to try it out much yet, but I did have one question: in contrast to the screenshot in your original post which only has one column of checkmarks, the dialog box I'm seeing has two columns of checkmarks:

    Spoiler :


    Is this what I'm supposed to be seeing? (That is, did you change the mod from that original version with only one column of checkmarks?) And if so, what's the difference between the two columns?
     

    Attached Files:

  12. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,370
    Location:
    Near Portsmouth, UK
    That version is ancient, you need to upgrade. The latest version is 1.0.2.21
     
  13. EndoConvert

    EndoConvert Warlord

    Joined:
    Dec 17, 2010
    Messages:
    297
    Thanks. What about the checkmarks? Are there supposed to be two columns of checkmarks?
     
  14. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,370
    Location:
    Near Portsmouth, UK
    Yes, IIRC the left hand one is for the User, the right for the Current Game. Uncheck the left hand one and you will never see those alerts again for any games player, uncheck the right hand one and you will not see any more of those alerts for the current game
     
  15. EndoConvert

    EndoConvert Warlord

    Joined:
    Dec 17, 2010
    Messages:
    297
    Just one more note on this, in case anyone is interested: I looked around the code some more and found out that rather than commenting out line 133, an alternative way to fix the problem I was having was to change the word "REQUEST" to "DEMAND", so that the line reads:

    Code:
    g_Notifications[NotificationTypes.NOTIFICATION_DEMAND_RESOURCE] = {item="BonusResource", key="NOTIFICATION_DEMAND_RESOURCE", show=true, ui=true}
    
     
  16. EndoConvert

    EndoConvert Warlord

    Joined:
    Dec 17, 2010
    Messages:
    297
    On a different subject, just thought I'd report two issues, with an attached savegame (which, by the way, requires the Info Addict mod) to reproduce.

    First, and this is just a minor cosmetic-only issue (display-only issue) with no gameplay effect, is that there are two apostrophes in the "Spy Can''t Steal Tech" choice in the dialog box when there should only be one, as seen in this screenshot:

    Spoiler :


    Second, and this is the more important thing, there is a issue that was also in alpaca's Improved Notifications mod from a couple years ago, so I think it's something left over from that which was never fixed? Basically, when a city has tiles extending beyond the 3-tile working range of the city (that is, it only affects tiles owned by a city that are at least 4 tiles distant from the city, meaning you will mostly see this issue if you play culturally and grow tall rather than REX/ICS and grow wide), whenever you load a savegame, the notifications for ALL such 4+ distance tiles will reappear as if the growth took place in the turn you loaded the game, hitting you with notifications and flooding your notifications log. See these screenshots:

    Spoiler :


    Spoiler :


    Obviously, the city didn't claim all those tiles in this single turn. The problem only occurs on the turn that you load the game; if you play to the next turn, you won't get hit with the notifications again, though your notifications log will still be filled with the notifications. The problem is not restricted to this one savegame, though, in the sense that if you continue playing on to the next turn, and then save the game again, this time to a different savefile, and then load that new 2nd savefile, that 2nd savefile will be afflicted with the same problem.
     

    Attached Files:

  17. BJV_Coug

    BJV_Coug Chieftain

    Joined:
    Feb 19, 2013
    Messages:
    29
    whoward69, so do I understand correctly that I install and use your mod and then add the additional codes (as shown in some of the posts) to my mod? To replace a notification, the bombard example is the one to follow correct? Also, I've never encountered making changes to the .modinfo file, can you give me a little more information on that? Thanks.
     
  18. Rowger

    Rowger Chieftain

    Joined:
    Jul 3, 2017
    Messages:
    93
    Gender:
    Male
    This mod just vanishes all options for me (diplomacy, world congress, victory progress, etc)
     

Share This Page