diff --git a/docs/docs/about.md b/docs/docs/about.md index 13dd69b..56aacb1 100644 --- a/docs/docs/about.md +++ b/docs/docs/about.md @@ -13,5 +13,5 @@ StarOpenSource UI (`SUI` for short) is a collection of common ui elements for th - [ ] Scroll bars - [ ] Support for Text scroll bars - [ ] Check boxes -- [ ] Progress bars +- [x] Progress bars - [ ] Dialogue boxes diff --git a/docs/docs/reference/elements/progressbar.md b/docs/docs/reference/elements/progressbar.md new file mode 100644 index 0000000..0fb596f --- /dev/null +++ b/docs/docs/reference/elements/progressbar.md @@ -0,0 +1,30 @@ +--- +sidebar_position: 5 +description: Useful for displaying progress. +--- + +# `SuiProgressBar` + +## Variables +### *int* font_size = *25* +The size the percentage text should have. +### *float* minimum_value = 0.0 +The minimum value this progress bar can display. +### *float* maximum_value = 100.0 +The maximum value this progress bar can display. +### *float* value = 50.0 +Forwarded from the internal `ProgressBar`. Will be overriden with the internal bar's value, any changes to this variable will not be reflected (except during `_ready`). +### *bool* rounded = *false* +Determines if `value` should be rounded to the nearest integer. +### *bool* exponential = *false* +See [Range.exp_edit](https://docs.godotengine.org/en/4.2/classes/class_range.html#class-range-property-exp-edit). +### *bool* editor_process = *true* +Determines if the element should be updated automatically **while running in the editor**. +### *bool* runtime_process = *true* +Determines if the element should be updated automatically **during your game/application's runtime**. + +## Functions +### *void* update_element() +Updates the element. +### *void* update_value(*float* value) +Updates the internal bar's value for `value`. Use this method to update `value`. diff --git a/godot/Test.gd b/godot/Test.gd index 2b948a1..eff9cee 100644 --- a/godot/Test.gd +++ b/godot/Test.gd @@ -30,3 +30,7 @@ func _ready() -> void: $SuiText.connect("meta_clicked", func(meta: Variant) -> void: logger.info("SuiText: meta_clicked(meta=" + str(meta) + ")")) $SuiText.connect("meta_hover_started", func(meta: Variant) -> void: logger.info("SuiText: meta_hover_started(meta=" + str(meta) + ")")) $SuiText.connect("meta_hover_ended", func(meta: Variant) -> void: logger.info("SuiText: meta_hover_ended(meta=" + str(meta) + ")")) + +func _process(_delta: float) -> void: + if $SuiProgressBar.value < 100.0: $SuiProgressBar.update_value($SuiProgressBar.value+0.025) + else: $SuiProgressBar.update_value(0.0) diff --git a/godot/Test.tscn b/godot/Test.tscn index 4bee187..fcc7d45 100644 --- a/godot/Test.tscn +++ b/godot/Test.tscn @@ -1,12 +1,13 @@ -[gd_scene load_steps=8 format=3 uid="uid://5fghtsgvqc7j"] +[gd_scene load_steps=9 format=3 uid="uid://5fghtsgvqc7j"] [ext_resource type="PackedScene" uid="uid://cxg471hoqg6mr" path="res://addons/SUI/scenesrc/SuiIconButton.tscn" id="1_3di6k"] [ext_resource type="Script" path="res://Test.gd" id="1_xnmp1"] [ext_resource type="PackedScene" uid="uid://4hi8y7pu3w0v" path="res://addons/SUI/scenesrc/SuiTextButton.tscn" id="2_dxvwu"] [ext_resource type="PackedScene" uid="uid://1r7pvm0biuk7" path="res://addons/SUI/scenesrc/SuiHeader.tscn" id="2_pcev0"] [ext_resource type="PackedScene" uid="uid://bso65vpjqc4g4" path="res://addons/SUI/scenesrc/SuiText.tscn" id="4_1lt1v"] -[ext_resource type="Texture2D" uid="uid://beqhfqbyme6in" path="res://addons/SUI/dist/example.png" id="4_12skp"] +[ext_resource type="Texture2D" uid="uid://beqhfqbyme6in" path="res://addons/SUI/dist/distrib/dist/example.png" id="4_12skp"] [ext_resource type="PackedScene" uid="uid://b31tqrkh73to2" path="res://addons/SUI/scenesrc/SuiScroller.tscn" id="6_6g04c"] +[ext_resource type="PackedScene" uid="uid://7v3lokrljsjw" path="res://addons/SUI/scenesrc/SuiProgressBar.tscn" id="7_lgkfh"] [node name="Test" type="Control"] layout_mode = 3 @@ -49,6 +50,13 @@ offset_right = -324.0 offset_bottom = -11.0 text = "Button: Normal [b]Bold[/b] [i]Italic[/i] [b][i]Bold Italic[/i][/b] [code]Code -->[/code]" +[node name="SuiProgressBar" parent="." instance=ExtResource("7_lgkfh")] +layout_mode = 1 +offset_left = 28.0 +offset_top = 635.0 +offset_right = -34.0 +offset_bottom = -127.0 + [node name="SuiScroller" parent="." instance=ExtResource("6_6g04c")] layout_mode = 1 offset_left = 11.0 diff --git a/sui/scenesrc/SuiProgressBar.tscn b/sui/scenesrc/SuiProgressBar.tscn new file mode 100644 index 0000000..743451c --- /dev/null +++ b/sui/scenesrc/SuiProgressBar.tscn @@ -0,0 +1,25 @@ +[gd_scene load_steps=3 format=3 uid="uid://7v3lokrljsjw"] + +[ext_resource type="Script" path="res://addons/SUI/src/SuiProgressBar.gd" id="1_t211g"] +[ext_resource type="Theme" uid="uid://bfln8p0ov8enx" path="res://addons/SUI/themes/ProgressBar.tres" id="2_rvtjx"] + +[node name="SuiProgressBar" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_right = -1063.0 +offset_bottom = -762.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_t211g") +editor_process = true +runtime_process = true + +[node name="Bar" type="ProgressBar" parent="."] +layout_mode = 0 +offset_right = 377.0 +offset_bottom = 48.0 +theme = ExtResource("2_rvtjx") +theme_override_font_sizes/font_size = 25 +value = 50.0 diff --git a/sui/src/SuiProgressBar.gd b/sui/src/SuiProgressBar.gd new file mode 100644 index 0000000..9fbf8b1 --- /dev/null +++ b/sui/src/SuiProgressBar.gd @@ -0,0 +1,53 @@ +# STAROPENSOURCE UI SOURCE FILE +# Copyright (c) 2024 The StarOpenSource Project & Contributors +# Licensed under the GNU Affero General Public License v3 +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +@tool +extends SuiBaseClass + +@export_category("Base Configuration") +## The size the percentage text should have. +@export var font_size: int = 25 +@export_subgroup("ProgressBar") +## The minimum value this progress bar can display. +@export var minimum_value: float = 0.0 +## The maximum value this progress bar can display. +@export var maximum_value: float = 100.0 +## Forwarded from the internal [ProgressBar]. Will be overriden with the internal bar's value, any changes to this variable will not be reflected (except during [method _ready]). +@export var value: float = 50.0 +## Determines if [code]value[/code] should be rounded to the nearest integer. +@export var rounded: bool = false +## See [member Range.exp_edit]. +@export var exponential: bool = false + +func _ready() -> void: + super() + if !in_editor(): $Bar.value = value + +func update_element() -> void: + # Update sizes + $Bar.size = size + + # Update ProgressBar stuff + $Bar.min_value = minimum_value + $Bar.max_value = maximum_value + $Bar.rounded = rounded + $Bar.exp_edit = exponential + if in_editor(): $Bar.value = value + else: value = $Bar.value + $Bar.add_theme_font_size_override("font_size", font_size) + +func update_value(value_new: float) -> void: + $Bar.value = value_new diff --git a/sui/themes/ProgressBar.tres b/sui/themes/ProgressBar.tres new file mode 100644 index 0000000..cc22ff9 --- /dev/null +++ b/sui/themes/ProgressBar.tres @@ -0,0 +1,23 @@ +[gd_resource type="Theme" load_steps=4 format=3 uid="uid://bfln8p0ov8enx"] + +[ext_resource type="FontFile" uid="uid://d3cdnrnmplqa2" path="res://addons/SUI/fonts/Jost/Jost-Medium.ttf" id="1_5nv4j"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_nesmb"] +bg_color = Color(0.997878, 0.337467, 0.369875, 1) +corner_radius_top_left = 8 +corner_radius_top_right = 8 +corner_radius_bottom_right = 8 +corner_radius_bottom_left = 8 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_1awnp"] +bg_color = Color(0.839216, 0.0196078, 0.196078, 1) +corner_radius_top_left = 8 +corner_radius_top_right = 8 +corner_radius_bottom_right = 8 +corner_radius_bottom_left = 8 + +[resource] +ProgressBar/colors/font_color = Color(1, 1, 1, 1) +ProgressBar/fonts/font = ExtResource("1_5nv4j") +ProgressBar/styles/background = SubResource("StyleBoxFlat_nesmb") +ProgressBar/styles/fill = SubResource("StyleBoxFlat_1awnp")