Making Godot Easier to Use..

-=-=-=-=-=-=-=-=-=-=-=-=-=-=

-Auto indenter in code editor, this makes it much easier to paste external code.
-Zoom in 2D viewport now uses the mouse pointer as reference.
-Obscure hack to see where code/line of GDScript in C++ backtrace.
-Fixed a bug where keys would get stuck on X11 if pressed simultaneously
-Added Api on IP singleton to request local IPs.
-Premultiplied alpha support when importing texture, editing PNGs and as a blend mode.
This commit is contained in:
Juan Linietsky
2014-05-24 01:35:47 -03:00
parent f9ff086235
commit 1cad087969
54 changed files with 928 additions and 106 deletions

View File

@ -1263,6 +1263,16 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *
gdfunc->name=func_name;
gdfunc->_script=p_script;
gdfunc->source=source;
#ifdef DEBUG_ENABLED
{
gdfunc->func_cname=(String(source)+" - "+String(func_name)).utf8();
gdfunc->_func_cname=gdfunc->func_cname.get_data();
}
#endif
if (p_func) {
gdfunc->_initial_line=p_func->line;
} else {

View File

@ -787,3 +787,67 @@ Error GDScriptLanguage::complete_keyword(const String& p_code, int p_line, const
return OK;
}
void GDScriptLanguage::auto_indent_code(String& p_code,int p_from_line,int p_to_line) const {
Vector<String> lines = p_code.split("\n");
List<int> indent_stack;
for(int i=0;i<lines.size();i++) {
String l = lines[i];
int tc=0;
for(int j=0;j<l.length();j++) {
if (l[j]==' ' || l[j]=='\t') {
tc++;
} else {
break;
}
}
String st = l.substr(tc,l.length()).strip_edges();
if (st=="" || st.begins_with("#"))
continue; //ignore!
int ilevel=0;
if (indent_stack.size()) {
ilevel=indent_stack.back()->get();
}
if (tc>ilevel) {
indent_stack.push_back(tc);
} else if (tc<ilevel) {
while(indent_stack.size() && indent_stack.back()->get()>tc) {
indent_stack.pop_back();
}
if (indent_stack.size() && indent_stack.back()->get()!=tc)
indent_stack.push_back(tc); //this is not right but gets the job done
}
if (i>=p_from_line) {
l="";
for(int j=0;j<indent_stack.size();j++)
l+="\t";
l+=st;
} else if (i>p_to_line) {
break;
}
//print_line(itos(indent_stack.size())+","+itos(tc)+": "+l);
lines[i]=l;
}
p_code="";
for(int i=0;i<lines.size();i++) {
if (i>0)
p_code+="\n";
p_code+=lines[i];
}
}

View File

@ -1221,6 +1221,15 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
return; //go back a level
}
if (pending_newline!=-1) {
NewLineNode *nl = alloc_node<NewLineNode>();
nl->line=pending_newline;
p_block->statements.push_back(nl);
pending_newline=-1;
}
switch(token) {
@ -1234,16 +1243,19 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
} break;
case GDTokenizer::TK_NEWLINE: {
if (!_parse_newline()) {
if (!error_set) {
p_block->end_line=tokenizer->get_token_line();
pending_newline=p_block->end_line;
}
return;
}
NewLineNode *nl = alloc_node<NewLineNode>();
nl->line=tokenizer->get_token_line();
p_block->statements.push_back(nl);
if (!_parse_newline()) {
if (!error_set) {
p_block->end_line=tokenizer->get_token_line();
}
return;
}
} break;
case GDTokenizer::TK_CF_PASS: {
if (tokenizer->get_token(1)!=GDTokenizer::TK_SEMICOLON && tokenizer->get_token(1)!=GDTokenizer::TK_NEWLINE ) {
@ -1782,6 +1794,7 @@ void GDParser::_parse_class(ClassNode *p_class) {
case GDTokenizer::TK_PR_FUNCTION: {
bool _static=false;
pending_newline=-1;
if (tokenizer->get_token(-1)==GDTokenizer::TK_PR_STATIC) {
@ -2490,6 +2503,7 @@ void GDParser::clear() {
tab_level.push_back(0);
error_line=0;
error_column=0;
pending_newline=-1;
parenthesis=0;
current_export.type=Variant::NIL;
error="";
@ -2501,6 +2515,7 @@ GDParser::GDParser() {
head=NULL;
list=NULL;
tokenizer=NULL;
pending_newline=-1;
clear();
}

View File

@ -362,6 +362,8 @@ private:
int error_line;
int error_column;
int pending_newline;
List<int> tab_level;
String base_path;

View File

@ -1159,6 +1159,9 @@ GDFunction::GDFunction() {
_stack_size=0;
_call_size=0;
name="<anonymous>";
#ifdef DEBUG_ENABLED
_func_cname=NULL;
#endif
}

View File

@ -118,10 +118,13 @@ friend class GDCompiler;
Vector<Variant> constants;
Vector<StringName> global_names;
Vector<int> default_arguments;
Vector<int> code;
#ifdef DEBUG_ENABLED
CharString func_cname;
const char*_func_cname;
#endif
List<StackDebug> stack_debug;
List<StackDebug> stack_debug;
_FORCE_INLINE_ Variant *_get_variant(int p_address,GDInstance *p_instance,GDScript *p_script,Variant &self,Variant *p_stack,String& r_error) const;
_FORCE_INLINE_ String _get_call_error(const Variant::CallError& p_err, const String& p_where,const Variant**argptrs) const;
@ -427,6 +430,7 @@ public:
virtual int find_function(const String& p_function,const String& p_code) const;
virtual String make_function(const String& p_class,const String& p_name,const StringArray& p_args) const;
virtual Error complete_keyword(const String& p_code, int p_line, const String& p_base_path,const String& p_keyword, List<String>* r_options);
virtual void auto_indent_code(String& p_code,int p_from_line,int p_to_line) const;
/* DEBUGGER FUNCTIONS */