Added correct initialization for script editor theme.

Some style fixes for VS interface.
This commit is contained in:
Daniel J. Ramirez 2017-10-02 18:33:42 -05:00
parent 6dc1025e63
commit 6d874ea685
4 changed files with 48 additions and 23 deletions

View File

@ -1683,9 +1683,8 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool
}
ERR_FAIL_COND_V(!se, false);
// load script before adding as child else editor will crash at theme loading
se->set_edited_script(p_script);
tab_container->add_child(se);
se->set_edited_script(p_script);
se->set_tooltip_request_func("_get_debug_tooltip", this);
if (se->get_edit_menu()) {
se->get_edit_menu()->hide();

View File

@ -168,14 +168,34 @@ void ScriptTextEditor::_load_theme_settings() {
text_edit->add_constant_override("line_spacing", EDITOR_DEF("text_editor/theme/line_spacing", 4));
colors_cache.symbol_color = symbol_color;
colors_cache.keyword_color = keyword_color;
colors_cache.basetype_color = basetype_color;
colors_cache.type_color = type_color;
colors_cache.comment_color = comment_color;
colors_cache.string_color = string_color;
theme_loaded = true;
if (!script.is_null())
_set_theme_for_script();
}
void ScriptTextEditor::_set_theme_for_script() {
if (!theme_loaded)
return;
TextEdit *text_edit = code_editor->get_text_edit();
List<String> keywords;
script->get_language()->get_reserved_words(&keywords);
for (List<String>::Element *E = keywords.front(); E; E = E->next()) {
text_edit->add_keyword_color(E->get(), keyword_color);
text_edit->add_keyword_color(E->get(), colors_cache.keyword_color);
}
//colorize core types
const Color basetype_color = colors_cache.basetype_color;
text_edit->add_keyword_color("String", basetype_color);
text_edit->add_keyword_color("Vector2", basetype_color);
text_edit->add_keyword_color("Rect2", basetype_color);
@ -210,7 +230,7 @@ void ScriptTextEditor::_load_theme_settings() {
if (n.begins_with("_"))
n = n.substr(1, n.length());
text_edit->add_keyword_color(n, type_color);
text_edit->add_keyword_color(n, colors_cache.type_color);
}
//colorize comments
@ -223,7 +243,7 @@ void ScriptTextEditor::_load_theme_settings() {
String beg = comment.get_slice(" ", 0);
String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String();
text_edit->add_color_region(beg, end, comment_color, end == "");
text_edit->add_color_region(beg, end, colors_cache.comment_color, end == "");
}
//colorize strings
@ -235,7 +255,7 @@ void ScriptTextEditor::_load_theme_settings() {
String string = E->get();
String beg = string.get_slice(" ", 0);
String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String();
text_edit->add_color_region(beg, end, string_color, end == "");
text_edit->add_color_region(beg, end, colors_cache.string_color, end == "");
}
}
@ -263,10 +283,10 @@ void ScriptTextEditor::reload_text() {
void ScriptTextEditor::_notification(int p_what) {
if (p_what == NOTIFICATION_READY) {
//emit_signal("name_changed");
_load_theme_settings();
switch (p_what) {
case NOTIFICATION_READY:
_load_theme_settings();
break;
}
}
@ -556,6 +576,8 @@ void ScriptTextEditor::set_edited_script(const Ref<Script> &p_script) {
emit_signal("name_changed");
code_editor->update_line_and_column();
_set_theme_for_script();
}
void ScriptTextEditor::_validate_script() {
@ -1452,6 +1474,8 @@ void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color) {
ScriptTextEditor::ScriptTextEditor() {
theme_loaded = false;
code_editor = memnew(CodeTextEditor);
add_child(code_editor);
code_editor->add_constant_override("separation", 0);

View File

@ -57,6 +57,17 @@ class ScriptTextEditor : public ScriptEditorBase {
int color_line;
String color_args;
struct ColorsCache {
Color symbol_color;
Color keyword_color;
Color basetype_color;
Color type_color;
Color comment_color;
Color string_color;
} colors_cache;
bool theme_loaded;
enum {
EDIT_UNDO,
EDIT_REDO,
@ -101,6 +112,7 @@ protected:
void _validate_script();
void _code_complete_script(const String &p_code, List<String> *r_options, bool &r_force);
void _load_theme_settings();
void _set_theme_for_script();
void _notification(int p_what);
static void _bind_methods();

View File

@ -710,7 +710,7 @@ void VisualScriptEditor::_update_members() {
functions->set_text(0, TTR("Functions:"));
functions->add_button(0, Control::get_icon("Override", "EditorIcons"), 1);
functions->add_button(0, Control::get_icon("Add", "EditorIcons"), 0);
functions->set_custom_bg_color(0, Control::get_color("prop_section", "Editor"));
functions->set_custom_color(0, Control::get_color("mono_color", "Editor"));
List<StringName> func_names;
script->get_function_list(&func_names);
@ -719,13 +719,7 @@ void VisualScriptEditor::_update_members() {
ti->set_text(0, E->get());
ti->set_selectable(0, true);
ti->set_editable(0, true);
//ti->add_button(0,Control::get_icon("Edit","EditorIcons"),0); function arguments are in the node now
//ti->add_button(0, Control::get_icon("Del", "EditorIcons"), 1);
ti->set_metadata(0, E->get());
if (E->get() == edited_func) {
ti->set_custom_bg_color(0, get_color("prop_category", "Editor"));
ti->set_custom_color(0, Color(1, 1, 1, 1));
}
if (selected == E->get())
ti->select(0);
}
@ -734,7 +728,7 @@ void VisualScriptEditor::_update_members() {
variables->set_selectable(0, false);
variables->set_text(0, TTR("Variables:"));
variables->add_button(0, Control::get_icon("Add", "EditorIcons"));
variables->set_custom_bg_color(0, Control::get_color("prop_section", "Editor"));
variables->set_custom_color(0, Control::get_color("mono_color", "Editor"));
Ref<Texture> type_icons[Variant::VARIANT_MAX] = {
Control::get_icon("MiniVariant", "EditorIcons"),
@ -778,8 +772,6 @@ void VisualScriptEditor::_update_members() {
ti->set_selectable(0, true);
ti->set_editable(0, true);
//ti->add_button(0, Control::get_icon("Edit", "EditorIcons"), 0);
//ti->add_button(0, Control::get_icon("Del", "EditorIcons"), 1);
ti->set_metadata(0, E->get());
if (selected == E->get())
ti->select(0);
@ -789,7 +781,7 @@ void VisualScriptEditor::_update_members() {
_signals->set_selectable(0, false);
_signals->set_text(0, TTR("Signals:"));
_signals->add_button(0, Control::get_icon("Add", "EditorIcons"));
_signals->set_custom_bg_color(0, Control::get_color("prop_section", "Editor"));
_signals->set_custom_color(0, Control::get_color("mono_color", "Editor"));
List<StringName> signal_names;
script->get_custom_signal_list(&signal_names);
@ -798,8 +790,6 @@ void VisualScriptEditor::_update_members() {
ti->set_text(0, E->get());
ti->set_selectable(0, true);
ti->set_editable(0, true);
//ti->add_button(0, Control::get_icon("Edit", "EditorIcons"), 0);
//ti->add_button(0, Control::get_icon("Del", "EditorIcons"), 1);
ti->set_metadata(0, E->get());
if (selected == E->get())
ti->select(0);