This commit is contained in:
Anselme 2017-08-29 21:33:08 +02:00
commit 36d5b79c9f
7 changed files with 95 additions and 29 deletions

View File

@ -53,7 +53,7 @@ public:
btDiscreteDynamicsWorld* getPhysics() const {return m_world;} btDiscreteDynamicsWorld* getPhysics() const {return m_world;}
SparrowShell* getShell() const {return m_sparrowshell;} SparrowShell* getShell() const {return m_sparrowshell;}
PhysicsDebugNode* getPhysicsDebug() const {return m_physicsDebugNode;} PhysicsDebugNode* getPhysicsDebug() const {return m_physicsDebugNode;}
Editor* getGuiTools() const {return m_editor;} Editor* getEditor() const {return m_editor;}
LoadingThread* getLoadingThread() const {return m_loadingThread;} LoadingThread* getLoadingThread() const {return m_loadingThread;}
SceneTree* getScene() const; SceneTree* getScene() const;

View File

@ -19,10 +19,11 @@ TextInputNode::TextInputNode(glm::vec2 dimension):
m_cursor_mesh(nullptr), m_cursor_mesh(nullptr),
m_cursor_pos(0), m_cursor_pos(0),
m_cursor_pos_updated(false), m_cursor_pos_updated(false),
m_move_cursor_left(NO_ACTION),
m_move_cursor_right(NO_ACTION),
m_callback(nullptr), m_callback(nullptr),
m_tab_callback(nullptr) m_tab_callback(nullptr),
m_history(std::vector<std::string>()),
m_history_pos(0),
m_inputActions({NO_ACTION, NO_ACTION, NO_ACTION, NO_ACTION})
{ {
// Font *shellfont = RESOURCE_GET(Font,"shellfont"); // Font *shellfont = RESOURCE_GET(Font,"shellfont");
Mesh* mesh = new Mesh(); Mesh* mesh = new Mesh();
@ -44,18 +45,46 @@ void TextInputNode::update()
auto input = getEngine().getInput(); auto input = getEngine().getInput();
for(auto action : input->getActions()){ 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){ if (m_cursor_pos > 0){
m_cursor_pos--; m_cursor_pos--;
m_cursor_pos_updated=true; 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()){ if(m_cursor_pos < m_text.length()){
m_cursor_pos++; m_cursor_pos++;
m_cursor_pos_updated=true; 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++){ for(unsigned int i = 0 ; i < text.length() ; i++){
@ -150,3 +179,18 @@ std::string TextInputNode::getText()
return m_text; 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;
}

View File

@ -7,6 +7,15 @@
#include "scene/textnode.h" #include "scene/textnode.h"
#include "scene/gui/callback.h" #include "scene/gui/callback.h"
/*
struct TextInputAction{
int cursor_left;
int cursor_right;
int history_next;
int history_previous;
};
*/
class TextInputNode : public GUINode class TextInputNode : public GUINode
{ {
glm::vec2 m_dimension; glm::vec2 m_dimension;
@ -22,12 +31,16 @@ class TextInputNode : public GUINode
unsigned int m_cursor_pos; unsigned int m_cursor_pos;
bool m_cursor_pos_updated; bool m_cursor_pos_updated;
int m_move_cursor_left;
int m_move_cursor_right;
CallBack* m_callback; CallBack* m_callback;
CallBack* m_tab_callback; CallBack* m_tab_callback;
std::vector<std::string> m_history;
unsigned int m_history_pos;
std::vector<int> m_inputActions;
enum TextInputAction {MOVE_CURSOR_LEFT,MOVE_CURSOR_RIGHT,HISTORY_PREVIOUS,HISTORY_NEXT};
public: public:
TextInputNode(glm::vec2 dimension); TextInputNode(glm::vec2 dimension);
void update(); void update();
@ -41,9 +54,10 @@ public:
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 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 setInputs(int cursor_left, int cursor_right, int history_up, int history_down);
void clearText(){m_text.clear();}
void clearText();
}; };
#endif // TEXTINPUTNODE_H #endif // TEXTINPUTNODE_H

View File

@ -99,17 +99,17 @@ void ScriptNode::testfunc(int i, float x=0.f,float y=0.f, float z=0.f){
} }
void ScriptNode::picker(){ void ScriptNode::picker(){
this->getEngine().getGuiTools()->togglePicker(); this->getEngine().getEditor()->togglePicker();
} }
void ScriptNode::materialEditor(){ void ScriptNode::materialEditor(){
this->getEngine().getGuiTools()->toggleMaterialEditor(); this->getEngine().getEditor()->toggleMaterialEditor();
} }
void ScriptNode::rendering(){ void ScriptNode::rendering(){
this->getEngine().getGuiTools()->toggleRenderingPipelineGui(); this->getEngine().getEditor()->toggleRenderingPipelineGui();
} }
void ScriptNode::resourcePackEditor(){ void ScriptNode::resourcePackEditor(){
this->getEngine().getGuiTools()->toggleResourcePackGui(); this->getEngine().getEditor()->toggleResourcePackGui();
} }

View File

@ -24,8 +24,7 @@ const float SparrowShell::DEFAULT_FONT_SIZE = 16.f;
SparrowShell::SparrowShell(sf::Window* window): SparrowShell::SparrowShell(sf::Window* window):
m_buffer(new ShellBuffer(BUFFER_MAX_LENGTH)), m_buffer(new ShellBuffer(BUFFER_MAX_LENGTH)),
m_text_color(glm::vec3(0.7,1,0.3)), m_text_color(glm::vec3(0.7,1,0.3))
m_inputActions({NO_ACTION, NO_ACTION, NO_ACTION, NO_ACTION})
{ {
sf::Vector2u size = window->getSize(); sf::Vector2u size = window->getSize();
m_dimension = glm::ivec2(size.x,DEFAULT_FONT_SIZE*(BUFFER_DISPLAYED_LINES+1)); 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(){ void SparrowShell::AutocompletionCallBack::exec(){
std::string text = m_text_input_node->getText(); std::string text = m_text_input_node->getText();
std::vector<std::string> result = m_shell->m_script->possibleCompletion(text); std::vector<std::string> 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 = ""; std::string output = "";
for(std::string& fun : result) for(std::string& fun : results)
output+=fun+" "; output+=fun+" ";
m_shell->out(output,glm::vec3(1,1,0)); 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){ void SparrowShell::setInputs(int cursor_left, int cursor_right, int history_up, int history_down){
m_inputActions[MOVE_CURSOR_LEFT] = cursor_left; m_input_node->setInputs(cursor_left,cursor_right,history_up,history_down);
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);
} }
void SparrowShell::toggleShell() void SparrowShell::toggleShell()

View File

@ -60,9 +60,9 @@ private:
int m_move_cursor_right; int m_move_cursor_right;
std::string m_previous_context; std::string m_previous_context;
std::vector<int> m_inputActions; // std::vector<int> 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: public:
static const unsigned int BUFFER_MAX_LENGTH; static const unsigned int BUFFER_MAX_LENGTH;

View File

@ -64,7 +64,7 @@ void ScenePicker::update()
ImGui::End(); ImGui::End();
if(!isEnabled) if(!isEnabled)
getEngine().getGuiTools()->togglePicker(); getEngine().getEditor()->togglePicker();
} }
void ScenePicker::pick() void ScenePicker::pick()