summaryrefslogtreecommitdiff
path: root/tools/editor/plugins
diff options
context:
space:
mode:
authorKostadin Damyanov <maxmight@gmail.com>2015-06-26 21:35:47 +0300
committerKostadin Damyanov <maxmight@gmail.com>2015-06-26 21:35:47 +0300
commite0e54ea7d456c0fabd8f3f9b2667a69ff520f852 (patch)
tree9ce4e0b6db40ac2ab07b8582e57282fe63130165 /tools/editor/plugins
parentf61eb5fd8e13642c82364f8ee66a0f6c791a4511 (diff)
parenta67486a39ee629acac068a6d014015944cf83bb3 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'tools/editor/plugins')
-rw-r--r--tools/editor/plugins/collision_shape_2d_editor_plugin.cpp533
-rw-r--r--tools/editor/plugins/collision_shape_2d_editor_plugin.h73
-rw-r--r--tools/editor/plugins/multimesh_editor_plugin.cpp2
-rw-r--r--tools/editor/plugins/script_editor_plugin.cpp478
-rw-r--r--tools/editor/plugins/script_editor_plugin.h58
-rw-r--r--tools/editor/plugins/tile_map_editor_plugin.cpp120
-rw-r--r--tools/editor/plugins/tile_map_editor_plugin.h11
7 files changed, 1082 insertions, 193 deletions
diff --git a/tools/editor/plugins/collision_shape_2d_editor_plugin.cpp b/tools/editor/plugins/collision_shape_2d_editor_plugin.cpp
new file mode 100644
index 0000000000..62cf1b4acb
--- /dev/null
+++ b/tools/editor/plugins/collision_shape_2d_editor_plugin.cpp
@@ -0,0 +1,533 @@
+#include "collision_shape_2d_editor_plugin.h"
+
+#include "canvas_item_editor_plugin.h"
+
+#include "scene/resources/segment_shape_2d.h"
+#include "scene/resources/shape_line_2d.h"
+#include "scene/resources/circle_shape_2d.h"
+#include "scene/resources/rectangle_shape_2d.h"
+#include "scene/resources/capsule_shape_2d.h"
+#include "scene/resources/convex_polygon_shape_2d.h"
+#include "scene/resources/concave_polygon_shape_2d.h"
+
+Variant CollisionShape2DEditor::get_handle_value(int idx) const {
+
+ switch ( shape_type ) {
+ case CAPSULE_SHAPE: {
+ Ref<CapsuleShape2D> capsule = node->get_shape();
+
+ if (idx==0) {
+ return capsule->get_radius();
+ } else if (idx==1) {
+ return capsule->get_height();
+ }
+
+ } break;
+
+ case CIRCLE_SHAPE: {
+ Ref<CircleShape2D> circle = node->get_shape();
+
+ if (idx==0) {
+ return circle->get_radius();
+ }
+
+ } break;
+
+ case CONCAVE_POLYGON_SHAPE: {
+
+ } break;
+
+ case CONVEX_POLYGON_SHAPE: {
+
+ } break;
+
+ case LINE_SHAPE: {
+
+ } break;
+
+ case RAY_SHAPE: {
+ Ref<RayShape2D> ray = node->get_shape();
+
+ if (idx==0) {
+ return ray->get_length();
+ }
+
+ } break;
+
+ case RECTANGLE_SHAPE: {
+ Ref<RectangleShape2D> rect = node->get_shape();
+
+ if (idx<2) {
+ return rect->get_extents().abs();
+ }
+
+ } break;
+
+ case SEGMENT_SHAPE: {
+ Ref<SegmentShape2D> seg = node->get_shape();
+
+ if (idx==0) {
+ return seg->get_a();
+ } else if (idx==1) {
+ return seg->get_b();
+ }
+
+ } break;
+ }
+
+ return Variant();
+}
+
+void CollisionShape2DEditor::set_handle(int idx, Point2& p_point) {
+
+ switch ( shape_type ) {
+ case CAPSULE_SHAPE: {
+ if (idx < 2) {
+ Ref<CapsuleShape2D> capsule = node->get_shape();
+
+ real_t parameter = Math::abs(p_point[idx]);
+
+ if (idx==0) {
+ capsule->set_radius(parameter);
+ } else if (idx==1){
+ capsule->set_height(parameter*2 - capsule->get_radius()*2);
+ }
+
+ canvas_item_editor->get_viewport_control()->update();
+ }
+
+ } break;
+
+ case CIRCLE_SHAPE: {
+ Ref<CircleShape2D> circle = node->get_shape();
+ circle->set_radius(p_point.length());
+
+ canvas_item_editor->get_viewport_control()->update();
+
+ } break;
+
+ case CONCAVE_POLYGON_SHAPE: {
+
+ } break;
+
+ case CONVEX_POLYGON_SHAPE: {
+
+ } break;
+
+ case LINE_SHAPE: {
+
+ } break;
+
+ case RAY_SHAPE: {
+ Ref<RayShape2D> ray = node->get_shape();
+
+ ray->set_length(Math::abs(p_point.y));
+
+ canvas_item_editor->get_viewport_control()->update();
+
+ } break;
+
+ case RECTANGLE_SHAPE: {
+ if (idx<2) {
+ Ref<RectangleShape2D> rect = node->get_shape();
+
+ Vector2 extents = rect->get_extents();
+ extents[idx] = p_point[idx];
+
+ rect->set_extents(extents.abs());
+
+ canvas_item_editor->get_viewport_control()->update();
+ }
+
+ } break;
+
+ case SEGMENT_SHAPE: {
+ if (edit_handle < 2) {
+ Ref<SegmentShape2D> seg = node->get_shape();
+
+ if (idx==0) {
+ seg->set_a(p_point);
+ } else if (idx==1) {
+ seg->set_b(p_point);
+ }
+
+ canvas_item_editor->get_viewport_control()->update();
+ }
+
+ } break;
+ }
+}
+
+void CollisionShape2DEditor::commit_handle(int idx, Variant& p_org) {
+
+ Control* c = canvas_item_editor->get_viewport_control();
+ undo_redo->create_action("Set Handle");
+
+ switch ( shape_type ) {
+ case CAPSULE_SHAPE: {
+ Ref<CapsuleShape2D> capsule = node->get_shape();
+
+ if (idx==0) {
+ undo_redo->add_do_method(capsule.ptr(),"set_radius",capsule->get_radius());
+ undo_redo->add_do_method(c,"update");
+ undo_redo->add_undo_method(capsule.ptr(),"set_radius",p_org);
+ undo_redo->add_do_method(c,"update");
+ } else if (idx==1) {
+ undo_redo->add_do_method(capsule.ptr(),"set_height",capsule->get_height());
+ undo_redo->add_do_method(c,"update");
+ undo_redo->add_undo_method(capsule.ptr(),"set_height",p_org);
+ undo_redo->add_undo_method(c,"update");
+ }
+
+ } break;
+
+ case CIRCLE_SHAPE: {
+ Ref<CircleShape2D> circle = node->get_shape();
+
+ undo_redo->add_do_method(circle.ptr(),"set_radius",circle->get_radius());
+ undo_redo->add_do_method(c,"update");
+ undo_redo->add_undo_method(circle.ptr(),"set_radius",p_org);
+ undo_redo->add_undo_method(c,"update");
+
+ } break;
+
+ case CONCAVE_POLYGON_SHAPE: {
+
+ } break;
+
+ case CONVEX_POLYGON_SHAPE: {
+
+ } break;
+
+ case LINE_SHAPE: {
+
+ } break;
+
+ case RAY_SHAPE: {
+ Ref<RayShape2D> ray = node->get_shape();
+
+ undo_redo->add_do_method(ray.ptr(),"set_length",ray->get_length());
+ undo_redo->add_do_method(c,"update");
+ undo_redo->add_undo_method(ray.ptr(),"set_length",p_org);
+ undo_redo->add_undo_method(c,"update");
+
+ } break;
+
+ case RECTANGLE_SHAPE: {
+ Ref<RectangleShape2D> rect = node->get_shape();
+
+ undo_redo->add_do_method(rect.ptr(),"set_extents",rect->get_extents());
+ undo_redo->add_do_method(c,"update");
+ undo_redo->add_undo_method(rect.ptr(),"set_extents",p_org);
+ undo_redo->add_undo_method(c,"update");
+
+ } break;
+
+ case SEGMENT_SHAPE: {
+ Ref<SegmentShape2D> seg = node->get_shape();
+ if (idx==0) {
+ undo_redo->add_do_method(seg.ptr(),"set_a",seg->get_a());
+ undo_redo->add_do_method(c,"update");
+ undo_redo->add_undo_method(seg.ptr(),"set_a",p_org);
+ undo_redo->add_undo_method(c,"update");
+ } else if (idx==1) {
+ undo_redo->add_do_method(seg.ptr(),"set_b",seg->get_b());
+ undo_redo->add_do_method(c,"update");
+ undo_redo->add_undo_method(seg.ptr(),"set_b",p_org);
+ undo_redo->add_undo_method(c,"update");
+ }
+
+ } break;
+ }
+
+ undo_redo->commit_action();
+}
+
+bool CollisionShape2DEditor::forward_input_event(const InputEvent& p_event) {
+
+ if (!node) {
+ return false;
+ }
+
+ if (!node->get_shape().is_valid()) {
+ return false;
+ }
+
+ if (shape_type == -1) {
+ return false;
+ }
+
+ switch( p_event.type ) {
+ case InputEvent::MOUSE_BUTTON: {
+ const InputEventMouseButton& mb = p_event.mouse_button;
+
+ Matrix32 gt = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
+
+ Point2 gpoint(mb.x,mb.y);
+
+ if (mb.button_index == BUTTON_LEFT) {
+ if (mb.pressed) {
+ for (int i = 0; i < handles.size(); i++) {
+ if (gt.xform(handles[i]).distance_to(gpoint) < 8) {
+ edit_handle = i;
+
+ break;
+ }
+ }
+
+ if (edit_handle==-1) {
+ pressed = false;
+
+ return false;
+ }
+
+ original = get_handle_value(edit_handle);
+ pressed = true;
+
+ return true;
+
+ } else {
+ if (pressed) {
+ commit_handle(edit_handle, original);
+
+ edit_handle = -1;
+ pressed = false;
+
+ return true;
+ }
+ }
+ }
+
+ return false;
+
+ } break;
+
+ case InputEvent::MOUSE_MOTION: {
+ const InputEventMouseMotion& mm = p_event.mouse_motion;
+
+ if (edit_handle == -1 || !pressed) {
+ return false;
+ }
+
+ Point2 gpoint = Point2(mm.x,mm.y);
+ Point2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
+ cpoint = canvas_item_editor->snap_point(cpoint);
+ cpoint = node->get_global_transform().affine_inverse().xform(cpoint);
+
+ set_handle(edit_handle, cpoint);
+
+ return true;
+
+ } break;
+ }
+
+ return false;
+}
+
+void CollisionShape2DEditor::_get_current_shape_type() {
+
+ if (!node) {
+ return;
+ }
+
+ Ref<Shape2D> s = node->get_shape();
+
+ if (!s.is_valid()) {
+ return;
+ }
+
+ if (s->cast_to<CapsuleShape2D>()) {
+ shape_type = CAPSULE_SHAPE;
+ } else if (s->cast_to<CircleShape2D>()) {
+ shape_type = CIRCLE_SHAPE;
+ } else if (s->cast_to<ConcavePolygonShape2D>()) {
+ shape_type = CONCAVE_POLYGON_SHAPE;
+ } else if (s->cast_to<ConvexPolygonShape2D>()) {
+ shape_type = CONVEX_POLYGON_SHAPE;
+ } else if (s->cast_to<LineShape2D>()) {
+ shape_type = LINE_SHAPE;
+ } else if (s->cast_to<RayShape2D>()) {
+ shape_type = RAY_SHAPE;
+ } else if (s->cast_to<RectangleShape2D>()) {
+ shape_type = RECTANGLE_SHAPE;
+ } else if (s->cast_to<SegmentShape2D>()) {
+ shape_type = SEGMENT_SHAPE;
+ } else {
+ shape_type = -1;
+ }
+
+ canvas_item_editor->get_viewport_control()->update();
+}
+
+void CollisionShape2DEditor::_canvas_draw() {
+
+ if (!node) {
+ return;
+ }
+
+ if (!node->get_shape().is_valid()) {
+ return;
+ }
+
+ _get_current_shape_type();
+
+ if (shape_type == -1) {
+ return;
+ }
+
+ Control *c = canvas_item_editor->get_viewport_control();
+ Matrix32 gt = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
+
+ Ref<Texture> h = get_icon("EditorHandle","EditorIcons");
+ Vector2 size = h->get_size()*0.5;
+
+ handles.clear();
+
+ switch (shape_type) {
+ case CAPSULE_SHAPE: {
+ Ref<CapsuleShape2D> shape = node->get_shape();
+
+ handles.resize(2);
+ float radius = shape->get_radius();
+ float height = shape->get_height()/2;
+
+ handles[0] = Point2(radius, -height);
+ handles[1] = Point2(0,-(height + radius));
+
+ c->draw_texture(h, gt.xform(handles[0])-size);
+ c->draw_texture(h, gt.xform(handles[1])-size);
+
+ } break;
+
+ case CIRCLE_SHAPE: {
+ Ref<CircleShape2D> shape = node->get_shape();
+
+ handles.resize(1);
+ handles[0] = Point2(shape->get_radius(),0);
+
+ c->draw_texture(h, gt.xform(handles[0])-size);
+
+ } break;
+
+ case CONCAVE_POLYGON_SHAPE: {
+
+ } break;
+
+ case CONVEX_POLYGON_SHAPE: {
+
+ } break;
+
+ case LINE_SHAPE: {
+
+ } break;
+
+ case RAY_SHAPE: {
+ Ref<RayShape2D> shape = node->get_shape();
+
+ handles.resize(1);
+ handles[0] = Point2(0,shape->get_length());
+
+ c->draw_texture(h,gt.xform(handles[0])-size);
+
+ } break;
+
+ case RECTANGLE_SHAPE: {
+ Ref<RectangleShape2D> shape = node->get_shape();
+
+ handles.resize(2);
+ Vector2 ext = shape->get_extents();
+ handles[0] = Point2(ext.x,0);
+ handles[1] = Point2(0,-ext.y);
+
+ c->draw_texture(h,gt.xform(handles[0])-size);
+ c->draw_texture(h,gt.xform(handles[1])-size);
+
+ } break;
+
+ case SEGMENT_SHAPE: {
+ Ref<SegmentShape2D> shape = node->get_shape();
+
+ handles.resize(2);
+ handles[0] = shape->get_a();
+ handles[1] = shape->get_b();
+
+ c->draw_texture(h, gt.xform(handles[0])-size);
+ c->draw_texture(h, gt.xform(handles[1])-size);
+
+ } break;
+ }
+}
+
+void CollisionShape2DEditor::edit(Node* p_node) {
+
+ if (!canvas_item_editor) {
+ canvas_item_editor=CanvasItemEditor::get_singleton();
+ }
+
+ if (p_node) {
+ node=p_node->cast_to<CollisionShape2D>();
+
+ if (!canvas_item_editor->get_viewport_control()->is_connected("draw",this,"_canvas_draw"))
+ canvas_item_editor->get_viewport_control()->connect("draw",this,"_canvas_draw");
+
+ _get_current_shape_type();
+
+ } else {
+ edit_handle = -1;
+ shape_type = -1;
+
+ if (canvas_item_editor->get_viewport_control()->is_connected("draw",this,"_canvas_draw"))
+ canvas_item_editor->get_viewport_control()->disconnect("draw",this,"_canvas_draw");
+
+ node=NULL;
+ }
+
+ canvas_item_editor->get_viewport_control()->update();
+}
+
+void CollisionShape2DEditor::_bind_methods() {
+
+ ObjectTypeDB::bind_method("_canvas_draw",&CollisionShape2DEditor::_canvas_draw);
+ ObjectTypeDB::bind_method("_get_current_shape_type",&CollisionShape2DEditor::_get_current_shape_type);
+}
+
+CollisionShape2DEditor::CollisionShape2DEditor(EditorNode* p_editor) {
+
+ node = NULL;
+ canvas_item_editor = NULL;
+ editor = p_editor;
+
+ undo_redo = p_editor->get_undo_redo();
+
+ edit_handle = -1;
+ pressed = false;
+}
+
+void CollisionShape2DEditorPlugin::edit(Object* p_obj) {
+
+ collision_shape_2d_editor->edit(p_obj->cast_to<Node>());
+}
+
+bool CollisionShape2DEditorPlugin::handles(Object* p_obj) const {
+
+ return p_obj->is_type("CollisionShape2D");
+}
+
+void CollisionShape2DEditorPlugin::make_visible(bool visible) {
+
+ if (!visible) {
+ edit(NULL);
+ }
+}
+
+CollisionShape2DEditorPlugin::CollisionShape2DEditorPlugin(EditorNode* p_node) {
+
+ editor=p_node;
+
+ collision_shape_2d_editor = memnew( CollisionShape2DEditor(p_node) );
+ p_node->get_gui_base()->add_child(collision_shape_2d_editor);
+}
+
+CollisionShape2DEditorPlugin::~CollisionShape2DEditorPlugin() {
+
+}
diff --git a/tools/editor/plugins/collision_shape_2d_editor_plugin.h b/tools/editor/plugins/collision_shape_2d_editor_plugin.h
new file mode 100644
index 0000000000..75e9b68ea7
--- /dev/null
+++ b/tools/editor/plugins/collision_shape_2d_editor_plugin.h
@@ -0,0 +1,73 @@
+#ifndef COLLISION_SHAPE_2D_EDITOR_PLUGIN_H
+#define COLLISION_SHAPE_2D_EDITOR_PLUGIN_H
+
+#include "tools/editor/editor_plugin.h"
+#include "tools/editor/editor_node.h"
+
+#include "scene/2d/collision_shape_2d.h"
+
+class CanvasItemEditor;
+
+class CollisionShape2DEditor : public Control {
+ OBJ_TYPE(CollisionShape2DEditor, Control);
+
+ enum ShapeType {
+ CAPSULE_SHAPE,
+ CIRCLE_SHAPE,
+ CONCAVE_POLYGON_SHAPE,
+ CONVEX_POLYGON_SHAPE,
+ LINE_SHAPE,
+ RAY_SHAPE,
+ RECTANGLE_SHAPE,
+ SEGMENT_SHAPE
+ };
+
+ EditorNode* editor;
+ UndoRedo* undo_redo;
+ CanvasItemEditor* canvas_item_editor;
+ CollisionShape2D* node;
+
+ Vector<Point2> handles;
+
+ int shape_type;
+ int edit_handle;
+ bool pressed;
+ Variant original;
+
+ Variant get_handle_value(int idx) const;
+ void set_handle(int idx, Point2& p_point);
+ void commit_handle(int idx, Variant& p_org);
+
+ void _get_current_shape_type();
+ void _canvas_draw();
+
+protected:
+ static void _bind_methods();
+
+public:
+ bool forward_input_event(const InputEvent& p_event);
+ void edit(Node* p_node);
+
+ CollisionShape2DEditor(EditorNode* p_editor);
+};
+
+class CollisionShape2DEditorPlugin : public EditorPlugin {
+ OBJ_TYPE(CollisionShape2DEditorPlugin, EditorPlugin);
+
+ CollisionShape2DEditor* collision_shape_2d_editor;
+ EditorNode* editor;
+
+public:
+ virtual bool forward_input_event(const InputEvent& p_event) { return collision_shape_2d_editor->forward_input_event(p_event); }
+
+ virtual String get_name() const { return "CollisionShape2D"; }
+ bool has_main_screen() const { return false; }
+ virtual void edit(Object* p_obj);
+ virtual bool handles(Object* p_obj) const;
+ virtual void make_visible(bool visible);
+
+ CollisionShape2DEditorPlugin(EditorNode* p_editor);
+ ~CollisionShape2DEditorPlugin();
+};
+
+#endif //COLLISION_SHAPE_2D_EDITOR_PLUGIN_H
diff --git a/tools/editor/plugins/multimesh_editor_plugin.cpp b/tools/editor/plugins/multimesh_editor_plugin.cpp
index d858f3b896..0df906117e 100644
--- a/tools/editor/plugins/multimesh_editor_plugin.cpp
+++ b/tools/editor/plugins/multimesh_editor_plugin.cpp
@@ -305,7 +305,7 @@ void MultiMeshEditor::edit(MultiMeshInstance *p_multimesh) {
void MultiMeshEditor::_browse(bool p_source) {
browsing_source=p_source;
- std->get_tree()->set_marked(node,false);
+ std->get_scene_tree()->set_marked(node,false);
std->popup_centered_ratio();
if (p_source)
std->set_title("Select a Source Mesh:");
diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp
index f5ba6a08e6..b15abf8096 100644
--- a/tools/editor/plugins/script_editor_plugin.cpp
+++ b/tools/editor/plugins/script_editor_plugin.cpp
@@ -38,10 +38,89 @@
#include "os/file_access.h"
#include "scene/main/viewport.h"
#include "os/keyboard.h"
+#include "os/input.h"
+
/*** SCRIPT EDITOR ****/
+class EditorScriptCodeCompletionCache : public ScriptCodeCompletionCache {
+
+
+ struct Cache {
+ uint64_t time_loaded;
+ RES cache;
+ };
+
+ Map<String,Cache> cached;
+
+
+public:
+
+ uint64_t max_time_cache;
+ int max_cache_size;
+
+ void cleanup() {
+
+ List< Map<String,Cache>::Element * > to_clean;
+
+
+ Map<String,Cache>::Element *I=cached.front();
+ while(I) {
+ if ((OS::get_singleton()->get_ticks_msec()-I->get().time_loaded)>max_time_cache) {
+ to_clean.push_back(I);
+ }
+ I=I->next();
+ }
+
+ while(to_clean.front()) {
+ cached.erase(to_clean.front()->get());
+ to_clean.pop_front();
+ }
+ }
+
+ RES get_cached_resource(const String& p_path) {
+
+ Map<String,Cache>::Element *E=cached.find(p_path);
+ if (!E) {
+
+ Cache c;
+ c.cache=ResourceLoader::load(p_path);
+ E=cached.insert(p_path,c);
+ }
+
+ E->get().time_loaded=OS::get_singleton()->get_ticks_msec();
+
+ if (cached.size()>max_cache_size) {
+ uint64_t older;
+ Map<String,Cache>::Element *O=cached.front();
+ older=O->get().time_loaded;
+ Map<String,Cache>::Element *I=O;
+ while(I) {
+ if (I->get().time_loaded<older) {
+ older = I->get().time_loaded;
+ O=I;
+ }
+ I=I->next();
+ }
+
+ if (O!=E) {//should never heppane..
+ cached.erase(O);
+ }
+ }
+
+ return E->get().cache;
+ }
+
+
+ EditorScriptCodeCompletionCache() {
+
+ max_cache_size=128;
+ max_time_cache=5*60*1000; //minutes, five
+ }
+
+};
+#define SORT_SCRIPT_LIST
void ScriptEditorQuickOpen::popup(const Vector<String>& p_functions, bool p_dontclear) {
@@ -118,6 +197,8 @@ void ScriptEditorQuickOpen::_notification(int p_what) {
if (p_what==NOTIFICATION_ENTER_TREE) {
connect("confirmed",this,"_confirmed");
+
+
}
}
@@ -286,8 +367,19 @@ void ScriptTextEditor::reload_text() {
ERR_FAIL_COND(script.is_null()) ;
- get_text_edit()->set_text(script->get_source_code());
- get_text_edit()->clear_undo_history();
+ TextEdit *te = get_text_edit();
+ int column = te->cursor_get_column();
+ int row = te->cursor_get_line();
+ int h = te->get_h_scroll();
+ int v = te->get_v_scroll();
+
+ te->set_text(script->get_source_code());
+ te->clear_undo_history();
+ te->cursor_set_line(row);
+ te->cursor_set_column(column);
+ te->set_h_scroll(h);
+ te->set_v_scroll(v);
+
_line_col_changed();
}
@@ -296,12 +388,11 @@ void ScriptTextEditor::_notification(int p_what) {
if (p_what==NOTIFICATION_READY) {
- _update_name();
+ //emit_signal("name_changed");
}
}
-void ScriptTextEditor::_update_name() {
-
+String ScriptTextEditor::get_name() {
String name;
if (script->get_path().find("local://")==-1 && script->get_path().find("::")==-1) {
@@ -314,21 +405,20 @@ void ScriptTextEditor::_update_name() {
else
name=script->get_type()+"("+itos(script->get_instance_ID())+")";
+ return name;
- if (name!=String(get_name())) {
+}
- set_name(name);
+Ref<Texture> ScriptTextEditor::get_icon() {
+ if (get_parent_control() && get_parent_control()->has_icon(script->get_type(),"EditorIcons")) {
+ return get_parent_control()->get_icon(script->get_type(),"EditorIcons");
}
- if (!has_meta("_tab_icon")) {
- if (get_parent_control() && get_parent_control()->has_icon(script->get_type(),"EditorIcons")) {
- set_meta("_tab_icon",get_parent_control()->get_icon(script->get_type(),"EditorIcons"));
- }
- }
+ return Ref<Texture>();
+}
-}
void ScriptTextEditor::set_edited_script(const Ref<Script>& p_script) {
@@ -344,8 +434,7 @@ void ScriptTextEditor::set_edited_script(const Ref<Script>& p_script) {
get_text_edit()->tag_saved_version();
- _update_name();
-
+ emit_signal("name_changed");
_line_col_changed();
}
@@ -384,7 +473,7 @@ void ScriptTextEditor::_validate_script() {
te->set_line_as_marked(i,line==i);
}
- _update_name();
+ emit_signal("name_changed");
}
@@ -418,6 +507,10 @@ void ScriptTextEditor::_code_complete_script(const String& p_code, List<String>*
}
}
+void ScriptTextEditor::_bind_methods() {
+
+ ADD_SIGNAL(MethodInfo("name_changed"));
+}
ScriptTextEditor::ScriptTextEditor() {
@@ -492,11 +585,15 @@ void ScriptEditor::_close_current_tab() {
memdelete(current);
if (idx>=tab_container->get_child_count())
idx=tab_container->get_child_count()-1;
- if (idx>=0)
+ if (idx>=0) {
tab_container->set_current_tab(idx);
+ //script_list->select(idx);
+ }
+
- _update_window_menu();
- _save_files_state();
+
+ _update_script_names();
+ EditorNode::get_singleton()->save_layout();
}
@@ -587,10 +684,10 @@ void ScriptEditor::_res_saved_callback(const Ref<Resource>& p_res) {
ste->get_text_edit()->tag_saved_version();
}
- ste->_update_name();
-
}
+ _update_script_names();
+
}
bool ScriptEditor::_test_script_times_on_disk() {
@@ -1045,7 +1142,7 @@ void ScriptEditor::_menu_option(int p_option) {
if (text != "")
editor->emit_signal("request_help", text);
} break;
- case WINDOW_CLOSE: {
+ case FILE_CLOSE: {
if (current->get_text_edit()->get_version()!=current->get_text_edit()->get_saved_version()) {
erase_tab_confirm->set_text("Close and save changes?\n\""+current->get_name()+"\"");
erase_tab_confirm->popup_centered_minsize();
@@ -1057,16 +1154,18 @@ void ScriptEditor::_menu_option(int p_option) {
if (tab_container->get_current_tab()>0) {
tab_container->call_deferred("set_current_tab",tab_container->get_current_tab()-1);
+ script_list->call_deferred("select",tab_container->get_current_tab()-1);
tab_container->move_child(current,tab_container->get_current_tab()-1);
- _update_window_menu();
+ _update_script_names();
}
} break;
case WINDOW_MOVE_RIGHT: {
if (tab_container->get_current_tab()<tab_container->get_child_count()-1) {
tab_container->call_deferred("set_current_tab",tab_container->get_current_tab()+1);
+ script_list->call_deferred("select",tab_container->get_current_tab()+1);
tab_container->move_child(current,tab_container->get_current_tab()+1);
- _update_window_menu();
+ _update_script_names();
}
@@ -1076,6 +1175,8 @@ void ScriptEditor::_menu_option(int p_option) {
if (p_option>=WINDOW_SELECT_BASE) {
tab_container->set_current_tab(p_option-WINDOW_SELECT_BASE);
+ script_list->select(p_option-WINDOW_SELECT_BASE);
+
}
}
}
@@ -1096,6 +1197,8 @@ void ScriptEditor::_notification(int p_what) {
editor->connect("stop_pressed",this,"_editor_stop");
editor->connect("script_add_function_request",this,"_add_callback");
editor->connect("resource_saved",this,"_res_saved_callback");
+ script_list->connect("item_selected",this,"_script_selected");
+ script_split->connect("dragged",this,"_script_split_dragged");
autosave_timer->connect("timeout",this,"_autosave_scripts");
{
float autosave_time = EditorSettings::get_singleton()->get("text_editor/autosave_interval_secs");
@@ -1113,7 +1216,8 @@ void ScriptEditor::_notification(int p_what) {
}
if (p_what==NOTIFICATION_READY) {
- _update_window_menu();
+
+ get_tree()->connect("tree_changed",this,"_tree_changed");
}
if (p_what==NOTIFICATION_EXIT_TREE) {
@@ -1153,10 +1257,11 @@ static const Node * _find_node_with_script(const Node* p_node, const RefPtr & p_
Dictionary ScriptEditor::get_state() const {
- apply_scripts();
- Dictionary state;
+// apply_scripts();
+ Dictionary state;
+#if 0
Array paths;
int open=-1;
@@ -1189,12 +1294,12 @@ Dictionary ScriptEditor::get_state() const {
if (open!=-1)
state["current"]=open;
-
+#endif
return state;
}
void ScriptEditor::set_state(const Dictionary& p_state) {
-
+#if 0
print_line("attempt set state: "+String(Variant(p_state)));
if (!p_state.has("sources"))
@@ -1231,6 +1336,7 @@ void ScriptEditor::set_state(const Dictionary& p_state) {
if (p_state.has("current")) {
tab_container->set_current_tab(p_state["current"]);
}
+#endif
}
void ScriptEditor::clear() {
@@ -1254,68 +1360,17 @@ void ScriptEditor::clear() {
int idx = tab_container->get_current_tab();
if (idx>=tab_container->get_child_count())
idx=tab_container->get_child_count()-1;
- if (idx>=0)
+ if (idx>=0) {
tab_container->set_current_tab(idx);
-
- _update_window_menu();
-
-
-}
-
-void ScriptEditor::_save_files_state() {
-
- return; //no thank you
-
- String rpath="_open_scripts_"+Globals::get_singleton()->get_resource_path();
- rpath=rpath.replace("\\","_-_");
- rpath=rpath.replace("/","_-_");
- rpath=rpath.replace(":","_");
-
- Vector<String> scripts;
-
- for(int i=0;i<tab_container->get_child_count();i++) {
-
- ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
- if (!ste)
- continue;
-
-
- Ref<Script> script = ste->get_edited_script();
- if (script->get_path()!="" && script->get_path().find("local://")==-1 && script->get_path().find("::")==-1) {
-
-
- scripts.push_back(script->get_path());
- }
+ script_list->select( script_list->find_metadata(idx) );
}
- EditorSettings::get_singleton()->set(rpath,scripts);
- EditorSettings::get_singleton()->save();
-
-}
-void ScriptEditor::_load_files_state() {
- return;
-
- String rpath="_open_scripts_"+Globals::get_singleton()->get_resource_path();
- rpath=rpath.replace("\\","_-_");
- rpath=rpath.replace("/","_-_");
- rpath=rpath.replace(":","_");
-
- if (EditorSettings::get_singleton()->has(rpath)) {
-
- Vector<String> open_files=EditorSettings::get_singleton()->get("rpath");
- for(int i=0;i<open_files.size();i++) {
- Ref<Script> scr = ResourceLoader::load(open_files[i]);
- if (!scr.is_valid())
- continue;
-
- editor->edit_resource(scr);
- }
- }
}
+
void ScriptEditor::get_breakpoints(List<String> *p_breakpoints) {
for(int i=0;i<tab_container->get_child_count();i++) {
@@ -1360,11 +1415,18 @@ void ScriptEditor::_bind_methods() {
ObjectTypeDB::bind_method("_get_debug_tooltip",&ScriptEditor::_get_debug_tooltip);
ObjectTypeDB::bind_method("_autosave_scripts",&ScriptEditor::_autosave_scripts);
ObjectTypeDB::bind_method("_editor_settings_changed",&ScriptEditor::_editor_settings_changed);
+ ObjectTypeDB::bind_method("_update_script_names",&ScriptEditor::_update_script_names);
+ ObjectTypeDB::bind_method("_tree_changed",&ScriptEditor::_tree_changed);
+ ObjectTypeDB::bind_method("_script_selected",&ScriptEditor::_script_selected);
+ ObjectTypeDB::bind_method("_script_split_dragged",&ScriptEditor::_script_split_dragged);
}
void ScriptEditor::ensure_focus_current() {
+ if (!is_inside_tree())
+ return;
+
int cidx = tab_container->get_current_tab();
if (cidx<0 || cidx>=tab_container->get_tab_count());
Control *c = tab_container->get_child(cidx)->cast_to<Control>();
@@ -1376,6 +1438,13 @@ void ScriptEditor::ensure_focus_current() {
ste->get_text_edit()->grab_focus();
}
+void ScriptEditor::_script_selected(int p_idx) {
+
+ grab_focus_block = !Input::get_singleton()->is_mouse_button_pressed(1); //amazing hack, simply amazing
+ tab_container->set_current_tab(script_list->get_item_metadata(p_idx));
+ grab_focus_block=false;
+}
+
void ScriptEditor::ensure_select_current() {
@@ -1386,8 +1455,66 @@ void ScriptEditor::ensure_select_current() {
return;
Ref<Script> script = ste->get_edited_script();
- ste->get_text_edit()->grab_focus();
+ if (!grab_focus_block && is_inside_tree())
+ ste->get_text_edit()->grab_focus();
}
+
+
+}
+
+void ScriptEditor::_find_scripts(Node* p_base, Node* p_current, Set<Ref<Script> > &used) {
+ if (p_current!=p_base && p_current->get_owner()!=p_base)
+ return;
+
+ if (p_current->get_script_instance()) {
+ Ref<Script> scr = p_current->get_script();
+ if (scr.is_valid())
+ used.insert(scr);
+ }
+
+ for(int i=0;i<p_current->get_child_count();i++) {
+ _find_scripts(p_base,p_current->get_child(i),used);
+ }
+
+}
+
+
+void ScriptEditor::_update_script_names() {
+
+ waiting_update_names=false;
+ Set<Ref<Script> > used;
+ Node* edited = EditorNode::get_singleton()->get_edited_scene();
+ if (edited) {
+ _find_scripts(edited,edited,used);
+ }
+
+ script_list->clear();
+ for(int i=0;i<tab_container->get_child_count();i++) {
+
+ ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
+ if (!ste)
+ continue;
+
+ String script = ste->get_name();
+ Ref<Texture> icon = ste->get_icon();
+ String path = ste->get_edited_script()->get_path();
+ script_list->add_item(script,icon);
+
+ int index = script_list->get_item_count()-1;
+
+ script_list->set_item_tooltip(index,path);
+ script_list->set_item_metadata(index,i);
+ if (used.has(ste->get_edited_script())) {
+
+ script_list->set_item_custom_bg_color(index,Color(88/255.0,88/255.0,60/255.0));
+ }
+ if (tab_container->get_current_tab()==index) {
+ script_list->select(index);
+ }
+ }
+
+ script_list->sort_items_by_text();
+
}
void ScriptEditor::edit(const Ref<Script>& p_script) {
@@ -1425,9 +1552,13 @@ void ScriptEditor::edit(const Ref<Script>& p_script) {
if (ste->get_edited_script()==p_script) {
- if (tab_container->get_current_tab()!=i)
- tab_container->set_current_tab(i);
- ste->get_text_edit()->grab_focus();
+ if (!EditorNode::get_singleton()->is_changing_scene()) {
+ if (tab_container->get_current_tab()!=i) {
+ tab_container->set_current_tab(i);
+ script_list->select( script_list->find_metadata(i) );
+ }
+ ste->get_text_edit()->grab_focus();
+ }
return;
}
}
@@ -1440,9 +1571,13 @@ void ScriptEditor::edit(const Ref<Script>& p_script) {
tab_container->add_child(ste);
tab_container->set_current_tab(tab_container->get_tab_count()-1);
- _update_window_menu();
- _save_files_state();
+
+ _update_script_names();
+ ste->connect("name_changed",this,"_update_script_names");
+ if (!restoring_layout) {
+ EditorNode::get_singleton()->save_layout();
+ }
}
void ScriptEditor::save_external_data() {
@@ -1502,51 +1637,6 @@ void ScriptEditor::_editor_stop() {
debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true );
}
-void ScriptEditor::_update_window_menu() {
-
- int idx=0;
- for(int i=0;i<tab_container->get_child_count();i++) {
-
- ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
- if (!ste)
- continue;
- idx++;
- }
-
- if (idx==0) {
- window_menu->set_disabled(true);
- edit_menu->set_disabled(true);
- search_menu->set_disabled(true);
- return;
- } else {
-
- window_menu->set_disabled(false);
- edit_menu->set_disabled(false);
- search_menu->set_disabled(false);
- }
-
- window_menu->get_popup()->clear();
- window_menu->get_popup()->add_item("Close",WINDOW_CLOSE,KEY_MASK_CMD|KEY_W);
- window_menu->get_popup()->add_separator();
- window_menu->get_popup()->add_item("Move Left",WINDOW_MOVE_LEFT,KEY_MASK_CMD|KEY_MASK_ALT|KEY_LEFT);
- window_menu->get_popup()->add_item("Move Right",WINDOW_MOVE_RIGHT,KEY_MASK_CMD|KEY_MASK_ALT|KEY_RIGHT);
- window_menu->get_popup()->add_separator();
-
- idx=0;
- for(int i=0;i<tab_container->get_child_count();i++) {
-
- ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
- if (!ste)
- continue;
- String n = ste->get_name();
- uint32_t accel=0;
- if (idx<9) {
- accel=KEY_MASK_ALT|KEY_MASK_CMD|(KEY_1+idx);
- }
- window_menu->get_popup()->add_item(n,WINDOW_SELECT_BASE+idx,accel);
- idx++;
- }
-}
void ScriptEditor::_add_callback(Object *p_obj, const String& p_function, const StringArray& p_args) {
@@ -1582,6 +1672,8 @@ void ScriptEditor::_add_callback(Object *p_obj, const String& p_function, const
ste->get_text_edit()->cursor_set_line(pos);
ste->get_text_edit()->cursor_set_column(1);
+ script_list->select( script_list->find_metadata(i) );
+
break;
}
@@ -1607,8 +1699,81 @@ void ScriptEditor::_autosave_scripts() {
save_external_data();
}
+void ScriptEditor::_tree_changed() {
+
+ if (waiting_update_names)
+ return;
+
+ waiting_update_names=true;
+ call_deferred("_update_script_names");
+}
+
+void ScriptEditor::_script_split_dragged(float) {
+
+ EditorNode::get_singleton()->save_layout();
+}
+
+void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) {
+
+ if (!bool(EDITOR_DEF("text_editor/restore_scripts_on_load",true))) {
+ return;
+ }
+
+ if (!p_layout->has_section_key("ScriptEditor","open_scripts"))
+ return;
+
+ Array scripts = p_layout->get_value("ScriptEditor","open_scripts");
+
+ restoring_layout=true;
+
+ for(int i=0;i<scripts.size();i++) {
+
+ String path = scripts[i];
+ Ref<Script> scr = ResourceLoader::load(path);
+ if (scr.is_valid()) {
+ edit(scr);
+ }
+ }
+
+ if (p_layout->has_section_key("ScriptEditor","split_offset")) {
+ script_split->set_split_offset(p_layout->get_value("ScriptEditor","split_offset"));
+ }
+
+
+ restoring_layout=false;
+
+}
+
+void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) {
+
+ Array scripts;
+
+ for(int i=0;i<tab_container->get_child_count();i++) {
+
+ ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
+ if (!ste)
+ continue;
+
+ String path = ste->get_edited_script()->get_path();
+ if (!path.is_resource_file())
+ continue;
+
+ scripts.push_back(path);
+
+ }
+
+ p_layout->set_value("ScriptEditor","open_scripts",scripts);
+ p_layout->set_value("ScriptEditor","split_offset",script_split->get_split_offset());
+
+}
+
+
+
ScriptEditor::ScriptEditor(EditorNode *p_editor) {
+ completion_cache = memnew( EditorScriptCodeCompletionCache );
+ restoring_layout=false;
+ waiting_update_names=false;
editor=p_editor;
menu_hb = memnew( HBoxContainer );
@@ -1618,17 +1783,32 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
add_child(v_split);
v_split->set_v_size_flags(SIZE_EXPAND_FILL);
+ script_split = memnew( HSplitContainer );
+ v_split->add_child(script_split);
+ script_split->set_v_size_flags(SIZE_EXPAND_FILL);
+
+ script_list = memnew( ItemList );
+ script_split->add_child(script_list);
+ script_list->set_custom_minimum_size(Size2(70,0));
+ script_split->set_split_offset(70);
+
tab_container = memnew( TabContainer );
- v_split->add_child(tab_container);
- tab_container->set_v_size_flags(SIZE_EXPAND_FILL);
+ tab_container->set_tabs_visible(false);
+ script_split->add_child(tab_container);
+
+
+ tab_container->set_h_size_flags(SIZE_EXPAND_FILL);
file_menu = memnew( MenuButton );
menu_hb->add_child(file_menu);
file_menu->set_text("File");
file_menu->get_popup()->add_item("Open",FILE_OPEN);
+ file_menu->get_popup()->add_separator();
file_menu->get_popup()->add_item("Save",FILE_SAVE,KEY_MASK_ALT|KEY_MASK_CMD|KEY_S);
file_menu->get_popup()->add_item("Save As..",FILE_SAVE_AS);
file_menu->get_popup()->add_item("Save All",FILE_SAVE_ALL,KEY_MASK_CMD|KEY_MASK_SHIFT|KEY_S);
+ file_menu->get_popup()->add_separator();
+ file_menu->get_popup()->add_item("Close",FILE_CLOSE,KEY_MASK_CMD|KEY_W);
file_menu->get_popup()->connect("item_pressed", this,"_menu_option");
edit_menu = memnew( MenuButton );
@@ -1690,6 +1870,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true );
+#if 0
window_menu = memnew( MenuButton );
menu_hb->add_child(window_menu);
window_menu->set_text("Window");
@@ -1700,6 +1881,8 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
window_menu->get_popup()->add_separator();
window_menu->get_popup()->connect("item_pressed", this,"_menu_option");
+#endif
+
help_menu = memnew( MenuButton );
menu_hb->add_child(help_menu);
help_menu->set_text("Help");
@@ -1762,11 +1945,18 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
autosave_timer->set_one_shot(false);
add_child(autosave_timer);
+ grab_focus_block=false;
+
// debugger_gui->hide();
}
+ScriptEditor::~ScriptEditor() {
+
+ memdelete(completion_cache);
+}
+
void ScriptEditorPlugin::edit(Object *p_object) {
if (!p_object->cast_to<Script>())
@@ -1826,20 +2016,24 @@ void ScriptEditorPlugin::apply_changes() {
void ScriptEditorPlugin::restore_global_state() {
- if (bool(EDITOR_DEF("text_editor/restore_scripts_on_load",true))) {
- script_editor->_load_files_state();
- }
}
void ScriptEditorPlugin::save_global_state() {
- if (bool(EDITOR_DEF("text_editor/restore_scripts_on_load",true))) {
- script_editor->_save_files_state();
- }
+}
+
+void ScriptEditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {
+
+ script_editor->set_window_layout(p_layout);
+}
+
+void ScriptEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout){
+ script_editor->get_window_layout(p_layout);
}
+
void ScriptEditorPlugin::get_breakpoints(List<String> *p_breakpoints) {
diff --git a/tools/editor/plugins/script_editor_plugin.h b/tools/editor/plugins/script_editor_plugin.h
index acfdd1e966..0dd152cb25 100644
--- a/tools/editor/plugins/script_editor_plugin.h
+++ b/tools/editor/plugins/script_editor_plugin.h
@@ -33,12 +33,13 @@
#include "scene/gui/tab_container.h"
#include "scene/gui/text_edit.h"
#include "scene/gui/menu_button.h"
+#include "scene/gui/tool_button.h"
#include "scene/gui/tree.h"
#include "scene/main/timer.h"
#include "script_language.h"
#include "tools/editor/code_editor.h"
#include "scene/gui/split_container.h"
-
+#include "scene/gui/item_list.h"
class ScriptEditorQuickOpen : public ConfirmationDialog {
@@ -88,6 +89,7 @@ protected:
virtual void _code_complete_script(const String& p_code, List<String>* r_options);
virtual void _load_theme_settings();
void _notification(int p_what);
+ static void _bind_methods();
public:
@@ -97,12 +99,15 @@ public:
Vector<String> get_functions() ;
void set_edited_script(const Ref<Script>& p_script);
void reload_text();
- void _update_name();
+ String get_name() ;
+ Ref<Texture> get_icon() ;
ScriptTextEditor();
};
+class EditorScriptCodeCompletionCache;
+
class ScriptEditor : public VBoxContainer {
OBJ_TYPE(ScriptEditor, VBoxContainer );
@@ -115,6 +120,7 @@ class ScriptEditor : public VBoxContainer {
FILE_SAVE,
FILE_SAVE_AS,
FILE_SAVE_ALL,
+ FILE_CLOSE,
EDIT_UNDO,
EDIT_REDO,
EDIT_CUT,
@@ -123,12 +129,12 @@ class ScriptEditor : public VBoxContainer {
EDIT_SELECT_ALL,
EDIT_COMPLETE,
EDIT_AUTO_INDENT,
- EDIT_TOGGLE_COMMENT,
- EDIT_MOVE_LINE_UP,
- EDIT_MOVE_LINE_DOWN,
- EDIT_INDENT_RIGHT,
- EDIT_INDENT_LEFT,
- EDIT_CLONE_DOWN,
+ EDIT_TOGGLE_COMMENT,
+ EDIT_MOVE_LINE_UP,
+ EDIT_MOVE_LINE_DOWN,
+ EDIT_INDENT_RIGHT,
+ EDIT_INDENT_LEFT,
+ EDIT_CLONE_DOWN,
SEARCH_FIND,
SEARCH_FIND_NEXT,
SEARCH_REPLACE,
@@ -140,8 +146,7 @@ class ScriptEditor : public VBoxContainer {
DEBUG_BREAK,
DEBUG_CONTINUE,
DEBUG_SHOW,
- HELP_CONTEXTUAL,
- WINDOW_CLOSE,
+ HELP_CONTEXTUAL,
WINDOW_MOVE_LEFT,
WINDOW_MOVE_RIGHT,
WINDOW_SELECT_BASE=100
@@ -151,17 +156,19 @@ class ScriptEditor : public VBoxContainer {
MenuButton *file_menu;
MenuButton *edit_menu;
MenuButton *search_menu;
- MenuButton *window_menu;
MenuButton *debug_menu;
MenuButton *help_menu;
Timer *autosave_timer;
uint64_t idle;
+ ItemList *script_list;
+ HSplitContainer *script_split;
TabContainer *tab_container;
FindReplaceDialog *find_replace_dialog;
GotoLineDialog *goto_line_dialog;
ConfirmationDialog *erase_tab_confirm;
ScriptEditorDebugger* debugger;
+ ToolButton *scripts_visible;
void _tab_changed(int p_which);
void _menu_option(int p_optin);
@@ -171,6 +178,8 @@ class ScriptEditor : public VBoxContainer {
VSplitContainer *v_split;
+ bool restoring_layout;
+
String _get_debug_tooltip(const String&p_text,Node *_ste);
void _resave_scripts(const String& p_str);
@@ -180,8 +189,11 @@ class ScriptEditor : public VBoxContainer {
void _close_current_tab();
+ bool grab_focus_block;
+
ScriptEditorQuickOpen *quick_open;
+ EditorScriptCodeCompletionCache *completion_cache;
void _editor_play();
void _editor_pause();
@@ -199,6 +211,18 @@ class ScriptEditor : public VBoxContainer {
void _editor_settings_changed();
void _autosave_scripts();
+ void _update_script_names();
+
+ void _script_selected(int p_idx);
+
+ void _find_scripts(Node* p_base, Node* p_current,Set<Ref<Script> >& used);
+
+ void _tree_changed();
+
+ void _script_split_dragged(float);
+
+ bool waiting_update_names;
+
static ScriptEditor *script_editor;
protected:
void _notification(int p_what);
@@ -206,9 +230,6 @@ protected:
public:
static ScriptEditor *get_singleton() { return script_editor; }
- void _save_files_state();
- void _load_files_state();
-
void ensure_focus_current();
void apply_scripts() const;
@@ -222,11 +243,15 @@ public:
void get_breakpoints(List<String> *p_breakpoints);
- void swap_lines(TextEdit *tx, int line1, int line2);
+ void swap_lines(TextEdit *tx, int line1, int line2);
void save_external_data();
+ void set_window_layout(Ref<ConfigFile> p_layout);
+ void get_window_layout(Ref<ConfigFile> p_layout);
+
ScriptEditor(EditorNode *p_editor);
+ ~ScriptEditor();
};
class ScriptEditorPlugin : public EditorPlugin {
@@ -254,6 +279,9 @@ public:
virtual void restore_global_state();
virtual void save_global_state();
+ virtual void set_window_layout(Ref<ConfigFile> p_layout);
+ virtual void get_window_layout(Ref<ConfigFile> p_layout);
+
virtual void get_breakpoints(List<String> *p_breakpoints);
diff --git a/tools/editor/plugins/tile_map_editor_plugin.cpp b/tools/editor/plugins/tile_map_editor_plugin.cpp
index 5c82973da4..017a26441d 100644
--- a/tools/editor/plugins/tile_map_editor_plugin.cpp
+++ b/tools/editor/plugins/tile_map_editor_plugin.cpp
@@ -71,22 +71,19 @@ void TileMapEditor::_canvas_mouse_exit() {
}
int TileMapEditor::get_selected_tile() const {
-
- TreeItem *item = palette->get_selected();
- if (!item)
+ int item = palette->get_current();
+ if (item==-1)
return TileMap::INVALID_CELL;
- return item->get_metadata(0);
+ return palette->get_item_metadata(item);
}
void TileMapEditor::set_selected_tile(int p_tile) {
- TreeItem *item = palette->get_root()->get_children();
- while (item) {
- if ((int)item->get_metadata(0) == p_tile) {
- item->select(0);
- palette->ensure_cursor_is_visible();
+ for (int i = 0; i < palette->get_item_count(); i++) {
+ if (palette->get_item_metadata(i).operator int() == p_tile) {
+ palette->select(i,true);
+ palette->ensure_current_is_visible();
break;
}
- item = item->get_next();
}
}
@@ -95,7 +92,7 @@ void TileMapEditor::_set_cell_shortened(const Point2& p_pos,int p_value,bool p_f
ERR_FAIL_COND(!node);
node->set_cell(floor(p_pos.x), floor(p_pos.y), p_value, p_flip_h, p_flip_v, p_transpose);
}
-
+
void TileMapEditor::_set_cell(const Point2i& p_pos,int p_value,bool p_flip_h, bool p_flip_v, bool p_transpose,bool p_with_undo) {
ERR_FAIL_COND(!node);
@@ -120,42 +117,78 @@ void TileMapEditor::_set_cell(const Point2i& p_pos,int p_value,bool p_flip_h, bo
}
+void TileMapEditor::_set_display_mode(int p_mode) {
+ if (display_mode == p_mode) {
+ return;
+ }
+
+ switch (p_mode) {
+ case DISPLAY_THUMBNAIL: {
+ button_thumbnail->set_pressed(true);
+ button_list->set_pressed(false);
+ } break;
+ case DISPLAY_LIST: {
+ button_thumbnail->set_pressed(false);
+ button_list->set_pressed(true);
+ } break;
+ }
+
+ display_mode = p_mode;
+
+ _update_palette();
+}
+
void TileMapEditor::_update_palette() {
if (!node)
return;
- palette->clear();;
+ palette->clear();
Ref<TileSet> tileset=node->get_tileset();
if (!tileset.is_valid())
return;
-
- TreeItem *root = palette->create_item();
- palette->set_hide_root(true);
List<int> tiles;
tileset->get_tile_list(&tiles);
- for(List<int>::Element *E=tiles.front();E;E=E->next()) {
+ if (display_mode == DISPLAY_THUMBNAIL) {
+ palette->set_max_columns(0);
+ palette->set_icon_mode(ItemList::ICON_MODE_TOP);
+ } else if (display_mode == DISPLAY_LIST) {
+ palette->set_max_columns(1);
+ palette->set_icon_mode(ItemList::ICON_MODE_LEFT);
+ }
- TreeItem *tile = palette->create_item(root);
+ palette->set_max_text_lines(2);
+
+ for(List<int>::Element *E=tiles.front();E;E=E->next()) {
+ palette->add_item("");
- tile->set_icon_max_width(0,64);
Ref<Texture> tex = tileset->tile_get_texture(E->get());
+
if (tex.is_valid()) {
- tile->set_icon(0,tex);
Rect2 region = tileset->tile_get_region(E->get());
- if (region!=Rect2())
- tile->set_icon_region(0,region);
- } else if (tileset->tile_get_name(E->get())!="")
- tile->set_text(0,tileset->tile_get_name(E->get()));
- else
- tile->set_text(0,"#"+itos(E->get()));
+ if (!region.has_no_area()) {
+ Image data = VS::get_singleton()->texture_get_data(tex->get_rid());
+
+ Ref<ImageTexture> img = memnew( ImageTexture );
+ img->create_from_image(data.get_rect(region));
+
+ palette->set_item_icon(palette->get_item_count()-1, img);
+ } else {
+ palette->set_item_icon(palette->get_item_count()-1,tex);
+ }
+ }
- tile->set_metadata(0,E->get());
+ if (tileset->tile_get_name(E->get())!="") {
+ palette->set_item_text(palette->get_item_count()-1, tileset->tile_get_name(E->get()));
+ } else {
+ palette->set_item_text(palette->get_item_count()-1, "#"+itos(E->get()));
+ }
+ palette->set_item_metadata(palette->get_item_count()-1, E->get());
}
}
@@ -387,7 +420,7 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) {
}
if (tool==TOOL_ERASING) {
- Point2i local =over_tile;
+ Point2i local =over_tile;
if (!paint_undo.has(over_tile)) {
paint_undo[over_tile]=_get_op_from_cell(over_tile);
}
@@ -641,7 +674,7 @@ void TileMapEditor::_canvas_draw() {
Ref<Texture> t = ts->tile_get_texture(st);
if (t.is_valid()) {
Vector2 from = node->map_to_world(over_tile)+node->get_cell_draw_offset();
- Rect2 r = ts->tile_get_region(st);
+ Rect2 r = ts->tile_get_region(st);
Size2 sc = xform.get_scale();
if (mirror_x->is_pressed())
sc.x*=-1.0;
@@ -755,7 +788,7 @@ void TileMapEditor::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_tileset_settings_changed"),&TileMapEditor::_tileset_settings_changed);
ObjectTypeDB::bind_method(_MD("_update_transform_buttons"),&TileMapEditor::_update_transform_buttons);
ObjectTypeDB::bind_method(_MD("_set_cell_shortened","pos","tile","flip_x","flip_y","transpose"),&TileMapEditor::_set_cell_shortened,DEFVAL(false),DEFVAL(false),DEFVAL(false));
-
+ ObjectTypeDB::bind_method(_MD("_set_display_mode","mode"),&TileMapEditor::_set_display_mode);
}
TileMapEditor::CellOp TileMapEditor::_get_op_from_cell(const Point2i& p_pos)
@@ -777,7 +810,7 @@ void TileMapEditor::_update_transform_buttons(Object *p_button) {
//ERR_FAIL_NULL(p_button);
ToolButton *b=p_button->cast_to<ToolButton>();
//ERR_FAIL_COND(!b);
-
+
mirror_x->set_block_signals(true);
mirror_y->set_block_signals(true);
transpose->set_block_signals(true);
@@ -785,7 +818,7 @@ void TileMapEditor::_update_transform_buttons(Object *p_button) {
rotate_90->set_block_signals(true);
rotate_180->set_block_signals(true);
rotate_270->set_block_signals(true);
-
+
if (b == rotate_0) {
mirror_x->set_pressed(false);
mirror_y->set_pressed(false);
@@ -806,7 +839,7 @@ void TileMapEditor::_update_transform_buttons(Object *p_button) {
mirror_y->set_pressed(true);
transpose->set_pressed(true);
}
-
+
rotate_0->set_pressed(!mirror_x->is_pressed() && !mirror_y->is_pressed() && !transpose->is_pressed());
rotate_90->set_pressed(mirror_x->is_pressed() && !mirror_y->is_pressed() && transpose->is_pressed());
rotate_180->set_pressed(mirror_x->is_pressed() && mirror_y->is_pressed() && !transpose->is_pressed());
@@ -833,8 +866,27 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) {
ec->set_custom_minimum_size(Size2(mw,0));
add_child(ec);
+ HBoxContainer *hb = memnew( HBoxContainer );
+ add_child(hb);
+ hb->set_h_size_flags(SIZE_EXPAND_FILL);
+ hb->add_spacer(true);
+
+ button_thumbnail = memnew( ToolButton );
+ button_thumbnail->set_toggle_mode(true);
+ button_thumbnail->set_pressed(true);
+ button_thumbnail->set_icon(p_editor->get_gui_base()->get_icon("FileThumbnail","EditorIcons"));
+ hb->add_child(button_thumbnail);
+ button_thumbnail->connect("pressed", this, "_set_display_mode", varray(DISPLAY_THUMBNAIL));
+
+ button_list = memnew( ToolButton );
+ button_list->set_toggle_mode(true);
+ button_list->set_pressed(false);
+ button_list->set_icon(p_editor->get_gui_base()->get_icon("FileList","EditorIcons"));
+ hb->add_child(button_list);
+ button_list->connect("pressed", this, "_set_display_mode", varray(DISPLAY_LIST));
+
// Add tile palette
- palette = memnew( Tree );
+ palette = memnew( ItemList );
palette->set_v_size_flags(SIZE_EXPAND_FILL);
add_child(palette);
@@ -886,7 +938,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) {
rotate_270->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_270));
canvas_item_editor_hb->add_child(rotate_270);
canvas_item_editor_hb->hide();
-
+
rotate_0->set_pressed(true);
tool=TOOL_NONE;
selection_active=false;
diff --git a/tools/editor/plugins/tile_map_editor_plugin.h b/tools/editor/plugins/tile_map_editor_plugin.h
index eaa5c256d7..74d1573d0f 100644
--- a/tools/editor/plugins/tile_map_editor_plugin.h
+++ b/tools/editor/plugins/tile_map_editor_plugin.h
@@ -55,10 +55,18 @@ class TileMapEditor : public VBoxContainer {
TOOL_PICKING
};
+ enum DisplayMode {
+ DISPLAY_THUMBNAIL,
+ DISPLAY_LIST
+ };
+
Tool tool;
Control *canvas_item_editor;
- Tree *palette;
+ int display_mode;
+ ItemList *palette;
+ ToolButton *button_thumbnail;
+ ToolButton *button_list;
EditorNode *editor;
Panel *panel;
TileMap *node;
@@ -95,6 +103,7 @@ class TileMapEditor : public VBoxContainer {
int get_selected_tile() const;
void set_selected_tile(int p_tile);
+ void _set_display_mode(int p_mode);
void _update_palette();
void _canvas_draw();
void _menu_option(int p_option);