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;}
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;

View File

@ -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<std::string>()),
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;
}

View File

@ -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<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:
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

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(){
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();
}

View File

@ -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<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 = "";
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()

View File

@ -60,9 +60,9 @@ private:
int m_move_cursor_right;
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:
static const unsigned int BUFFER_MAX_LENGTH;

View File

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