Advertisement
Guest User

Untitled

a guest
Oct 8th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.53 KB | None | 0 0
  1. require "base/internal/ui/reflexcore"
  2.  
  3. local function checkDefaults(defaults, target)
  4. for k, v in pairs(defaults) do
  5. if(type(v) == 'table') then checkDefaults(v, target);
  6. CheckSetDefaultValue(target, k, type(v), v);
  7. end
  8. end
  9. end
  10.  
  11. CrosshairWeapons = {
  12. canPosition = false;
  13. defaultData = {crosshairs = {
  14. [1] = {style = 1; size = 16; color = Color(255,255,255);};
  15. [2] = {style = 10; size = 16; color = Color(255,255,255);};
  16. [3] = {style = 4; size = 16; color = Color(255,255,255);};
  17. [4] = {style = 10; size = 16; color = Color(255,255,255);};
  18. [5] = {style = 1; size = 16; color = Color(255,255,255);};
  19. [6] = {style = 10; size = 64; color = Color(255,255,255);};
  20. [7] = {style = 1; size = 16; color = Color(255,255,255);};
  21. [8] = {style = 4; size = 16; color = Color(255,255,255);};
  22. };
  23. };
  24. crosshairWidget = nil;
  25. userData = nil;
  26. optionHeight = 0;
  27. ------------------------------------------------------------------
  28. -- INITIALIZE!
  29. ------------------------------------------------------------------
  30. initialize = function(self)
  31. self.crosshairWidgetName = "Crosshairs";
  32. -- Load userData
  33. self.userData = loadUserData();
  34. CheckSetDefaultValue(self, "userData", 'table', {});
  35. checkDefaults(self.defaultData, self.userData);
  36. --get Crosshair widget data.
  37. self.crosshairWidget = _G[self.crosshairWidgetName];
  38. end;
  39. ------------------------------------------------------------------
  40. -- DRAW!
  41. ------------------------------------------------------------------
  42. draw = function(self)
  43.  
  44. local crosshairData = self.crosshairWidget.userData;
  45.  
  46. -- Early out if HUD shouldn't be shown.
  47. if not shouldShowHUD() then return end;
  48.  
  49. local player = getPlayer();
  50. for k,v in pairs(self.userData.crosshairs) do
  51. if(self.userData.crosshairs[player.weaponIndexSelected]) then
  52. -- set crosshair type.
  53. consolePerformCommand("ui_" .. self.crosshairWidgetName .. "_type " .. self.userData.crosshairs[player.weaponIndexSelected].style);
  54. -- set crosshair size.
  55. crosshairData.crosshairSize = self.userData.crosshairs[player.weaponIndexSelected].size;
  56. -- set crosshair color.
  57. consolePerformCommand("ui_" .. self.crosshairWidgetName .. "_r " .. self.userData.crosshairs[player.weaponIndexSelected].color.r);
  58. consolePerformCommand("ui_" .. self.crosshairWidgetName .. "_g " .. self.userData.crosshairs[player.weaponIndexSelected].color.g);
  59. consolePerformCommand("ui_" .. self.crosshairWidgetName .. "_b " .. self.userData.crosshairs[player.weaponIndexSelected].color.b);
  60. end
  61. end
  62. end;
  63. ------------------------------------------------------------------
  64. -- DRAW OPTIONS!
  65. ------------------------------------------------------------------
  66. drawOptions = function(self, x, y)
  67. local sliderWidth = 100;
  68. local p = getPlayer() or getLocalPlayer();
  69.  
  70. uiLabel("Type", x + sliderWidth + 10, y);
  71. uiLabel("Size", x + sliderWidth + 10 + 80, y);
  72. uiLabel("R", x + sliderWidth + 10 + 80 * 2, y);
  73. uiLabel("G", x + sliderWidth + 10 + 80 * 3, y);
  74. uiLabel("B", x + sliderWidth + 10 + 80 * 4, y);
  75. y = y + 40;
  76. -- Draw Options for each weapon
  77. for k = 1, #self.userData.crosshairs do -- i dont recommend using # to count tables. this case it doesnt matter though.
  78. uiLabel( p.weapons[k].name .. ":", x, y);
  79. y = y + 25;
  80. self.userData.crosshairs[k].style = round(uiSlider(x , y, sliderWidth, 1, 16, self.userData.crosshairs[k].style, k));
  81. self.userData.crosshairs[k].style = round(uiEditBox(self.userData.crosshairs[k].style, x + sliderWidth + 10, y, 60, k));
  82. self.userData.crosshairs[k].size = round(uiEditBox(self.userData.crosshairs[k].size, x + sliderWidth + 10 + 80, y, 60, k));
  83.  
  84. self.userData.crosshairs[k].color.r = round(uiEditBox(self.userData.crosshairs[k].color.r, x + sliderWidth + 10 + 80 * 2, y, 60, k));
  85. self.userData.crosshairs[k].color.g = round(uiEditBox(self.userData.crosshairs[k].color.g, x + sliderWidth + 10 + 80 * 3, y, 60, k));
  86. self.userData.crosshairs[k].color.b = round(uiEditBox(self.userData.crosshairs[k].color.b, x + sliderWidth + 10 + 80 * 4, y, 60, k));
  87. y = y + 40;
  88. end
  89.  
  90. self.optionHeight = y;
  91. saveUserData(self.userData);
  92. end;
  93. ------------------------------------------------------------------
  94. -- Get Height For Options ScrollBox.
  95. ------------------------------------------------------------------
  96. getOptionsHeight = function(self)
  97. return self.optionHeight; -- debug with: ui_optionsmenu_show_properties_height 1
  98. end;
  99. }
  100. registerWidget("CrosshairWeapons");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement