Advertisement
Guest User

SimpleHUD code

a guest
Jul 22nd, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.08 KB | None | 0 0
  1. ------------------------------------------
  2. --If you don't want to see the temperature, change the following "true" to "false":
  3. ------------------------------------------
  4. local displaytemperature=true
  5.  
  6. -------------------------------------------
  7. --Unless you know what you're doing, LEAVE EVERYTHING BELOW THIS LINE ALONE
  8. -------------------------------------------
  9.  
  10. require = GLOBAL.require
  11. local Text = require "widgets/text"
  12. local Widget = require "widgets/widget"
  13. local Badge = require "widgets/badge"
  14.  
  15. local mybadgelosefocus = Badge.OnLoseFocus
  16. function Badge:OnLoseFocus()
  17.     local asdf = mybadgelosefocus(self)
  18.         self.isfocused=false
  19.         if self.num then
  20.             self.num:Show()
  21.         end
  22.         if self.num2 then
  23.             self.num2:Hide()
  24.         end
  25.     return asdf
  26. end
  27.  
  28. local mybadgegainfocus = Badge.OnGainFocus
  29. function Badge:OnGainFocus()
  30.     local asdf = mybadgegainfocus(self)
  31.         self.isfocused=true
  32.         if self.num then
  33.             self.num:Hide()
  34.         end
  35.         if self.num2 then
  36.             self.num2:Show()
  37.         end
  38.     return asdf
  39. end
  40.  
  41. local mysetpercent = Badge.SetPercent
  42. function Badge:SetPercent(val,max)
  43.     local asdf = mysetpercent(self, val, max)
  44.         if self.num then
  45.             if not self.isfocused then
  46.                 self.num:Show()
  47.             else
  48.                 if self.isfocused==false then
  49.                     self.num:Show()
  50.                 end
  51.             end
  52.         end
  53.         if not self.num2 then
  54.             self.num2 = self:AddChild(Text(GLOBAL.BODYTEXTFONT, 33))
  55.             self.num2:SetHAlign(GLOBAL.ANCHOR_MIDDLE)
  56.             self.num2:SetPosition(5, 0, 0)
  57.             self.num2:Hide()
  58.         end
  59.         self.num2:SetString(tostring(max))
  60.     return asdf
  61. end
  62.  
  63. --temperature:
  64. local UIClock=require"widgets/uiclock"
  65. local myclockupdate=UIClock.UpdateDayString
  66. function UIClock:UpdateDayString()
  67.     local asdf=myclockupdate(self)
  68.     if displaytemperature==true then
  69.         self.text:SetPosition(5, 3/self.base_scale, 0)
  70.         if not self.text2 then
  71.             self.text2 = self:AddChild(Text(GLOBAL.BODYTEXTFONT, 25/self.base_scale))
  72.             self.text2:SetPosition(5, -23/self.base_scale, 0)
  73.             local temper=tostring(GLOBAL.GetPlayer().components.temperature.current or "?")
  74.             self.inst:DoPeriodicTask(0, function(inst)
  75.                 temper=tostring(GLOBAL.GetPlayer().components.temperature.current or "?")
  76.                 temper=math.floor(temper)
  77.                 self.text2:SetString(temper.."\176C")
  78.             end)
  79.         end
  80.     end
  81.     return asdf
  82. end
  83.  
  84. --rain meter:
  85. AddSimPostInit(function(inst)
  86.     if (GLOBAL.IsDLCEnabled(1)) then
  87.         local MoistureMeter = require "widgets/moisturemeter"
  88.         local mymoistureact = MoistureMeter.Activate
  89.         function MoistureMeter:Activate()
  90.             local asdf = mymoistureact(self)
  91.                 if self.num then
  92.                     self.num:Show()
  93.                 end
  94.             return asdf
  95.         end
  96.         local mymoisturedeact = MoistureMeter.Deactivate
  97.         function MoistureMeter:Deactivate()
  98.             local asdf = mymoisturedeact(self)
  99.                 if self.num then
  100.                     self.num:Hide()
  101.                     inst:DoTaskInTime(.25, function(inst)
  102.                         self.num:Hide()
  103.                     end)
  104.                 end
  105.             return asdf
  106.         end
  107.         local mymoisturelosefoc = MoistureMeter.OnLoseFocus
  108.         function MoistureMeter:OnLoseFocus()
  109.             local asdf = mymoisturelosefoc(self)
  110.                 if self.num then
  111.                     self.num:Show()
  112.                 end
  113.             return asdf
  114.         end
  115.     end
  116. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement