Game.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. tr.renderText( 5 + index * 50, 5, slot->zStack()->zItem()->getName(), *invB, 0xFFFFFFFF );
  76. }
  77. index++;
  78. }
  79. inventory->setRender();
  80. }