SHARE
TWEET

mat_stack.lua

a guest Aug 20th, 2015 279 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require "base/internal/ui/reflexcore"
  2.  
  3. mat_stack =
  4. {
  5.         userData = {};
  6. };
  7. registerWidget("mat_stack");
  8.  
  9. function mat_stack:initialize()
  10.         self.userData = loadUserData();
  11.  
  12.         CheckSetDefaultValue(self, "userData", "table", {});
  13.         CheckSetDefaultValue(self.userData, "alpha1", "number", 255);
  14.         CheckSetDefaultValue(self.userData, "alpha2", "number", 255);
  15. end
  16.  
  17. function mat_stack:drawOptions(x, y)
  18.         local u = self.userData;
  19.  
  20.         uiLabel("Transparency (white boxes)", x, y);
  21.         u.alpha1 = uiEditBox(u.alpha1, x+230, y, 80);
  22.         y = y + 40;
  23.  
  24.         uiLabel("Transparency (black boxes)", x, y);
  25.         u.alpha2 = uiEditBox(u.alpha2, x+230, y, 80);
  26.         y = y + 40;
  27.  
  28.         saveUserData(u);
  29. end
  30.  
  31. function draw_box(x, y, w, h, r, color, stroke, strokeColor)
  32.         nvgBeginPath();
  33.  
  34.         nvgRoundedRect(x, y, w, h, r);
  35.         nvgFillColor(color);
  36.         nvgFill();
  37.  
  38.         if stroke then
  39.                 nvgStrokeWidth(2);
  40.                 nvgStrokeColor(strokeColor);
  41.                 nvgStroke();
  42.         end
  43. end
  44.  
  45. function mat_stack:draw()
  46.  
  47.         if not shouldShowHUD() then return end;
  48.  
  49.         local player = getPlayer();
  50.  
  51.         local alpha1 = self.userData.alpha1;
  52.         local alpha2 = self.userData.alpha2;
  53.  
  54.         -- colors
  55.  
  56.         local colorTop = Color(255,255,255,alpha1);
  57.         local colorMid = Color(255,176,14,alpha1);
  58.         local colorLow = Color(236,0,0,alpha1);
  59.  
  60.         local iconColor;
  61.         if player.armorProtection == 0 then iconColor = Color(2,167,46,255) end
  62.         if player.armorProtection == 1 then iconColor = Color(245,215,50,255) end
  63.         if player.armorProtection == 2 then iconColor = Color(236,0,0,255) end
  64.  
  65.         local healthColor = Color(255,255,255,alpha1);
  66.         local armorColor = Color(255,255,255,alpha1);
  67.  
  68.         -- thresholds
  69.         local top = 100;
  70.         local mid = 65;
  71.         local low = 30;
  72.  
  73.         -- health
  74.         if player.health >= top then
  75.                 healthColor = colorTop;
  76.         end
  77.         if player.health < top then
  78.                 local x = (player.health - mid) / (top - mid);
  79.                 healthColor.r = x * colorTop.r + (1-x) * colorMid.r;
  80.                 healthColor.g = x * colorTop.g + (1-x) * colorMid.g;
  81.                 healthColor.b = x * colorTop.b + (1-x) * colorMid.b;
  82.         end
  83.         if player.health <= mid then
  84.                 local x = (player.health - low) / (mid - low);
  85.                 healthColor.r = x * colorMid.r + (1-x) * colorLow.r;
  86.                 healthColor.g = x * colorMid.g + (1-x) * colorLow.g;
  87.                 healthColor.b = x * colorMid.b + (1-x) * colorLow.b;
  88.         end
  89.  
  90.         -- armor
  91.         if player.armor >= top then
  92.                 armorColor = colorTop;
  93.         end
  94.         if player.armor < top then
  95.                 local x = (player.armor - mid) / (top - mid);
  96.                 armorColor.r = x * colorTop.r + (1-x) * colorMid.r;
  97.                 armorColor.g = x * colorTop.g + (1-x) * colorMid.g;
  98.                 armorColor.b = x * colorTop.b + (1-x) * colorMid.b;
  99.         end
  100.         if player.armor <= mid then
  101.                 local x = (player.armor - low) / (mid - low);
  102.                 armorColor.r = x * colorMid.r + (1-x) * colorLow.r;
  103.                 armorColor.g = x * colorMid.g + (1-x) * colorLow.g;
  104.                 armorColor.b = x * colorMid.b + (1-x) * colorLow.b;
  105.         end
  106.  
  107.         -- style
  108.  
  109.         local color_IconBox = Color(0,0,0,alpha2);
  110.         local color_HealthBox = healthColor;
  111.         local color_ArmorBox = armorColor;
  112.  
  113.         local boxStroke = false;
  114.         local boxStrokeColor = boxColor;
  115.  
  116.         local roundness = 0;
  117.         local space = 0;
  118.  
  119.         -- boxes
  120.  
  121.         local size_Boxes = 80;
  122.  
  123.         local width_IconBox = size_Boxes;
  124.         local height_IconBox = size_Boxes;
  125.  
  126.         local width_HealthBox = 105;
  127.         local height_HealthBox = size_Boxes;
  128.  
  129.         local width_ArmorBox = width_HealthBox;
  130.         local height_ArmorBox = size_Boxes;
  131.  
  132.         local x_IconBox = -width_IconBox / 2;
  133.         local y_IconBox = -width_IconBox / 2;
  134.  
  135.         local x_HealthBox = x_IconBox - space - width_HealthBox;
  136.         local y_HealthBox = y_IconBox;
  137.  
  138.         local x_ArmorBox = width_IconBox / 2 + space;
  139.         local y_ArmorBox = y_IconBox;
  140.  
  141.         -- draw
  142.  
  143.         draw_box(x_IconBox, y_IconBox, width_IconBox, height_IconBox, roundness, color_IconBox);
  144.         draw_box(x_HealthBox, y_HealthBox, width_HealthBox, height_HealthBox, roundness, color_HealthBox);
  145.         draw_box(x_ArmorBox, y_ArmorBox, width_ArmorBox, height_ArmorBox, roundness, color_ArmorBox);
  146.  
  147.         -- content
  148.  
  149.         local pad = 10;
  150.  
  151.         local size_Icon = size_Boxes / 2 - pad;
  152.         local x_Icon = x_IconBox + width_IconBox / 2;
  153.         local y_Icon = y_IconBox + height_IconBox / 2;
  154.  
  155.         local size_Health = size_Boxes * 1.1;
  156.         local x_Health = x_HealthBox + width_HealthBox / 2;
  157.         local y_Health = y_HealthBox + height_HealthBox / 2;
  158.  
  159.         local size_Armor = size_Health;
  160.         local x_Armor = x_ArmorBox + width_ArmorBox / 2;
  161.         local y_Armor = y_ArmorBox + height_ArmorBox / 2;
  162.  
  163.         -- draw
  164.  
  165.         nvgFillColor(iconColor);
  166.         nvgSvg("internal/ui/icons/armor", x_Icon, y_Icon, size_Icon);
  167.  
  168.         nvgFontSize(size_Health);
  169.         --nvgFontFace("TitilliumWeb-Bold");
  170.         nvgTextAlign(NVG_ALIGN_CENTER, NVG_ALIGN_MIDDLE);
  171.         nvgFontBlur(0);
  172.  
  173.         nvgFillColor(Color(0,0,0,255));
  174.         nvgText(x_Health, y_Health, player.health);
  175.  
  176.         nvgFillColor(Color(0,0,0,255));
  177.         nvgText(x_Armor, y_Armor, player.armor);
  178.  
  179. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top