Divergent/mods/Utjans QoL Bundle/gamedata/scripts/sleep_gain_indicator.script

72 lines
2.6 KiB
Plaintext
Raw Permalink Normal View History

2024-03-17 20:18:03 -04:00
base_init = ui_sleep_dialog.UISleep.InitControls
function ui_sleep_dialog.UISleep:InitControls()
base_init(self)
if not actor_status_sleep.in_hour then
printf("-User missing Unlocalizer! Install or update your Modded Exes")
return
end
local xml = CScriptXmlInit()
xml:ParseFile("ui_sleep_gain_indicator.xml")
self.form = xml:InitStatic("form", self.back)
self.bg = xml:InitStatic("form:bg", self.form)
self.sensor = xml:InitProgressBar("form:bar", self.form)
self.sensor_gain = xml:InitProgressBar("form:bar", self.form)
end
base_Initialize = ui_sleep_dialog.UISleep.Initialize
function ui_sleep_dialog.UISleep:Initialize()
base_Initialize(self)
if not self.form then return end
self.sensor_gain:Show(false)
local sensor_w = self.sensor:GetWidth()
local sensor_h = self.sensor:GetHeight()
local back_w = self.back:GetWidth()
--local back_h = self.back:GetHeight()
local sensor_y = self.btn_sleep:GetWndPos().y - 2 - sensor_h
self.form:SetWndPos(vector2():set( (back_w / 2) - (self.form:GetWidth() / 2), sensor_y))
local sleep = self:Get_Sleep()
self.sensor:SetProgressPos( sleep )
if sleep >= 0.995 then return end
local sensor_pos = self.sensor:GetWndPos()
self.sensor_gain:SetWndPos(vector2():set( sensor_pos.x + (sensor_w * sleep), sensor_pos.y))
self.sensor_gain:SetProgressPos( clamp( self:Get_Sleep_Gain(), 0, 1 - sleep ) )
self.sensor_gain:SetColor( GetARGB(255, 50, 200, 50) )
self.sensor_gain:Show(true)
end
base_Update = ui_sleep_dialog.UISleep.Update
function ui_sleep_dialog.UISleep:Update()
base_Update(self)
if self:IsShown() and self.sensor_gain and self.sensor_gain:IsShown() then
self.sensor_gain:SetProgressPos( clamp( self:Get_Sleep_Gain() , 0, 1 - self.sensor:GetProgressPos() ) )
end
end
function ui_sleep_dialog.UISleep:Get_Sleep()
local sleep = actor_status_sleep.last_sleep or 0
local sleep_red_icon = actor_status_sleep.start_blur_4
sleep = (sleep_red_icon - sleep) / sleep_red_icon
return clamp( sleep, 0, 1)
end
function ui_sleep_dialog.UISleep:Get_Sleep_Gain()
local sleep_per_hour = actor_status_sleep.in_hour / 2 -- Remove the "/ 2" if you use Gamma. Or tell Grok to undo the removal of that divison in his actor_status_sleep.actor_on_sleep
if actor_status_sleep.comfy then -- Possible fix for Gamma incompatibility
sleep_per_hour = actor_status_sleep.in_hour
end
local hours = self.time_track:GetIValue()
local sleep_red_icon = actor_status_sleep.start_blur_4
local sleep_gain = (sleep_per_hour * hours) / sleep_red_icon
return sleep_gain
end