5 @onready var editor_view := find_parent('EditorView')
9 await editor_view.ready
10 theme = editor_view.theme
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)
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()
26 func load_info(info:Dictionary, update_type:int) -> void:
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?"
35 %Install.disabled = true
38 # If we are up to date (or beyond):
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
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
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
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
65 if info.has('reactions'):
67 var reactions := {"laugh":"😂", "hooray":"🎉", "confused":"😕", "heart":"❤️", "rocket":"🚀", "eyes":"👀"}
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'])
75 %Reactions.get_node("Likes").visible = false
79 func _on_window_close_requested() -> void:
80 get_parent().visible = false
83 func _on_install_pressed() -> void:
84 find_parent('UpdateManager').request_update_download()
86 %InfoLabel.text = "Downloading. This can take a moment."
88 %LoadingIcon.create_tween().set_loops().tween_property(%LoadingIcon, 'rotation', 2*PI, 1).from(0)
91 func _on_refresh_pressed() -> void:
92 find_parent('UpdateManager').request_update_check()
95 func _on_update_manager_downdload_completed(result:int):
99 %InfoLabel.text = "Installed successfully. Restart needed!"
100 %InfoLabel.modulate = editor_view.get_theme_color("success_color", "Editor")
102 %Restart.grab_focus()
104 %InfoLabel.text = "Download failed."
105 %InfoLabel.modulate = editor_view.get_theme_color("readonly_color", "Editor")
108 func _on_resources_reimported(resources:Array) -> void:
110 await get_tree().process_frame
111 get_parent().move_to_foreground()
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)
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)
122 var link_regex := RegEx.create_from_string('(?<!\\!)\\[(?<text>[^\\]]*)]\\((?<link>[^)]*)\\)')
123 res = link_regex.search(text)
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)
128 var image_regex := RegEx.create_from_string('\\!\\[(?<text>[^\\]]*)]\\((?<link>[^)]*)\\)\n*')
129 res = image_regex.search(text)
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)
134 var italics_regex := RegEx.create_from_string('\\*(?<text>[^\\*\\n]*)\\*')
135 res = italics_regex.search(text)
137 text = text.replace(res.get_string(), '[i]'+res.get_string('text').strip_edges()+'[/i]')
138 res = italics_regex.search(text)
140 var bullets_regex := RegEx.create_from_string('(?<=\\n)(\\*|-)(?<text>[^\\*\\n]*)\\n')
141 res = bullets_regex.search(text)
143 text = text.replace(res.get_string(), '[ul]'+res.get_string('text').strip_edges()+'[/ul]\n')
144 res = bullets_regex.search(text)
146 var small_code_regex := RegEx.create_from_string('(?<!`)`(?<text>[^`]+)`')
147 res = small_code_regex.search(text)
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)
152 var big_code_regex := RegEx.create_from_string('(?<!`)```(?<text>[^`]+)```')
153 res = big_code_regex.search(text)
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)
162 func _on_content_meta_clicked(meta:Variant) -> void:
163 OS.shell_open(str(meta))
166 func _on_install_mouse_entered() -> void:
167 if not %Install.disabled:
168 %InstallWarning.show()
171 func _on_install_mouse_exited() -> void:
172 %InstallWarning.hide()
175 func _on_restart_pressed() -> void:
176 DialogicUtil.get_dialogic_plugin().get_editor_interface().restart_editor(true)
179 func _on_close_button_pressed() -> void: