Browse Source

text typing

Kajetan Johannes Hammerle 3 years ago
parent
commit
31bf20a043
5 changed files with 21 additions and 10 deletions
  1. 11 5
      client/Game.cpp
  2. 5 2
      client/Game.h
  3. 3 2
      client/Main.cpp
  4. 1 1
      gaming-core
  5. 1 0
      meson.build

+ 11 - 5
client/Game.cpp

@@ -2,14 +2,17 @@
 #include "common/network/Packets.h"
 #include "gaming-core/utils/Utils.h"
 
-Game::Game(const Controller& controller, const Clock& fps, const Clock& tps,
-           RenderSettings& settings, const Size& size, Client& client)
-    : controller(controller), fps(fps), tps(tps), renderSettings(settings),
-      size(size), client(client), world(blockRegistry), worldRenderer(world),
-      connected(false) {
+Game::Game(TextInput& textInput, const Controller& controller, const Clock& fps,
+           const Clock& tps, RenderSettings& settings, const Size& size,
+           Client& client)
+    : textInput(textInput), controller(controller), fps(fps), tps(tps),
+      renderSettings(settings), size(size), client(client),
+      world(blockRegistry), worldRenderer(world), connected(false) {
     pos = Vector3(16.0f, 30.0f, -10.0f);
     rotation = Quaternion(Vector3(1.0f, 0.0f, 0.0f), 30) * rotation;
     rotation = Quaternion(Vector3(0.0f, 1.0f, 0.0f), 30) * rotation;
+
+    textInput.setActive(true);
 }
 
 void Game::tick() {
@@ -80,6 +83,9 @@ void Game::renderTextOverlay(float lag, Renderer& renderer, FontRenderer& fr) {
         .append(" &999TPS: &722")
         .append(tps.getUpdatesPerSecond());
     fr.drawString(10, 10, s);
+    s.clear();
+    textInput.getInput(s);
+    fr.drawString(10, 30, s);
 }
 
 bool Game::isRunning() const {

+ 5 - 2
client/Game.h

@@ -7,6 +7,7 @@
 #include "client/rendering/Renderer.h"
 #include "common/block/BlockRegistry.h"
 #include "common/world/World.h"
+#include "gaming-core/input/TextInput.h"
 #include "gaming-core/network/Client.h"
 #include "gaming-core/utils/Clock.h"
 #include "gaming-core/utils/Size.h"
@@ -14,8 +15,9 @@
 
 class Game final {
 public:
-    Game(const Controller& controller, const Clock& fps, const Clock& tps,
-         RenderSettings& renderSettings, const Size& size, Client& client);
+    Game(TextInput& textInput, const Controller& controller, const Clock& fps,
+         const Clock& tps, RenderSettings& renderSettings, const Size& size,
+         Client& client);
 
     void tick();
     void renderWorld(float lag, Renderer& renderer);
@@ -29,6 +31,7 @@ public:
     void onPacket(InPacket& in);
 
 private:
+    TextInput& textInput;
     const Controller& controller;
     const Clock& fps;
     const Clock& tps;

+ 3 - 2
client/Main.cpp

@@ -38,7 +38,8 @@ int main() {
 
     Size size(1024, 620);
     WindowOptions options(4, 0, size, false, "test");
-    Window window(options);
+    TextInput textInput;
+    Window window(textInput, options);
     if(window.hasError() || GLEW::init()) {
         return 0;
     }
@@ -60,7 +61,7 @@ int main() {
     Controller controller(buttons);
     Clock fps;
     Clock tps;
-    Game game(controller, fps, tps, renderSettings, size, client);
+    Game game(textInput, controller, fps, tps, renderSettings, size, client);
 
     window.show();
 

+ 1 - 1
gaming-core

@@ -1 +1 @@
-Subproject commit 48800a9c38ca720dbdc9132109def675c65f99e1
+Subproject commit 4d90e6c85950353937e5550fec81406a074410b7

+ 1 - 0
meson.build

@@ -42,6 +42,7 @@ sourcesClient = ['client/Main.cpp',
     'gaming-core/utils/Buffer.cpp',
     'gaming-core/input/Button.cpp',
     'gaming-core/input/Buttons.cpp',
+    'gaming-core/input/TextInput.cpp',
     'gaming-core/network/Client.cpp',
     'client/rendering/Framebuffers.cpp',
     'client/rendering/Engine.cpp',