-
Notifications
You must be signed in to change notification settings - Fork 55
Allergies exist, Please don't make me regret this. (I already do) #284
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
ScarlettJFG
wants to merge
6
commits into
Floof-Station:master
Choose a base branch
from
ScarlettJFG:Major-Additions
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 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a56bc07
Allergies exist,Please don't make me regret this.
ScarlettJFG 17ea64b
Update Content.Client/Content.Client.csproj
ScarlettJFG 2e4a570
Database Migration files re-created, took a minute.
ScarlettJFG 8fa9e06
Merge branch 'Floof-Station:master' into Major-Additions
ScarlettJFG 9240a02
Third time is...hopefully the charm.
ScarlettJFG fd0e5a8
Merge remote-tracking branch 'Panta-Rhei/Major-Additions' into Major-…
ScarlettJFG 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
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
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
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,29 @@ | ||
| <BoxContainer xmlns="https://spacestation14.io" Orientation="Vertical" HorizontalExpand="True" Margin="5"> | ||
| <!-- Allergen lists --> | ||
| <BoxContainer Orientation="Horizontal" SeparationOverride="5" VerticalExpand="True"> | ||
| <!-- Unused reagents --> | ||
| <BoxContainer Orientation="Vertical" HorizontalExpand="True"> | ||
| <OptionButton Name="CReagentGroupButton" StyleClasses="OpenLeft" /> | ||
| <LineEdit Name="CReagentSearch" PlaceHolder="{Loc 'cd-allergies-editor-search'}" /> | ||
| <ItemList Name="CReagents" VerticalExpand="True" MinSize="275 250" /> | ||
| </BoxContainer> | ||
|
|
||
| <BoxContainer Orientation="Vertical" Align="Center" MinSize="50 250"> | ||
| <Button Name="CAllergyAdd" Text="+" /> | ||
| <Button Name="CAllergyRemove" Text="-" /> | ||
| </BoxContainer> | ||
|
|
||
| <!-- Current allergies --> | ||
| <BoxContainer Orientation="Vertical" HorizontalExpand="True"> | ||
| <Label Text="{Loc 'cd-allergies-editor-allergies'}" /> | ||
| <ItemList Name="CAllergies" VerticalExpand="True" MinSize="275 250" /> | ||
| </BoxContainer> | ||
| </BoxContainer> | ||
|
|
||
| <!-- Allergy attributes --> | ||
| <BoxContainer Name="CAllergyAttributes" VerticalExpand="True"> | ||
| <Label Text="{Loc 'cd-allergies-editor-intensity'}" /> | ||
| <Control HorizontalExpand="True" /> | ||
| <OptionButton Name="CIntensityButton" StyleClasses="OpenLeft" /> | ||
| </BoxContainer> | ||
| </BoxContainer> |
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,242 @@ | ||
| using System.Collections.Immutable; | ||
| using System.Linq; | ||
| using Content.Shared.Chemistry.Reagent; | ||
| using Content.Shared.FixedPoint; | ||
| using Robust.Client.AutoGenerated; | ||
| using Robust.Client.Graphics; | ||
| using Robust.Client.UserInterface.Controls; | ||
| using Robust.Client.UserInterface.XAML; | ||
| using Robust.Shared.Prototypes; | ||
| using SixLabors.ImageSharp; | ||
| using SixLabors.ImageSharp.PixelFormats; | ||
|
|
||
| namespace Content.Client._CD.Humanoid; | ||
|
|
||
| [GenerateTypedNameReferences] | ||
| public sealed partial class AllergyPicker : BoxContainer | ||
| { | ||
| [Dependency] private readonly IPrototypeManager _prototypeManager = default!; | ||
|
|
||
| private readonly Texture _textureWhite; | ||
|
|
||
| private readonly Action<Dictionary<ReagentPrototype, FixedPoint2>> _onUpdateAllergies; | ||
|
|
||
| private Dictionary<ReagentPrototype, FixedPoint2> _currentAllergies = new(); | ||
|
|
||
| private ItemList.Item? _selectedAllergy; | ||
| private int _selectedReagentGroup; | ||
| private ItemList.Item? _selectedUnusedAllergy; | ||
|
|
||
| private readonly ImmutableList<(string, ImmutableList<ReagentPrototype>)> _reagentGroups; | ||
|
|
||
|
|
||
| // As hundredths | ||
| public enum Intensity | ||
| { | ||
| Mild = 0_50, | ||
| Moderate = 1_00, | ||
| Severe = 5_00, | ||
| Extreme = 100_00, | ||
| } | ||
|
|
||
| public AllergyPicker(Action<Dictionary<ReagentPrototype, FixedPoint2>> onUpdateAllergies) | ||
| { | ||
| _onUpdateAllergies = onUpdateAllergies; | ||
|
|
||
| RobustXamlLoader.Load(this); | ||
| IoCManager.InjectDependencies(this); | ||
|
|
||
| var white = new Image<Rgba32>(32, 32); | ||
| for (var x = 0; x < 32; x++) | ||
| { | ||
| for (var y = 0; y < 32; y++) | ||
| { | ||
| white[x, y] = new Rgba32(255, 255, 255, 255); | ||
| } | ||
| } | ||
|
|
||
| _textureWhite = Texture.LoadFromImage(white); | ||
|
|
||
| _reagentGroups = _prototypeManager.EnumeratePrototypes<ReagentPrototype>() | ||
| .Select(reagent => reagent.Group) | ||
| .Distinct() | ||
| .Order() | ||
| .Select(group => | ||
| { | ||
| var reagents = _prototypeManager.EnumeratePrototypes<ReagentPrototype>() | ||
| .Where(reagent => reagent.Group.Equals(group)) | ||
| .OrderBy(reagent => reagent.LocalizedName) | ||
| .ToImmutableList(); | ||
| return (group, reagents); | ||
| }) | ||
| .Where(tuple => !tuple.reagents.IsEmpty) | ||
| .ToImmutableList(); | ||
|
|
||
| PopulateIntensities(); | ||
|
|
||
| CReagentGroupButton.OnItemSelected += OnGroupChange; | ||
| CReagentSearch.OnTextChanged += args => PopulateReagents(args.Text); | ||
|
|
||
| CReagents.OnItemSelected += item => _selectedUnusedAllergy = CReagents[item.ItemIndex]; | ||
|
|
||
| CAllergyAdd.OnPressed += _ => AllergyAdd(); | ||
| CAllergyRemove.OnPressed += _ => AllergyRemove(); | ||
|
|
||
| CAllergies.OnItemSelected += OnAllergySelected; | ||
|
|
||
| CIntensityButton.OnItemSelected += args => | ||
| { | ||
| if (CIntensityButton.IsItemDisabled(0)) | ||
| CIntensityButton.RemoveItem(0); | ||
|
|
||
| CIntensityButton.SelectId(args.Id); | ||
| _currentAllergies[(ReagentPrototype)_selectedAllergy!.Metadata!] = FixedPoint2.FromCents(args.Id); | ||
| _onUpdateAllergies.Invoke(_currentAllergies); | ||
| }; | ||
| } | ||
|
|
||
| private void PopulateIntensities(FixedPoint2? custom = null) | ||
| { | ||
| CIntensityButton.Clear(); | ||
| if (custom is not null) | ||
| { | ||
| CIntensityButton.AddItem(custom.Value.ToString(), custom.Value.Value); | ||
| CIntensityButton.SetItemDisabled(0, true); | ||
| } | ||
| foreach (var level in Enum.GetValues<Intensity>()) | ||
| { | ||
| CIntensityButton.AddItem( | ||
| Loc.GetString("cd-allergies-editor-intensity-" + Enum.GetName(level)!.ToLower()), | ||
| (int)level | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| private ItemList.Item GetReagentItem(ItemList list, ReagentPrototype reagent) | ||
| { | ||
| return new ItemList.Item(list) | ||
| { | ||
| Text = reagent.LocalizedName[0].ToString().ToUpper() + reagent.LocalizedName[1..], | ||
| Selectable = true, | ||
| Metadata = reagent, | ||
| Icon = _textureWhite, | ||
| IconModulate = reagent.SubstanceColor, | ||
| }; | ||
| } | ||
|
|
||
| public void SetData(Dictionary<ReagentPrototype, FixedPoint2> newAllergies) | ||
| { | ||
| _currentAllergies = newAllergies; | ||
| PopulateReagents(CReagentSearch.Text); | ||
| PopulateAllergies(); | ||
| } | ||
|
|
||
| private void SetupCategoryButtons() | ||
| { | ||
| CReagentGroupButton.Clear(); | ||
|
|
||
| foreach (var (group, _) in _reagentGroups) | ||
| { | ||
| CReagentGroupButton.AddItem(group); | ||
| } | ||
|
|
||
| CReagentGroupButton.SelectId(_selectedReagentGroup); | ||
| } | ||
|
|
||
| private void PopulateReagents(string filter) | ||
| { | ||
| SetupCategoryButtons(); | ||
|
|
||
| CReagents.Clear(); | ||
| _selectedUnusedAllergy = null; | ||
|
|
||
| var sortedReagents = _reagentGroups[_selectedReagentGroup] | ||
| .Item2 | ||
| .Where(m => | ||
| m.ID.Contains(filter, StringComparison.CurrentCultureIgnoreCase) || | ||
| m.LocalizedName.Contains(filter, StringComparison.CurrentCultureIgnoreCase) | ||
| ); | ||
|
|
||
| foreach (var reagent in sortedReagents) | ||
| { | ||
| if (_currentAllergies.ContainsKey(reagent)) | ||
| continue; | ||
|
|
||
| CReagents.Add(GetReagentItem(CReagents, reagent)); | ||
| } | ||
| } | ||
|
|
||
| private void PopulateAllergies() | ||
| { | ||
| CAllergies.Clear(); | ||
| CAllergyAttributes.Visible = false; | ||
| _selectedAllergy = null; | ||
|
|
||
| foreach (var reagent in _currentAllergies.Keys) | ||
| { | ||
| CAllergies.Add(GetReagentItem(CAllergies, reagent)); | ||
| } | ||
| } | ||
|
|
||
| private void OnGroupChange(OptionButton.ItemSelectedEventArgs group) | ||
| { | ||
| CReagentGroupButton.SelectId(group.Id); | ||
| _selectedReagentGroup = group.Id; | ||
| PopulateReagents(CReagentSearch.Text); | ||
| PopulateAllergies(); | ||
| } | ||
|
|
||
| private void OnAllergySelected(ItemList.ItemListSelectedEventArgs item) | ||
| { | ||
| _selectedAllergy = CAllergies[item.ItemIndex]; | ||
| var intensity = _currentAllergies[(ReagentPrototype)_selectedAllergy.Metadata!]; | ||
|
|
||
| if (CIntensityButton.IsItemDisabled(0)) | ||
| CIntensityButton.RemoveItem(0); | ||
|
|
||
| if (!CIntensityButton.TrySelectId(intensity.Value)) | ||
| { | ||
| PopulateIntensities(intensity); | ||
| CIntensityButton.SelectId(intensity.Value); | ||
| } | ||
|
|
||
| CAllergyAttributes.Visible = true; | ||
| } | ||
|
|
||
| private void AllergyAdd() | ||
| { | ||
| if (_selectedUnusedAllergy is null) | ||
| return; | ||
|
|
||
| var reagent = (ReagentPrototype)_selectedUnusedAllergy.Metadata!; | ||
| CReagents.Remove(_selectedUnusedAllergy); | ||
| _selectedUnusedAllergy = null; | ||
|
|
||
| _currentAllergies[reagent] = 1.0; | ||
| CAllergies.Add(GetReagentItem(CAllergies, reagent)); | ||
|
|
||
| _onUpdateAllergies.Invoke(_currentAllergies); | ||
| } | ||
|
|
||
| private void AllergyRemove() | ||
| { | ||
| if (_selectedAllergy is null) | ||
| return; | ||
|
|
||
| var reagent = (ReagentPrototype)_selectedAllergy.Metadata!; | ||
|
|
||
| _currentAllergies.Remove(reagent); | ||
|
|
||
| CAllergies.Remove(_selectedAllergy); | ||
|
|
||
| if (reagent.Group == _reagentGroups[_selectedReagentGroup].Item1) | ||
| { | ||
| CReagents.Add(GetReagentItem(CReagents, reagent)); | ||
| CReagents.SortItemsByText(); | ||
| } | ||
|
|
||
| _selectedAllergy = null; | ||
| CAllergyAttributes.Visible = false; | ||
| _onUpdateAllergies.Invoke(_currentAllergies); | ||
| } | ||
| } |
Empty file.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.