Game.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "Game.h"
  2. #include "Initialisierung.h"
  3. #include "Globals.h"
  4. #include <AsynchronCall.h>
  5. #include <Bildschirm.h>
  6. Game::Game( Bildschirm* zScreen )
  7. : Menu( zScreen )
  8. {
  9. logout = initKnopf( 10, 10, 200, 20, Knopf::Style::Normal, "Verlassen" );
  10. logout->setMausEreignis( [this, zScreen]( void* p, void* o, MausEreignis me ) {
  11. if( me.id == ME_RLinks )
  12. {
  13. logout->removeStyle( Knopf::Style::Erlaubt );
  14. new AsynchronCall( [this, zScreen]() {
  15. if( network->leaveGame() )
  16. {
  17. currentGame->release();
  18. currentGame = 0;
  19. zScreen->lock();
  20. hide();
  21. menuRegister->get( "directConnect" )->show();
  22. zScreen->unlock();
  23. }
  24. logout->addStyle( Knopf::Style::Erlaubt );
  25. } );
  26. }
  27. return 1;
  28. } );
  29. elements.add( logout );
  30. debug = initTextFeld( 10, 40, 500, 40, TextFeld::Style::Text | TextFeld::Style::Mehrzeilig, "" );
  31. elements.add( debug );
  32. invB = new Bild();
  33. invB->neuBild( zScreen->getBackBufferSize().x - 20, 50, 0 );
  34. invB->setAlpha3D( 1 );
  35. inventory = initBildZ( 10, zScreen->getBackBufferSize().y - 60, zScreen->getBackBufferSize().x - 20, 50, BildZ::Style::Sichtbar | BildZ::Style::Alpha, invB );
  36. elements.add( inventory );
  37. }
  38. void Game::updatePosition( Vec3<float> position, bool target, Vec3<int> targetPos )
  39. {
  40. Text txt = "Position: (";
  41. txt.setPrecision( 2 );
  42. txt += position.x;
  43. txt += ", ";
  44. txt += position.y;
  45. txt += ", ";
  46. txt += position.z;
  47. txt += ")";
  48. if( target )
  49. {
  50. txt += "\nTarget: (";
  51. txt += targetPos.x;
  52. txt += ", ";
  53. txt += targetPos.y;
  54. txt += ", ";
  55. txt += targetPos.z;
  56. txt += ")";
  57. }
  58. debug->setText( txt );
  59. }
  60. void Game::updateInventory( Framework::Array<ItemSlot*>& itemBar, int pos )
  61. {
  62. invB->fillRegion( 0, 0, invB->getBreite(), invB->getHeight(), 0 );
  63. TextRenderer tr;
  64. tr.setSchriftZ( dynamic_cast<Schrift*>(uiFactory.initParam.schrift->getThis()) );
  65. tr.setSchriftSize( 12 );
  66. int index = 0;
  67. for( auto slot : itemBar )
  68. {
  69. if( pos == index )
  70. {
  71. invB->fillRegion( 50 * index, 0, 50, 50, 0x7F202020 );
  72. }
  73. if( slot && slot->zStack() && slot->zStack()->zItem() )
  74. {
  75. Bild* icon = itemIcons->z( slot->zStack()->zItem()->zItemType()->getId() );
  76. invB->alphaBild( 50 * index, 0, 50, 50, *icon );
  77. tr.renderText( 5 + index * 50, 5, slot->zStack()->zItem()->getName(), *invB, 0xFFFFFFFF );
  78. int size = slot->zStack()->getSize();
  79. const char* units[] = { "", "K", "M", "G", "T", "P" };
  80. int index = 0;
  81. for( ; index < 6 && size > 1024; index++ )
  82. size = size / 1024;
  83. Text count = size;
  84. count += units[ index ];
  85. tr.renderText( 45 - tr.getTextBreite( count ) + index * 50, 45 - tr.getTextHeight( count ), count, *invB, 0xFFFFFFFF );
  86. }
  87. index++;
  88. }
  89. inventory->setRender();
  90. }