LuaConsole now retains input focus after pressing enter. But must press escape to use command recall.

Gui_Panel_Refactor
Joeyrp 4 years ago
parent 6a03409ae3
commit 7628794d10

@ -308,7 +308,10 @@ namespace lunarium
{
// Logger::Log(LogCategory::CORE, LogLevel::INFO, "New LUA command: %s", command.c_str());
OpRes result = ScriptManager::RunScript(command.c_str());
// NOTE: Ignoring script result
if (Failed(result))
{
Logger::Log(LogCategory::CORE, LogLevel::INFO_VERBOSE, result.Description.c_str());
}
}
}

@ -125,7 +125,7 @@ namespace lunarium
ImVec4 color(1.0f, 1.0f, 1.0f, 1.0f);
if (mMsgHistory[i].find("WANRING") != std::string::npos)
if (mMsgHistory[i].find("WARNING") != std::string::npos)
{
color = ImVec4(0.75f, 0.75f, 0.0f, 1.0f);
}
@ -135,6 +135,11 @@ namespace lunarium
color = ImVec4(1.0f, 0.0f, 0.0f, 1.0f);
}
if (mMsgHistory[i].find("[LUA]") != std::string::npos)
{
color = ImVec4(0.25f, 0.5f, 0.95f, 1.0f);
}
const char* msg = mMsgHistory[i].c_str();
int len = strlen(msg);

@ -19,7 +19,7 @@ namespace lunarium
{
LuaConsole* LuaConsole::mpInstance = nullptr;
LuaConsole::LuaConsole()
: mbShow(false), mbStickToWindow(true), mbNewCommand(false)
: mbShow(false), mbStickToWindow(true), mbNewCommand(false), mRecalledCommand(-1)
{
memset(mBuffer, 0, LUA_CON_BUFFER_SIZE);
}
@ -55,11 +55,13 @@ namespace lunarium
Core::MainWindow().GetPosition(&x, &y);
int width, height;
Core::MainWindow().GetFramebufferSize(&width, &height);
float myHeight = height / 3.0f;
if (mbStickToWindow)
{
ImGui::SetNextWindowPos(ImVec2(x, y), ImGuiCond_Always);
ImGui::SetNextWindowSize(ImVec2(width / 3.0f, height / 3.0f), ImGuiCond_Always);
ImGui::SetNextWindowSize(ImVec2(width / 3.0f, myHeight + 20), ImGuiCond_Always);
if (!ImGui::Begin("LUA Console", &mbShow, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove
| ImGuiWindowFlags_NoSavedSettings))
{
@ -70,7 +72,7 @@ namespace lunarium
else
{
ImGui::SetNextWindowPos(ImVec2(x, y), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(width / 3.0f, height / 3.0f), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(width / 3.0f, myHeight + 20), ImGuiCond_FirstUseEver);
if (!ImGui::Begin("LUA Console", &mbShow))
{
ImGui::End();
@ -79,7 +81,7 @@ namespace lunarium
}
ImGui::BeginChild("history", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
ImGui::BeginChild("history", ImVec2(0, myHeight - 45), false, ImGuiWindowFlags_AlwaysVerticalScrollbar);
for (int i = 0; i < mCommandHistory.size(); i++)
{
const char* msg = mCommandHistory[i].c_str();
@ -88,20 +90,62 @@ namespace lunarium
ImGui::TextUnformatted(msg);
}
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
ImGui::SetScrollHereY(1.0f);
ImGui::EndChild();
ImGui::Separator();
ImGui::InputText("command", mBuffer, LUA_CON_BUFFER_SIZE);
ImGui::BeginChild("console", ImVec2(0, 20));
if (ImGui::InputText("command", mBuffer, LUA_CON_BUFFER_SIZE, ImGuiInputTextFlags_EnterReturnsTrue))
{
mCommandHistory.push_back(mBuffer);
memset(mBuffer, 0, LUA_CON_BUFFER_SIZE);
mbNewCommand = true;
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
ImGui::SetScrollHereY(1.0f);
// Doesn't keep the focus on the input text field
// Might be another way to do it now
ImGui::SetKeyboardFocusHere(-1);
}
ImGui::EndChild();
ImGui::End();
if (Core::Input().IsKeyPressed(KeyCode::RETURN, true) && strlen(mBuffer) > 1)
// if (Core::Input().IsKeyPressed(KeyCode::RETURN, true) && strlen(mBuffer) > 1)
// {
// mCommandHistory.push_back(mBuffer);
// memset(mBuffer, 0, LUA_CON_BUFFER_SIZE);
// mbNewCommand = true;
// // Doesn't keep the focus on the input text field
// // Might be another way to do it now
// ImGui::SetKeyboardFocusHere(-1);
// }
bool changeCommand = false;
if (Core::Input().IsKeyPressed(KeyCode::UP, true))
{
mRecalledCommand--;
if (mRecalledCommand <= -1)
{
mRecalledCommand = mCommandHistory.size() - 1;
}
changeCommand = true;
}
if (Core::Input().IsKeyPressed(KeyCode::DOWN, true))
{
mRecalledCommand++;
if (mRecalledCommand >= mCommandHistory.size())
{
mRecalledCommand = 0;
}
changeCommand = true;
}
if (changeCommand)
{
mCommandHistory.push_back(mBuffer);
memset(mBuffer, 0, LUA_CON_BUFFER_SIZE);
mbNewCommand = true;
strcpy(mBuffer, mCommandHistory[mRecalledCommand].c_str());
}
}

@ -42,6 +42,7 @@ namespace lunarium
char mBuffer[LUA_CON_BUFFER_SIZE];
std::vector<std::string> mCommandHistory;
bool mbNewCommand;
int mRecalledCommand;
private:
LuaConsole();

@ -10,6 +10,7 @@
#include "scriptManager.h"
#include <utils/logger.h>
#include <sstream>
namespace lunarium
{
@ -55,8 +56,10 @@ namespace lunarium
if (!result.valid())
{
sol::error err = result;
Logger::Log(mpInstance->mCat, LogLevel::WARNING, "LUA script has errors: %s", err.what());
return OpRes::Fail(err.what());
Logger::Log(mpInstance->mCat, LogLevel::WARNING, "LUA script has errors");
std::ostringstream oss;
oss << "LUA code has error. CODE:\n" << code << "\nEND CODE -- ERROR: " << err.what();
return OpRes::Fail(oss.str().c_str());
}
return OpRes::OK();

Loading…
Cancel
Save