Skip to content

Commit

Permalink
* ADD:[LE] Фичи для лог окна
Browse files Browse the repository at this point in the history
  • Loading branch information
BearIvan committed Jul 2, 2022
1 parent e085de1 commit ab5b097
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 60 deletions.
25 changes: 17 additions & 8 deletions Source/Editors/XrECore/Editor/ELog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@
void ELogCallback(LPCSTR txt)
{
if (0 == txt[0]) return;
bool bDlg = ('#' == txt[0]) || ((0 != txt[1]) && ('#' == txt[1]));
TMsgDlgType mt = ('!' == txt[0]) || ((0 != txt[1]) && ('!' == txt[1])) ? mtError : mtInformation;
if (('!' == txt[0]) || ('#' == txt[0])) txt++;
if (('!' == txt[0]) || ('#' == txt[0])) txt++;
if (bDlg) UILogForm::AddDlgMessage(mt, txt);
else UILogForm::AddMessage(mt, txt);
TMsgDlgType mt = TMsgDlgType::mtCustom;
if (strncmp(txt, "! ", 2) == 0)
{
mt = mtError;
}
if (strncmp(txt, "~ ", 2) == 0)
{
mt = mtConfirmation;
}
if (strncmp(txt, "* ", 2) == 0)
{
mt = mtInformation;
}

UILogForm::AddMessage(txt);
if(UI)
UI->WriteConsole(mt, txt);
UI->WriteConsole(mt, txt);

}

Expand Down Expand Up @@ -200,7 +209,7 @@ void CLog::Msg(TMsgDlgType mt, LPCSTR _Format, ...)
vsprintf( buf, _Format, l );

#if 1
UILogForm::AddMessage(mt,xr_string(buf));
UILogForm::AddMessage(xr_string(buf));
#endif
#ifdef _MAX_EXPORT
EConsole.print(mt,buf);
Expand Down
92 changes: 47 additions & 45 deletions Source/Editors/XrECore/Editor/UILogForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
#include "ELog.h"
#include "UILogForm.h"
#include "..\XrCore\os_clipboard.h"
#include "..\XrEngine\XR_IOConsole.h"
#define MSG_ERROR 0x00C4C4FF
#define MSG_INFO 0x00E6FFE7
#define MSG_CONF 0x00FFE6E7
#define MSG_DEF 0x00E8E8E8
bool UILogForm::bAutoScroll = true;
bool UILogForm::bOnlyError = false;
string_path UILogForm::m_Filter="";
string_path UILogForm::m_Exec="";
xr_vector<xr_string>* UILogForm::List = nullptr;
extern bool bAllowLogCommands;
void UILogForm::AddMessage(TMsgDlgType mt, const xr_string& msg)
void UILogForm::AddMessage( const xr_string& msg)
{
xr_string M;
for (int i = 0; i < msg.size(); i++)
Expand All @@ -19,22 +21,10 @@ void UILogForm::AddMessage(TMsgDlgType mt, const xr_string& msg)
if (msg[i] == '\n') M += " ";
else M += msg[i];
}
switch (mt)
{
case mtError:
M.insert(0, "###");
break;
case mtConfirmation:
M.insert(0, "##@");
break;
}

GetList()->push_back(M);
}

void UILogForm::AddDlgMessage(TMsgDlgType mt, const xr_string& msg)
{
GetList()->push_back(msg);
}

void UILogForm::Show()
{
Expand All @@ -48,6 +38,7 @@ void UILogForm::Hide()

void UILogForm::Update()
{
static bool FistRun = false;
if (bAllowLogCommands)
{
bool NeedCopy = false;
Expand All @@ -70,56 +61,67 @@ void UILogForm::Update()
}ImGui::SameLine();
ImGui::Checkbox("Auto Scroll", &bAutoScroll);
ImGui::SameLine();
ImGui::Checkbox("Only Error", &bOnlyError);
ImGui::InputText("Filter", m_Filter, sizeof(m_Filter));;


ImGui::Spacing();
if (ImGui::BeginChild("Log",ImVec2(0,0),true))
if (ImGui::BeginChild("Log",ImVec2(0, -ImGui::GetFrameHeightWithSpacing()),true))
{
xr_string CopyLog;
for (int i = 0; i < GetList()->size(); i++)
{
if (bOnlyError)

ImVec4 Color = { 1,1,1,1 };
const char* Str = GetList()->at(i).c_str();
if (m_Filter[0] && strstr(Str, m_Filter)==0)
{
const char* Str = GetList()->at(i).c_str();
if (strncmp(Str, "###", 3) == 0)
{
Str += 3;
ImGui::Text( Str);
if(NeedCopy)
CopyLog.append(Str).append("\r\n");
}
continue;
}
else
if (strncmp(Str, "! ", 2) == 0)
{
ImVec4 Color = { 1,1,1,1 };
const char* Str = GetList()->at(i).c_str();
if (strncmp(Str, "###", 3) == 0)
{
Color = { 1,0,0,1 };
Str += 3;
}
else if (strncmp(Str, "##@", 3) == 0)
{
Color = { 1,1,0,1 };
Str += 3;
}

ImGui::TextColored(Color, Str);
if (NeedCopy)
CopyLog.append(Str).append("\r\n");
Color = { 1,0,0,1 };
}
if (strncmp(Str, "~ ", 2) == 0)
{
Color = { 1,1,0,1 };
}
if (strncmp(Str, "* ", 2) == 0)
{
Color = { 0.5,0.5,0.5,1 };
}

ImGui::TextColored(Color, Str);
if (NeedCopy)
CopyLog.append(Str).append("\r\n");


}

if (NeedCopy)
{
os_clipboard::copy_to_clipboard(CopyLog.c_str());
}
if (bAutoScroll)ImGui::SetScrollHereY();

if (bAutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()|| FistRun==false)ImGui::SetScrollHereY();

FistRun = true;
}
ImGui::EndChild();
ImGuiInputTextFlags input_text_flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory;
if (ImGui::InputText("Exec", m_Exec, IM_ARRAYSIZE(m_Exec), input_text_flags))
{
if (m_Exec[0])
{
Msg("~ Exec %s", m_Exec);
Console->Execute(m_Exec);
}

}
ImGui::End();
}
else
{
FistRun = false;
}
}

void UILogForm::Destroy()
Expand Down
8 changes: 3 additions & 5 deletions Source/Editors/XrECore/Editor/UILogForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
class UILogForm
{
public:
static void AddMessage(TMsgDlgType mt, const xr_string& msg);
static void AddMessage(const xr_string& msg) { AddMessage(mtCustom, msg); }
static void AddDlgMessage(TMsgDlgType mt, const xr_string& msg);
static void AddDlgMessage(const xr_string& msg) { AddDlgMessage(mtCustom, msg); }
static void AddMessage( const xr_string& msg);
static void Show();
static void Hide();
static void Update();
Expand All @@ -19,7 +16,8 @@ class UILogForm
static xr_vector<xr_string>*List;
static xr_vector<xr_string>* GetList();
static bool bAutoScroll;
static bool bOnlyError;
static string_path m_Filter;
static string_path m_Exec;
};
//---------------------------------------------------------------------------
#endif
4 changes: 2 additions & 2 deletions Source/Editors/XrECore/Editor/UI_MainCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ CCommandVar ExecCommand (u32 cmd, CCommandVar p1, CCommandVar p2)
xr_string sp2 = p2.IsString()?xr_string(p2):xr_string("");
if (p1.IsString()) sp1 = ((sp1.find("\n")==sp1.npos)&&(sp1.find("\r")==sp1.npos))?sp1:xr_string("...");
if (p2.IsString()) sp2 = ((sp2.find("\n")==sp2.npos)&&(sp2.find("\r")==sp2.npos))?sp2:xr_string("...");
if (p1.IsString()&&p2.IsString()) Msg("%s%s (\"%s\",\"%s\")", level,CMD->Name(),sp1.c_str(),sp2.c_str());
/* if (p1.IsString() && p2.IsString()) Msg("%s%s (\"%s\",\"%s\")", level, CMD->Name(), sp1.c_str(), sp2.c_str());
else if (p1.IsInteger()&&p2.IsInteger())Msg("%s%s (%d,%d)", level,CMD->Name(),u32(p1),u32(p2));
else if (p1.IsInteger()&&p2.IsString()) Msg("%s%s (%d,\"%s\")", level,CMD->Name(),u32(p1),sp2.c_str());
else if (p1.IsString()&&p2.IsInteger()) Msg("%s%s (\"%s\",%d)", level,CMD->Name(),sp1.c_str(),u32(p2));
else if (p1.IsString()&&p2.IsInteger()) Msg("%s%s (\"%s\",%d)", level,CMD->Name(),sp1.c_str(),u32(p2));*/
}
exec_level++;
res = CMD->command(p1,p2);
Expand Down

0 comments on commit ab5b097

Please sign in to comment.