]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Editor/Common/update_install_window.gd
Updated export config options
[wolf-seeking-sheep.git] / addons / dialogic / Editor / Common / update_install_window.gd
1 @tool
2 extends Control
3
4 var current_info := {}
5 @onready var editor_view := find_parent('EditorView')
6
7
8 func _ready() -> void:
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         %CloseButton.icon = editor_view.get_theme_icon("Close", "EditorIcons")
16         DialogicUtil.get_dialogic_plugin().get_editor_interface().get_resource_filesystem().resources_reimported.connect(_on_resources_reimported)
17
18
19 func open() -> void:
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                 return
37
38         # If we are up to date (or beyond):
39         if info.is_empty():
40                 info['name'] = "You are in the future, Marty!"
41                 info["body"] = "# 😎 You are using the WIP branch!\nSeems like you are using a version that isn't even released yet. Be careful and give us your feedback ;)"
42                 info["published_at"] = "????T"
43                 info["author"] = {'login':"???"}
44                 %State.text = "Where are we Doc?"
45                 %UpdateName.add_theme_color_override("font_color", editor_view.get_theme_color("property_color_z", "Editor"))
46                 %Install.disabled = true
47
48         elif update_type == 0:
49                 %State.text = "Update Available!"
50                 %UpdateName.add_theme_color_override("font_color", editor_view.get_theme_color("warning_color", "Editor"))
51                 %Install.disabled = false
52         else:
53                 %State.text = "You are up to date:"
54                 %UpdateName.add_theme_color_override("font_color", editor_view.get_theme_color("success_color", "Editor"))
55                 %Install.disabled = true
56
57         %UpdateName.text = info.name
58         %Content.text = markdown_to_bbcode(info.body).get_slice("\n[font_size", 0).strip_edges()
59         %ShortInfo.text = "Published on "+info.published_at.substr(0, info.published_at.find('T'))+" by "+info.author.login
60         if info.has("html_url"):
61                 %ReadFull.uri = info.html_url
62                 %ReadFull.show()
63         else:
64                 %ReadFull.hide()
65         if info.has('reactions'):
66                 %Reactions.show()
67                 var reactions := {"laugh":"😂", "hooray":"🎉", "confused":"😕", "heart":"❤️", "rocket":"🚀", "eyes":"👀"}
68                 for i in reactions:
69                         %Reactions.get_node(i.capitalize()).visible = info.reactions[i] > 0
70                         %Reactions.get_node(i.capitalize()).text = reactions[i]+" "+str(info.reactions[i]) if info.reactions[i] > 0 else reactions[i]
71                 if info.reactions['+1']+info.reactions['-1'] > 0:
72                         %Reactions.get_node("Likes").visible = true
73                         %Reactions.get_node("Likes").text = "👍 "+str(info.reactions['+1']+info.reactions['-1'])
74                 else:
75                         %Reactions.get_node("Likes").visible = false
76         else:
77                 %Reactions.hide()
78
79 func _on_window_close_requested() -> void:
80         get_parent().visible = false
81
82
83 func _on_install_pressed() -> void:
84         find_parent('UpdateManager').request_update_download()
85
86         %InfoLabel.text = "Downloading. This can take a moment."
87         %Loading.show()
88         %LoadingIcon.create_tween().set_loops().tween_property(%LoadingIcon, 'rotation', 2*PI, 1).from(0)
89
90
91 func _on_refresh_pressed() -> void:
92         find_parent('UpdateManager').request_update_check()
93
94
95 func _on_update_manager_downdload_completed(result:int):
96         %Loading.hide()
97         match result:
98                 0: # success
99                         %InfoLabel.text = "Installed successfully. Restart needed!"
100                         %InfoLabel.modulate = editor_view.get_theme_color("success_color", "Editor")
101                         %Restart.show()
102                         %Restart.grab_focus()
103                 1: # failure
104                         %InfoLabel.text = "Download failed."
105                         %InfoLabel.modulate = editor_view.get_theme_color("readonly_color", "Editor")
106
107
108 func _on_resources_reimported(resources:Array) -> void:
109         if is_inside_tree():
110                 await get_tree().process_frame
111                 get_parent().move_to_foreground()
112
113
114 func markdown_to_bbcode(text:String) -> String:
115         var font_sizes := {1:20, 2:16, 3:16,4:14, 5:14}
116         var title_regex := RegEx.create_from_string('(^|\n)((?<level>#+)(?<title>.*))\\n')
117         var res := title_regex.search(text)
118         while res:
119                 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]')
120                 res = title_regex.search(text)
121
122         var link_regex := RegEx.create_from_string('(?<!\\!)\\[(?<text>[^\\]]*)]\\((?<link>[^)]*)\\)')
123         res = link_regex.search(text)
124         while res:
125                 text = text.replace(res.get_string(), '[url='+res.get_string('link')+']'+res.get_string('text').strip_edges()+'[/url]')
126                 res = link_regex.search(text)
127
128         var image_regex := RegEx.create_from_string('\\!\\[(?<text>[^\\]]*)]\\((?<link>[^)]*)\\)\n*')
129         res = image_regex.search(text)
130         while res:
131                 text = text.replace(res.get_string(), '[url='+res.get_string('link')+']'+res.get_string('text').strip_edges()+'[/url]')
132                 res = image_regex.search(text)
133
134         var italics_regex := RegEx.create_from_string('\\*(?<text>[^\\*\\n]*)\\*')
135         res = italics_regex.search(text)
136         while res:
137                 text = text.replace(res.get_string(), '[i]'+res.get_string('text').strip_edges()+'[/i]')
138                 res = italics_regex.search(text)
139
140         var bullets_regex := RegEx.create_from_string('(?<=\\n)(\\*|-)(?<text>[^\\*\\n]*)\\n')
141         res = bullets_regex.search(text)
142         while res:
143                 text = text.replace(res.get_string(), '[ul]'+res.get_string('text').strip_edges()+'[/ul]\n')
144                 res = bullets_regex.search(text)
145
146         var small_code_regex := RegEx.create_from_string('(?<!`)`(?<text>[^`]+)`')
147         res = small_code_regex.search(text)
148         while res:
149                 text = text.replace(res.get_string(), '[code][color='+get_theme_color("accent_color", "Editor").to_html()+']'+res.get_string('text').strip_edges()+'[/color][/code]')
150                 res = small_code_regex.search(text)
151
152         var big_code_regex := RegEx.create_from_string('(?<!`)```(?<text>[^`]+)```')
153         res = big_code_regex.search(text)
154         while res:
155                 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]')
156                 res = big_code_regex.search(text)
157
158         return text
159
160
161
162 func _on_content_meta_clicked(meta:Variant) -> void:
163         OS.shell_open(str(meta))
164
165
166 func _on_install_mouse_entered() -> void:
167         if not %Install.disabled:
168                 %InstallWarning.show()
169
170
171 func _on_install_mouse_exited() -> void:
172         %InstallWarning.hide()
173
174
175 func _on_restart_pressed() -> void:
176         DialogicUtil.get_dialogic_plugin().get_editor_interface().restart_editor(true)
177
178
179 func _on_close_button_pressed() -> void:
180         get_parent().hide()