Advertisement
Guest User

modmain.lua

a guest
Jul 22nd, 2014
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.46 KB | None | 0 0
  1. require = GLOBAL.require
  2. local Text = require "widgets/text"
  3.  
  4. local displayTemperature = GetModConfigData("displayTemperature")
  5.  
  6. AddClassPostConstruct("widgets/badge", function(self)
  7.     self.isFocused = false
  8.  
  9.     local oldOnLoseFocus = self.OnLoseFocus
  10.     function self:OnLoseFocus()
  11.         local result = oldOnLoseFocus(self)
  12.  
  13.         self.isFocused = false
  14.  
  15.         if self.num then
  16.             self.num:Show()
  17.         end
  18.  
  19.         if self.num2 then
  20.             self.num2:Hide()
  21.         end
  22.  
  23.         return result
  24.     end
  25.  
  26.     local oldOnGainFocus = self.OnGainFocus
  27.     function self:OnGainFocus()
  28.         local result = oldOnGainFocus(self)
  29.  
  30.         self.isFocused = true
  31.  
  32.         if self.num then
  33.             self.num:Hide()
  34.         end
  35.  
  36.         if self.num2 then
  37.             self.num2:Show()
  38.         end
  39.  
  40.         return result
  41.     end
  42.  
  43.     local oldSetPercent = self.SetPercent
  44.     function self:SetPercent(val, max)
  45.         local result = oldSetPercent(self, val, max)
  46.  
  47.         if self.num and self.isFocused == false then
  48.             self.num:Show()
  49.         end
  50.  
  51.         if not self.num2 then
  52.             self.num2 = self:AddChild(Text(GLOBAL.BODYTEXTFONT, 33))
  53.             self.num2:SetHAlign(GLOBAL.ANCHOR_MIDDLE)
  54.             self.num2:SetPosition(5, 0, 0)
  55.             self.num2:Hide()
  56.         end
  57.         self.num2:SetString(tostring(max))
  58.  
  59.         return result
  60.     end
  61. end)
  62.  
  63. -- Temperature in the clock area
  64. if displayTemperature == "yes" then
  65.     AddClassPostConstruct("widgets/uiclock", function(self)
  66.         local oldUpdateDayString = self.UpdateDayString
  67.         function self:UpdateDayString()
  68.             local result = oldUpdateDayString(self)
  69.  
  70.             self.text:SetPosition(5, 3/self.base_scale, 0)
  71.  
  72.             if not self.text2 then
  73.                 self.text2 = self:AddChild(Text(GLOBAL.BODYTEXTFONT, 25/self.base_scale))
  74.                 self.text2:SetPosition(5, -23/self.base_scale, 0)
  75.  
  76.                 local temper = tostring(GLOBAL.GetPlayer().components.temperature.current or "?")
  77.  
  78.                 self.inst:DoPeriodicTask(0.25, function(inst)
  79.                     temper=tostring(GLOBAL.GetPlayer().components.temperature.current or "?")
  80.                     temper=math.floor(temper)
  81.                     self.text2:SetString(temper.."\176C")
  82.                 end)
  83.             end
  84.  
  85.             return result
  86.         end
  87.  
  88.         self:UpdateDayString()
  89.     end)
  90. end
  91.  
  92. -- Moisture Meter: apparently not a widget/badge
  93. if (GLOBAL.IsDLCEnabled(1)) then
  94.     AddClassPostConstruct("widgets/moisturemeter", function(self)
  95.         local oldActivate = self.Activate
  96.         function self:Activate()
  97.             local result = oldActivate(self)
  98.  
  99.             if self.num then
  100.                 self.num:Show()
  101.             end
  102.  
  103.             return result
  104.         end
  105.  
  106.         local oldDeactivate = self.Deactivate
  107.         function self:Deactivate()
  108.             local result = oldDeactivate(self)
  109.  
  110.             if self.num then
  111.                 self.num:Hide()
  112.  
  113.                 self.inst:DoTaskInTime(.25, function(inst)
  114.                     self.num:Hide()
  115.                 end)
  116.             end
  117.  
  118.             return result
  119.         end
  120.  
  121.         local oldOnLoseFocus = self.OnLoseFocus
  122.         function self:OnLoseFocus()
  123.             local result = oldOnLoseFocus(self)
  124.  
  125.             if self.num then
  126.                 self.num:Show()
  127.             end
  128.  
  129.             return result
  130.         end
  131.     end)
  132. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement