Concluded base visual scripting! can edit but not run though.

This commit is contained in:
Juan Linietsky 2016-08-04 00:05:35 -03:00
parent cd25624667
commit 6ed5d48d0c
7 changed files with 175 additions and 6 deletions

View file

@ -1808,6 +1808,7 @@ bool GridMap::is_using_baked_light() const{
}
GridMap::GridMap() {
cell_size=2;

View file

@ -1045,6 +1045,12 @@ void VisualScriptEditor::_available_node_doubleclicked() {
return;
Vector2 ofs = graph->get_scroll_ofs() + graph->get_size() * 0.5;
if (graph->is_using_snap()) {
int snap = graph->get_snap();
ofs = ofs.snapped(Vector2(snap,snap));
}
ofs/=EDSCALE;
while(true) {
@ -1054,7 +1060,7 @@ void VisualScriptEditor::_available_node_doubleclicked() {
for (List<int>::Element *E=existing.front();E;E=E->next()) {
Point2 pos = script->get_node_pos(edited_func,E->get());
if (pos.distance_to(ofs)<15) {
ofs+=Vector2(25,25);
ofs+=Vector2(graph->get_snap(),graph->get_snap());
exists=true;
break;
}
@ -1415,6 +1421,12 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
Vector2 ofs = graph->get_scroll_ofs() + p_point;
if (graph->is_using_snap()) {
int snap = graph->get_snap();
ofs = ofs.snapped(Vector2(snap,snap));
}
ofs/=EDSCALE;
Ref<VisualScriptNode> vnode = VisualScriptLanguage::singleton->create_node_from_name(d["node_type"]);
@ -1437,6 +1449,10 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
if (d.has("type") && String(d["type"])=="visual_script_variable_drag") {
Vector2 ofs = graph->get_scroll_ofs() + p_point;
if (graph->is_using_snap()) {
int snap = graph->get_snap();
ofs = ofs.snapped(Vector2(snap,snap));
}
ofs/=EDSCALE;
@ -1463,6 +1479,10 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
if (d.has("type") && String(d["type"])=="visual_script_function_drag") {
Vector2 ofs = graph->get_scroll_ofs() + p_point;
if (graph->is_using_snap()) {
int snap = graph->get_snap();
ofs = ofs.snapped(Vector2(snap,snap));
}
ofs/=EDSCALE;
@ -1491,6 +1511,10 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
if (d.has("type") && String(d["type"])=="visual_script_signal_drag") {
Vector2 ofs = graph->get_scroll_ofs() + p_point;
if (graph->is_using_snap()) {
int snap = graph->get_snap();
ofs = ofs.snapped(Vector2(snap,snap));
}
ofs/=EDSCALE;
@ -1527,6 +1551,10 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
Vector2 ofs = graph->get_scroll_ofs() + p_point;
if (graph->is_using_snap()) {
int snap = graph->get_snap();
ofs = ofs.snapped(Vector2(snap,snap));
}
ofs/=EDSCALE;
undo_redo->create_action(TTR("Add Node(s) From Tree"));
@ -1573,6 +1601,12 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat
Node *node = obj->cast_to<Node>();
Vector2 ofs = graph->get_scroll_ofs() + p_point;
if (graph->is_using_snap()) {
int snap = graph->get_snap();
ofs = ofs.snapped(Vector2(snap,snap));
}
ofs/=EDSCALE;
#ifdef OSX_ENABLED
bool use_set = Input::get_singleton()->is_key_pressed(KEY_META);

View file

@ -109,6 +109,10 @@ void GraphEdit::_scroll_moved(double) {
_update_scroll_offset();
top_layer->update();
if (is_using_snap()) {
//must redraw grid
update();
}
}
void GraphEdit::_update_scroll_offset() {
@ -229,6 +233,11 @@ void GraphEdit::_notification(int p_what) {
h_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,hmin.height);
h_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0);
zoom_minus->set_icon(get_icon("minus"));
zoom_reset->set_icon(get_icon("reset"));
zoom_plus->set_icon(get_icon("more"));
snap_button->set_icon(get_icon("snap"));
// zoom_icon->set_texture( get_icon("Zoom", "EditorIcons"));
}
@ -236,6 +245,48 @@ void GraphEdit::_notification(int p_what) {
draw_style_box( get_stylebox("bg"),Rect2(Point2(),get_size()) );
VS::get_singleton()->canvas_item_set_clip(get_canvas_item(),true);
if (is_using_snap()) {
//draw grid
int snap = get_snap();
Vector2 offset = get_scroll_ofs()/zoom;
Size2 size = get_size()/zoom;
Point2i from = (offset/float(snap)).floor();
Point2i len = (size/float(snap)).floor()+Vector2(1,1);
Color grid_minor = get_color("grid_minor");
Color grid_major = get_color("grid_major");
for(int i=from.x;i<from.x+len.x;i++) {
Color color;
if (ABS(i)%10==0)
color=grid_major;
else
color=grid_minor;
float base_ofs = i*snap*zoom - offset.x*zoom;
draw_line(Vector2(base_ofs,0),Vector2(base_ofs,get_size().height),color);
}
for(int i=from.y;i<from.y+len.y;i++) {
Color color;
if (ABS(i)%10==0)
color=grid_major;
else
color=grid_minor;
float base_ofs = i*snap*zoom - offset.y*zoom;
draw_line(Vector2(0,base_ofs),Vector2(get_size().width,base_ofs),color);
}
}
}
if (p_what==NOTIFICATION_RESIZED) {
@ -597,8 +648,16 @@ void GraphEdit::_input_event(const InputEvent& p_ev) {
drag_accum = get_local_mouse_pos() - drag_origin;
for(int i=get_child_count()-1;i>=0;i--) {
GraphNode *gn=get_child(i)->cast_to<GraphNode>();
if (gn && gn->is_selected())
gn->set_offset((gn->get_drag_from()*zoom+drag_accum)/zoom);
if (gn && gn->is_selected()) {
Vector2 pos = (gn->get_drag_from()*zoom+drag_accum)/zoom;
if (is_using_snap()) {
int snap = get_snap();
pos = pos.snapped(Vector2(snap,snap));
}
gn->set_offset(pos);
}
}
}
@ -937,6 +996,38 @@ bool GraphEdit::is_valid_connection_type(int p_type,int p_with_type) const {
}
void GraphEdit::set_use_snap(bool p_enable) {
snap_button->set_pressed(p_enable);
update();
}
bool GraphEdit::is_using_snap() const{
return snap_button->is_pressed();
}
int GraphEdit::get_snap() const{
return snap_amount->get_val();
}
void GraphEdit::set_snap(int p_snap) {
ERR_FAIL_COND(p_snap<5);
snap_amount->set_val(p_snap);
update();
}
void GraphEdit::_snap_toggled() {
update();
}
void GraphEdit::_snap_value_changed(double) {
update();
}
void GraphEdit::_bind_methods() {
@ -949,6 +1040,12 @@ void GraphEdit::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_zoom","p_zoom"),&GraphEdit::set_zoom);
ObjectTypeDB::bind_method(_MD("get_zoom"),&GraphEdit::get_zoom);
ObjectTypeDB::bind_method(_MD("set_snap","pixels"),&GraphEdit::set_snap);
ObjectTypeDB::bind_method(_MD("get_snap"),&GraphEdit::get_snap);
ObjectTypeDB::bind_method(_MD("set_use_snap","enable"),&GraphEdit::set_use_snap);
ObjectTypeDB::bind_method(_MD("is_using_snap"),&GraphEdit::is_using_snap);
ObjectTypeDB::bind_method(_MD("set_right_disconnects","enable"),&GraphEdit::set_right_disconnects);
ObjectTypeDB::bind_method(_MD("is_right_disconnects_enabled"),&GraphEdit::is_right_disconnects_enabled);
@ -961,6 +1058,8 @@ void GraphEdit::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_zoom_minus"),&GraphEdit::_zoom_minus);
ObjectTypeDB::bind_method(_MD("_zoom_reset"),&GraphEdit::_zoom_reset);
ObjectTypeDB::bind_method(_MD("_zoom_plus"),&GraphEdit::_zoom_plus);
ObjectTypeDB::bind_method(_MD("_snap_toggled"),&GraphEdit::_snap_toggled);
ObjectTypeDB::bind_method(_MD("_snap_value_changed"),&GraphEdit::_snap_value_changed);
ObjectTypeDB::bind_method(_MD("_input_event"),&GraphEdit::_input_event);
@ -1017,17 +1116,33 @@ GraphEdit::GraphEdit() {
zoom_minus = memnew( ToolButton );
zoom_hb->add_child(zoom_minus);
zoom_minus->connect("pressed",this,"_zoom_minus");
zoom_minus->set_icon(get_icon("minus"));
zoom_minus->set_focus_mode(FOCUS_NONE);
zoom_reset = memnew( ToolButton );
zoom_hb->add_child(zoom_reset);
zoom_reset->connect("pressed",this,"_zoom_reset");
zoom_reset->set_icon(get_icon("reset"));
zoom_reset->set_focus_mode(FOCUS_NONE);
zoom_plus = memnew( ToolButton );
zoom_hb->add_child(zoom_plus);
zoom_plus->connect("pressed",this,"_zoom_plus");
zoom_plus->set_icon(get_icon("more"));
zoom_plus->set_focus_mode(FOCUS_NONE);
snap_button = memnew( ToolButton );
snap_button->set_toggle_mode(true);
snap_button->connect("pressed",this,"_snap_toggled");
snap_button->set_pressed(true);
snap_button->set_focus_mode(FOCUS_NONE);
zoom_hb->add_child(snap_button);
snap_amount = memnew( SpinBox );
snap_amount->set_min(5);
snap_amount->set_max(100);
snap_amount->set_step(1);
snap_amount->set_val(20);
snap_amount->connect("value_changed",this,"_snap_value_changed");
zoom_hb->add_child(snap_amount);
}

View file

@ -33,6 +33,7 @@
#include "scene/gui/scroll_bar.h"
#include "scene/gui/slider.h"
#include "scene/gui/tool_button.h"
#include "scene/gui/spin_box.h"
#include "texture_frame.h"
class GraphEdit;
@ -70,6 +71,9 @@ private:
ToolButton *zoom_reset;
ToolButton *zoom_plus;
ToolButton *snap_button;
SpinBox *snap_amount;
void _zoom_minus();
void _zoom_reset();
void _zoom_plus();
@ -149,6 +153,8 @@ private:
friend class GraphEditFilter;
bool _filter_input(const Point2& p_point);
void _snap_toggled();
void _snap_value_changed(double);
protected:
static void _bind_methods();
@ -186,6 +192,11 @@ public:
void set_selected(Node* p_child);
void set_use_snap(bool p_enable);
bool is_using_snap() const;
int get_snap() const;
void set_snap(int p_snap);
GraphEdit();
};

View file

@ -921,7 +921,10 @@ void fill_default_theme(Ref<Theme>& t,const Ref<Font> & default_font,const Ref<F
t->set_icon("minus","GraphEdit", make_icon(icon_zoom_less_png) );
t->set_icon("reset","GraphEdit", make_icon(icon_zoom_reset_png) );
t->set_icon("more","GraphEdit", make_icon(icon_zoom_more_png) );
t->set_icon("snap","GraphEdit", make_icon(icon_snap_png) );
t->set_stylebox("bg","GraphEdit", make_stylebox( tree_bg_png,4,4,4,5) );
t->set_color("grid_minor","GraphEdit", Color(1,1,1,0.05) );
t->set_color("grid_major","GraphEdit", Color(1,1,1,0.2) );

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

View file

@ -194,6 +194,11 @@ static const unsigned char icon_reload_png[]={
};
static const unsigned char icon_snap_png[]={
0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0xff,0x0,0xff,0x0,0xff,0xa0,0xbd,0xa7,0x93,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe0,0x8,0x4,0x2,0x10,0x2e,0xf0,0x12,0xa6,0x44,0x0,0x0,0x0,0x2d,0x49,0x44,0x41,0x54,0x38,0xcb,0x63,0x60,0xa0,0x26,0x78,0xf0,0xe0,0xc1,0x7f,0x52,0xd8,0xc,0xc,0xc,0xc,0x4c,0x94,0x5a,0xca,0x88,0xcd,0x54,0x62,0x81,0x82,0x82,0x2,0xe3,0xa8,0x17,0x46,0xbd,0x30,0x4c,0xbc,0x40,0x31,0x0,0x0,0x40,0xb8,0x58,0x7b,0x75,0x2f,0x50,0xcd,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
};
static const unsigned char icon_stop_png[]={
0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x4,0x0,0x0,0x0,0xb5,0xfa,0x37,0xea,0x0,0x0,0x0,0x4,0x67,0x41,0x4d,0x41,0x0,0x0,0xb1,0x8f,0xb,0xfc,0x61,0x5,0x0,0x0,0x0,0x20,0x63,0x48,0x52,0x4d,0x0,0x0,0x7a,0x26,0x0,0x0,0x80,0x84,0x0,0x0,0xfa,0x0,0x0,0x0,0x80,0xe8,0x0,0x0,0x75,0x30,0x0,0x0,0xea,0x60,0x0,0x0,0x3a,0x98,0x0,0x0,0x17,0x70,0x9c,0xba,0x51,0x3c,0x0,0x0,0x0,0x2,0x62,0x4b,0x47,0x44,0x0,0xff,0x87,0x8f,0xcc,0xbf,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe0,0x6,0x16,0x12,0x2b,0x4,0x4e,0x1d,0x2,0xaf,0x0,0x0,0x0,0x2b,0x49,0x44,0x41,0x54,0x28,0xcf,0x63,0x60,0x20,0xc,0x3e,0x30,0xe3,0x93,0x61,0x64,0x60,0x60,0x60,0x78,0xf8,0x1f,0xbb,0x2,0x79,0x46,0x6,0x6,0x26,0x42,0xe6,0x8f,0x2a,0xa0,0x96,0x2,0x6,0x42,0x91,0x45,0x10,0x0,0x0,0x95,0x31,0x5,0xe4,0xe,0x1,0x8e,0x3,0x0,0x0,0x0,0x25,0x74,0x45,0x58,0x74,0x64,0x61,0x74,0x65,0x3a,0x63,0x72,0x65,0x61,0x74,0x65,0x0,0x32,0x30,0x31,0x36,0x2d,0x30,0x36,0x2d,0x32,0x32,0x54,0x32,0x30,0x3a,0x33,0x39,0x3a,0x32,0x36,0x2b,0x30,0x32,0x3a,0x30,0x30,0xc9,0xad,0xc8,0x52,0x0,0x0,0x0,0x25,0x74,0x45,0x58,0x74,0x64,0x61,0x74,0x65,0x3a,0x6d,0x6f,0x64,0x69,0x66,0x79,0x0,0x32,0x30,0x31,0x36,0x2d,0x30,0x36,0x2d,0x32,0x32,0x54,0x32,0x30,0x3a,0x33,0x39,0x3a,0x32,0x36,0x2b,0x30,0x32,0x3a,0x30,0x30,0xb8,0xf0,0x70,0xee,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
};