ItemList.cpp 5.7 KB

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