Dialog.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #include "Dialog.h"
  2. #include <DateiSystem.h>
  3. #include <TastaturEreignis.h>
  4. #include <TextFeld.h>
  5. #include <XML.h>
  6. #include "CraftingGrid.h"
  7. #include "CraftingRecipies.h"
  8. #include "Equipment.h"
  9. #include "Globals.h"
  10. #include "InventoryView.h"
  11. #include "RecipieIngredient.h"
  12. #include "RecipieOutput.h"
  13. #include "ShapedRecipie.h"
  14. #include "UnshapedRecipie.h"
  15. using namespace Framework;
  16. UIMLDialog::UIMLDialog(
  17. Framework::Text uiml, std::function<void(UIMLDialog* self)> onClose)
  18. : Fenster()
  19. {
  20. XML::Element* xml = new XML::Element(uiml);
  21. view = new UIMLView("<v/>", uiFactory);
  22. view->setStyle(UIMLView::Style::Erlaubt | UIMLView::Style::Sichtbar);
  23. view->setMausEreignis(_ret1ME);
  24. view->addKnownElement(new InventoryElement());
  25. view->addKnownElement(new EquipmentElement());
  26. view->addKnownElement(new CraftingGridElement());
  27. view->addKnownElement(new CraftingRecipiesElement());
  28. view->addKnownElement(new RecipieIngredientElement());
  29. view->addKnownElement(new RecipieOutputElement());
  30. view->addKnownElement(new ShapedRecipieElement());
  31. view->addKnownElement(new UnshapedRecipieElement());
  32. view->setUIML(xml);
  33. view->setSize((int)xml->getAttributeValue("width"),
  34. (int)xml->getAttributeValue("height"));
  35. name = xml->getAttributeValue("id");
  36. view->layout();
  37. if (!xml->hasAttribute("width"))
  38. {
  39. view->setSize(view->calculateContentSize().x, view->getHeight());
  40. }
  41. if (!xml->hasAttribute("height"))
  42. {
  43. view->setSize(view->getBreite(), view->calculateContentSize().y);
  44. }
  45. bool notifyOnClose = 0;
  46. int notifyOnCloseDimension = -1;
  47. Vec3<int> notifyOnCloseBlock;
  48. if (xml->hasAttribute("notifyOnClose"))
  49. {
  50. notifyOnClose = 1;
  51. Text value = xml->getAttributeValue("notifyOnClose");
  52. if (value.hat(","))
  53. {
  54. Text* first = value.getTeilText(0, value.positionVon(",", 0) + 1);
  55. Text* second = value.getTeilText(
  56. value.positionVon(",", 0) + 1, value.positionVon(",", 1));
  57. Text* third = value.getTeilText(
  58. value.positionVon(",", 1) + 1, value.positionVon(",", 2));
  59. Text* forth = value.getTeilText(value.positionVon(",", 2) + 1);
  60. notifyOnCloseDimension = (int)*first;
  61. notifyOnCloseBlock.x = (int)*second;
  62. notifyOnCloseBlock.y = (int)*third;
  63. notifyOnCloseBlock.z = (int)*forth;
  64. first->release();
  65. second->release();
  66. third->release();
  67. forth->release();
  68. } // TODO: else entity id
  69. }
  70. addMember(view);
  71. LTDBDatei iconsDat;
  72. iconsDat.setDatei(new Text("data/bilder/gui_icons.ltdb"));
  73. iconsDat.leseDaten(0);
  74. setStyle(
  75. Fenster::Style::Sichtbar | Fenster::Style::Erlaubt
  76. | Fenster::Style::Rahmen | Fenster::Style::BodyHAlpha
  77. | Fenster::Style::Beweglich | Fenster::Style::Titel
  78. | Fenster::Style::TitelHAlpha | Fenster::Style::Closable
  79. | Fenster::Style::ClosingHAlpha | Fenster::Style::ClosingKlickBuffer
  80. | Fenster::Style::TitelHintergrund | Fenster::Style::BodyHintergrund
  81. | Fenster::Style::ClosingHintergrund | Fenster::Style::MEIgnoreInside
  82. | Style::ClosingBuffer | Style::ClosingHBild);
  83. setKBgFarbe(0xA0000000);
  84. setTBgFarbe(0xA0000000);
  85. setSBgFarbe(0xA0000000);
  86. setSize(view->getBreite() + 4, view->getHeight() + 24);
  87. setPosition(window->zBildschirm()->getBackBufferSize() / 2 - getSize() / 2);
  88. setRBreite(2);
  89. this->onClose = [onClose,
  90. notifyOnClose,
  91. notifyOnCloseDimension,
  92. notifyOnCloseBlock,
  93. this](UIMLDialog* self) {
  94. if (notifyOnClose)
  95. {
  96. if (notifyOnCloseDimension >= 0)
  97. {
  98. char* msg = new char[name.getLength() + 3];
  99. msg[0] = 1; // dialog closed
  100. *(short*)(msg + 1) = (short)name.getLength();
  101. memcpy(msg + 3, name.getText(), name.getLength());
  102. World::INSTANCE->zClient()->blockAPIRequest(
  103. notifyOnCloseDimension,
  104. notifyOnCloseBlock,
  105. msg,
  106. name.getLength() + 3);
  107. delete[] msg;
  108. } // TODO: else entity notification
  109. }
  110. onClose(this);
  111. };
  112. setClosingMe(
  113. [notifyOnClose, notifyOnCloseDimension, notifyOnCloseBlock, this](
  114. void* p, void* o, MausEreignis me) {
  115. if (me.id == ME_RLinks)
  116. {
  117. this->close();
  118. }
  119. return 1;
  120. });
  121. setRFarbe(0xFF52525E);
  122. setTitel(xml->getAttributeValue("title"));
  123. setTSchriftZ(
  124. dynamic_cast<Schrift*>(uiFactory.initParam.schrift->getThis()));
  125. zTTextFeld()->setSize(0, 20);
  126. zTTextFeld()->addStyle(TextFeld::Style::Center);
  127. setTastaturEreignis(_ret1TE);
  128. setSAfStrength(10);
  129. setSAfFarbe(0x5F9C0A0A);
  130. setSBgBildZ(iconsDat.laden(0, new Text("close.png")));
  131. setSKAfFarbe(0xFF9C0A0A);
  132. setSKAfStrength(10);
  133. }
  134. UIMLDialog::~UIMLDialog() {}
  135. void UIMLDialog::api(char* message)
  136. {
  137. short idLen = *(short*)message;
  138. char* id = new char[idLen + 1];
  139. memcpy(id, message + 2, idLen);
  140. id[idLen] = 0;
  141. NetworkAPIProcessor* processor
  142. = dynamic_cast<NetworkAPIProcessor*>(view->zZeichnungById(id));
  143. if (processor) processor->api(message + 2 + idLen);
  144. delete[] id;
  145. }
  146. const Framework::Text& UIMLDialog::getName() const
  147. {
  148. return name;
  149. }
  150. void UIMLDialog::close()
  151. {
  152. onClose(this);
  153. }