-improved completion options for InputEvent, shows all event types now

This commit is contained in:
Juan Linietsky 2014-12-18 00:56:33 -03:00
parent bed3b7f092
commit 9f5bbfc322
4 changed files with 98 additions and 28 deletions

View File

@ -805,12 +805,25 @@ void ObjectTypeDB::add_virtual_method(const StringName& p_type,const MethodInfo&
}
void ObjectTypeDB::get_virtual_methods(const StringName& p_type,List<MethodInfo> * p_methods ) {
void ObjectTypeDB::get_virtual_methods(const StringName& p_type, List<MethodInfo> * p_methods , bool p_no_inheritance) {
ERR_FAIL_COND(!types.has(p_type));
#ifdef DEBUG_METHODS_ENABLED
*p_methods=types[p_type].virtual_methods;
TypeInfo *type=types.getptr(p_type);
TypeInfo *check=type;
while(check) {
for(List<MethodInfo>::Element *E=check->virtual_methods.front();E;E=E->next()) {
p_methods->push_back(E->get());
}
if (p_no_inheritance)
return;
check=check->inherits_ptr;
}
#endif
}

View File

@ -468,7 +468,7 @@ public:
static MethodBind *get_method(StringName p_type, StringName p_name);
static void add_virtual_method(const StringName& p_type,const MethodInfo& p_method );
static void get_virtual_methods(const StringName& p_type,List<MethodInfo> * p_methods );
static void get_virtual_methods(const StringName& p_type,List<MethodInfo> * p_methods,bool p_no_inheritance=false );
static void bind_integer_constant(const StringName& p_type, const StringName &p_name, int p_constant);
static void get_integer_constant_list(const StringName& p_type, List<String> *p_constants, bool p_no_inheritance=false);

View File

@ -1625,12 +1625,6 @@ static void _find_call_arguments(GDCompletionContext& context,const GDParser::No
}
Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base_path, Object*p_owner, List<String>* r_options, String &r_call_hint) {
/* bugs:
a[0].<complete> does not work
functions should end in (
when completing virtuals, ask for full back
*/
//print_line( p_code.replace(String::chr(0xFFFF),"<cursor>"));
GDParser p;
@ -1700,11 +1694,63 @@ Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base
}
} else {
if (t.type==Variant::INPUT_EVENT) {
//this is hardcoded otherwise it's not obvious
Set<String> exclude;
for(int i=0;i<InputEvent::TYPE_MAX;i++) {
InputEvent ie;
ie.type=InputEvent::Type(i);
static const char*evnames[]={
"# Common",
"# Key",
"# MouseMotion",
"# MouseButton",
"# JoyMotion",
"# JoyButton",
"# ScreenTouch",
"# ScreenDrag",
"# Action"
};
r_options->push_back(evnames[i]);
Variant v = ie;
if (i==0) {
List<MethodInfo> mi;
v.get_method_list(&mi);
for (List<MethodInfo>::Element *E=mi.front();E;E=E->next()) {
r_options->push_back(E->get().name+"(");
}
}
List<PropertyInfo> pi;
v.get_property_list(&pi);
for (List<PropertyInfo>::Element *E=pi.front();E;E=E->next()) {
if (i==0)
exclude.insert(E->get().name);
else if (exclude.has(E->get().name))
continue;
r_options->push_back(E->get().name);
}
}
return OK;
} else {
if (t.value.get_type()==Variant::NIL) {
Variant::CallError ce;
t.value=Variant::construct(t.type,NULL,0,ce);
}
if (!isfunction) {
List<PropertyInfo> pl;
t.value.get_property_list(&pl);
@ -1726,6 +1772,7 @@ Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base
}
}
}
}

View File

@ -793,6 +793,7 @@ void TextEdit::_notification(int p_what) {
int maxlines = get_constant("completion_lines");
int cmax_width = get_constant("completion_max_width")*cache.font->get_char_size('x').x;
Color existing = get_color("completion_existing");
existing.a=0.2;
int scrollw = get_constant("completion_scroll_width");
Color scrollc = get_color("completion_scroll_color");
@ -841,11 +842,20 @@ void TextEdit::_notification(int p_what) {
draw_rect(Rect2(completion_rect.pos,Size2(nofs,completion_rect.size.height)),existing);
for(int i=0;i<lines;i++) {
int l = line_from + i;
ERR_CONTINUE( l < 0 || l>= completion_options.size());
draw_string(cache.font,Point2(completion_rect.pos.x,completion_rect.pos.y+i*get_row_height()+cache.font->get_ascent()),completion_options[l],cache.font_color,completion_rect.size.width);
Color text_color = cache.font_color;
for(int j=0;j<color_regions.size();j++) {
if (completion_options[l].begins_with(color_regions[j].begin_key)) {
text_color=color_regions[j].color;
}
}
draw_string(cache.font,Point2(completion_rect.pos.x,completion_rect.pos.y+i*get_row_height()+cache.font->get_ascent()),completion_options[l],text_color,completion_rect.size.width);
}
if (scrollw) {