MessagePopup

alpaca

King of Ungulates
Joined
Aug 3, 2006
Messages
2,322
I wrote a small pop-up window that can display a message and some buttons to the player by simply triggering a Lua event.


Simple Usage

First of all, add the two files to your mod and make sure Import into VFS is set to true for both, and add MessagePopup as an InGameUIAddin.

The easiest way to use this is to just create a message popup with a message, for example "test" and a button called "Close". To do this, call LuaEvents.DisplayMessage("test"). This will create a message without title, just your text and a close button.

To add a title, simply add a second argument to the function call: LuaEvents.DisplayMessage("test", "title")

There's more, though. If you want to keep just one button with a custom text and add a tooltip or callback function to it, you can call add even more arguments (all of them optional): LuaEvents.DisplayMessage("test", "title", "my button", "this is my button, shiny, eh?", function() print("my button clicked") end)


Advanced Usage

Even better, you can add multiple buttons by passing tables as arguments 3-5. This is a bit more complicated and in the case that argument 3 is a table, the key will be used as button text while the value will be displayed as a tooltip. If you don't want a tooltip, set the value to false, like this (note that the order of the buttons is unpredictable): LuaEvents.DisplayMessage("test", "title", {["button 1"] = "button 1 has a tooltip", ["button 2"] = false})

Argument 4 in this case takes an optional table that you can use to re-order the buttons. Like this to make sure button 1 comes before button 2: LuaEvents.DisplayMessage("test", "title", {["button 1"] = "button 1 has a tooltip", ["button 2"] = false}, {"button 1", "button 2"})

Argument 5 allows you to add a callback function to each button, where the key is the table key from argument 3: LuaEvents.DisplayMessage("test", "title", {["button 1"] = "button 1 has a tooltip", ["button 2"] = false}, {"button 1", "button 2"}, {["button 1"] = function() print("button 1 clicked") end, ["button 2"] = function() print("button 2 clicked") end})


Expert Usage

If that is not enough customization for you and you need more fancy crap, I also added another event called DisplayPopup that allows you to provide your own set-up function that will be called to create the message pop-up and where you can add your own buttons and multiple texts. Since you're an expert, I'll leave it up to you to figure out how to do that if you really need it.


Useful Localisation Strings

Lastly, here are some localisation strings you may want to use:

  • Close: Locale.ConvertTextKey("TXT_KEY_CLOSE")
  • Yes: Locale.ConvertTextKey("TXT_KEY_POPUP_YES")
  • No: Locale.ConvertTextKey("TXT_KEY_POPUP_NO")
  • OK: Locale.ConvertTextKey("TXT_KEY_OK_BUTTON")

--------------------------------------

Enjoy! One last thing: If you add a tooltip or use other table keys than strings for argument 3, the script automatically calls a tostring on it, so you can feed it numbers and whatever. Wouldn't really recommend it, though.
 

Attachments

  • messagepopup.png
    messagepopup.png
    60.4 KB · Views: 145
  • MessagePopup_1.rar
    MessagePopup_1.rar
    2.1 KB · Views: 70
A standard confirmation dialog box with endless extensibility. Another wonderful addition for the modding community. We could use more like you, alpaca. :thumbsup:
 
Back
Top Bottom