Godot 4.2.2
Question
I want to load textures for TextureButton
with Theme
set in code.
I have paths to files
@export_group('Buttons')
@export_subgroup('Textures')
@export_file('*.png', '.jpg') var button_texture_normal := "res://addons/dialogic_additions/DefaultLayoutParts/Layer_TextureChoice/button_textures/normal.png"
@export_file('*.png', '.jpg') var button_texture_hovered := "res://addons/dialogic_additions/DefaultLayoutParts/Layer_TextureChoice/button_textures/hover.png"
@export_file('*.png', '.jpg') var button_texture_pressed := "res://addons/dialogic_additions/DefaultLayoutParts/Layer_TextureChoice/button_textures/pressed.png"
@export_file('*.png', '.jpg') var button_texture_disabled := ""
@export_file('*.png', '.jpg') var button_texture_focused := ""
Overrides stored in theme
variable and then applied to layer’s root node.
But I don’t know how to load textures correctly.
I tried StyleBoxTexture
but it didn’t work.
var theme: Theme = Theme.new()
if ResourceLoader.exists(button_texture_normal):
var style_box: StyleBoxTexture = StyleBoxTexture.new()
style_box.texture = load(button_texture_normal)
theme.set_stylebox('texture_normal', 'TextureButton', style_box)
theme.set_stylebox('texture_hover', 'TextureButton', style_box)
theme.set_stylebox('texture_pressed', 'TextureButton', style_box)
theme.set_stylebox('texture_disabled', 'TextureButton', style_box)
theme.set_stylebox('texture_focus', 'TextureButton', style_box)
How to properly load texture to TextureButton
with the Theme
class?