Show remaining liquid in a drink when you examine it (#8721)
* Show drink volume on examine * Approximate measurement unless a beaker * Changed percentage threshold and added subjectivity * Update default switch case since it can never be 0 here * Remove int cast from PercentFull method
This commit is contained in:
@@ -113,6 +113,14 @@ public sealed partial class SolutionContainerSystem
|
||||
: solution.CurrentVolume;
|
||||
}
|
||||
|
||||
public float PercentFull(EntityUid uid)
|
||||
{
|
||||
if (!TryGetDrainableSolution(uid, out var solution) || solution.MaxVolume.Equals(FixedPoint2.Zero))
|
||||
return 0;
|
||||
|
||||
return ((solution.CurrentVolume.Float() / solution.MaxVolume.Float()) * 100);
|
||||
}
|
||||
|
||||
public bool TryGetFitsInDispenser(EntityUid owner,
|
||||
[NotNullWhen(true)] out Solution? solution,
|
||||
FitsInDispenserComponent? dispenserFits = null,
|
||||
|
||||
@@ -74,6 +74,35 @@ namespace Content.Server.Nutrition.EntitySystems
|
||||
var openedText =
|
||||
Loc.GetString(IsEmpty(uid, component) ? "drink-component-on-examine-is-empty" : "drink-component-on-examine-is-opened");
|
||||
args.Message.AddMarkup($"\n{Loc.GetString("drink-component-on-examine-details-text", ("colorName", color), ("text", openedText))}");
|
||||
if (!IsEmpty(uid, component))
|
||||
{
|
||||
if (TryComp<ExaminableSolutionComponent>(component.Owner, out var comp))
|
||||
{
|
||||
//provide exact measurement for beakers
|
||||
args.Message.AddMarkup($" - {Loc.GetString("drink-component-on-examine-exact-volume", ("amount", _solutionContainerSystem.DrainAvailable(uid)))}");
|
||||
}
|
||||
else
|
||||
{
|
||||
//general approximation
|
||||
string remainingString;
|
||||
switch ((int)_solutionContainerSystem.PercentFull(uid))
|
||||
{
|
||||
case int perc when perc == 100:
|
||||
remainingString = "drink-component-on-examine-is-full";
|
||||
break;
|
||||
case int perc when perc > 66:
|
||||
remainingString = "drink-component-on-examine-is-mostly-full";
|
||||
break;
|
||||
case int perc when perc > 33:
|
||||
remainingString = HalfEmptyOrHalfFull(args);
|
||||
break;
|
||||
default:
|
||||
remainingString = "drink-component-on-examine-is-mostly-empty";
|
||||
break;
|
||||
}
|
||||
args.Message.AddMarkup($" - {Loc.GetString(remainingString)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetOpen(EntityUid uid, bool opened = false, DrinkComponent? component = null)
|
||||
@@ -353,5 +382,17 @@ namespace Content.Server.Nutrition.EntitySystems
|
||||
|
||||
ev.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
// some see half empty, and others see half full
|
||||
private string HalfEmptyOrHalfFull(ExaminedEvent args)
|
||||
{
|
||||
string remainingString = "drink-component-on-examine-is-half-full";
|
||||
|
||||
if (TryComp<MetaDataComponent>(args.Examiner, out var examiner) && examiner.EntityName.Length > 0
|
||||
&& string.Compare(examiner.EntityName.Substring(0, 1), "m", StringComparison.InvariantCultureIgnoreCase) > 0)
|
||||
remainingString = "drink-component-on-examine-is-half-empty";
|
||||
|
||||
return remainingString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,12 @@ drink-component-on-use-is-empty = {$owner} is empty!
|
||||
drink-component-on-examine-is-empty = Empty
|
||||
drink-component-on-examine-is-opened = Opened
|
||||
drink-component-on-examine-details-text = [color={$colorName}]{$text}[/color]
|
||||
drink-component-on-examine-is-full = Full
|
||||
drink-component-on-examine-is-mostly-full = Mostly Full
|
||||
drink-component-on-examine-is-half-full = Halfway Full
|
||||
drink-component-on-examine-is-half-empty = Halfway Empty
|
||||
drink-component-on-examine-is-mostly-empty = Mostly Empty
|
||||
drink-component-on-examine-exact-volume = {$amount}u Full
|
||||
drink-component-try-use-drink-not-open = Open {$owner} first!
|
||||
drink-component-try-use-drink-is-empty = {$entity} is empty!
|
||||
drink-component-try-use-drink-cannot-drink = You can't drink anything!
|
||||
|
||||
Reference in New Issue
Block a user