alpaca
King of Ungulates
- Joined
- Aug 3, 2006
- Messages
- 2,322
An improved version of this mod component was created by whoward69. You can find it here
This is now outdated
Modularized DiploCorner
I created a version of diplo corner that allows you to easily add new item to it and should preserve compatibility between mods if they all include this version.
To use it, just add it to your mod with VFS set to true for both DiploCorner.xml and DiploCorner.lua, then add your own Lua file that has the code for the button you want to add (see the example below) as a DiploCornerAddin in the content tab of your mod properties.
Resizing is handled automatically so there's no need to do anything much.
Tutorial
Step 1: Adding the DiploCorner
Extract the attached files to wherever your mod resides. Add them to your ModBuddy project by right-clicking on the folder they're in and selecting Add->Add existing item. Select both and click OK.
Select the files you just added in turn in ModBuddy and make sure to set ImportIntoVFS to True in the bottom right options inspector.
Step 2: Creating your button
Create a new Lua file in ModBuddy and give it a name of your choosing (I called it ImprovedNotifications_DiploCornerHook.lua). Make sure the filename you choose is something unique to your mod to avoid incompatibility with other mods, an easy way to do that is to prepend your modname to it. Set ImportIntoVFS to True for this file, too. Open it and put a code like the following into it:
What this file does is to invoke a LuaEvent I defined called DiploCornerAddin. This event takes a table as parameter that contains the data necessary for DiploCorner to create a new button.
The text property is the text that's displayed on the button. This property can be an index to a localization string, which is in fact recommended, or a string (like in the example).
The tip property works in the same fashion and allows you to add a tooltip if you so choose. The vanilla buttons don't have tooltips but adding one works flawlessly.
The more interesting part is the call property, which stores a function that is executed when the user clicks your button. For testing, this just prints a message to your Lua.log (and FireTuner). A slightly more complicated version that I use in the new version of my Notifications mod is this:
In the first part of the call function, I set up a new Lua Context for my NotificationOptions panel, which is stored in a file called NotificationOptions.lua that is added into my VFS. In the second part I queue it to the UI as a pop-up window.
The context is only set up the first time the user clicks the button. Afterwards, the old context is reused as a pop-up. Doing it like this allows me to keep local data for that context in the game's memory instead of having to load it again every time the button is clicked.
Step 3: Adding the DiploCornerAddin
Now we're almost done. All that remains is to add the DiploCornerAddin to the Content tab, like this:
Step 4: Testing
If everything worked correctly, you should now have a new button in the DiploCorner. Click it and your Lua.log should show you a message.
This is now outdated
Modularized DiploCorner
I created a version of diplo corner that allows you to easily add new item to it and should preserve compatibility between mods if they all include this version.
To use it, just add it to your mod with VFS set to true for both DiploCorner.xml and DiploCorner.lua, then add your own Lua file that has the code for the button you want to add (see the example below) as a DiploCornerAddin in the content tab of your mod properties.
Resizing is handled automatically so there's no need to do anything much.
Tutorial
Step 1: Adding the DiploCorner
Extract the attached files to wherever your mod resides. Add them to your ModBuddy project by right-clicking on the folder they're in and selecting Add->Add existing item. Select both and click OK.
Select the files you just added in turn in ModBuddy and make sure to set ImportIntoVFS to True in the bottom right options inspector.
Step 2: Creating your button
Create a new Lua file in ModBuddy and give it a name of your choosing (I called it ImprovedNotifications_DiploCornerHook.lua). Make sure the filename you choose is something unique to your mod to avoid incompatibility with other mods, an easy way to do that is to prepend your modname to it. Set ImportIntoVFS to True for this file, too. Open it and put a code like the following into it:
Code:
LuaEvents.DiploCornerAddin({ text="To click...", tip="... or not to click", call=function()
print("I am clicked! Woe is me!")
end})
What this file does is to invoke a LuaEvent I defined called DiploCornerAddin. This event takes a table as parameter that contains the data necessary for DiploCorner to create a new button.
The text property is the text that's displayed on the button. This property can be an index to a localization string, which is in fact recommended, or a string (like in the example).
The tip property works in the same fashion and allows you to add a tooltip if you so choose. The vanilla buttons don't have tooltips but adding one works flawlessly.
The more interesting part is the call property, which stores a function that is executed when the user clicks your button. For testing, this just prints a message to your Lua.log (and FireTuner). A slightly more complicated version that I use in the new version of my Notifications mod is this:
Code:
LuaEvents.DiploCornerAddin({ text="Notification Options", tip="Opens a window that allows you to choose which notifications you would like to receive.", call=function()
if notificationOptionsContext == nil then
notificationOptionsContext = ContextPtr:LoadNewContext("NotificationOptions")
end
UIManager:QueuePopup( notificationOptionsContext, PopupPriority.BarbarianCamp );
end})
In the first part of the call function, I set up a new Lua Context for my NotificationOptions panel, which is stored in a file called NotificationOptions.lua that is added into my VFS. In the second part I queue it to the UI as a pop-up window.
The context is only set up the first time the user clicks the button. Afterwards, the old context is reused as a pop-up. Doing it like this allows me to keep local data for that context in the game's memory instead of having to load it again every time the button is clicked.
Step 3: Adding the DiploCornerAddin
Now we're almost done. All that remains is to add the DiploCornerAddin to the Content tab, like this:
Step 4: Testing
If everything worked correctly, you should now have a new button in the DiploCorner. Click it and your Lua.log should show you a message.