Ver Fonte

render basic inventory information

Kolja Strohm há 3 anos atrás
pai
commit
b6659fd759

+ 27 - 0
FactoryCraft/Game.cpp

@@ -31,6 +31,11 @@ Game::Game( Bildschirm* zScreen )
     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 )
@@ -54,4 +59,26 @@ void Game::updatePosition( Vec3<float> position, bool target, Vec3<int> targetPo
         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() )
+        {
+            tr.renderText( 5 + index * 50, 5, slot->zStack()->zItem()->getName(), *invB, 0xFFFFFFFF );
+        }
+        index++;
+    }
+    inventory->setRender();
 }

+ 9 - 2
FactoryCraft/Game.h

@@ -1,18 +1,25 @@
 #pragma once
 
 #include <Knopf.h>
+#include <Bild.h>
 
 #include "Menu.h"
 
+class Player;
+class ItemSlot;
+
 class Game : public Menu
 {
 private:
-    Knopf* logout;
-    TextFeld* debug;
+    Framework::Knopf* logout;
+    Framework::TextFeld* debug;
+    Framework::Bild* invB;
+    Framework::BildZ* inventory;
 
 public:
     // Konstruktor
     Game( Bildschirm* zScreen );
 
     void updatePosition( Vec3<float> position, bool target, Vec3<int> targetPos );
+    void updateInventory( Framework::Array<ItemSlot*>& itemBar, int pos );
 };

+ 1 - 1
FactoryCraft/Initialisierung.cpp

@@ -55,7 +55,7 @@ TextFeld* initTextFeld( int x, int y, int br, int h
 BildZ* initBildZ( int x, int y, int br, int hö, __int64 style, Bild* b )
 {
     BildZ* ret = uiFactory.createBildZ( uiFactory.initParam );
-    ret->addStyle( style );
+    ret->setStyle( style );
     ret->setPosition( x, y );
     ret->setSize( br, hö );
     if( b )

+ 1 - 0
FactoryCraft/Initialisierung.h

@@ -22,6 +22,7 @@ struct OBJTabelleSpalteIni
 Knopf* initKnopf( int x, int y, int br, int hö, __int64 style, char* titel );
 KontrollKnopf* initKontrollKnopf( int x, int y, int br, int hö, __int64 style, char* txt );
 TextFeld* initTextFeld( int x, int y, int br, int hö, __int64 style, char* txt );
+BildZ* initBildZ( int x, int y, int br, int hö, __int64 style, Bild* b );
 AuswahlBox* initAuswahlBox( int x, int y, int br, int hö, __int64 style, std::initializer_list< char* > values );
 ObjTabelle* initObjTabelle( int x, int y, int br, int hö, __int64 style, std::initializer_list< OBJTabelleSpalteIni > spalten, int überschriftHöhe );
 LDiag* initLinienDiagramm( int x, int y, int br, int hö, __int64 style, DiagDaten* data );

+ 5 - 0
FactoryCraft/Item.cpp

@@ -70,4 +70,9 @@ int Item::getMaxStackSize() const
 float Item::getMaxDamage() const
 {
     return maxDamage;
+}
+
+const char* Item::getName() const
+{
+    return name;
 }

+ 1 - 0
FactoryCraft/Item.h

@@ -35,6 +35,7 @@ public:
     float getMaxDurability() const;
     int getMaxStackSize() const;
     float getMaxDamage() const;
+    const char* getName() const;
 
     friend ItemType;
 };

+ 2 - 0
FactoryCraft/Player.cpp

@@ -28,6 +28,7 @@ Player::Player()
     for( int i = 0; i < 9; i++ )
     {
         ItemSlot* slot = new ItemSlot( 50, 0, i, 0, ANY_DIRECTION, 0 );
+        itemBar.add( slot );
         addSlot( slot );
     }
     currentGame->setVisibility( this, 1 );
@@ -58,6 +59,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
     }
     return Entity::tick( time );
 }

+ 3 - 0
FactoryCraft/Player.h

@@ -4,10 +4,13 @@
 #include "Entity.h"
 #include "StaticRegistry.h"
 
+class ItemSlot;
+
 class Player : public Entity
 {
 private:
     Framework::Text name;
+    Framework::Array<ItemSlot*> itemBar;
 
 public:
     Player();