-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'space-sunrise:master' into fully-translate
- Loading branch information
Showing
95 changed files
with
1,690 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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,53 @@ | ||
using Content.Shared.Humanoid.Markings; | ||
using Content.Shared._Sunrise.Razor; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.UserInterface; | ||
|
||
namespace Content.Client._Sunrise.Razor; | ||
|
||
public sealed class RazorBoundUserInterface(EntityUid owner, Enum uiKey) : BoundUserInterface(owner, uiKey) | ||
{ | ||
[ViewVariables] | ||
private RazorWindow? _window; | ||
|
||
protected override void Open() | ||
{ | ||
base.Open(); | ||
_window = this.CreateWindow<RazorWindow>(); | ||
|
||
_window.OnHairSelected += tuple => SelectHair(RazorCategory.Hair, tuple.id, tuple.slot); | ||
_window.OnHairSlotAdded += delegate () { AddSlot(RazorCategory.Hair); }; | ||
_window.OnHairSlotRemoved += args => RemoveSlot(RazorCategory.Hair, args); | ||
|
||
_window.OnFacialHairSelected += tuple => SelectHair(RazorCategory.FacialHair, tuple.id, tuple.slot); | ||
_window.OnFacialHairSlotAdded += delegate () { AddSlot(RazorCategory.FacialHair); }; | ||
_window.OnFacialHairSlotRemoved += args => RemoveSlot(RazorCategory.FacialHair, args); | ||
} | ||
|
||
private void SelectHair(RazorCategory category, string marking, int slot) | ||
{ | ||
SendMessage(new RazorSelectMessage(category, marking, slot)); | ||
} | ||
|
||
private void RemoveSlot(RazorCategory category, int slot) | ||
{ | ||
SendMessage(new RazorRemoveSlotMessage(category, slot)); | ||
} | ||
|
||
private void AddSlot(RazorCategory category) | ||
{ | ||
SendMessage(new RazorAddSlotMessage(category)); | ||
} | ||
|
||
protected override void UpdateState(BoundUserInterfaceState state) | ||
{ | ||
base.UpdateState(state); | ||
|
||
if (state is not RazorUiState data || _window == null) | ||
{ | ||
return; | ||
} | ||
|
||
_window.UpdateState(data); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Content.Client/_Sunrise/Razor/RazorSingleMarkingPicker.xaml
This file contains 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,20 @@ | ||
<BoxContainer xmlns="https://spacestation14.io" | ||
Orientation="Vertical" | ||
HorizontalExpand="True" | ||
VerticalExpand="True"> | ||
<!-- "Slot" selection --> | ||
<Label Name="CategoryName" /> | ||
<BoxContainer Name="SlotSelectorContainer" HorizontalExpand="True"> | ||
<OptionButton Name="SlotSelector" HorizontalExpand="True" StyleClasses="OpenBoth" /> | ||
<Button Name="AddButton" Text="{Loc 'marking-slot-add'}" StyleClasses="OpenBoth" /> | ||
<Button Name="RemoveButton" Text="{Loc 'marking-slot-remove'}" StyleClasses="OpenLeft" /> | ||
</BoxContainer> | ||
<LineEdit Name="Search" PlaceHolder="{Loc 'markings-search'}" HorizontalExpand="True" /> | ||
|
||
<!-- Item list --> | ||
<BoxContainer Name="MarkingSelectorContainer" Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True"> | ||
<ScrollContainer MinHeight="500" VerticalExpand="True" HorizontalExpand="True"> | ||
<ItemList Name="MarkingList" VerticalExpand="True" /> | ||
</ScrollContainer> | ||
</BoxContainer> | ||
</BoxContainer> |
240 changes: 240 additions & 0 deletions
240
Content.Client/_Sunrise/Razor/RazorSingleMarkingPicker.xaml.cs
This file contains 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,240 @@ | ||
using System.Linq; | ||
using Content.Shared.Humanoid.Markings; | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.UserInterface.Controls; | ||
using Robust.Client.UserInterface.XAML; | ||
using Robust.Client.Utility; | ||
|
||
namespace Content.Client._Sunrise.Razor; | ||
|
||
[GenerateTypedNameReferences] | ||
public sealed partial class RazorSingleMarkingPicker : BoxContainer | ||
{ | ||
[Dependency] private readonly MarkingManager _markingManager = default!; | ||
|
||
public Action<(int slot, string id)>? OnMarkingSelect; | ||
public Action<int>? OnSlotRemove; | ||
public Action? OnSlotAdd; | ||
|
||
private int _slot = -1; | ||
private int Slot | ||
{ | ||
get | ||
{ | ||
if (_markings == null || _markings.Count == 0) | ||
{ | ||
_slot = -1; | ||
} | ||
else if (_slot == -1) | ||
{ | ||
_slot = 0; | ||
} | ||
|
||
return _slot; | ||
} | ||
set | ||
{ | ||
if (_markings == null || _markings.Count == 0) | ||
{ | ||
_slot = -1; | ||
return; | ||
} | ||
|
||
_slot = value; | ||
_ignoreItemSelected = true; | ||
|
||
foreach (var item in MarkingList) | ||
{ | ||
item.Selected = (string) item.Metadata! == _markings[_slot].MarkingId; | ||
} | ||
|
||
_ignoreItemSelected = false; | ||
} | ||
} | ||
|
||
private int _totalPoints; | ||
|
||
private bool _ignoreItemSelected; | ||
|
||
private MarkingCategories _category; | ||
public MarkingCategories Category | ||
{ | ||
get => _category; | ||
set | ||
{ | ||
_category = value; | ||
CategoryName.Text = Loc.GetString($"markings-category-{_category}"); | ||
|
||
if (!string.IsNullOrEmpty(_species)) | ||
{ | ||
PopulateList(Search.Text); | ||
} | ||
} | ||
} | ||
private IReadOnlyDictionary<string, MarkingPrototype>? _markingPrototypeCache; | ||
|
||
private string? _species; | ||
private List<Marking>? _markings; | ||
|
||
private int PointsLeft | ||
{ | ||
get | ||
{ | ||
if (_markings == null) | ||
{ | ||
return 0; | ||
} | ||
|
||
if (_totalPoints < 0) | ||
{ | ||
return -1; | ||
} | ||
|
||
return _totalPoints - _markings.Count; | ||
} | ||
} | ||
|
||
private int PointsUsed => _markings?.Count ?? 0; | ||
|
||
public RazorSingleMarkingPicker() | ||
{ | ||
RobustXamlLoader.Load(this); | ||
IoCManager.InjectDependencies(this); | ||
|
||
MarkingList.OnItemSelected += SelectMarking; | ||
AddButton.OnPressed += _ => | ||
{ | ||
OnSlotAdd!(); | ||
}; | ||
|
||
SlotSelector.OnItemSelected += args => | ||
{ | ||
Slot = args.Button.SelectedId; | ||
}; | ||
|
||
RemoveButton.OnPressed += _ => | ||
{ | ||
OnSlotRemove!(_slot); | ||
}; | ||
|
||
Search.OnTextChanged += args => | ||
{ | ||
PopulateList(args.Text); | ||
}; | ||
} | ||
|
||
public void UpdateData(List<Marking> markings, string species, int totalPoints) | ||
{ | ||
_markings = markings; | ||
_species = species; | ||
_totalPoints = totalPoints; | ||
|
||
_markingPrototypeCache = _markingManager.MarkingsByCategoryAndSpecies(Category, _species); | ||
|
||
Visible = _markingPrototypeCache.Count != 0; | ||
if (_markingPrototypeCache.Count == 0) | ||
{ | ||
return; | ||
} | ||
|
||
PopulateList(Search.Text); | ||
PopulateSlotSelector(); | ||
} | ||
|
||
public void PopulateList(string filter) | ||
{ | ||
if (string.IsNullOrEmpty(_species)) | ||
{ | ||
throw new ArgumentException("Tried to populate marking list without a set species!"); | ||
} | ||
|
||
_markingPrototypeCache ??= _markingManager.MarkingsByCategoryAndSpecies(Category, _species); | ||
|
||
MarkingSelectorContainer.Visible = _markings != null && _markings.Count != 0; | ||
if (_markings == null || _markings.Count == 0) | ||
{ | ||
return; | ||
} | ||
|
||
MarkingList.Clear(); | ||
|
||
var sortedMarkings = _markingPrototypeCache.Where(m => | ||
m.Key.ToLower().Contains(filter.ToLower()) || | ||
GetMarkingName(m.Value).ToLower().Contains(filter.ToLower()) | ||
) | ||
.OrderBy(p => Loc.GetString($"marking-{p.Key}")); | ||
|
||
foreach (var (id, marking) in sortedMarkings) | ||
{ | ||
var item = MarkingList.AddItem(Loc.GetString($"marking-{id}"), marking.Sprites[0].Frame0()); | ||
item.Metadata = marking.ID; | ||
if (marking.SponsorOnly) | ||
{ | ||
item.Disabled = false; | ||
item.Text = $"{GetMarkingName(marking)} [СПОНСОР] "; | ||
} | ||
|
||
if (_markings[Slot].MarkingId == id) | ||
{ | ||
_ignoreItemSelected = true; | ||
item.Selected = true; | ||
_ignoreItemSelected = false; | ||
} | ||
} | ||
} | ||
|
||
private void SelectMarking(ItemList.ItemListSelectedEventArgs args) | ||
{ | ||
if (_ignoreItemSelected) | ||
{ | ||
return; | ||
} | ||
|
||
var id = (string) MarkingList[args.ItemIndex].Metadata!; | ||
if (!_markingManager.Markings.TryGetValue(id, out var proto)) | ||
{ | ||
throw new ArgumentException("Attempted to select non-existent marking."); | ||
} | ||
|
||
var oldMarking = _markings![Slot]; | ||
_markings[Slot] = proto.AsMarking(); | ||
|
||
for (var i = 0; i < _markings[Slot].MarkingColors.Count && i < oldMarking.MarkingColors.Count; i++) | ||
{ | ||
_markings[Slot].SetColor(i, oldMarking.MarkingColors[i]); | ||
} | ||
|
||
OnMarkingSelect!((_slot, id)); | ||
} | ||
|
||
private void PopulateSlotSelector() | ||
{ | ||
SlotSelector.Visible = Slot >= 0; | ||
Search.Visible = Slot >= 0; | ||
AddButton.HorizontalExpand = Slot < 0; | ||
RemoveButton.HorizontalExpand = Slot < 0; | ||
AddButton.Disabled = PointsLeft == 0 && _totalPoints > -1 ; | ||
RemoveButton.Disabled = PointsUsed == 0; | ||
SlotSelector.Clear(); | ||
|
||
if (Slot < 0) | ||
{ | ||
return; | ||
} | ||
|
||
for (var i = 0; i < PointsUsed; i++) | ||
{ | ||
SlotSelector.AddItem($"Слот {i + 1}", i); | ||
|
||
if (i == _slot) | ||
{ | ||
SlotSelector.SelectId(i); | ||
} | ||
} | ||
} | ||
|
||
private string GetMarkingName(MarkingPrototype marking) | ||
{ | ||
return Loc.GetString($"marking-{marking.ID}"); | ||
} | ||
} |
This file contains 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,8 @@ | ||
using Content.Shared._Sunrise.Razor; | ||
|
||
namespace Content.Client._Sunrise.Razor; | ||
|
||
public sealed class RazorSystem : SharedRazorSystem | ||
{ | ||
|
||
} |
This file contains 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,9 @@ | ||
<DefaultWindow xmlns="https://spacestation14.io" | ||
xmlns:razor="clr-namespace:Content.Client._Sunrise.Razor" | ||
Title="{Loc 'razor-window-title'}" | ||
MinSize="600 400"> | ||
<BoxContainer> | ||
<razor:RazorSingleMarkingPicker Name="HairPicker" Category="Hair" /> | ||
<razor:RazorSingleMarkingPicker Name="FacialHairPicker" Category="FacialHair" /> | ||
</BoxContainer> | ||
</DefaultWindow> |
This file contains 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,44 @@ | ||
using Content.Shared.Humanoid.Markings; | ||
using Content.Shared._Sunrise.Razor; | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.UserInterface.Controls; | ||
using Robust.Client.UserInterface.CustomControls; | ||
using Robust.Client.UserInterface.XAML; | ||
|
||
namespace Content.Client._Sunrise.Razor; | ||
|
||
[GenerateTypedNameReferences] | ||
public sealed partial class RazorWindow : DefaultWindow | ||
{ | ||
public Action<(int slot, string id)>? OnHairSelected; | ||
public Action<int>? OnHairSlotRemoved; | ||
public Action? OnHairSlotAdded; | ||
|
||
public Action<(int slot, string id)>? OnFacialHairSelected; | ||
public Action<int>? OnFacialHairSlotRemoved; | ||
public Action? OnFacialHairSlotAdded; | ||
|
||
public RazorWindow() | ||
{ | ||
RobustXamlLoader.Load(this); | ||
|
||
HairPicker.OnMarkingSelect += args => OnHairSelected!(args); | ||
HairPicker.OnSlotRemove += args => OnHairSlotRemoved!(args); | ||
HairPicker.OnSlotAdd += delegate { OnHairSlotAdded!(); }; | ||
|
||
FacialHairPicker.OnMarkingSelect += args => OnFacialHairSelected!(args); | ||
FacialHairPicker.OnSlotRemove += args => OnFacialHairSlotRemoved!(args); | ||
FacialHairPicker.OnSlotAdd += delegate { OnFacialHairSlotAdded!(); }; | ||
} | ||
|
||
public void UpdateState(RazorUiState state) | ||
{ | ||
HairPicker.UpdateData(state.Hair, state.Species, state.HairSlotTotal); | ||
FacialHairPicker.UpdateData(state.FacialHair, state.Species, state.FacialHairSlotTotal); | ||
|
||
if (!HairPicker.Visible && !FacialHairPicker.Visible) | ||
{ | ||
AddChild(new Label { Text = Loc.GetString("magic-mirror-component-activate-user-has-no-hair") }); | ||
} | ||
} | ||
} |
Oops, something went wrong.