Bläddra i källkod

show pre rendered item icons in inventory

Kolja Strohm 3 år sedan
förälder
incheckning
78c0d3e0fc

+ 3 - 3
FactoryCraft/BasicBlocks.cpp

@@ -14,7 +14,7 @@ BasicBlock::BasicBlock( const BlockType* zType, const char* texture, ItemType* z
     setModelDaten( data );
     Bild* b = new Bild();
     b->neuBild( 10, 10, 0xFFFFFFFF );
-    Textur* tex = currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( texture, 0 );
+    Textur* tex = uiFactory.initParam.bildschirm->zGraphicsApi()->createOrGetTextur( texture, 0 );
     if( !tex->zBild() )
         tex->setBildZ( b );
     else
@@ -27,7 +27,7 @@ BasicBlock::BasicBlock( const BlockType* zType, const char* texture, ItemType* z
     textur->setPolygonTextur( 4, dynamic_cast<Textur*>(tex->getThis()) );
     textur->setPolygonTextur( 5, tex );
     setModelTextur( textur );
-    breakTextur = currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( "blocks.ltdb/crack.png", 0 );
+    breakTextur = uiFactory.initParam.bildschirm->zGraphicsApi()->createOrGetTextur( "blocks.ltdb/crack.png", 0 );
 }
 
 BasicBlock::~BasicBlock()
@@ -98,7 +98,7 @@ DirtBlockType::DirtBlockType()
 Block* DirtBlockType::createBlock( Framework::Vec3<int> position )
 {
     Block* b = BasicBlockType::createBlock( position );
-    b->zTextur()->setPolygonTextur( 4, currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( "blocks.ltdb/lawn.png", 0 ) );
+    b->zTextur()->setPolygonTextur( 4, uiFactory.initParam.bildschirm->zGraphicsApi()->createOrGetTextur( "blocks.ltdb/lawn.png", 0 ) );
     return b;
 }
 

+ 3 - 3
FactoryCraft/Block.cpp

@@ -59,7 +59,7 @@ BasicBlockItem::BasicBlockItem( const ItemType* zType, const char* name )
 
 
 BasicBlockItemType::BasicBlockItemType( int id, const char* name, const char* texturPath )
-    : ItemType( id ),
+    : ItemType( id, name ),
     name( name ),
     texturPath( texturPath )
 {}
@@ -82,7 +82,7 @@ void BasicBlockItemType::loadSuperItem( Item* zItem, Framework::StreamReader* zR
 
 Framework::Model3DData* BasicBlockItemType::getItemModel() const
 {
-    return window->zBildschirm()->zGraphicsApi()->getModel( "itemCube" );
+    return uiFactory.initParam.bildschirm->zGraphicsApi()->getModel( "itemCube" );
 }
 
 Item* BasicBlockItemType::createItem() const
@@ -93,7 +93,7 @@ Item* BasicBlockItemType::createItem() const
 Framework::Model3DTextur* BasicBlockItemType::getItemTextur() const
 {
     Model3DTextur* textur = new Model3DTextur();
-    Textur* tex = currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( texturPath, 0 );
+    Textur* tex = uiFactory.initParam.bildschirm->zGraphicsApi()->createOrGetTextur( texturPath, 0 );
     textur->setPolygonTextur( 0, dynamic_cast<Textur*>(tex->getThis()) );
     textur->setPolygonTextur( 1, dynamic_cast<Textur*>(tex->getThis()) );
     textur->setPolygonTextur( 2, dynamic_cast<Textur*>(tex->getThis()) );

+ 5 - 3
FactoryCraft/Game.cpp

@@ -76,14 +76,16 @@ void Game::updateInventory( Framework::Array<ItemSlot*>& itemBar, int pos )
         }
         if( slot && slot->zStack() && slot->zStack()->zItem() )
         {
+            Bild* icon = itemIcons->z( slot->zStack()->zItem()->zItemType()->getId() );
+            invB->alphaBild( 50 * index, 0, 50, 50, *icon );
             tr.renderText( 5 + index * 50, 5, slot->zStack()->zItem()->getName(), *invB, 0xFFFFFFFF );
             int size = slot->zStack()->getSize();
             const char* units[] = { "", "K", "M", "G", "T", "P" };
-            int index = 0;
-            for( ; index < 6 && size > 1024; index++ )
+            int i = 0;
+            for( ; i < 6 && size > 1024; i++ )
                 size = size / 1024;
             Text count = size;
-            count += units[ index ];
+            count += units[ i ];
             tr.renderText( 45 - tr.getTextBreite( count ) + index * 50, 45 - tr.getTextHeight( count ), count, *invB, 0xFFFFFFFF );
         }
         index++;

+ 2 - 0
FactoryCraft/Globals.cpp

@@ -19,6 +19,7 @@ void initVariables()
     network = new NetworkHandler();
     currentGame = 0;
     window = 0;
+    itemIcons = new RCArray<Bild>();
 }
 
 void initMenus()
@@ -39,4 +40,5 @@ void releaseVariables()
     fontRegister->release();
     network->release();
     dlls->release();
+    itemIcons->release();
 }

+ 1 - 0
FactoryCraft/Globals.h

@@ -23,6 +23,7 @@ variable NetworkHandler* network;
 variable DLLRegister* dlls;
 variable World* currentGame;
 variable Framework::WFenster* window;
+variable RCArray<Bild>* itemIcons;
 
 
 void initVariables();

+ 8 - 2
FactoryCraft/ItemType.cpp

@@ -5,9 +5,10 @@
 #include "ItemStack.h"
 #include "Registries.h"
 
-ItemType::ItemType( int id )
+ItemType::ItemType( int id, const char* defaultName )
     : ReferenceCounter(),
-    id( id )
+    id( id ),
+    defaultName( defaultName )
 {
     STATIC_REGISTRY( ItemType ).registerT( this, id );
 }
@@ -53,4 +54,9 @@ Item* ItemType::loadItem( Framework::StreamReader* zReader ) const
     Item* item = createItem();
     loadSuperItem( item, zReader );
     return item;
+}
+
+const char* ItemType::getDefaultItemName() const
+{
+    return defaultName;
 }

+ 3 - 1
FactoryCraft/ItemType.h

@@ -16,8 +16,9 @@ class ItemType : public virtual Framework::ReferenceCounter
 {
 protected:
     const int id;
+    const char* defaultName;
 
-    ItemType( int id );
+    ItemType( int id, const char* defaultName );
 
     virtual void loadSuperItem( Item* zItem, Framework::StreamReader* zReader ) const;
 
@@ -30,4 +31,5 @@ public:
     virtual Item* loadItem( Framework::StreamReader* zReader ) const;
     virtual Framework::Model3DData* getItemModel() const = 0;
     virtual Framework::Model3DTextur* getItemTextur() const = 0;
+    const char* getDefaultItemName() const;
 };

+ 40 - 1
FactoryCraft/Load.cpp

@@ -7,6 +7,8 @@
 #include <Text.h>
 #include "Globals.h"
 #include <Textur.h>
+#include <GraphicsApi.h>
+#include "Login.h"
 
 void createDefaultCube( Bildschirm* zScreen )
 {
@@ -463,7 +465,7 @@ LoadMenu::LoadMenu( Bildschirm* zScreen )
 
     new AsynchronCall( "Load Menu", [this, zScreen]() {
         Sleep( 1000 );
-        all->setAktionAnzahl( 1 );
+        all->setAktionAnzahl( 2 );
         all->reset();
         // loading textures
         Datei texturF;
@@ -498,8 +500,45 @@ LoadMenu::LoadMenu( Bildschirm* zScreen )
         }
         createModels( zScreen );
         all->aktionPlus();
+        stage->reset();
+        stage->setAktionAnzahl( STATIC_REGISTRY( ItemType ).getCount() );
+        // pre rendering item icons
+        Kam3D* kam = new Kam3D();
+        Welt3D* w = new Welt3D();
+        w->addDiffuseLight( DiffuseLight{ Vec3<float>( 0.5f, 0.5f, -1.f ), Vec3<float>( 1.f, 1.f, 1.f ) } );
+        kam->setWelt( w );
+        kam->setBildschirmPosition( 0, 0 );
+        kam->setBildschirmSize( 50, 50 );
+        kam->setPosition( Vec3<float>( 0, 0, 0 ) );
+        kam->setRotation( { 2.f, 0, -1.f } );
+        Bild* b = new Bild();
+        b->neuBild( 50, 50, 0 );
+        for( int i = 0; i < STATIC_REGISTRY( ItemType ).getCount(); i++ )
+        {
+            Model3D* mdl = new Model3D();
+            mdl->setModelDaten( STATIC_REGISTRY( ItemType ).zElement( i )->getItemModel() );
+            mdl->setModelTextur( STATIC_REGISTRY( ItemType ).zElement( i )->getItemTextur() );
+            mdl->setPosition( Vec3<float>( -0.8f, -0.45f, -0.4f ) );
+            mdl->setSize( 2.f );
+            w->addZeichnung( mdl );
+            w->tick( 0 );
+            zScreen->lock();
+            DX11Textur* t = (DX11Textur*)zScreen->zGraphicsApi()->createOrGetTextur( Text( "rendered/items/" ) + STATIC_REGISTRY( ItemType ).zElement( i )->getDefaultItemName(), dynamic_cast<Bild*>(b->getThis()) );
+            zScreen->zGraphicsApi()->renderKamera( kam, t );
+            Bild* result = new Bild();
+            t->copyToImage( result );
+            itemIcons->add( result );
+            t->release();
+            zScreen->unlock();
+            w->removeZeichnung( mdl );
+            stage->aktionPlus();
+        }
+        b->release();
+        kam->release();
+        all->aktionPlus();
         zScreen->lock();
         hide();
+        ((LoginMenu*)(Menu*)menuRegister->get( "login" ))->onLoadingFinished();
         menuRegister->get( "login" )->show();
         zScreen->unlock();
     } );

+ 4 - 1
FactoryCraft/Login.cpp

@@ -31,4 +31,7 @@ LoginMenu::LoginMenu( Bildschirm* zScreen )
         return 1;
     } );
     elements.add( login );
-}
+}
+
+void LoginMenu::onLoadingFinished()
+{}

+ 1 - 0
FactoryCraft/Login.h

@@ -12,4 +12,5 @@ private:
 
 public:
     LoginMenu( Bildschirm* zScreen );
+    void onLoadingFinished();
 };

+ 1 - 0
FactoryCraft/Main.cpp

@@ -16,6 +16,7 @@ int KSGStart Framework::Start( Framework::Startparam p )
 {
     Network::Start( 20 );
     initVariables();
+    setDebugDX( 0 );
 
     Datei d;
     d.setDatei( "data/schriften" );

+ 2 - 2
FactoryCraft/Player.cpp

@@ -10,10 +10,10 @@ Player::Player()
     : Entity( PlayerEntityType::INSTANCE, 1 ),
     leftHandPosition( 0 )
 {
-    setModelDaten( window->zBildschirm()->zGraphicsApi()->getModel( "player" ) );
+    setModelDaten( uiFactory.initParam.bildschirm->zGraphicsApi()->getModel( "player" ) );
     Bild* b = new Bild();
     b->neuBild( 10, 10, 0xFFFFFFFF );
-    Textur* tex = currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( "player", 0 );
+    Textur* tex = uiFactory.initParam.bildschirm->zGraphicsApi()->createOrGetTextur( "player", 0 );
     if( !tex->zBild() )
         tex->setBildZ( b );
     else

+ 1 - 1
FactoryCraft/StaticRegistry.h

@@ -20,7 +20,7 @@ private:
 public:
     StaticRegistry()
     {
-        count = 100;
+        count = 1;
         registry = new T * [ count ];
         memset( registry, 0, sizeof( T* ) * count );
     }

+ 0 - 5
FactoryCraft/World.cpp

@@ -179,11 +179,6 @@ void World::setVisibility( Entity* zEntity, bool visible )
     renderedWorld->unlock();
 }
 
-Framework::Bildschirm3D* World::zScreen() const
-{
-    return zScreenPtr;
-}
-
 Framework::Punkt World::getChunkCenter( int x, int y ) const
 {
     return Punkt( ((x < 0 ? x + 1 : x) / CHUNK_SIZE) * CHUNK_SIZE + (x < 0 ? -CHUNK_SIZE : CHUNK_SIZE) / 2, ((y < 0 ? y + 1 : y) / CHUNK_SIZE) * CHUNK_SIZE + (y < 0 ? -CHUNK_SIZE : CHUNK_SIZE) / 2 );

+ 0 - 1
FactoryCraft/World.h

@@ -37,7 +37,6 @@ public:
     Dimension* zDimensionOrCreate( int id );
     void setVisibility( Chunk* zChunk, bool visible );
     void setVisibility( Entity* zEntity, bool visible );
-    Framework::Bildschirm3D* zScreen() const;
     Framework::Punkt getChunkCenter( int x, int y ) const;
     Entity* zEntity( int id ) const;
     Entity* getEntity( int id ) const;

+ 94 - 0
enc_temp_folder/3a42a274dd97048b8aa306a3eb81718/Game.cpp

@@ -0,0 +1,94 @@
+#include "Game.h"
+#include "Initialisierung.h"
+#include "Globals.h"
+
+#include <AsynchronCall.h>
+#include <Bildschirm.h>
+
+Game::Game( Bildschirm* zScreen )
+    : Menu( zScreen )
+{
+    logout = initKnopf( 10, 10, 200, 20, Knopf::Style::Normal, "Verlassen" );
+    logout->setMausEreignis( [this, zScreen]( void* p, void* o, MausEreignis me ) {
+        if( me.id == ME_RLinks )
+        {
+            logout->removeStyle( Knopf::Style::Erlaubt );
+            new AsynchronCall( [this, zScreen]() {
+                if( network->leaveGame() )
+                {
+                    currentGame->release();
+                    currentGame = 0;
+                    zScreen->lock();
+                    hide();
+                    menuRegister->get( "directConnect" )->show();
+                    zScreen->unlock();
+                }
+                logout->addStyle( Knopf::Style::Erlaubt );
+            } );
+        }
+        return 1;
+    } );
+    elements.add( logout );
+    debug = initTextFeld( 10, 40, 500, 40, TextFeld::Style::Text | TextFeld::Style::Mehrzeilig, "" );
+    elements.add( debug );
+    invB = new Bild();
+    invB->neuBild( zScreen->getBackBufferSize().x - 20, 50, 0 );
+    invB->setAlpha3D( 1 );
+    inventory = initBildZ( 10, zScreen->getBackBufferSize().y - 60, zScreen->getBackBufferSize().x - 20, 50, BildZ::Style::Sichtbar | BildZ::Style::Alpha, invB );
+    elements.add( inventory );
+}
+
+void Game::updatePosition( Vec3<float> position, bool target, Vec3<int> targetPos )
+{
+    Text txt = "Position: (";
+    txt.setPrecision( 2 );
+    txt += position.x;
+    txt += ", ";
+    txt += position.y;
+    txt += ", ";
+    txt += position.z;
+    txt += ")";
+    if( target )
+    {
+        txt += "\nTarget: (";
+        txt += targetPos.x;
+        txt += ", ";
+        txt += targetPos.y;
+        txt += ", ";
+        txt += targetPos.z;
+        txt += ")";
+    }
+    debug->setText( txt );
+}
+
+void Game::updateInventory( Framework::Array<ItemSlot*>& itemBar, int pos )
+{
+    invB->fillRegion( 0, 0, invB->getBreite(), invB->getHeight(), 0 );
+    TextRenderer tr;
+    tr.setSchriftZ( dynamic_cast<Schrift*>(uiFactory.initParam.schrift->getThis()) );
+    tr.setSchriftSize( 12 );
+    int index = 0;
+    for( auto slot : itemBar )
+    {
+        if( pos == index )
+        {
+            invB->fillRegion( 50 * index, 0, 50, 50, 0x7F202020 );
+        }
+        if( slot && slot->zStack() && slot->zStack()->zItem() )
+        {
+            Bild* icon = itemIcons->z( slot->zStack()->zItem()->zItemType()->getId() );
+            invB->drawBild( 50 * index, 0, 50, 50, *icon );
+            tr.renderText( 5 + index * 50, 5, slot->zStack()->zItem()->getName(), *invB, 0xFFFFFFFF );
+            int size = slot->zStack()->getSize();
+            const char* units[] = { "", "K", "M", "G", "T", "P" };
+            int index = 0;
+            for( ; index < 6 && size > 1024; index++ )
+                size = size / 1024;
+            Text count = size;
+            count += units[ index ];
+            tr.renderText( 45 - tr.getTextBreite( count ) + index * 50, 45 - tr.getTextHeight( count ), count, *invB, 0xFFFFFFFF );
+        }
+        index++;
+    }
+    inventory->setRender();
+}

+ 94 - 0
enc_temp_folder/4bd6d7d4a23757a254aa0a7352999e/Game.cpp

@@ -0,0 +1,94 @@
+#include "Game.h"
+#include "Initialisierung.h"
+#include "Globals.h"
+
+#include <AsynchronCall.h>
+#include <Bildschirm.h>
+
+Game::Game( Bildschirm* zScreen )
+    : Menu( zScreen )
+{
+    logout = initKnopf( 10, 10, 200, 20, Knopf::Style::Normal, "Verlassen" );
+    logout->setMausEreignis( [this, zScreen]( void* p, void* o, MausEreignis me ) {
+        if( me.id == ME_RLinks )
+        {
+            logout->removeStyle( Knopf::Style::Erlaubt );
+            new AsynchronCall( [this, zScreen]() {
+                if( network->leaveGame() )
+                {
+                    currentGame->release();
+                    currentGame = 0;
+                    zScreen->lock();
+                    hide();
+                    menuRegister->get( "directConnect" )->show();
+                    zScreen->unlock();
+                }
+                logout->addStyle( Knopf::Style::Erlaubt );
+            } );
+        }
+        return 1;
+    } );
+    elements.add( logout );
+    debug = initTextFeld( 10, 40, 500, 40, TextFeld::Style::Text | TextFeld::Style::Mehrzeilig, "" );
+    elements.add( debug );
+    invB = new Bild();
+    invB->neuBild( zScreen->getBackBufferSize().x - 20, 50, 0 );
+    invB->setAlpha3D( 1 );
+    inventory = initBildZ( 10, zScreen->getBackBufferSize().y - 60, zScreen->getBackBufferSize().x - 20, 50, BildZ::Style::Sichtbar | BildZ::Style::Alpha, invB );
+    elements.add( inventory );
+}
+
+void Game::updatePosition( Vec3<float> position, bool target, Vec3<int> targetPos )
+{
+    Text txt = "Position: (";
+    txt.setPrecision( 2 );
+    txt += position.x;
+    txt += ", ";
+    txt += position.y;
+    txt += ", ";
+    txt += position.z;
+    txt += ")";
+    if( target )
+    {
+        txt += "\nTarget: (";
+        txt += targetPos.x;
+        txt += ", ";
+        txt += targetPos.y;
+        txt += ", ";
+        txt += targetPos.z;
+        txt += ")";
+    }
+    debug->setText( txt );
+}
+
+void Game::updateInventory( Framework::Array<ItemSlot*>& itemBar, int pos )
+{
+    invB->fillRegion( 0, 0, invB->getBreite(), invB->getHeight(), 0 );
+    TextRenderer tr;
+    tr.setSchriftZ( dynamic_cast<Schrift*>(uiFactory.initParam.schrift->getThis()) );
+    tr.setSchriftSize( 12 );
+    int index = 0;
+    for( auto slot : itemBar )
+    {
+        if( pos == index )
+        {
+            invB->fillRegion( 50 * index, 0, 50, 50, 0x7F202020 );
+        }
+        if( slot && slot->zStack() && slot->zStack()->zItem() )
+        {
+            Bild* icon = itemIcons->z( slot->zStack()->zItem()->zItemType()->getId() );
+            invB->alphaBild( 50 * index, 0, 50, 50, *icon );
+            tr.renderText( 5 + index * 50, 5, slot->zStack()->zItem()->getName(), *invB, 0xFFFFFFFF );
+            int size = slot->zStack()->getSize();
+            const char* units[] = { "", "K", "M", "G", "T", "P" };
+            int index = 0;
+            for( ; index < 6 && size > 1024; index++ )
+                size = size / 1024;
+            Text count = size;
+            count += units[ index ];
+            tr.renderText( 45 - tr.getTextBreite( count ) + index * 50, 45 - tr.getTextHeight( count ), count, *invB, 0xFFFFFFFF );
+        }
+        index++;
+    }
+    inventory->setRender();
+}