From 0828d019b609ea499600600039ebea0b20a35cf8 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Wed, 8 May 2024 23:17:02 +0200 Subject: [PATCH] Added class documentation + renamed size_* (->msg) I also renamed all 'size_*' variables in SuiScroller.gd to 'thickness_*' as it's a much better fitting name. --- godot/Test.tscn | 6 +++++ sui/src/SuiBaseClass.gd | 10 +++++++++ sui/src/SuiHeader.gd | 3 +++ sui/src/SuiIconButton.gd | 12 ++++++++++ sui/src/SuiScroller.gd | 48 +++++++++++++++++++++++++--------------- sui/src/SuiText.gd | 6 +++++ sui/src/SuiTextButton.gd | 10 +++++++++ 7 files changed, 77 insertions(+), 18 deletions(-) diff --git a/godot/Test.tscn b/godot/Test.tscn index 20f6167..ae3ee4f 100644 --- a/godot/Test.tscn +++ b/godot/Test.tscn @@ -55,6 +55,9 @@ offset_left = 11.0 offset_top = 8.0 offset_right = -1124.0 offset_bottom = -576.0 +thickness_mode = null +thickness_multiplier = null +thickness_value = null [node name="Control" type="Control" parent="SuiScroller"] anchors_preset = 0 @@ -111,6 +114,9 @@ offset_left = 338.0 offset_top = 20.0 offset_right = -814.0 offset_bottom = -577.0 +thickness_mode = null +thickness_multiplier = null +thickness_value = null [node name="Control" type="Control" parent="SuiScroller2"] anchors_preset = 0 diff --git a/sui/src/SuiBaseClass.gd b/sui/src/SuiBaseClass.gd index df1aaae..9aef9c3 100644 --- a/sui/src/SuiBaseClass.gd +++ b/sui/src/SuiBaseClass.gd @@ -2,28 +2,38 @@ extends Control class_name SuiBaseClass +## Reference to the [CORE] Object. var core: Core +## Reference to a [CoreLoggerInstance] var logger: CoreLoggerInstance = null @export_category("Debugging") +## Determines if the element should be updated automatically [b]while running in the editor[/b]. @export var editor_process: bool = true +## Determines if the element should be updated automatically [b]during your game/application's runtime[/b]. @export var runtime_process: bool = true # +++ initialization and process methods +++ +# Initializes the base class func _ready() -> void: if !in_editor(): core = get_node("/root/CORE") +# Calls 'update_element()' if allowed to execute func _process(_delta: float): if execute_process(): update_element() # +++ element updating +++ +# This should be used by the element extending this script +# to provide their own update logic. func update_element() -> void: pass # +++ etc +++ +# Determines if '_process()' is allowed to execute func execute_process() -> bool: if in_editor() and !editor_process: return false elif !in_editor() and !runtime_process: return false else: return true +# Determines if running inside the editor func in_editor() -> bool: return get_node_or_null("/root/CORE") == null diff --git a/sui/src/SuiHeader.gd b/sui/src/SuiHeader.gd index 67d8f1e..23363c9 100644 --- a/sui/src/SuiHeader.gd +++ b/sui/src/SuiHeader.gd @@ -3,8 +3,11 @@ extends SuiBaseClass @export_category("Base Configuration") @export_subgroup("RichTextLabel") +## Enables support for BBCode. @export var bbcode_support: bool = true +## The text you want to display. @export_multiline var text: String = "[center]SuiHeader[/center]" +## The size your font should have. @export var font_size: int = 35 func update_element() -> void: diff --git a/sui/src/SuiIconButton.gd b/sui/src/SuiIconButton.gd index 00b9a3a..2aed66a 100644 --- a/sui/src/SuiIconButton.gd +++ b/sui/src/SuiIconButton.gd @@ -3,12 +3,18 @@ extends SuiBaseClass @export_category("Base Configuration") @export_subgroup("Button") +## Makes the button unable to be interacted with. @export var disabled: bool = false +## Makes the button toggleable. @export var toggle_mode: bool = false +## Forwarded from the internal [Button]. Will be overwritten with the internal button's value, any manual changes to this variable will not be reflected. @export var button_pressed: bool = false @export_subgroup("Icon") +## The image you want to display. @export var image: Texture2D +## See [member NinePatchRect.region_rect] @export var region_rect: Rect2 = Rect2(0, 0, 0, 0) +## See [member NinePatchRect.draw_center] @export var draw_center: bool = true @export_category("Advanced Configuration") @export_subgroup("Icon Padding") @@ -22,12 +28,18 @@ extends SuiBaseClass @export var pm_right: int = 0 @export var pm_bottom: int = 0 @export_subgroup("Axis Stretch") +## See [member NinePathRect.axis_stretch_horizontal]. @export var as_horizontal: NinePatchRect.AxisStretchMode = NinePatchRect.AxisStretchMode.AXIS_STRETCH_MODE_STRETCH +## See [member NinePathRect.axis_stretch_vertical]. @export var as_vertical: NinePatchRect.AxisStretchMode = NinePatchRect.AxisStretchMode.AXIS_STRETCH_MODE_STRETCH +## Emitted when the button is pressed. signal down +## Emitted when the button is released. signal up +## Emitted when the button has been pressed. signal pressed +## Emitted when the button has been toggled. signal toggled func _ready() -> void: diff --git a/sui/src/SuiScroller.gd b/sui/src/SuiScroller.gd index 445e11c..8c786c4 100644 --- a/sui/src/SuiScroller.gd +++ b/sui/src/SuiScroller.gd @@ -3,20 +3,32 @@ extends SuiBaseClass @export_category("Base Configuration") @export_subgroup("Visibility") +## Controls the visibility of the horizontal scroll bar. @export var hscroll_visibility: SuiTypes.ScrollVisibility = SuiTypes.ScrollVisibility.AUTO +## Controls the visibility of the vertical scroll bar. @export var vscroll_visibility: SuiTypes.ScrollVisibility = SuiTypes.ScrollVisibility.AUTO @export_category("Advanced Configuration") @export_subgroup("Scroller speed") +## Determines how the scrolling speed should be calculated. @export var speed_mode: SuiTypes.ScrollMode = SuiTypes.ScrollMode.MULTIPLY_CUSTOM_VALUE +## The speed multiplier, used for [constant SuiTypes.ScrollMode.MULTIPLY_VIEWPORT] and [constant SuiTypes.ScrollMode.MULTIPLY_CUSTOM_VALUE]. @export var speed_multiplier: float = 1 +## The speed value, used for [constant SuiTypes.ScrollMode.MULTIPLY_CUSTOM_VALUE] and [constant SuiTypes.ScrollMode.CUSTOM_VALUE]. @export var speed_value: float = 1 @export_subgroup("Scroller speed (wheel)") +## Determines how much the scrolling speed should be multiplied by when scrolling with the scroll wheel. +## Using a lower value results in more mouse scrolling, higher values result in less mouse scrolling. @export var speed_wheel_multiplier: float = 50 -@export_subgroup("Scroller size") -@export var size_mode: SuiTypes.ScrollMode = SuiTypes.ScrollMode.MULTIPLY_VIEWPORT -@export var size_multiplier: float = 0.025 -@export var size_value: float = 0 +@export_subgroup("Scroll bar thickness") +## Determines how the thickness of both scroll bars should be calculated. +@export var thickness_mode: SuiTypes.ScrollMode = SuiTypes.ScrollMode.MULTIPLY_VIEWPORT +## The thickness multiplier, used for [constant SuiTypes.ScrollMode.MULTIPLY_VIEWPORT] and [constant SuiTypes.ScrollMode.MULTIPLY_CUSTOM_VALUE]. +@export var thickness_multiplier: float = 0.025 +## The thickness value, used for [constant SuiTypes.ScrollMode.MULTIPLY_CUSTOM_VALUE] and [constant SuiTypes.ScrollMode.CUSTOM_VALUE]. +@export var thickness_value: float = 0 @export_category("Debugging") +## Will cause elements not inside the SuiScroller node to be no longer clipped [i]in editor mode[/i]. +## Useful when editing the contents of a SuiScroller node, but may cause visual chaos. @export var editor_clip_content: bool = true func _ready() -> void: @@ -29,7 +41,7 @@ func update_element() -> void: else: clip_contents = true # Update sizes and positions - match(size_mode): + match(thickness_mode): SuiTypes.ScrollMode.MULTIPLY_VIEWPORT: var window_size: Vector2i = Vector2i(ProjectSettings.get("display/window/size/viewport_width"), ProjectSettings.get("display/window/size/viewport_height")) # Find smaller value @@ -37,14 +49,14 @@ func update_element() -> void: if window_size.x < window_size.y: scale_size = window_size.x elif window_size.x > window_size.y: scale_size = window_size.y - $HScrollBar.size.y = scale_size*size_multiplier - $VScrollBar.size.x = scale_size*size_multiplier + $HScrollBar.size.y = scale_size*thickness_multiplier + $VScrollBar.size.x = scale_size*thickness_multiplier SuiTypes.ScrollMode.MULTIPLY_CUSTOM_VALUE: - $HScrollBar.size.y = size_value*size_multiplier - $VScrollBar.size.x = size_value*size_multiplier + $HScrollBar.size.y = thickness_value*thickness_multiplier + $VScrollBar.size.x = thickness_value*thickness_multiplier SuiTypes.ScrollMode.CUSTOM_VALUE: - $HScrollBar.size.y = size_value - $VScrollBar.size.x = size_value + $HScrollBar.size.y = thickness_value + $VScrollBar.size.x = thickness_value $HScrollBar.size.x = size.x-$VScrollBar.size.x $VScrollBar.size.y = size.y-$HScrollBar.size.y $HScrollBar.position.x = 0 @@ -151,7 +163,7 @@ func update_element() -> void: $HScrollBar.max_value = size.x $VScrollBar.max_value = size.y -func scroll(direction: SuiTypes.ScrollDirection) -> void: +func _scroll(direction: SuiTypes.ScrollDirection) -> void: var bar: ScrollBar var dsign: int = 0 @@ -177,13 +189,13 @@ func _input(event: InputEvent): if event.is_pressed(): match(event.button_index): MouseButton.MOUSE_BUTTON_WHEEL_UP: - if Input.is_key_pressed(Key.KEY_SHIFT): scroll(SuiTypes.ScrollDirection.LEFT) - else: scroll(SuiTypes.ScrollDirection.DOWN) + if Input.is_key_pressed(Key.KEY_SHIFT): _scroll(SuiTypes.ScrollDirection.LEFT) + else: _scroll(SuiTypes.ScrollDirection.DOWN) MouseButton.MOUSE_BUTTON_WHEEL_DOWN: - if Input.is_key_pressed(Key.KEY_SHIFT): scroll(SuiTypes.ScrollDirection.RIGHT) - else: scroll(SuiTypes.ScrollDirection.UP) - MouseButton.MOUSE_BUTTON_WHEEL_LEFT: scroll(SuiTypes.ScrollDirection.RIGHT) - MouseButton.MOUSE_BUTTON_WHEEL_RIGHT: scroll(SuiTypes.ScrollDirection.LEFT) + if Input.is_key_pressed(Key.KEY_SHIFT): _scroll(SuiTypes.ScrollDirection.RIGHT) + else: _scroll(SuiTypes.ScrollDirection.UP) + MouseButton.MOUSE_BUTTON_WHEEL_LEFT: _scroll(SuiTypes.ScrollDirection.RIGHT) + MouseButton.MOUSE_BUTTON_WHEEL_RIGHT: _scroll(SuiTypes.ScrollDirection.LEFT) func _get_configuration_warnings(): if get_child_count() != 3: diff --git a/sui/src/SuiText.gd b/sui/src/SuiText.gd index e4f77e1..63e0f67 100644 --- a/sui/src/SuiText.gd +++ b/sui/src/SuiText.gd @@ -3,12 +3,18 @@ extends SuiBaseClass @export_category("Base Configuration") @export_subgroup("RichTextLabel") +## Enables support for BBCode. @export var bbcode_support: bool = true +## The text you want to display. @export_multiline var text: String = "[center]SuiText[/center]" +## The size your font should have. @export var font_size: int = 25 +## Emitted when some interactive BBCode tag (e.g. url) is clicked signal meta_clicked +## Emitted when some interactive BBCode tag (e.g. url) is hovered over signal meta_hover_started +## Emitted when some interactive BBCode tag (e.g. url) is no longer being hovered over signal meta_hover_ended func _ready(): diff --git a/sui/src/SuiTextButton.gd b/sui/src/SuiTextButton.gd index f508b46..6a90476 100644 --- a/sui/src/SuiTextButton.gd +++ b/sui/src/SuiTextButton.gd @@ -3,17 +3,27 @@ extends SuiBaseClass @export_category("Base Configuration") @export_subgroup("Button") +## Makes the button unable to be interacted with. @export var disabled: bool = false +## Makes the button toggleable. @export var toggle_mode: bool = false +## Forwarded from the internal [Button]. Will be overwritten with the internal button's value, any manual changes to this variable will not be reflected. @export var button_pressed: bool = false @export_subgroup("RichTextLabel") +## Enables support for BBCode. @export var bbcode_support: bool = true +## The text you want to display. @export_multiline var text: String = "[center]SuiTextButton[/center]" +## The size your font should have. @export var font_size: int = 35 +## Emitted when the button is pressed. signal down +## Emitted when the button is released. signal up +## Emitted when the button has been pressed. signal pressed +## Emitted when the button has been toggled. signal toggled func _ready() -> void: