Browse Source

Add selection ring size configuration to TroopConfig and update renderers

Co-authored-by: djeada <[email protected]>
copilot-swe-agent[bot] 2 months ago
parent
commit
2a85f40868
3 changed files with 36 additions and 2 deletions
  1. 15 0
      game/units/troop_config.h
  2. 10 1
      render/entity/archer_renderer.cpp
  3. 11 1
      render/entity/arrow_vfx_renderer.cpp

+ 15 - 0
game/units/troop_config.h

@@ -29,6 +29,14 @@ public:
     return 10;
   }
 
+  float getSelectionRingSize(const std::string &unitType) const {
+    auto it = m_selectionRingSize.find(unitType);
+    if (it != m_selectionRingSize.end()) {
+      return it->second;
+    }
+    return 0.5f;
+  }
+
   void registerTroopType(const std::string &unitType, int individualsPerUnit) {
     m_individualsPerUnit[unitType] = individualsPerUnit;
   }
@@ -37,15 +45,22 @@ public:
     m_maxUnitsPerRow[unitType] = maxUnitsPerRow;
   }
 
+  void registerSelectionRingSize(const std::string &unitType,
+                                  float selectionRingSize) {
+    m_selectionRingSize[unitType] = selectionRingSize;
+  }
+
 private:
   TroopConfig() {
 
     m_individualsPerUnit["archer"] = 30;
     m_maxUnitsPerRow["archer"] = 8;
+    m_selectionRingSize["archer"] = 0.5f;
   }
 
   std::unordered_map<std::string, int> m_individualsPerUnit;
   std::unordered_map<std::string, int> m_maxUnitsPerRow;
+  std::unordered_map<std::string, float> m_selectionRingSize;
 };
 
 } // namespace Units

+ 10 - 1
render/entity/archer_renderer.cpp

@@ -409,10 +409,19 @@ static inline void drawBowAndArrow(const DrawContext &p, ISubmitter &out,
 
 static inline void drawSelectionFX(const DrawContext &p, ISubmitter &out) {
   if (p.selected || p.hovered) {
+    float ringSize = 0.5f;
+    if (p.entity) {
+      auto *unit = p.entity->getComponent<Engine::Core::UnitComponent>();
+      if (unit && !unit->unitType.empty()) {
+        ringSize = Game::Units::TroopConfig::instance().getSelectionRingSize(
+            unit->unitType);
+      }
+    }
+
     QMatrix4x4 ringM;
     QVector3D pos = p.model.column(3).toVector3D();
     ringM.translate(pos.x(), pos.y() + 0.05f, pos.z());
-    ringM.scale(0.5f, 1.0f, 0.5f);
+    ringM.scale(ringSize, 1.0f, ringSize);
     if (p.selected)
       out.selectionRing(ringM, 0.6f, 0.25f, QVector3D(0.2f, 0.4f, 1.0f));
     else

+ 11 - 1
render/entity/arrow_vfx_renderer.cpp

@@ -1,5 +1,6 @@
 #include "../../game/core/component.h"
 #include "../../game/core/entity.h"
+#include "../../game/units/troop_config.h"
 #include "../../game/visuals/team_colors.h"
 #include "../geom/math_utils.h"
 #include "../geom/selection_ring.h"
@@ -377,10 +378,19 @@ static inline void drawBowAndArrow(const DrawContext &p, ISubmitter &out,
 
 static inline void drawSelectionFX(const DrawContext &p, ISubmitter &out) {
   if (p.selected || p.hovered) {
+    float ringSize = 0.5f;
+    if (p.entity) {
+      auto *unit = p.entity->getComponent<Engine::Core::UnitComponent>();
+      if (unit && !unit->unitType.empty()) {
+        ringSize = Game::Units::TroopConfig::instance().getSelectionRingSize(
+            unit->unitType);
+      }
+    }
+
     QMatrix4x4 ringM;
     QVector3D pos = p.model.column(3).toVector3D();
     ringM.translate(pos.x(), 0.15f, pos.z());
-    ringM.scale(0.5f, 1.0f, 0.5f);
+    ringM.scale(ringSize, 1.0f, ringSize);
     if (p.selected)
       out.selectionRing(ringM, 0.6f, 0.25f, QVector3D(0.2f, 0.8f, 0.2f));
     else