ItemList.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #include "ItemList.h"
  2. #include <Scroll.h>
  3. #include <TextFeld.h>
  4. #include "Globals.h"
  5. #include "Game.h"
  6. #include "UIMLToolTip.h"
  7. #include "World.h"
  8. ItemList::ItemList()
  9. : ZeichnungHintergrund(),
  10. currentTooltipSlot(-1)
  11. {
  12. setStyle(ZeichnungHintergrund::Style::Sichtbar
  13. | ZeichnungHintergrund::Style::Erlaubt);
  14. slotList = new int[itemTypeCount];
  15. memset(slotList, 0, sizeof(int) * itemTypeCount);
  16. slotCount = 0;
  17. setNeedToolTipEvent([this](Zeichnung* z, Punkt p) {
  18. int slot = getSlotByLocalPos(p);
  19. if (currentTooltipSlot != slot && currentTooltipSlot != -1)
  20. {
  21. std::cout << "closing tooltip\n";
  22. this->setToolTipZ(0);
  23. currentTooltipSlot = -1;
  24. }
  25. if (slot != -1)
  26. {
  27. std::cout << "requesting tooltip for slot " << slot << "\n";
  28. UIMLToolTip* tip = new UIMLToolTip();
  29. tip->setUIML(itemTypes[slot]->getTooltipUIML());
  30. tip->setWarten(0);
  31. tip->setPosition(mausPos.x, mausPos.y + 15);
  32. setToolTipZ(tip);
  33. currentTooltipSlot = slot;
  34. return 1;
  35. }
  36. return 0;
  37. });
  38. }
  39. ItemList::~ItemList()
  40. {
  41. delete[] slotList;
  42. }
  43. int ItemList::getSlotByLocalPos(Framework::Punkt pos)
  44. {
  45. int x = 0;
  46. int y = 0;
  47. for (int i = 0; i < slotCount; i++)
  48. {
  49. if (pos.x >= x && pos.x < x + 50 && pos.y >= y && pos.y < y + 50)
  50. return slotList[i];
  51. x += 60;
  52. if (x >= getBreite())
  53. {
  54. y += 60;
  55. x = 0;
  56. }
  57. }
  58. return -1;
  59. }
  60. void ItemList::doMausEreignis(Framework::MausEreignis& me, bool userRet) {
  61. mausPos.x = me.originalX;
  62. mausPos.y = me.originalY;
  63. if (me.id == ME_Bewegung)
  64. {
  65. if (getSlotByLocalPos(Punkt(me.mx, me.my)) != currentTooltipSlot)
  66. {
  67. if (currentTooltipSlot != -1)
  68. {
  69. std::cout << "closing tooltip\n";
  70. setToolTipZ(0);
  71. }
  72. else
  73. toolTipRequested = 0;
  74. currentTooltipSlot = -1;
  75. }
  76. }
  77. else if (me.id == ME_RLinks)
  78. {
  79. int pos = getSlotByLocalPos(Punkt(me.mx, me.my));
  80. if (pos >= 0)
  81. {
  82. World::INSTANCE->zClient()->craftingUIMLRequest(
  83. itemTypes[pos]->getId());
  84. }
  85. }
  86. ZeichnungHintergrund::doMausEreignis(me, userRet);
  87. }
  88. bool ItemList::tick(double time)
  89. {
  90. return ZeichnungHintergrund::tick(time);
  91. }
  92. void ItemList::adjustSize(int parentWidth, int parentHeight)
  93. {
  94. int ipr = (parentWidth + 10) / 60;
  95. if (ipr == 0)
  96. {
  97. ipr = 1;
  98. }
  99. setSize(ipr * 60 - 10,
  100. (itemTypeCount / ipr + (itemTypeCount % ipr == 0 ? 0 : 1)) * 60
  101. - 10);
  102. }
  103. void ItemList::render(Framework::Bild& rObj)
  104. {
  105. const Text* filter
  106. = dynamic_cast<Game*>((Menu*)menuRegister->get("game"))->zFilterText();
  107. ZeichnungHintergrund::render(rObj);
  108. if (!rObj.setDrawOptions(pos.x, pos.y, gr.x, gr.y)) return;
  109. int x = 0;
  110. int y = 0;
  111. int index = 0;
  112. for (int i = 0; i < itemTypeCount; i++)
  113. {
  114. if (filter->getLength() > 0
  115. && !itemTypes[i]->getName().hat(filter->getText()))
  116. {
  117. continue;
  118. }
  119. slotList[index] = i;
  120. rObj.fillRegion(x, y, 50, 50, 0xFF222222);
  121. rObj.alphaBild(x, y, 50, 50, *itemTypes[i]->zIcon());
  122. x += 60;
  123. if (x >= getBreite())
  124. {
  125. x = 0;
  126. y += 60;
  127. }
  128. index++;
  129. }
  130. slotCount = index;
  131. rObj.releaseDrawOptions();
  132. }
  133. ItemListContainer::ItemListContainer()
  134. : Fenster()
  135. {
  136. setStyle(
  137. Fenster::Style::Erlaubt | Fenster::Style::Rahmen
  138. | Fenster::Style::BodyHAlpha | Fenster::Style::Beweglich
  139. | Fenster::Style::Titel | Fenster::Style::TitelHAlpha
  140. | Fenster::Style::TitelHintergrund | Fenster::Style::BodyHintergrund
  141. | Fenster::Style::MEIgnoreInside | Fenster::Style::VScroll
  142. | Fenster::Style::BreiteChangeable | Fenster::Style::BodyMinBr
  143. | Fenster::Style::BodyMinHi | Fenster::Style::HeightChangeable
  144. | Fenster::Style::Closable | Fenster::Style::ClosingHAlpha
  145. | Fenster::Style::ClosingKlickBuffer | Fenster::Style::ClosingHAlpha
  146. | Fenster::Style::ClosingHintergrund);
  147. setKBgFarbe(0xA0000000);
  148. setTBgFarbe(0xA0000000);
  149. setSBgFarbe(0xA0000000);
  150. setSize(329, window->zBildschirm()->getBackBufferSize().y - 20);
  151. setPosition(
  152. window->zBildschirm()->getBackBufferSize().x - getBreite() - 10, 10);
  153. setRBreite(2);
  154. setRFarbe(0xFF52525E);
  155. setTitel("Recipies");
  156. setTSchriftZ(
  157. dynamic_cast<Schrift*>(uiFactory.initParam.schrift->getThis()));
  158. zTTextFeld()->setSize(0, 20);
  159. zTTextFeld()->addStyle(TextFeld::Style::Center);
  160. setTastaturEreignis(_ret1TE);
  161. setKMin(70, 70);
  162. setVSBScroll(0);
  163. zVScrollBar()->setBgFarbe(0xA0000000, 1);
  164. setClosingMe([this](void* p, void* o, MausEreignis me) {
  165. if (me.id == ME_RLinks) removeStyle(Style::Sichtbar);
  166. return 1;
  167. });
  168. list = new ItemList();
  169. list->setPosition(10, 10);
  170. addMember(list);
  171. }
  172. bool ItemListContainer::tick(double time)
  173. {
  174. list->adjustSize(getInnenBreite() - 35, getInnenHeight());
  175. if (zVScrollBar()->getScrollData()->max != list->getHeight() + 20)
  176. setVSBMax(list->getHeight() + 20);
  177. return Fenster::tick(time);
  178. }