diff --git a/src/engine.h b/src/engine.h index d05f8a8..992fac6 100644 --- a/src/engine.h +++ b/src/engine.h @@ -53,7 +53,7 @@ public: btDiscreteDynamicsWorld* getPhysics() const {return m_world;} SparrowShell* getShell() const {return m_sparrowshell;} PhysicsDebugNode* getPhysicsDebug() const {return m_physicsDebugNode;} - Editor* getGuiTools() const {return m_editor;} + Editor* getEditor() const {return m_editor;} LoadingThread* getLoadingThread() const {return m_loadingThread;} SceneTree* getScene() const; diff --git a/src/scene/gui/textinputnode.cpp b/src/scene/gui/textinputnode.cpp index efe6cd5..6629855 100644 --- a/src/scene/gui/textinputnode.cpp +++ b/src/scene/gui/textinputnode.cpp @@ -19,10 +19,11 @@ TextInputNode::TextInputNode(glm::vec2 dimension): m_cursor_mesh(nullptr), m_cursor_pos(0), m_cursor_pos_updated(false), - m_move_cursor_left(NO_ACTION), - m_move_cursor_right(NO_ACTION), m_callback(nullptr), - m_tab_callback(nullptr) + m_tab_callback(nullptr), + m_history(std::vector()), + m_history_pos(0), + m_inputActions({NO_ACTION, NO_ACTION, NO_ACTION, NO_ACTION}) { // Font *shellfont = RESOURCE_GET(Font,"shellfont"); Mesh* mesh = new Mesh(); @@ -44,18 +45,46 @@ void TextInputNode::update() auto input = getEngine().getInput(); for(auto action : input->getActions()){ - if (action.action == m_move_cursor_left){ + if (action.action == m_inputActions[MOVE_CURSOR_LEFT]){ if (m_cursor_pos > 0){ m_cursor_pos--; m_cursor_pos_updated=true; } } - else if(action.action == m_move_cursor_right){ + else if(action.action == m_inputActions[MOVE_CURSOR_RIGHT]){ if(m_cursor_pos < m_text.length()){ m_cursor_pos++; m_cursor_pos_updated=true; } } + else if(action.action == m_inputActions[HISTORY_PREVIOUS]){ + if(m_history_pos > 0) + { + m_history_pos--; + m_text = m_history[m_history_pos]; + m_cursor_pos = m_text.size(); + m_text_updated = true; + m_cursor_pos_updated = true; + } + } + else if(action.action == m_inputActions[HISTORY_NEXT]){ + if (m_history_pos < m_history.size()) + { + m_history_pos++; + if (m_history_pos == m_history.size()) + { + m_text.clear(); + m_cursor_pos = 0; + } + else + { + m_text = m_history[m_history_pos]; + m_cursor_pos = m_text.size(); + } + m_text_updated = true; + m_cursor_pos_updated = true; + } + } } for(unsigned int i = 0 ; i < text.length() ; i++){ @@ -150,3 +179,18 @@ std::string TextInputNode::getText() return m_text; } +void TextInputNode::clearText() +{ + m_history.push_back(m_text); + m_history_pos++; + m_text.clear(); +} + +void TextInputNode::setInputs(int cursor_left, int cursor_right, int history_up, int history_down) +{ + m_inputActions[TextInputAction::MOVE_CURSOR_LEFT] = cursor_left; + m_inputActions[TextInputAction::MOVE_CURSOR_RIGHT] = cursor_right; + m_inputActions[TextInputAction::HISTORY_NEXT] = history_down; + m_inputActions[TextInputAction::HISTORY_PREVIOUS] = history_up; +} + diff --git a/src/scene/gui/textinputnode.h b/src/scene/gui/textinputnode.h index a53789b..ba8b270 100644 --- a/src/scene/gui/textinputnode.h +++ b/src/scene/gui/textinputnode.h @@ -7,6 +7,15 @@ #include "scene/textnode.h" #include "scene/gui/callback.h" +/* +struct TextInputAction{ + int cursor_left; + int cursor_right; + int history_next; + int history_previous; +}; +*/ + class TextInputNode : public GUINode { glm::vec2 m_dimension; @@ -22,12 +31,16 @@ class TextInputNode : public GUINode unsigned int m_cursor_pos; bool m_cursor_pos_updated; - int m_move_cursor_left; - int m_move_cursor_right; - CallBack* m_callback; CallBack* m_tab_callback; + std::vector m_history; + unsigned int m_history_pos; + + std::vector m_inputActions; + + enum TextInputAction {MOVE_CURSOR_LEFT,MOVE_CURSOR_RIGHT,HISTORY_PREVIOUS,HISTORY_NEXT}; + public: TextInputNode(glm::vec2 dimension); void update(); @@ -41,9 +54,10 @@ public: std::string getText(); 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 setMoveCursorRight(int action){m_move_cursor_right = action;} - void clearText(){m_text.clear();} + + void setInputs(int cursor_left, int cursor_right, int history_up, int history_down); + + void clearText(); }; #endif // TEXTINPUTNODE_H diff --git a/src/sparrowshell/scriptnode.cpp b/src/sparrowshell/scriptnode.cpp index 017624e..7cbcfd1 100644 --- a/src/sparrowshell/scriptnode.cpp +++ b/src/sparrowshell/scriptnode.cpp @@ -99,17 +99,17 @@ void ScriptNode::testfunc(int i, float x=0.f,float y=0.f, float z=0.f){ } void ScriptNode::picker(){ - this->getEngine().getGuiTools()->togglePicker(); + this->getEngine().getEditor()->togglePicker(); } void ScriptNode::materialEditor(){ - this->getEngine().getGuiTools()->toggleMaterialEditor(); + this->getEngine().getEditor()->toggleMaterialEditor(); } void ScriptNode::rendering(){ - this->getEngine().getGuiTools()->toggleRenderingPipelineGui(); + this->getEngine().getEditor()->toggleRenderingPipelineGui(); } void ScriptNode::resourcePackEditor(){ - this->getEngine().getGuiTools()->toggleResourcePackGui(); + this->getEngine().getEditor()->toggleResourcePackGui(); } diff --git a/src/sparrowshell/sparrowshell.cpp b/src/sparrowshell/sparrowshell.cpp index 593fcaa..1d51954 100644 --- a/src/sparrowshell/sparrowshell.cpp +++ b/src/sparrowshell/sparrowshell.cpp @@ -24,8 +24,7 @@ const float SparrowShell::DEFAULT_FONT_SIZE = 16.f; SparrowShell::SparrowShell(sf::Window* window): m_buffer(new ShellBuffer(BUFFER_MAX_LENGTH)), - m_text_color(glm::vec3(0.7,1,0.3)), - m_inputActions({NO_ACTION, NO_ACTION, NO_ACTION, NO_ACTION}) + m_text_color(glm::vec3(0.7,1,0.3)) { sf::Vector2u size = window->getSize(); m_dimension = glm::ivec2(size.x,DEFAULT_FONT_SIZE*(BUFFER_DISPLAYED_LINES+1)); @@ -71,9 +70,23 @@ SparrowShell::AutocompletionCallBack::AutocompletionCallBack(SparrowShell* shell void SparrowShell::AutocompletionCallBack::exec(){ std::string text = m_text_input_node->getText(); - std::vector result = m_shell->m_script->possibleCompletion(text); + std::vector results = m_shell->m_script->possibleCompletion(text); + + if (!results.empty()){ + std:: string common_prefix = results[0]; + for( auto result : results){ + int i = 0; + auto s1 = common_prefix.c_str(); + auto s2 = result.c_str(); + std::string cp; + while( (s1[i] && s2[i]) && (s1[i] == s2[i]) ) + cp.push_back(s1[i++]); + common_prefix = cp; + } + m_text_input_node->setText(common_prefix); + } std::string output = ""; - for(std::string& fun : result) + for(std::string& fun : results) output+=fun+" "; m_shell->out(output,glm::vec3(1,1,0)); } @@ -124,12 +137,7 @@ void SparrowShell::scrollDown() } void SparrowShell::setInputs(int cursor_left, int cursor_right, int history_up, int history_down){ - m_inputActions[MOVE_CURSOR_LEFT] = cursor_left; - m_inputActions[MOVE_CURSOR_RIGHT] = cursor_right; - m_inputActions[HISTORY_PREVIOUS] = history_up; - m_inputActions[HISTORY_NEXT] = history_down; - m_input_node->setMoveCursorLeft(cursor_left); - m_input_node->setMoveCursorRight(cursor_right); + m_input_node->setInputs(cursor_left,cursor_right,history_up,history_down); } void SparrowShell::toggleShell() diff --git a/src/sparrowshell/sparrowshell.h b/src/sparrowshell/sparrowshell.h index 7f3eaab..cce3c9a 100644 --- a/src/sparrowshell/sparrowshell.h +++ b/src/sparrowshell/sparrowshell.h @@ -60,9 +60,9 @@ private: int m_move_cursor_right; std::string m_previous_context; - std::vector m_inputActions; +// std::vector m_inputActions; - enum ShellAction {MOVE_CURSOR_LEFT=0,MOVE_CURSOR_RIGHT,HISTORY_PREVIOUS,HISTORY_NEXT}; +// enum ShellAction {MOVE_CURSOR_LEFT,MOVE_CURSOR_RIGHT,HISTORY_PREVIOUS,HISTORY_NEXT}; public: static const unsigned int BUFFER_MAX_LENGTH; diff --git a/src/tools/scenepicker.cpp b/src/tools/scenepicker.cpp index 6f78c3c..adca975 100644 --- a/src/tools/scenepicker.cpp +++ b/src/tools/scenepicker.cpp @@ -64,7 +64,7 @@ void ScenePicker::update() ImGui::End(); if(!isEnabled) - getEngine().getGuiTools()->togglePicker(); + getEngine().getEditor()->togglePicker(); } void ScenePicker::pick()