mirror of
https://github.com/RPG-Research/bcirpg.git
synced 2024-04-16 14:23:01 +00:00
Made a toolset folder, and added the Dialogic plugin.
This commit is contained in:
@ -0,0 +1,202 @@
|
||||
extends Node
|
||||
|
||||
var heading1_font = "res://addons/dialogic/Documentation/Theme/DocumentationH1.tres"
|
||||
var heading2_font = "res://addons/dialogic/Documentation/Theme/DocumentationH2.tres"
|
||||
var heading3_font = "res://addons/dialogic/Documentation/Theme/DocumentationH3.tres"
|
||||
var heading4_font = "res://addons/dialogic/Documentation/Theme/DocumentationH4.tres"
|
||||
var heading5_font = "res://addons/dialogic/Documentation/Theme/DocumentationH5.tres"
|
||||
|
||||
## These will change with each parsing, but can be saved manually after parsing
|
||||
var heading1s = []
|
||||
var heading2s = []
|
||||
var heading3s = []
|
||||
var heading4s = []
|
||||
var heading5s = []
|
||||
var result = ""
|
||||
var bolded = []
|
||||
var italics = []
|
||||
var striked = []
|
||||
var coded = []
|
||||
var linknames = []
|
||||
var links = []
|
||||
var imagenames = []
|
||||
var imagelinks = []
|
||||
var lists = []
|
||||
var underlined = []
|
||||
|
||||
var accent_color := Color()
|
||||
var sub_accent_color := Color()
|
||||
|
||||
var editor_scale := 1.0
|
||||
|
||||
################################################################################
|
||||
## PUBLIC FUNCTIONS ##
|
||||
################################################################################
|
||||
|
||||
func set_accent_colors(new_accent_color : Color, new_sub_accent_color : Color) -> void:
|
||||
accent_color = new_accent_color
|
||||
sub_accent_color = new_sub_accent_color
|
||||
|
||||
### Takes a markdown string and returns it as BBCode
|
||||
func parse(content : String, file_path:String = '', docs_path:String = ''):
|
||||
|
||||
heading1s = []
|
||||
heading2s = []
|
||||
heading3s = []
|
||||
heading4s = []
|
||||
heading5s = []
|
||||
result = ""
|
||||
bolded = []
|
||||
italics = []
|
||||
striked = []
|
||||
coded = []
|
||||
linknames = []
|
||||
links = []
|
||||
imagenames = []
|
||||
imagelinks = []
|
||||
lists = []
|
||||
underlined = []
|
||||
|
||||
var parsed_text = content
|
||||
|
||||
var regex = RegEx.new()
|
||||
|
||||
## Remove all comments
|
||||
# TODO: remove comments <!-- -->
|
||||
|
||||
|
||||
## Find all occurences of bold text
|
||||
regex.compile('\\*\\*(?<boldtext>(\\.|[^(\\*\\*)])*)\\*\\*')
|
||||
result = regex.search_all(content)
|
||||
if result:
|
||||
for res in result:
|
||||
parsed_text = parsed_text.replace("**"+res.get_string("boldtext")+"**","[b]"+res.get_string("boldtext")+"[/b]")
|
||||
|
||||
## Find all occurences of underlined text
|
||||
regex.compile('\\_\\_(?<underlinetext>.*)\\_\\_')
|
||||
result = regex.search_all(content)
|
||||
if result:
|
||||
for res in result:
|
||||
parsed_text = parsed_text.replace("__"+res.get_string("underlinetext")+"__","[u]"+res.get_string("underlinetext")+"[/u]")
|
||||
|
||||
## Find all occurences of italic text
|
||||
regex.compile("\\*(?<italictext>[^\\*]*)\\*")
|
||||
result = regex.search_all(content)
|
||||
if result:
|
||||
for res in result:
|
||||
parsed_text = parsed_text.replace("*"+res.get_string('italictext')+'*', "[i]"+res.get_string('italictext')+"[/i]")
|
||||
# italics.append(res.get_string("italictext"))
|
||||
# for italic in italics:
|
||||
# content = content.replace("*"+italic+"*",)
|
||||
|
||||
|
||||
## Find all occurences of underlined text
|
||||
regex.compile("~~(?<strikedtext>.*)~~")
|
||||
result = regex.search_all(content)
|
||||
if result:
|
||||
for res in result:
|
||||
parsed_text = parsed_text.replace("~~"+res.get_string("strikedtext")+"~~","[s]"+res.get_string("strikedtext")+"[/s]")
|
||||
|
||||
## Find all occurences of code snippets
|
||||
regex.compile("(([^`]`)|(```))(?<coded>[^`]+)(?(2)(`)|(```))")
|
||||
result = regex.search_all(content)
|
||||
if result:
|
||||
for res in result:
|
||||
if res.get_string().begins_with("```"):
|
||||
parsed_text = parsed_text.replace("```"+res.get_string("coded")+"```","[indent][color=#"+accent_color.lightened(0.6).to_html()+"][code]"+res.get_string("coded")+"[/code][/color][/indent]")
|
||||
else:
|
||||
parsed_text = parsed_text.replace("`"+res.get_string("coded")+"`","[color=#"+accent_color.lightened(0.6).to_html()+"][code]"+res.get_string("coded")+"[/code][/color]")
|
||||
|
||||
|
||||
|
||||
## Find all occurences of list items
|
||||
regex.compile("\\n\\s*(?<symbol>[-+*])(?<element>\\s.*)")
|
||||
result = regex.search_all(parsed_text)
|
||||
if result:
|
||||
for res in result:
|
||||
var symbol = res.get_string('symbol')
|
||||
var element = res.get_string("element")
|
||||
if parsed_text.find(symbol+" "+element):
|
||||
parsed_text = parsed_text.replace(symbol+" "+element,"[indent]"+symbol+" "+element+"[/indent]")
|
||||
|
||||
## Find all occurences of images
|
||||
regex.compile("!\\[(?<imgname>.*)\\]\\((?<imglink>.*)\\)")
|
||||
result = regex.search_all(content)
|
||||
if result:
|
||||
for res in result:
|
||||
if res.get_string("imglink")!="":
|
||||
imagelinks.append(res.get_string("imglink"))
|
||||
if res.get_string("imgname")!="":
|
||||
imagenames.append(res.get_string("imgname"))
|
||||
|
||||
## Find all occurences of links (that are not images)
|
||||
regex.compile("[^!]\\[(?<linkname>[^\\[]+)\\]\\((?<link>[^\\)]*\\S*?)\\)")
|
||||
result = regex.search_all(content)
|
||||
if result:
|
||||
for res in result:
|
||||
if res.get_string("link")!="":
|
||||
links.append(res.get_string("link"))
|
||||
if res.get_string("linkname")!="":
|
||||
linknames.append(res.get_string("linkname"))
|
||||
|
||||
## Find all heading1s
|
||||
regex.compile("(?:\\n|^)#(?<heading>[^#\\n]+[^\\n]+)")
|
||||
result = regex.search_all(content)
|
||||
if result:
|
||||
for res in result:
|
||||
var heading = res.get_string("heading")
|
||||
heading1s.append(heading)
|
||||
parsed_text = parsed_text.replace("#"+heading, "[color=#"+accent_color.lightened(0.2).to_html()+"][font="+heading1_font+"]"+heading.strip_edges()+"[/font][/color]")
|
||||
|
||||
## Find all heading2s
|
||||
regex.compile("(?:\\n|^)##(?<heading>[^#\\n]+[^\\n]+)")
|
||||
result = regex.search_all(content)
|
||||
if result:
|
||||
for res in result:
|
||||
var heading = res.get_string("heading")
|
||||
heading2s.append(heading)
|
||||
parsed_text = parsed_text.replace("\n##"+heading, "\n[color=#"+accent_color.lightened(0.5).to_html()+"][font="+heading2_font+"]"+heading.strip_edges()+"[/font][/color]")
|
||||
|
||||
## Find all heading3s
|
||||
regex.compile("(?:\\n|^)###(?<heading>[^#\\n]+[^\\n]+)")
|
||||
result = regex.search_all(content)
|
||||
if result:
|
||||
for res in result:
|
||||
var heading = res.get_string("heading")
|
||||
parsed_text = parsed_text.replace("\n###"+heading, "\n[color=#"+accent_color.lightened(0.7).to_html()+"][font="+heading3_font+"]"+heading.strip_edges()+"[/font][/color]")
|
||||
|
||||
## Find all heading4s
|
||||
regex.compile("(?:\\n|^)####(?<heading>[^#\\n]+[^\\n]+)")
|
||||
result = regex.search_all(content)
|
||||
if result:
|
||||
for res in result:
|
||||
var heading = res.get_string("heading")
|
||||
parsed_text = parsed_text.replace("\n####"+heading, "\n[color=#"+accent_color.lightened(0.85).to_html()+"][font="+heading4_font+"]"+heading.strip_edges()+"[/font][/color]")
|
||||
|
||||
|
||||
## Find all heading5s
|
||||
regex.compile("(?:\\n|^)#####(?<heading>[^#\\n]+[^\\n]+)")
|
||||
result = regex.search_all(content)
|
||||
if result:
|
||||
for res in result:
|
||||
var heading = res.get_string("heading")
|
||||
parsed_text = parsed_text.replace("\n#####"+heading, "\n[color=#"+accent_color.lightened(0.85).to_html()+"][font="+heading5_font+"]"+heading.strip_edges()+"[/font][/color]")
|
||||
|
||||
for i in links.size():
|
||||
parsed_text = parsed_text.replace("["+linknames[i]+"]("+links[i]+")","[color=#"+accent_color.to_html()+"][url="+links[i]+"]"+linknames[i]+"[/url][/color]")
|
||||
|
||||
for i in imagenames.size():
|
||||
var imagelink_to_use = imagelinks[i]
|
||||
if imagelink_to_use.begins_with("http"):
|
||||
var path_parts = imagelink_to_use.split("/Documentation/")
|
||||
if path_parts.size() > 1:
|
||||
imagelink_to_use = docs_path +"/"+ path_parts[1]
|
||||
else:
|
||||
imagelink_to_use = "icon.png"
|
||||
if imagelink_to_use.begins_with(".") and file_path:
|
||||
imagelink_to_use = file_path.trim_suffix(file_path.get_file()).trim_suffix("/") + imagelink_to_use.trim_prefix(".")
|
||||
parsed_text = parsed_text.replace("!["+imagenames[i]+"]("+imagelinks[i]+")","[img="+str(int(700*editor_scale))+"]"+imagelink_to_use+"[/img]")
|
||||
|
||||
parsed_text += "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
|
||||
|
||||
return parsed_text
|
@ -0,0 +1,206 @@
|
||||
tool
|
||||
extends Control
|
||||
|
||||
export (bool) var enable_editing = false
|
||||
# needs to be corrected, if you use this on a diffrent plugin!!!
|
||||
export (String) var documentation_path: String = "res://addons/dialogic/Documentation"
|
||||
var MarkdownParser = load("res://addons/dialogic/Documentation/Nodes/DocsMarkdownParser.gd").new()
|
||||
|
||||
var current_path: String = ""
|
||||
var current_headings = []
|
||||
|
||||
onready var Content = $Content
|
||||
|
||||
signal open_non_html_link(link, section)
|
||||
|
||||
################################################################################
|
||||
## PUBLIC FUNCTIONS ##
|
||||
################################################################################
|
||||
|
||||
## Opens a page at path PAGE_PATH
|
||||
## The PAGE_PATH can be a full godot path or a path from Documentation/Content
|
||||
## E.g.:
|
||||
## "res://addons/thing/Documentation/Content/Tuts/welcome.md" == "Tuts/welcome"
|
||||
##
|
||||
## The section can either be passed as a second argument or in the PAGE_PATH with #
|
||||
## E.g.: "Tuts/welcome#how-to-use-the-plugin" == "Tuts/welcome", "#how-to-use-the-plugin"
|
||||
func load_page(page_path: String, section : String=''):
|
||||
Content.set('custom_styles/normal', StyleBoxEmpty.new())
|
||||
Content.get('custom_styles/normal').content_margin_left = 15
|
||||
Content.get('custom_styles/normal').content_margin_top = 15
|
||||
Content.get('custom_styles/normal').content_margin_right = 15
|
||||
Content.get('custom_styles/normal').content_margin_bottom = 15
|
||||
|
||||
var base_size = 16
|
||||
Content.set('custom_fonts/normal_font/size', int(base_size * get_constant("scale", "Editor")))
|
||||
Content.set('custom_fonts/bold_font/size', int(base_size * get_constant("scale", "Editor")))
|
||||
#Content.set('custom_fonts/italics_font/size', int(base_size * get_constant("scale", "Editor")))
|
||||
Content.set('custom_fonts/mono_font/size', int(base_size * get_constant("scale", "Editor")))
|
||||
Content.set('custom_fonts/bold_italics_font/size', int(base_size * get_constant("scale", "Editor")))
|
||||
|
||||
|
||||
# Fonts
|
||||
Content.set('custom_fonts/mono_font', get_font("doc_source", "EditorFonts"))
|
||||
Content.set('custom_fonts/bold_font', Content.get_font("doc_bold", "EditorFonts"))
|
||||
|
||||
MarkdownParser.set_accent_colors(get_color("accent_color", "Editor"),get_color("disabled_font_color", "Editor"))
|
||||
# return if no path is given
|
||||
if page_path == '' and not section:
|
||||
return
|
||||
|
||||
show()
|
||||
_on_Content_resized()
|
||||
|
||||
#print("load page ", page_path)
|
||||
# find a section specifier at the end of the path
|
||||
if page_path.count("#") > 0:
|
||||
var result = page_path.split('#')
|
||||
page_path = result[0]
|
||||
section = '#'+result[1]
|
||||
|
||||
# add necessary parts to the path
|
||||
if not page_path.begins_with("res://"):
|
||||
page_path = documentation_path+"/Content/"+page_path
|
||||
if not page_path.ends_with('.md'):
|
||||
page_path += ".md"
|
||||
|
||||
# opening the file
|
||||
var f = File.new()
|
||||
f.open(page_path,File.READ)
|
||||
current_path = page_path
|
||||
|
||||
# parsing the file
|
||||
Content.bbcode_text = MarkdownParser.parse(f.get_as_text(), current_path, documentation_path)
|
||||
f.close()
|
||||
|
||||
# saving the headings for going to sections
|
||||
current_headings = MarkdownParser.heading1s + MarkdownParser.heading2s + MarkdownParser.heading3s + MarkdownParser.heading4s + MarkdownParser.heading5s
|
||||
create_content_menu(MarkdownParser.heading1s + MarkdownParser.heading2s)
|
||||
|
||||
# scroll to the given section
|
||||
if not scroll_to_section(section):
|
||||
Content.scroll_to_line(0)
|
||||
|
||||
# Scroll to top of the document. This probably broke the previews "scroll to the given section" part of the code
|
||||
yield(get_tree(), "idle_frame")
|
||||
_on_Up_pressed()
|
||||
|
||||
|
||||
# looks if there is a heading similar to the given TITLE and then scrolls there
|
||||
func scroll_to_section(title):
|
||||
if not title:
|
||||
return
|
||||
# this is not really nicely done...
|
||||
for heading in current_headings:
|
||||
if (heading.to_lower().strip_edges().replace(' ', '-') == title.replace('#', '')) or \
|
||||
(heading.to_lower().strip_edges() == title.to_lower().strip_edges()):
|
||||
var x = Content.bbcode_text.find(heading.replace('#', '').strip_edges()+"[/font]")
|
||||
x = Content.bbcode_text.count("\n", 0, x)
|
||||
Content.scroll_to_line(x)
|
||||
|
||||
$ContentMenu/Panel.hide()
|
||||
|
||||
return true
|
||||
|
||||
|
||||
################################################################################
|
||||
## PRIVATE FUNCTIONS ##
|
||||
################################################################################
|
||||
|
||||
func _ready():
|
||||
$Up.icon = get_icon("ArrowUp", "EditorIcons")
|
||||
|
||||
$Editing.visible = enable_editing
|
||||
|
||||
|
||||
# creates the conten menu
|
||||
func create_content_menu(headings):
|
||||
for child in $ContentMenu/Panel/VBox.get_children():
|
||||
child.queue_free()
|
||||
if len(headings) < 2:
|
||||
$ContentMenu.hide()
|
||||
return
|
||||
$ContentMenu.show()
|
||||
headings.pop_front()
|
||||
for heading in headings:
|
||||
var button = Button.new()
|
||||
button.set("custom_styles/normal", get_stylebox("sub_inspector_bg0", "Editor"))
|
||||
button.text = heading
|
||||
button.align = Button.ALIGN_LEFT
|
||||
button.connect("pressed", self, "content_button_pressed", [heading])
|
||||
$ContentMenu/Panel/VBox.add_child(button)
|
||||
|
||||
|
||||
func content_button_pressed(heading):
|
||||
scroll_to_section(heading)
|
||||
$ContentMenu/ToggleContents.pressed = false
|
||||
|
||||
|
||||
## When one of the links is clicked
|
||||
func _on_meta_clicked(meta):
|
||||
## Check wether this is a real LINK
|
||||
if meta.begins_with("http"):
|
||||
|
||||
# test if we can interpret this as a normal link to a docs file
|
||||
if meta.count("Documentation/Content") > 0:
|
||||
meta = meta.split("Documentation/Content")[1]
|
||||
|
||||
# else open it with the browser
|
||||
else:
|
||||
OS.shell_open(meta)
|
||||
return
|
||||
|
||||
## Check wether it is a section
|
||||
if meta.begins_with("#"):
|
||||
# try to open it in this document
|
||||
scroll_to_section(meta)
|
||||
|
||||
## Else send a signal that the pluginmaker has to interpret
|
||||
else:
|
||||
# if the link contains a section
|
||||
var link = meta
|
||||
var section = null
|
||||
if meta.count("#") > 0:
|
||||
var split = meta.split('#')
|
||||
link = split[0]
|
||||
section = split[1]
|
||||
if link.begins_with('.'):
|
||||
link = current_path.trim_suffix(current_path.get_file()).trim_suffix("/") + link.trim_prefix(".")
|
||||
if not link.begins_with("res://"):
|
||||
link = documentation_path.plus_file('Content').plus_file(link)
|
||||
if not link.ends_with(".md"):
|
||||
link += '.md'
|
||||
|
||||
emit_signal("open_non_html_link", link, section)
|
||||
|
||||
|
||||
func _on_EditPage_pressed():
|
||||
var x = File.new()
|
||||
x.open(current_path, File.READ)
|
||||
OS.shell_open(x.get_path_absolute())
|
||||
|
||||
|
||||
func _on_RefreshPage_pressed():
|
||||
load_page(current_path)
|
||||
|
||||
|
||||
func _on_Up_pressed():
|
||||
Content.scroll_to_line(0)
|
||||
|
||||
|
||||
func _on_ToggleContents_toggled(button_pressed):
|
||||
$ContentMenu/Panel.visible = button_pressed
|
||||
|
||||
func toggle_editing():
|
||||
enable_editing = !enable_editing
|
||||
$Editing.visible = enable_editing
|
||||
|
||||
func _on_Content_resized():
|
||||
if not Content: return
|
||||
if Content.rect_size.x < 500:
|
||||
Content.get('custom_styles/normal').content_margin_left = 15
|
||||
Content.get('custom_styles/normal').content_margin_right = 15
|
||||
else:
|
||||
Content.get('custom_styles/normal').content_margin_left = (Content.rect_size.x-500)/4
|
||||
Content.get('custom_styles/normal').content_margin_right = (Content.rect_size.x-500)/3
|
||||
Content.update()
|
@ -0,0 +1,178 @@
|
||||
[gd_scene load_steps=13 format=2]
|
||||
|
||||
[ext_resource path="res://addons/dialogic/Documentation/Theme/Font/NotoSans-Regular.ttf" type="DynamicFontData" id=1]
|
||||
[ext_resource path="res://addons/dialogic/Documentation/Theme/Font/NotoSans-Bold.ttf" type="DynamicFontData" id=2]
|
||||
[ext_resource path="res://addons/dialogic/Documentation/Theme/Font/NotoSans-Italic.ttf" type="DynamicFontData" id=3]
|
||||
[ext_resource path="res://addons/dialogic/Documentation/Nodes/DocsPageViewer.gd" type="Script" id=6]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id=1]
|
||||
content_margin_left = 89.5
|
||||
content_margin_right = 119.333
|
||||
|
||||
[sub_resource type="DynamicFont" id=2]
|
||||
use_filter = true
|
||||
extra_spacing_char = 2
|
||||
extra_spacing_space = 2
|
||||
font_data = ExtResource( 1 )
|
||||
|
||||
[sub_resource type="DynamicFont" id=3]
|
||||
use_filter = true
|
||||
font_data = ExtResource( 2 )
|
||||
|
||||
[sub_resource type="DynamicFont" id=4]
|
||||
font_data = ExtResource( 3 )
|
||||
|
||||
[sub_resource type="DynamicFont" id=5]
|
||||
font_data = ExtResource( 2 )
|
||||
|
||||
[sub_resource type="DynamicFont" id=6]
|
||||
use_filter = true
|
||||
font_data = ExtResource( 1 )
|
||||
|
||||
[sub_resource type="Image" id=9]
|
||||
data = {
|
||||
"data": PoolByteArray( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
|
||||
"format": "LumAlpha8",
|
||||
"height": 16,
|
||||
"mipmaps": false,
|
||||
"width": 16
|
||||
}
|
||||
|
||||
[sub_resource type="ImageTexture" id=8]
|
||||
flags = 4
|
||||
flags = 4
|
||||
image = SubResource( 9 )
|
||||
size = Vector2( 16, 16 )
|
||||
|
||||
[node name="DocsPageViewer" type="Control"]
|
||||
margin_right = 1024.0
|
||||
margin_bottom = 600.0
|
||||
focus_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource( 6 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Content" type="RichTextLabel" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
rect_min_size = Vector2( 50, 0 )
|
||||
focus_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
custom_styles/normal = SubResource( 1 )
|
||||
custom_fonts/mono_font = SubResource( 2 )
|
||||
custom_fonts/bold_italics_font = SubResource( 3 )
|
||||
custom_fonts/italics_font = SubResource( 4 )
|
||||
custom_fonts/bold_font = SubResource( 5 )
|
||||
custom_fonts/normal_font = SubResource( 6 )
|
||||
custom_colors/selection_color = Color( 0.45098, 0.45098, 0.45098, 0.45098 )
|
||||
bbcode_enabled = true
|
||||
bbcode_text = "Can't find the specified file."
|
||||
text = "Can't find the specified file."
|
||||
scroll_following = true
|
||||
selection_enabled = true
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Editing" type="HBoxContainer" parent="."]
|
||||
visible = false
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
margin_left = -202.807
|
||||
margin_top = 8.09956
|
||||
margin_right = -8.80664
|
||||
margin_bottom = 33.0996
|
||||
grow_horizontal = 0
|
||||
alignment = 2
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="RefreshPage" type="Button" parent="Editing"]
|
||||
margin_left = 94.0
|
||||
margin_right = 154.0
|
||||
margin_bottom = 25.0
|
||||
text = "Refresh"
|
||||
|
||||
[node name="EditPage" type="Button" parent="Editing"]
|
||||
margin_left = 158.0
|
||||
margin_right = 194.0
|
||||
margin_bottom = 25.0
|
||||
text = "Edit"
|
||||
|
||||
[node name="Up" type="Button" parent="."]
|
||||
anchor_left = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = -40.5946
|
||||
margin_top = -41.6541
|
||||
margin_right = -10.5946
|
||||
margin_bottom = -11.6541
|
||||
rect_min_size = Vector2( 30, 30 )
|
||||
hint_tooltip = "Back to top"
|
||||
icon = SubResource( 8 )
|
||||
expand_icon = true
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="ContentMenu" type="VBoxContainer" parent="."]
|
||||
anchor_left = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = -207.0
|
||||
margin_top = -590.0
|
||||
margin_right = -49.0
|
||||
margin_bottom = -13.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
rect_min_size = Vector2( 50, 40 )
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 9
|
||||
custom_constants/separation = 20
|
||||
alignment = 2
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Panel" type="Control" parent="ContentMenu"]
|
||||
visible = false
|
||||
margin_top = 537.0
|
||||
margin_right = 158.0
|
||||
margin_bottom = 537.0
|
||||
|
||||
[node name="VBox" type="VBoxContainer" parent="ContentMenu/Panel"]
|
||||
margin_top = -88.0
|
||||
margin_right = 156.0
|
||||
margin_bottom = 4.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
size_flags_horizontal = 3
|
||||
alignment = 2
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="ToggleContents" type="Button" parent="ContentMenu"]
|
||||
margin_top = 557.0
|
||||
margin_right = 158.0
|
||||
margin_bottom = 577.0
|
||||
toggle_mode = true
|
||||
text = "Contents"
|
||||
|
||||
[node name="Control" type="Control" parent="."]
|
||||
margin_right = 40.0
|
||||
margin_bottom = 40.0
|
||||
|
||||
[connection signal="meta_clicked" from="Content" to="." method="_on_meta_clicked"]
|
||||
[connection signal="resized" from="Content" to="." method="_on_Content_resized"]
|
||||
[connection signal="pressed" from="Editing/RefreshPage" to="." method="_on_RefreshPage_pressed"]
|
||||
[connection signal="pressed" from="Editing/EditPage" to="." method="_on_EditPage_pressed"]
|
||||
[connection signal="pressed" from="Up" to="." method="_on_Up_pressed"]
|
||||
[connection signal="toggled" from="ContentMenu/ToggleContents" to="." method="_on_ToggleContents_toggled"]
|
@ -0,0 +1,224 @@
|
||||
tool
|
||||
extends Control
|
||||
|
||||
# Don't change this if possible
|
||||
export (String) var documentation_path : String = "res://addons/dialogic/Documentation"
|
||||
|
||||
# This enables/disables the use of folder files
|
||||
# If enabled, the docs will expect a file named
|
||||
# exactly like a folder for each folder in the docs:
|
||||
## E.g.: If you have a Tutorials folder somewhere put a Tutorials.md file next to it.
|
||||
## This way the folder will be clickable and you can see the page,
|
||||
## but it won't be shown as a separate page
|
||||
var use_folder_files = true
|
||||
|
||||
# These files will not be listed. Just use the filename! No paths in here
|
||||
var file_ignore_list = ['Welcome.md']
|
||||
|
||||
|
||||
################################################################################
|
||||
## PUBLIC FUNCTIONS ##
|
||||
################################################################################
|
||||
|
||||
## Returns a dictionary that contains the important parts of the
|
||||
## documentations Content folder.
|
||||
##
|
||||
## This is mainly used if you want to somehow display a list of the docs content,
|
||||
## for example to create a file-tree or a list of documents
|
||||
##
|
||||
## Only files ending on .md are noticed.
|
||||
## Folders that contain no such files are ignored
|
||||
func get_documentation_content():
|
||||
return get_dir_contents(documentation_path+"/Content")
|
||||
|
||||
## Will create a hirarchy of TreeItems on the given 'trees' root_item
|
||||
## If not root_item is given a new root_item will be created
|
||||
## The root item does not have to be the actual root item of the whole tree,
|
||||
## but the root of the documentation branch.
|
||||
##
|
||||
## With def_folder_info and def_page_info special information can be
|
||||
## added to the meta of the Items
|
||||
##
|
||||
## If a filter_term is given, only items with that filter will be created.
|
||||
## Right now there will always be all folders.
|
||||
func build_documentation_tree(tree : Tree, root_item:TreeItem = null, def_folder_info:Dictionary = {}, def_page_info:Dictionary = {}, filter_term:String = ''):
|
||||
return _build_documentation_tree(tree, root_item, def_folder_info, def_page_info, filter_term)
|
||||
|
||||
|
||||
################################################################################
|
||||
## PRIVATE FUNCTIONS ##
|
||||
################################################################################
|
||||
|
||||
|
||||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
### LOOKING THROUGH THE DOCS FOLDERS:
|
||||
|
||||
func get_dir_contents(rootPath: String) -> Dictionary:
|
||||
var directory_structure = {}
|
||||
var dir := Directory.new()
|
||||
|
||||
if dir.open(rootPath) == OK:
|
||||
dir.list_dir_begin(true, false)
|
||||
directory_structure = _add_dir_contents(dir)
|
||||
else:
|
||||
push_error("Docs: An error occurred when trying to access the path.")
|
||||
return directory_structure
|
||||
|
||||
func _add_dir_contents(dir: Directory) -> Dictionary:
|
||||
var file_name = dir.get_next()
|
||||
|
||||
var structure = {}
|
||||
while (file_name != ""):
|
||||
var path = dir.get_current_dir() + "/" + file_name
|
||||
if dir.current_is_dir():
|
||||
#print("Found directory: %s" % path)
|
||||
var subDir = Directory.new()
|
||||
subDir.open(path)
|
||||
subDir.list_dir_begin(true, false)
|
||||
var dir_content = _add_dir_contents(subDir)
|
||||
if dir_content.has('_files_'):
|
||||
structure[path] = dir_content
|
||||
else:
|
||||
#print("Found file: %s" % path)
|
||||
if not file_name.ends_with(".md"):
|
||||
file_name = dir.get_next()
|
||||
continue
|
||||
if file_name in file_ignore_list:
|
||||
file_name = dir.get_next()
|
||||
continue
|
||||
if not structure.has("_files_"):
|
||||
structure["_files_"] = []
|
||||
|
||||
structure["_files_"].append(path)
|
||||
|
||||
file_name = dir.get_next()
|
||||
dir.list_dir_end()
|
||||
return structure
|
||||
|
||||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
### For bouilding the tree
|
||||
|
||||
func _build_documentation_tree(tree : Tree, root_item:TreeItem = null, def_folder_info:Dictionary = {}, def_page_info:Dictionary = {}, filter_term:String =''):
|
||||
|
||||
var documentation_tree
|
||||
if root_item == null:
|
||||
documentation_tree = tree.create_item()
|
||||
documentation_tree.set_text(0, "Documentation")
|
||||
|
||||
else:
|
||||
documentation_tree = root_item
|
||||
|
||||
# if no search is performed, collapse the tree by default
|
||||
if not filter_term:
|
||||
documentation_tree.collapsed = true
|
||||
else:
|
||||
documentation_tree.collapsed = false
|
||||
|
||||
# create the rest of the tree based on the dict we get from the DocsHelper
|
||||
var doc_structure = get_documentation_content()
|
||||
#print(doc_structure)
|
||||
create_doc_tree(tree, documentation_tree, def_folder_info, def_page_info, doc_structure, filter_term)
|
||||
return documentation_tree
|
||||
|
||||
# this calls itself recursivly to create the tree, based on the given dict
|
||||
func create_doc_tree(tree, parent_item, def_folder_info, def_page_info, doc_structure, filter_term):
|
||||
for key in doc_structure.keys():
|
||||
# if this is a folder
|
||||
if typeof(doc_structure[key]) == TYPE_DICTIONARY:
|
||||
var folder_item = _add_documentation_folder(tree, parent_item, {'name':key.get_file(), 'path':key}, def_folder_info)
|
||||
create_doc_tree(tree, folder_item, def_folder_info, def_page_info, doc_structure[key], filter_term)
|
||||
if not filter_term:
|
||||
folder_item.collapsed = true
|
||||
# if this is a page
|
||||
elif typeof(doc_structure[key]) == TYPE_ARRAY:
|
||||
for file in doc_structure[key]:
|
||||
if use_folder_files and file.trim_suffix('.md') in doc_structure.keys():
|
||||
pass
|
||||
else:
|
||||
if not filter_term or (filter_term and filter_term.to_lower() in get_title(file, '').to_lower()):
|
||||
_add_documentation_page(tree, parent_item, {'name':file.get_file().trim_suffix(".md"), 'path': file}, def_page_info)
|
||||
|
||||
func merge_dir(target: Dictionary, patch: Dictionary):
|
||||
var copy = target.duplicate()
|
||||
for key in patch:
|
||||
copy[key] = patch[key]
|
||||
return copy
|
||||
|
||||
# this adds a folder item to the tree
|
||||
func _add_documentation_folder(tree, parent_item, folder_info, default_info):
|
||||
var item = tree.create_item(parent_item)
|
||||
item.set_text(0, folder_info['name'])
|
||||
item.set_icon(0, tree.get_icon("HelpSearch", "EditorIcons"))
|
||||
item.set_editable(0, false)
|
||||
if use_folder_files:
|
||||
var x = File.new()
|
||||
if x.file_exists(folder_info['path']+'.md'):
|
||||
folder_info['path'] += '.md'
|
||||
else:
|
||||
folder_info['path'] = ''
|
||||
else:
|
||||
folder_info['path'] = ''
|
||||
item.set_metadata(0, merge_dir(default_info, folder_info))
|
||||
if not tree.get_constant("dark_theme", "Editor"):
|
||||
item.set_icon_modulate(0, get_color("property_color", "Editor"))
|
||||
return item
|
||||
|
||||
# this adds a page item to the tree
|
||||
func _add_documentation_page(tree, parent, page_info, default_info):
|
||||
var item = tree.create_item(parent)
|
||||
item.set_text(0, get_title(page_info['path'], page_info['name']))
|
||||
item.set_tooltip(0,page_info['path'])
|
||||
item.set_editable(0, false)
|
||||
item.set_icon(0, tree.get_icon("Help", "EditorIcons"))
|
||||
var new_dir = merge_dir(default_info, page_info)
|
||||
#print(new_dir)
|
||||
item.set_metadata(0,new_dir)
|
||||
if not tree.get_constant("dark_theme", "Editor"):
|
||||
item.set_icon_modulate(0, get_color("property_color", "Editor"))
|
||||
return item
|
||||
|
||||
# returns the first line of a text_file, a bit cleaned up
|
||||
func get_title(path, default_name):
|
||||
# opening the file
|
||||
var f = File.new()
|
||||
f.open(path, File.READ)
|
||||
var arr = f.get_as_text().split('\n', false, 1)
|
||||
if not arr.empty():
|
||||
return arr[0].trim_prefix('#').strip_edges()
|
||||
else:
|
||||
return default_name
|
||||
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
## For searching the tree
|
||||
## used to search and select an item of the tree based on a info saved in the metadata
|
||||
## in most cases you just want to search for the item that has a certain path
|
||||
##
|
||||
## the paren_item parameter is only used so this can call itself recursivly
|
||||
func search_and_select_docs(docs_tree_item:TreeItem, info:String, key:String = 'path'):
|
||||
if info == "": return
|
||||
if info == "/":
|
||||
docs_tree_item.select(0)
|
||||
return true
|
||||
#print("Asearch ", key, " ", info)
|
||||
#print("Asearchin on item: ", docs_tree_item.get_text(0))
|
||||
var item = docs_tree_item.get_children()
|
||||
while item:
|
||||
#print("A ",item.get_text(0))
|
||||
if not item.has_method('get_metadata'):
|
||||
item = item.get_next()
|
||||
|
||||
var meta = item.get_metadata(0)
|
||||
#print(meta)
|
||||
if meta.has(key):
|
||||
if meta[key] == info:
|
||||
item.select(0)
|
||||
return true
|
||||
if search_and_select_docs(item, info, key):
|
||||
return true
|
||||
item = item.get_next()
|
||||
return false
|
||||
|
||||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
#### For bouilding the tree
|
||||
#func create_reference():
|
||||
# var RefColl = ReferenceCollector.new()
|
||||
# RefColl._run()
|
@ -0,0 +1,11 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/dialogic/Documentation/Nodes/DocsTreeHelper.gd" type="Script" id=1]
|
||||
|
||||
[node name="DocsTreeHelper" type="Control"]
|
||||
margin_right = 40.0
|
||||
margin_bottom = 40.0
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
tool
|
||||
extends Tree
|
||||
|
||||
var documentation_tree
|
||||
|
||||
# emited when an item is selceted
|
||||
signal _page_selected(path)
|
||||
|
||||
################################################################################
|
||||
## PUBLIC FUNCTIONS ##
|
||||
################################################################################
|
||||
|
||||
func select_item(path):
|
||||
#DocsHelper.search_and_select_docs(documentation_tree, path)
|
||||
pass
|
||||
|
||||
################################################################################
|
||||
## PRIVATE FUNCTIONS ##
|
||||
################################################################################
|
||||
|
||||
func _ready():
|
||||
connect('item_selected', self, '_on_item_selected')
|
||||
#documentation_tree = DocsHelper.build_documentation_tree(self)
|
||||
# have to do this here, because the DocsHelpe has no access to the theme...
|
||||
documentation_tree.set_icon(0, get_icon("Folder", "EditorIcons"))
|
||||
|
||||
|
||||
func _on_item_selected():
|
||||
var item = get_selected()
|
||||
var metadata = item.get_metadata(0)
|
||||
if metadata.has('path'):
|
||||
emit_signal("_page_selected", metadata['path'])
|
@ -0,0 +1,14 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/dialogic/Documentation/Nodes/DocumentationTree.gd" type="Script" id=1]
|
||||
|
||||
|
||||
[node name="DocumentationTree" type="Tree"]
|
||||
margin_right = 506.0
|
||||
margin_bottom = 600.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
tool
|
||||
extends Control
|
||||
|
||||
onready var DocTree = $HSplit/VBoxContainer/DocumentationTree
|
||||
onready var DocPageViewer = $HSplit/DocsPageViewer
|
||||
|
||||
|
||||
func _on_DocsPageViewer_open_non_html_link(link, section):
|
||||
DocTree.select_item(link)
|
||||
DocPageViewer.scroll_to_section(section)
|
||||
|
||||
func _on_DocumentationTree_page_selected(path):
|
||||
DocPageViewer.load_page(path)
|
||||
|
||||
func _on_FilterEntry_text_changed(new_text):
|
||||
var child = DocTree.documentation_tree.get_children()
|
||||
while child:
|
||||
child.call_recursive("call_deferred", "free")
|
||||
child = child.get_next()
|
||||
#DocsHelper.build_documentation_tree(DocTree, DocTree.documentation_tree,{},{}, new_text)
|
||||
DocTree.call_deferred("update")
|
@ -0,0 +1,49 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://addons/dialogic/Documentation/Nodes/DocsPageViewer.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://addons/dialogic/Documentation/Nodes/DocumentationTree.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://addons/dialogic/Documentation/Nodes/DocumentationViewer.gd" type="Script" id=3]
|
||||
|
||||
[node name="DocumentationViewer" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource( 3 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="HSplit" type="HSplitContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="HSplit"]
|
||||
margin_right = 230.0
|
||||
margin_bottom = 600.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
size_flags_stretch_ratio = 0.3
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="FilterEntry" type="LineEdit" parent="HSplit/VBoxContainer"]
|
||||
margin_right = 230.0
|
||||
margin_bottom = 24.0
|
||||
placeholder_text = "Filter Documentation"
|
||||
placeholder_alpha = 0.502
|
||||
|
||||
[node name="DocumentationTree" parent="HSplit/VBoxContainer" instance=ExtResource( 2 )]
|
||||
margin_top = 28.0
|
||||
margin_right = 230.0
|
||||
|
||||
[node name="DocsPageViewer" parent="HSplit" instance=ExtResource( 1 )]
|
||||
margin_left = 242.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[connection signal="text_changed" from="HSplit/VBoxContainer/FilterEntry" to="." method="_on_FilterEntry_text_changed"]
|
||||
[connection signal="open_non_html_link" from="HSplit/DocsPageViewer" to="." method="_on_DocsPageViewer_open_non_html_link"]
|
Reference in New Issue
Block a user