CustomNotifications

Bhruic

Emperor
Joined
Nov 15, 2005
Messages
1,457
Ok, I've got a working CustomNotification module... Completely unlocked from any other script, and fully customizable. Updated: Now with generated type values.

Functions to note:
LuaEvents.SetCustomNotificationDetails(table, name, LeftClickCallback, RightClickCallback)

This needs to be called before any notifications are added to ensure that the mod knows how to handle your specific notifications.

table - updated - This table will return a type for your mod. You need to precreate the table with something like "local table = {type=0}", the important part being the inclusion of the "type" label. Upon return from the function, "type" will be updated with a unique reference number for your mod, which you will use for the following functions when they request "type".

name - This corresponds to the button type names within the g_NameTable[] variable. The most commonly used button is "Generic", but others exist - see the table for the various names available.

LeftClickCallback - This will be a callback to how you want a Left Click on your notification to be handled. This should be setup as a LuaEvent to ensure that it's callable from the Notification.lua mod. The name you use in your mod will need to be unique, as LuaEvents are available to all Lua scripts.

RightClickCallback - Ditto for the above, but for right clicks.

LuaEvents.RemoveCustomNotification(Id, type)

This will remove a specific notification from the list on the right side of the screen. Generally this will be called by your RightClickCallback function.

Id - Each notification needs a unique Id to identify it

type - The type that was obtained from the function above

LuaEvents.AddCustomNotification(Id, type, toolTip, strSummary)

This will add a new notification.

Id - As above, this must be a unique identifier for this specific notification. Generally it's easiest to have an incrementing global variable in your mod to identify each notification

type - As above, the type that was obtained from the first function

toolTip - This is the text that is displayed when the mouse hovers over the notification

strSummary - This is the text that is displayed when the notification first appears on the screen to identify it

Bh
 

Attachments

  • CustomNotificationPanel (v 2).civ5mod
    7.6 KB · Views: 252
Example:
Code:
local g_Locations = {}
local g_Counter = 0;
local g_Type;

-- Both callback functions get passed the Id of the notification being clicked on
-- In this example, the x and y co-ordinates of the notification are stored in g_Locations when the notification
-- is created, and then are looked up by the left mouse click function, and the camera will pan to that location

LuaEvents.ExampleLeftClickCallback.Add(
function(Id)
    local x = g_Locations[Id][1];
    local y = g_Locations[Id][2];

    plot = Map.GetPlot(x, y);
    UI.LookAt(plot, 0);
end};

-- A right click will simply remove the notification from the list

LuaEvents.ExampleRightClickCallback.Add(
function(Id)
    LuaEvents.RemoveCustomNotification(Id, g_Type);
end};

function ExampleNotification
    local x = Map.Rand(10, "Generic roll");
    local y = Map.Rand(10, "Generic roll");

    g_Counter = g_Counter + 1;
    g_Locations[g_Counter] = {x, y};
    LuaEvents.AddCustomNotification(g_Counter, g_Type, "Fooled you!", "This is very important, click here");
end

-- By calling this outside of a function, it's ensured to run before any attempts are made to add a notification

local table = {type=0};
LuaEvents.SetCustomNotificationDetails(table, "Generic", LuaEvents.ExampleLeftClickCallback, LuaEvents.ExampleRightClickCallback) 
g_Type = table.type;
 
The only problem I have now is that the "Dependencies" part in ModBuddy doesn't seem to be functional, so I'm not sure how to force them. This mod doesn't do anything by itself, so what's the best distribution method? Should it just be included in each mod? Is there any way to make the in-game Mod browser download this mod for other mods that use it?

Bh
 
I'll have to look at how the custom notifications are stored, but it should be possible to write a function that can autogenerate a unique index so that multiple mods using this can avoid conflicts without modders manually coordinating their indices. I do a simple form of one in my mod to insert my resources info panel into the InfoCornerID list.
 
Out of curiosity, if two mods include exactly the same Custom Notifications code... will it conflict? I know using two different files will conflict, but can mods use exactly the same one?
 
That's what I'm not sure about. If they have identical code, I'd hope not. But if it actually runs both of them, it'd setup multiple LuaEvents, which would obviously be a problem.

Bh
 
That's what I'm not sure about. If they have identical code, I'd hope not. But if it actually runs both of them, it'd setup multiple LuaEvents, which would obviously be a problem.

Bh

Hmm. I guess we need those dependencies working. :(
 
Yes, it would be great if SetCustomNotificationDetails() created and returned a unique type for the modder to pass later and AddCustomNotification() created and returned a unique ID (per type or globally doesn't matter I guess) to pass to RemoveCustomNotification().
 
The first one might be possible. The second one doesn't really matter, the Id only has to be unique to your mod, it doesn't have to be unique globally. So whether this mod does it, or your mod does it, it just needs to be done. And since you'll likely want to track the Id for the callback functions anyway, it makes more sense to me to have your mod do it.

But as long as I can return a value via a LuaEvents call, then yes, it should be feasible to allow it to determine unique types.

Bh
 
Good point about going through the LuaEvents call. If you can return a value, I say better to generate and return it. Yes, the modder can do it themselves fairly easily, but you can do it once easily and save that work for every modder. ;)
 
Hmm, doesn't look like LuaEvents allows you to return a value... So the next option would be annoyingly kludgy, but passing the type as a table would allow it to be changed by the SetCustomNotificationDetails() function and returned.

Bh
 
Ok, I've uploaded a new version that will generate unique types for each mod. As I mentioned above, I couldn't do it via return, so I had to muck through with a table. I've updated the example (as well as the description) to illustrate how that is accomplished.

Bh
 
You can create a function that the modder calls, passing the same stuff you have being passed to LuaEvents. In that function, generate the type/id as needed, call LuaEvents, and return it. Sorry to only give design ideas right now; too busy to mod but that'll change very soon.
 
Top Bottom