载入中...
搜索中...
未找到
ImGuiHostPanels.cpp
浏览该文件的文档.
4
5#include <imgui.h>
6#include <imgui_internal.h>
7
8// Desktop-only host registration: draws the DevTools AI / console / stats ImGui windows.
9// Kept outside EVDevTools (which avoids imgui.h inlines → MSVC 65535 export
10// bloat); compiled into the `eve` host executable, where imgui is linked.
11//
12// The panels are rendered between `ui.beginFrameAndRender()` and
13// `gfx.present()` (load.nut calls eve.dev.ai.draw() / eve.dev.console.draw()).
14
15#if !defined(EVENGINE_ANDROID) && !defined(EVENGINE_IOS) && !defined(EVENGINE_WEBGPU)
16
17namespace eve::dev {
18namespace {
19
20void drawAiWindow(AiPanel& panel) {
21 // Games without an ImGui UI pass still run DevTools/MCP. In that case
22 // load.nut invokes this hook after the game render, but ImGui::Begin is
23 // invalid until UI::beginFrameAndRender has called ImGui::NewFrame.
24 if (!panel.isVisible() || !GImGui || !GImGui->WithinFrameScope) return;
25 bool visible = panel.isVisible();
26 if (ImGui::Begin("AI / MCP", &visible, ImGuiWindowFlags_AlwaysAutoResize)) {
27 ImGui::TextUnformatted(panel.statusLine().c_str());
28 ImGui::Separator();
29 const auto log = panel.recentLog(64);
30 if (ImGui::BeginChild("ai_log", ImVec2(480, 260), true)) {
31 for (const auto& e : log) {
32 ImGui::TextWrapped("[%s] %s | %s", e.timestamp.c_str(), e.kind.c_str(),
33 e.title.c_str());
34 if (!e.detail.empty()) ImGui::TextWrapped(" %s", e.detail.c_str());
35 }
36 if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
37 ImGui::SetScrollHereY(1.0f);
38 }
39 ImGui::EndChild();
40 if (ImGui::Button("Clear")) panel.clearLog();
41 ImGui::SameLine();
42 if (ImGui::Button("Hide")) panel.setVisible(false);
43 }
44 ImGui::End();
45 if (!visible) panel.setVisible(false);
46}
47
48// Draw the console: scrolling log + Squirrel REPL input line.
49void drawConsoleWindow(ConsolePanel& panel) {
50 if (!panel.isVisible() || !GImGui || !GImGui->WithinFrameScope) return;
51 bool visible = panel.isVisible();
52 if (ImGui::Begin("Console", &visible,
53 ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoScrollbar)) {
54 if (ImGui::BeginMenuBar()) {
55 if (ImGui::BeginMenu("Log")) {
56 if (ImGui::MenuItem("Clear")) panel.clear();
57 if (ImGui::MenuItem("Copy all"))
58 ImGui::SetClipboardText(panel.format(4096).c_str());
59 ImGui::EndMenu();
60 }
61 ImGui::EndMenuBar();
62 }
63
64 ImGui::BeginChild("console_log", ImVec2(0, ImGui::GetContentRegionAvail().y - 30),
65 true);
66 const auto lines = panel.recent(500);
67 for (const auto& l : lines) {
68 ImVec4 color = ImVec4(0.80f, 0.80f, 0.80f, 1.0f);
69 if (l.level == "error")
70 color = ImVec4(1.0f, 0.35f, 0.35f, 1.0f);
71 else if (l.level == "warn")
72 color = ImVec4(1.0f, 0.85f, 0.35f, 1.0f);
73 else if (l.level == "cmd" || l.level == "result")
74 color = ImVec4(0.45f, 0.80f, 1.0f, 1.0f);
75 ImGui::PushStyleColor(ImGuiCol_Text, color);
76 ImGui::TextUnformatted(("[" + l.timestamp + "] " + l.level + " | " + l.text).c_str());
77 ImGui::PopStyleColor();
78 }
79 if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) ImGui::SetScrollHereY(1.0f);
80 ImGui::EndChild();
81
82 static char input[512] = "";
83 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - 90);
84 const bool enter = ImGui::InputText("##repl", input, sizeof(input),
85 ImGuiInputTextFlags_EnterReturnsTrue);
86 ImGui::SameLine();
87 if (ImGui::Button("Run") || enter) {
88 std::string expr = input;
89 if (!expr.empty()) {
90 const std::string result = panel.eval(expr);
91 ImGui::SetClipboardText(result.c_str());
92 }
93 input[0] = '\0';
94 }
95 if (ImGui::Button("Hide")) panel.setVisible(false);
96 }
97 ImGui::End();
98 if (!visible) panel.setVisible(false);
99}
100
101void drawFrameStatsWindow(FrameStatsPanel& panel) {
102 if (!panel.isVisible() || !GImGui || !GImGui->WithinFrameScope) return;
103 bool visible = panel.isVisible();
104 ImGui::SetNextWindowBgAlpha(0.72f);
105 if (ImGui::Begin("Frame stats", &visible,
106 ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoFocusOnAppearing |
107 ImGuiWindowFlags_NoNav)) {
108 ImGui::TextUnformatted(panel.format().c_str());
109 if (ImGui::Button("Hide")) panel.setVisible(false);
110 }
111 ImGui::End();
112 if (!visible) panel.setVisible(false);
113}
114
115struct HostPanels {
116 HostPanels() {
117 AiPanel::setImGuiDrawer(&drawAiWindow);
118 ConsolePanel::setImGuiDrawer(&drawConsoleWindow);
119 FrameStatsPanel::setImGuiDrawer(&drawFrameStatsWindow);
120 }
121};
122
123} // namespace
124} // namespace eve::dev
125
126static eve::dev::HostPanels gHostPanels;
127
128#endif
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
EvpackChunkInput input
Definition Evpack.cpp:170
bool visible
std::vector< std::string_view > lines
static void setImGuiDrawer(ImGuiDrawer fn)
Definition AiPanel.cpp:138
static void setImGuiDrawer(ImGuiDrawer fn)
static void setImGuiDrawer(ImGuiDrawer fn)
glm::vec4 color