CatStation/Content.Client/Disposal/PressureBar.cs
chromiumboy 2ca5d9d81a
Disposals refactor (#40540)
* Initial commit

* Added pods

* Transit tubes should no longer connect with disposal pipes

* Updated the transit tube sprites

* Revisited how the transit tubes work

* Fixing merge conflict

* Updated sprites

* Simplified disposal component collections and updated yaml

* Moved the majority of the disposals code to Shared

* Move disposed ents via physics

* Disposal unit now use generic visualizers

* Followers of disposed entities have predicted movement

* Made BeingDisposedSystem shared

* Added documentation for some components

* Code clean up

* Removed unneeded container entries, tubes use directions instead of angles

* Many EntityUid/Comp -> Entity<Comp> changes

* Updated DisposableSystem

* Review of DisposalTubeSystem

* Review of DisposalUnitSystem

* Review of DisposalSignalRouterSystem

* Unit updates

* Fixing merge conflict

* Merge conflict resolved

* Re-organization of systems and components

* Allow trapped entities to escape endless loops

* Fix for item ejection

* UI updates

* Minor tweak

* Fixes for transit tubes

* Removed placeholder sprite

* Removed transit tubes (for now)

* Moved exit stun time to DisposalHolderComponent

* Added a limit on the amount of damage that can sustained from disposals travel

* Fix for PVS-related sound issues

* Added a limit on the number of entities that can be inserted into units

* Clean up

* Undid file scoping

* Fixed test fail

* Fixed test fail

* Increased min default capacity of disposal units

* Fixed audio spam occurring when dumping multiple items into a disposal unit

* Tile prying now occurs whenever exiting an open pipe

* Prevent attacking and interactions while traveling through disposals

* Added generic verbs for entering/exiting disposal units

* Fixed UI prediction bug

* Bug fixes

* Small improvements

* Moved the disposal holder prototype from the disposal entry to the unit

* Minor clean up

* Added support for a disposal holder despawn effect

* Added prediction guard

* Test fail fix

* Re-added new escape behavior

* Removed outdated PVS code

* Clean up

* More escape behavior changes

* More clean up

* Updated exit selection logic

* Bug fix

* More clean up

* Split up disposal unit code

* Cleaned up disposal units some more

* Adjusted exit throw distance

* Capitalized disposal and mailing unit window titles

* Bug fixes

* Taggers and routers show existing tags when the UI opens

* Fixed test fail

* test fail fix

* Minor performance improvement

* Minor improvement in pathing

* merge conflicts

* Fix heisentest

* Fixed mispredict

* Updated system referencing conventions

* Updated to account for changes made to the code

* Attempting to fix submodule issue

* Addressing test fails

* Additional fixes for tests

* Addressing reviewer comments

* Cleaned up exit randomization

* T-ray can see disposal pipes when in 'pipe' mode

* Fix for flush animation flickering

* mild thing

* fix both

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2026-05-27 04:38:03 +00:00

54 lines
2 KiB
C#

using System.Numerics;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;
namespace Content.Client.Disposal;
public sealed class PressureBar : ProgressBar
{
public bool UpdatePressure(TimeSpan fullPressureTime, float pressurePreSecond)
{
var currentTime = IoCManager.Resolve<IGameTiming>().CurTime;
var pressure = (float)Math.Min(1.0f, 1.0f - (fullPressureTime.TotalSeconds - currentTime.TotalSeconds) * pressurePreSecond);
UpdatePressureBar(pressure);
return pressure >= 1.0f;
}
private void UpdatePressureBar(float pressure)
{
Value = pressure;
var normalized = pressure / MaxValue;
const float leftHue = 0.0f; // Red
const float middleHue = 0.066f; // Orange
const float rightHue = 0.33f; // Green
const float saturation = 1.0f; // Uniform saturation
const float value = 0.8f; // Uniform value / brightness
const float alpha = 1.0f; // Uniform alpha
// These should add up to 1.0 or your transition won't be smooth
const float leftSideSize = 0.5f; // Fraction of _chargeBar lerped from leftHue to middleHue
const float rightSideSize = 0.5f; // Fraction of _chargeBar lerped from middleHue to rightHue
float finalHue;
if (normalized <= leftSideSize)
{
normalized /= leftSideSize; // Adjust range to 0.0 to 1.0
finalHue = MathHelper.Lerp(leftHue, middleHue, normalized);
}
else
{
normalized = (normalized - leftSideSize) / rightSideSize; // Adjust range to 0.0 to 1.0.
finalHue = MathHelper.Lerp(middleHue, rightHue, normalized);
}
// Check if null first to avoid repeatedly creating this.
ForegroundStyleBoxOverride ??= new StyleBoxFlat();
var foregroundStyleBoxOverride = (StyleBoxFlat) ForegroundStyleBoxOverride;
foregroundStyleBoxOverride.BackgroundColor =
Color.FromHsv(new Vector4(finalHue, saturation, value, alpha));
}
}