2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* call_dialog.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:11:42 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "call_dialog.h"
|
|
|
|
|
2017-01-08 22:11:35 +00:00
|
|
|
#if 0
|
2017-01-16 07:04:19 +00:00
|
|
|
#include "class_db.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "print_string.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "scene/gui/label.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CallDialogParams : public Object {
|
|
|
|
|
2017-01-03 02:03:46 +00:00
|
|
|
GDCLASS( CallDialogParams, Object );
|
2014-02-10 01:10:30 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
bool _set(const StringName& p_name, const Variant& p_value) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
values[p_name]=p_value;
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
bool _get(const StringName& p_name,Variant &r_ret) const {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (values.has(p_name)) {
|
|
|
|
r_ret=values[p_name];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void _get_property_list( List<PropertyInfo> *p_list) const {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
for(int i=0;i<method.arguments.size();i++)
|
|
|
|
p_list->push_back(method.arguments[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
MethodInfo method;
|
|
|
|
HashMap<String,Variant> values;
|
|
|
|
|
|
|
|
CallDialogParams() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void CallDialog::_notification(int p_what) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (p_what==NOTIFICATION_READY) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
call->connect("pressed", this,"_call");
|
|
|
|
cancel->connect("pressed", this,"_cancel");
|
|
|
|
//filter->get_path()->connect("text_changed", this,"_text_changed");
|
|
|
|
_update_method_list();
|
|
|
|
}
|
|
|
|
|
2014-11-06 00:20:42 +00:00
|
|
|
if (p_what==NOTIFICATION_EXIT_TREE) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
call->disconnect("pressed", this,"_call");
|
|
|
|
cancel->disconnect("pressed", this,"_cancel");
|
|
|
|
|
|
|
|
//filter->get_path()->connect("text_changed", this,"_text_changed");
|
|
|
|
_update_method_list();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_what==NOTIFICATION_DRAW) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
RID ci = get_canvas_item();
|
2016-03-08 23:00:52 +00:00
|
|
|
get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CallDialog::_call() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!tree->get_selected())
|
|
|
|
return;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
TreeItem* item=tree->get_selected();
|
|
|
|
ERR_FAIL_COND(!item);
|
|
|
|
int idx=item->get_metadata(0);
|
|
|
|
ERR_FAIL_INDEX(idx,methods.size());
|
|
|
|
MethodInfo &m = methods[idx];
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Variant args[VARIANT_ARG_MAX];
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
for(int i=0;i<VARIANT_ARG_MAX;i++) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (i>=m.arguments.size())
|
|
|
|
continue;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (call_params->values.has(m.arguments[i].name))
|
|
|
|
args[i]=call_params->values[m.arguments[i].name];
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Variant ret = object->call(m.name,args[0],args[1],args[2],args[3],args[4]);
|
|
|
|
if (ret.get_type()!=Variant::NIL)
|
|
|
|
return_value->set_text(ret);
|
|
|
|
else
|
|
|
|
return_value->set_text("");
|
|
|
|
}
|
|
|
|
|
|
|
|
void CallDialog::_cancel() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CallDialog::_item_selected() {
|
|
|
|
|
|
|
|
TreeItem* item=tree->get_selected();
|
|
|
|
ERR_FAIL_COND(!item);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (item->get_metadata(0).get_type()==Variant::NIL) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
call->set_disabled(true);
|
|
|
|
return;
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
call->set_disabled(false);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
int idx=item->get_metadata(0);
|
|
|
|
ERR_FAIL_INDEX(idx,methods.size());
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
MethodInfo &m = methods[idx];
|
|
|
|
|
|
|
|
call_params->values.clear();
|
|
|
|
call_params->method=m;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
property_editor->edit(call_params);
|
|
|
|
property_editor->update_tree();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CallDialog::_update_method_list() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
tree->clear();
|
|
|
|
if (!object)
|
|
|
|
return;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
TreeItem *root = tree->create_item();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
List<MethodInfo> method_list;
|
|
|
|
object->get_method_list(&method_list);
|
|
|
|
method_list.sort();
|
|
|
|
methods.clear();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
List<String> inheritance_list;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-01-03 02:03:46 +00:00
|
|
|
String type = object->get_class();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
|
|
|
while(type!="") {
|
2014-02-10 01:10:30 +00:00
|
|
|
inheritance_list.push_back( type );
|
2017-01-03 02:03:46 +00:00
|
|
|
type=ClassDB::get_parent_class(type);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
TreeItem *selected_item=NULL;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
for(int i=0;i<inheritance_list.size();i++) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String type=inheritance_list[i];
|
2017-01-03 02:03:46 +00:00
|
|
|
String parent_type=ClassDB::get_parent_class(type);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
TreeItem *type_item=NULL;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
List<MethodInfo>::Element *N,*E=method_list.front();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
while(E) {
|
|
|
|
|
|
|
|
N=E->next();
|
|
|
|
|
2017-01-03 02:03:46 +00:00
|
|
|
if (parent_type!="" && ClassDB::get_method(parent_type,E->get().name)!=NULL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
E=N;
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!type_item) {
|
|
|
|
type_item=tree->create_item(root);
|
|
|
|
type_item->set_text(0,type);
|
|
|
|
if (has_icon(type,"EditorIcons"))
|
|
|
|
type_item->set_icon(0,get_icon(type,"EditorIcons"));
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
TreeItem *method_item = tree->create_item(type_item);
|
|
|
|
method_item->set_text(0,E->get().name);
|
|
|
|
method_item->set_metadata(0,methods.size());
|
|
|
|
if (E->get().name==selected)
|
|
|
|
selected_item=method_item;
|
|
|
|
methods.push_back( E->get() );
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
method_list.erase(E);
|
|
|
|
E=N;
|
|
|
|
}
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (selected_item)
|
|
|
|
selected_item->select(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CallDialog::_bind_methods() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-01-03 02:03:46 +00:00
|
|
|
ClassDB::bind_method("_call",&CallDialog::_call);
|
|
|
|
ClassDB::bind_method("_cancel",&CallDialog::_cancel);
|
|
|
|
ClassDB::bind_method("_item_selected", &CallDialog::_item_selected);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CallDialog::set_object(Object *p_object,StringName p_selected) {
|
|
|
|
|
|
|
|
object=p_object;
|
|
|
|
selected=p_selected;
|
|
|
|
property_editor->edit(NULL);
|
|
|
|
call->set_disabled(true);
|
|
|
|
return_value->clear();
|
|
|
|
|
|
|
|
_update_method_list();
|
2017-01-03 02:03:46 +00:00
|
|
|
method_label->set_text(vformat(TTR("Method List For '%s':"),p_object->get_class()));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CallDialog::CallDialog() {
|
|
|
|
|
|
|
|
object=NULL;
|
|
|
|
|
|
|
|
call = memnew( Button );
|
|
|
|
call->set_anchor( MARGIN_LEFT, ANCHOR_END );
|
|
|
|
call->set_anchor( MARGIN_TOP, ANCHOR_END );
|
|
|
|
call->set_anchor( MARGIN_RIGHT, ANCHOR_END );
|
|
|
|
call->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
|
|
|
|
call->set_begin( Point2( 70, 29 ) );
|
2016-03-08 23:00:52 +00:00
|
|
|
call->set_end( Point2( 15, 15 ) );
|
2016-05-04 01:25:37 +00:00
|
|
|
call->set_text(TTR("Call"));
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(call);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
cancel = memnew( Button );
|
|
|
|
cancel->set_anchor( MARGIN_TOP, ANCHOR_END );
|
|
|
|
cancel->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
|
|
|
|
cancel->set_begin( Point2( 15, 29 ) );
|
2016-03-08 23:00:52 +00:00
|
|
|
cancel->set_end( Point2( 70, 15 ) );
|
2016-05-04 01:25:37 +00:00
|
|
|
cancel->set_text(TTR("Close"));
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(cancel);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
tree = memnew( Tree );
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
tree->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
|
|
|
|
tree->set_begin( Point2( 20,50 ) );
|
|
|
|
tree->set_margin(MARGIN_BOTTOM, 44 );
|
|
|
|
tree->set_margin(MARGIN_RIGHT, 0.5 );
|
|
|
|
tree->set_select_mode( Tree::SELECT_ROW );
|
|
|
|
add_child(tree);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
tree->connect("item_selected", this,"_item_selected");
|
|
|
|
tree->set_hide_root(true);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
property_editor = memnew( PropertyEditor );
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
property_editor->set_anchor_and_margin( MARGIN_RIGHT, ANCHOR_END, 15 );
|
|
|
|
property_editor->set_anchor_and_margin( MARGIN_TOP, ANCHOR_BEGIN, 50 );
|
2017-01-14 11:26:56 +00:00
|
|
|
//property_editor->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.55 );
|
2014-02-10 01:10:30 +00:00
|
|
|
property_editor->set_anchor_and_margin( MARGIN_BOTTOM, ANCHOR_END, 90 );
|
2014-11-06 00:20:42 +00:00
|
|
|
property_editor->get_scene_tree()->set_hide_root( true );
|
2014-02-10 01:10:30 +00:00
|
|
|
property_editor->hide_top_label();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(property_editor);
|
|
|
|
method_label = memnew( Label );
|
|
|
|
method_label->set_pos( Point2( 15,25) );
|
2016-05-04 01:25:37 +00:00
|
|
|
method_label->set_text(TTR("Method List:"));
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(method_label);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Label *label = memnew( Label );
|
2017-01-08 22:11:35 +00:00
|
|
|
//label->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.53 );
|
2014-02-10 01:10:30 +00:00
|
|
|
label->set_anchor_and_margin( MARGIN_TOP, ANCHOR_BEGIN, 25 );
|
2016-05-04 01:25:37 +00:00
|
|
|
label->set_text(TTR("Arguments:"));
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(label);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return_label = memnew( Label );
|
2017-01-08 22:11:35 +00:00
|
|
|
//return_label->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.53 );
|
2014-02-10 01:10:30 +00:00
|
|
|
return_label->set_anchor_and_margin( MARGIN_TOP, ANCHOR_END, 85 );
|
2016-05-04 01:25:37 +00:00
|
|
|
return_label->set_text(TTR("Return:"));
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(return_label);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return_value = memnew( LineEdit );
|
2017-01-08 22:11:35 +00:00
|
|
|
//return_value->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.55 );
|
2016-03-08 23:00:52 +00:00
|
|
|
return_value->set_anchor_and_margin( MARGIN_RIGHT, ANCHOR_END, 15 );
|
2014-02-10 01:10:30 +00:00
|
|
|
return_value->set_anchor_and_margin( MARGIN_TOP, ANCHOR_END, 65 );
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(return_value);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
/*
|
|
|
|
label = memnew( Label );
|
|
|
|
label->set_anchor( MARGIN_TOP, ANCHOR_END );
|
|
|
|
label->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
label->set_begin( Point2( 15,54) );
|
|
|
|
label->set_end( Point2( 16,44) );
|
2016-05-20 23:18:35 +00:00
|
|
|
label->set_text("Parameters:");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(label);
|
|
|
|
*/
|
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
call_params = memnew( CallDialogParams );
|
|
|
|
set_as_toplevel(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CallDialog::~CallDialog()
|
|
|
|
{
|
|
|
|
memdelete(call_params);
|
|
|
|
}
|
2017-01-08 22:11:35 +00:00
|
|
|
#endif
|