SHARE
TWEET

KovPickupTime.lua

a guest Sep 4th, 2015 18 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require "base/internal/ui/reflexcore"
  2.  
  3. KovPickupTime =
  4. {
  5. };
  6. registerWidget("KovPickupTime");
  7.  
  8. function KovPickupTime:initialize()
  9.     -- load data stored in engine
  10.     self.userData = loadUserData();
  11.    
  12.     -- ensure it has what we need
  13.     CheckSetDefaultValue(self, "userData", "table", {});
  14.     CheckSetDefaultValue(self.userData, "TimerCountsDown", "boolean", true);
  15.     CheckSetDefaultValue(self.userData, "ReplaceMinutes", "boolean", false);
  16.  
  17.     CheckSetDefaultValue(self.userData, "ShowReds", "boolean", true);
  18.     CheckSetDefaultValue(self.userData, "ShowYellows", "boolean", true);
  19.     CheckSetDefaultValue(self.userData, "ShowGreens", "boolean", true);
  20.     CheckSetDefaultValue(self.userData, "ShowMegas", "boolean", true);
  21.     CheckSetDefaultValue(self.userData, "ShowCarnage", "boolean", true);
  22.  
  23. end
  24.  
  25. --------------------------------------------------------------------------------
  26. --------------------------------------------------------------------------------
  27. function KovPickupTime:finalize()
  28. end
  29.  
  30.  
  31. --------------------------------------------------------------------------------
  32. --------------------------------------------------------------------------------
  33. function KovPickupTime:draw()
  34.    
  35.     local TimerCountsDown = self.userData.TimerCountsDown;
  36.     local ReplaceMinutes = self.userData.ReplaceMinutes;
  37.     local ShowReds = self.userData.ShowReds;
  38.     local ShowYellows = self.userData.ShowYellows;
  39.     local ShowGreens = self.userData.ShowGreens;
  40.     local ShowMegas = self.userData.ShowMegas;
  41.     local ShowCarnage = self.userData.ShowCarnage;
  42.    
  43.     local gameTime
  44.     local gameTimeLimit = world.gameTimeLimit
  45.     if TimerCountsDown then
  46.         gameTime = gameTimeLimit - world.gameTime  
  47.     else
  48.         gameTime = world.gameTime
  49.     end
  50.    
  51.    
  52.     -- Early out if HUD shouldn't be shown.
  53.     if not shouldShowHUD() then return end;
  54.  
  55.     local translucency = 192;
  56.    
  57.     -- Find player
  58.     local player = getPlayer();
  59.  
  60.     -- count pickups
  61.     local pickupCount = 0;
  62.     for k, v in pairs(pickupTimers) do
  63.         pickupCount = pickupCount + 1;
  64.     end
  65.  
  66.     local spaceCount = pickupCount - 1;
  67.    
  68.     -- Options
  69.     local timerWidth = 100;
  70.     local timerHeight = 30;
  71.     local timerSpacing = 5; -- 0 or -1 to remove spacing
  72.    
  73.     -- Helpers
  74.     local rackHeight = (timerHeight * pickupCount) + (timerSpacing * spaceCount);
  75.     local rackTop = -(rackHeight / 2);
  76.     local timerX = 0;
  77.     local timerY = rackTop;
  78.  
  79.     -- iterate pickups
  80.     for i = 1, pickupCount do
  81.         local pickup = pickupTimers[i];
  82.  
  83.         if (pickup.type == PICKUP_TYPE_ARMOR50 and ShowGreens) or (pickup.type == PICKUP_TYPE_ARMOR100 and ShowYellows) or (pickup.type == PICKUP_TYPE_ARMOR150 and ShowReds) then
  84.  
  85.             local backgroundColor = Color(0,0,0,65)
  86.            
  87.             -- Frame background
  88.             nvgBeginPath();
  89.             nvgRect(timerX,timerY,timerWidth,timerHeight);
  90.             nvgFillColor(backgroundColor);
  91.             nvgFill();
  92.  
  93.             -- Icon
  94.             local iconRadius = timerHeight * 0.40;
  95.             local iconX = timerX + iconRadius + 5;
  96.             local iconY = timerY + (timerHeight / 2);
  97.             local iconColor = Color(255,255,255);
  98.             local iconSvg = "internal/ui/icons/armor";
  99.             if pickup.type == PICKUP_TYPE_ARMOR50 then
  100.                 iconColor = Color(0,180,0);
  101.             elseif pickup.type == PICKUP_TYPE_ARMOR100 then
  102.                 iconColor = Color(255,255,0);
  103.             elseif pickup.type == PICKUP_TYPE_ARMOR150 then
  104.                 iconColor = Color(255,0,0);
  105.             elseif pickup.type == PICKUP_TYPE_HEALTH100 then
  106.                 iconSvg = "internal/ui/icons/health";
  107.                 iconColor = Color(60,80,255);
  108.             elseif pickup.type == PICKUP_TYPE_POWERUPCARNAGE then
  109.                 iconSvg = "internal/ui/icons/carnage";
  110.                 iconColor = Color(255,120,128);        
  111.             end
  112.          
  113.             -- TODO: tint based on pickup type
  114.             local svgName = "internal/ui/icons/armor";
  115.             nvgFillColor(iconColor);
  116.             nvgSvg(iconSvg, iconX, iconY, iconRadius);
  117.  
  118.             -- Time
  119.  
  120.             --[[
  121.             Logic for timers:
  122.             If you're in prematch, just use the normal method
  123.             If you have the timer set to count up,
  124.             --]]
  125.            
  126.             local t = FormatTime(pickup.timeUntilRespawn);
  127.             local timeX = timerX + (timerWidth / 2) + iconRadius;
  128.             local time = t.seconds + 60 * t.minutes;
  129.  
  130.             if time == 0 then
  131.                 time = "-";
  132.             end
  133.            
  134.             if world.gameState == GAME_STATE_ACTIVE then
  135.                 local OTFlag = 0
  136.                 if time ~= "-" and time > 0 then
  137.                     if TimerCountsDown == true then
  138.                         time = gameTime - pickup.timeUntilRespawn + 25*1000
  139.                         if time < 0 then
  140.                             time = time + 120*1000
  141.                             OTFlag = 1
  142.                         end
  143.                     else
  144.                         time = gameTime + pickup.timeUntilRespawn - 25*1000
  145.                         if time > gameTimeLimit then
  146.                             OTFlag = 1
  147.                         end
  148.                     end    
  149.                     local seconds = math.floor(time/1000)%60
  150.                     if seconds < 10 then
  151.                     seconds = "0"..seconds
  152.                     end
  153.                     local minutes = (math.floor(time/1000) - seconds)/60
  154.                     if ReplaceMinutes == true then
  155.                         minutes = ""
  156.                     end
  157.                     time = minutes..":"..seconds
  158.                     if OTFlag == 1 then
  159.                         time = "OT "..time
  160.                     end
  161.                 end
  162.  
  163.             end
  164.  
  165.             if not pickup.canSpawn then
  166.                 time = "held";
  167.             end
  168.  
  169.             nvgFontSize(30);
  170.             nvgFontFace("TitilliumWeb-Bold");
  171.             nvgTextAlign(NVG_ALIGN_CENTER, NVG_ALIGN_TOP);
  172.  
  173.             nvgFontBlur(0);
  174.             nvgFillColor(Color(255,255,255));
  175.             nvgText(timeX, timerY, time);
  176.            
  177.             timerY = timerY + timerHeight + timerSpacing;
  178.         end
  179.     end
  180. end
  181.  
  182. --------------------------------------------------------------------------------
  183. --------------------------------------------------------------------------------
  184. function KovPickupTime:drawOptions(x, y)
  185.     local user = self.userData;
  186.  
  187.     user.TimerCountsDown = uiCheckBox(user.TimerCountsDown, "Timer Counts Down", x, y);
  188.     y = y + 30;
  189.  
  190.     user.ReplaceMinutes = uiCheckBox(user.ReplaceMinutes, "Hide Minutes", x, y);
  191.     y = y + 50;
  192.    
  193.     user.ShowReds = uiCheckBox(user.ShowReds, "Show Red Armors", x, y);
  194.     y = y + 30;
  195.  
  196.     user.ShowYellows = uiCheckBox(user.ShowYellows, "Show Yellow Armors", x, y);
  197.     y = y + 30;
  198.  
  199.     user.ShowGreens = uiCheckBox(user.ShowGreens, "Show Green Armors", x, y);
  200.     y = y + 30;
  201.         --[[
  202.     user.ShowMegas = uiCheckBox(user.ShowMegas, "Show Mega Healths", x, y);
  203.     y = y + 30;
  204.  
  205.     user.ShowCarnage = uiCheckBox(user.ShowCarnage, "Show Carnage", x, y);
  206.     y = y + 30;
  207.     --]]
  208.     --[[
  209.     CheckSetDefaultValue(self.userData, "ShowReds", "boolean", true);
  210.     CheckSetDefaultValue(self.userData, "ShowYellows", "boolean", true);
  211.     CheckSetDefaultValue(self.userData, "ShowGreens", "boolean", true);
  212.     CheckSetDefaultValue(self.userData, "ShowMegas", "boolean", true);
  213.     CheckSetDefaultValue(self.userData, "ShowCarnage", "boolean", true);
  214.     --]]
  215.     saveUserData(user);
  216. end
  217.  
  218. --------------------------------------------------------------------------------
  219. --------------------------------------------------------------------------------
  220. function KovPickupTime:getOptionsHeight()
  221.     return 370; -- debug with: ui_optionsmenu_show_properties_height 1
  222. 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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top