]> git.localhorst.tv Git - blank.git/blobdiff - src/ui/ui.cpp
split chunk redering from world model
[blank.git] / src / ui / ui.cpp
index 1de6237e32cee5899b9d6ab0e647270f98461382..acf877fd1da6811dca1679d80461d7c86105f0ee 100644 (file)
@@ -59,6 +59,10 @@ HUD::HUD(const BlockTypeRegistry &types, const Font &font)
 }
 
 
+void HUD::DisplayNone() {
+       block_visible = false;
+}
+
 void HUD::Display(const Block &b) {
        const BlockType &type = types.Get(b.type);
 
@@ -112,14 +116,15 @@ 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)
 , place_timer(256)
 , remove_timer(256)
 , remove(0)
-, selection(1)
+, selection(0)
 , place_sound(env.assets.LoadSound("thump"))
 , remove_sound(env.assets.LoadSound("plop"))
 , fwd(0)
@@ -138,10 +143,14 @@ 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));
-       hud.Display(selection);
+       hud.DisplayNone();
 }
 
 
@@ -385,6 +394,7 @@ void Interface::ToggleDebug() {
                UpdatePosition();
                UpdateOrientation();
                UpdateBlockInfo();
+               UpdateEntityInfo();
        }
 }
 
@@ -413,21 +423,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;
                }
        }
 }
@@ -575,10 +596,10 @@ OutlineModel::Buffer outl_buf;
 }
 
 void Interface::CheckAim() {
-       if (!world.Intersection(aim, glm::mat4(1.0f), aim_world)) {
+       if (!world.Intersection(aim, glm::mat4(1.0f), ctrl.Controlled().ChunkCoords(), aim_world)) {
                aim_world = WorldCollision();
        }
-       if (!world.Intersection(aim, glm::mat4(1.0f), aim_entity)) {
+       if (!world.Intersection(aim, glm::mat4(1.0f), ctrl.Controlled(), aim_entity)) {
                aim_entity = EntityCollision();
        }
        if (aim_world && aim_entity) {
@@ -594,6 +615,7 @@ void Interface::CheckAim() {
        }
        if (debug) {
                UpdateBlockInfo();
+               UpdateEntityInfo();
        }
 }
 
@@ -620,7 +642,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()) {