Browse Source

Fix troop icons not showing by adding NO_RESOURCE_TARGET_PATH to Qt6 QML module

djeada 1 month ago
parent
commit
3378924f35

+ 3 - 0
app/core/game_engine.cpp

@@ -261,6 +261,9 @@ GameEngine::GameEngine(QObject *parent)
           &App::Controllers::CommandController::troopLimitReached, [this]() {
             setError("Maximum troop limit reached. Cannot produce more units.");
           });
+  connect(m_commandController.get(),
+          &App::Controllers::CommandController::hold_modeChanged, this,
+          &GameEngine::holdModeChanged);
 
   connect(this, SIGNAL(selectedUnitsChanged()), m_selectedUnitsModel,
           SLOT(refresh()));

+ 1 - 0
app/core/game_engine.h

@@ -335,4 +335,5 @@ signals:
   void lastErrorChanged();
   void mapsLoadingChanged();
   void saveSlotsChanged();
+  void holdModeChanged(bool active);
 };

+ 1 - 0
app/models/selected_units_model.h

@@ -26,6 +26,7 @@ public:
        int role = Qt::DisplayRole) const -> QVariant override;
   [[nodiscard]] auto roleNames() const -> QHash<int, QByteArray> override;
 
+public slots:
   void refresh();
 
 private:

+ 0 - 142
assets/shaders/archer_kingdom_of_iron.frag

@@ -181,145 +181,3 @@ void main() {
   color *= diff;
   FragColor = vec4(color, u_alpha);
 }
-
-float hash(vec2 p) {
-  vec3 p3 = fract(vec3(p.xyx) * 0.1031);
-  p3 += dot(p3, p3.yzx + 33.33);
-  return fract((p3.x + p3.y) * p3.z);
-}
-
-float noise(vec2 p) {
-  vec2 i = floor(p);
-  vec2 f = fract(p);
-  f = f * f * (3.0 - 2.0 * f);
-  float a = hash(i);
-  float b = hash(i + vec2(1.0, 0.0));
-  float c = hash(i + vec2(0.0, 1.0));
-  float d = hash(i + vec2(1.0, 1.0));
-  return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
-}
-
-// Roman chainmail (lorica hamata) ring pattern
-float chainmailRings(vec2 p) {
-  vec2 grid = fract(p * 32.0) - 0.5;
-  float ring = length(grid);
-  float ringPattern =
-      smoothstep(0.38, 0.32, ring) - smoothstep(0.28, 0.22, ring);
-
-  // Offset rows for interlocking
-  vec2 offsetGrid = fract(p * 32.0 + vec2(0.5, 0.0)) - 0.5;
-  float offsetRing = length(offsetGrid);
-  float offsetPattern =
-      smoothstep(0.38, 0.32, offsetRing) - smoothstep(0.28, 0.22, offsetRing);
-
-  return (ringPattern + offsetPattern) * 0.14;
-}
-
-// Leather pteruges strips (hanging skirt/shoulder guards)
-float pterugesStrips(vec2 p, float y) {
-  // Vertical leather strips
-  float stripX = fract(p.x * 9.0);
-  float strip = smoothstep(0.15, 0.20, stripX) - smoothstep(0.80, 0.85, stripX);
-
-  // Add leather texture to strips
-  float leatherTex = noise(p * 18.0) * 0.35;
-
-  // Strips hang and curve
-  float hang = smoothstep(0.65, 0.45, y);
-
-  return strip * leatherTex * hang;
-}
-
-void main() {
-  vec3 color = u_color;
-  if (u_useTexture) {
-    color *= texture(u_texture, v_texCoord).rgb;
-  }
-
-  vec3 normal = normalize(v_normal);
-  vec2 uv = v_worldPos.xz * 4.5;
-  float avgColor = (color.r + color.g + color.b) / 3.0;
-
-  // Detect bronze vs steel by color warmth
-  bool isBronze =
-      (color.r > color.g * 1.02 && color.r > color.b * 1.06 && avgColor > 0.45);
-  bool isRoyalCape = (color.b > color.g * 1.25 && color.b > color.r * 1.4);
-
-  // === KINGDOM OF IRON STANDARD ISSUE MATERIALS ===
-
-  // BRUSHED STEEL WITH WARM ACCENTS
-  if (isBronze) {
-    float steelBrush = noise(uv * 20.0) * 0.08;
-    float steelSpec =
-        pow(abs(dot(normal, normalize(vec3(0.1, 1.0, 0.3)))), 8.0) * 0.35;
-    float steelFresnel = pow(1.0 - abs(normal.y), 2.4) * 0.22;
-    color += vec3(steelBrush * 0.4 + steelSpec + steelFresnel);
-  }
-  // STEEL CHAINMAIL
-  else if (avgColor > 0.38 && avgColor <= 0.65 && !isRoyalCape) {
-    float rings = chainmailRings(v_worldPos.xz);
-
-    float viewAngle = abs(dot(normal, normalize(vec3(0.0, 1.0, 0.6))));
-    float chainSheen = pow(viewAngle, 6.0) * 0.20;
-    float patina = noise(uv * 14.0) * 0.05;
-
-    color += vec3(rings * 0.8 + chainSheen);
-    color -= vec3(patina * 0.3);
-  }
-  // NAVY BATTLE CAPE
-  else if (isRoyalCape) {
-    float weaveX = sin(v_worldPos.x * 45.0);
-    float weaveZ = sin(v_worldPos.z * 48.0);
-    float weave = weaveX * weaveZ * 0.035;
-    float woolFuzz = noise(uv * 18.0) * 0.08;
-    float folds = noise(uv * 5.0) * 0.10 - 0.05;
-    float capeSheen = pow(1.0 - abs(normal.y), 6.0) * 0.06;
-
-    color *= 1.0 + woolFuzz - 0.04 + folds;
-    color += vec3(weave * 0.7 + capeSheen);
-  }
-  // LEATHER PTERUGES & ARMOR STRIPS (tan/brown leather strips)
-  else if (avgColor > 0.35) {
-    // Thick leather with visible grain
-    float leatherGrain = noise(uv * 10.0) * 0.16;
-    float leatherPores = noise(uv * 22.0) * 0.08;
-
-    // Pteruges strip pattern
-    float strips = pterugesStrips(v_worldPos.xz, v_worldPos.y);
-
-    // Worn leather edges
-    float wear = noise(uv * 4.0) * 0.10 - 0.05;
-
-    // Leather has subtle sheen
-    float viewAngle = abs(dot(normal, normalize(vec3(0.0, 1.0, 0.5))));
-    float leatherSheen = pow(1.0 - viewAngle, 4.5) * 0.10;
-
-    color *= 1.0 + leatherGrain + leatherPores - 0.08 + wear;
-    color += vec3(strips * 0.15 + leatherSheen);
-  }
-  // DARK ELEMENTS (cingulum belt, straps, manicae)
-  else {
-    float leatherDetail = noise(uv * 8.0) * 0.14;
-    float tooling = noise(uv * 16.0) * 0.06; // Decorative tooling
-    float darkening = noise(uv * 2.5) * 0.08;
-
-    color *= 1.0 + leatherDetail - 0.07 + tooling - darkening;
-  }
-
-  color = clamp(color, 0.0, 1.0);
-
-  // Lighting model - soft wrap for leather/fabric, harder for metal
-  vec3 lightDir = normalize(vec3(1.0, 1.15, 1.0));
-  float nDotL = dot(normal, lightDir);
-
-  float wrapAmount = isBronze ? 0.20 : 0.40;
-  float diff = max(nDotL * (1.0 - wrapAmount) + wrapAmount, 0.22);
-
-  // Enhance contrast for bronze
-  if (isBronze) {
-    diff = pow(diff, 0.88);
-  }
-
-  color *= diff;
-  FragColor = vec4(color, u_alpha);
-}

+ 6 - 1
main.cpp

@@ -287,13 +287,18 @@ auto main(int argc, char *argv[]) -> int {
   engine->rootContext()->setContextProperty("game", game_engine.get());
   qInfo() << "Adding import path...";
   engine->addImportPath("qrc:/StandardOfIron/ui/qml");
+  engine->addImportPath("qrc:/");
   qInfo() << "Registering QML types...";
   qmlRegisterType<GLView>("StandardOfIron", 1, 0, "GLView");
 
   // Register Theme singleton
-  qmlRegisterSingletonType<Theme>("StandardOfIron.UI", 1, 0, "Theme",
+  qmlRegisterSingletonType<Theme>("StandardOfIron", 1, 0, "Theme",
                                   &Theme::create);
 
+  // Register StyleGuide singleton from QML file
+  qmlRegisterSingletonType(QUrl("qrc:/StandardOfIron/ui/qml/StyleGuide.qml"),
+                           "StandardOfIron", 1, 0, "StyleGuide");
+
   qInfo() << "Loading Main.qml...";
   qInfo() << "Loading Main.qml...";
   engine->load(QUrl(QStringLiteral("qrc:/StandardOfIron/ui/qml/Main.qml")));

+ 1 - 1
ui/qml/CampaignMenu.qml

@@ -1,7 +1,7 @@
 import QtQuick 2.15
 import QtQuick.Controls 2.15
 import QtQuick.Layouts 1.15
-import StandardOfIron.UI 1.0
+import StandardOfIron 1.0
 
 Item {
     id: root

+ 6 - 9
ui/qml/HUDBottom.qml

@@ -1,7 +1,7 @@
 import QtQuick 2.15
 import QtQuick.Controls 2.15
 import QtQuick.Layouts 1.15
-import StandardOfIron.UI 1.0
+import StandardOfIron 1.0
 
 RowLayout {
     id: bottomRoot
@@ -27,14 +27,14 @@ RowLayout {
         border.width: 2
         radius: 6
 
-        Column {
+        ColumnLayout {
             anchors.fill: parent
             anchors.margins: 6
             spacing: 6
 
             Rectangle {
-                width: parent.width
-                height: 25
+                Layout.fillWidth: true
+                Layout.preferredHeight: 25
                 color: "#1a252f"
                 radius: 4
 
@@ -49,11 +49,8 @@ RowLayout {
             }
 
             ScrollView {
-                anchors.left: parent.left
-                anchors.right: parent.right
-                anchors.top: undefined
-                anchors.bottom: parent.bottom
-                height: parent.height - 35
+                Layout.fillWidth: true
+                Layout.fillHeight: true
                 clip: true
                 ScrollBar.vertical.policy: ScrollBar.AsNeeded
 

+ 4 - 3
ui/qml/LoadGamePanel.qml

@@ -2,7 +2,7 @@ import QtQml 2.15
 import QtQuick 2.15
 import QtQuick.Controls 2.15
 import QtQuick.Layouts 1.3
-import StandardOfIron.UI 1.0
+import StandardOfIron 1.0
 
 Item {
     id: root
@@ -52,8 +52,7 @@ Item {
     }
 
     Connections {
-        target: typeof game !== 'undefined' ? game : null
-        onSaveSlotsChanged: {
+        function onSaveSlotsChanged() {
             if (typeof loadListModel === 'undefined')
                 return ;
 
@@ -85,6 +84,8 @@ Item {
             }
             loadListView.selectedIndex = newIndex;
         }
+
+        target: typeof game !== 'undefined' ? game : null
     }
 
     Rectangle {

+ 1 - 1
ui/qml/MainMenu.qml

@@ -2,7 +2,7 @@ import QtQuick 2.15
 import QtQuick.Controls 2.15
 import QtQuick.Layouts 1.3
 import QtQuick.Window 2.15
-import StandardOfIron.UI 1.0
+import StandardOfIron 1.0
 
 Item {
     id: root

+ 1 - 1
ui/qml/MapSelect.qml

@@ -1,7 +1,7 @@
 import QtQuick 2.15
 import QtQuick.Controls 2.15
 import QtQuick.Layouts 1.15
-import StandardOfIron.UI 1.0
+import StandardOfIron 1.0
 
 Item {
     id: root

+ 1 - 1
ui/qml/ProductionPanel.qml

@@ -1,7 +1,7 @@
 import QtQuick 2.15
 import QtQuick.Controls 2.15
 import QtQuick.Layouts 1.15
-import StandardOfIron.UI 1.0
+import StandardOfIron 1.0
 
 Rectangle {
     id: productionPanel

+ 4 - 3
ui/qml/SaveGamePanel.qml

@@ -2,7 +2,7 @@ import QtQml 2.15
 import QtQuick 2.15
 import QtQuick.Controls 2.15
 import QtQuick.Layouts 1.3
-import StandardOfIron.UI 1.0
+import StandardOfIron 1.0
 
 Item {
     id: root
@@ -34,12 +34,13 @@ Item {
     }
 
     Connections {
-        target: typeof game !== 'undefined' ? game : null
-        onSaveSlotsChanged: {
+        function onSaveSlotsChanged() {
             if (typeof saveListModel !== 'undefined')
                 saveListModel.loadFromGame();
 
         }
+
+        target: typeof game !== 'undefined' ? game : null
     }
 
     Rectangle {

+ 1 - 1
ui/qml/SettingsPanel.qml

@@ -2,7 +2,7 @@ import QtQml 2.15
 import QtQuick 2.15
 import QtQuick.Controls 2.15
 import QtQuick.Layouts 1.3
-import StandardOfIron.UI 1.0
+import StandardOfIron 1.0
 
 Item {
     id: root

+ 41 - 36
ui/qml/StyleGuide.qml

@@ -137,61 +137,66 @@ QtObject {
     })
     readonly property var unitIconSources: ({
         "archer": ({
-            "default": "qrc:/assets/visuals/icons/archer_rome.png",
-            "kingdom_of_iron": "qrc:/assets/visuals/icons/archer_rome.png",
-            "roman_republic": "qrc:/assets/visuals/icons/archer_rome.png",
-            "carthage": "qrc:/assets/visuals/icons/archer_cartaghe.png"
+            "default": root.iconPath("archer_rome.png"),
+            "kingdom_of_iron": root.iconPath("archer_rome.png"),
+            "roman_republic": root.iconPath("archer_rome.png"),
+            "carthage": root.iconPath("archer_cartaghe.png")
         }),
         "swordsman": ({
-            "default": "qrc:/assets/visuals/icons/swordsman_rome.png",
-            "kingdom_of_iron": "qrc:/assets/visuals/icons/swordsman_rome.png",
-            "roman_republic": "qrc:/assets/visuals/icons/swordsman_rome.png",
-            "carthage": "qrc:/assets/visuals/icons/swordsman_cartaghe.png"
+            "default": root.iconPath("swordsman_rome.png"),
+            "kingdom_of_iron": root.iconPath("swordsman_rome.png"),
+            "roman_republic": root.iconPath("swordsman_rome.png"),
+            "carthage": root.iconPath("swordsman_cartaghe.png")
         }),
         "spearman": ({
-            "default": "qrc:/assets/visuals/icons/spearman_rome.png",
-            "kingdom_of_iron": "qrc:/assets/visuals/icons/spearman_rome.png",
-            "roman_republic": "qrc:/assets/visuals/icons/spearman_rome.png",
-            "carthage": "qrc:/assets/visuals/icons/spearman_cartaghe.png"
+            "default": root.iconPath("spearman_rome.png"),
+            "kingdom_of_iron": root.iconPath("spearman_rome.png"),
+            "roman_republic": root.iconPath("spearman_rome.png"),
+            "carthage": root.iconPath("spearman_cartaghe.png")
         }),
         "horse_swordsman": ({
-            "default": "qrc:/assets/visuals/icons/horse_swordsman_rome.png",
-            "kingdom_of_iron": "qrc:/assets/visuals/icons/horse_swordsman_rome.png",
-            "roman_republic": "qrc:/assets/visuals/icons/horse_swordsman_rome.png",
-            "carthage": "qrc:/assets/visuals/icons/horse_swordsman_cartaghe.png"
+            "default": root.iconPath("horse_swordsman_rome.png"),
+            "kingdom_of_iron": root.iconPath("horse_swordsman_rome.png"),
+            "roman_republic": root.iconPath("horse_swordsman_rome.png"),
+            "carthage": root.iconPath("horse_swordsman_cartaghe.png")
         }),
         "horse_archer": ({
-            "default": "qrc:/assets/visuals/icons/horse_archer_rome.png",
-            "kingdom_of_iron": "qrc:/assets/visuals/icons/horse_archer_rome.png",
-            "roman_republic": "qrc:/assets/visuals/icons/horse_archer_rome.png",
-            "carthage": "qrc:/assets/visuals/icons/horse_archer_cartaghe.png"
+            "default": root.iconPath("horse_archer_rome.png"),
+            "kingdom_of_iron": root.iconPath("horse_archer_rome.png"),
+            "roman_republic": root.iconPath("horse_archer_rome.png"),
+            "carthage": root.iconPath("horse_archer_cartaghe.png")
         }),
         "horse_spearman": ({
-            "default": "qrc:/assets/visuals/icons/horse_spearman_rome.png",
-            "kingdom_of_iron": "qrc:/assets/visuals/icons/horse_spearman_rome.png",
-            "roman_republic": "qrc:/assets/visuals/icons/horse_spearman_rome.png",
-            "carthage": "qrc:/assets/visuals/icons/horse_spearman_cartaghe.png"
+            "default": root.iconPath("horse_spearman_rome.png"),
+            "kingdom_of_iron": root.iconPath("horse_spearman_rome.png"),
+            "roman_republic": root.iconPath("horse_spearman_rome.png"),
+            "carthage": root.iconPath("horse_spearman_cartaghe.png")
         }),
         "healer": ({
-            "default": "qrc:/assets/visuals/icons/healer_rome.png",
-            "kingdom_of_iron": "qrc:/assets/visuals/icons/healer_rome.png",
-            "roman_republic": "qrc:/assets/visuals/icons/healer_rome.png",
-            "carthage": "qrc:/assets/visuals/icons/healer_cartaghe.png"
+            "default": root.iconPath("healer_rome.png"),
+            "kingdom_of_iron": root.iconPath("healer_rome.png"),
+            "roman_republic": root.iconPath("healer_rome.png"),
+            "carthage": root.iconPath("healer_cartaghe.png")
         }),
         "catapult": ({
-            "default": "qrc:/assets/visuals/icons/catapult_rome.png",
-            "kingdom_of_iron": "qrc:/assets/visuals/icons/catapult_rome.png",
-            "roman_republic": "qrc:/assets/visuals/icons/catapult_rome.png",
-            "carthage": "qrc:/assets/visuals/icons/catapult_cartaghe.png"
+            "default": root.iconPath("catapult_rome.png"),
+            "kingdom_of_iron": root.iconPath("catapult_rome.png"),
+            "roman_republic": root.iconPath("catapult_rome.png"),
+            "carthage": root.iconPath("catapult_cartaghe.png")
         }),
         "ballista": ({
-            "default": "qrc:/assets/visuals/icons/ballista_rome.png",
-            "kingdom_of_iron": "qrc:/assets/visuals/icons/ballista_rome.png",
-            "roman_republic": "qrc:/assets/visuals/icons/ballista_rome.png",
-            "carthage": "qrc:/assets/visuals/icons/ballista_cartaghe.png"
+            "default": root.iconPath("ballista_rome.png"),
+            "kingdom_of_iron": root.iconPath("ballista_rome.png"),
+            "roman_republic": root.iconPath("ballista_rome.png"),
+            "carthage": root.iconPath("ballista_cartaghe.png")
         }),
         "default": ({
             "default": ""
         })
     })
+
+    function iconPath(filename) {
+        return "qrc:/StandardOfIron/assets/visuals/icons/" + filename;
+    }
+
 }

+ 1 - 0
ui/qml/StyledButton.qml

@@ -1,5 +1,6 @@
 import QtQuick 2.15
 import QtQuick.Controls 2.15
+import StandardOfIron 1.0
 
 Button {
     id: control

+ 0 - 1
ui/qml/qmldir

@@ -1,4 +1,3 @@
-module StandardOfIron.UI
 singleton StyleGuide 1.0 StyleGuide.qml
 StyledButton 1.0 StyledButton.qml
 ProductionPanel 1.0 ProductionPanel.qml