Add compact generated icon button surfaces

This commit is contained in:
2026-06-20 09:25:32 +09:00
parent 1ec8a78063
commit bd0b7a238e
13 changed files with 271 additions and 13 deletions

View File

@@ -32,6 +32,7 @@ const TITLE_MENU_SURFACE_PATH := "res://art/ui/panels/panel_title_command.png"
const TOOLBAR_ICON_PATH_TEMPLATE := "res://art/ui/icons/toolbar_%s.png"
const PANEL_TEXTURE_PATH_TEMPLATE := "res://art/ui/panels/panel_%s.png"
const BUTTON_TEXTURE_PATH_TEMPLATE := "res://art/ui/buttons/button_%s.png"
const ICON_BUTTON_TEXTURE_PATH_TEMPLATE := "res://art/ui/buttons/button_icon_%s.png"
const TILE_MARKER_TEXTURE_PATH_TEMPLATE := "res://art/ui/tiles/tile_marker_%s.png"
const CLASS_ICON_TEXTURE_PATH_TEMPLATE := "res://art/ui/class_icons/class_%s.png"
const MAP_BADGE_TEXTURE_PATH_TEMPLATE := "res://art/ui/map_badges/map_badge_%s.png"
@@ -1038,12 +1039,32 @@ func _make_button_texture_style(state_key: String, content_margin: int = 10) ->
return style
func _make_icon_button_texture_style(state_key: String, content_margin: int = 6) -> StyleBoxTexture:
var texture := _load_art_texture(ICON_BUTTON_TEXTURE_PATH_TEMPLATE % state_key)
if texture == null:
return null
var style := StyleBoxTexture.new()
style.texture = texture
style.draw_center = true
style.texture_margin_left = 72
style.texture_margin_right = 72
style.texture_margin_top = 72
style.texture_margin_bottom = 72
var resolved_margin: int = maxi(content_margin, 5)
style.content_margin_left = resolved_margin
style.content_margin_right = resolved_margin
style.content_margin_top = resolved_margin
style.content_margin_bottom = resolved_margin
return style
func _apply_generated_button_style(button: Button, important: bool = false) -> bool:
var normal_style := _make_button_texture_style("pressed" if important else "normal")
var hover_style := _make_button_texture_style("hover")
var pressed_style := _make_button_texture_style("pressed")
var focus_style := _make_button_texture_style("hover")
var disabled_style := _make_button_texture_style("disabled")
var icon_only := bool(button.get_meta("icon_only", false))
var normal_style := _make_icon_button_texture_style("pressed" if important else "normal") if icon_only else _make_button_texture_style("pressed" if important else "normal")
var hover_style := _make_icon_button_texture_style("hover") if icon_only else _make_button_texture_style("hover")
var pressed_style := _make_icon_button_texture_style("pressed") if icon_only else _make_button_texture_style("pressed")
var focus_style := _make_icon_button_texture_style("hover") if icon_only else _make_button_texture_style("hover")
var disabled_style := _make_icon_button_texture_style("disabled") if icon_only else _make_button_texture_style("disabled")
if normal_style == null or hover_style == null or pressed_style == null or focus_style == null or disabled_style == null:
return false
button.add_theme_stylebox_override("normal", normal_style)
@@ -1052,6 +1073,7 @@ func _apply_generated_button_style(button: Button, important: bool = false) -> b
button.add_theme_stylebox_override("focus", focus_style)
button.add_theme_stylebox_override("disabled", disabled_style)
button.set_meta("generated_button_texture", true)
button.set_meta("generated_icon_button_texture", icon_only)
return true
@@ -1143,6 +1165,7 @@ func _apply_button_style(button: Button, important: bool = false) -> void:
button.add_theme_color_override("font_disabled_color", UI_DISABLED_TEXT)
_apply_control_font(button, important)
button.set_meta("generated_button_texture", false)
button.set_meta("generated_icon_button_texture", false)
func _suppress_local_command_tooltip(button: Button) -> void: