refactor: 将SceneView拆分为Scene和Game两个独立窗口
- 新增GameViewPanel作为独立窗口 - 移除SceneViewPanel中的TabBar - Scene和Game现在像Console/Project一样并排显示
This commit is contained in:
@@ -39,6 +39,7 @@ add_executable(${PROJECT_NAME} WIN32
|
||||
src/panels/MenuBar.cpp
|
||||
src/panels/HierarchyPanel.cpp
|
||||
src/panels/SceneViewPanel.cpp
|
||||
src/panels/GameViewPanel.cpp
|
||||
src/panels/InspectorPanel.cpp
|
||||
src/panels/ConsolePanel.cpp
|
||||
src/panels/ProjectPanel.cpp
|
||||
|
||||
@@ -47,6 +47,7 @@ bool Application::Initialize(HWND hwnd) {
|
||||
m_menuBar = std::make_unique<MenuBar>();
|
||||
m_hierarchyPanel = std::make_unique<HierarchyPanel>();
|
||||
m_sceneViewPanel = std::make_unique<SceneViewPanel>();
|
||||
m_gameViewPanel = std::make_unique<GameViewPanel>();
|
||||
m_inspectorPanel = std::make_unique<InspectorPanel>();
|
||||
m_consolePanel = std::make_unique<ConsolePanel>();
|
||||
m_projectPanel = std::make_unique<ProjectPanel>();
|
||||
@@ -277,6 +278,7 @@ void Application::SetupDockspace() {
|
||||
|
||||
ImGui::DockBuilderDockWindow("Hierarchy", dockLeft);
|
||||
ImGui::DockBuilderDockWindow("Scene", dockMain);
|
||||
ImGui::DockBuilderDockWindow("Game", dockMain);
|
||||
ImGui::DockBuilderDockWindow("Inspector", dockRight);
|
||||
ImGui::DockBuilderDockWindow("Console", dockBottom);
|
||||
ImGui::DockBuilderDockWindow("Project", dockBottom);
|
||||
@@ -292,6 +294,7 @@ void Application::RenderUI() {
|
||||
|
||||
m_hierarchyPanel->Render();
|
||||
m_sceneViewPanel->Render();
|
||||
m_gameViewPanel->Render();
|
||||
m_inspectorPanel->Render();
|
||||
m_consolePanel->Render();
|
||||
m_projectPanel->Render();
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "panels/MenuBar.h"
|
||||
#include "panels/HierarchyPanel.h"
|
||||
#include "panels/SceneViewPanel.h"
|
||||
#include "panels/GameViewPanel.h"
|
||||
#include "panels/InspectorPanel.h"
|
||||
#include "panels/ConsolePanel.h"
|
||||
#include "panels/ProjectPanel.h"
|
||||
@@ -55,6 +56,7 @@ private:
|
||||
std::unique_ptr<MenuBar> m_menuBar;
|
||||
std::unique_ptr<HierarchyPanel> m_hierarchyPanel;
|
||||
std::unique_ptr<SceneViewPanel> m_sceneViewPanel;
|
||||
std::unique_ptr<GameViewPanel> m_gameViewPanel;
|
||||
std::unique_ptr<InspectorPanel> m_inspectorPanel;
|
||||
std::unique_ptr<ConsolePanel> m_consolePanel;
|
||||
std::unique_ptr<ProjectPanel> m_projectPanel;
|
||||
|
||||
31
ui/src/panels/GameViewPanel.cpp
Normal file
31
ui/src/panels/GameViewPanel.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "GameViewPanel.h"
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
|
||||
namespace UI {
|
||||
|
||||
GameViewPanel::GameViewPanel() : Panel("Game") {}
|
||||
|
||||
void GameViewPanel::Render() {
|
||||
ImGui::Begin(m_name.c_str(), &m_isOpen, ImGuiWindowFlags_None);
|
||||
|
||||
RenderGameView();
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void GameViewPanel::RenderGameView() {
|
||||
ImVec2 canvasSize = ImGui::GetContentRegionAvail();
|
||||
ImDrawList* drawList = ImGui::GetWindowDrawList();
|
||||
ImVec2 canvasPos = ImGui::GetCursorScreenPos();
|
||||
|
||||
ImU32 bgColor = IM_COL32(20, 20, 25, 255);
|
||||
drawList->AddRectFilled(canvasPos, ImVec2(canvasPos.x + canvasSize.x, canvasPos.y + canvasSize.y), bgColor);
|
||||
|
||||
const char* text = "Game View (Press Play)";
|
||||
ImVec2 textSize = ImGui::CalcTextSize(text);
|
||||
ImVec2 textPos(canvasPos.x + (canvasSize.x - textSize.x) * 0.5f, canvasPos.y + (canvasSize.y - textSize.y) * 0.5f);
|
||||
drawList->AddText(textPos, IM_COL32(128, 128, 128, 255), text);
|
||||
}
|
||||
|
||||
}
|
||||
16
ui/src/panels/GameViewPanel.h
Normal file
16
ui/src/panels/GameViewPanel.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "Panel.h"
|
||||
|
||||
namespace UI {
|
||||
|
||||
class GameViewPanel : public Panel {
|
||||
public:
|
||||
GameViewPanel();
|
||||
void Render() override;
|
||||
|
||||
private:
|
||||
void RenderGameView();
|
||||
};
|
||||
|
||||
}
|
||||
@@ -9,38 +9,14 @@ SceneViewPanel::SceneViewPanel() : Panel("Scene") {}
|
||||
void SceneViewPanel::Render() {
|
||||
ImGui::Begin(m_name.c_str(), &m_isOpen, ImGuiWindowFlags_None);
|
||||
|
||||
if (ImGui::BeginTabBar("SceneGameTabs")) {
|
||||
if (ImGui::BeginTabItem("Scene")) {
|
||||
m_isSceneView = true;
|
||||
ImVec2 canvasSize = ImGui::GetContentRegionAvail();
|
||||
ImDrawList* drawList = ImGui::GetWindowDrawList();
|
||||
ImVec2 canvasPos = ImGui::GetCursorScreenPos();
|
||||
|
||||
ImU32 bgColor = IM_COL32(30, 30, 30, 255);
|
||||
drawList->AddRectFilled(canvasPos, ImVec2(canvasPos.x + canvasSize.x, canvasPos.y + canvasSize.y), bgColor);
|
||||
|
||||
RenderGrid();
|
||||
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (ImGui::BeginTabItem("Game")) {
|
||||
m_isSceneView = false;
|
||||
ImVec2 canvasSize = ImGui::GetContentRegionAvail();
|
||||
ImDrawList* drawList = ImGui::GetWindowDrawList();
|
||||
ImVec2 canvasPos = ImGui::GetCursorScreenPos();
|
||||
|
||||
ImU32 bgColor = IM_COL32(20, 20, 25, 255);
|
||||
drawList->AddRectFilled(canvasPos, ImVec2(canvasPos.x + canvasSize.x, canvasPos.y + canvasSize.y), bgColor);
|
||||
|
||||
const char* text = "Game View (Press Play)";
|
||||
ImVec2 textSize = ImGui::CalcTextSize(text);
|
||||
ImVec2 textPos(canvasPos.x + (canvasSize.x - textSize.x) * 0.5f, canvasPos.y + (canvasSize.y - textSize.y) * 0.5f);
|
||||
drawList->AddText(textPos, IM_COL32(128, 128, 128, 255), text);
|
||||
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
ImVec2 canvasSize = ImGui::GetContentRegionAvail();
|
||||
ImDrawList* drawList = ImGui::GetWindowDrawList();
|
||||
ImVec2 canvasPos = ImGui::GetCursorScreenPos();
|
||||
|
||||
ImU32 bgColor = IM_COL32(30, 30, 30, 255);
|
||||
drawList->AddRectFilled(canvasPos, ImVec2(canvasPos.x + canvasSize.x, canvasPos.y + canvasSize.y), bgColor);
|
||||
|
||||
RenderGrid();
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ public:
|
||||
void Render() override;
|
||||
|
||||
private:
|
||||
bool m_isSceneView = true;
|
||||
void RenderGrid();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user