浏览代码

Lesson 22.4

Godzil 3 年之前
父节点
当前提交
57060a06c9
共有 2 个文件被更改,包括 53 次插入4 次删除
  1. 3 4
      source/Game.cpp
  2. 50 0
      source/include/Systems/RenderGUI.h

+ 3 - 4
source/Game.cpp

@@ -45,6 +45,7 @@
 #include <Systems/ProjectileLifeCycle.h>
 #include <Systems/RenderText.h>
 #include <Systems/RenderHealth.h>
+#include <Systems/RenderGUI.h>
 
 uint32_t Game::windowsWidth = 0;
 uint32_t Game::windowsHeight = 0;
@@ -167,6 +168,7 @@ void Game::LoadLevel(int level)
     this->registry->addSystem<ProjectileLifeCycleSystem>();
     this->registry->addSystem<RenderTextSystem>();
     this->registry->addSystem<RenderHealthSystem>();
+    this->registry->addSystem<RenderGUISystem>();
 
     this->assetStore->addTexture(this->renderer, "tank-image", "assets/images/tank-panther-right.png");
     this->assetStore->addTexture(this->renderer, "truck-image", "assets/images/truck-ford-right.png");
@@ -347,10 +349,7 @@ void Game::Render()
     {
         registry->getSystem<CollisionSystem>().debugRender(this->renderer, this->camera);
 
-        ImGui::NewFrame();
-        ImGui::ShowDemoWindow();
-        ImGui::Render();
-        ImGuiSDL::Render(ImGui::GetDrawData());
+        registry->getSystem<RenderGUISystem>().update();
     }
 
     SDL_RenderPresent(this->renderer);

+ 50 - 0
source/include/Systems/RenderGUI.h

@@ -0,0 +1,50 @@
+/*
+ * 2D Game Engine 
+ * RenderGUI.h: 
+ * Based on pikuma.com 2D game engine in C++ and Lua course
+ * Copyright (c) 2021 986-Studio. All rights reserved.
+ *
+ * Created by Manoël Trapier on 28/02/2021.
+ */
+
+#ifndef IMGUI_SOURCE_INCLUDE_SYSTEMS_RENDERGUI_H
+#define IMGUI_SOURCE_INCLUDE_SYSTEMS_RENDERGUI_H
+
+#include <SDL.h>
+
+#include <imgui.h>
+#include <imgui_sdl.h>
+
+#include <AssetStore.h>
+#include <ECS.h>
+#include <Logger.h>
+
+class RenderGUISystem : public System
+{
+public:
+    RenderGUISystem() = default;
+
+    void update()
+    {
+        ImGui::NewFrame();
+
+        if (ImGui::Begin("Spawn enemies"))
+        {
+            ImGui::Text("Press that button to spawn an enemy");
+            ImGui::NewLine();
+            ImGui::Button("Hello");
+            ImGui::NewLine();
+            ImGui::NewLine();
+            ImGui::NewLine();
+            ImGui::NewLine();
+            ImGui::NewLine();
+            ImGui::Button("World");
+            ImGui::End();
+        }
+
+        ImGui::Render();
+        ImGuiSDL::Render(ImGui::GetDrawData());
+    }
+};
+
+#endif /* IMGUI_SOURCE_INCLUDE_SYSTEMS_RENDERGUI_H */