Ver código fonte

add inventoty search filter

Kolja Strohm 2 anos atrás
pai
commit
6bc09bae6d

+ 7 - 0
FactoryCraft/Block.cpp

@@ -111,6 +111,13 @@ void Block::api(char* message)
     }
 }
 
+void Block::copyLightTo(Block* zB)
+{
+    memcpy(zB->lightBuffer, lightBuffer, 24 * 4);
+    memcpy(zB->lightData, lightData, 6 * 6);
+    memcpy(zB->sideVisible, sideVisible, 6);
+}
+
 void Block::setLightData(Direction dir, unsigned char* data)
 {
     memcpy(lightData + getDirectionIndex(dir) * 6, data, 6);

+ 1 - 0
FactoryCraft/Block.h

@@ -40,6 +40,7 @@ public:
     virtual ~Block();
 
     void api(char* message);
+    void copyLightTo(Block* zB);
     void setLightData(Direction dir, unsigned char* data);
     bool isVisible() const;
 

+ 1 - 0
FactoryCraft/Chunk.cpp

@@ -85,6 +85,7 @@ void Chunk::setBlock(Block* block)
                 }
             }
             vcs.unlock();
+            iterator->copyLightTo(block);
             iterator->release();
             iterator.set(block);
             cs.unlock();

+ 40 - 3
FactoryCraft/CraftingGrid.cpp

@@ -1,5 +1,6 @@
 #include "CraftingGrid.h"
 
+#include <DateiSystem.h>
 #include <XML.h>
 
 #include "DragController.h"
@@ -81,7 +82,7 @@ CraftingGridView::CraftingGridView(Text id,
       requestetTooltipSlot(-1)
 {
     craft = uiFactory.createKnopf(uiFactory.initParam);
-    craft->setPosition(rowSize * 60, 10);
+    craft->setPosition(rowSize * 60, 0);
     craft->setSize(40, 20);
     craft->setText("Craft");
     craft->setMausEreignis([this](void* p, void* o, MausEreignis me) {
@@ -105,6 +106,26 @@ CraftingGridView::CraftingGridView(Text id,
         }
         return 1;
     });
+    recipies = uiFactory.createKnopf(uiFactory.initParam);
+    recipies->setPosition(rowSize * 60, colSize * 60 - 49);
+    recipies->setSize(40, 40);
+    recipies->addStyle(
+        Knopf::Style::HBild | Knopf::Style::HAlpha | Knopf::Style::Hintergrund);
+    recipies->removeStyle(Knopf::Style::Buffered);
+    recipies->setRahmenBreite(1);
+    Framework::LTDBDatei file;
+    file.setDatei(new Framework::Text("data/bilder/gui_icons.ltdb"));
+    file.leseDaten(0);
+    recipies->setHintergrundBildZ(file.laden(0, new Text("recipies.png")));
+    recipies->setMausEreignis([this](void* p, void* o, MausEreignis me) {
+        if (me.id == ME_RLinks)
+        {
+            // Open Item Recipies
+        }
+        return 1;
+    });
+    recipies->setToolTipText(
+        "Recipies", uiFactory.initParam.bildschirm, uiFactory.initParam.schrift);
     setStyle(ZeichnungHintergrund::Style::Sichtbar
              | ZeichnungHintergrund::Style::Erlaubt);
     char* msg = new char[id.getLength() + 12 + 3];
@@ -156,6 +177,7 @@ CraftingGridView::~CraftingGridView()
         target, msg, id.getLength() + 2);
     delete[] msg;
     craft->release();
+    recipies->release();
 }
 
 int CraftingGridView::getSlotByLocalPos(Punkt pos)
@@ -205,10 +227,17 @@ void CraftingGridView::api(char* message)
                     info.durability = *(float*)(message += 4);
                     info.maxDurability = *(float*)(message += 4);
                     info.zItem = zItemType(*(int*)(message += 4))->zIcon();
+                    char len = *(message += 4);
+                    char* name = new char[len + 1];
+                    memcpy(name, message += 1, len);
+                    name[len] = 0;
+                    info.name = name;
+                    delete[] name;
+                    message += len - 4;
                 }
                 slots->add(info);
             }
-            postAction([this, slots]() {
+            window->zBildschirm()->postAction([this, slots]() {
                 if (this->slots) this->slots->release();
                 this->slots = slots;
             });
@@ -258,6 +287,12 @@ void CraftingGridView::api(char* message)
                     info.durability = *(float*)(message + 17);
                     info.maxDurability = *(float*)(message + 21);
                     info.zItem = zItemType(*(int*)(message + 25))->zIcon();
+                    char len = *(message + 29);
+                    char* name = new char[len + 1];
+                    memcpy(name, message + 30, len);
+                    name[len] = 0;
+                    info.name = name;
+                    delete[] name;
                     slots->set(info, i);
                     break;
                 }
@@ -309,7 +344,7 @@ void CraftingGridView::api(char* message)
                 }
                 outputs->add(info);
             }
-            postAction([this, outputs]() {
+            window->zBildschirm()->postAction([this, outputs]() {
                 if (this->outputs) this->outputs->release();
                 this->outputs = outputs;
             });
@@ -350,6 +385,7 @@ void CraftingGridView::render(Bild& rObj)
         }
     }
     craft->render(rObj);
+    recipies->render(rObj);
     rObj.fillRegion(rowSize * 60, gr.y / 2 - 5, 25, 10, 0xFF52525E);
     rObj.drawDreieck(Punkt(rowSize * 60 + 25, gr.y / 2 - 15),
         Punkt(rowSize * 60 + 40, gr.y / 2),
@@ -396,6 +432,7 @@ void CraftingGridView::doMausEreignis(MausEreignis& me, bool userRet)
         }
     }
     craft->doPublicMausEreignis(me);
+    recipies->doPublicMausEreignis(me);
     DragController<InventoryDragSource, int>* controller
         = ((Game*)(Menu*)menuRegister->get("game"))->zInventoryDragController();
     int x = 0;

+ 1 - 0
FactoryCraft/CraftingGrid.h

@@ -42,6 +42,7 @@ private:
     int dragStartId;
     int dragStopId;
     Framework::Knopf* craft;
+    Framework::Knopf* recipies;
     int currentTooltipSlot;
     int requestetTooltipSlot;
     int getSlotByLocalPos(Framework::Punkt pos);

+ 39 - 3
FactoryCraft/Game.cpp

@@ -9,7 +9,8 @@
 #include "StatusBars.h"
 
 Game::Game(Bildschirm* zScreen)
-    : Menu(zScreen)
+    : Menu(zScreen),
+      recipieVisible(0)
 {
     inventoryDragController = new DragController<InventoryDragSource, int>();
     logout = initKnopf(10, 10, 200, 20, Knopf::Style::Normal, "Verlassen");
@@ -52,11 +53,19 @@ Game::Game(Bildschirm* zScreen)
                              | UIMLView::Style::HAlpha);
     targetUIMLView->setHintergrundFarbe(0xA0000000);
     elements.add(targetUIMLView);
+    
+    filter = initTextFeld(zScreen->getBackBufferSize().x / 2 - 200,
+        zScreen->getBackBufferSize().y - 200,
+        400,
+        20,
+        Framework::TextFeld::Style::TextFeld,
+        "");
 }
 
 Game::~Game()
 {
     inventoryDragController->release();
+    filter->release();
 }
 
 void Game::updatePosition(
@@ -117,17 +126,18 @@ void Game::api(char* data)
                 uiml[uimlLen] = 0;
                 UIMLDialog* dialog
                     = new UIMLDialog(uiml, [this](UIMLDialog* dialog) {
-                          logout->postAction([this, dialog]() {
+                          window->zBildschirm()->postAction([this, dialog]() {
                               int index = 0;
                               for (UIMLDialog* d : dialogs)
                               {
                                   if (d == dialog)
                                   {
-                                      dialogs.remove(index);
                                       window->zBildschirm()->removeMember(d);
+                                      dialogs.remove(index);
                                       World::INSTANCE->zKamera()
                                           ->setControlEnabled(
                                               dialogs.getEintragAnzahl() == 0);
+                                      updateRecipieVisibility();
                                       break;
                                   }
                                   index++;
@@ -135,6 +145,7 @@ void Game::api(char* data)
                           });
                       });
                 dialogs.add(dialog);
+                updateRecipieVisibility();
                 World::INSTANCE->zKamera()->setControlEnabled(0);
                 window->zBildschirm()->addMember(dialog);
                 delete[] uiml;
@@ -179,6 +190,7 @@ void Game::closeCurrentDialog()
         dialogs.remove(dialogs.getEintragAnzahl() - 1);
         World::INSTANCE->zKamera()->setControlEnabled(
             dialogs.getEintragAnzahl() == 0);
+        updateRecipieVisibility();
     }
 }
 
@@ -205,4 +217,28 @@ void Game::setTargetUIML(Framework::Text uiml)
     {
         targetUIMLView->removeStyle(UIMLView::Style::Sichtbar);
     }
+}
+
+void Game::updateRecipieVisibility()
+{
+    if (!recipieVisible)
+    {
+        if (dialogs.getEintragAnzahl() > 0)
+        {
+            recipieVisible = 1;
+            window->zBildschirm()->addMember(dynamic_cast<Zeichnung*>(filter->getThis()));
+        }
+    }
+    else
+    {
+        if (dialogs.getEintragAnzahl() == 0)
+        {
+            recipieVisible = 0;
+            window->zBildschirm()->removeMember(filter);
+        }
+    }
+}
+
+const Text* Game::zFilterText() {
+    return filter->zText();
 }

+ 5 - 0
FactoryCraft/Game.h

@@ -19,6 +19,8 @@ private:
     Framework::UIMLView* guiView;
     Framework::UIMLView* targetUIMLView;
     DragController<InventoryDragSource, int>* inventoryDragController;
+    Framework::TextFeld* filter;
+    bool recipieVisible;
 
 public:
     // Konstruktor
@@ -30,4 +32,7 @@ public:
     void closeCurrentDialog();
     DragController<InventoryDragSource, int>* zInventoryDragController();
     void setTargetUIML(Framework::Text uiml);
+
+    void updateRecipieVisibility();
+    const Text* zFilterText();
 };

+ 27 - 3
FactoryCraft/InventoryView.cpp

@@ -65,13 +65,23 @@ void InventoryElement::layout(Framework::XML::Element& element,
 void SlotInfo::render(
     int x, int y, Framework::Bild& rObj, bool selected, bool lightBackground)
 {
+    const Text* filter
+        = dynamic_cast<Game*>((Menu*)menuRegister->get("game"))->zFilterText();
     TextRenderer tr;
     tr.setSchriftZ(
         dynamic_cast<Schrift*>(uiFactory.initParam.schrift->getThis()));
     tr.setSchriftSize(12);
-    rObj.fillRegion(x, y, 52, 52, selected ? 0xFFFFFFFF : 0xFF52525E);
+    bool filterMatch = filter->getLength() > 0 && this->name.hat(filter->getText());
     rObj.fillRegion(
-        x + 1, y + 1, 50, 50, lightBackground ? 0xFF42424E : 0xFF222222);
+        x, y, 52, 52, selected || filterMatch ? 0xFFFFFFFF : 0xFF52525E);
+    rObj.fillRegion(x + 1,
+        y + 1,
+        50,
+        50,
+        lightBackground ? 0xFF42424E
+        : filter->getLength() == 0
+            ? 0xFF222222
+            : (filterMatch ? 0xFF222222 : 0xFF000000));
     if (itemCount > 0)
     {
         rObj.alphaBild(x + 1, y + 1, 50, 50, *zItem);
@@ -217,10 +227,17 @@ void InventoryView::api(char* message)
                     info.durability = *(float*)(message += 4);
                     info.maxDurability = *(float*)(message += 4);
                     info.zItem = zItemType(*(int*)(message += 4))->zIcon();
+                    char len = *(message += 4);
+                    char* name = new char[len + 1];
+                    memcpy(name, message += 1, len);
+                    name[len] = 0;
+                    info.name = name;
+                    delete[] name;
+                    message += len - 4;
                 }
                 slots->add(info);
             }
-            postAction([this, slots]() {
+            window->zBildschirm()->postAction([this, slots]() {
                 if (this->slots) this->slots->release();
                 this->slots = slots;
             });
@@ -239,6 +256,7 @@ void InventoryView::api(char* message)
                     info.itemCount = count;
                     if (info.itemCount == 0)
                     {
+                        info.name = "";
                         DragController<InventoryDragSource, int>* controller
                             = ((Game*)(Menu*)menuRegister->get("game"))
                                   ->zInventoryDragController();
@@ -270,6 +288,12 @@ void InventoryView::api(char* message)
                     info.durability = *(float*)(message + 17);
                     info.maxDurability = *(float*)(message + 21);
                     info.zItem = zItemType(*(int*)(message + 25))->zIcon();
+                    char len = *(message + 29);
+                    char* name = new char[len + 1];
+                    memcpy(name, message + 30, len);
+                    name[len] = 0;
+                    info.name = name;
+                    delete[] name;
                     slots->set(info, i);
                     break;
                 }

+ 1 - 0
FactoryCraft/InventoryView.h

@@ -32,6 +32,7 @@ struct SlotInfo
     float maxHp;
     float durability;
     float maxDurability;
+    Framework::Text name;
     Framework::Bild* zItem;
 
     void render(int x,

+ 14 - 1
FactoryCraft/ItemBar.cpp

@@ -98,10 +98,17 @@ void ItemBarView::api(char* message)
                     info.durability = *(float*)(message += 4);
                     info.maxDurability = *(float*)(message += 4);
                     info.zItem = zItemType(*(int*)(message += 4))->zIcon();
+                    char len = *(message += 4);
+                    char* name = new char[len + 1];
+                    memcpy(name, message += 1, len);
+                    name[len] = 0;
+                    info.name = name;
+                    delete[] name;
+                    message += len - 4;
                 }
                 slots->add(info);
             }
-            postAction([this, slots]() {
+            window->zBildschirm()->postAction([this, slots]() {
                 if (this->slots) this->slots->release();
                 this->slots = slots;
             });
@@ -137,6 +144,12 @@ void ItemBarView::api(char* message)
                     info.durability = *(float*)(message + 17);
                     info.maxDurability = *(float*)(message + 21);
                     info.zItem = zItemType(*(int*)(message + 25))->zIcon();
+                    char len = *(message + 29);
+                    char* name = new char[len + 1];
+                    memcpy(name, message + 30, len);
+                    name[len] = 0;
+                    info.name = name;
+                    delete[] name;
                     slots->set(info, i);
                     break;
                 }