Unify input behind Engine::Input facade; fix Ctrl+P and Pause button
New Engine/Core/Input.h/.cpp: static input facade with a Key/MouseButton enum (values map to GLFW key codes internally) so scripts and game logic no longer touch GLFW directly - window backend becomes swappable and the facade is the surface to expose when embedding scripting later. Wired up in Application's constructor; Camera (editor camera WASD/RMB/MMB), the WASDMove script and SandboxApp key handling now query Input only. Ctrl+P hotkey fix: the !m_Playing guard made the hotkey dead exactly when it was needed - after pressing Play. Now toggles both ways. Toolbar Pause button now reads "Resume" while paused (tooltip follows).
This commit is contained in:
@@ -26,8 +26,6 @@
|
||||
#include <imgui_internal.h> // DockBuilder*(内部 API)
|
||||
#include <ImGuizmo.h>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
@@ -283,8 +281,9 @@ void Editor::DrawMenuBar()
|
||||
void Editor::DrawToolbar()
|
||||
{
|
||||
const ImGuiIO& io = ImGui::GetIO();
|
||||
// Ctrl+P:文本输入中(改名/路径框)不触发,防打字误切 PIE
|
||||
if (!m_Playing && io.KeyCtrl && !io.WantTextInput &&
|
||||
// Ctrl+P 全局热键:编辑态进 PIE,运行态停回编辑器(双向)。
|
||||
// 文本输入中(改名/路径框)不触发,防打字误切
|
||||
if (io.KeyCtrl && !io.WantTextInput &&
|
||||
ImGui::IsKeyPressed(ImGuiKey_P, false))
|
||||
{
|
||||
TogglePlay();
|
||||
@@ -293,12 +292,14 @@ void Editor::DrawToolbar()
|
||||
// 按钮加大触感(工具栏行高 = 一个按钮高;DockSpace avail 自适应)
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(12.0f, 4.0f));
|
||||
const ImGuiStyle& st = ImGui::GetStyle();
|
||||
const char* pauseLabel = m_Paused ? "Resume" : "Pause";
|
||||
|
||||
// Play 组宽度 → 水平居中(编辑态 1 钮 / 运行态 2 钮)
|
||||
float groupW = 0.0f;
|
||||
if (m_Playing)
|
||||
{
|
||||
groupW = ImGui::CalcTextSize("Pause").x + ImGui::CalcTextSize("Stop").x +
|
||||
groupW = ImGui::CalcTextSize(pauseLabel).x +
|
||||
ImGui::CalcTextSize("Stop").x +
|
||||
4.0f * st.FramePadding.x + st.ItemSpacing.x;
|
||||
}
|
||||
else
|
||||
@@ -309,7 +310,7 @@ void Editor::DrawToolbar()
|
||||
|
||||
if (m_Playing)
|
||||
{
|
||||
// Pause:暂停中亮黄常驻(UE 按下态),运行中暗黄
|
||||
// Pause/Resume:暂停中亮黄常驻(UE 按下态),运行中暗黄
|
||||
ImGui::PushStyleColor(ImGuiCol_Button,
|
||||
m_Paused ? ImVec4(0.85f, 0.62f, 0.12f, 1.0f)
|
||||
: ImVec4(0.55f, 0.42f, 0.10f, 1.0f));
|
||||
@@ -318,7 +319,7 @@ void Editor::DrawToolbar()
|
||||
: ImVec4(0.65f, 0.50f, 0.14f, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive,
|
||||
ImVec4(0.95f, 0.76f, 0.24f, 1.0f));
|
||||
if (ImGui::Button("Pause"))
|
||||
if (ImGui::Button(pauseLabel))
|
||||
{
|
||||
TogglePause();
|
||||
}
|
||||
|
||||
+5
-4
@@ -24,8 +24,8 @@
|
||||
#include <Engine/Renderer/Renderer.h>
|
||||
#include <Engine/Renderer/EditorCamera.h>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <Engine/Core/Input.h>
|
||||
|
||||
#include "Editor.h"
|
||||
#include "EditorContext.h"
|
||||
|
||||
@@ -94,11 +94,12 @@ namespace
|
||||
|
||||
void OnKeyPress(const Event& event) override
|
||||
{
|
||||
if (event.key == GLFW_KEY_GRAVE_ACCENT)
|
||||
// 键码统一走 Input::Key(App 层零 GLFW 依赖)
|
||||
if (event.key == static_cast<int>(Input::Key::GraveAccent))
|
||||
{
|
||||
SetImGuiEnabled(!GetImGuiEnabled());
|
||||
}
|
||||
if (event.key == GLFW_KEY_F1)
|
||||
if (event.key == static_cast<int>(Input::Key::F1))
|
||||
{
|
||||
STATS.PrintComparison();
|
||||
}
|
||||
|
||||
@@ -12,15 +12,16 @@
|
||||
|
||||
#include <Engine/Scripting/Script.h>
|
||||
#include <Engine/Core/Application.h>
|
||||
#include <Engine/Core/Window.h>
|
||||
#include <Engine/Core/Input.h>
|
||||
#include <Engine/Renderer/Renderer.h>
|
||||
#include <Engine/Renderer/EditorCamera.h>
|
||||
#include <Engine/Physics/PhysicsWorld.h>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
using namespace Engine; // Input 门面(统一输入入口)
|
||||
|
||||
namespace {
|
||||
|
||||
class WASDMove final : public Engine::Scripting::ScriptBehavior {
|
||||
@@ -29,7 +30,8 @@ namespace {
|
||||
|
||||
void OnUpdate(float dt) override {
|
||||
// 位移方向 = 视线水平投影(W 前进 / A 左 / D 右),UE Scene
|
||||
// view 移动惯例;Y 锁 0(升降/跳跃归物理或将来扩展)
|
||||
// view 移动惯例;Y 锁 0(升降/跳跃归物理或将来扩展)。
|
||||
// 键鼠查询统一走 Input 门面(脚本层零 GLFW 依赖)
|
||||
const glm::quat cq = App().GetRenderer()
|
||||
.GetEditorCamera()
|
||||
.GetTransform()
|
||||
@@ -37,12 +39,11 @@ namespace {
|
||||
const glm::vec3 fwd = cq * glm::vec3(0.0f, 0.0f, -1.0f);
|
||||
const glm::vec3 right = cq * glm::vec3(1.0f, 0.0f, 0.0f);
|
||||
|
||||
auto& win = App().GetWindow();
|
||||
glm::vec3 move(0.0f);
|
||||
if (win.IsKeyPressed(GLFW_KEY_W)) move += fwd;
|
||||
if (win.IsKeyPressed(GLFW_KEY_S)) move -= fwd;
|
||||
if (win.IsKeyPressed(GLFW_KEY_D)) move += right;
|
||||
if (win.IsKeyPressed(GLFW_KEY_A)) move -= right;
|
||||
if (Input::IsKeyDown(Input::Key::W)) move += fwd;
|
||||
if (Input::IsKeyDown(Input::Key::S)) move -= fwd;
|
||||
if (Input::IsKeyDown(Input::Key::D)) move += right;
|
||||
if (Input::IsKeyDown(Input::Key::A)) move -= right;
|
||||
move.y = 0.0f;
|
||||
if (glm::length(move) > 1e-4f) {
|
||||
move = glm::normalize(move);
|
||||
|
||||
Reference in New Issue
Block a user