|
|
|
@ -44,6 +44,42 @@ namespace lunarium
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return OpRes::OK();
|
|
|
|
return OpRes::OK();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LuaConsole::MyCallback(ImGuiInputTextCallbackData* data)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (data->EventFlag == ImGuiInputTextFlags_CallbackHistory)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bool changeCommand = false;
|
|
|
|
|
|
|
|
if (data->EventKey == ImGuiKey_UpArrow)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mpInstance->mRecalledCommand--;
|
|
|
|
|
|
|
|
if (mpInstance->mRecalledCommand <= -1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mpInstance->mRecalledCommand = mpInstance->mCommandHistory.size() - 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
changeCommand = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (data->EventKey == ImGuiKey_DownArrow)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mpInstance->mRecalledCommand++;
|
|
|
|
|
|
|
|
if (mpInstance->mRecalledCommand >= mpInstance->mCommandHistory.size())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mpInstance->mRecalledCommand = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
changeCommand = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (changeCommand)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
memset(mpInstance->mBuffer, 0, LUA_CON_BUFFER_SIZE);
|
|
|
|
|
|
|
|
strcpy(mpInstance->mBuffer, mpInstance->mCommandHistory[mpInstance->mRecalledCommand].c_str());
|
|
|
|
|
|
|
|
data->DeleteChars(0, data->BufTextLen);
|
|
|
|
|
|
|
|
data->InsertChars(0, mpInstance->mBuffer);
|
|
|
|
|
|
|
|
data->SelectAll();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaConsole::Show()
|
|
|
|
void LuaConsole::Show()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -51,6 +87,11 @@ namespace lunarium
|
|
|
|
if (!mbShow)
|
|
|
|
if (!mbShow)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Core::Input().IsKeyDown(KeyCode::ESCAPE, true))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mpInstance->mRecalledCommand = -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int x, y;
|
|
|
|
int x, y;
|
|
|
|
Core::MainWindow().GetPosition(&x, &y);
|
|
|
|
Core::MainWindow().GetPosition(&x, &y);
|
|
|
|
int width, height;
|
|
|
|
int width, height;
|
|
|
|
@ -86,8 +127,15 @@ namespace lunarium
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const char* msg = mCommandHistory[i].c_str();
|
|
|
|
const char* msg = mCommandHistory[i].c_str();
|
|
|
|
int len = strlen(msg);
|
|
|
|
int len = strlen(msg);
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::TextUnformatted(msg);
|
|
|
|
if (i == mRecalledCommand)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ImGui::TextColored(ImVec4(0.2f, 0.9f, 0.5f, 1.0f), msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ImGui::TextUnformatted(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
|
|
|
|
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
|
|
|
|
@ -96,7 +144,8 @@ namespace lunarium
|
|
|
|
ImGui::EndChild();
|
|
|
|
ImGui::EndChild();
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::BeginChild("console", ImVec2(0, 20));
|
|
|
|
ImGui::BeginChild("console", ImVec2(0, 20));
|
|
|
|
if (ImGui::InputText("command", mBuffer, LUA_CON_BUFFER_SIZE, ImGuiInputTextFlags_EnterReturnsTrue))
|
|
|
|
if (ImGui::InputText("command", mBuffer, LUA_CON_BUFFER_SIZE, ImGuiInputTextFlags_EnterReturnsTrue
|
|
|
|
|
|
|
|
| ImGuiInputTextFlags_CallbackHistory, LuaConsole::MyCallback))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mCommandHistory.push_back(mBuffer);
|
|
|
|
mCommandHistory.push_back(mBuffer);
|
|
|
|
memset(mBuffer, 0, LUA_CON_BUFFER_SIZE);
|
|
|
|
memset(mBuffer, 0, LUA_CON_BUFFER_SIZE);
|
|
|
|
@ -109,44 +158,6 @@ namespace lunarium
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
ImGui::EndChild();
|
|
|
|
ImGui::End();
|
|
|
|
ImGui::End();
|
|
|
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
memset(mBuffer, 0, LUA_CON_BUFFER_SIZE);
|
|
|
|
|
|
|
|
strcpy(mBuffer, mCommandHistory[mRecalledCommand].c_str());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LuaConsole::SetShow(bool show)
|
|
|
|
void LuaConsole::SetShow(bool show)
|
|
|
|
|