diff --git a/addons/dreadpon.spatial_gardener/controls/input_fields/action_thumbnail/ui_action_thumbnail.gd b/addons/dreadpon.spatial_gardener/controls/input_fields/action_thumbnail/ui_action_thumbnail.gd index 21d21a1..a331e88 100644 --- a/addons/dreadpon.spatial_gardener/controls/input_fields/action_thumbnail/ui_action_thumbnail.gd +++ b/addons/dreadpon.spatial_gardener/controls/input_fields/action_thumbnail/ui_action_thumbnail.gd @@ -1,35 +1,41 @@ @tool extends Control - #------------------------------------------------------------------------------- # A button with multiple children buttons corresponding to various possible interactions # It's main purpose is to display a thumbnail and respond to UI inputs #------------------------------------------------------------------------------- - - - # These flags define what sort of signals and broadcast -enum InteractionFlags {DELETE, SET_DIALOG, SET_DRAG, PRESS, CHECK, CLEAR, SHOW_COUNT, EDIT_LABEL} -const PRESET_ALL:Array = [ InteractionFlags.DELETE, InteractionFlags.SET_DIALOG, InteractionFlags.SET_DRAG, InteractionFlags.PRESS, - InteractionFlags.CHECK, InteractionFlags.CLEAR, InteractionFlags.SHOW_COUNT, InteractionFlags.EDIT_LABEL] +enum InteractionFlags { DELETE, SET_DIALOG, SET_DRAG, PRESS, CHECK, CLEAR, SHOW_COUNT, EDIT_LABEL } +const PRESET_ALL: Array = [ + InteractionFlags.DELETE, + InteractionFlags.SET_DIALOG, + InteractionFlags.SET_DRAG, + InteractionFlags.PRESS, + InteractionFlags.CHECK, + InteractionFlags.CLEAR, + InteractionFlags.SHOW_COUNT, + InteractionFlags.EDIT_LABEL +] const ThemeAdapter = preload("../../../controls/theme_adapter.gd") const FunLib = preload("../../../utility/fun_lib.gd") -var active_interaction_flags:Array = [] : set = set_active_interaction_flags -@export var thumb_size:int = 100 : set = set_thumb_size - -var root_button_nd:Control = null -var texture_rect_nd:Control = null -var selection_panel_nd:Control = null -var check_box_nd:Control = null -var counter_label_nd:Control = null -var label_line_container_nd:Control = null -var label_line_edit_nd:Control = null -var menu_button_nd:Control = null -var alt_text_label_nd:Control = null +var active_interaction_flags: Array = []: + set = set_active_interaction_flags +@export var thumb_size: int = 100: + set = set_thumb_size + +var root_button_nd: Control = null +var texture_rect_nd: Control = null +var selection_panel_nd: Control = null +var check_box_nd: Control = null +var counter_label_nd: Control = null +var label_line_container_nd: Control = null +var label_line_edit_nd: Control = null +var menu_button_nd: Control = null +var alt_text_label_nd: Control = null var default_button_sizes: Dictionary = {} @@ -38,10 +44,9 @@ var default_button_sizes: Dictionary = {} @export var new_texture: Texture2D = null @export var options_texture: Texture2D = null -var def_rect_size:Vector2 = Vector2(100.0, 100.0) -var def_button_size:Vector2 = Vector2(24.0, 24.0) -var def_max_title_chars:int = 8 - +var def_rect_size: Vector2 = Vector2(100.0, 100.0) +var def_button_size: Vector2 = Vector2(24.0, 24.0) +var def_max_title_chars: int = 8 signal requested_delete signal requested_set_dialog @@ -51,15 +56,12 @@ signal requested_check signal requested_label_edit signal requested_clear - - - #------------------------------------------------------------------------------- # Lifecycle #------------------------------------------------------------------------------- -func init(_thumb_size:int, _button_size:int, _active_interaction_flags:Array): +func init(_thumb_size: int, _button_size: int, _active_interaction_flags: Array): set_meta("class", "UI_ActionThumbnail") thumb_size = _thumb_size active_interaction_flags = _active_interaction_flags.duplicate() @@ -70,7 +72,7 @@ func init(_thumb_size:int, _button_size:int, _active_interaction_flags:Array): func _ready(): var Label_font_size = get_theme_font_size("font_size", "Label") _set_default_textures() - + if has_node("%RootButton"): root_button_nd = %RootButton if root_button_nd.has_signal("dropped"): @@ -96,26 +98,27 @@ func _ready(): if has_node("%AltTextLabel"): alt_text_label_nd = %AltTextLabel alt_text_label_nd.visible = false - if has_node('%LabelLineEdit'): + if has_node("%LabelLineEdit"): label_line_container_nd = %LabelLineContainer label_line_edit_nd = %LabelLineEdit label_line_edit_nd.theme_type_variation = "PlantTitleLineEdit" label_line_edit_nd.text_changed.connect(on_label_edit) label_line_container_nd.visible = false - if has_node('%MenuButton'): + if has_node("%MenuButton"): menu_button_nd = %MenuButton menu_button_nd.theme_type_variation = "MenuButton" menu_button_nd.get_popup().id_pressed.connect(on_popup_menu_press) menu_button_nd.visible = true default_button_sizes[menu_button_nd] = menu_button_nd.size - + if counter_label_nd: - counter_label_nd.add_theme_font_size_override('font_size', Label_font_size) + counter_label_nd.add_theme_font_size_override("font_size", Label_font_size / 1.5) if label_line_edit_nd: - label_line_edit_nd.add_theme_font_size_override('font_size', Label_font_size) + # Prevent overdraw when the rect size is small + label_line_edit_nd.add_theme_font_size_override("font_size", Label_font_size / 2) if alt_text_label_nd: - alt_text_label_nd.add_theme_font_size_override('font_size', Label_font_size) - + alt_text_label_nd.add_theme_font_size_override("font_size", Label_font_size / 2) + update_size() set_active_interaction_flags(active_interaction_flags) @@ -124,58 +127,59 @@ func _set_default_textures(): if !clear_texture || !delete_texture || !new_texture || !options_texture: var editor_theme = ThemeAdapter.editor_theme clear_texture = editor_theme.get_theme_item(Theme.DATA_TYPE_ICON, "Clear", "EditorIcons") - delete_texture = editor_theme.get_theme_item(Theme.DATA_TYPE_ICON, "ImportFail", "EditorIcons") + delete_texture = editor_theme.get_theme_item( + Theme.DATA_TYPE_ICON, "ImportFail", "EditorIcons" + ) new_texture = editor_theme.get_theme_item(Theme.DATA_TYPE_ICON, "Add", "EditorIcons") - options_texture = editor_theme.get_theme_item(Theme.DATA_TYPE_ICON, "CodeFoldDownArrow", "EditorIcons") + options_texture = editor_theme.get_theme_item( + Theme.DATA_TYPE_ICON, "CodeFoldDownArrow", "EditorIcons" + ) if has_node("%MenuButton"): %MenuButton.icon = options_texture - - #------------------------------------------------------------------------------- # Resizing #------------------------------------------------------------------------------- -func set_thumb_size(val:int): +func set_thumb_size(val: int): thumb_size = val update_size() func update_size(): - if !is_node_ready(): return - + if !is_node_ready(): + return + var thumb_rect = Vector2(thumb_size, thumb_size) custom_minimum_size = thumb_rect - size = thumb_rect -func set_counter_val(val:int): +func set_counter_val(val: int): if !is_node_ready(): await ready - if !counter_label_nd: return + if !counter_label_nd: + return counter_label_nd.text = str(val) - - #------------------------------------------------------------------------------- # Interaction flags #------------------------------------------------------------------------------- -func set_active_interaction_flags(flags:Array): +func set_active_interaction_flags(flags: Array): var ownFlagsCopy = active_interaction_flags.duplicate() var flagsCopy = flags.duplicate() - + for flag in ownFlagsCopy: set_interaction_flag(flag, false) for flag in flagsCopy: set_interaction_flag(flag, true) -func set_interaction_flag(flag:int, state:bool): +func set_interaction_flag(flag: int, state: bool): if state: if !active_interaction_flags.has(flag): active_interaction_flags.append(flag) @@ -185,26 +189,30 @@ func set_interaction_flag(flag:int, state:bool): enable_features_to_flag(flag, state) -func enable_features_to_flag(flag:int, state:bool): +func enable_features_to_flag(flag: int, state: bool): if is_node_ready(): match flag: InteractionFlags.CHECK: check_box_nd.visible = state InteractionFlags.CLEAR: if state: - menu_button_nd.get_popup().remove_item(menu_button_nd.get_popup().get_item_index(0)) - menu_button_nd.get_popup().add_icon_item(clear_texture, 'Clear', 0) + menu_button_nd.get_popup().remove_item( + menu_button_nd.get_popup().get_item_index(0) + ) + menu_button_nd.get_popup().add_icon_item(clear_texture, "Clear", 0) InteractionFlags.DELETE: if state: - menu_button_nd.get_popup().remove_item(menu_button_nd.get_popup().get_item_index(1)) - menu_button_nd.get_popup().add_icon_item(delete_texture, 'Delete', 1) + menu_button_nd.get_popup().remove_item( + menu_button_nd.get_popup().get_item_index(1) + ) + menu_button_nd.get_popup().add_icon_item(delete_texture, "Delete", 1) InteractionFlags.SHOW_COUNT: counter_label_nd.visible = state InteractionFlags.EDIT_LABEL: label_line_container_nd.visible = state -func set_features_val_to_flag(flag:int, val): +func set_features_val_to_flag(flag: int, val): if is_node_ready(): match flag: InteractionFlags.PRESS: @@ -220,22 +228,27 @@ func on_set_dialog(): if active_interaction_flags.has(InteractionFlags.SET_DIALOG): requested_set_dialog.emit() + func on_set_drag(path): if active_interaction_flags.has(InteractionFlags.SET_DRAG): requested_set_drag.emit(path) + func on_press(): if active_interaction_flags.has(InteractionFlags.PRESS): requested_press.emit() + func on_check(): if active_interaction_flags.has(InteractionFlags.CHECK): requested_check.emit(check_box_nd.button_pressed) + func on_label_edit(label_text: String): if active_interaction_flags.has(InteractionFlags.EDIT_LABEL): requested_label_edit.emit(label_text) + func on_popup_menu_press(id: int): match id: 0: @@ -243,34 +256,43 @@ func on_popup_menu_press(id: int): 1: call_deferred("on_delete") + func on_clear(): if active_interaction_flags.has(InteractionFlags.CLEAR): requested_clear.emit() + func on_delete(): if active_interaction_flags.has(InteractionFlags.DELETE): requested_delete.emit() - - #------------------------------------------------------------------------------- # Thumbnail itself and other visuals #------------------------------------------------------------------------------- -func set_thumbnail(texture:Texture2D): +func trim_text(text: String, length: int = 8) -> String: + if text.length() <= length: + return text + + return text.substr(0, length - 3) + "..." + + +func set_thumbnail(texture: Texture2D): texture_rect_nd.visible = true alt_text_label_nd.visible = false - + texture_rect_nd.texture = texture alt_text_label_nd.text = "" -func set_alt_text(alt_text:String): - if !is_instance_valid(alt_text_label_nd) || !is_instance_valid(texture_rect_nd): return +func set_alt_text(alt_text: String): + if !is_instance_valid(alt_text_label_nd) || !is_instance_valid(texture_rect_nd): + return + alt_text_label_nd.visible = true texture_rect_nd.visible = false - - alt_text_label_nd.text = alt_text + + alt_text_label_nd.text = trim_text(alt_text) texture_rect_nd.texture = null diff --git a/addons/dreadpon.spatial_gardener/controls/input_fields/action_thumbnail/ui_action_thumbnail.tscn b/addons/dreadpon.spatial_gardener/controls/input_fields/action_thumbnail/ui_action_thumbnail.tscn index 014f241..69b1aa4 100644 --- a/addons/dreadpon.spatial_gardener/controls/input_fields/action_thumbnail/ui_action_thumbnail.tscn +++ b/addons/dreadpon.spatial_gardener/controls/input_fields/action_thumbnail/ui_action_thumbnail.tscn @@ -53,13 +53,18 @@ data = { [sub_resource type="ImageTexture" id="ImageTexture_sj7sv"] image = SubResource("Image_sbj0x") -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jixsw"] +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_lb883"] content_margin_left = 6.0 content_margin_top = 5.0 content_margin_right = 6.0 content_margin_bottom = 5.0 bg_color = Color(0.147, 0.168, 0.203, 1) -border_color = Color(0.1155, 0.132, 0.1595, 1) +draw_center = false +border_width_left = 2 +border_width_top = 2 +border_width_right = 2 +border_width_bottom = 2 +border_color = Color(0.44, 0.73, 0.98, 1) corner_radius_top_left = 3 corner_radius_top_right = 3 corner_radius_bottom_right = 3 @@ -67,13 +72,13 @@ corner_radius_bottom_left = 3 corner_detail = 3 anti_aliasing = false -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_078kf"] +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_shaa3"] content_margin_left = 6.0 content_margin_top = 5.0 content_margin_right = 6.0 content_margin_bottom = 5.0 -bg_color = Color(0.128625, 0.147, 0.177625, 1) -border_color = Color(0.1155, 0.132, 0.1595, 1) +bg_color = Color(0.189, 0.216, 0.261, 1) +border_color = Color(0.147, 0.168, 0.203, 1) corner_radius_top_left = 3 corner_radius_top_right = 3 corner_radius_bottom_right = 3 @@ -95,13 +100,13 @@ corner_radius_bottom_left = 3 corner_detail = 3 anti_aliasing = false -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_shaa3"] +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_078kf"] content_margin_left = 6.0 content_margin_top = 5.0 content_margin_right = 6.0 content_margin_bottom = 5.0 -bg_color = Color(0.189, 0.216, 0.261, 1) -border_color = Color(0.147, 0.168, 0.203, 1) +bg_color = Color(0.128625, 0.147, 0.177625, 1) +border_color = Color(0.1155, 0.132, 0.1595, 1) corner_radius_top_left = 3 corner_radius_top_right = 3 corner_radius_bottom_right = 3 @@ -109,18 +114,13 @@ corner_radius_bottom_left = 3 corner_detail = 3 anti_aliasing = false -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_lb883"] +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jixsw"] content_margin_left = 6.0 content_margin_top = 5.0 content_margin_right = 6.0 content_margin_bottom = 5.0 bg_color = Color(0.147, 0.168, 0.203, 1) -draw_center = false -border_width_left = 2 -border_width_top = 2 -border_width_right = 2 -border_width_bottom = 2 -border_color = Color(0.44, 0.73, 0.98, 1) +border_color = Color(0.1155, 0.132, 0.1595, 1) corner_radius_top_left = 3 corner_radius_top_right = 3 corner_radius_bottom_right = 3 @@ -185,7 +185,7 @@ unique_name_in_owner = true layout_mode = 2 theme_type_variation = &"PlantTitleLineEdit" theme_override_fonts/font = ExtResource("3_idy6e") -theme_override_font_sizes/font_size = 16 +theme_override_font_sizes/font_size = 8 placeholder_text = "Plant Label" alignment = 1 script = ExtResource("3") @@ -206,6 +206,7 @@ theme_override_constants/margin_bottom = 2 [node name="TextureRect" type="TextureRect" parent="InteractionMargin/InteractionLayout/UnderLabelMargin/ButtonVisualsMargin"] unique_name_in_owner = true +visible = false layout_mode = 2 mouse_filter = 2 expand_mode = 1 @@ -213,11 +214,10 @@ stretch_mode = 5 [node name="AltTextLabel" type="Label" parent="InteractionMargin/InteractionLayout/UnderLabelMargin/ButtonVisualsMargin"] unique_name_in_owner = true -visible = false layout_mode = 2 size_flags_vertical = 1 theme_override_fonts/font = ExtResource("3_idy6e") -theme_override_font_sizes/font_size = 16 +theme_override_font_sizes/font_size = 8 text = "Alt text Label" horizontal_alignment = 1 vertical_alignment = 1 @@ -236,18 +236,18 @@ size_flags_horizontal = 8 size_flags_vertical = 4 focus_mode = 2 theme_type_variation = &"MenuButton" -theme_override_colors/font_color = Color(0.8025, 0.81, 0.8225, 1) -theme_override_colors/font_pressed_color = Color(0.44, 0.73, 0.98, 1) -theme_override_colors/font_hover_color = Color(0.90125, 0.905, 0.91125, 1) -theme_override_colors/font_focus_color = Color(0.90125, 0.905, 0.91125, 1) theme_override_colors/font_disabled_color = Color(1, 1, 1, 0.35) +theme_override_colors/font_hover_color = Color(0.90125, 0.905, 0.91125, 1) theme_override_colors/font_outline_color = Color(0, 0, 0, 0) +theme_override_colors/font_color = Color(0.8025, 0.81, 0.8225, 1) +theme_override_colors/font_focus_color = Color(0.90125, 0.905, 0.91125, 1) +theme_override_colors/font_pressed_color = Color(0.44, 0.73, 0.98, 1) theme_override_constants/outline_size = 0 -theme_override_styles/normal = SubResource("StyleBoxFlat_jixsw") -theme_override_styles/pressed = SubResource("StyleBoxFlat_078kf") -theme_override_styles/hover = SubResource("StyleBoxFlat_hr20n") -theme_override_styles/disabled = SubResource("StyleBoxFlat_shaa3") theme_override_styles/focus = SubResource("StyleBoxFlat_lb883") +theme_override_styles/disabled = SubResource("StyleBoxFlat_shaa3") +theme_override_styles/hover = SubResource("StyleBoxFlat_hr20n") +theme_override_styles/pressed = SubResource("StyleBoxFlat_078kf") +theme_override_styles/normal = SubResource("StyleBoxFlat_jixsw") icon = SubResource("ImageTexture_sj7sv") icon_alignment = 1 @@ -257,12 +257,12 @@ size_flags_vertical = 3 mouse_filter = 2 [node name="BottomButtonLayout" type="HBoxContainer" parent="InteractionMargin/InteractionLayout/UnderLabelMargin/ButtionLayout"] +z_index = 1 layout_mode = 2 mouse_filter = 2 [node name="CheckBox" type="CheckBox" parent="InteractionMargin/InteractionLayout/UnderLabelMargin/ButtionLayout/BottomButtonLayout"] unique_name_in_owner = true -visible = false layout_mode = 2 size_flags_vertical = 8 @@ -274,12 +274,11 @@ mouse_filter = 2 [node name="CounterLabel" type="Label" parent="InteractionMargin/InteractionLayout/UnderLabelMargin/ButtionLayout/BottomButtonLayout"] unique_name_in_owner = true -visible = false layout_mode = 2 size_flags_horizontal = 9 size_flags_vertical = 6 theme_override_fonts/font = ExtResource("3_idy6e") -theme_override_font_sizes/font_size = 16 +theme_override_font_sizes/font_size = 10 text = "123" horizontal_alignment = 2 vertical_alignment = 2 diff --git a/addons/dreadpon.spatial_gardener/icons/gardener_icon.png b/addons/dreadpon.spatial_gardener/icons/gardener_icon.png index 7d859b8..70e4705 100644 Binary files a/addons/dreadpon.spatial_gardener/icons/gardener_icon.png and b/addons/dreadpon.spatial_gardener/icons/gardener_icon.png differ