Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[clientside][dev 8] Simple menu framework
#1
Hello, i want to release my old menu framework so here it is.

Squirrel Script
  1. class Menu
  2. {
  3. constructor(x, y, title, lineHeight)
  4. {
  5. m_Position = { x = x, y = y };
  6. m_TitleId = createDraw(title, "Font_Old_20_White_Hi.TGA", x, y, 123, 118, 94);
  7. m_TextureId = createTexture(x - 100, y - 100, 3000, 1500, "ramka_gui.tga");
  8. m_Options = [];
  9. m_CopyOptions = [];
  10. m_LineHeight = lineHeight
  11. m_Cur = 0;
  12. m_CurTitle = "";
  13. m_Page = 0;
  14. m_Showed = false;
  15.  
  16. local m_This = this;
  17. addEvent("onKey", function(key, letter) {m_This.onKey(key, letter);});
  18. }
  19.  
  20. function addOption(title)
  21. {
  22. if(m_Options.len() == 0)
  23. {
  24. m_Position.y += 300;
  25.  
  26. m_Options.append(createDraw(title, "Font_Old_10_White_Hi.TGA", m_Position.x + 50, m_Position.y, 255, 255, 255));
  27. m_CopyOptions.append(title);
  28. m_CurTitle = title;
  29. }
  30. else
  31. {
  32. m_Position.y += 150;
  33.  
  34. m_Options.append(createDraw(title, "Font_Old_10_White_Hi.TGA", m_Position.x + 50, m_Position.y, 111, 106, 81));
  35. m_CopyOptions.append(title);
  36. }
  37. }
  38.  
  39. function show()
  40. {
  41. m_Showed = true;
  42. setDrawVisible(m_TitleId, true);
  43. setTextureVisible(m_TextureId, true);
  44. for(local i = 0; i < m_LineHeight; i++)
  45. {
  46. setDrawVisible(m_Options[i], true);
  47. }
  48. }
  49.  
  50. function hide()
  51. {
  52. m_Showed = false;
  53. setDrawVisible(m_TitleId, false);
  54. setTextureVisible(m_TextureId, false);
  55. for(local i = 0; i < m_LineHeight; i++)
  56. {
  57. setDrawVisible(m_Options[i], false);
  58. }
  59. }
  60.  
  61. function moveUp()
  62. {
  63. if(m_Cur % m_LineHeight == 0 && m_Page > 0)
  64. m_Page -= m_LineHeight;
  65.  
  66. if(m_Cur > 0)
  67. m_Cur--;
  68.  
  69. refresh();
  70. }
  71.  
  72. function moveDown()
  73. {
  74. if(m_Cur == (m_Options.len() - 1))
  75. return false;
  76.  
  77. m_Cur++;
  78.  
  79. if(m_Cur % m_LineHeight == 0)
  80. m_Page += m_LineHeight;
  81.  
  82. refresh();
  83. }
  84.  
  85. function refresh()
  86. {
  87. for(local i = 0; i < m_LineHeight; i++)
  88. {
  89. try {
  90. setDrawText(m_Options[i], m_CopyOptions[i + m_Page]);
  91. setDrawColor(m_Options[i], 111, 106, 81);
  92. } catch(error) {
  93. setDrawText(m_Options[i], "");
  94. setDrawColor(m_Options[i], 111, 106, 81);
  95. }
  96. }
  97.  
  98. if(m_Page > 0)
  99. setDrawColor(m_Options[m_Cur - m_Page], 255, 255, 255);
  100. else
  101. setDrawColor(m_Options[m_Cur], 255, 255, 255);
  102.  
  103. m_CurTitle = m_CopyOptions[m_Cur];
  104. }
  105.  
  106. function onKey(key, letter)
  107. {
  108. switch(key)
  109. {
  110. case KEY_UP:
  111. moveUp();
  112. break;
  113. case KEY_DOWN:
  114. moveDown();
  115. break;
  116. }
  117. }
  118.  
  119. m_Position = null;
  120. m_TitleId = null;
  121. m_TextureId = null;
  122. m_Options = null;
  123. m_CopyOptions = null;
  124. m_LineHeight = null;
  125. m_Cur = null;
  126. m_CurTitle = null;
  127. m_Page = null;
  128. m_Showed = null;
  129. }



Example of usage. (It uses my NPC class but you should know how to use this by your own way.)
Squirrel Script
  1. local Npc = Npcs("Trener");
  2.  
  3. local menu = Menu(3000, 6500, "Trener", 5);
  4. menu.addOption("Siła (+1)");
  5. menu.addOption("Siła (+5)");
  6. menu.addOption("Zręczność (+1)");
  7. menu.addOption("Zręczność (+5)");
  8. menu.addOption("(Powrót)");
  9.  
  10. addEvent("onKey", function(key, letter)
  11. {
  12. Npc.onCtrl(key, letter);
  13. });
  14.  
  15. addEvent("onTakeFocus", function(id, name)
  16. {
  17. Npc.setFocus(name, true);
  18. });
  19.  
  20. addEvent("onLostFocus", function(id, name)
  21. {
  22. Npc.setFocus(name, false);
  23.  
  24. if(menu.m_Showed)
  25. {
  26. menu.hide();
  27. setFreeze(false);
  28. }
  29. });
  30.  
  31. Npc.onCtrl = function(key, letter)
  32. {
  33. if(menu.m_Showed && key == KEY_RETURN)
  34. {
  35. if(menu.m_CurTitle == "(Powrót)")
  36. {
  37. menu.hide();
  38. setFreeze(false);
  39. }
  40. }
  41. if(Npc.isFocused() && key == KEY_LCONTROL)
  42. {
  43. if(!menu.m_Showed)
  44. {
  45. callServerFunc(RELIABLE, "botAngleToPos", FOCUS_ID, getID());
  46. menu.show();
  47. setFreeze(true);
  48. }
  49. else
  50. {
  51. menu.hide();
  52. setFreeze(false);
  53. }
  54. }
  55. };


Reply


Messages In This Thread
[clientside][dev 8] Simple menu framework - by Nubzior - 28.03.2017, 19:12

Possibly Related Threads…
Thread Author Replies Views Last Post
  [New G2O][Client] GUI.Framework Patrix 0 3,151 07.02.2019, 01:39
Last Post: Patrix
  GUI Framework 2.0 Osmith 7 9,622 27.01.2018, 15:01
Last Post: Osmith
  [Clientside] Simple menu framework Sative 1 4,188 09.05.2016, 06:46
Last Post: Sative

Forum Jump:


Users browsing this thread: 1 Guest(s)