SHARE
TWEET

mat_clock.lua

a guest Aug 21st, 2015 241 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require "base/internal/ui/reflexcore"
  2.  
  3. mat_clock =
  4. {
  5.         userData = {};
  6. };
  7. registerWidget("mat_clock");
  8.  
  9. function mat_clock:initialize()
  10.         self.userData = loadUserData();
  11.  
  12.         CheckSetDefaultValue(self, "userData", "table", {});
  13.         CheckSetDefaultValue(self.userData, "showSpawnTime", "boolean", true);
  14.         CheckSetDefaultValue(self.userData, "countUp", "boolean", true);
  15.         CheckSetDefaultValue(self.userData, "warmupClock", "boolean", true);
  16.         CheckSetDefaultValue(self.userData, "alpha1", "number", 255);
  17.         CheckSetDefaultValue(self.userData, "alpha2", "number", 255);
  18. end
  19.  
  20. function mat_clock:drawOptions(x, y)
  21.         local u = self.userData;
  22.  
  23.         u.showSpawnTime = uiCheckBox(u.showSpawnTime, "Show respawn times", x, y);
  24.         y = y + 40;
  25.  
  26.         u.countUp = uiCheckBox(u.countUp, "Count up", x, y);
  27.         y = y + 40;
  28.  
  29.         u.warmupClock = uiCheckBox(u.warmupClock, "Clock during warmup", x, y);
  30.         y = y + 40;
  31.  
  32.         uiLabel("Transparency (white boxes)", x, y);
  33.         u.alpha1 = uiEditBox(u.alpha1, x+230, y, 80);
  34.         y = y + 40;
  35.  
  36.         uiLabel("Transparency (black boxes)", x, y);
  37.         u.alpha2 = uiEditBox(u.alpha2, x+230, y, 80);
  38.         y = y + 40;
  39.  
  40.         saveUserData(u);
  41. end
  42.  
  43. local PickupVis = {};
  44. PickupVis[PICKUP_TYPE_ARMOR50] = {};
  45. PickupVis[PICKUP_TYPE_ARMOR50].svg = "internal/ui/icons/armor";
  46. PickupVis[PICKUP_TYPE_ARMOR50].color = Color(0,255,0);
  47. PickupVis[PICKUP_TYPE_ARMOR50].time = 0;
  48. PickupVis[PICKUP_TYPE_ARMOR50].spawn = 25;
  49. PickupVis[PICKUP_TYPE_ARMOR50].delta = 25;
  50. PickupVis[PICKUP_TYPE_ARMOR100] = {};
  51. PickupVis[PICKUP_TYPE_ARMOR100].svg = "internal/ui/icons/armor";
  52. PickupVis[PICKUP_TYPE_ARMOR100].color = Color(255,255,0);
  53. PickupVis[PICKUP_TYPE_ARMOR100].time = 0;
  54. PickupVis[PICKUP_TYPE_ARMOR100].spawn = 25;
  55. PickupVis[PICKUP_TYPE_ARMOR100].delta = 25;
  56. PickupVis[PICKUP_TYPE_ARMOR150] = {};
  57. PickupVis[PICKUP_TYPE_ARMOR150].svg = "internal/ui/icons/armor";
  58. PickupVis[PICKUP_TYPE_ARMOR150].color = Color(255,0,0);
  59. PickupVis[PICKUP_TYPE_ARMOR150].time = 5;
  60. PickupVis[PICKUP_TYPE_ARMOR150].spawn = 25;
  61. PickupVis[PICKUP_TYPE_ARMOR150].delta = 25;
  62. PickupVis[PICKUP_TYPE_HEALTH100] = {};
  63. PickupVis[PICKUP_TYPE_HEALTH100].svg = "internal/ui/icons/health";
  64. PickupVis[PICKUP_TYPE_HEALTH100].color = Color(60,80,255);
  65. PickupVis[PICKUP_TYPE_HEALTH100].time = 0;
  66. PickupVis[PICKUP_TYPE_HEALTH100].spawn = 30;
  67. PickupVis[PICKUP_TYPE_HEALTH100].delta = 30;
  68. PickupVis[PICKUP_TYPE_POWERUPCARNAGE] = {};
  69. PickupVis[PICKUP_TYPE_POWERUPCARNAGE].svg = "internal/ui/icons/carnage";
  70. PickupVis[PICKUP_TYPE_POWERUPCARNAGE].color = Color(255,120,128);
  71. PickupVis[PICKUP_TYPE_POWERUPCARNAGE].time = 0;
  72. PickupVis[PICKUP_TYPE_POWERUPCARNAGE].spawn = 90;
  73. PickupVis[PICKUP_TYPE_POWERUPCARNAGE].delta = 90;
  74. PickupVis[PICKUP_TYPE_POWERUPRESIST] = {};
  75. PickupVis[PICKUP_TYPE_POWERUPRESIST].svg = "internal/ui/icons/resist";
  76. PickupVis[PICKUP_TYPE_POWERUPRESIST].color = Color(255,120,128);
  77. PickupVis[PICKUP_TYPE_POWERUPRESIST].time = 0;
  78. PickupVis[PICKUP_TYPE_POWERUPRESIST].spawn = 90;
  79. PickupVis[PICKUP_TYPE_POWERUPRESIST].delta = 90;
  80.  
  81. local artificialTime = 0; -- clock in warmup
  82.  
  83. function mat_clock:draw()
  84.  
  85.         if not shouldShowHUD() then return end;
  86.  
  87.         local showSpawnTime = self.userData.showSpawnTime;
  88.         local warmupClock = self.userData.warmupClock;
  89.         local countUp = self.userData.countUp;
  90.         local alpha1 = self.userData.alpha1;
  91.         local alpha2 = self.userData.alpha2;
  92.  
  93.         -- clock
  94.  
  95.         local timeRemaining = world.gameTimeLimit - world.gameTime;
  96.         if timeRemaining < 0 then
  97.                 timeRemaining = 0;
  98.         end
  99.  
  100.         local t = FormatTime(timeRemaining);
  101.         if countUp then
  102.                 t = FormatTime(world.gameTime);
  103.         end
  104.  
  105.         local minutes = t.minutes;
  106.         local seconds = t.seconds;
  107.  
  108.         if world.gameState == GAME_STATE_WARMUP and warmupClock then
  109.                 local fps = consoleGetVariable("com_maxfps");
  110.                 local sgn = countUp and 1 or -1;
  111.                 artificialTime = artificialTime + 1 / fps * sgn;
  112.                 minutes = math.floor(artificialTime / 60);
  113.                 seconds = math.floor(artificialTime % 60);
  114.         else
  115.                 artificialTime = 0;
  116.         end
  117.  
  118.         local textTime = string.format("%d:%02d", minutes, seconds);
  119.  
  120.         local width_Clock = 160;
  121.         local height_Clock = 80;
  122.         local fontSize = 88;
  123.  
  124.         local frameColor = Color(255,255,255,alpha1);
  125.         local textColor = Color(0,0,0,255);
  126.  
  127.         local x = -width_Clock / 2;
  128.         local y = -height_Clock / 2;
  129.  
  130.         nvgBeginPath();
  131.         nvgRect(x, y, width_Clock, height_Clock);
  132.         nvgFillColor(frameColor);
  133.         nvgFill();
  134.  
  135.         nvgFontSize(fontSize);
  136.         nvgTextAlign(NVG_ALIGN_CENTER, NVG_ALIGN_MIDDLE);
  137.         nvgFontBlur(0);
  138.         nvgFillColor(textColor);
  139.         nvgText(0, 0, textTime);
  140.  
  141.         -- respawn timer
  142.  
  143.         if not showSpawnTime then
  144.                 return;
  145.         end
  146.  
  147.         for k, v in pairs(pickupTimers) do
  148.                 if PickupVis[v.type] ~= nil then
  149.                         local itemTime = FormatTime(v.timeUntilRespawn);
  150.                         local diff_counter = math.abs(PickupVis[v.type].delta - itemTime.seconds);
  151.                         local diff_seconds = math.abs(PickupVis[v.type].time - seconds);
  152.  
  153.                         if diff_counter <= 2 then
  154.                                 if diff_counter == 0 and diff_seconds > 1 then
  155.                                         local spawnTime = seconds - PickupVis[v.type].delta;
  156.                                         if spawnTime < 0 then
  157.                                                 spawnTime = spawnTime + 60;
  158.                                         end
  159.  
  160.                                         if countUp then
  161.                                                 spawnTime = seconds + PickupVis[v.type].delta;
  162.                                                 if spawnTime >= 60 then
  163.                                                         spawnTime = spawnTime - 60;
  164.                                                 end
  165.                                         end
  166.  
  167.                                         PickupVis[v.type].spawn = spawnTime;
  168.                                         PickupVis[v.type].time = seconds;
  169.                                 end
  170.  
  171.                                 local textTime = string.format(":%02d", PickupVis[v.type].spawn);
  172.  
  173.                                 local itemX = x;
  174.                                 local itemY = y + height_Clock;
  175.  
  176.                                 local width_ItemIcon = 80;
  177.                                 local width_ItemTime = 80;
  178.  
  179.                                 local width_Item = width_ItemIcon + width_ItemTime;
  180.                                 local height_Item = height_Clock;
  181.  
  182.                                 local color_ItemBox = Color(0,0,0,alpha2);
  183.                                 local fontColor_Item = Color(255,255,255,255);
  184.  
  185.                                 local iconRadius = width_ItemIcon * 0.4;
  186.                                 local iconX = -width_ItemIcon / 2;
  187.                                 local iconY = height_Clock;
  188.                                 local iconColor = PickupVis[v.type].color;
  189.                                 local iconSvg = PickupVis[v.type].svg;
  190.  
  191.                                 -- box
  192.                                 nvgBeginPath();
  193.                                 nvgRect(itemX, itemY, width_Item, height_Item);
  194.                                 nvgFillColor(color_ItemBox);
  195.                                 nvgFill();
  196.  
  197.                                 -- icon
  198.                                 nvgFillColor(iconColor);
  199.                                 nvgSvg(iconSvg, iconX, iconY, iconRadius);
  200.  
  201.                                 -- time
  202.                                 nvgFontSize(fontSize);
  203.                                 nvgTextAlign(NVG_ALIGN_CENTER, NVG_ALIGN_MIDDLE);
  204.                                 nvgFontBlur(0);
  205.                                 nvgFillColor(fontColor_Item);
  206.                                 nvgText(width_ItemIcon / 2, height_Clock, textTime);
  207.                         end
  208.                 end
  209.         end
  210.  
  211. 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