QoL для ХоПа (#369)

* add: nice job icons ui for HoP console

* Ebanniy rot

* add: Changing id visuals with HoP console

* cleanup

* add: remove drop down list and replace it with icon-buttons

* add: colored and sorted by department buttons

* add: columns

* tweak: nicer colors

* cleanup
This commit is contained in:
ThereDrD0
2024-06-20 22:29:26 +03:00
committed by GitHub
parent 76e46de7e9
commit cb37ba5714
12 changed files with 332 additions and 122 deletions

View File

@@ -13,6 +13,7 @@ namespace Content.Client.Access.UI;
public sealed partial class AccessLevelControl : GridContainer
{
public readonly Dictionary<ProtoId<AccessLevelPrototype>, Button> ButtonsList = new();
public readonly List<Dictionary<ProtoId<AccessLevelPrototype>, Button>> ButtonGroups = new ();
public AccessLevelControl()
{
@@ -39,6 +40,61 @@ public sealed partial class AccessLevelControl : GridContainer
}
}
public void PopulateForConsole(List<List<ProtoId<AccessLevelPrototype>>> accessLevels, IPrototypeManager prototypeManager)
{
var departmentColors = new List<String> // Colors from StyleNano.cs
{
"ButtonColorCommandDepartment",
"ButtonColorSecurityDepartment",
"ButtonColorMedicalDepartment",
"ButtonColorEngineeringDepartment",
"ButtonColorResearchingDepartment",
"ButtonColorCargoDepartment",
"ButtonColorServiceDepartment"
};
var currentColorIndex = 0;
foreach (var department in accessLevels)
{
Dictionary<ProtoId<AccessLevelPrototype>, Button> buttons = new();
foreach (var access in department)
{
if (!prototypeManager.TryIndex(access, out var accessLevel))
{
Logger.Error($"Unable to find accesslevel for {access}");
continue;
}
var newButton = new Button
{
Text = accessLevel.GetAccessLevelName(),
ToggleMode = true,
};
newButton.AddStyleClass(departmentColors[currentColorIndex]);
buttons.Add(accessLevel.ID, newButton);
}
ButtonGroups.Add(buttons);
currentColorIndex++;
}
}
public void UpdateStateConsole(
List<ProtoId<AccessLevelPrototype>> pressedList,
List<ProtoId<AccessLevelPrototype>>? enabledList = null)
{
foreach (var department in ButtonGroups)
{
foreach (var (accessName, button) in department)
{
button.Pressed = pressedList.Contains(accessName);
button.Disabled = !(enabledList?.Contains(accessName) ?? true);
}
}
}
public void UpdateState(
List<ProtoId<AccessLevelPrototype>> pressedList,
List<ProtoId<AccessLevelPrototype>>? enabledList = null)

View File

@@ -23,15 +23,15 @@ namespace Content.Client.Access.UI
protected override void Open()
{
base.Open();
List<ProtoId<AccessLevelPrototype>> accessLevels;
List<List<ProtoId<AccessLevelPrototype>>> accessLevels;
if (EntMan.TryGetComponent<IdCardConsoleComponent>(Owner, out var idCard))
{
accessLevels = idCard.AccessLevels;
accessLevels = idCard.AccessLevelsConsole;
}
else
{
accessLevels = new List<ProtoId<AccessLevelPrototype>>();
accessLevels = new List<List<ProtoId<AccessLevelPrototype>>>();
_idCardConsoleSystem.Log.Error($"No IdCardConsole component found for {EntMan.ToPrettyString(Owner)}!");
}

View File

@@ -26,16 +26,13 @@
<Button Name="JobTitleSaveButton" Text="{Loc 'id-card-console-window-save-button'}" Disabled="True" />
</GridContainer>
<Control MinSize="0 8" />
<GridContainer Columns="2">
<Label Text="{Loc 'id-card-console-window-job-selection-label'}" />
<OptionButton Name="JobPresetOptionButton" />
</GridContainer>
<Control Name="AccessLevelControlContainer" />
<GridContainer Name="AccessLevelControlContainer" Columns="7" HorizontalExpand="True" HorizontalAlignment="Center" >
<!-- WD EDIT -->
</GridContainer>
<GridContainer Name="CurrentJobIcon" Columns="2">
<Label Text="Текущая выбранная иконка для роли: " />
</GridContainer>
<GridContainer Name="JobIconsGrid" Columns="10" HorizontalAlignment="Center">
<GridContainer Name="JobIconsGrid" HorizontalAlignment="Center">
<!-- Job icon buttons are generated in the code -->
</GridContainer>
<!-- WD EDIT END -->

View File

@@ -24,9 +24,11 @@ namespace Content.Client.Access.UI
private readonly IdCardConsoleBoundUserInterface _owner;
private AccessLevelControl _accessButtons = new();
private GridContainer _grid = default!;
private readonly AccessLevelControl _groupAccessButtons = new();
private readonly Dictionary<string, TextureButton> _jobIconButtons = new(); //WD-EDIT
private readonly List<string> _jobPrototypeIds = new();
private string _newJob = "";
private string? _lastFullName;
private string? _lastJobTitle;
@@ -36,7 +38,7 @@ namespace Content.Client.Access.UI
public IdCardConsoleWindow(
IdCardConsoleBoundUserInterface owner,
IPrototypeManager prototypeManager,
List<ProtoId<AccessLevelPrototype>> accessLevels)
List<List<ProtoId<AccessLevelPrototype>>> accessLevels)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
@@ -59,26 +61,20 @@ namespace Content.Client.Access.UI
JobTitleSaveButton.OnPressed += _ => SubmitData();
var jobs = _prototypeManager.EnumeratePrototypes<JobPrototype>().ToList();
jobs.Sort((x, y) => string.Compare(x.LocalizedName, y.LocalizedName, StringComparison.CurrentCulture));
_groupAccessButtons.PopulateForConsole(accessLevels, prototypeManager);
foreach (var job in jobs)
foreach (var department in _groupAccessButtons.ButtonGroups)
{
if (!job.OverrideConsoleVisibility.GetValueOrDefault(job.SetPreference))
var departmentGrid = new GridContainer {};
foreach (var button in department.Values)
{
continue;
departmentGrid.AddChild(button);
}
_jobPrototypeIds.Add(job.ID);
JobPresetOptionButton.AddItem(Loc.GetString(job.Name), _jobPrototypeIds.Count - 1);
AccessLevelControlContainer.AddChild(departmentGrid);
}
JobPresetOptionButton.OnItemSelected += SelectJobPreset;
_accessButtons.Populate(accessLevels, prototypeManager);
AccessLevelControlContainer.AddChild(_accessButtons);
foreach (var (id, button) in _accessButtons.ButtonsList)
foreach (var (id, button) in _groupAccessButtons.ButtonsList)
{
button.OnPressed += _ => SubmitData();
}
@@ -92,72 +88,89 @@ namespace Content.Client.Access.UI
if (rsi == null)
return;
foreach (var jobIcon in idConsoleComponent.JobIcons)
foreach (var department in idConsoleComponent.JobIcons)
{
var newButton = new TextureButton
_grid = new GridContainer
{
TextureNormal = rsi.RSI.TryGetState(jobIcon, out var state) ? state.Frame0
: rsi.RSI.TryGetState("CustomId", out var customState) ? customState.Frame0
: null,
Scale = new Vector2(5, 5)
Columns = department.Count
};
_jobIconButtons.Add(jobIcon, newButton);
newButton.OnPressed += _ =>
foreach (var jobIcon in department)
{
_lastJobIcon = "JobIcon" + jobIcon;
SubmitData();
};
var newButton = new TextureButton
{
TextureNormal = rsi.RSI.TryGetState(jobIcon, out var state) ? state.Frame0
: rsi.RSI.TryGetState("CustomId", out var customState) ? customState.Frame0
: null,
Scale = new Vector2(5, 5)
};
JobIconsGrid.AddChild(newButton);
_jobIconButtons.TryAdd(jobIcon, newButton);
newButton.OnPressed += _ =>
{
SelectJobPreset(jobIcon);
_newJob = jobIcon;
_lastJobIcon = "JobIcon" + jobIcon;
SubmitData();
};
_grid.AddChild(newButton);
}
JobIconsGrid.AddChild(_grid);
}
//WD-EDIT
}
private void ClearAllAccess()
{
foreach (var button in _accessButtons.ButtonsList.Values)
foreach (var group in _groupAccessButtons.ButtonGroups)
{
if (button.Pressed)
foreach (var button in group.Values)
{
button.Pressed = false;
if (button.Pressed)
{
button.Pressed = false;
}
}
}
}
private void SelectJobPreset(OptionButton.ItemSelectedEventArgs args)
private void SelectJobPreset(string jobName)
{
if (!_prototypeManager.TryIndex(_jobPrototypeIds[args.Id], out JobPrototype? job))
if (!_prototypeManager.TryIndex(jobName, out JobPrototype? job))
{
return;
}
JobTitleLineEdit.Text = Loc.GetString(job.Name);
args.Button.SelectId(args.Id);
ClearAllAccess();
// this is a sussy way to do this
foreach (var access in job.Access)
{
if (_accessButtons.ButtonsList.TryGetValue(access, out var button) && !button.Disabled)
foreach (var group in _groupAccessButtons.ButtonGroups)
{
button.Pressed = true;
if (group.TryGetValue(access, out var button) && !button.Disabled)
{
button.Pressed = true;
}
}
}
foreach (var group in job.AccessGroups)
{
if (!_prototypeManager.TryIndex(group, out AccessGroupPrototype? groupPrototype))
{
continue;
}
foreach (var access in groupPrototype.Tags)
{
if (_accessButtons.ButtonsList.TryGetValue(access, out var button) && !button.Disabled)
foreach (var buttonGroup in _groupAccessButtons.ButtonGroups)
{
button.Pressed = true;
if (buttonGroup.TryGetValue(access, out var button) && !button.Disabled)
button.Pressed = true;
}
}
}
@@ -204,19 +217,12 @@ namespace Content.Client.Access.UI
JobTitleSaveButton.Disabled = !interfaceEnabled || !jobTitleDirty;
JobPresetOptionButton.Disabled = !interfaceEnabled;
_accessButtons.UpdateState(state.TargetIdAccessList?.ToList() ??
new List<ProtoId<AccessLevelPrototype>>(),
_groupAccessButtons.UpdateStateConsole(state.TargetIdAccessList?.ToList() ??
new List<ProtoId<AccessLevelPrototype>>(),
state.AllowedModifyAccessList?.ToList() ??
new List<ProtoId<AccessLevelPrototype>>());
var jobIndex = _jobPrototypeIds.IndexOf(state.TargetIdJobPrototype);
if (jobIndex >= 0)
{
JobPresetOptionButton.SelectId(jobIndex);
}
//WD-EDIT
if (_resource.TryGetResource(new ResPath("/Textures/Interface/Misc/job_icons.rsi"), out RSIResource? rsi))
{
@@ -234,7 +240,6 @@ namespace Content.Client.Access.UI
: rsi.RSI.TryGetState("CustomId", out var customState)
? customState.Frame0
: null,
TextureScale = new Vector2(4, 4)
};
@@ -256,15 +261,18 @@ namespace Content.Client.Access.UI
private void SubmitData()
{
// Don't send this if it isn't dirty.
var jobProtoDirty = _lastJobProto != null &&
_jobPrototypeIds[JobPresetOptionButton.SelectedId] != _lastJobProto;
var jobProtoDirty = _lastJobProto != null && _newJob != _lastJobProto;
_owner.SubmitData(
FullNameLineEdit.Text,
JobTitleLineEdit.Text,
// Iterate over the buttons dictionary, filter by `Pressed`, only get key from the key/value pair
_accessButtons.ButtonsList.Where(x => x.Value.Pressed).Select(x => x.Key).ToList(),
jobProtoDirty ? _jobPrototypeIds[JobPresetOptionButton.SelectedId] : string.Empty,
_groupAccessButtons.ButtonGroups
.SelectMany(dict => dict)
.Where(x => x.Value.Pressed)
.Select(x => x.Key)
.ToList(),
jobProtoDirty ? _newJob : string.Empty,
_lastJobIcon);
}
}

View File

@@ -158,6 +158,16 @@ namespace Content.Client.Stylesheets
public const string StyleClassButtonColorGreen = "ButtonColorGreen";
public const string StyleClassButtonColorPurple = "ButtonColorPurple";
// WD - HoP console
public static readonly Color ButtonColorCommand = Color.FromHex("#436BAD");
public static readonly Color ButtonColorSecurity = Color.FromHex("#BF5454");
public static readonly Color ButtonColorMedical = Color.FromHex("#4494C8");
public static readonly Color ButtonColorEngineering = Color.FromHex("#FDA55E");
public static readonly Color ButtonColorCargo = Color.FromHex("#9E6A34");
public static readonly Color ButtonColorResearching = Color.FromHex("#984EB4");
public static readonly Color ButtonColorService = Color.FromHex("#40A166");
public override Stylesheet Stylesheet { get; }
public StyleNano(IResourceCache resCache) : base(resCache)
@@ -1340,6 +1350,55 @@ namespace Content.Client.Stylesheets
{
new StyleProperty(Label.StylePropertyFont, notoSansDisplayBold14),
}),
// WD - HoP conlose
new StyleRule(
new SelectorElement(typeof(MenuButton), new[] {MenuButton.StyleClassRedTopButton}, null, new[] {Button.StylePseudoClassNormal}),
new[]
{
new StyleProperty(Button.StylePropertyModulateSelf, ButtonColorCommand),
}),
new StyleRule(
new SelectorElement(typeof(MenuButton), new[] {MenuButton.StyleClassRedTopButton}, null, new[] {Button.StylePseudoClassNormal}),
new[]
{
new StyleProperty(Button.StylePropertyModulateSelf, ButtonColorSecurity),
}),
new StyleRule(
new SelectorElement(typeof(MenuButton), new[] {MenuButton.StyleClassRedTopButton}, null, new[] {Button.StylePseudoClassNormal}),
new[]
{
new StyleProperty(Button.StylePropertyModulateSelf, ButtonColorMedical),
}),
new StyleRule(
new SelectorElement(typeof(MenuButton), new[] {MenuButton.StyleClassRedTopButton}, null, new[] {Button.StylePseudoClassNormal}),
new[]
{
new StyleProperty(Button.StylePropertyModulateSelf, ButtonColorEngineering),
}),
new StyleRule(
new SelectorElement(typeof(MenuButton), new[] {MenuButton.StyleClassRedTopButton}, null, new[] {Button.StylePseudoClassNormal}),
new[]
{
new StyleProperty(Button.StylePropertyModulateSelf, ButtonColorService),
}),
new StyleRule(
new SelectorElement(typeof(MenuButton), new[] {MenuButton.StyleClassRedTopButton}, null, new[] {Button.StylePseudoClassNormal}),
new[]
{
new StyleProperty(Button.StylePropertyModulateSelf, ButtonColorResearching),
}),
new StyleRule(
new SelectorElement(typeof(MenuButton), new[] {MenuButton.StyleClassRedTopButton}, null, new[] {Button.StylePseudoClassNormal}),
new[]
{
new StyleProperty(Button.StylePropertyModulateSelf, ButtonColorCargo),
}),
// NanoHeading
@@ -1576,6 +1635,44 @@ namespace Content.Client.Stylesheets
.Prop(Control.StylePropertyModulateSelf, ButtonColorHoveredRed),
// ---
// WD - HoP console
Element<Button>().Class("ButtonColorCommandDepartment")
.Prop(Control.StylePropertyModulateSelf, ButtonColorCommand),
Element<Button>().Class("ButtonColorCommandDepartment").Pseudo(ContainerButton.StylePseudoClassNormal)
.Prop(Control.StylePropertyModulateSelf, ButtonColorCommand),
Element<Button>().Class("ButtonColorSecurityDepartment")
.Prop(Control.StylePropertyModulateSelf, ButtonColorSecurity),
Element<Button>().Class("ButtonColorSecurityDepartment").Pseudo(ContainerButton.StylePseudoClassNormal)
.Prop(Control.StylePropertyModulateSelf, ButtonColorSecurity),
Element<Button>().Class("ButtonColorMedicalDepartment")
.Prop(Control.StylePropertyModulateSelf, ButtonColorMedical),
Element<Button>().Class("ButtonColorMedicalDepartment").Pseudo(ContainerButton.StylePseudoClassNormal)
.Prop(Control.StylePropertyModulateSelf, ButtonColorMedical),
Element<Button>().Class("ButtonColorEngineeringDepartment")
.Prop(Control.StylePropertyModulateSelf, ButtonColorEngineering),
Element<Button>().Class("ButtonColorEngineeringDepartment").Pseudo(ContainerButton.StylePseudoClassNormal)
.Prop(Control.StylePropertyModulateSelf, ButtonColorEngineering),
Element<Button>().Class("ButtonColorResearchingDepartment")
.Prop(Control.StylePropertyModulateSelf, ButtonColorResearching),
Element<Button>().Class("ButtonColorResearchingDepartment").Pseudo(ContainerButton.StylePseudoClassNormal)
.Prop(Control.StylePropertyModulateSelf, ButtonColorResearching),
Element<Button>().Class("ButtonColorServiceDepartment")
.Prop(Control.StylePropertyModulateSelf, ButtonColorService),
Element<Button>().Class("ButtonColorServiceDepartment").Pseudo(ContainerButton.StylePseudoClassNormal)
.Prop(Control.StylePropertyModulateSelf, ButtonColorService),
Element<Button>().Class("ButtonColorCargoDepartment")
.Prop(Control.StylePropertyModulateSelf, ButtonColorCargo),
Element<Button>().Class("ButtonColorCargoDepartment").Pseudo(ContainerButton.StylePseudoClassNormal)
.Prop(Control.StylePropertyModulateSelf, ButtonColorCargo),
// ---
// Green Button ---
Element<Button>().Class("ButtonColorGreen")
.Prop(Control.StylePropertyModulateSelf, ButtonColorGoodDefault),