add autocompletion
This commit is contained in:
parent
e596ffef52
commit
30c5674667
@ -69,6 +69,15 @@ void TextInputNode::update()
|
|||||||
cursor_pos_updated=true;
|
cursor_pos_updated=true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 9:
|
||||||
|
if (!m_text.empty())
|
||||||
|
{
|
||||||
|
if(m_tab_callback)
|
||||||
|
m_tab_callback->exec();
|
||||||
|
input_string_updated = true;
|
||||||
|
cursor_pos_updated=true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 127:
|
case 127:
|
||||||
m_text.erase(m_cursor_pos,1);
|
m_text.erase(m_cursor_pos,1);
|
||||||
input_string_updated = true;
|
input_string_updated = true;
|
||||||
|
@ -24,6 +24,7 @@ class TextInputNode : public GUINode
|
|||||||
int m_move_cursor_right;
|
int m_move_cursor_right;
|
||||||
|
|
||||||
CallBack* m_callback;
|
CallBack* m_callback;
|
||||||
|
CallBack* m_tab_callback;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TextInputNode(glm::vec2 dimension);
|
TextInputNode(glm::vec2 dimension);
|
||||||
@ -34,6 +35,7 @@ public:
|
|||||||
void setTextColor(glm::vec3 color);
|
void setTextColor(glm::vec3 color);
|
||||||
std::string getText();
|
std::string getText();
|
||||||
void setCallBack(CallBack* callback){m_callback = callback;}
|
void setCallBack(CallBack* callback){m_callback = callback;}
|
||||||
|
void setTabCallBack(CallBack* callback){m_tab_callback = callback;}
|
||||||
void setMoveCursorLeft(int action){m_move_cursor_left = action;}
|
void setMoveCursorLeft(int action){m_move_cursor_left = action;}
|
||||||
void setMoveCursorRight(int action){m_move_cursor_right = action;}
|
void setMoveCursorRight(int action){m_move_cursor_right = action;}
|
||||||
void clearText(){m_text.clear();}
|
void clearText(){m_text.clear();}
|
||||||
|
@ -8,10 +8,12 @@
|
|||||||
#include "SparrowRenderer/Version.h"
|
#include "SparrowRenderer/Version.h"
|
||||||
#include "SparrowSerializer/Version.h"
|
#include "SparrowSerializer/Version.h"
|
||||||
|
|
||||||
#define LUA_SET_FUN(var) m_script.set_function(#var,&ScriptNode::var,this)
|
#define LUA_DEFINE(var) S[#var]=var
|
||||||
|
#define LUA_SET_FUN(var) m_script.set_function(#var,&ScriptNode::var,this);this->functions_name.push_back(#var);
|
||||||
|
|
||||||
ScriptNode::ScriptNode()
|
ScriptNode::ScriptNode()
|
||||||
{
|
{
|
||||||
|
LUA_SET_FUN(getDeltaTime);
|
||||||
LUA_SET_FUN(print);
|
LUA_SET_FUN(print);
|
||||||
LUA_SET_FUN(version);
|
LUA_SET_FUN(version);
|
||||||
LUA_SET_FUN(clear);
|
LUA_SET_FUN(clear);
|
||||||
@ -31,6 +33,14 @@ void ScriptNode::execute(std::string to_execute){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> ScriptNode::possibleCompletion(std::string search){
|
||||||
|
std::vector<std::string> result;
|
||||||
|
for(std::string& name : functions_name)
|
||||||
|
if(name.find(search)==0)
|
||||||
|
result.push_back(name);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptNode::print(std::string to_print){
|
void ScriptNode::print(std::string to_print){
|
||||||
this->getEngine().getShell()->out(to_print.append("\n"));
|
this->getEngine().getShell()->out(to_print.append("\n"));
|
||||||
}
|
}
|
||||||
@ -54,3 +64,6 @@ void ScriptNode::clear(){
|
|||||||
this->getEngine().getShell()->clear();
|
this->getEngine().getShell()->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float ScriptNode::getDeltaTime(){
|
||||||
|
return this->getEngine().getDeltaTime()/1000.;
|
||||||
|
}
|
||||||
|
@ -8,16 +8,19 @@ class ScriptNode : public GraphicalNode
|
|||||||
{
|
{
|
||||||
|
|
||||||
sol::state m_script;
|
sol::state m_script;
|
||||||
|
std::vector<std::string> functions_name;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ScriptNode();
|
ScriptNode();
|
||||||
void update();
|
void update();
|
||||||
void execute(std::string);
|
void execute(std::string);
|
||||||
|
std::vector<std::string> possibleCompletion(std::string);
|
||||||
|
|
||||||
/* -- LUA function -- */
|
/* -- LUA function -- */
|
||||||
void print(std::string);
|
void print(std::string);
|
||||||
void version();
|
void version();
|
||||||
void clear();
|
void clear();
|
||||||
|
float getDeltaTime();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ SparrowShell::SparrowShell(sf::Window* window):
|
|||||||
m_input_node = new TextInputNode(glm::vec2(m_buffer->getFontSize(),size.y));
|
m_input_node = new TextInputNode(glm::vec2(m_buffer->getFontSize(),size.y));
|
||||||
m_input_node->setPosition(glm::vec2(0,m_buffer->getFontSize()*BUFFER_DISPLAYED_LINES));
|
m_input_node->setPosition(glm::vec2(0,m_buffer->getFontSize()*BUFFER_DISPLAYED_LINES));
|
||||||
m_input_node->setCallBack(new InputCallBack(this,m_input_node));
|
m_input_node->setCallBack(new InputCallBack(this,m_input_node));
|
||||||
|
m_input_node->setTabCallBack(new AutocompletionCallBack(this,m_input_node));
|
||||||
|
|
||||||
this->addChild(m_background);
|
this->addChild(m_background);
|
||||||
this->addChild(m_buffer);
|
this->addChild(m_buffer);
|
||||||
@ -61,6 +62,21 @@ SparrowShell::InputCallBack::InputCallBack(SparrowShell* shell,TextInputNode* te
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SparrowShell::AutocompletionCallBack::AutocompletionCallBack(SparrowShell* shell,TextInputNode* textinput):
|
||||||
|
m_shell(shell),
|
||||||
|
m_text_input_node(textinput)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SparrowShell::AutocompletionCallBack::exec(){
|
||||||
|
std::string text = m_text_input_node->getText();
|
||||||
|
std::vector<std::string> result = m_shell->m_script->possibleCompletion(text);
|
||||||
|
std::string output = "";
|
||||||
|
for(std::string& fun : result)
|
||||||
|
output+=fun+" ";
|
||||||
|
m_shell->out(output,glm::vec3(1,1,0));
|
||||||
|
}
|
||||||
|
|
||||||
void SparrowShell::InputCallBack::exec(){
|
void SparrowShell::InputCallBack::exec(){
|
||||||
std::string text = m_text_input_node->getText();
|
std::string text = m_text_input_node->getText();
|
||||||
m_shell->out(text);
|
m_shell->out(text);
|
||||||
@ -76,16 +92,18 @@ void SparrowShell::out(std::string str)
|
|||||||
|
|
||||||
void SparrowShell::out(std::string str,glm::vec3 color)
|
void SparrowShell::out(std::string str,glm::vec3 color)
|
||||||
{
|
{
|
||||||
Font *shellfont = RESOURCE_GET(Font,"shellfont");
|
if(!str.empty()){
|
||||||
TextNode* tnode = shellfont->getTextNode(str,color,m_buffer->getFontSize(),false);
|
Font *shellfont = RESOURCE_GET(Font,"shellfont");
|
||||||
std::string name = "shellTextLine";
|
TextNode* tnode = shellfont->getTextNode(str,color,m_buffer->getFontSize(),false);
|
||||||
name += m_buffer->size();
|
std::string name = "shellTextLine";
|
||||||
tnode->getGeometryNode()->mesh->setName(name);
|
name += m_buffer->size();
|
||||||
tnode->setDepth(SHELL_DEPTH+1);
|
tnode->getGeometryNode()->mesh->setName(name);
|
||||||
m_buffer->push(tnode);
|
tnode->setDepth(SHELL_DEPTH+1);
|
||||||
scrollDown();
|
m_buffer->push(tnode);
|
||||||
if (m_buffer->size() > SparrowShell::BUFFER_DISPLAYED_LINES)
|
scrollDown();
|
||||||
m_scrollbar->setSize(m_buffer->size());
|
if (m_buffer->size() > SparrowShell::BUFFER_DISPLAYED_LINES)
|
||||||
|
m_scrollbar->setSize(m_buffer->size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SparrowShell::scrollUp()
|
void SparrowShell::scrollUp()
|
||||||
|
@ -37,6 +37,14 @@ private:
|
|||||||
virtual void exec();
|
virtual void exec();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class AutocompletionCallBack : public CallBack{
|
||||||
|
SparrowShell* m_shell;
|
||||||
|
TextInputNode* m_text_input_node;
|
||||||
|
public:
|
||||||
|
AutocompletionCallBack(SparrowShell* shell,TextInputNode* textinput);
|
||||||
|
virtual void exec();
|
||||||
|
};
|
||||||
|
|
||||||
glm::vec2 m_dimension;
|
glm::vec2 m_dimension;
|
||||||
bool m_shellEnabled = false;
|
bool m_shellEnabled = false;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user