Modding GUI
Element positioning
Position. Element's position is calculated for its upper left corner relative to its parent.
Orientation changes the basepoint when calculating the position of the element relative to its parent. By default, it's upper_left. Other options are:
- UPPER_LEFT
- UPPER_RIGHT
- CENTER
- CENTER_UP
- CENTER_DOWN
- LOWER_LEFT
- LOWER_RIGHT
How to center elements
Use old CSS hacks of half-size back:
instantTextBoxType = {
name = "alice_readme_text"
position = { -235 -180 }
maxsize = { 460 160 }
fixedsize = yes
font = "Arial14"
Orientation = "CENTER_DOWN"
}
Scripting GUI
Scriptable buttons
Adding new buttons wouldn't mean much if you couldn't make them do things. To allow you to add custom button effects to the game, we have introduced two new ui element types: provinceScriptButtonType and nationScriptButtonType. These buttons are defined in the same way as a guiButtonType, except that they can be given additional allow and effect parameters. For example:
provinceScriptButtonType = {
name = "wololo_button"
extends = "province_view_header"
position = { x= 146 y = 3 }
quadTextureSprite = "GFX_wololo"
visible = {
tag = USA
}
allow = {
owner = { tag = FROM }
}
effect = {
assimilate = "yes please"
}
}
nationScriptButtonType = {
name = "wololo_button"
extends = "province_view_header"
position = { x= 146 y = 3 }
quadTextureSprite = "GFX_wololo"
visible = {
tag = USA
}
allow = {
owner = { tag = FROM }
}
effect = {
assimilate = "yes please"
}
ai_will_do = {
always = yes
}
}
How does it work:
- A province script button has its main and THIS slots filled with the province that the containing window is about, with FROM the player's nation.
- A nation script button has its main and THIS slots filled with the nation that the containing window is about, if there is one, or the player's nation if there is not, and has FROM populated with the player's nation.
- The
visibletrigger condition is optional and is used to determine when the button is rendered. If the allow condition is omitted, the button will always be enabled. - The
allowtrigger condition is optional and is used to determine when the button is enabled. If the allow condition is omitted, the button will always be enabled. - The tooltip for these scriptable buttons will always display the relevant allow condition and the effect. You may also optionally add a custom description to the tooltip by adding a localization key that is the name of the button followed by
_tooltip. In the case of the button above, for example, the tooltip is defined aswololo_button_tooltip;Wololo $PROVINCE$. The following three variables can be used in the tooltip:$PROVINCE$, which will resolve to the targeted province,$NATION$, which will resolve to the targeted nation or the owner of the targeted province, and$PLAYER$, which will always resolve to the player's own nation. - AI evaluates national scripted interactions once a month in a similar way to decisions.
- AI doesn't use province scripted interactions.
As a Modder, I want to mod scripted buttons, So that I add extra interactions to the game.
Acceptance Criteria:
| Criteria | Description |
|---|---|
| AC1 | Allow trigger is parsed |
| AC2 | Visible trigger is parsed |
| AC3 | Effect is parsed |
| AC4 | Ai_will_do block is parsed |
| AC5 | AI takes national interactions |
Toggleable windows
As a Modder, I want to mod buttons that toggle windows visibility, So that I add extra windows to the game.
Acceptance Criteria:
| Criteria | Description |
|---|---|
| AC1 | uiscriptbuttontype elements can have toggle_ui_key with a name of UI variable |
| AC2 | when clicking uiscriptbuttontype the associated UI variable is toggled True/False |
| AC3 | windowType elements can have visible_ui_key with a name of UI variable |
| AC4 | Window is shown only when UI variable in visible_ui_key is set to True |
| AC5 | uiscriptbuttontype can have visible triggers |
| AC6 | uiscriptbuttontype can have allow triggers |
uiscriptbuttontype = {
name = "starting_bonuses_button"
position = { x=425 y = 700 }
buttonText = "Starting Bonuses"
buttonFont = "vic_18_black"
spriteType = "GFX_button_standard_177"
extends="topbar"
toggle_ui_key = "starting_bonuses_window"
visible = {
OR = {
NOT = { has_country_flag = starting_bonus_0_selected }
NOT = { has_country_flag = starting_bonus_1_selected }
NOT = { has_country_flag = starting_bonus_2_selected }
}
}
}
windowType = {
name = "starting_bonuses_window"
position = { x = 400 y = 150 }
size = { x=310 y=600 }
moveable = 1
dontRender = ""
horizontalBorder = "0"
verticalBorder = ""
fullScreen = no
visible_ui_key = "starting_bonuses_window"
extends="topbar"
...
}
Scriptable images with dynamic frames through datamodels
As a Modder, I want to mod in icons that have dynamic frames, So that I add extra consistency to the UI.
Acceptance Criteria:
| Criteria | Description |
|---|---|
| AC1 | GUI elements can have datamodel with one of the datamodel options |
| AC2 | Datamodel can be state_religion |
| AC3 | When a supper element has datamodel="state_religion", it always displays the state religion of the player |
| AC4 | uiscriptbuttontype can have a datamodel |
| AC5 | iconType can have a datamodel |
uiscriptbuttontype = {
name = "religion_button"
position = { x=485 y = 5 }
spriteType = "GFX_icon_religion"
extends="topbar"
datamodel = "state_religion"
toggle_ui_key = "religion_window"
}