Skip to content

Commit

Permalink
Merge pull request #8 from ThePat02/enhance-ui
Browse files Browse the repository at this point in the history
add: Automatically check for new versions and notify user
  • Loading branch information
ThePat02 authored Nov 9, 2023
2 parents 67047c4 + b867997 commit deaa8a4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ This plugin provides a set of tools to create custom and complex behaviour in th
- [Templates](docs/documentation.md#using-script-templates) for easy extension and integration.
- Example Scene

When a new version is available on GitHub, the plugin will display a notification in the Toolbox!



## Usage
Expand Down
44 changes: 33 additions & 11 deletions addons/behaviour_toolkit/ui/toolkit_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,25 @@
extends Control


const CONFIG_URL = "https://raw.githubusercontent.com/ThePat02/BehaviourToolkit/main/addons/behaviour_toolkit/plugin.cfg"


var current_selection: Node
var undo_redo: EditorUndoRedoManager

var current_version
var newest_version: String


@onready var dialog_blackboard: FileDialog = $FileDialogNewBlackboard
@onready var http_request: HTTPRequest = $HTTPRequest


func _ready():
# Get current version of the plugin
var config = ConfigFile.new()

# Load data from a file.
var err = config.load("res://addons/behaviour_toolkit/plugin.cfg")
update_current_version()
update_newest_version()

# If the file didn't load, ignore it.
if not err != OK:
var plugin_version = config.get_value("plugin", "version")
%Version.text = "BehaviourToolkit v" + str(plugin_version)

config.clear()
%Version.text = "BehaviourToolkit v" + str(current_version)

# Connect buttons
%ButtonState.connect("pressed", _on_button_pressed.bind(FSMState, "FSMState"))
Expand Down Expand Up @@ -54,6 +53,18 @@ func set_current_selection(new_selection):
current_selection = new_selection


func update_newest_version():
http_request.request(CONFIG_URL)


func update_current_version():
var config = ConfigFile.new()
var err = config.load("res://addons/behaviour_toolkit/plugin.cfg")

current_version = config.get_value("plugin", "version")
config.clear()


func _on_button_pressed(type, name: String):
var new_node: BehaviourToolkit = type.new()

Expand Down Expand Up @@ -86,3 +97,14 @@ func _on_button_blackboard_pressed():
func _on_file_dialog_new_blackboard_file_selected(path:String):
var new_blackboard := Blackboard.new()
ResourceSaver.save(new_blackboard, path)


func _on_http_request_request_completed(result:int, response_code:int, headers:PackedStringArray, body:PackedByteArray):
var config = ConfigFile.new()
var err = config.parse(body.get_string_from_ascii())

newest_version = config.get_value("plugin", "version")
config.clear()

if newest_version != current_version:
%LinkGithub.show()
13 changes: 12 additions & 1 deletion addons/behaviour_toolkit/ui/toolkit_ui.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ grow_vertical = 2
script = ExtResource("1_51rvx")
metadata/_edit_vertical_guides_ = []

[node name="HTTPRequest" type="HTTPRequest" parent="."]

[node name="FileDialogNewBlackboard" type="FileDialog" parent="."]
title = "Create a new Blackboard"
size = Vector2i(800, 500)
Expand Down Expand Up @@ -253,13 +255,22 @@ layout_mode = 2
text = "Repeat"
icon = ExtResource("10_nvbp1")

[node name="LinkGithub" type="LinkButton" parent="ScrollContainer/MarginContainer/VBoxContainer"]
unique_name_in_owner = true
visible = false
layout_mode = 2
theme_override_colors/font_color = Color(0.0823529, 0.756863, 0.32549, 1)
text = "New Version available on GitHub!"
uri = "https://github.com/ThePat02/BehaviourToolkit"

[node name="Footer" type="HBoxContainer" parent="ScrollContainer/MarginContainer/VBoxContainer"]
layout_mode = 2

[node name="Version" type="Label" parent="ScrollContainer/MarginContainer/VBoxContainer/Footer"]
unique_name_in_owner = true
layout_mode = 2
text = "BehaviourToolkit v0.9.4"
text = "BehaviourToolkit v1.0.0"

[connection signal="request_completed" from="HTTPRequest" to="." method="_on_http_request_request_completed"]
[connection signal="file_selected" from="FileDialogNewBlackboard" to="." method="_on_file_dialog_new_blackboard_file_selected"]
[connection signal="pressed" from="ScrollContainer/MarginContainer/VBoxContainer/Panel/ScrollContainer/Toolbox/Misc/ButtonBlackboard" to="." method="_on_button_blackboard_pressed"]

0 comments on commit deaa8a4

Please sign in to comment.