-
Notifications
You must be signed in to change notification settings - Fork 439
Oxygen Generator Improvements #15497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jade-Harleyy
wants to merge
9
commits into
FakeFishGames:master
Choose a base branch
from
Jade-Harleyy:oxygen-changes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e654e3b
Code changes and base content.
Jade-Harleyy ce2b099
Content changes.
Jade-Harleyy fce4b42
Change position of this.
Jade-Harleyy 57b7500
Address review comments.
Jade-Harleyy 2ab447f
Address review comments:
Jade-Harleyy 6dc0643
Make this more accurate.
Jade-Harleyy fdb553e
Re-balance upgrades:
Jade-Harleyy 1708511
Decrease the warning indicator sizes as well.
Jade-Harleyy 03aeeab
Revert "Decrease the warning indicator sizes as well."
Jade-Harleyy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
Barotrauma/BarotraumaClient/ClientSource/Items/Components/Machines/OxygenGenerator.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| using Barotrauma.Networking; | ||
| using Microsoft.Xna.Framework; | ||
|
|
||
| namespace Barotrauma.Items.Components | ||
| { | ||
| internal partial class OxygenGenerator : IServerSerializable, IClientSerializable | ||
| { | ||
| private GUITickBox powerIndicator, autoControlIndicator; | ||
| private GUIScrollBar rateSlider; | ||
|
|
||
| [Serialize(0.5f, IsPropertySaveable.Yes)] | ||
| public float RateWarningIndicatorLow { get; set; } | ||
|
|
||
| [Serialize(0.25f, IsPropertySaveable.Yes)] | ||
| public float RateWarningIndicatorExtremelyLow { get; set; } | ||
|
|
||
| protected override void CreateGUI() | ||
| { | ||
| if (GuiFrame == null) | ||
| { | ||
| DebugConsole.AddWarning($"OxygenGenerator component of {Item.Name} ({Item.Prefab.Identifier}) has no GUIFrame defined.", Item.ContentPackage); | ||
| return; | ||
| } | ||
| GUILayoutGroup paddedFrame = new(new RectTransform(GuiFrame.Rect.Size - GUIStyle.ItemFrameMargin, GuiFrame.RectTransform, Anchor.Center) { AbsoluteOffset = GUIStyle.ItemFrameOffset }) | ||
| { | ||
| Stretch = true, | ||
| RelativeSpacing = 0.1f | ||
| }; | ||
|
|
||
| int indicatorHeight = MathUtils.RoundToInt(GUIStyle.SubHeadingFont.LineHeight * 2); | ||
| GUILayoutGroup indicatorArea = new(new RectTransform(Vector2.One, paddedFrame.RectTransform), isHorizontal: true, Anchor.CenterLeft) { Stretch = true }; | ||
| powerIndicator = new GUITickBox(new RectTransform(Vector2.UnitX, indicatorArea.RectTransform, minSize: (0, indicatorHeight)), TextManager.Get("EnginePowered"), GUIStyle.SubHeadingFont, style: "IndicatorLightGreen") | ||
| { | ||
| CanBeFocused = false, | ||
| OnAddedToGUIUpdateList = comp => comp.Selected = HasPower && IsActive, | ||
| TextBlock = { Wrap = true } | ||
| }; | ||
| powerIndicator.TextBlock.OverrideTextColor(GUIStyle.TextColorNormal); | ||
| autoControlIndicator = new GUITickBox(new RectTransform(Vector2.UnitX, indicatorArea.RectTransform, minSize: (0, indicatorHeight)), TextManager.Get("PumpAutoControl", "ReactorAutoControl"), GUIStyle.SubHeadingFont, style: "IndicatorLightYellow") | ||
| { | ||
| Enabled = false, | ||
| OnAddedToGUIUpdateList = comp => comp.Selected = controlLockTimer > 0f, | ||
| ToolTip = TextManager.Get("AutoControlTip"), | ||
| TextBlock = { Wrap = true, TextAlignment = Alignment.CenterRight } | ||
| }; | ||
| autoControlIndicator.TextBlock.OverrideTextColor(GUIStyle.TextColorNormal); | ||
| autoControlIndicator.TextBlock.SetAsFirstChild(); | ||
| GUITextBlock.AutoScaleAndNormalize(powerIndicator.TextBlock, autoControlIndicator.TextBlock); | ||
|
|
||
| GUITextBlock rateName = new(new RectTransform(Vector2.UnitX, paddedFrame.RectTransform), TextManager.Get("OxygenGenerationRate"), GUIStyle.TextColorNormal, GUIStyle.SubHeadingFont, Alignment.CenterLeft); | ||
| GUITextBlock rateText = new(new RectTransform(Vector2.One, rateName.RectTransform), "", GUIStyle.TextColorNormal, GUIStyle.Font, Alignment.CenterRight) | ||
| { | ||
| TextGetter = () => $"{MathUtils.RoundToInt(generatedAmount * generationRatio)}/s ({MathUtils.RoundToInt(generationRatio * 100f)}%)" | ||
| }; | ||
| if (rateText.TextSize.X > rateText.Rect.Width) { rateText.Font = GUIStyle.SmallFont; } | ||
|
|
||
| GUIFrame rateSliderContainer = new(new RectTransform(Vector2.UnitX, paddedFrame.RectTransform, minSize: (0, 50))); | ||
| new GUICustomComponent(new RectTransform(new Vector2(0.95f, 0.9f), rateSliderContainer.RectTransform, Anchor.Center), (sb, comp) => | ||
| { | ||
| if (RateWarningIndicatorLow > 0f) | ||
| { | ||
| GUI.DrawRectangle(sb, comp.Rect.Location.ToVector2(), ( comp.Rect.Width * RateWarningIndicatorLow, comp.Rect.Height), GUIStyle.Orange, isFilled: true); | ||
| } | ||
| if (RateWarningIndicatorExtremelyLow > 0f) | ||
| { | ||
| GUI.DrawRectangle(sb, comp.Rect.Location.ToVector2(), (comp.Rect.Width * RateWarningIndicatorExtremelyLow, comp.Rect.Height), GUIStyle.Red, isFilled: true); | ||
| } | ||
| }); | ||
| rateSlider = new GUIScrollBar(new RectTransform(Vector2.One, rateSliderContainer.RectTransform, Anchor.Center), barSize: 0.1f, isHorizontal: true, style: "DeviceSliderSeeThrough") | ||
| { | ||
| Step = GenerationRatioStep, | ||
| OnMoved = (_, newRatio) => | ||
| { | ||
| GenerationRatio = newRatio; | ||
| if (GameMain.Client != null) | ||
| { | ||
| item.CreateClientEvent(this); | ||
| correctionTimer = CorrectionDelay; | ||
| } | ||
| return true; | ||
| }, | ||
| OnAddedToGUIUpdateList = comp => comp.Enabled = controlLockTimer <= 0f | ||
| }; | ||
| rateSlider.Bar.RectTransform.MaxSize = new Point(rateSlider.Bar.Rect.Height); | ||
| } | ||
|
|
||
| partial void InitProjSpecific() => CreateGUI(); | ||
|
|
||
| public override void OnItemLoaded() | ||
| { | ||
| base.OnItemLoaded(); | ||
| UpdateSlider(); | ||
| } | ||
|
|
||
| #region Networking | ||
| public void ClientEventWrite(IWriteMessage msg, NetEntityEvent.IData extraData) => WriteGenerationRatio(msg); | ||
| public void ClientEventRead(IReadMessage msg, float sendingTime) | ||
| { | ||
| if (correctionTimer > 0f) | ||
| { | ||
| StartDelayedCorrection(msg.ExtractBits(4), sendingTime); | ||
| return; | ||
| } | ||
|
|
||
| GenerationRatio = ReadGenerationRatio(msg); | ||
| } | ||
| #endregion | ||
|
|
||
| private void UpdateSlider() | ||
| { | ||
| if (rateSlider != null) | ||
| { | ||
| rateSlider.BarScroll = generationRatio; | ||
| } | ||
| } | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
Barotrauma/BarotraumaServer/ServerSource/Items/Components/Machines/OxygenGenerator.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| using Barotrauma.Networking; | ||
|
|
||
| namespace Barotrauma.Items.Components | ||
| { | ||
| internal partial class OxygenGenerator : IServerSerializable, IClientSerializable | ||
| { | ||
| #region Networking | ||
| public void ServerEventWrite(IWriteMessage msg, Client c, NetEntityEvent.IData extraData = null) => WriteGenerationRatio(msg); | ||
| public void ServerEventRead(IReadMessage msg, Client c) | ||
| { | ||
| float newGenerationRatio = ReadGenerationRatio(msg); | ||
|
|
||
| if (item.CanClientAccess(c)) | ||
| { | ||
| GenerationRatio = newGenerationRatio; | ||
| GameServer.Log($"{GameServer.CharacterLogName(c.Character)} set the oxygen generation amount of {item.Name} to {MathUtils.RoundToInt(generationRatio * 100f)}%", ServerLog.MessageType.ItemInteraction); | ||
| } | ||
|
|
||
| item.CreateServerEvent(this); | ||
| } | ||
| #endregion | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
Barotrauma/BarotraumaShared/LocalMods/oxygen-changes/Locale/English.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <Text language="English"> | ||
| <OxygenGenerationRate>Oxygen Generation Rate</OxygenGenerationRate> | ||
| <connection.oxygen.setrate>set_oxygen_rate</connection.oxygen.setrate> | ||
| <connection.oxygen.rateout>oxygen_rate_out</connection.oxygen.rateout> | ||
| </Text> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we intend to change the vanilla content, these lines should be defined in EnglishVanillaNew.xml, which is where we take the new lines to be translated. When the translations are done, we'll move the new lines in EnglishVanilla.xml and the other language files. For a mod, I think these would be fine.