Add SuiProgressBar

This commit is contained in:
JeremyStar™ 2024-05-15 00:56:34 +02:00
parent 2d3fd6c918
commit 3c37c05c68
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
7 changed files with 146 additions and 3 deletions

View file

@ -13,5 +13,5 @@ StarOpenSource UI (`SUI` for short) is a collection of common ui elements for th
- [ ] Scroll bars - [ ] Scroll bars
- [ ] Support for Text scroll bars - [ ] Support for Text scroll bars
- [ ] Check boxes - [ ] Check boxes
- [ ] Progress bars - [x] Progress bars
- [ ] Dialogue boxes - [ ] Dialogue boxes

View file

@ -0,0 +1,30 @@
---
sidebar_position: 5
description: Useful for displaying progress.
---
# `SuiProgressBar`
## Variables
### *int* <u>font_size</u> = *25*
The size the percentage text should have.
### *float* <u>minimum_value</u> = 0.0
The minimum value this progress bar can display.
### *float* <u>maximum_value</u> = 100.0
The maximum value this progress bar can display.
### *float* <u>value</u> = 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* <u>rounded</u> = *false*
Determines if `value` should be rounded to the nearest integer.
### *bool* <u>exponential</u> = *false*
See [Range.exp_edit](https://docs.godotengine.org/en/4.2/classes/class_range.html#class-range-property-exp-edit).
### *bool* <u>editor_process</u> = *true*
Determines if the element should be updated automatically **while running in the editor**.
### *bool* <u>runtime_process</u> = *true*
Determines if the element should be updated automatically **during your game/application's runtime**.
## Functions
### *void* <u>update_element</u>()
Updates the element.
### *void* <u>update_value</u>(*float* <u>value</u>)
Updates the internal bar's value for `value`. Use this method to update `value`.

View file

@ -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_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_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) + ")")) $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)

View file

@ -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="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="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://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://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="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://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"] [node name="Test" type="Control"]
layout_mode = 3 layout_mode = 3
@ -49,6 +50,13 @@ offset_right = -324.0
offset_bottom = -11.0 offset_bottom = -11.0
text = "Button: Normal [b]Bold[/b] [i]Italic[/i] [b][i]Bold Italic[/i][/b] [code]Code -->[/code]" 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")] [node name="SuiScroller" parent="." instance=ExtResource("6_6g04c")]
layout_mode = 1 layout_mode = 1
offset_left = 11.0 offset_left = 11.0

View file

@ -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

53
sui/src/SuiProgressBar.gd Normal file
View file

@ -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 <https://www.gnu.org/licenses/>.
@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

View file

@ -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")