|
|
|
@ -19,7 +19,7 @@ namespace lunarium
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LuaConsole* LuaConsole::mpInstance = nullptr;
|
|
|
|
LuaConsole* LuaConsole::mpInstance = nullptr;
|
|
|
|
LuaConsole::LuaConsole()
|
|
|
|
LuaConsole::LuaConsole()
|
|
|
|
: mbShow(false), mbStickToWindow(true), mbNewCommand(false)
|
|
|
|
: mbShow(false), mbStickToWindow(true), mbNewCommand(false), mRecalledCommand(-1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
memset(mBuffer, 0, LUA_CON_BUFFER_SIZE);
|
|
|
|
memset(mBuffer, 0, LUA_CON_BUFFER_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -56,10 +56,12 @@ namespace lunarium
|
|
|
|
int width, height;
|
|
|
|
int width, height;
|
|
|
|
Core::MainWindow().GetFramebufferSize(&width, &height);
|
|
|
|
Core::MainWindow().GetFramebufferSize(&width, &height);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float myHeight = height / 3.0f;
|
|
|
|
|
|
|
|
|
|
|
|
if (mbStickToWindow)
|
|
|
|
if (mbStickToWindow)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ImGui::SetNextWindowPos(ImVec2(x, y), ImGuiCond_Always);
|
|
|
|
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
|
|
|
|
if (!ImGui::Begin("LUA Console", &mbShow, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove
|
|
|
|
| ImGuiWindowFlags_NoSavedSettings))
|
|
|
|
| ImGuiWindowFlags_NoSavedSettings))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -70,7 +72,7 @@ namespace lunarium
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ImGui::SetNextWindowPos(ImVec2(x, y), ImGuiCond_FirstUseEver);
|
|
|
|
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))
|
|
|
|
if (!ImGui::Begin("LUA Console", &mbShow))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ImGui::End();
|
|
|
|
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++)
|
|
|
|
for (int i = 0; i < mCommandHistory.size(); i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const char* msg = mCommandHistory[i].c_str();
|
|
|
|
const char* msg = mCommandHistory[i].c_str();
|
|
|
|
@ -88,20 +90,62 @@ namespace lunarium
|
|
|
|
ImGui::TextUnformatted(msg);
|
|
|
|
ImGui::TextUnformatted(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
|
|
|
|
|
|
|
|
ImGui::SetScrollHereY(1.0f);
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
ImGui::EndChild();
|
|
|
|
ImGui::Separator();
|
|
|
|
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())
|
|
|
|
// Doesn't keep the focus on the input text field
|
|
|
|
ImGui::SetScrollHereY(1.0f);
|
|
|
|
// Might be another way to do it now
|
|
|
|
|
|
|
|
ImGui::SetKeyboardFocusHere(-1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
ImGui::End();
|
|
|
|
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);
|
|
|
|
memset(mBuffer, 0, LUA_CON_BUFFER_SIZE);
|
|
|
|
mbNewCommand = true;
|
|
|
|
strcpy(mBuffer, mCommandHistory[mRecalledCommand].c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|