Quellcode durchsuchen

add uiml tooltips describing the currently targeted block

Kolja Strohm vor 2 Jahren
Ursprung
Commit
87ec3841ea

+ 11 - 5
FactoryCraft/BasicBlock.cpp

@@ -60,18 +60,24 @@ void AdditionalItemSpawningBlock::onDestroy()
     BasicBlock::onDestroy();
 }
 
-BasicBlockType::BasicBlockType(int typeId, int itemTypeId, ModelInfo model)
+BasicBlockType::BasicBlockType(
+    int typeId, int itemTypeId, ModelInfo model, const char* name)
     : BasicBlockType(
-        typeId, itemTypeId, model, [typeId](Framework::Vec3<int> pos) {
+        typeId,
+        itemTypeId,
+        model,
+        [typeId](Framework::Vec3<int> pos) {
             return new BasicBlock(typeId, 0, pos);
-        })
+        },
+        name)
 {}
 
 BasicBlockType::BasicBlockType(int typeId,
     int itemTypeId,
     ModelInfo model,
-    std::function<Block*(Framework::Vec3<int>)> creatBlockCustom)
-    : BlockType(typeId, 0, model, 1, 100, 0),
+    std::function<Block*(Framework::Vec3<int>)> creatBlockCustom,
+    const char* name)
+    : BlockType(typeId, 0, model, 1, 100, 0, name),
       itemType(itemTypeId),
       transparent(0),
       passable(0),

+ 4 - 2
FactoryCraft/BasicBlocks.h

@@ -55,11 +55,13 @@ protected:
     virtual void createSuperBlock(Block* zBlock, Item* zItem) const override;
 
 public:
-    BasicBlockType(int typeId, int itemTypeId, ModelInfo model);
+    BasicBlockType(
+        int typeId, int itemTypeId, ModelInfo model, const char* name);
     BasicBlockType(int typeId,
         int itemTypeId,
         ModelInfo model,
-        std::function<Block*(Framework::Vec3<int>)> creatBlockCustom);
+        std::function<Block*(Framework::Vec3<int>)> creatBlockCustom,
+        const char* name);
     virtual Block* createBlock(Framework::Vec3<int> position) const override;
     virtual Item* createItem() const override;
     BasicBlockType* setHardness(float hardness);

+ 5 - 0
FactoryCraft/Block.cpp

@@ -169,6 +169,11 @@ void Block::onUnloaded()
         structure->onBlockUnloaded(this);
 }
 
+Framework::Text Block::getTargetUIML()
+{
+    return StaticRegistry<BlockType>::INSTANCE.zElement(typeId)->getTargetUIML();
+}
+
 void api(Framework::StreamReader* zRequest, NetworkMessage* zResponse)
 {
     // TODO: answer api requests

+ 1 - 0
FactoryCraft/Block.h

@@ -88,6 +88,7 @@ public:
         Direction dir, Framework::Either<Block*, int> neighbor);
     virtual void setNeighbourBlock(Direction dir, Block* zN);
     virtual void setNeighbourType(Direction dir, int type);
+    virtual Framework::Text getTargetUIML();
 
     void api(Framework::StreamReader* zRequest, NetworkMessage* zResponse);
 

+ 10 - 2
FactoryCraft/BlockType.cpp

@@ -13,14 +13,16 @@ BlockType::BlockType(int id,
     ModelInfo model,
     bool needsClientInstance,
     int initialMaxHP,
-    bool lightSource)
+    bool lightSource,
+    const char* name)
     : ReferenceCounter(),
       id(id),
       model(model),
       initialMaxHP(initialMaxHP),
       needsClientInstance(needsClientInstance),
       lightSource(lightSource),
-      defaultBlock(defaultBlock)
+      defaultBlock(defaultBlock),
+      name(name)
 {
     StaticRegistry<BlockType>::INSTANCE.registerT(this, id);
 }
@@ -121,6 +123,12 @@ void BlockType::createSuperItem(Block* zBlock, Item* zItem) const
     item->interactable = zBlock->interactable;
 }
 
+Framework::Text BlockType::getTargetUIML() const
+{
+    return Text("<targetInfo><text width=\"auto\" height=\"auto\">") + name
+         + "</text></targetInfo>";
+}
+
 Block* BlockType::loadBlock(Framework::Vec3<int> position,
     Framework::StreamReader* zReader,
     int dimensionId) const

+ 3 - 1
FactoryCraft/BlockType.h

@@ -48,6 +48,7 @@ private:
     int initialMaxHP;
     const bool needsClientInstance;
     bool lightSource;
+    const char* name;
 
 protected:
     Block* defaultBlock;
@@ -56,7 +57,7 @@ protected:
         ModelInfo model,
         bool needsClientInstance,
         int initialMaxHP,
-        bool lightSource);
+        bool lightSource, const char *name);
     virtual ~BlockType();
 
     virtual void loadSuperBlock(
@@ -69,6 +70,7 @@ protected:
     virtual Item* createItem() const = 0;
 
 public:
+    virtual Framework::Text getTargetUIML() const;
     virtual Block* loadBlock(Framework::Vec3<int> position,
         Framework::StreamReader* zReader,
         int dimensionId) const;

+ 22 - 3
FactoryCraft/Entity.cpp

@@ -1,5 +1,7 @@
 #include "Entity.h"
 
+#include <Text.h>
+
 #include "BlockType.h"
 #include "Dimension.h"
 #include "EntityRemovedUpdate.h"
@@ -64,7 +66,8 @@ void ActionTarget::placeBlock(Entity* zActor, Item* zItem)
     }
 }
 
-void ActionTarget::toMessage(const ActionTarget* zTarget, NetworkMessage* zMsg)
+void ActionTarget::toMessage(
+    const ActionTarget* zTarget, int dimensionId, NetworkMessage* zMsg)
 {
     if (zTarget)
     {
@@ -78,14 +81,30 @@ void ActionTarget::toMessage(const ActionTarget* zTarget, NetworkMessage* zMsg)
         }
         else
         {
-            char* message = new char[18];
+            Framework::Text targetUIML = "";
+            auto block
+                = Game::INSTANCE->zBlockAt(zTarget->blockPos, dimensionId);
+            if (block.isA())
+            {
+                targetUIML = block.getA()->getTargetUIML();
+            }
+            else if (block.isB())
+            {
+                targetUIML = StaticRegistry<BlockType>::INSTANCE
+                                 .zElement(block.getB())
+                                 ->getTargetUIML();
+            }
+            char* message = new char[18 + targetUIML.getLength() + 2];
             message[0] = 3;
             message[1] = 2;
             *(int*)(message + 2) = zTarget->blockPos.x;
             *(int*)(message + 6) = zTarget->blockPos.y;
             *(int*)(message + 10) = zTarget->blockPos.z;
             *(int*)(message + 14) = zTarget->targetBlockSide;
-            zMsg->setMessage(message, 18);
+            short len = (short)targetUIML.getLength();
+			*(short*)(message + 18) = len;
+			memcpy(message + 20, targetUIML.getText(), len);
+            zMsg->setMessage(message, 18 + len + 2);
         }
     }
     else

+ 2 - 1
FactoryCraft/Entity.h

@@ -32,7 +32,8 @@ public:
         Entity* zActor, ItemSkill* zItemSkill, Item* zUsedItem);
     void placeBlock(Entity* zActor, Item* zItem);
 
-    static void toMessage(const ActionTarget* zTarget, NetworkMessage* zMsg);
+    static void toMessage(
+        const ActionTarget* zTarget, int dimensionId, NetworkMessage* zMsg);
     static void save(ActionTarget* zTarget, Framework::StreamWriter* zWriter);
     static ActionTarget* load(Framework::StreamReader* zReader);
 };

+ 2 - 2
FactoryCraft/LightSources.cpp

@@ -68,8 +68,8 @@ bool BasicLightSource::onTick(TickQueue* zQueue, int numTicks, bool& blocked)
 void BasicLightSource::onPostTick() {}
 
 BasicLightSourceBlockType::BasicLightSourceBlockType(
-    int typeId, int itemTypeId, ModelInfo model)
-    : BlockType(typeId, 0, model, 1, 1, 1),
+    int typeId, int itemTypeId, ModelInfo model, const char* name)
+    : BlockType(typeId, 0, model, 1, 1, 1, name),
       itemType(itemTypeId),
       transparent(1),
       passable(1),

+ 1 - 1
FactoryCraft/LightSources.h

@@ -71,7 +71,7 @@ protected:
         Block* zBlock, Framework::StreamWriter* zWriter) const override;
 
 public:
-    BasicLightSourceBlockType(int typeId, int itemTypeId, ModelInfo model);
+    BasicLightSourceBlockType(int typeId, int itemTypeId, ModelInfo model, const char *name);
     virtual Block* createBlock(Framework::Vec3<int> position) const override;
     virtual Item* createItem() const override;
     BasicLightSourceBlockType* setHardness(float hardness);

+ 0 - 1
FactoryCraft/NetworkMessage.h

@@ -25,7 +25,6 @@ public:
     void addressChunck(Chunk* zChunk);
     void addressEntity(Entity* zEntity);
     void addressBlock(Block* zBlock);
-    ;
     void addressDimension();
     void openDialog(Framework::Text dialogName);
     void addressGui(Framework::Text elementId);

+ 1 - 1
FactoryCraft/NoBlock.cpp

@@ -1,7 +1,7 @@
 #include "NoBlock.h"
 
 NoBlockBlockType::NoBlockBlockType(int id, const Block* defaultB)
-    : BlockType(id, 0, ModelInfo("", "", 0), 0, 1, 0),
+    : BlockType(id, 0, ModelInfo("", "", 0), 0, 1, 0, ""),
       defaultB(defaultB)
 {}
 

+ 1 - 1
FactoryCraft/Player.cpp

@@ -39,7 +39,7 @@ Player::Player(Framework::Vec3<float> location, int dimensionId, int entityId)
 void Player::onTargetChange()
 {
     NetworkMessage* msg = new NetworkMessage();
-    ActionTarget::toMessage(zTarget(), msg);
+    ActionTarget::toMessage(zTarget(), getCurrentDimensionId(), msg);
     Game::INSTANCE->sendMessage(msg, this);
 }
 

+ 39 - 20
FactoryCraft/StaticInitializerOrder.cpp

@@ -36,21 +36,25 @@ void initializeBlockTypes()
                  "blocks.ltdb/dirt.png",
                  "blocks.ltdb/dirt.png",
                  "blocks.ltdb/lawn.png",
-                 "blocks.ltdb/dirt.png"})))
+                 "blocks.ltdb/dirt.png"}),
+         "Dirt"))
         ->initializeDefault();
     (new BasicBlockType(BlockTypeEnum::STONE,
          ItemTypeEnum::STONE,
-         ModelInfo("cube", "blocks.ltdb/stone.png", 6)))
+         ModelInfo("cube", "blocks.ltdb/stone.png", 6),
+         "Stone"))
         ->setHardness(2.f)
         ->initializeDefault();
     (new BasicBlockType(BlockTypeEnum::SAND,
          ItemTypeEnum::SAND,
-         ModelInfo("cube", "blocks.ltdb/sand.png", 6)))
+         ModelInfo("cube", "blocks.ltdb/sand.png", 6),
+         "Sand"))
         ->setHardness(0.5f)
         ->initializeDefault();
     (new BasicBlockType(BlockTypeEnum::WOOD_OAK,
          ItemTypeEnum::WOOD_OAK,
-         ModelInfo("cube", "blocks.ltdb/oak.png", 6)))
+         ModelInfo("cube", "blocks.ltdb/oak.png", 6),
+         "Oak Wood"))
         ->setHardness(1.5f)
         ->initializeDefault();
     (new BasicBlockType(BlockTypeEnum::LEAVES_WOOD_OAK,
@@ -62,28 +66,33 @@ void initializeBlockTypes()
                      BlockTypeEnum::LEAVES_WOOD_OAK, 0, pos);
              block->addSpawn({1, 1, 0.015, ItemTypeEnum::SEBLING_WOOD_OAK});
              return (Block*)block;
-         }))
+         },
+         "Oak Wood Leaves"))
         ->setHardness(0.1f)
         ->initializeDefault();
 
     (new BasicBlockType(BlockTypeEnum::GRAVEL,
          ItemTypeEnum::GRAVEL,
-         ModelInfo("cube", "blocks.ltdb/gravel.png", 6)))
+         ModelInfo("cube", "blocks.ltdb/gravel.png", 6),
+         "Gravel"))
         ->setHardness(0.75f)
         ->initializeDefault();
     (new BasicBlockType(BlockTypeEnum::STONE_GRANITE,
          ItemTypeEnum::STONE_GRANITE,
-         ModelInfo("cube", "blocks.ltdb/granite.png", 6)))
+         ModelInfo("cube", "blocks.ltdb/granite.png", 6),
+         "Granite Stone"))
         ->setHardness(3.f)
         ->initializeDefault();
     (new BasicBlockType(BlockTypeEnum::STONE_COBBLE,
          ItemTypeEnum::STONE_COBBLE,
-         ModelInfo("cube", "blocks.ltdb/cobble.png", 6)))
+         ModelInfo("cube", "blocks.ltdb/cobble.png", 6),
+         "Cobble Stone"))
         ->setHardness(1.f)
         ->initializeDefault();
     (new BasicBlockType(BlockTypeEnum::WOOD_BIRCH,
          ItemTypeEnum::WOOD_BIRCH,
-         ModelInfo("cube", "blocks.ltdb/birch.png", 6)))
+         ModelInfo("cube", "blocks.ltdb/birch.png", 6),
+         "Birch Wood"))
         ->setHardness(1.5f)
         ->initializeDefault();
     (new BasicBlockType(BlockTypeEnum::LEAVES_WOOD_BIRCH,
@@ -95,13 +104,15 @@ void initializeBlockTypes()
                      BlockTypeEnum::LEAVES_WOOD_BIRCH, 0, pos);
              block->addSpawn({1, 1, 0.03, ItemTypeEnum::SEBLING_WOOD_BIRCH});
              return (Block*)block;
-         }))
+         },
+         "Birch Wood Leaves"))
         ->setHardness(0.1f)
         ->initializeDefault();
 
     (new BasicBlockType(BlockTypeEnum::WOOD_BEECH,
          ItemTypeEnum::WOOD_BEECH,
-         ModelInfo("cube", "blocks.ltdb/beech.png", 6)))
+         ModelInfo("cube", "blocks.ltdb/beech.png", 6),
+         "Beech Wood"))
         ->setHardness(1.5f)
         ->initializeDefault();
     (new BasicBlockType(BlockTypeEnum::LEAVES_WOOD_BEECH,
@@ -113,18 +124,21 @@ void initializeBlockTypes()
                      BlockTypeEnum::LEAVES_WOOD_BEECH, 0, pos);
              block->addSpawn({1, 1, 0.02, ItemTypeEnum::SEBLING_WOOD_BEECH});
              return (Block*)block;
-         }))
+         },
+         "Beech Wood Leaves"))
         ->setHardness(0.1f)
         ->initializeDefault();
 
     (new BasicBlockType(BlockTypeEnum::STONE_BASALT,
          ItemTypeEnum::STONE_BASALT,
-         ModelInfo("cube", "blocks.ltdb/basalt.png", 6)))
+         ModelInfo("cube", "blocks.ltdb/basalt.png", 6),
+         "Basalt Stone"))
         ->setHardness(2.f)
         ->initializeDefault();
     (new BasicBlockType(BlockTypeEnum::WOOD_PINE,
          ItemTypeEnum::WOOD_PINE,
-         ModelInfo("cube", "blocks.ltdb/pine.png", 6)))
+         ModelInfo("cube", "blocks.ltdb/pine.png", 6),
+         "Pine Wood"))
         ->setHardness(1.4f)
         ->initializeDefault();
     (new BasicBlockType(BlockTypeEnum::LEAVES_WOOD_PINE,
@@ -136,13 +150,15 @@ void initializeBlockTypes()
                      BlockTypeEnum::LEAVES_WOOD_PINE, 0, pos);
              block->addSpawn({1, 1, 0.025, ItemTypeEnum::SEBLING_WOOD_PINE});
              return (Block*)block;
-         }))
+         },
+         "Pine Wood Leaves"))
         ->setHardness(0.1f)
         ->initializeDefault();
 
     (new BasicLightSourceBlockType(BlockTypeEnum::TORCH,
          ItemTypeEnum::TORCH,
-         ModelInfo("blocks.m3/torch", "blocks.ltdb/torch.png", 6)))
+         ModelInfo("blocks.m3/torch", "blocks.ltdb/torch.png", 6),
+         "Torch"))
         ->setHardness(0.f)
         ->setColor(0x00F69A54)
         ->initializeDefault();
@@ -151,28 +167,31 @@ void initializeBlockTypes()
          ItemTypeEnum::SEBLING_WOOD_OAK,
          ModelInfo("blocks.m3/sebling", "blocks.ltdb/sebling.png", 1),
          BlockTypeEnum::WOOD_OAK,
-         BlockTypeEnum::LEAVES_WOOD_OAK))
+         BlockTypeEnum::LEAVES_WOOD_OAK,
+         "Oak Wood Sebling"))
         ->setHardness(0.1f)
         ->initializeDefault();
     (new TreeSeblingBlockType(BlockTypeEnum::SEBLING_WOOD_BIRCH,
          ItemTypeEnum::SEBLING_WOOD_BIRCH,
          ModelInfo("blocks.m3/sebling", "blocks.ltdb/sebling.png", 1),
          BlockTypeEnum::WOOD_BIRCH,
-         BlockTypeEnum::LEAVES_WOOD_BIRCH))
+         BlockTypeEnum::LEAVES_WOOD_BIRCH,
+         "Birch Wood Sebling"))
         ->setHardness(0.1f)
         ->initializeDefault();
     (new TreeSeblingBlockType(BlockTypeEnum::SEBLING_WOOD_BEECH,
          ItemTypeEnum::SEBLING_WOOD_BEECH,
          ModelInfo("blocks.m3/sebling", "blocks.ltdb/sebling.png", 1),
          BlockTypeEnum::WOOD_BEECH,
-         BlockTypeEnum::LEAVES_WOOD_BEECH))
+         BlockTypeEnum::LEAVES_WOOD_BEECH,
+         "Beech Wood Sebling"))
         ->setHardness(0.1f)
         ->initializeDefault();
     (new TreeSeblingBlockType(BlockTypeEnum::SEBLING_WOOD_PINE,
          ItemTypeEnum::SEBLING_WOOD_PINE,
          ModelInfo("blocks.m3/sebling", "blocks.ltdb/sebling.png", 1),
          BlockTypeEnum::WOOD_PINE,
-         BlockTypeEnum::LEAVES_WOOD_PINE))
+         BlockTypeEnum::LEAVES_WOOD_PINE, "Pine Wood Sebling"))
         ->setHardness(0.1f)
         ->initializeDefault();
 }

+ 7 - 3
FactoryCraft/TreeSeblingBlock.cpp

@@ -49,9 +49,13 @@ void TreeSeblingBlock::onPostTick()
     }
 }
 
-TreeSeblingBlockType::TreeSeblingBlockType(
-    int typeId, int itemTypeId, ModelInfo model, int woodType, int leavesType)
-    : BlockType(typeId, 0, model, 1, 10, 0),
+TreeSeblingBlockType::TreeSeblingBlockType(int typeId,
+    int itemTypeId,
+    ModelInfo model,
+    int woodType,
+    int leavesType,
+    const char* name)
+    : BlockType(typeId, 0, model, 1, 10, 0, name),
       itemType(itemTypeId),
       transparent(true),
       passable(true),

+ 3 - 2
FactoryCraft/TreeSeblingBlock.h

@@ -39,7 +39,7 @@ private:
     int leavesType;
 
 protected:
-    virtual void createSuperBlock(Block* zBlock, Item* zItem) const override;
+    virtual void createSuperBlock(Block* zBlock, Item* zItem ) const override;
     virtual void loadSuperBlock(Block* zBlock,
         Framework::StreamReader* zReader,
         int dimensionId) const override;
@@ -53,6 +53,7 @@ public:
         int itemTypeId,
         ModelInfo model,
         int woodType,
-        int leavesType);
+        int leavesType,
+        const char* name);
     TreeSeblingBlockType* setHardness(float hardness);
 };