Sinael

Somecode

Oct 21st, 2022 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. /* Copyright Alexander Kromm ([email protected]) 2021
  2. * Carrascado 2022
  3. *
  4. * This file is part of Gearbox.
  5. *
  6. * Gearbox is free software: you can redistribute it and/or modify it under the
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, either version 3 of the License, or (at your option) any later
  9. * version.
  10. *
  11. * Gearbox is distributed in the hope that it will be useful, but WITHOUT ANY
  12. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  13. * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * Gearbox. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18.  
  19. class gb_InventoryMenu
  20. {
  21.  
  22. static
  23. gb_InventoryMenu from()
  24. {
  25. let result = new("gb_InventoryMenu");
  26.  
  27. result.mSelectedIndex = 0;
  28.  
  29. return result;
  30. }
  31.  
  32. static
  33. bool thereAreNoItems()
  34. {
  35. return getItemsNumber() == 0;
  36. }
  37.  
  38. string confirmSelection() const
  39. {
  40. let item = players[consolePlayer].mo.inv;
  41. int index = 0;
  42. while (item != NULL)
  43. {
  44. if (item.bInvBar)
  45. {
  46. if (index == mSelectedIndex) return item.getClassName();
  47. ++index;
  48. }
  49. item = item.inv;
  50. }
  51.  
  52. return "";
  53. }
  54.  
  55. ui
  56. bool selectNext()
  57. {
  58. int nItems = getItemsNumber();
  59. if (nItems == 0) return false;
  60.  
  61. mSelectedIndex = (mSelectedIndex + 1) % nItems;
  62.  
  63. return true;
  64. }
  65.  
  66. ui
  67. bool selectPrev()
  68. {
  69. int nItems = getItemsNumber();
  70. if (nItems == 0) return false;
  71.  
  72. mSelectedIndex = (mSelectedIndex - 1 + nItems) % nItems;
  73.  
  74. return true;
  75. }
  76.  
  77. ui
  78. bool setSelectedIndex(int index)
  79. {
  80. if (index == -1 || mSelectedIndex == index) return false;
  81.  
  82. mSelectedIndex = index;
  83.  
  84. return true;
  85. }
  86.  
  87. ui
  88. int getSelectedIndex() const
  89. {
  90. return mSelectedIndex;
  91. }
  92.  
  93.  
  94. Private transient CVar gb_item_scale;
  95. if (!gb_item_scale)
  96. {
  97. gb_item_scale = CVar.GetCVar("gb_item_scale", player);
  98. }
  99.  
  100.  
  101. ui
  102. void fill(out gb_ViewModel viewModel)
  103. {
  104. let item = players[consolePlayer].mo.inv;
  105. int index = 0;
  106.  
  107. while (item != NULL)
  108. {
  109. if (item.bInvBar)
  110. {
  111. string tag = item.getTag();
  112. int icon = int(BaseStatusBar.getInventoryIcon(item, BaseStatusBar.DI_AltIconFirst));
  113. viewModel.tags .push(tag);
  114. viewModel.slots .push(index + 1);
  115. viewModel.indices .push(index);
  116. viewModel.icons .push(icon);
  117. viewModel.iconScaleXs .push(gb_item_scale.GetFloat());
  118. viewModel.iconScaleYs .push(gb_item_scale.GetFloat());
  119. viewModel.quantity1 .push(item.maxAmount > 1 ? item.amount : -1);
  120. viewModel.maxQuantity1.push(item.maxAmount);
  121. viewModel.quantity2 .push(-1);
  122. viewModel.maxQuantity2.push(-1);
  123.  
  124. ++index;
  125. }
  126. item = item.inv;
  127. }
  128.  
  129. mSelectedIndex = min(mSelectedIndex, getItemsNumber() - 1);
  130. if (mSelectedIndex == -1 && getItemsNumber() > 0) mSelectedIndex = 0;
  131. viewModel.selectedIndex = mSelectedIndex;
  132. }
  133.  
  134. // private: ////////////////////////////////////////////////////////////////////////////////////////
  135.  
  136. private static
  137. int getItemsNumber()
  138. {
  139. let item = players[consolePlayer].mo.inv;
  140. int result = 0;
  141. while (item != NULL)
  142. {
  143. result += item.bInvBar;
  144. item = item.inv;
  145. }
  146. return result;
  147. }
  148.  
  149. private int mSelectedIndex;
  150.  
  151. } // class gb_InventoryMenu
Add Comment
Please, Sign In to add comment