Procházet zdrojové kódy

selected inventory slot is now synchronized for player

Kolja Strohm před 3 roky
rodič
revize
9a17d632df

+ 1 - 1
FactoryCraft/Load.cpp

@@ -461,7 +461,7 @@ LoadMenu::LoadMenu( Bildschirm* zScreen )
     elements.add( stage );
     elements.add( all );
 
-    new AsynchronCall( [this, zScreen]() {
+    new AsynchronCall( "Load Menu", [this, zScreen]() {
         Sleep( 1000 );
         all->setAktionAnzahl( 1 );
         all->reset();

+ 7 - 2
FactoryCraft/Player.cpp

@@ -7,7 +7,8 @@
 
 
 Player::Player()
-    : Entity( PlayerEntityType::INSTANCE, 1 )
+    : Entity( PlayerEntityType::INSTANCE, 1 ),
+    leftHandPosition( 0 )
 {
     setModelDaten( window->zBildschirm()->zGraphicsApi()->getModel( "player" ) );
     Bild* b = new Bild();
@@ -64,7 +65,7 @@ bool Player::tick( double time )
             currentGame->setTarget( 0 );
             ((Game*)(Menu*)menuRegister->get( "game" ))->updatePosition( pos, 0, { 0, 0, 0 } );
         }
-        ((Game*)(Menu*)menuRegister->get( "game" ))->updateInventory( itemBar, 0 ); // todo: pass selected slot
+        ((Game*)(Menu*)menuRegister->get( "game" ))->updateInventory( itemBar, leftHandPosition );
     }
     cs.unlock();
     return Entity::tick( time );
@@ -77,6 +78,10 @@ PlayerEntityType::PlayerEntityType()
 
 void PlayerEntityType::loadSuperEntity( Entity* zEntity, Framework::StreamReader* zReader ) const
 {
+    Player* zPlayer = dynamic_cast<Player*>(zEntity);
+    if( !zPlayer )
+        throw "PlayerEntityType::loadSuperEntity was called with an entity witch is not an instance of Player";
+    zReader->lese( (char*)&zPlayer->leftHandPosition, 4 );
     EntityType::loadSuperEntity( zEntity, zReader );
 }
 

+ 4 - 0
FactoryCraft/Player.h

@@ -5,18 +5,22 @@
 #include "StaticRegistry.h"
 
 class ItemSlot;
+class PlayerEntityType;
 
 class Player : public Entity
 {
 private:
     Framework::Text name;
     Framework::Array<ItemSlot*> itemBar;
+    int leftHandPosition;
 
 public:
     Player();
     ~Player();
 
     virtual bool tick( double time ) override;
+
+    friend PlayerEntityType;
 };
 
 class PlayerEntityType : public EntityType

+ 10 - 1
FactoryCraft/PlayerKam.cpp

@@ -66,6 +66,15 @@ void PlayerKam::doTastaturEreignis( Framework::TastaturEreignis& te )
             action[ 1 ] = 7;
             network->zFactoryClient()->sendPlayerAction( action, 2 );
         }
+        if( te.taste >= '0' && te.taste <= '9' )
+        {
+            char action[ 5 ];
+            action[ 0 ] = 3;
+            *(int*)(action + 1) = te.taste - '1';
+            if( *(int*)(action + 1) < 0 )
+                *(int*)(action + 1) = 9;
+            network->zFactoryClient()->sendPlayerAction( &action, 5 );
+        }
     }
     if( te.id == TE_Release )
     {
@@ -180,7 +189,7 @@ void PlayerKam::doMausEreignis( Framework::MausEreignis& me )
                     network->zFactoryClient()->sendPlayerAction( action, 2 );
                 }
             }
-            
+
         }
         me.verarbeitet = 1;
     }