Skip to content

Commit

Permalink
v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
EnoPM committed Dec 24, 2023
1 parent 6eecab8 commit 151575f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
16 changes: 2 additions & 14 deletions AmongUsSpecimen/AmongUsSpecimen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,7 @@
</Compile>
</ItemGroup>

<Target Name="CopyPlugins" AfterTargets="AfterBuild">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="C:\Program Files (x86)\Steam\steamapps\common\Among Us - Specimen\BepInEx\plugins" />
</Target>
<Target Name="CopyPluginsToBetterOtherRolesLibs" AfterTargets="AfterBuild">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="C:\Users\Utilisateur\RiderProjects\BetterOtherRoles-v2\BetterOtherRoles\libs" />
</Target>
<Target Name="CopyPluginsToBetterOtherRolesGameFolder" AfterTargets="AfterBuild">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="C:\Program Files (x86)\Steam\steamapps\common\Among Us - BetterOtherRoles2\BepInEx\plugins" />
</Target>
<Target Name="CopyPluginsToTheOtherRolesProject" AfterTargets="AfterBuild">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="C:\Users\Utilisateur\RiderProjects\TOR-Devel\TheOtherRoles\libs" />
</Target>
<Target Name="CopyPluginsToTheOtherRolesGameFolder" AfterTargets="AfterBuild">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="C:\Program Files (x86)\Steam\steamapps\common\Among Us - TheOtherRoles\BepInEx\plugins" />
<Target Name="CopyPluginToGameDirectory" AfterTargets="AfterBuild" Condition="Exists('$(AmongUsDev)/BepInEx/plugins/')">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(AmongUsDev)/BepInEx/plugins/" />
</Target>
</Project>
5 changes: 0 additions & 5 deletions AmongUsSpecimen/ModOptions/BaseModOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public int CurrentSelection

internal void BehaviourUpdate()
{
var toReturn = 0f;
if (!OptionBehaviour) return;
if (Type == OptionType.Boolean)
{
Expand Down Expand Up @@ -177,14 +176,10 @@ protected int GetStorageSelection()
{
case OptionSaveLocation.Global:
return OptionStorage.Current.Global.GetValueOrDefault(Id, DefaultSelection);
break;
case OptionSaveLocation.Local:
return OptionStorage.Current.Local.GetValueOrDefault(Id, DefaultSelection);
break;
case OptionSaveLocation.Preset:
return OptionStorage.Current.GetCurrentPreset().Values.GetValueOrDefault(Id, DefaultSelection);
default:
break;
}

return DefaultSelection;
Expand Down
48 changes: 44 additions & 4 deletions AmongUsSpecimen/ModOptions/PresetManagerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
using AmongUsSpecimen.UI;
using AmongUsSpecimen.UI.Components;
using AmongUsSpecimen.UI.Extensions;
using AmongUsSpecimen.Utils;
using BepInEx.Unity.IL2CPP.Utils;
using UnityEngine;
using UnityEngine.UI;
using UniverseLib;
using UniverseLib.UI;
using UniverseLib.UI.Models;
using ButtonRef = AmongUsSpecimen.UI.Components.ButtonRef;
Expand All @@ -33,6 +35,8 @@ public class PresetManagerWindow : UiWindow
private ButtonRef _pasteButton;
private InputFieldRef _createInput;
private ButtonRef _createButton;
private readonly List<GameObject> _presetItems = [];
private GameObject _presetsContainer;

protected override void ConstructWindowContent()
{
Expand All @@ -53,21 +57,56 @@ protected override void ConstructWindowContent()
_pasteButton.OnClick += OnPasteButtonClick;
UiFactory.SetLayoutElement(_pasteButton.GameObject, 170, 35, 0, 0, 0, 0);

var creationContainer = UiFactory.CreateVerticalGroup(ContentRoot, "CreatePreset", false, false, true, true, 5, childAlignment: TextAnchor.MiddleCenter, bgColor: UIPalette.LightDanger, padding: new Vector4(15f, 0f, 0f, 0f));
var creationContainer = UiFactory.CreateVerticalGroup(ContentRoot, "CreatePreset", false, false, true, true, 5, childAlignment: TextAnchor.UpperCenter, bgColor: UIPalette.LightDanger, padding: new Vector4(15f, 0f, 0f, 0f));
creationContainer.GetComponent<Image>().enabled = false;
UiFactory.SetLayoutElement(creationContainer, MinWidth, 80, 0, 0, 0, 0);
UiFactory.SetLayoutElement(creationContainer, MinWidth, 90, 0, 0, 0, 0);
_createInput = UiFactory.CreateInputField(creationContainer, "PresetName", "Preset name");
UiFactory.SetLayoutElement(_createInput.GameObject, MinWidth - 20, 30, 0, 0, 0, 0);
_createInput.OnValueChanged += OnCreateInputValueChanged;
_createButton = UiFactory.CreateButton(creationContainer, "CreateButton", "Create preset");
_createButton.Component.SetColorsAuto(UIPalette.Success);
_createButton.ButtonText.fontSize = 16;
_createButton.ButtonText.fontStyle = FontStyle.Bold;
_createButton.OnClick += OnCreateButtonClick;
_createButton.Enabled = true;
UiFactory.SetLayoutElement(_createButton.GameObject, MinWidth - 20, 30, 0, 0, 0, 0);

var presetList = UiFactory.CreateScrollView(ContentRoot, "PresetList", out _presetsContainer, out _, minHeight: 200, minWidth: MinWidth, color: UIPalette.Dark, contentAlignment: TextAnchor.UpperCenter);
UiFactory.SetLayoutElement(presetList, MinWidth, 200, 0, 0, 0, 0);
foreach (var preset in OptionStorage.Current.Presets)
{
CreatePresetItem(preset);
}
}

private void CreatePresetItem(ModOptionPreset preset)
{
var presetContainer = UiFactory.CreateHorizontalGroup(_presetsContainer, "PresetItem", false, false, true, true, childAlignment: TextAnchor.MiddleCenter, bgColor: UIPalette.Primary);
UiFactory.SetLayoutElement(presetContainer, MinWidth - 50, 40, 0, 0, 0, 0);
var label = UiFactory.CreateLabel(presetContainer, "PresetLabel", preset.Name, TextAnchor.MiddleLeft, UIPalette.Secondary, true, 18);
UiFactory.SetLayoutElement(label.gameObject, MinWidth - 95, 40, 0, 0, 0, 0);
var buttonContainer = UiFactory.CreateVerticalGroup(presetContainer, "PresetDeleteButton", false, false, true, true, bgColor: Palette.EnabledColor);
UiFactory.SetLayoutElement(buttonContainer, 40, 40, 0, 0, 0, 0);
buttonContainer.GetComponent<Image>().sprite = SpecimenSprites.ErrorIcon;
var btn = buttonContainer.AddComponent<Button>();
btn.onClick.AddListener(() =>
{
UnityEngine.Object.Destroy(presetContainer);
OptionStorage.Current.Presets.Remove(preset);
_presetItems.Remove(presetContainer);
});
_presetItems.Add(presetContainer);
}

internal const string SerializedPrefix = "%%SPECIMEN_SERIALIZED_PRESET%%";

private void OnCreateInputValueChanged(string value)
{
var isEnabled = value.Trim() != string.Empty && !string.Equals(value, OptionStorage.Current.OnlinePreset.Name, StringComparison.InvariantCultureIgnoreCase) &&
!OptionStorage.Current.Presets.Any(x => string.Equals(x.Name, value, StringComparison.InvariantCultureIgnoreCase));
_createButton.Component.SetColorsAuto(isEnabled ? UIPalette.Success : UIPalette.Danger);
}

private void OnCopyButtonClick()
{
_copyButton.Component.StartCoroutine(CoCopyPreset());
Expand All @@ -84,7 +123,7 @@ private void OnCreateButtonClick()
if (value.Trim() == string.Empty) return;
if (value == OptionStorage.Current.OnlinePreset.Name || OptionStorage.Current.Presets.Any(x => x.Name == value))
{
DisplayError($"A preset with the name {value} already exists.");
DisplayError($"A preset with the name \"{value}\" already exists.");
return;
}

Expand All @@ -96,14 +135,15 @@ private void OnCreateButtonClick()
Values = new Dictionary<int, int>()
};
OptionStorage.SavePreset(preset);
CreatePresetItem(preset);
}

private static void DisplayError(string message)
{
NotificationManager.AddNotification(new BasicNotification(new BasicNotificationConfig
{
Type = NotificationTypes.Danger,
Title = "Create preset error",
Title = ColorHelpers.Colorize(Color.red, "Preset error"),
Description = message
}, DateTime.UtcNow.Add(TimeSpan.FromSeconds(10))));
}
Expand Down
2 changes: 1 addition & 1 deletion AmongUsSpecimen/UI/Extensions/SelectableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class SelectableExtensions
{
public static void SetColorsAuto(this Selectable selectable, Color color)
{
selectable.SetColors(normal: color, hover: color * 1.2f, pressed: color * 0.8f, focused: color, disabled: UIPalette.Danger);
selectable.SetColors(normal: color, hover: color * 1.2f, pressed: color * 0.8f, focused: color, disabled: UIPalette.Secondary);
}

public static void SetColors(this Selectable selectable, Color? normal = null, Color? hover = null, Color? pressed = null, Color? disabled = null, Color? focused = null)
Expand Down

0 comments on commit 151575f

Please sign in to comment.