-
Notifications
You must be signed in to change notification settings - Fork 3
Types and Templates
Types and Templates are useful for 4 reasons:
- much like scripted_triggers and scripted_effects in normal script, using them makes your GUI script less redundant
- likewise, they also simplify changing your GUI, as modifying a Type or Template automatically translates to where they're used
- they can greatly expedite your GUI update process when vanilla releases a patch
- they're great for compatibility
A Type is a predefined widget that you can plug in.
If you want to display a button in GUI, you might use this:
button = {
text = "YOUR_LOCK_KEY"
}
If you use the same button 3 times in various places, you'll copy/paste that 3 times in your GUI script.
And when you want to add an onclick
effect to your button, you'll need to update it 3 times - but not if you use a Type.
Types can be defined in any .gui file, always outside of windows, in a top block, and you can define several types in the same block.
Be careful about the use of =
and brackets there, which is unusual:
types your_types {
type your_button = button {
text = "YOUR_LOC_KEY"
}
type your_widget = widget {
<...>
}
}
Then in your gui file, if you use
your_button = {}
It will do a basic text replacement, and work just like before. But now if you add a onclick
parameter to your type, all your buttons will get that behavior, without having to modify each one of them.
You can also add things to a type. If you want a different onclick for each button, you can use:
your_button = {
onclick = "[<...>]"
}
so this particular button will have that particular behaviour.
This example is quite simple, but to ensure that what you append to a type is inserted right where it needs to be, you can use blockoverrides.
In your type, define a block:
type your_button = button {
text = "YOUR_LOC_KEY"
block "button_onclick" {
onclick = "[<...>]"
}
}
When invoking the type, this will remove the default onclick behavior from that instance of the button:
your_button = {
blockoverride "button_onclick" {
}
}
while this will replace the default behavior with another one, specific to that instance of the button:
your_button = {
blockoverride "button_onclick" {
onclick = "[<...>]"
}
}