]> git.localhorst.tv Git - blank.git/commitdiff
display focused entity in debug overlay
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 18 Aug 2015 14:46:42 +0000 (16:46 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 18 Aug 2015 15:04:04 +0000 (17:04 +0200)
src/ai/Spawner.cpp
src/ui/Interface.hpp
src/ui/ui.cpp

index fd449c9a99b8698d9250fe7e044bd09ba782ce11..b0ded15ab771121763f93c72bf1604164c12aa70 100644 (file)
@@ -108,7 +108,7 @@ void Spawner::Spawn(const glm::ivec3 &chunk, const glm::vec3 &pos) {
        rot.z *= (rand() % 1024);
 
        Entity &e = world.AddEntity();
-       e.Name("test");
+       e.Name("spawned");
        e.Position(chunk, pos);
        e.Bounds({ { -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f } });
        e.WorldCollidable(true);
index 2538c46cc9176f9a677c255738370504edd283d2..5cf82076a74b0f629dc15930f2dca2b3c001296e 100644 (file)
@@ -73,6 +73,7 @@ public:
        void UpdatePosition();
        void UpdateOrientation();
        void UpdateBlockInfo();
+       void UpdateEntityInfo();
 
        void PostMessage(const char *);
        void PostMessage(const std::string &msg) {
@@ -104,7 +105,9 @@ private:
        FixedText position_text;
        FixedText orientation_text;
        FixedText block_text;
-       Block last_displayed;
+       FixedText entity_text;
+       Block last_block;
+       Entity *last_entity;
        MessageBox messages;
        IntervalTimer msg_timer;
 
index 1de6237e32cee5899b9d6ab0e647270f98461382..aeaccc55c915e49bf21689f01c1347d82b346da3 100644 (file)
@@ -112,7 +112,8 @@ Interface::Interface(
 , position_text()
 , orientation_text()
 , block_text()
-, last_displayed()
+, last_block()
+, last_entity(nullptr)
 , messages(env.assets.small_ui_font)
 , msg_timer(5000)
 , config(config)
@@ -138,6 +139,10 @@ Interface::Interface(
        block_text.Foreground(glm::vec4(1.0f));
        block_text.Background(glm::vec4(0.5f));
        block_text.Set(env.assets.small_ui_font, "Block: none");
+       entity_text.Position(glm::vec3(-25.0f, 25.0f + 4 * env.assets.small_ui_font.LineSkip(), 0.0f), Gravity::NORTH_EAST);
+       entity_text.Foreground(glm::vec4(1.0f));
+       entity_text.Background(glm::vec4(0.5f));
+       entity_text.Set(env.assets.small_ui_font, "Entity: none");
        messages.Position(glm::vec3(25.0f, -25.0f, 0.0f), Gravity::SOUTH_WEST);
        messages.Foreground(glm::vec4(1.0f));
        messages.Background(glm::vec4(0.5f));
@@ -385,6 +390,7 @@ void Interface::ToggleDebug() {
                UpdatePosition();
                UpdateOrientation();
                UpdateBlockInfo();
+               UpdateEntityInfo();
        }
 }
 
@@ -413,21 +419,32 @@ void Interface::UpdateOrientation() {
 void Interface::UpdateBlockInfo() {
        if (aim_world) {
                const Block &block = aim_world.GetBlock();
-               if (last_displayed != block) {
+               if (last_block != block) {
                        std::stringstream s;
                        s << "Block: "
                                << aim_world.GetType().label
                                << ", face: " << block.GetFace()
                                << ", turn: " << block.GetTurn();
                        block_text.Set(env.assets.small_ui_font, s.str());
-                       last_displayed = block;
+                       last_block = block;
                }
        } else {
-               if (last_displayed != Block()) {
+               if (last_block != Block()) {
                        std::stringstream s;
                        s << "Block: none";
                        block_text.Set(env.assets.small_ui_font, s.str());
-                       last_displayed = Block();
+                       last_block = Block();
+               }
+       }
+}
+
+void Interface::UpdateEntityInfo() {
+       if (aim_entity) {
+               if (last_entity != aim_entity.entity) {
+                       std::stringstream s;
+                       s << "Entity: " << aim_entity.entity->Name();
+                       entity_text.Set(env.assets.small_ui_font, s.str());
+                       last_entity = aim_entity.entity;
                }
        }
 }
@@ -594,6 +611,7 @@ void Interface::CheckAim() {
        }
        if (debug) {
                UpdateBlockInfo();
+               UpdateEntityInfo();
        }
 }
 
@@ -620,7 +638,11 @@ void Interface::Render(Viewport &viewport) noexcept {
                counter_text.Render(viewport);
                position_text.Render(viewport);
                orientation_text.Render(viewport);
-               block_text.Render(viewport);
+               if (aim_world) {
+                       block_text.Render(viewport);
+               } else if (aim_entity) {
+                       entity_text.Render(viewport);
+               }
        }
 
        if (msg_timer.Running()) {