Nimbin[12]?SDL & Graphics / mapcreator / commits / 7192800

mapcreator git · master

SDL3 2.5D game and engine using assets, with map editor

sdl3 c++ game engine map-editor cmake · first commit 2025-10-31 · last commit 2026-09-07 (1 month ago) · synced 3 days ago · upstream: git.ide3.de/hsnr/sdl-spieleentwicklung/map_creator

C++ 99.3%
git clone https://git.christianimmanuel.de/sdl-graphics/mapcreator.gitwget https://git.christianimmanuel.de/sdl-graphics/mapcreator/archive/mapcreator.tar.gz

Fix VEG/SEED inventory message top left

Christian Immanuel · 2026-02-17 11:57 · 7192800fb512dcbfef0fb640bf03d304071f6840

 src/character/message.cpp     | 54 ++++++++++++++++++++++++++++++++-----------
 src/character/message.hpp     |  1 +
 src/inventory/inventory.hpp   |  2 +-
 src/vegetables/vegetables.cpp |  4 ++--
 src/vegetables/vegetables.hpp |  2 +-
 5 files changed, 45 insertions(+), 18 deletions(-)

diff --git a/src/character/message.cpp b/src/character/message.cpp
index 7f5f0ef..66f09ec 100644
--- a/src/character/message.cpp
+++ b/src/character/message.cpp
@@ -25,7 +25,7 @@ Messages::Messages() {
         {MessageKey::ADD_INVENTORY, {10, MessageType::INVENTORY, "Added item: "}},
         {MessageKey::ADD_RESOURCE,  {10, MessageType::RESOURCE,  "Resource "}},
         {MessageKey::ADD_VEGETABLE, {10, MessageType::VEGETABLE, "Vegetable "}},
-        {MessageKey::ADD_VEGETABLE_SEED,   {10, MessageType::VEGETABLE, "Seed "}},
+        {MessageKey::ADD_VEGETABLE_SEED,   {10, MessageType::VEGETABLE_SEED, "Seed "}},
         {MessageKey::NOTHING_TO_INTERACT,  {4, MessageType::CHARACTER, "I cant find anything to interact with.."}},
     };
 }
@@ -205,8 +205,9 @@ void Messages::render_InventoryMessages(Game* game, Inventory* inventory) {
 
     for (auto &kv : messages) {
         if ( kv.second.message_type == MessageType::INVENTORY ||
-             kv.second.message_type == MessageType::RESOURCE ||
-             kv.second.message_type == MessageType::VEGETABLE)
+             kv.second.message_type == MessageType::RESOURCE  ||
+             kv.second.message_type == MessageType::VEGETABLE ||
+             kv.second.message_type == MessageType::VEGETABLE_SEED)
             inv_msgs.push_back(&kv.second);
     }
     if (inv_msgs.empty())
@@ -214,9 +215,9 @@ void Messages::render_InventoryMessages(Game* game, Inventory* inventory) {
 
     // Sort by remaining duration
     std::sort(inv_msgs.begin(), inv_msgs.end(),
-        [](const Message_s* a, const Message_s* b){
+            [](const Message_s* a, const Message_s* b){
             return a->duration > b->duration;
-        });
+            });
 
     // Measure max text width
     float max_text_w = 0.0f;
@@ -237,14 +238,25 @@ void Messages::render_InventoryMessages(Game* game, Inventory* inventory) {
             int amount = inventory->resources[type];
             text = std::to_string(amount);
         }
-        /*
         else
         if (msg->message_type == MessageType::VEGETABLE) {
             VegetableData::Type* vtype = static_cast<VegetableData::Type*>(msg->type_data);
-            int amount = inventory->vegetables[*vtype].count;
+            auto it = inventory->vegetables.find(*vtype);
+            int amount = 0;
+            if (it != inventory->vegetables.end())
+                amount = it->second.count;
+            text = std::to_string(amount);
+        }
+        else
+        if (msg->message_type == MessageType::VEGETABLE_SEED) {
+            std::cout << "GET SEED MESS\n";
+            VegetableData::Type* vtype = static_cast<VegetableData::Type*>(msg->type_data);
+            auto it = inventory->seeds.find(*vtype);
+            int amount = 0;
+            if (it != inventory->seeds.end())
+                amount = it->second.count;
             text = std::to_string(amount);
         }
-        */
 
         SDL_Color col{255,255,255,255};
         SDL_Surface* surf = TTF_RenderText_Blended(Ui::font_menu, text.c_str(), text.length(), col);
@@ -263,6 +275,7 @@ void Messages::render_InventoryMessages(Game* game, Inventory* inventory) {
         InventoryItem* item        = nullptr;
         ResourceType* rtype        = nullptr;
         VegetableData::Type* vtype = nullptr;
+        bool is_seed               = false;
 
         std::string text ;
         if (msg->message_type == MessageType::INVENTORY) {
@@ -277,14 +290,26 @@ void Messages::render_InventoryMessages(Game* game, Inventory* inventory) {
             int amount = inventory->resources[*rtype];
             text = std::to_string(amount);
         }
-        /*
         else
         if (msg->message_type == MessageType::VEGETABLE) {
             vtype = static_cast<VegetableData::Type*>(msg->type_data);
-            int amount = inventory->vegetables[*vtype].count;
+            auto it = inventory->vegetables.find(*vtype);
+            int amount = 0;
+            if (it != inventory->vegetables.end())
+                amount = it->second.count;
+            text = std::to_string(amount);
+        }
+        else
+        if (msg->message_type == MessageType::VEGETABLE_SEED) {
+            std::cout << "SET MES SEED \n";
+            is_seed = true;
+            vtype = static_cast<VegetableData::Type*>(msg->type_data);
+            auto it = inventory->seeds.find(*vtype);
+            int amount = 0;
+            if (it != inventory->seeds.end())
+                amount = it->second.count;
             text = std::to_string(amount);
         }
-        */
 
         SDL_Color col{255,255,255,255};
         SDL_Surface* surf = TTF_RenderText_Blended(Ui::font_menu, text.c_str(), text.length(), col);
@@ -334,7 +359,7 @@ void Messages::render_InventoryMessages(Game* game, Inventory* inventory) {
             auto it = Icon::item_pos.find(item->type);
             if (it != Icon::item_pos.end()) {
                 src = SDL_FRect{
-                    it->second.x * 16.0f,
+                        it->second.x * 16.0f,
                         it->second.y * 16.0f,
                         16.0f,
                         16.0f
@@ -348,7 +373,7 @@ void Messages::render_InventoryMessages(Game* game, Inventory* inventory) {
             auto it = Icon::resource_pos.find(*rtype);
             if (it != Icon::resource_pos.end()) {
                 src = SDL_FRect{
-                    it->second.x * 16.0f,
+                        it->second.x * 16.0f,
                         it->second.y * 16.0f,
                         16.0f,
                         16.0f
@@ -359,7 +384,8 @@ void Messages::render_InventoryMessages(Game* game, Inventory* inventory) {
 
         // ---- VEGETABLE ----
         if (vtype && *vtype != VegetableData::Type::NONE) {
-            SDL_Point pos = VegetableData::get_IconTilePosByType(*vtype);
+            SDL_Point pos = VegetableData::get_IconTilePosByType(*vtype, is_seed);
+            std::cout << "POS :::: " << pos.x << " " << pos.y << std::endl;
             src = SDL_FRect{
                     pos.x * 16.0f,
                     pos.y * 16.0f,
diff --git a/src/character/message.hpp b/src/character/message.hpp
index 311dc50..4ab2601 100644
--- a/src/character/message.hpp
+++ b/src/character/message.hpp
@@ -14,6 +14,7 @@ enum class MessageType {
     INVENTORY,
     RESOURCE,
     VEGETABLE,
+    VEGETABLE_SEED,
 };
 
 struct Message_s {
diff --git a/src/inventory/inventory.hpp b/src/inventory/inventory.hpp
index 76810e0..d84c22f 100644
--- a/src/inventory/inventory.hpp
+++ b/src/inventory/inventory.hpp
@@ -57,7 +57,7 @@ struct InventoryVegetable : Inventory_s {
     VegetableData::Type type;
     const ConsumingStatsBonus& stats_bonus;
     InventoryVegetable(size_t d, VegetableData::Type t, bool s)
-        : Inventory_s(d, s ? InventoryObjectType::SEED : InventoryObjectType::VEGETABLE),
+        : Inventory_s(d, s ? InventoryObjectType::SEED : InventoryObjectType::VEGETABLE), count(0),
           is_seed(s), type(t),
           stats_bonus(VegetableData::crop_defs[static_cast<uint32_t>(t)].stats_bonus)
     { }
diff --git a/src/vegetables/vegetables.cpp b/src/vegetables/vegetables.cpp
index 4195fa3..54420e5 100644
--- a/src/vegetables/vegetables.cpp
+++ b/src/vegetables/vegetables.cpp
@@ -21,9 +21,9 @@ namespace VegetableData {
         return &crop_defs[static_cast<size_t>(type)];
     }
 
-    const SDL_Point get_IconTilePosByType(Type type) {
+    const SDL_Point get_IconTilePosByType(Type type, bool is_seed) {
         CropDefinition data = crop_defs[(int)type];
-        return {data.icon_tile_x, data.icon_tile_y};
+        return {data.icon_tile_x - (!is_seed ? 0 : 1), data.icon_tile_y};
     }
 }
 
diff --git a/src/vegetables/vegetables.hpp b/src/vegetables/vegetables.hpp
index 5031a97..9f0bc9b 100644
--- a/src/vegetables/vegetables.hpp
+++ b/src/vegetables/vegetables.hpp
@@ -54,7 +54,7 @@ namespace VegetableData {
     extern const CropDefinition crop_defs[(int)Type::COUNT];
 
     const CropDefinition* get_DataByType(Type type);
-    const SDL_Point get_IconTilePosByType(Type type);
+    const SDL_Point get_IconTilePosByType(Type type, bool is_seed = false);
 
 
 }