Skip to content

Commit 11d9ecb

Browse files
Implement Version Checker and Downloader (#1803)
* Playing around * Implement Update checker and Update downloader
1 parent c5f2a85 commit 11d9ecb

File tree

8 files changed

+686
-27
lines changed

8 files changed

+686
-27
lines changed

addons/dialogic/Editor/Common/side_bar.tscn

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,13 @@ theme_override_styles/selected_focus = SubResource("StyleBoxEmpty_n8rql")
8282
allow_reselect = true
8383
same_column_width = true
8484

85-
[node name="CurrentVersion" type="Label" parent="VBox"]
85+
[node name="CurrentVersion" type="Button" parent="VBox"]
8686
unique_name_in_owner = true
8787
layout_mode = 2
88+
text = "Some Version"
89+
flat = true
8890
clip_text = true
8991

9092
[connection signal="gui_input" from="VBox/Margin/VSplitContainer/VBox/Logo" to="." method="_on_logo_gui_input"]
9193
[connection signal="text_changed" from="VBox/Margin/VSplitContainer/VBox/Search" to="." method="_on_search_text_changed"]
94+
[connection signal="pressed" from="VBox/CurrentVersion" to="." method="_on_current_version_pressed"]

addons/dialogic/Editor/Common/sidebar.gd

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ func _ready():
3636
## MARGINS
3737
$VBox/Margin.set("theme_override_constants/margin_left", 4 * editor_scale)
3838
$VBox/Margin.set("theme_override_constants/margin_bottom", 4 * editor_scale)
39-
40-
## VERSION LABEL
41-
var plugin_cfg := ConfigFile.new()
42-
plugin_cfg.load("res://addons/dialogic/plugin.cfg")
43-
%CurrentVersion.text = plugin_cfg.get_value('plugin', 'version', 'unknown version')
44-
45-
4639

4740

4841
################################################################################
@@ -157,3 +150,4 @@ func update_content_list(list:PackedStringArray) -> void:
157150
editors_manager.resource_helper.label_directory[i] = list
158151
editors_manager.resource_helper.label_directory[''] = list
159152
DialogicUtil.set_editor_setting('label_ref', editors_manager.resource_helper.label_directory)
153+
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
@tool
2+
extends Control
3+
4+
var current_info : Dictionary = {}
5+
@onready var editor_view := find_parent('EditorView')
6+
7+
8+
func _ready():
9+
await editor_view.ready
10+
theme = editor_view.theme
11+
12+
%Install.icon = editor_view.get_theme_icon("AssetLib", "EditorIcons")
13+
%LoadingIcon.texture = editor_view.get_theme_icon("KeyTrackScale", "EditorIcons")
14+
%InstallWarning.modulate = editor_view.get_theme_color("warning_color", "Editor")
15+
16+
DialogicUtil.get_dialogic_plugin().get_editor_interface().get_resource_filesystem().resources_reimported.connect(_on_resources_reimported)
17+
18+
19+
func open():
20+
get_parent().popup_centered_ratio(0.5)
21+
get_parent().mode = Window.MODE_WINDOWED
22+
get_parent().move_to_foreground()
23+
get_parent().grab_focus()
24+
25+
26+
func load_info(info:Dictionary, update_type:int) -> void:
27+
current_info = info
28+
if update_type == 2:
29+
%State.text = "No Information Available"
30+
%UpdateName.text = "Unable to access versions."
31+
%UpdateName.add_theme_color_override("font_color", editor_view.get_theme_color("readonly_color", "Editor"))
32+
%Content.text = "You are probably not connected to the internet. Fair enough."
33+
%ShortInfo.text = "Huh, what happened here?"
34+
%ReadFull.hide()
35+
%Install.disabled = true
36+
else:
37+
%UpdateName.text = info.name
38+
%Content.text = markdown_to_bbcode('#'+info.body.get_slice('#', 1)).strip_edges()
39+
%ShortInfo.text = "Published on "+info.published_at.substr(0, info.published_at.find('T'))+" by "+info.author.login
40+
%ReadFull.uri = info.html_url
41+
%ReadFull.show()
42+
if update_type == 0:
43+
%State.text = "Update Available!"
44+
%UpdateName.add_theme_color_override("font_color", editor_view.get_theme_color("warning_color", "Editor"))
45+
%Install.disabled = false
46+
else:
47+
%State.text = "You are up to date:"
48+
%UpdateName.add_theme_color_override("font_color", editor_view.get_theme_color("success_color", "Editor"))
49+
%Install.disabled = true
50+
var reactions := {"laugh":"😂", "hooray":"🎉", "confused":"😕", "heart":"❤️", "rocket":"🚀", "eyes":"👀"}
51+
for i in reactions:
52+
%Reactions.get_node(i.capitalize()).visible = info.reactions[i] > 0
53+
%Reactions.get_node(i.capitalize()).text = reactions[i]+" "+str(info.reactions[i]) if info.reactions[i] > 0 else reactions[i]
54+
if info.reactions['+1']+info.reactions['-1'] > 0:
55+
%Reactions.get_node("Likes").visible = true
56+
%Reactions.get_node("Likes").text = "👍 "+str(info.reactions['+1']+info.reactions['-1'])
57+
else:
58+
%Reactions.get_node("Likes").visible = false
59+
60+
61+
func _on_window_close_requested():
62+
get_parent().visible = false
63+
64+
65+
func _on_install_pressed():
66+
find_parent('UpdateManager').request_update_download()
67+
68+
%InfoLabel.text = "Downloading. This can take a moment."
69+
%Loading.show()
70+
%LoadingIcon.create_tween().set_loops().tween_property(%LoadingIcon, 'rotation', 2*PI, 1).from(0)
71+
72+
73+
func _on_refresh_pressed():
74+
find_parent('UpdateManager').request_update_check()
75+
76+
77+
func _on_update_manager_downdload_completed(result:int):
78+
%Loading.hide()
79+
match result:
80+
0: # success
81+
%InfoLabel.text = "Installed successfully. Restart needed!"
82+
%InfoLabel.modulate = editor_view.get_theme_color("success_color", "Editor")
83+
%Restart.show()
84+
%Restart.grab_focus()
85+
1: # failure
86+
%InfoLabel.text = "Download failed."
87+
%InfoLabel.modulate = editor_view.get_theme_color("readonly_color", "Editor")
88+
89+
90+
func _on_resources_reimported(resources:Array) -> void:
91+
await get_tree().process_frame
92+
get_parent().move_to_foreground()
93+
94+
95+
func markdown_to_bbcode(text:String) -> String:
96+
var font_sizes := {1:16, 2:16, 3:16,4:14, 5:14}
97+
var title_regex := RegEx.create_from_string('(^|\n)((?<level>#+)(?<title>.*))\\n')
98+
var res := title_regex.search(text)
99+
while res:
100+
text = text.replace(res.get_string(2), '[font_size='+str(font_sizes[len(res.get_string('level'))])+']'+res.get_string('title').strip_edges()+'[/font_size]')
101+
res = title_regex.search(text)
102+
103+
var link_regex := RegEx.create_from_string('(?<!\\!)\\[(?<text>[^\\]]*)]\\((?<link>[^)]*)\\)')
104+
res = link_regex.search(text)
105+
while res:
106+
text = text.replace(res.get_string(), '[url='+res.get_string('link')+']'+res.get_string('text').strip_edges()+'[/url]')
107+
res = link_regex.search(text)
108+
109+
var image_regex := RegEx.create_from_string('\\!\\[(?<text>[^\\]]*)]\\((?<link>[^)]*)\\)\n*')
110+
res = image_regex.search(text)
111+
while res:
112+
text = text.replace(res.get_string(), '[url='+res.get_string('link')+']'+res.get_string('text').strip_edges()+'[/url]')
113+
res = image_regex.search(text)
114+
115+
var italics_regex := RegEx.create_from_string('\\*(?<text>[^\\*\\n]*)\\*')
116+
res = italics_regex.search(text)
117+
while res:
118+
text = text.replace(res.get_string(), '[i]'+res.get_string('text').strip_edges()+'[/i]')
119+
res = italics_regex.search(text)
120+
121+
var bullets_regex := RegEx.create_from_string('(?<=\\n)(\\*|-)(?<text>[^\\*\\n]*)\\n')
122+
res = bullets_regex.search(text)
123+
while res:
124+
text = text.replace(res.get_string(), '[ul]'+res.get_string('text').strip_edges()+'[/ul]\n')
125+
res = bullets_regex.search(text)
126+
127+
var small_code_regex := RegEx.create_from_string('(?<!`)`(?<text>[^`]+)`')
128+
res = small_code_regex.search(text)
129+
while res:
130+
text = text.replace(res.get_string(), '[code][color='+get_theme_color("accent_color", "Editor").to_html()+']'+res.get_string('text').strip_edges()+'[/color][/code]')
131+
res = small_code_regex.search(text)
132+
133+
var big_code_regex := RegEx.create_from_string('(?<!`)```(?<text>[^`]+)```')
134+
res = big_code_regex.search(text)
135+
while res:
136+
text = text.replace(res.get_string(), '[code][bgcolor='+get_theme_color("box_selection_fill_color", "Editor").to_html()+']'+res.get_string('text').strip_edges()+'[/bgcolor][/code]')
137+
res = big_code_regex.search(text)
138+
139+
return text
140+
141+
142+
143+
func _on_content_meta_clicked(meta:Variant) -> void:
144+
OS.shell_open(str(meta))
145+
146+
147+
func _on_install_mouse_entered():
148+
if not %Install.disabled:
149+
%InstallWarning.show()
150+
151+
152+
func _on_install_mouse_exited():
153+
%InstallWarning.hide()
154+
155+
156+
func _on_restart_pressed():
157+
DialogicUtil.get_dialogic_plugin().get_editor_interface().restart_editor(true)

0 commit comments

Comments
 (0)