add scripts for custom font

This commit is contained in:
Nicolò Santilio 2020-10-12 18:18:45 +02:00 committed by GitHub
parent a636be4115
commit 5965161df7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 684 additions and 647 deletions

View File

@ -9,9 +9,11 @@ onready var NewFileDialogue_name = $NewFileDialogue/VBoxContainer/new_filename
onready var FileBTN = $FileEditorContainer/TobBar/file_btn.get_popup()
onready var PreviewBTN = $FileEditorContainer/TobBar/preview_btn.get_popup()
onready var EditorBTN = $FileEditorContainer/TobBar/editor_btn.get_popup()
onready var SettingsBTN : PopupMenu = $FileEditorContainer/TobBar/SettingsBtn.get_popup()
onready var Version = $FileEditorContainer/TobBar/version
onready var SelectFontDialog : FileDialog = $SelectFontDialog
onready var FileContainer = $FileEditorContainer/SplitContainer/FileContainer
onready var OpenFileList = $FileEditorContainer/SplitContainer/FileContainer/OpenFileList
@ -62,7 +64,7 @@ var save_as = false
var current_editor : Control
var current_ini_editor : Control
var current_csv_editor : Control
var current_font : DynamicFont
func _ready():
@ -74,8 +76,8 @@ func _ready():
load_icons()
var opened_files : Array = LastOpenedFiles.load_opened_files()
for open_file in opened_files:
open_file(open_file[1])
for opened_file in opened_files:
open_file(opened_file[1], opened_file[2])
FileList.set_filters(EXTENSIONS)
@ -145,17 +147,21 @@ func load_icons():
$FileEditorContainer/TobBar/file_btn.icon = IconLoader.load_icon_from_name("file")
$FileEditorContainer/TobBar/preview_btn.icon = IconLoader.load_icon_from_name("read")
$FileEditorContainer/TobBar/editor_btn.icon = IconLoader.load_icon_from_name("edit_")
$FileEditorContainer/TobBar/SettingsBtn.icon = IconLoader.load_icon_from_name("settings")
func connect_signals():
FileList.connect("confirmed",self,"update_list")
FileBTN.connect("id_pressed",self,"_on_filebtn_pressed")
PreviewBTN.connect("id_pressed",self,"_on_previewbtn_pressed")
EditorBTN.connect("id_pressed",self,"_on_editorbtn_pressed")
SettingsBTN.connect("id_pressed",self,"_on_settingsbtn_pressed")
OpenFileList.connect("item_selected",self,"_on_fileitem_pressed")
WrapBTN.connect("item_selected",self,"on_wrap_button")
MapBTN.connect("item_selected",self,"on_minimap_button")
SelectFontDialog.connect("file_selected",self,"_on_font_selected")
func update_version():
var plugin_version = ""
var config = ConfigFile.new()
@ -279,6 +285,19 @@ func _on_editorbtn_pressed(index : int):
current_ini_editor = open_in_inieditor(current_file_path)
current_ini_editor.show()
func _on_settingsbtn_pressed(index : int):
match index:
0:
SelectFontDialog.popup()
func _on_font_selected(font_path : String):
current_editor.set_font(font_path)
LastOpenedFiles.store_editor_fonts(current_file_path.get_file(), font_path)
# Enable this part of code to apply the new font to all Vanilla Editors opened
# for file in [0,OpenFileList.get_child_count()]:
# OpenFileList.get_item_metadata(file)[0].set_font(dynamic_font)
# current_font = dynamic_font
func _on_fileitem_pressed(index : int):
current_file_index = index
var selected_item_metadata = OpenFileList.get_item_metadata(current_file_index)
@ -337,11 +356,13 @@ func _on_fileitem_pressed(index : int):
current_editor.show()
OpenFileName.set_text(current_editor.current_path)
func open_file(path : String):
func open_file(path : String, font : String = "null"):
if current_file_path != path:
current_file_path = path
var vanilla_editor = open_in_vanillaeditor(path)
if font != "null":
vanilla_editor.set_font(font)
var ini_editor = open_in_inieditor(path)
var csv_editor = open_in_csveditor(path)

View File

@ -26,8 +26,17 @@ func load_opened_files() -> Array:
var file = ConfigFile.new()
file.load(lastopenedfile_path)
var keys = []
# Load opened files
if file.has_section("Opened"):
var openedfiles = file.get_section_keys("Opened")
for openedfile in openedfiles:
keys.append([openedfile,file.get_value("Opened",openedfile)])
# Load each single file which was opened
# creating and returning an Array with this format [1:file name, 2:file path, 3:file font]
keys.append([openedfile, file.get_value("Opened",openedfile), file.get_value("Fonts",openedfile) if file.has_section_key("Fonts",openedfile) else "null"])
return keys
func store_editor_fonts(file_name : String, font_path : String):
var file = ConfigFile.new()
file.load(lastopenedfile_path)
file.set_value("Fonts",file_name,font_path)
file.save(lastopenedfile_path)

View File

@ -40,6 +40,13 @@ func _ready():
add_to_group("vanilla_editor")
func set_font(font_path : String) -> void:
var dynamic_font : DynamicFont = DynamicFont.new()
var dynamic_font_data : DynamicFontData = DynamicFontData.new()
dynamic_font_data.set_font_path(font_path)
dynamic_font.set_font_data(dynamic_font_data)
TextEditor.set("custom_fonts/font",dynamic_font)
func set_wrap_enabled(enabled:bool):
TextEditor.set_wrap_enabled(enabled)
TextEditor.update()