mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 11:39:45 +00:00
Compare commits
422
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d751819534 | ||
|
|
b8b85e2bc3 | ||
|
|
043845ee11 | ||
|
|
df7c182abb | ||
|
|
2a4d16e65e | ||
|
|
840761787f | ||
|
|
615d527c86 | ||
|
|
7628a41d86 | ||
|
|
63d1003b2b | ||
|
|
0645c32cca | ||
|
|
8beabb20a2 | ||
|
|
3f28d70308 | ||
|
|
b919c55ef1 | ||
|
|
55a2161876 | ||
|
|
4ca2249fbd | ||
|
|
fc94c8e67e | ||
|
|
83e550c1f2 | ||
|
|
edee889ffe | ||
|
|
8c5aee4beb | ||
|
|
30a39fa223 | ||
|
|
228ed9711a | ||
|
|
7c085b1072 | ||
|
|
8750e5c894 | ||
|
|
1b40b1c5e4 | ||
|
|
0a0ad74419 | ||
|
|
992bdbcbf8 | ||
|
|
f9721a8d69 | ||
|
|
e541840da9 | ||
|
|
eb18d82d8e | ||
|
|
7afd899e56 | ||
|
|
5cccc192b1 | ||
|
|
9d7e41a3c9 | ||
|
|
662b52f78d | ||
|
|
dac1d82d5c | ||
|
|
1b718092ee | ||
|
|
3eb0a4fdb3 | ||
|
|
850e82155c | ||
|
|
ff30d5fdd6 | ||
|
|
2eecba2e51 | ||
|
|
84321f290e | ||
|
|
d8d3cc202a | ||
|
|
e08e7e5f4b | ||
|
|
a5f0ed5975 | ||
|
|
d1f5e56cb9 | ||
|
|
127e3f600e | ||
|
|
47e02d3dcf | ||
|
|
f53e4fdc38 | ||
|
|
b1f0ec6da3 | ||
|
|
d0d5056e39 | ||
|
|
57e3f20cba | ||
|
|
7fdfd506e0 | ||
|
|
edf61e722f | ||
|
|
791daa08ad | ||
|
|
e4d2509895 | ||
|
|
62c8e27535 | ||
|
|
8852c014ab | ||
|
|
adb9a2823d | ||
|
|
ff658db6f1 | ||
|
|
750e00d06d | ||
|
|
3a5a397846 | ||
|
|
c846109d07 | ||
|
|
e3b0eb68c0 | ||
|
|
90921ff786 | ||
|
|
c1d0bb5d26 | ||
|
|
c59ed8eaa6 | ||
|
|
d2fafc3650 | ||
|
|
0c0157fed2 | ||
|
|
90bf402cbc | ||
|
|
245f2e6919 | ||
|
|
fed3abafb2 | ||
|
|
925d47a275 | ||
|
|
45a3597ab2 | ||
|
|
faeb39d3de | ||
|
|
6b46cffe5e | ||
|
|
00a60bb7ad | ||
|
|
d89bce6956 | ||
|
|
7f92e94293 | ||
|
|
6199e55110 | ||
|
|
eac442443b | ||
|
|
6321753ec0 | ||
|
|
e66d45bd21 | ||
|
|
1e00181220 | ||
|
|
fcd7856571 | ||
|
|
5680d27db1 | ||
|
|
49d77fcf40 | ||
|
|
dcb4a3876f | ||
|
|
9270de408d | ||
|
|
8940de76bb | ||
|
|
1813fe5a84 | ||
|
|
272b14f0e0 | ||
|
|
6cc1d4b762 | ||
|
|
9dfad78df6 | ||
|
|
7f506000a4 | ||
|
|
795b6a81d7 | ||
|
|
bd8d7a3208 | ||
|
|
e8536e5d4b | ||
|
|
090db766b2 | ||
|
|
1f0027108e | ||
|
|
665724010d | ||
|
|
2d58c91289 | ||
|
|
b3ed6d67f9 | ||
|
|
64ef78e3a2 | ||
|
|
5e9e4012ef | ||
|
|
fe04a7033a | ||
|
|
ba0ee49255 | ||
|
|
97528b4380 | ||
|
|
50030c113b | ||
|
|
20e51cc993 | ||
|
|
64b5e01ba1 | ||
|
|
d4469153ab | ||
|
|
ab67c233d8 | ||
|
|
c72eacc7a2 | ||
|
|
13072d6834 | ||
|
|
c6342750ef | ||
|
|
5c2e95376d | ||
|
|
067859b9fd | ||
|
|
fe3bfcdbc4 | ||
|
|
5d01462a32 | ||
|
|
a9b6f40ed0 | ||
|
|
eae0024ec3 | ||
|
|
2907564d6a | ||
|
|
7ad003ed1e | ||
|
|
93eea6ea2f | ||
|
|
8e09b7fee0 | ||
|
|
1e4894538c | ||
|
|
303aedafc7 | ||
|
|
8ed4355504 | ||
|
|
76b02835a7 | ||
|
|
8d5bc710e7 | ||
|
|
798ce451d5 | ||
|
|
136bbde516 | ||
|
|
5252620108 | ||
|
|
c9b1c57774 | ||
|
|
d97df1a891 | ||
|
|
e93ef6fd1d | ||
|
|
3afe437101 | ||
|
|
62c01b2f72 | ||
|
|
089d2c1ea5 | ||
|
|
c65511d03e | ||
|
|
aee304fb96 | ||
|
|
11ba564eed | ||
|
|
259b9b7097 | ||
|
|
7e3a279b56 | ||
|
|
1fd2dd3539 | ||
|
|
3f60bcae2c | ||
|
|
fe1580bb7e | ||
|
|
8b23021b2a | ||
|
|
fdc715dac2 | ||
|
|
e1ca50be3e | ||
|
|
bf9b34e728 | ||
|
|
baf80618bb | ||
|
|
7d1976f772 | ||
|
|
4ce24c2a00 | ||
|
|
7fa75946fd | ||
|
|
43f92d4dc2 | ||
|
|
ee22b776eb | ||
|
|
f31349f6e8 | ||
|
|
448e2f9152 | ||
|
|
dde7e70406 | ||
|
|
713a7a2bcc | ||
|
|
056a9b6102 | ||
|
|
4b144a782d | ||
|
|
ae917a9c77 | ||
|
|
7a8d608b17 | ||
|
|
6503bbecb7 | ||
|
|
cb794c3fc2 | ||
|
|
88329bef79 | ||
|
|
eb7abecd75 | ||
|
|
fc9e9740be | ||
|
|
3c51c88963 | ||
|
|
e42f5e6029 | ||
|
|
61be7dda82 | ||
|
|
3220a4a820 | ||
|
|
8fd142a92e | ||
|
|
fcec6ad6e5 | ||
|
|
10a7ffe886 | ||
|
|
7e541733b7 | ||
|
|
99a275a97c | ||
|
|
67a5f0dd67 | ||
|
|
f13d46ec18 | ||
|
|
f9096b6160 | ||
|
|
8bf101534f | ||
|
|
479323acdd | ||
|
|
50c5899f4d | ||
|
|
fd719ae42f | ||
|
|
e050b043cb | ||
|
|
e78c456636 | ||
|
|
7e8d07672c | ||
|
|
77ae01c66a | ||
|
|
ce824f05fa | ||
|
|
b5fe3c7afd | ||
|
|
1750cd3db9 | ||
|
|
4dd2554b38 | ||
|
|
e5cfd8a2fc | ||
|
|
6d387cae96 | ||
|
|
59f3058685 | ||
|
|
9dfb40d7bf | ||
|
|
ffca13e6e6 | ||
|
|
c1d2868e77 | ||
|
|
18c52e0138 | ||
|
|
b64bf7c9de | ||
|
|
e98c16b9f5 | ||
|
|
e166efa666 | ||
|
|
8da80be027 | ||
|
|
af75cc3606 | ||
|
|
0f1962394a | ||
|
|
36991f34ee | ||
|
|
ae5f3783b4 | ||
|
|
12a1908c3e | ||
|
|
8246e05da6 | ||
|
|
c75e039141 | ||
|
|
ac66e0d62b | ||
|
|
c4cbf0b18d | ||
|
|
f3175990d3 | ||
|
|
790d868759 | ||
|
|
9f11874189 | ||
|
|
1b6a2c4eb3 | ||
|
|
81887c34d9 | ||
|
|
810fd54e10 | ||
|
|
5492c2b3cc | ||
|
|
f7a515882a | ||
|
|
89eb774501 | ||
|
|
5fd57633ff | ||
|
|
834d1d878e | ||
|
|
790b37e8d3 | ||
|
|
dfa8b29710 | ||
|
|
da7aab9aa2 | ||
|
|
2c0042e6a8 | ||
|
|
70f63f8b16 | ||
|
|
03a3733966 | ||
|
|
3d274c2f61 | ||
|
|
b94e20c6f7 | ||
|
|
5a0428c7c0 | ||
|
|
c41dd27f88 | ||
|
|
6872ca6866 | ||
|
|
4b7fa906b9 | ||
|
|
b7173d18ab | ||
|
|
ffc7a1a4fd | ||
|
|
a1611f5f7a | ||
|
|
1664aa1003 | ||
|
|
af3d99eafe | ||
|
|
94197e38dd | ||
|
|
97a0b2084a | ||
|
|
1d87790212 | ||
|
|
9d130a53de | ||
|
|
d8afc6887d | ||
|
|
c0a406610d | ||
|
|
d73c21936c | ||
|
|
449192f0ef | ||
|
|
f3614b9a5c | ||
|
|
a62c6d496c | ||
|
|
bebd648691 | ||
|
|
ecadfa86dd | ||
|
|
5ad53f695f | ||
|
|
31a9c0c98d | ||
|
|
ea389b986f | ||
|
|
ef85fab6a6 | ||
|
|
b2fdaaf89f | ||
|
|
e6043b6f5f | ||
|
|
ffe0db0e9e | ||
|
|
705ef64b4d | ||
|
|
ebdb4a09ca | ||
|
|
ac113b6a7f | ||
|
|
1f6962efe9 | ||
|
|
6b37b9c09c | ||
|
|
f515516937 | ||
|
|
8b2d24ccc1 | ||
|
|
57bab258e5 | ||
|
|
04d5e72caa | ||
|
|
b4e6e448f2 | ||
|
|
b19a0178ad | ||
|
|
8a71f13874 | ||
|
|
809e7a07ab | ||
|
|
47394c6afe | ||
|
|
a2a1e91439 | ||
|
|
2f5ca32475 | ||
|
|
5fb59408fa | ||
|
|
57c842ece6 | ||
|
|
63e552245d | ||
|
|
43d7f80660 | ||
|
|
45291b0e98 | ||
|
|
45972f71a9 | ||
|
|
a6f7171b71 | ||
|
|
e6d3819517 | ||
|
|
b97ada22bc | ||
|
|
5f67960b28 | ||
|
|
b4e30b2b68 | ||
|
|
2237d3a2df | ||
|
|
e708c23f81 | ||
|
|
3ca33b1d86 | ||
|
|
8967348cd3 | ||
|
|
305d2c3714 | ||
|
|
85a0275eea | ||
|
|
f006deab3f | ||
|
|
a274f23e65 | ||
|
|
f1a5aef581 | ||
|
|
ce15e93e59 | ||
|
|
08ca995eb1 | ||
|
|
453259df98 | ||
|
|
2ec3eec370 | ||
|
|
2ee8730ba4 | ||
|
|
c89e5938cc | ||
|
|
513be01c02 | ||
|
|
01fa1f0915 | ||
|
|
355eef509b | ||
|
|
763a493283 | ||
|
|
68e421bf91 | ||
|
|
c343ab5e9f | ||
|
|
9c1ef70ea7 | ||
|
|
c0c8fa08ff | ||
|
|
e7fba386aa | ||
|
|
72e5e0c137 | ||
|
|
4422072060 | ||
|
|
8145c8e599 | ||
|
|
afd6fbc3b6 | ||
|
|
74741b41a7 | ||
|
|
f98429b5f9 | ||
|
|
bf7edb30ab | ||
|
|
b4527014b7 | ||
|
|
277391ef1c | ||
|
|
dfe124d67a | ||
|
|
2b06633488 | ||
|
|
4784b1f0ad | ||
|
|
d9d0d6bc62 | ||
|
|
6b3038f397 | ||
|
|
4e1db039a0 | ||
|
|
62bee24789 | ||
|
|
2156c80467 | ||
|
|
0ff60071c2 | ||
|
|
de2f3f0d95 | ||
|
|
05f132c506 | ||
|
|
ab54c44434 | ||
|
|
bf652b68c3 | ||
|
|
00377c7926 | ||
|
|
55555604f3 | ||
|
|
de77a9fa92 | ||
|
|
eba2a037d3 | ||
|
|
bc7f772de9 | ||
|
|
f43191c4f2 | ||
|
|
cd818a18cf | ||
|
|
56d4e399d9 | ||
|
|
0d41ebbc13 | ||
|
|
9388ff487a | ||
|
|
720491e5cf | ||
|
|
9884df356e | ||
|
|
7ec4addacc | ||
|
|
bc9bc0ce24 | ||
|
|
aff1c311fa | ||
|
|
0d2a9d9700 | ||
|
|
669c541279 | ||
|
|
2e5f9639b3 | ||
|
|
e6d1f440c8 | ||
|
|
2ac8bdc240 | ||
|
|
d5d99001ea | ||
|
|
5628b79814 | ||
|
|
72a44f65f1 | ||
|
|
db6a336a63 | ||
|
|
90b23ec2ca | ||
|
|
20e927208c | ||
|
|
13ef3bdd49 | ||
|
|
b3ff6755bb | ||
|
|
67604600cd | ||
|
|
6e35de6185 | ||
|
|
a26ec51c7d | ||
|
|
3f6ae4cc41 | ||
|
|
15a2cdcd5b | ||
|
|
cf0bd6ec38 | ||
|
|
130236e899 | ||
|
|
3b7b247ac0 | ||
|
|
52de9a22de | ||
|
|
372a9e3aa9 | ||
|
|
10a9dcfa34 | ||
|
|
d46fdb0185 | ||
|
|
a361afbcbf | ||
|
|
24cdac0243 | ||
|
|
5fe75843ad | ||
|
|
a0436dcbba | ||
|
|
35be381a77 | ||
|
|
1298beb517 | ||
|
|
d41c19a176 | ||
|
|
476f4400ad | ||
|
|
2b46d90570 | ||
|
|
ae4aaf7af9 | ||
|
|
757b9436ca | ||
|
|
0ab80c42f9 | ||
|
|
b94472ee07 | ||
|
|
f8056c29da | ||
|
|
8d4f2baf1e | ||
|
|
11ba3dae64 | ||
|
|
86145f94f4 | ||
|
|
e0da386567 | ||
|
|
6f1da2de9f | ||
|
|
b85358e304 | ||
|
|
2c901bb9b9 | ||
|
|
68f40a96b7 | ||
|
|
a96ffc42f2 | ||
|
|
0907b14893 | ||
|
|
32a44d646d | ||
|
|
8f590b94a8 | ||
|
|
2e769d79f2 | ||
|
|
41305ad0e2 | ||
|
|
2418e17af6 | ||
|
|
6fb0afe14e | ||
|
|
ab0063dd99 | ||
|
|
a35bf60870 | ||
|
|
692b9d7180 | ||
|
|
b99efaa420 | ||
|
|
2ecfa267d6 | ||
|
|
9afe821b0f | ||
|
|
a8d076656d | ||
|
|
429b64fc03 | ||
|
|
bf5dadc6a0 | ||
|
|
b2137230da | ||
|
|
9e8c05f21d | ||
|
|
2f56c95b39 | ||
|
|
38f72c42a3 | ||
|
|
5b608f5b3a | ||
|
|
2248726450 | ||
|
|
c60537cbd1 | ||
|
|
f5b4bdd1d4 | ||
|
|
cd6c4f5390 | ||
|
|
5cc29d903a |
No files matched your search
+3
-3
@@ -1,13 +1,13 @@
|
||||
<Project>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Reactor" Version="2.3.1" />
|
||||
<PackageReference Include="Reactor" Version="2.5.0-ci.371" />
|
||||
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.735" Private="false" ExcludeAssets="runtime;native" />
|
||||
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2025.4.15" PrivateAssets="all" />
|
||||
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2026.3.31" PrivateAssets="all" />
|
||||
|
||||
<PackageReference Include="BepInEx.AutoPlugin" Version="1.1.0" PrivateAssets="all" />
|
||||
<PackageReference Include="BepInEx.IL2CPP.MSBuild" Version="2.1.0-rc.1" PrivateAssets="all" ExcludeAssets="runtime" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<Target Name="Copy" AfterTargets="Build" Condition="'$(AmongUs)' != ''">
|
||||
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(AmongUs)/BepInEx/plugins/" UseSymboliclinksIfPossible="true" />
|
||||
</Target>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
||||
|
||||
<VersionPrefix>0.2.0</VersionPrefix>
|
||||
<VersionPrefix>0.4.3</VersionPrefix>
|
||||
<VersionSuffix>dev</VersionSuffix>
|
||||
|
||||
<Authors>All Of Us, XtraCube, Angxl</Authors>
|
||||
@@ -42,4 +42,4 @@
|
||||
<PropertyGroup>
|
||||
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)\stylecop.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -3,6 +3,7 @@ using MiraAPI.Example.Options.Roles;
|
||||
using MiraAPI.Example.Roles;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Keybinds;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
@@ -15,10 +16,10 @@ public class FreezeButton : CustomActionButton<PlayerControl>
|
||||
public override string Name => "Freeze";
|
||||
|
||||
public override float Cooldown => OptionGroupSingleton<FreezerRoleSettings>.Instance.FreezeDuration;
|
||||
|
||||
public override int MaxUses => (int)OptionGroupSingleton<FreezerRoleSettings>.Instance.FreezeUses;
|
||||
public override bool PauseTimerInVent => true;
|
||||
|
||||
public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;
|
||||
public override MiraKeybind? Keybind => MiraGlobalKeybinds.PrimaryAbility;
|
||||
|
||||
protected override void OnClick()
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using MiraAPI.Example.Modifiers;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Keybinds;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using UnityEngine;
|
||||
@@ -15,6 +16,7 @@ public class MeetingButton : CustomActionButton
|
||||
public override int MaxUses => 3;
|
||||
|
||||
public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;
|
||||
public override MiraKeybind? Keybind => MiraGlobalKeybinds.ModifierPrimaryAbility;
|
||||
|
||||
public override bool Enabled(RoleBehaviour? role)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using MiraAPI.Example.Roles;
|
||||
using MiraAPI.GameEnd;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Keybinds;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -12,6 +13,8 @@ public class NeutralKillerButton : CustomActionButton
|
||||
public override string Name => "Win Game";
|
||||
public override float Cooldown => 0f;
|
||||
public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;
|
||||
public override MiraKeybind Keybind => ExampleKeybinds.NeutralWinKeybind;
|
||||
|
||||
protected override void OnClick()
|
||||
{
|
||||
CustomGameOver.Trigger<NeutralKillerGameOver>([PlayerControl.LocalPlayer.Data]);
|
||||
|
||||
@@ -3,6 +3,7 @@ using MiraAPI.Example.Options.Roles;
|
||||
using MiraAPI.Example.Roles;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Keybinds;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities;
|
||||
using UnityEngine;
|
||||
@@ -21,6 +22,7 @@ public class TeleportButton : CustomActionButton
|
||||
public override LoadableAsset<Sprite> Sprite => ExampleAssets.TeleportButton;
|
||||
public override Color TextOutlineColor => new Color32(221, 176, 152, 255);
|
||||
public static bool IsZoom { get; private set; }
|
||||
public override MiraKeybind? Keybind => MiraGlobalKeybinds.PrimaryAbility;
|
||||
|
||||
public override bool Enabled(RoleBehaviour? role)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Buttons;
|
||||
|
||||
public class ThinkButton : CustomActionButton
|
||||
{
|
||||
public override string Name => "Think";
|
||||
public override float Cooldown => 15f;
|
||||
public override float EffectDuration => 10f;
|
||||
public override int MaxUses => 1;
|
||||
public override ButtonUsesMode UsesMode => ButtonUsesMode.PerRound;
|
||||
public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;
|
||||
protected override void OnClick()
|
||||
{
|
||||
// This button does absolutely nothing besides changing its text
|
||||
Button!.OverrideText("Thinking...");
|
||||
}
|
||||
|
||||
public override void OnEffectEnd()
|
||||
{
|
||||
Button!.OverrideText("Think");
|
||||
}
|
||||
|
||||
public override bool IsEffectCancellable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Enabled(RoleBehaviour? role)
|
||||
{
|
||||
return role != null && role.IsImpostor;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,10 @@ namespace MiraAPI.Example;
|
||||
[RegisterCustomColors]
|
||||
public static class ExampleColors
|
||||
{
|
||||
public static CustomColor Cerulean { get; } = new("Cerulean", new Color(0.0f, 0.48f, 0.65f));
|
||||
public static CustomColor Cerulean { get; } = new("Cerulean", new Color(0.0f, 0.48f, 0.65f))
|
||||
{
|
||||
ColorBrightness = CustomColorBrightness.Lighter,
|
||||
};
|
||||
|
||||
public static CustomColor Rose { get; } = new("Rose", new Color(0.98f, 0.26f, 0.62f));
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Mira;
|
||||
using MiraAPI.Events.Vanilla.Gameplay;
|
||||
@@ -17,7 +18,7 @@ public static class ExampleEventHandlers
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
// You can register event handlers with the MiraEventManager class.
|
||||
// You can register event handlers with the MiraEventManager class
|
||||
var handle = MiraEventManager.RegisterEventHandler<BeforeMurderEvent>(@event =>
|
||||
{
|
||||
Logger<ExamplePlugin>.Info($"{@event.Source.Data.PlayerName} is about to kill {@event.Target.Data.PlayerName}");
|
||||
@@ -37,6 +38,21 @@ public static class ExampleEventHandlers
|
||||
MiraEventManager.UnregisterEventHandler(handle);
|
||||
}
|
||||
|
||||
// If you want to check vanilla buttons, use something like this!
|
||||
[RegisterEvent]
|
||||
public static void VanillaButtonClickHandler(VanillaButtonClickEvent @event)
|
||||
{
|
||||
Logger<ExamplePlugin>.Info($"{@event.Button.buttonLabelText.text} is being used!");
|
||||
if (@event.PlayerTarget != null)
|
||||
{
|
||||
Logger<ExamplePlugin>.Info($"{@event.PlayerTarget.Data.PlayerName} is being targeted!");
|
||||
}
|
||||
else if (@event.VentTarget != null)
|
||||
{
|
||||
Logger<ExamplePlugin>.Info($"Vent with id {@event.VentTarget.Id.ToString(CultureInfo.InvariantCulture)} is being targeted!");
|
||||
}
|
||||
}
|
||||
|
||||
// If you want to add extra votes to a player, do something like this.
|
||||
[RegisterEvent]
|
||||
public static void StartMeetingEvent(StartMeetingEvent _)
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
using MiraAPI.Keybinds;
|
||||
using Rewired;
|
||||
|
||||
namespace MiraAPI.Example;
|
||||
|
||||
[RegisterCustomKeybinds]
|
||||
public static class ExampleKeybinds
|
||||
{
|
||||
public static MiraKeybind NeutralWinKeybind { get; } = new("Neutral Win", KeyboardKeyCode.C, [ModifierKey.Shift]);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using BepInEx.Configuration;
|
||||
using MiraAPI.LocalSettings;
|
||||
using MiraAPI.LocalSettings.Attributes;
|
||||
using MiraAPI.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example;
|
||||
|
||||
public class ExampleLocalSettings(ConfigFile config) : LocalSettingsTab(config)
|
||||
{
|
||||
public override string TabName => "Mira Example";
|
||||
protected override bool ShouldCreateLabels => false;
|
||||
|
||||
public override LocalSettingTabAppearance TabAppearance => new()
|
||||
{
|
||||
ToggleActiveColor = Color.blue,
|
||||
ToggleInactiveColor = Color.red,
|
||||
};
|
||||
|
||||
[LocalSettingsButton]
|
||||
public LocalSettingsButton ExampleButton { get; private set; } = new("Example Button", OnExampleButtonClick);
|
||||
|
||||
[LocalToggleSetting]
|
||||
public ConfigEntry<bool> ExampleToggle { get; private set; } = config.Bind("General", "Example Bool", true);
|
||||
|
||||
[LocalToggleSetting]
|
||||
public ConfigEntry<bool> ExampleToggle2 { get; private set; } = config.Bind("General", "Example Bool 2", false);
|
||||
|
||||
[LocalSliderSetting(suffixType: MiraNumberSuffixes.Percent, formatString: "0", roundValue: true)]
|
||||
public ConfigEntry<float> ExampleSlider { get; private set; } = config.Bind("General", "Slider", 50f);
|
||||
|
||||
[LocalNumberSetting]
|
||||
public ConfigEntry<float> ExampleNumber { get; private set; } = config.Bind("General", "Example Number", 4f);
|
||||
|
||||
[LocalNumberSetting(min: 0.1f, max: 2.5f, increment: 0.1f, formatString: "0.0", suffixType: MiraNumberSuffixes.Multiplier)]
|
||||
public ConfigEntry<float> ExampleFloatNumber { get; private set; } = config.Bind("General", "Example Multplier", 1f);
|
||||
|
||||
[LocalEnumSetting]
|
||||
public ConfigEntry<ExampleEnumSetting> ExampleEnum { get; private set; } = config.Bind("General", "Example Enum", ExampleEnumSetting.Fries);
|
||||
|
||||
private static void OnExampleButtonClick()
|
||||
{
|
||||
LocalSettingsTabSingleton<MiraApiSettings>.Instance.Open();
|
||||
}
|
||||
}
|
||||
|
||||
public enum ExampleEnumSetting
|
||||
{
|
||||
Cheeseburger,
|
||||
Sandwich,
|
||||
Fries,
|
||||
ChickenNuggets,
|
||||
}
|
||||
@@ -10,6 +10,10 @@ public class ExampleOptions2 : AbstractOptionGroup
|
||||
|
||||
public override uint GroupPriority => 0; // This group will be displayed first. The default value is uint.MaxValue.
|
||||
|
||||
public override MenuCategory ParentMenu => MenuCategory.CustomTwo;
|
||||
|
||||
public ModdedPlayerOption PlayerOption2 { get; } = new("YOU MUST CHOSE A PLAYER", false);
|
||||
public ModdedPlayerOption PlayerOption { get; } = new("Eh whatever");
|
||||
public ModdedToggleOption ToggleOpt1 { get; } = new("Toggle Option 1", false);
|
||||
|
||||
public ModdedToggleOption ToggleOpt2 { get; } = new("Toggle Option 2", false)
|
||||
|
||||
@@ -9,7 +9,7 @@ public class GeneralModifierOptions : AbstractOptionGroup
|
||||
|
||||
public override uint GroupPriority => 0;
|
||||
|
||||
public override bool ShowInModifiersMenu => true;
|
||||
public override MenuCategory ParentMenu => MenuCategory.Modifiers;
|
||||
|
||||
[ModdedToggleOption("Some Boolean Option")]
|
||||
public bool SomeBooleanOption { get; set; } = true;
|
||||
|
||||
@@ -2,11 +2,17 @@
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.GameOptions.Attributes;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
|
||||
namespace MiraAPI.Example.Options.Roles;
|
||||
|
||||
public class FreezerRoleSettings : AbstractOptionGroup<FreezerRole>
|
||||
{
|
||||
public override OptionNotifConfiguration Configuration => new(
|
||||
Palette.Blue,
|
||||
TmpSpriteUtils.CreateSpriteAsset(
|
||||
MiraAssets.ImpostorFile.LoadAsset(),
|
||||
"ApiExample.Role.Impostor.FreezerRole"));
|
||||
public override string GroupName => "Custom Role";
|
||||
|
||||
[ModdedNumberOption("Freeze Duration", 1, 15, 1, MiraNumberSuffixes.Seconds)]
|
||||
|
||||
@@ -6,7 +6,7 @@ using MiraAPI.Utilities;
|
||||
|
||||
namespace MiraAPI.Example.Options.Roles;
|
||||
|
||||
public class TeleporterOptions : AbstractOptionGroup<TeleporterRole>
|
||||
public class TeleporterOptions : AbstractRoleOptionGroup<TeleporterRole>
|
||||
{
|
||||
public override string GroupName => "Teleporter";
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using AmongUs.GameOptions;
|
||||
using MiraAPI.Patches.Stubs;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
@@ -20,6 +21,8 @@ public class ChameloenRole : CrewmateRole, ICustomRole
|
||||
public CustomRoleConfiguration Configuration => new(this)
|
||||
{
|
||||
OptionsScreenshot = ExampleAssets.Banner,
|
||||
Icon = MiraAssets.CrewmateFile,
|
||||
IconTmp = TmpSpriteUtils.CreateSpriteAsset(MiraAssets.CrewmateFile.LoadAsset(), "ApiExample.Role.Impostor.ChameleonRole"),
|
||||
IntroSound = CustomRoleUtils.GetIntroSound(RoleTypes.Shapeshifter),
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Roles;
|
||||
@@ -13,6 +14,8 @@ public class FreezerRole : ImpostorRole, ICustomRole
|
||||
|
||||
public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this)
|
||||
{
|
||||
Icon = MiraAssets.ImpostorFile,
|
||||
IconTmp = TmpSpriteUtils.CreateSpriteAsset(MiraAssets.ImpostorFile.LoadAsset(), "ApiExample.Role.Impostor.FreezerRole"),
|
||||
OptionsScreenshot = ExampleAssets.Banner,
|
||||
MaxRoleCount = 2,
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MiraAPI.Example.GameOver;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.Example.GameOver;
|
||||
using MiraAPI.GameEnd;
|
||||
using MiraAPI.Roles;
|
||||
using UnityEngine;
|
||||
@@ -22,6 +23,7 @@ public class NeutralKillerRole : ImpostorRole, ICustomRole
|
||||
|
||||
public RoleOptionsGroup RoleOptionsGroup { get; } = new("Outcast", Color.gray);
|
||||
|
||||
[HideFromIl2Cpp]
|
||||
public TeamIntroConfiguration? IntroConfiguration { get; } = new(
|
||||
Color.gray,
|
||||
"OUTCAST",
|
||||
|
||||
@@ -13,19 +13,24 @@ namespace MiraAPI.Colors;
|
||||
public sealed class CustomColor(StringNames name, Color32 mainColor, Color32 shadowColor)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the main color.
|
||||
/// Gets or sets the main color.
|
||||
/// </summary>
|
||||
public Color32 MainColor { get; } = mainColor;
|
||||
public Color32 MainColor { get; set; } = mainColor;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the shadow color.
|
||||
/// Gets or sets the shadow color.
|
||||
/// </summary>
|
||||
public Color32 ShadowColor { get; } = shadowColor;
|
||||
public Color32 ShadowColor { get; set; } = shadowColor;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the color.
|
||||
/// Gets or sets the name of the color.
|
||||
/// </summary>
|
||||
public StringNames Name { get; } = name;
|
||||
public StringNames Name { get; set; } = name;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the color is lighter or darker. Can be used to help with colorblind stuff.
|
||||
/// </summary>
|
||||
public CustomColorBrightness ColorBrightness { get; set; } = CustomColorBrightness.Darker;
|
||||
|
||||
/// <inheritdoc />
|
||||
public CustomColor(StringNames name, Color32 mainColor) : this(name, mainColor, mainColor.GetShadowColor(60))
|
||||
@@ -42,3 +47,19 @@ public sealed class CustomColor(StringNames name, Color32 mainColor, Color32 sha
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Can be used to help with colorblind stuff.
|
||||
/// </summary>
|
||||
public enum CustomColorBrightness
|
||||
{
|
||||
/// <summary>
|
||||
/// A lighter color.
|
||||
/// </summary>
|
||||
Lighter,
|
||||
|
||||
/// <summary>
|
||||
/// A darker color.
|
||||
/// </summary>
|
||||
Darker,
|
||||
}
|
||||
@@ -5,12 +5,12 @@ using HarmonyLib;
|
||||
namespace MiraAPI.Colors;
|
||||
|
||||
/// <summary>
|
||||
/// Used to register and track custom colors.
|
||||
/// Used to register and track <see cref="CustomColor"/>s.
|
||||
/// </summary>
|
||||
public static class PaletteManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all registered custom colors.
|
||||
/// Gets all registered <see cref="CustomColor"/>s.
|
||||
/// </summary>
|
||||
public static CustomColor[] RegisteredColors => [.. CustomColors];
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace MiraAPI.Colors;
|
||||
|
||||
/// <summary>
|
||||
/// Used to mark a class for custom colors registration.
|
||||
/// Used to mark a class for <see cref="CustomColor"/> registration.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class RegisterCustomColorsAttribute : Attribute;
|
||||
@@ -3,20 +3,20 @@
|
||||
namespace MiraAPI.Events.Mira;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a Mira Button click is cancelled. Do not use for vanilla buttons.
|
||||
/// Invoked when a <see cref="CustomActionButton"/> click is cancelled. Do not use for vanilla <see cref="AbilityButton"/>s.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The Mira Button type.</typeparam>
|
||||
/// <typeparam name="T">The <see cref="CustomActionButton"/> type.</typeparam>
|
||||
public sealed class MiraButtonCancelledEvent<T> : MiraEvent where T : CustomActionButton
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets Mira Button whose click was cancelled.
|
||||
/// Gets the <see cref="CustomActionButton"/> whose click was cancelled.
|
||||
/// </summary>
|
||||
public T Button { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MiraButtonCancelledEvent{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The Mira Button whose click was cancelled.</param>
|
||||
/// <param name="button">The <see cref="CustomActionButton"/> whose click was cancelled.</param>
|
||||
public MiraButtonCancelledEvent(T button)
|
||||
{
|
||||
Button = button;
|
||||
@@ -24,19 +24,19 @@ public sealed class MiraButtonCancelledEvent<T> : MiraEvent where T : CustomActi
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a Mira Button click is cancelled. Do not use for vanilla buttons.
|
||||
/// Invoked when a <see cref="CustomActionButton"/> click is cancelled. Do not use for vanilla <see cref="AbilityButton"/>s.
|
||||
/// </summary>
|
||||
public sealed class MiraButtonCancelledEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets Mira Button whose click was cancelled.
|
||||
/// Gets the <see cref="CustomActionButton"/> whose click was cancelled.
|
||||
/// </summary>
|
||||
public CustomActionButton Button { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MiraButtonCancelledEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The Mira Button whose click was cancelled.</param>
|
||||
/// <param name="button">The <see cref="CustomActionButton"/> whose click was cancelled.</param>
|
||||
public MiraButtonCancelledEvent(CustomActionButton button)
|
||||
{
|
||||
Button = button;
|
||||
|
||||
@@ -3,26 +3,26 @@
|
||||
namespace MiraAPI.Events.Mira;
|
||||
|
||||
/// <summary>
|
||||
/// Button click event for Mira Buttons only. Do not use for vanilla buttons.
|
||||
/// Button click event for <see cref="CustomActionButton"/>s only. Do not use for vanilla <see cref="AbilityButton"/>s.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The Mira Button type.</typeparam>
|
||||
/// <typeparam name="T">The <see cref="CustomActionButton"/> type.</typeparam>
|
||||
public sealed class MiraButtonClickEvent<T> : MiraCancelableEvent where T : CustomActionButton
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets Mira Button that was clicked.
|
||||
/// Gets the <see cref="CustomActionButton"/> that was clicked.
|
||||
/// </summary>
|
||||
public T Button { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the generic click event that is invoked before this button-specific event.
|
||||
/// Gets the generic <see cref="MiraButtonClickEvent"/> that is invoked before this button-specific event.
|
||||
/// </summary>
|
||||
public MiraButtonClickEvent GenericClickEvent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MiraButtonClickEvent{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The Mira Button that was clicked.</param>
|
||||
/// <param name="genericClickEvent">The generic click event invoked before button-specific events.</param>
|
||||
/// <param name="button">The <see cref="CustomActionButton"/> that was clicked.</param>
|
||||
/// <param name="genericClickEvent">The generic <see cref="MiraButtonClickEvent"/> invoked before button-specific events.</param>
|
||||
public MiraButtonClickEvent(T button, MiraButtonClickEvent genericClickEvent)
|
||||
{
|
||||
GenericClickEvent = genericClickEvent;
|
||||
@@ -31,19 +31,19 @@ public sealed class MiraButtonClickEvent<T> : MiraCancelableEvent where T : Cust
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Button click event for Mira Buttons only. Do not use for vanilla buttons.
|
||||
/// Button click event for <see cref="CustomActionButton"/>s only. Do not use for vanilla <see cref="AbilityButton"/>s.
|
||||
/// </summary>
|
||||
public sealed class MiraButtonClickEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets Mira Button that was clicked.
|
||||
/// Gets the <see cref="CustomActionButton"/> that was clicked.
|
||||
/// </summary>
|
||||
public CustomActionButton Button { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MiraButtonClickEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The Mira Button that was clicked.</param>
|
||||
/// <param name="button">The <see cref="CustomActionButton"/> that was clicked.</param>
|
||||
public MiraButtonClickEvent(CustomActionButton button)
|
||||
{
|
||||
Button = button;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace MiraAPI.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Event handle to use when unregistering an event.
|
||||
/// Event handle to use when unregistering a <see cref="MiraEvent"/>.
|
||||
/// </summary>
|
||||
public class MiraEventHandle
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.Events;
|
||||
|
||||
@@ -13,11 +12,11 @@ public static class MiraEventManager
|
||||
private static readonly Dictionary<Type, List<MiraEventWrapper>> EventWrappers = [];
|
||||
|
||||
/// <summary>
|
||||
/// Invoke an event.
|
||||
/// Invoke a <see cref="MiraEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="eventInstance">The event instance.</param>
|
||||
/// <param name="eventInstance">The <typeparamref name="T"/> instance.</param>
|
||||
/// <typeparam name="T">Type of Event.</typeparam>
|
||||
/// <returns>If there was an event handler invoked for this event, return true. Otherwise, return false.</returns>
|
||||
/// <returns>If there was an event handler invoked for this event, return <see langword="true"/>. Otherwise, return <see langword="false"/>.</returns>
|
||||
public static bool InvokeEvent<T>(T eventInstance) where T : MiraEvent
|
||||
{
|
||||
EventWrappers.TryGetValue(typeof(T), out var handlers);
|
||||
@@ -34,7 +33,7 @@ public static class MiraEventManager
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Error invoking event handler for {typeof(T).Name}: {ex.ToString()}");
|
||||
Error($"Error invoking event handler for {typeof(T).Name}: {ex.ToString()}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,11 +41,11 @@ public static class MiraEventManager
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoke an event and use a specific type to find the handlers.
|
||||
/// Invoke a <see cref="MiraEvent"/> and use a specific type to find the handlers.
|
||||
/// </summary>
|
||||
/// <param name="eventInstance">The event instance.</param>
|
||||
/// <param name="eventInstance">The <see cref="MiraEvent"/> instance.</param>
|
||||
/// <param name="type">The type to use for handler lookup.</param>
|
||||
/// <returns>If there was an event handler invoked for this event, return true. Otherwise, return false.</returns>
|
||||
/// <returns>If there was an event handler invoked for this event, return <see langword="true"/>. Otherwise, return <see langword="false"/>.</returns>
|
||||
public static bool InvokeEvent(MiraEvent eventInstance, Type type)
|
||||
{
|
||||
EventWrappers.TryGetValue(type, out var handlers);
|
||||
@@ -63,7 +62,7 @@ public static class MiraEventManager
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Error invoking event handler for {type.Name}: {ex.ToString()}");
|
||||
Error($"Error invoking event handler for {type.Name}: {ex.ToString()}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,12 +70,12 @@ public static class MiraEventManager
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register an event.
|
||||
/// Register a <see cref="MiraEvent"/> handler.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of event.</param>
|
||||
/// <param name="methodInfo">The MethodInfo of the event handler.</param>
|
||||
/// <param name="type">The type of <see cref="MiraEvent"/> event.</param>
|
||||
/// <param name="methodInfo">The <see cref="MethodInfo"/> of the event handler.</param>
|
||||
/// <param name="priority">The priority of the event handler. Lower values are called first.</param>
|
||||
/// <returns>An event handle to use when unregistering the event.</returns>
|
||||
/// <returns>A <see cref="MiraEventHandle"/> to use when unregistering the event.</returns>
|
||||
public static MiraEventHandle RegisterEventHandler(Type type, MethodInfo methodInfo, int priority = 0)
|
||||
{
|
||||
if (!type.IsSubclassOf(typeof(MiraEvent)))
|
||||
@@ -102,12 +101,12 @@ public static class MiraEventManager
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register an event.
|
||||
/// Register a <typeparamref name="T"/> handler.
|
||||
/// </summary>
|
||||
/// <param name="handler">The callback method/handler for the event.</param>
|
||||
/// <param name="priority">The priority of the event handler. Lower values are called first.</param>
|
||||
/// <typeparam name="T">Type of event.</typeparam>
|
||||
/// <returns>An event handle to use when unregistering the event.</returns>
|
||||
/// <typeparam name="T">Type of <see cref="MiraEvent"/> event.</typeparam>
|
||||
/// <returns>A <see cref="MiraEventHandle"/> to use when unregistering the event.</returns>
|
||||
public static MiraEventHandle RegisterEventHandler<T>(Action<T> handler, int priority = 0) where T : MiraEvent
|
||||
{
|
||||
EventWrappers.TryAdd(typeof(T), []);
|
||||
@@ -127,10 +126,10 @@ public static class MiraEventManager
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregister an event using the event handle.
|
||||
/// Unregister a <see cref="MiraEvent"/> handler using the <see cref="MiraEventHandle"/>.
|
||||
/// </summary>
|
||||
/// <param name="eventHandle">A handle to the event.</param>
|
||||
/// <returns>True if the event was unregistered successfully, false otherwise.</returns>
|
||||
/// <returns><see langword="true"/> if the event was unregistered successfully, <see langword="false"/> otherwise.</returns>
|
||||
public static bool UnregisterEventHandler(MiraEventHandle eventHandle)
|
||||
{
|
||||
if (!EventWrappers.TryGetValue(eventHandle.EventType, out var handlers))
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace MiraAPI.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper for event handlers.
|
||||
/// Wrapper for <see cref="MiraEvent"/> handlers.
|
||||
/// </summary>
|
||||
public class MiraEventWrapper
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace MiraAPI.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Register an event.
|
||||
/// Register a <see cref="MiraEvent"/> handler.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class RegisterEventAttribute : Attribute
|
||||
|
||||
@@ -6,17 +6,17 @@
|
||||
public class AfterMurderEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player that killed the target.
|
||||
/// Gets the <see cref="PlayerControl"/> that killed the <see cref="Target"/>.
|
||||
/// </summary>
|
||||
public PlayerControl Source { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player that was killed.
|
||||
/// Gets the <see cref="PlayerControl"/> that was killed.
|
||||
/// </summary>
|
||||
public PlayerControl Target { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player's body, if it exists.
|
||||
/// Gets the <see cref="Target"/>'s <see cref="global::DeadBody"/>, if it exists.
|
||||
/// </summary>
|
||||
public DeadBody? DeadBody { get; }
|
||||
|
||||
@@ -24,8 +24,8 @@ public class AfterMurderEvent : MiraEvent
|
||||
/// Initializes a new instance of the <see cref="AfterMurderEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="source">The killer.</param>
|
||||
/// <param name="target">The killed player.</param>
|
||||
/// <param name="deadBody">The player's vody, if it exists.</param>
|
||||
/// <param name="target">The killed <see cref="PlayerControl"/>.</param>
|
||||
/// <param name="deadBody">The <paramref name="target"/>'s <see cref="global::DeadBody"/>, if it exists.</param>
|
||||
public AfterMurderEvent(PlayerControl source, PlayerControl target, DeadBody? deadBody)
|
||||
{
|
||||
Source = source;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked before <see cref="GameManager.RpcEndGame"/> is called, allowing cancellation of the game end entirely.
|
||||
/// </summary>
|
||||
public class BeforeGameEndEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the reason for the game end.
|
||||
/// </summary>
|
||||
public GameOverReason Reason { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BeforeGameEndEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="reason">The reason for the game end.</param>
|
||||
public BeforeGameEndEvent(GameOverReason reason)
|
||||
{
|
||||
Reason = reason;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
using MiraAPI.Networking;
|
||||
|
||||
namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
|
||||
/// <summary>
|
||||
/// Event that is invoked before a player is murdered. This event is cancelable.
|
||||
@@ -6,23 +8,42 @@
|
||||
public sealed class BeforeMurderEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player that is killing the target.
|
||||
/// Gets the <see cref="PlayerControl"/> that is killing the <see cref="Target"/>.
|
||||
/// </summary>
|
||||
public PlayerControl Source { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player that is being killed.
|
||||
/// Gets the <see cref="PlayerControl"/> that is being killed.
|
||||
/// </summary>
|
||||
public PlayerControl Target { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the murder was meant to be done in a meeting, via an enum.
|
||||
/// </summary>
|
||||
public MeetingCheck InMeeting { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BeforeMurderEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="source">The player that is killing the target.</param>
|
||||
/// <param name="target">The player that is being killed.</param>
|
||||
/// <param name="source">The <see cref="PlayerControl"/> that is killing the <paramref name="target"/>.</param>
|
||||
/// <param name="target">The <see cref="PlayerControl"/> that is being killed.</param>
|
||||
/// <param name="inMeeting">Whether the murder is intended to be triggered in a meeting.</param>
|
||||
public BeforeMurderEvent(PlayerControl source, PlayerControl target, MeetingCheck inMeeting)
|
||||
{
|
||||
Source = source;
|
||||
Target = target;
|
||||
InMeeting = inMeeting;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BeforeMurderEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="source">The <see cref="PlayerControl"/> that is killing the <paramref name="target"/>.</param>
|
||||
/// <param name="target">The <see cref="PlayerControl"/> that is being killed.</param>
|
||||
public BeforeMurderEvent(PlayerControl source, PlayerControl target)
|
||||
{
|
||||
Source = source;
|
||||
Target = target;
|
||||
InMeeting = MeetingCheck.Ignore;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
|
||||
/// <summary>
|
||||
/// Event invoked on <see cref="IntroCutscene.OnDestroy"/> and <see cref="ExileController.WrapUp"/>
|
||||
/// to determine if it should run the <see cref="RoundStartEvent"/> event or not.
|
||||
/// </summary>
|
||||
public class BeforeRoundStartEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the event was triggered by the <see cref="IntroCutscene"/> or <see cref="ExileController"/>.
|
||||
/// </summary>
|
||||
public bool TriggeredByIntro { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BeforeRoundStartEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="triggeredByIntro">Whether the event was triggered by the intro or not.</param>
|
||||
public BeforeRoundStartEvent(bool triggeredByIntro)
|
||||
{
|
||||
TriggeredByIntro = triggeredByIntro;
|
||||
}
|
||||
}
|
||||
@@ -6,14 +6,14 @@
|
||||
public class GameEndEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the EndGameManager.
|
||||
/// Gets the <see cref="global::EndGameManager"/> instance.
|
||||
/// </summary>
|
||||
public EndGameManager EndGameManager { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GameEndEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="manager">The instance of the EndGameManager.</param>
|
||||
/// <param name="manager">The <see cref="global::EndGameManager"/> instance.</param>
|
||||
public GameEndEvent(EndGameManager manager)
|
||||
{
|
||||
EndGameManager = manager;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
public class IntroBeginEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the IntroCutscene.
|
||||
/// Gets the <see cref="global::IntroCutscene"/> instance.
|
||||
/// </summary>
|
||||
public IntroCutscene IntroCutscene { get; }
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
public class IntroEndEvent(IntroCutscene introCutscene) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the IntroCutscene.
|
||||
/// Gets the <see cref="global::IntroCutscene"/> instance.
|
||||
/// </summary>
|
||||
public IntroCutscene IntroCutscene { get; } = introCutscene;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
|
||||
/// <summary>
|
||||
/// The event that is invoked when the player's role is shown on the intro cutscene. Non cancelable.
|
||||
/// </summary>
|
||||
public class IntroRoleRevealEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="global::IntroCutscene"/> instance.
|
||||
/// </summary>
|
||||
public IntroCutscene IntroCutscene { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IntroRoleRevealEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="introCutscene">The intro cutscene.</param>
|
||||
public IntroRoleRevealEvent(IntroCutscene introCutscene)
|
||||
{
|
||||
IntroCutscene = introCutscene;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
|
||||
/// <summary>
|
||||
/// Start Round event, invoked on IntroCutscene.OnDestroy and ExileController.WrapUp.
|
||||
/// Start Round event, invoked on <see cref="IntroCutscene.OnDestroy"/> and <see cref="ExileController.WrapUp"/>
|
||||
/// if the <see cref="BeforeRoundStartEvent"/> isn't cancelled.
|
||||
/// </summary>
|
||||
public class RoundStartEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the event was triggered by the IntroCutscene or ExileController.
|
||||
/// Gets a value indicating whether the event was triggered by the <see cref="IntroCutscene"/> or <see cref="ExileController"/>.
|
||||
/// </summary>
|
||||
public bool TriggeredByIntro { get; }
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
public class SetRoleEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player whos role was changed.
|
||||
/// Gets the <see cref="PlayerControl"/> whose role was changed.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using MiraAPI.Hud;
|
||||
|
||||
namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a Vanilla <see cref="AbilityButton"/> click is cancelled. Do not use for <see cref="CustomActionButton"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The vanilla <see cref="AbilityButton"/> type.</typeparam>
|
||||
public sealed class VanillaButtonCancelledEvent<T> : MiraEvent where T : AbilityButton
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Vanilla <see cref="AbilityButton"/> whose click was cancelled.
|
||||
/// </summary>
|
||||
public T Button { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="VanillaButtonCancelledEvent{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The vanilla <see cref="AbilityButton"/> whose click was cancelled.</param>
|
||||
public VanillaButtonCancelledEvent(T button)
|
||||
{
|
||||
Button = button;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a Vanilla <see cref="AbilityButton"/> click is cancelled. Do not use for <see cref="CustomActionButton"/>s.
|
||||
/// </summary>
|
||||
public sealed class VanillaButtonCancelledEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Vanilla <see cref="AbilityButton"/> whose click was cancelled.
|
||||
/// </summary>
|
||||
public AbilityButton Button { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="VanillaButtonCancelledEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The vanilla <see cref="AbilityButton"/> whose click was cancelled.</param>
|
||||
public VanillaButtonCancelledEvent(AbilityButton button)
|
||||
{
|
||||
Button = button;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using MiraAPI.Hud;
|
||||
|
||||
namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
|
||||
/// <summary>
|
||||
/// Button click event for Vanilla <see cref="AbilityButton"/>s only. Do not use for <see cref="CustomActionButton"/>s.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The vanilla <see cref="AbilityButton"/> type.</typeparam>
|
||||
public sealed class VanillaButtonClickEvent<T> : MiraCancelableEvent where T : AbilityButton
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the vanilla <see cref="AbilityButton"/> that was clicked.
|
||||
/// </summary>
|
||||
public T Button { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the generic <see cref="VanillaButtonClickEvent"/> that is invoked before this button-specific event.
|
||||
/// </summary>
|
||||
public VanillaButtonClickEvent GenericClickEvent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="VanillaButtonClickEvent{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The vanilla <see cref="AbilityButton"/> that was clicked.</param>
|
||||
/// <param name="genericClickEvent">The generic <see cref="VanillaButtonClickEvent"/> invoked before button-specific events.</param>
|
||||
public VanillaButtonClickEvent(T button, VanillaButtonClickEvent genericClickEvent)
|
||||
{
|
||||
GenericClickEvent = genericClickEvent;
|
||||
Button = button;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Button click event for Vanilla <see cref="AbilityButton"/> only. Do not use for <see cref="CustomActionButton"/>s.
|
||||
/// </summary>
|
||||
public sealed class VanillaButtonClickEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Vanilla <see cref="AbilityButton"/> that was clicked.
|
||||
/// </summary>
|
||||
public AbilityButton Button { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the target <see cref="PlayerControl"/>, if any, of the Vanilla <see cref="AbilityButton"/> that was clicked.
|
||||
/// </summary>
|
||||
public PlayerControl? PlayerTarget { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the target <see cref="Vent"/>, if any, of the Vanilla <see cref="AbilityButton"/> that was clicked.
|
||||
/// </summary>
|
||||
public Vent? VentTarget { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="VanillaButtonClickEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The Vanilla <see cref="AbilityButton"/> that was clicked.</param>
|
||||
/// <param name="playerTarget">The <see cref="PlayerControl"/> target, if any.</param>
|
||||
/// <param name="ventTarget">The <see cref="Vent"/> target, if any.</param>
|
||||
public VanillaButtonClickEvent(AbilityButton button, PlayerControl? playerTarget = null, Vent? ventTarget = null)
|
||||
{
|
||||
Button = button;
|
||||
PlayerTarget = playerTarget;
|
||||
VentTarget = ventTarget;
|
||||
}
|
||||
}
|
||||
@@ -6,14 +6,14 @@
|
||||
public class PlayerOpenSabotageEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the MapBehaviour.
|
||||
/// Gets the <see cref="global::MapBehaviour"/>.
|
||||
/// </summary>
|
||||
public MapBehaviour MapBehaviour { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlayerOpenSabotageEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="mapBehaviour">The MapBehaviour.</param>
|
||||
/// <param name="mapBehaviour">The <see cref="global::MapBehaviour"/>.</param>
|
||||
public PlayerOpenSabotageEvent(MapBehaviour mapBehaviour)
|
||||
{
|
||||
MapBehaviour = mapBehaviour;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace MiraAPI.Events.Vanilla.Map;
|
||||
|
||||
/// <summary>
|
||||
/// Cancelable event that is invoked before a system is updated. Usually used for sabotage events.
|
||||
/// <see cref="MiraCancelableEvent"/> that is invoked before a system is updated. Usually used for sabotage events.
|
||||
/// </summary>
|
||||
public class UpdateSystemEvent : MiraCancelableEvent
|
||||
{
|
||||
@@ -11,7 +11,7 @@ public class UpdateSystemEvent : MiraCancelableEvent
|
||||
public SystemTypes SystemType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player that is updating the system.
|
||||
/// Gets the <see cref="PlayerControl"/> that is updating the system.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
|
||||
@@ -21,10 +21,10 @@ public class UpdateSystemEvent : MiraCancelableEvent
|
||||
public byte Amount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateSystemEvent"/> class.
|
||||
/// Initializes a new instance of the <see cref="UpdateSystemEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="systemType">The SystemType being updated.</param>
|
||||
/// <param name="player">The player that is updating the system.</param>
|
||||
/// <param name="systemType">The <see cref="SystemTypes"/> being updated.</param>
|
||||
/// <param name="player">The <see cref="PlayerControl"/> that is updating the system.</param>
|
||||
/// <param name="amount">Amount to update System to.</param>
|
||||
public UpdateSystemEvent(SystemTypes systemType, PlayerControl player, byte amount)
|
||||
{
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
public class EjectionEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the ExileController.
|
||||
/// Gets the <see cref="global::ExileController"/> instance.
|
||||
/// </summary>
|
||||
public ExileController ExileController { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EjectionEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="controller">The exile controller.</param>
|
||||
/// <param name="controller">The <see cref="global::ExileController"/> instance.</param>
|
||||
public EjectionEvent(ExileController controller)
|
||||
{
|
||||
ExileController = controller;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
public class EndMeetingEvent(MeetingHud meetingHud) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the MeetingHud instance.
|
||||
/// Gets the <see cref="global::MeetingHud"/> instance.
|
||||
/// </summary>
|
||||
public MeetingHud MeetingHud { get; } = meetingHud;
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
/// <summary>
|
||||
/// The event that is invoked when a body is reported.
|
||||
/// This is invoked in CmdReportBody.
|
||||
/// This is invoked in <see cref="PlayerControl.CmdReportDeadBody(NetworkedPlayerInfo)"/>.
|
||||
/// </summary>
|
||||
public class ReportBodyEvent : MiraCancelableEvent
|
||||
{
|
||||
@@ -12,12 +12,12 @@ public class ReportBodyEvent : MiraCancelableEvent
|
||||
public PlayerControl Reporter { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player that is being reported. Will be null for emergency meeting.
|
||||
/// Gets the player that is being reported. Will be <see langword="null"/> for emergency meeting.
|
||||
/// </summary>
|
||||
public NetworkedPlayerInfo? Target { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the body that is being reported. Will be null for emergency meeting.
|
||||
/// Gets the <see cref="DeadBody"/> that is being reported. Will be <see langword="null"/> for emergency meeting.
|
||||
/// </summary>
|
||||
public DeadBody? Body { get; }
|
||||
|
||||
@@ -26,7 +26,7 @@ public class ReportBodyEvent : MiraCancelableEvent
|
||||
/// </summary>
|
||||
/// <param name="reporter">The player who reported the body.</param>
|
||||
/// <param name="target">The player being reported.</param>
|
||||
/// <param name="body">The body being reported.</param>
|
||||
/// <param name="body">The <see cref="DeadBody"/> being reported.</param>
|
||||
public ReportBodyEvent(PlayerControl reporter, NetworkedPlayerInfo? target, DeadBody? body)
|
||||
{
|
||||
Reporter = reporter;
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
public class StartMeetingEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the MeetingHud instance.
|
||||
/// Gets the <see cref="global::MeetingHud"/> instance.
|
||||
/// </summary>
|
||||
public MeetingHud MeetingHud { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StartMeetingEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="meetingHud">The MeetingHud instance.</param>
|
||||
/// <param name="meetingHud">The <see cref="global::MeetingHud"/> instance.</param>
|
||||
public StartMeetingEvent(MeetingHud meetingHud)
|
||||
{
|
||||
MeetingHud = meetingHud;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||
|
||||
/// <summary>
|
||||
/// Event that is invoked after the local player successfully votes a player or skips. This event is not cancelable.
|
||||
/// </summary>
|
||||
public class AfterVoteEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the voter's <see cref="PlayerVoteArea"/>.
|
||||
/// </summary>
|
||||
public PlayerVoteArea VoteArea { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player who voted.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AfterVoteEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="playerVoteArea">The <see cref="PlayerVoteArea"/> that was voted on.</param>
|
||||
/// <param name="voter">The player who voted.</param>
|
||||
public AfterVoteEvent(PlayerVoteArea playerVoteArea, PlayerControl voter)
|
||||
{
|
||||
VoteArea = playerVoteArea;
|
||||
Player = voter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||
|
||||
/// <summary>
|
||||
/// Event that is invoked before the local player confirms a vote on a player or when skipping. This event is cancelable.
|
||||
/// </summary>
|
||||
public class BeforeVoteEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the voter's <see cref="PlayerVoteArea"/>.
|
||||
/// </summary>
|
||||
public PlayerVoteArea VoteArea { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player who voted.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BeforeVoteEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="playerVoteArea">The <see cref="PlayerVoteArea"/> that was voted on.</param>
|
||||
/// <param name="voter">The player who voted.</param>
|
||||
public BeforeVoteEvent(PlayerVoteArea playerVoteArea, PlayerControl voter)
|
||||
{
|
||||
VoteArea = playerVoteArea;
|
||||
Player = voter;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public class CheckForEndVotingEvent : MiraCancelableEvent
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CheckForEndVotingEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="isVotingComplete">>True if voting is complete, false otherwise.</param>
|
||||
/// <param name="isVotingComplete"><see langword="true"/> if voting is complete, <see langword="false"/> otherwise.</param>
|
||||
public CheckForEndVotingEvent(bool isVotingComplete)
|
||||
{
|
||||
IsVotingComplete = isVotingComplete;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Voting;
|
||||
|
||||
namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked before the dummy selects their vote. If canceled, the dummy won't vote.
|
||||
/// </summary>
|
||||
public class DummyVoteEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the dummy that needs to vote.
|
||||
/// </summary>
|
||||
public DummyBehaviour Dummy { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance of the dummy's <see cref="PlayerVoteData"/>.
|
||||
/// </summary>
|
||||
public PlayerVoteData VoteData { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the dummy can vote to skip the meeting.
|
||||
/// </summary>
|
||||
public bool CanSkip { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a predicate for validating whether the dummy can vote on a player.
|
||||
/// By default, excludes dead and disconnected players.
|
||||
/// </summary>
|
||||
public Predicate<PlayerControl> PlayerIsValid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DummyVoteEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="dummy">The voting dummy.</param>
|
||||
public DummyVoteEvent(DummyBehaviour dummy)
|
||||
{
|
||||
Dummy = dummy;
|
||||
VoteData = dummy.myPlayer.GetVoteData();
|
||||
CanSkip = true;
|
||||
PlayerIsValid = x => !x.Data.IsDead && !x.Data.Disconnected;
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,12 @@ namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||
/// <summary>
|
||||
/// The event that is invoked when Mira handles a vote. This is invoked before Mira's behaviour, so be cautious.
|
||||
/// If you intend on adding custom vote behaviour, cancel the event and do so.
|
||||
/// If you are NOT canceling the event, keep in mind that Mira automatically removes a vote and adds the suspect to the VotedPlayers list after this event is invoked.
|
||||
/// If you are NOT canceling the event, keep in mind that Mira automatically removes a vote and adds the suspect to the <see cref="PlayerVoteData.Votes"/> list after this event is invoked.
|
||||
/// </summary>
|
||||
public class HandleVoteEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the voter's vote data.
|
||||
/// Gets the instance of the voter's <see cref="PlayerVoteData"/>.
|
||||
/// </summary>
|
||||
public PlayerVoteData VoteData { get; }
|
||||
|
||||
@@ -30,14 +30,14 @@ public class HandleVoteEvent : MiraCancelableEvent
|
||||
public bool PreventVote { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player info of the target.
|
||||
/// Gets the <see cref="NetworkedPlayerInfo"/> of the target.
|
||||
/// </summary>
|
||||
public NetworkedPlayerInfo TargetPlayerInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HandleVoteEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="playerVoteData">The voter's data.</param>
|
||||
/// <param name="playerVoteData">The voter's <see cref="PlayerVoteData"/>.</param>
|
||||
/// <param name="targetId">The target's playerId.</param>
|
||||
public HandleVoteEvent(PlayerVoteData playerVoteData, byte targetId)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||
public class MeetingSelectEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the voter's vote data.
|
||||
/// Gets the instance of the voter's <see cref="PlayerVoteData"/>.
|
||||
/// </summary>
|
||||
public PlayerVoteData VoteData { get; }
|
||||
|
||||
@@ -18,7 +18,7 @@ public class MeetingSelectEvent : MiraEvent
|
||||
public int TargetId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player info of the target.
|
||||
/// Gets the <see cref="NetworkedPlayerInfo"/> of the target.
|
||||
/// </summary>
|
||||
public NetworkedPlayerInfo TargetPlayerInfo { get; }
|
||||
|
||||
@@ -30,9 +30,9 @@ public class MeetingSelectEvent : MiraEvent
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MeetingSelectEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="playerVoteData">The voter's data.</param>
|
||||
/// <param name="playerVoteData">The voter's <see cref="PlayerVoteData"/>.</param>
|
||||
/// <param name="targetId">The target's playerId.</param>
|
||||
/// <param name="allowSelect">>Whether the player is allowed to select the target.</param>
|
||||
/// <param name="allowSelect">Whether the player is allowed to select the target.</param>
|
||||
public MeetingSelectEvent(PlayerVoteData playerVoteData, int targetId, bool allowSelect)
|
||||
{
|
||||
VoteData = playerVoteData;
|
||||
|
||||
@@ -4,20 +4,20 @@ using MiraAPI.Voting;
|
||||
namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||
|
||||
/// <summary>
|
||||
/// Called in VotingUtils.HandlePopulateResults.
|
||||
/// Called in <see cref="VotingUtils.HandlePopulateResults"/>.
|
||||
/// Cancelling is NOT advised but if you do plan on cancelling, please ensure you account for displaying ALL player's votes.
|
||||
/// </summary>
|
||||
public class PopulateResultsEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a list of networked votes.
|
||||
/// Gets a list of networked <see cref="CustomVote"/>s.
|
||||
/// </summary>
|
||||
public List<CustomVote> Votes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PopulateResultsEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="votes">The list of votes.</param>
|
||||
/// <param name="votes">The list of <see cref="CustomVote"/>s.</param>
|
||||
public PopulateResultsEvent(List<CustomVote> votes)
|
||||
{
|
||||
Votes = votes;
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||
/// <remarks>
|
||||
/// Initializes a new instance of the <see cref="ProcessVotesEvent"/> class.
|
||||
/// </remarks>
|
||||
/// <param name="votes">>The list of votes that are being processed.</param>
|
||||
/// <param name="exiledPlayer">The player to be exiled. Will be null if no player is to be exiled.</param>
|
||||
/// <param name="votes">The list of <see cref="CustomVote"/>s that are being processed.</param>
|
||||
/// <param name="exiledPlayer">The player to be exiled. Will be <see langword="null"/> if no player is to be exiled.</param>
|
||||
public class ProcessVotesEvent(List<CustomVote> votes, NetworkedPlayerInfo? exiledPlayer = null) : MiraEvent
|
||||
{
|
||||
private readonly List<CustomVote> _originalVotes = [.. votes];
|
||||
@@ -29,12 +29,12 @@ public class ProcessVotesEvent(List<CustomVote> votes, NetworkedPlayerInfo? exil
|
||||
public bool VotesModified => !Votes.SequenceEqual(_originalVotes);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of votes that are being processed.
|
||||
/// Gets the list of <see cref="CustomVote"/>s that are being processed.
|
||||
/// </summary>
|
||||
public List<CustomVote> Votes { get; } = votes;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the player to be exiled. Will be null if no player is to be exiled.
|
||||
/// Gets or sets the player to be exiled. Will be <see langword="null"/> if no player is to be exiled.
|
||||
/// </summary>
|
||||
public NetworkedPlayerInfo? ExiledPlayer
|
||||
{
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
/// <summary>
|
||||
/// The event that is invoked when the voting phase of a meeting is complete.
|
||||
/// </summary>
|
||||
/// <param name="meetingHud">The MeetingHud instance.</param>
|
||||
/// <param name="meetingHud">The <see cref="global::MeetingHud"/> instance.</param>
|
||||
public class VotingCompleteEvent(MeetingHud meetingHud) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the MeetingHud instance.
|
||||
/// Gets the <see cref="global::MeetingHud"/> instance.
|
||||
/// </summary>
|
||||
public MeetingHud MeetingHud { get; } = meetingHud;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
namespace MiraAPI.Events.Vanilla.Player;
|
||||
|
||||
/// <summary>
|
||||
/// The event that is invoked when a player completes a task within Hide and Seek. Non-cancelable.
|
||||
/// </summary>
|
||||
public class CompleteHnsTaskEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the <see cref="PlayerControl"/>.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance of the <see cref="PlayerTask"/> that the player completed.
|
||||
/// </summary>
|
||||
public PlayerTask Task { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance of the <see cref="HideAndSeekManager"/> attached to the game.
|
||||
/// </summary>
|
||||
public HideAndSeekManager HnsManager { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CompleteHnsTaskEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="hnsManager">The <see cref="HideAndSeekManager"/> currently active.</param>
|
||||
/// <param name="player">The player who completed the task.</param>
|
||||
/// <param name="task">The task that the player completed.</param>
|
||||
public CompleteHnsTaskEvent(HideAndSeekManager hnsManager, PlayerControl player, PlayerTask task)
|
||||
{
|
||||
HnsManager = hnsManager;
|
||||
Player = player;
|
||||
Task = task;
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ public class PlayerDeathEvent : MiraEvent
|
||||
public DeathReason DeathReason { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the dead body associated with the player, if any.
|
||||
/// Gets the <see cref="global::DeadBody"/> associated with the player, if any.
|
||||
/// </summary>
|
||||
public DeadBody? DeadBody { get; }
|
||||
|
||||
@@ -25,7 +25,7 @@ public class PlayerDeathEvent : MiraEvent
|
||||
/// </summary>
|
||||
/// <param name="player">The player who died.</param>
|
||||
/// <param name="reason">The reason the player died.</param>
|
||||
/// <param name="deadBody">The player's body, if it exists.</param>
|
||||
/// <param name="deadBody">The player's <see cref="global::DeadBody"/>, if it exists.</param>
|
||||
public PlayerDeathEvent(PlayerControl player, DeathReason reason, DeadBody? deadBody)
|
||||
{
|
||||
Player = player;
|
||||
|
||||
@@ -6,20 +6,20 @@
|
||||
public class EnterVentEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player that is entering the vent.
|
||||
/// Gets the <see cref="PlayerControl"/> that is entering the <see cref="Vent"/>.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the vent that the player is entering.
|
||||
/// Gets the <see cref="global::Vent"/> that the <see cref="Player"/> is entering.
|
||||
/// </summary>
|
||||
public Vent? Vent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EnterVentEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="player">The player that is entering the vent.</param>
|
||||
/// <param name="vent">The vent being entered.</param>
|
||||
/// <param name="player">The <see cref="PlayerControl"/> that is entering the <paramref name="vent"/>.</param>
|
||||
/// <param name="vent">The <see cref="global::Vent"/> being entered.</param>
|
||||
public EnterVentEvent(PlayerControl player, Vent? vent)
|
||||
{
|
||||
Player = player;
|
||||
|
||||
@@ -6,20 +6,20 @@
|
||||
public class ExitVentEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player that is exiting the vent.
|
||||
/// Gets the <see cref="PlayerControl"/> that is exiting the <see cref="Vent"/>.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the vent that the player is exiting.
|
||||
/// Gets the <see cref="global::Vent"/> that the <see cref="Player"/> is exiting.
|
||||
/// </summary>
|
||||
public Vent? Vent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ExitVentEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="player">The player who is exiting the vent.</param>
|
||||
/// <param name="vent">The vent being exited from.</param>
|
||||
/// <param name="player">The <see cref="PlayerControl"/> who is exiting the <paramref name="vent"/>.</param>
|
||||
/// <param name="vent">The <see cref="global::Vent"/> being exited from.</param>
|
||||
public ExitVentEvent(PlayerControl player, Vent? vent)
|
||||
{
|
||||
Player = player;
|
||||
|
||||
@@ -8,7 +8,7 @@ public class PlayerCanUseEvent : PlayerUseEvent
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlayerCanUseEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="usable">The IUsable.</param>
|
||||
/// <param name="usable">The <see cref="IUsable"/>.</param>
|
||||
public PlayerCanUseEvent(IUsable usable) : base(usable)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -11,19 +11,19 @@ public class PlayerUseEvent : MiraCancelableEvent
|
||||
public IUsable Usable { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the IUsable is a <see cref="Console"/>, <see cref="MapConsole"/>, or <see cref="SystemConsole"/>.
|
||||
/// Gets a value indicating whether the <see cref="Usable"/> is a <see cref="Console"/>, <see cref="MapConsole"/>, or <see cref="SystemConsole"/>.
|
||||
/// </summary>
|
||||
public bool IsPrimaryConsole { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the IUsable is a <see cref="Vent"/>.
|
||||
/// Gets a value indicating whether the <see cref="Usable"/> is a <see cref="Vent"/>.
|
||||
/// </summary>
|
||||
public bool IsVent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlayerUseEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="usable">The IUsable.</param>
|
||||
/// <param name="usable">The <see cref="IUsable"/>.</param>
|
||||
public PlayerUseEvent(IUsable usable)
|
||||
{
|
||||
Usable = usable;
|
||||
|
||||
@@ -10,44 +10,44 @@ namespace MiraAPI.GameEnd;
|
||||
public abstract class CustomGameOver
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the current CustomGameOver.
|
||||
/// Gets the current <see cref="CustomGameOver"/>.
|
||||
/// </summary>
|
||||
public static CustomGameOver? Instance { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Verifies if the condition for this CustomGameOver is met.
|
||||
/// Verifies if the condition for this <see cref="CustomGameOver"/> is met.
|
||||
/// </summary>
|
||||
/// <param name="playerControl">The PlayerControl that requested the Game Over.</param>
|
||||
/// <param name="playerControl">The <see cref="PlayerControl"/> that requested the Game Over.</param>
|
||||
/// <param name="winners">The collection of winners.</param>
|
||||
/// <returns>True if the condition is met, otherwise false.</returns>
|
||||
/// <returns><see langword="true"/> if the condition is met, otherwise <see langword="false"/>.</returns>
|
||||
public virtual bool VerifyCondition(PlayerControl playerControl, NetworkedPlayerInfo[] winners)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs before the base game calls EndGameManager.SetEverythingUp.
|
||||
/// Runs before the base game calls <see cref="EndGameManager.SetEverythingUp"/>.
|
||||
/// </summary>
|
||||
/// <param name="endGameManager">The EndGameManager instance.</param>
|
||||
/// <returns>Return True to use the run the original method, return False to skip it.</returns>
|
||||
/// <param name="endGameManager">The <see cref="EndGameManager"/> instance.</param>
|
||||
/// <returns>Return <see langword="true"/> to use the run the original method, return <see langword="false"/> to skip it.</returns>
|
||||
public virtual bool BeforeEndGameSetup(EndGameManager endGameManager)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs after the base game calls EndGameManager.SetEverythingUp.
|
||||
/// Runs after the base game calls <see cref="EndGameManager.SetEverythingUp"/>.
|
||||
/// </summary>
|
||||
/// <param name="endGameManager">The EndGameManager instance.</param>
|
||||
/// <param name="endGameManager">The <see cref="EndGameManager"/> instance.</param>
|
||||
public virtual void AfterEndGameSetup(EndGameManager endGameManager)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the GameOverReason associated with this CustomGameOver.
|
||||
/// Get the <see cref="global::GameOverReason"/> associated with this <see cref ="CustomGameOver"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the custom game over.</typeparam>
|
||||
/// <returns>The GameOverReason associated with the custom game over.</returns>
|
||||
/// <returns>The <see cref="global::GameOverReason"/> associated with the custom game over.</returns>
|
||||
public static GameOverReason GameOverReason<T>() where T : CustomGameOver
|
||||
{
|
||||
return (GameOverReason)GameOverManager.GetGameOverId<T>();
|
||||
@@ -63,14 +63,14 @@ public abstract class CustomGameOver
|
||||
var reason = GameOverManager.GetGameOverId<T>();
|
||||
var data = new GameOverData(reason, [.. winners]);
|
||||
|
||||
Rpc<CustomGameOverRpc>.Instance.Send(PlayerControl.LocalPlayer, data);
|
||||
Rpc<CustomGameOverRpc>.Instance.Send(PlayerControl.LocalPlayer, data, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly convert a CustomGameOver to a GameOverReason.
|
||||
/// Implicitly convert a <see cref="CustomGameOver"/> to a <see cref="global::GameOverReason"/>.
|
||||
/// </summary>
|
||||
/// <param name="gameOver">The CustomGameOver instance.</param>
|
||||
/// <returns>The GameOverReason associated with the CustomGameOver.</returns>
|
||||
/// <param name="gameOver">The <see cref="CustomGameOver"/> instance.</param>
|
||||
/// <returns>The <see cref="global::GameOverReason"/> associated with the CustomGameOver.</returns>
|
||||
public static implicit operator GameOverReason(CustomGameOver gameOver)
|
||||
{
|
||||
return (GameOverReason)GameOverManager.GetGameOverId(gameOver.GetType());
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.GameEnd;
|
||||
|
||||
/// <summary>
|
||||
/// Manage custom game overs.
|
||||
/// Manage <see cref="CustomGameOver"/>s.
|
||||
/// </summary>
|
||||
public static class GameOverManager
|
||||
{
|
||||
@@ -16,11 +15,11 @@ public static class GameOverManager
|
||||
private static int _nextId = Enum.GetNames<GameOverReason>().Length;
|
||||
|
||||
/// <summary>
|
||||
/// Register a custom game over.
|
||||
/// Register a <see cref="CustomGameOver"/>.
|
||||
/// </summary>
|
||||
/// <param name="gameOverType">Type of the custom game over.</param>
|
||||
/// <exception cref="ArgumentException">Thrown when the type is not a subclass of CustomGameOver, is abstract, or does not have a parameterless constructor.</exception>
|
||||
/// <returns>>True if the game over was registered successfully, false otherwise.</returns>
|
||||
/// <param name="gameOverType">Type of the <see cref="CustomGameOver"/>.</param>
|
||||
/// <exception cref="ArgumentException">Thrown when the type is not a subclass of <see cref="CustomGameOver"/>, is abstract, or does not have a parameterless constructor.</exception>
|
||||
/// <returns><see langword="true"/> if the game over was registered successfully, <see langword="false"/> otherwise.</returns>
|
||||
public static bool RegisterGameOver(Type gameOverType)
|
||||
{
|
||||
if (!typeof(CustomGameOver).IsAssignableFrom(gameOverType))
|
||||
@@ -30,13 +29,13 @@ public static class GameOverManager
|
||||
|
||||
if (gameOverType.IsAbstract)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error("The type must not be abstract.");
|
||||
Error("The type must not be abstract.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (gameOverType.GetConstructor(Type.EmptyTypes) == null)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error("The type must have a parameterless constructor.");
|
||||
Error("The type must have a parameterless constructor.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -47,11 +46,11 @@ public static class GameOverManager
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an instance of a custom game over.
|
||||
/// Create an instance of a <see cref="CustomGameOver"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">ID of the custom game over.</param>
|
||||
/// <param name="customGameOver">The created instance of the custom game over.</param>
|
||||
/// <returns>An instance of the custom game over.</returns>
|
||||
/// <param name="id">ID of the <see cref="CustomGameOver"/>.</param>
|
||||
/// <param name="customGameOver">The created instance of the <see cref="CustomGameOver"/>.</param>
|
||||
/// <returns>An instance of the <see cref="CustomGameOver"/>.</returns>
|
||||
public static bool TryGetGameOver(int id, [NotNullWhen(true)] out CustomGameOver? customGameOver)
|
||||
{
|
||||
if (GameOverTypes.TryGetValue(id, out var gameOverType))
|
||||
@@ -65,20 +64,20 @@ public static class GameOverManager
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the ID of a custom game over.
|
||||
/// Get the ID of a <see cref="CustomGameOver"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the custom game over.</typeparam>
|
||||
/// <returns>The ID of the custom game over.</returns>
|
||||
/// <typeparam name="T">Type of the <see cref="CustomGameOver"/>.</typeparam>
|
||||
/// <returns>The ID of the <see cref="CustomGameOver"/>.</returns>
|
||||
public static int GetGameOverId<T>() where T : CustomGameOver
|
||||
{
|
||||
return GetGameOverId(typeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the ID of a custom game over.
|
||||
/// Get the ID of a <see cref="CustomGameOver"/>.
|
||||
/// </summary>
|
||||
/// <param name="gameOverType">Type of the custom game over.</param>
|
||||
/// <returns>The ID of the custom game over.</returns>
|
||||
/// <param name="gameOverType">Type of the <see cref="CustomGameOver"/>.</param>
|
||||
/// <returns>The ID of the <see cref="CustomGameOver"/>.</returns>
|
||||
/// <exception cref="ArgumentException">Thrown when the type is not registered.</exception>
|
||||
public static int GetGameOverId(Type gameOverType)
|
||||
{
|
||||
|
||||
@@ -23,24 +23,24 @@ public abstract class CustomGameMode
|
||||
public abstract int Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Called when Intro Cutscene is destroyed.
|
||||
/// Called when <see cref="IntroCutscene"/> is destroyed.
|
||||
/// </summary>
|
||||
public virtual void Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on HudManager.Start().
|
||||
/// Called on <see cref="HudManager.Start"/>.
|
||||
/// </summary>
|
||||
/// <param name="instance">Instance of HudManager.</param>
|
||||
/// <param name="instance">Instance of <see cref="HudManager"/>.</param>
|
||||
public virtual void HudStart(HudManager instance)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called every frame on HudManager.Update().
|
||||
/// Called every frame on <see cref="HudManager.Update"/>.
|
||||
/// </summary>
|
||||
/// <param name="instance">Instance of HudManager.</param>
|
||||
/// <param name="instance">Instance of <see cref="HudManager"/>.</param>
|
||||
public virtual void HudUpdate(HudManager instance)
|
||||
{
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public abstract class CustomGameMode
|
||||
/// <summary>
|
||||
/// Called when a player is killed.
|
||||
/// </summary>
|
||||
/// <param name="player">PlayerControl that was killed.</param>
|
||||
/// <param name="player"><see cref="PlayerControl"/> that was killed.</param>
|
||||
public virtual void OnDeath(PlayerControl player)
|
||||
{
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public abstract class CustomGameMode
|
||||
/// Calculate Game End logic.
|
||||
/// </summary>
|
||||
/// <param name="runOriginal">Should original game end logic be used.</param>
|
||||
/// <param name="instance">Instance of LogicGameFlowNormal.</param>
|
||||
/// <param name="instance">Instance of <see cref="LogicGameFlowNormal"/>.</param>
|
||||
public virtual void CheckGameEnd(out bool runOriginal, LogicGameFlowNormal instance)
|
||||
{
|
||||
runOriginal = true;
|
||||
@@ -67,7 +67,7 @@ public abstract class CustomGameMode
|
||||
/// Custom role assignment.
|
||||
/// </summary>
|
||||
/// <param name="runOriginal">Should original role assignment be used.</param>
|
||||
/// <param name="instance">Instance of LogicRoleSelection.</param>
|
||||
/// <param name="instance">Instance of <see cref="LogicRoleSelection"/>.</param>
|
||||
public virtual void AssignRoles(out bool runOriginal, LogicRoleSelectionNormal instance)
|
||||
{
|
||||
runOriginal = true;
|
||||
@@ -78,7 +78,7 @@ public abstract class CustomGameMode
|
||||
/// </summary>
|
||||
/// <param name="runOriginal">Should the original murder logic be used.</param>
|
||||
/// <param name="result">Result of custom murder logic.</param>
|
||||
/// <param name="target">Target player for murder.</param>
|
||||
/// <param name="target">Target <see cref="PlayerControl"/> for murder.</param>
|
||||
public virtual void CanKill(out bool runOriginal, out bool result, PlayerControl target)
|
||||
{
|
||||
result = false;
|
||||
@@ -88,60 +88,60 @@ public abstract class CustomGameMode
|
||||
/// <summary>
|
||||
/// Should Roles Settings be available when this gamemode is selected.
|
||||
/// </summary>
|
||||
/// <returns>True if Role Settings are enabled in this game mode.</returns>
|
||||
/// <returns><see langword="true"/> if Role Settings are enabled in this game mode.</returns>
|
||||
public virtual bool AreRoleSettingsEnabled() => true;
|
||||
|
||||
/// <summary>
|
||||
/// Should Game Settings be available when this gamemode is selected.
|
||||
/// </summary>
|
||||
/// <returns>True if Game Settings are enabled in this mode.</returns>
|
||||
/// <returns><see langword="true"/> if Game Settings are enabled in this mode.</returns>
|
||||
public virtual bool AreGameSettingsEnabled() => true;
|
||||
|
||||
/// <summary>
|
||||
/// Custom winner selection.
|
||||
/// </summary>
|
||||
/// <returns>List of winners or null.</returns>
|
||||
/// <returns>List of winners or <see langword="null"/>.</returns>
|
||||
public virtual List<NetworkedPlayerInfo>? CalculateWinners() => null;
|
||||
|
||||
/// <summary>
|
||||
/// Show gamemode in Intro Cutscene.
|
||||
/// Show gamemode in <see cref="IntroCutscene"/>.
|
||||
/// </summary>
|
||||
/// <returns>True if the game mode should be shown in the intro cutscene.</returns>
|
||||
/// <returns><see langword="true"/> if the game mode should be shown in the intro cutscene.</returns>
|
||||
public virtual bool ShowGameModeIntroCutscene() => false;
|
||||
|
||||
/// <summary>
|
||||
/// Can Admin be used in this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="console">Admin Console.</param>
|
||||
/// <returns>True if Admin console is enabled.</returns>
|
||||
/// <returns><see langword="true"/> if Admin console is enabled.</returns>
|
||||
public virtual bool CanUseMapConsole(MapConsole console) => true;
|
||||
|
||||
/// <summary>
|
||||
/// Can a body be reported in this gamemode.
|
||||
/// Can a <see cref="DeadBody"/> be reported in this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="body">Target body for reporting.</param>
|
||||
/// <returns>True if dead bodies can be reported.</returns>
|
||||
/// <param name="body">Target <see cref="DeadBody"/> for reporting.</param>
|
||||
/// <returns><see langword="true"/> if <see cref="DeadBody"/>s can be reported.</returns>
|
||||
public virtual bool CanReport(DeadBody body) => true;
|
||||
|
||||
/// <summary>
|
||||
/// Can system consoles be used in this gamemode.
|
||||
/// Can <see cref="SystemConsole"/>s be used in this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="console">System Console.</param>
|
||||
/// <returns>True if system consoles are enabled in this mode.</returns>
|
||||
/// <returns><see langword="true"/> if <see cref="SystemConsole"/>s are enabled in this mode.</returns>
|
||||
public virtual bool CanUseSystemConsole(SystemConsole console) => true;
|
||||
|
||||
/// <summary>
|
||||
/// Can tasks be interacted with in this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="console">Task console.</param>
|
||||
/// <returns>True if tasks are enabled in this mode.</returns>
|
||||
/// <returns><see langword="true"/> if tasks are enabled in this mode.</returns>
|
||||
public virtual bool CanUseTasks(Console console) => true;
|
||||
|
||||
/// <summary>
|
||||
/// Should the sabotage map be used when attempting to open sabotage overlay.
|
||||
/// </summary>
|
||||
/// <param name="map">MapBehaviour object.</param>
|
||||
/// <returns>True if the sabotage map should be shown.</returns>
|
||||
/// <param name="map"><see cref="MapBehaviour"/> object.</param>
|
||||
/// <returns><see langword="true"/> if the sabotage map should be shown.</returns>
|
||||
public virtual bool ShouldShowSabotageMap(MapBehaviour map) => true;
|
||||
|
||||
/// <summary>
|
||||
@@ -149,6 +149,6 @@ public abstract class CustomGameMode
|
||||
/// </summary>
|
||||
/// <param name="vent">Target vent.</param>
|
||||
/// <param name="playerInfo">Player attempting to vent.</param>
|
||||
/// <returns>True if venting is enabled in this mode.</returns>
|
||||
/// <returns><see langword="true"/> if venting is enabled in this mode.</returns>
|
||||
public virtual bool CanVent(Vent vent, NetworkedPlayerInfo playerInfo) => true;
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.GameModes;
|
||||
|
||||
/// <summary>
|
||||
/// Manages custom gamemodes.
|
||||
/// Manages <see cref="CustomGameMode"/>s.
|
||||
/// </summary>
|
||||
public static class CustomGameModeManager
|
||||
{
|
||||
/// <summary>
|
||||
/// List of registered gamemodes.
|
||||
/// List of registered <see cref="CustomGameMode"/>.
|
||||
/// </summary>
|
||||
internal static readonly Dictionary<int, CustomGameMode> GameModes = [];
|
||||
|
||||
@@ -21,14 +20,14 @@ public static class CustomGameModeManager
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current gamemode.
|
||||
/// Gets the current <see cref="CustomGameMode"/>.
|
||||
/// </summary>
|
||||
public static CustomGameMode? ActiveMode { get; internal set; } = new DefaultMode();
|
||||
|
||||
/// <summary>
|
||||
/// Set current gamemode.
|
||||
/// Set current <see cref="CustomGameMode"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">gamemode ID.</param>
|
||||
/// <param name="id"><see cref="CustomGameMode"/> ID.</param>
|
||||
public static void SetGameMode(int id)
|
||||
{
|
||||
if (GameModes.TryGetValue(id, out var gameMode))
|
||||
@@ -37,18 +36,18 @@ public static class CustomGameModeManager
|
||||
return;
|
||||
}
|
||||
|
||||
Logger<MiraApiPlugin>.Error($"No gamemode with id {id} found!");
|
||||
Error($"No gamemode with id {id} found!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register gamemode from type.
|
||||
/// Register <see cref="CustomGameMode"/> from type.
|
||||
/// </summary>
|
||||
/// <param name="gameModeType">Type of gamemode class, should inherit from <see cref="CustomGameMode"/>.</param>
|
||||
/// <param name="gameModeType">Type of <see cref="CustomGameMode"/>, should inherit from <see cref="CustomGameMode"/>.</param>
|
||||
internal static void RegisterGameMode(Type gameModeType)
|
||||
{
|
||||
if (!typeof(CustomGameMode).IsAssignableFrom(gameModeType))
|
||||
{
|
||||
Logger<MiraApiPlugin>.Warning($"{gameModeType.Name} does not inherit CustomGameMode!");
|
||||
Warning($"{gameModeType.Name} does not inherit CustomGameMode!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -56,13 +55,13 @@ public static class CustomGameModeManager
|
||||
|
||||
if (modeObj is not CustomGameMode gameMode)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Failed to create instance of {gameModeType.Name}");
|
||||
Error($"Failed to create instance of {gameModeType.Name}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (GameModes.Any(x => x.Key == gameMode.Id))
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"ID for gamemode {gameMode.Name} already exists!");
|
||||
Error($"ID for gamemode {gameMode.Name} already exists!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Roles;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.GameOptions;
|
||||
@@ -31,27 +34,42 @@ public abstract class AbstractOptionGroup
|
||||
/// Gets a value indicating whether the group should be shown in the modifiers menu.
|
||||
/// </summary>
|
||||
// TODO: make this not a boolean
|
||||
#pragma warning disable S1133
|
||||
[Obsolete("Use ParentMenu instead.")]
|
||||
#pragma warning restore S1133
|
||||
public virtual bool ShowInModifiersMenu => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating which menu the group is in.
|
||||
/// </summary>
|
||||
public virtual MenuCategory ParentMenu => MenuCategory.Game;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the function that determines whether the group should be visible or not.
|
||||
/// </summary>
|
||||
public virtual Func<bool> GroupVisible => () => true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the group color. This is used to color the group in the options menu.
|
||||
/// Gets the group <see cref="Color"/>. This is used to color the group in the options menu.
|
||||
/// </summary>
|
||||
public virtual Color GroupColor => MiraApiPlugin.DefaultHeaderColor;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the group priority. This is used to determine the order in which groups are displayed in the options menu.
|
||||
/// Zero is the highest priority, and the default value is the max uint value.
|
||||
/// Zero is the highest priority, and the default value is the max <see langword="uint"/> value.
|
||||
/// </summary>
|
||||
public virtual uint GroupPriority => uint.MaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default notification settings for the group.
|
||||
/// </summary>
|
||||
public virtual OptionNotifConfiguration Configuration => new(new Color(0.7333f, 0.7333f, 0.7333f, 1));
|
||||
|
||||
internal bool AllOptionsHidden { get; set; }
|
||||
|
||||
internal CategoryHeaderMasked? Header { get; set; }
|
||||
|
||||
internal bool Ready { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -62,4 +80,85 @@ public abstract class AbstractOptionGroup<T> : AbstractOptionGroup where T : IOp
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override Type OptionableType => typeof(T);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override MenuCategory ParentMenu
|
||||
{
|
||||
get
|
||||
{
|
||||
var type = typeof(T);
|
||||
if (type == typeof(BaseModifier))
|
||||
{
|
||||
return MenuCategory.Modifiers;
|
||||
}
|
||||
else if (type == typeof(RoleBehaviour))
|
||||
{
|
||||
return MenuCategory.Roles;
|
||||
}
|
||||
return MenuCategory.Game;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base class for option groups. An option group is a collection of options that are displayed together in the options menu.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The custom role that the group is for.</typeparam>
|
||||
public abstract class AbstractRoleOptionGroup<T>() : AbstractOptionGroup<T> where T : ICustomRole
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override Type OptionableType => typeof(T);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override MenuCategory ParentMenu => MenuCategory.Roles;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override OptionNotifConfiguration Configuration
|
||||
{
|
||||
get
|
||||
{
|
||||
var role = CustomRoleManager.CustomMiraRoles.FirstOrDefault(x => x.GetType() == OptionableType);
|
||||
if (role == null)
|
||||
{
|
||||
return new(new Color(0.7333f, 0.7333f, 0.7333f, 1));
|
||||
}
|
||||
return new(role.RoleColor, role.Configuration.IconTmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Menu categories for option groups.
|
||||
/// </summary>
|
||||
public enum MenuCategory
|
||||
{
|
||||
/// <summary>
|
||||
/// Placeholder for indexing purposes. Options don't exist in the presset tab.
|
||||
/// </summary>
|
||||
Preset,
|
||||
|
||||
/// <summary>
|
||||
/// Determines the option group is in the game settings tab.
|
||||
/// </summary>
|
||||
Game,
|
||||
|
||||
/// <summary>
|
||||
/// Determines the option group is in the role settings tab.
|
||||
/// </summary>
|
||||
Roles,
|
||||
|
||||
/// <summary>
|
||||
/// Determines the option group is in the modifier settings tab.
|
||||
/// </summary>
|
||||
Modifiers,
|
||||
|
||||
/// <summary>
|
||||
/// Determines the option group is in the first custom settings tab.
|
||||
/// </summary>
|
||||
CustomOne,
|
||||
|
||||
/// <summary>
|
||||
/// Determines the option group is in the second custom settings tab.
|
||||
/// </summary>
|
||||
CustomTwo,
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using MiraAPI.GameOptions.OptionTypes;
|
||||
namespace MiraAPI.GameOptions.Attributes;
|
||||
|
||||
/// <summary>
|
||||
/// Attribute for creating an enum option.
|
||||
/// Attribute for creating a <see cref="ModdedEnumOption"/>.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ModdedEnumOptionAttribute(string title, Type enumType, string[]? values = null)
|
||||
|
||||
@@ -6,7 +6,7 @@ using MiraAPI.Utilities;
|
||||
namespace MiraAPI.GameOptions.Attributes;
|
||||
|
||||
/// <summary>
|
||||
/// A number option attribute for the modded options system.
|
||||
/// Attribute for a <see cref="ModdedNumberOption"/>.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ModdedNumberOptionAttribute(
|
||||
@@ -21,7 +21,15 @@ public class ModdedNumberOptionAttribute(
|
||||
{
|
||||
internal override IModdedOption CreateOption(object? value, PropertyInfo property)
|
||||
{
|
||||
return new ModdedNumberOption(Title, (float)(value ?? min+increment), min, max, increment, suffixType, formatString, zeroInfinity);
|
||||
return new ModdedNumberOption(
|
||||
Title,
|
||||
(float)(value ?? min + increment),
|
||||
min,
|
||||
max,
|
||||
increment,
|
||||
suffixType,
|
||||
formatString,
|
||||
zeroInfinity);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Reflection;
|
||||
namespace MiraAPI.GameOptions.Attributes;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an attribute that is used to define a modded option.
|
||||
/// Represents an attribute that is used to define an <see cref="IModdedOption"/>.
|
||||
/// </summary>
|
||||
/// <param name="title">The option title.</param>
|
||||
/// <param name="roleType">Optional parameter to specify a role Type.</param>
|
||||
@@ -26,13 +26,13 @@ public abstract class ModdedOptionAttribute(string title, Type? roleType = null)
|
||||
/// <summary>
|
||||
/// Sets the value of the option.
|
||||
/// </summary>
|
||||
/// <param name="value">The new value as an object.</param>
|
||||
/// <param name="value">The new value as an <see langword="object"/>.</param>
|
||||
public abstract void SetValue(object value);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the option.
|
||||
/// </summary>
|
||||
/// <returns>The value of the option as an object.</returns>
|
||||
/// <returns>The value of the option as an <see langword="object"/>.</returns>
|
||||
public abstract object GetValue();
|
||||
|
||||
internal abstract IModdedOption? CreateOption(object? value, PropertyInfo property);
|
||||
|
||||
@@ -5,7 +5,7 @@ using MiraAPI.GameOptions.OptionTypes;
|
||||
namespace MiraAPI.GameOptions.Attributes;
|
||||
|
||||
/// <summary>
|
||||
/// Attribute for a toggle option.
|
||||
/// Attribute for a <see cref="ModdedToggleOption"/>.
|
||||
/// </summary>
|
||||
/// <param name="title">The option title.</param>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
|
||||
@@ -17,27 +17,37 @@ public interface IModdedOption
|
||||
uint Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the title of the option.
|
||||
/// Gets or sets the title of the option.
|
||||
/// </summary>
|
||||
string Title { get; }
|
||||
string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the StringName for the option, used for localization.
|
||||
/// Gets or sets the parent <see cref="AbstractOptionGroup"/> of the option.
|
||||
/// </summary>
|
||||
AbstractOptionGroup ParentGroup { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the notification settings for the option.
|
||||
/// </summary>
|
||||
OptionNotifConfiguration Configuration { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="StringNames"/> for the option, used for localization.
|
||||
/// </summary>
|
||||
StringNames StringName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the MiraPlugin that created this option.
|
||||
/// Gets or sets the <see cref="IMiraPlugin"/> that created this option.
|
||||
/// </summary>
|
||||
IMiraPlugin? ParentMod { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the game setting data for the option.
|
||||
/// Gets the <see cref="BaseGameSetting"/> for the option.
|
||||
/// </summary>
|
||||
BaseGameSetting Data { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the OptionBehaviour object of the option.
|
||||
/// Gets the <see cref="global::OptionBehaviour"/> object of the option.
|
||||
/// </summary>
|
||||
OptionBehaviour? OptionBehaviour { get; }
|
||||
|
||||
@@ -47,35 +57,60 @@ public interface IModdedOption
|
||||
Func<bool> Visible { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ConfigDefinition for the option, used for BepInEx configuration.
|
||||
/// Gets or sets a value indicating whether the option should be included with presets.
|
||||
/// </summary>
|
||||
bool IncludeInPreset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="BepInEx.Configuration.ConfigDefinition"/> for the option, used for BepInEx configuration.
|
||||
/// </summary>
|
||||
ConfigDefinition? ConfigDefinition { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates the option behaviour for the modded option.
|
||||
/// </summary>
|
||||
/// <param name="toggleOpt">The ToggleOption template.</param>
|
||||
/// <param name="numberOpt">The NumberOption template.</param>
|
||||
/// <param name="stringOpt">The StringOption template.</param>
|
||||
/// <param name="container">>The Transform container for the option.</param>
|
||||
/// <returns>>The created OptionBehaviour object.</returns>
|
||||
OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container);
|
||||
/// <param name="toggleOpt">The <see cref="ToggleOption"/> template.</param>
|
||||
/// <param name="numberOpt">The <see cref="NumberOption"/> template.</param>
|
||||
/// <param name="stringOpt">The <see cref="StringOption"/> template.</param>
|
||||
/// <param name="playerOpt">The <see cref="PlayerOption"/> template.</param>
|
||||
/// <param name="container">The <see cref="Transform"/> container for the option.</param>
|
||||
/// <returns>The created <see cref="global::OptionBehaviour"/> object.</returns>
|
||||
OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, PlayerOption playerOpt, Transform container);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value as a float.
|
||||
/// Gets the value as a <see langword="float"/>.
|
||||
/// </summary>
|
||||
/// <returns>>The value of the option as a float.</returns>
|
||||
/// <returns>The value of the option as a <see langword="float"/>.</returns>
|
||||
float GetFloatData();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the NetData for the option, used for network synchronization.
|
||||
/// Gets the <see cref="NetData"/> for the option, used for network synchronization.
|
||||
/// </summary>
|
||||
/// <returns>>Returns the NetData object for the option.</returns>
|
||||
/// <returns>Returns the <see cref="NetData"/> object for the option.</returns>
|
||||
NetData GetNetData();
|
||||
|
||||
/// <summary>
|
||||
/// Handles incoming network data for the option.
|
||||
/// </summary>
|
||||
/// <param name="data">>The byte array representing the network data.</param>
|
||||
/// <param name="data">The byte array representing the network data.</param>
|
||||
void HandleNetData(byte[] data);
|
||||
|
||||
/// <summary>
|
||||
/// Saves the option to a preset configuration file.
|
||||
/// </summary>
|
||||
/// <param name="presetConfig">The <see cref="ConfigFile"/> representing the preset configuration.</param>
|
||||
/// <param name="saveDefault">Indicates whether to save the default value instead of the current value.</param>
|
||||
void SaveToPreset(ConfigFile presetConfig, bool saveDefault = false);
|
||||
|
||||
/// <summary>
|
||||
/// Binds the option to a configuration file.
|
||||
/// </summary>
|
||||
/// <param name="config">The <see cref="ConfigFile"/> to bind the option to.</param>
|
||||
void Bind(ConfigFile config);
|
||||
|
||||
/// <summary>
|
||||
/// Loads the option from a preset configuration file, applying the values to the option's configuration.
|
||||
/// </summary>
|
||||
/// <param name="presetConfig">The <see cref="ConfigFile"/> representing the preset configuration.</param>
|
||||
void LoadFromPreset(ConfigFile presetConfig);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.GameOptions;
|
||||
|
||||
/// <summary>
|
||||
/// Component added onto options generated via MiraAPI. This allows developers to hook patches onto options in general, without using a list.
|
||||
/// </summary>
|
||||
[RegisterInIl2Cpp]
|
||||
public class MiraNumberOptionComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="ModdedNumberOption"/> associated with the object.
|
||||
/// </summary>
|
||||
[HideFromIl2Cpp]
|
||||
public ModdedNumberOption NumberOption { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default increment.
|
||||
/// </summary>
|
||||
public float DefaultIncrement { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether holding shift will split the increment in half.
|
||||
/// </summary>
|
||||
public bool ShiftIncrementToggle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating what Zero displays.
|
||||
/// </summary>
|
||||
public string ZeroValue { get; set; } = "#";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating what Negative One displays.
|
||||
/// </summary>
|
||||
public string NegativeValue { get; set; } = "#";
|
||||
}
|
||||
@@ -1,32 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameOptions.Attributes;
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Networking.Rpc;
|
||||
using Reactor.Utilities;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.GameOptions;
|
||||
|
||||
/// <summary>
|
||||
/// Handles modded options.
|
||||
/// Handles <see cref="IModdedOption"/>s.
|
||||
/// </summary>
|
||||
public static class ModdedOptionsManager
|
||||
{
|
||||
private static readonly Dictionary<PropertyInfo, ModdedOptionAttribute> OptionAttributes = [];
|
||||
private static readonly Dictionary<Type, AbstractOptionGroup> TypeToGroup = [];
|
||||
|
||||
internal static readonly Dictionary<OptionBehaviour, ModdedPlayerOption> CreatedPlayerOptions = [];
|
||||
internal static readonly Dictionary<uint, IModdedOption> ModdedOptions = [];
|
||||
internal static readonly List<AbstractOptionGroup> Groups = [];
|
||||
|
||||
internal static uint NextId => _nextId++;
|
||||
private static uint _nextId = 1;
|
||||
|
||||
public static void AddSettingsChangeMessage(NotificationPopper notif, StringNames key, string value, Color textColor, TMP_SpriteAsset? sprite, bool playSound = true)
|
||||
{
|
||||
var item = string.Empty;
|
||||
var text = textColor.ToTextColor();
|
||||
if (sprite != null)
|
||||
{
|
||||
item = TranslationController.Instance.GetString(
|
||||
StringNames.LobbyChangeSettingNotification,
|
||||
string.Concat(
|
||||
"<sprite name=\"",
|
||||
sprite.name,
|
||||
"\"><font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">",
|
||||
text,
|
||||
TranslationController.Instance.GetString(key),
|
||||
"</color></font>"),
|
||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">" + value + "</font>"
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
item = TranslationController.Instance.GetString(
|
||||
StringNames.LobbyChangeSettingNotification,
|
||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">" +
|
||||
text +
|
||||
TranslationController.Instance.GetString(key) + "</color></font>",
|
||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">" + value + "</font>");
|
||||
}
|
||||
notif.SettingsChangeMessageLogic(key, item, playSound);
|
||||
}
|
||||
|
||||
internal static bool RegisterGroup(Type type, MiraPluginInfo pluginInfo)
|
||||
{
|
||||
if (Activator.CreateInstance(type) is not AbstractOptionGroup group)
|
||||
@@ -36,13 +71,13 @@ public static class ModdedOptionsManager
|
||||
|
||||
if (TypeToGroup.ContainsKey(type))
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Group {type.Name} already exists.");
|
||||
Error($"Group {type.Name} already exists.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Groups.Add(group);
|
||||
TypeToGroup.Add(type, group);
|
||||
pluginInfo.OptionGroups.Add(group);
|
||||
pluginInfo.InternalOptionGroups.Add(group);
|
||||
|
||||
typeof(OptionGroupSingleton<>).MakeGenericType(type)
|
||||
#pragma warning disable S3011
|
||||
@@ -57,13 +92,13 @@ public static class ModdedOptionsManager
|
||||
{
|
||||
if (!TypeToGroup.TryGetValue(type, out var group))
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Failed to get group for {type.Name}");
|
||||
Error($"Failed to get group for {type.Name}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (property.GetValue(group) is not IModdedOption option)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Failed to get option for {property.Name}");
|
||||
Error($"Failed to get option for {property.Name}");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -78,13 +113,13 @@ public static class ModdedOptionsManager
|
||||
{
|
||||
if (OptionAttributes.ContainsKey(property))
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Property {property.Name} already has an attribute registered.");
|
||||
Error($"Property {property.Name} already has an attribute registered.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TypeToGroup.TryGetValue(type, out var group))
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Failed to get group for {type.Name}");
|
||||
Error($"Failed to get group for {type.Name}");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -92,7 +127,7 @@ public static class ModdedOptionsManager
|
||||
|
||||
if (option == null)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Failed to get option for {property.Name}");
|
||||
Error($"Failed to get option for {property.Name}");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -120,8 +155,9 @@ public static class ModdedOptionsManager
|
||||
|
||||
option.ConfigDefinition = new ConfigDefinition(groupName, propertyName);
|
||||
|
||||
option.ParentGroup = group;
|
||||
option.ParentMod = pluginInfo.MiraPlugin;
|
||||
pluginInfo.Options.Add(option);
|
||||
pluginInfo.InternalOptions.Add(option);
|
||||
ModdedOptions.Add(option.Id, option);
|
||||
group.Options.Add(option);
|
||||
}
|
||||
@@ -142,7 +178,7 @@ public static class ModdedOptionsManager
|
||||
// we dont know how other plugins handle their configs
|
||||
// this way, all the options are saved at once, instead of one by one
|
||||
var oldConfigSetting = new Dictionary<MiraPluginInfo, bool>();
|
||||
foreach (var plugin in MiraPluginManager.Instance.RegisteredPlugins())
|
||||
foreach (var plugin in MiraPluginManager.Instance.RegisteredPlugins)
|
||||
{
|
||||
oldConfigSetting.Add(plugin, plugin.PluginConfig.SaveOnConfigSet);
|
||||
plugin.PluginConfig.SaveOnConfigSet = false;
|
||||
@@ -158,7 +194,7 @@ public static class ModdedOptionsManager
|
||||
option.HandleNetData(netData.Data);
|
||||
}
|
||||
|
||||
foreach (var plugin in MiraPluginManager.Instance.RegisteredPlugins())
|
||||
foreach (var plugin in MiraPluginManager.Instance.RegisteredPlugins)
|
||||
{
|
||||
plugin.PluginConfig.Save();
|
||||
plugin.PluginConfig.SaveOnConfigSet = oldConfigSetting[plugin];
|
||||
@@ -175,7 +211,10 @@ public static class ModdedOptionsManager
|
||||
/// </summary>
|
||||
/// <param name="__originalMethod">The original setter method.</param>
|
||||
/// <param name="value">The new object value.</param>
|
||||
#pragma warning disable CA1707
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Harmony naming convention")]
|
||||
public static void PropertySetterPatch(MethodBase __originalMethod, object value)
|
||||
#pragma warning restore CA1707
|
||||
{
|
||||
var attribute = OptionAttributes.First(pair => pair.Key.GetSetMethod() == __originalMethod).Value;
|
||||
attribute.SetValue(value);
|
||||
@@ -186,8 +225,11 @@ public static class ModdedOptionsManager
|
||||
/// </summary>
|
||||
/// <param name="__originalMethod">The original getter method.</param>
|
||||
/// <param name="__result">The result of the property getter.</param>
|
||||
/// <returns>False so the original getter gets skipped.</returns>
|
||||
/// <returns><see langword="false"/> so the original getter gets skipped.</returns>
|
||||
#pragma warning disable CA1707
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Harmony naming convention")]
|
||||
public static bool PropertyGetterPatch(MethodBase __originalMethod, ref object __result)
|
||||
#pragma warning restore CA1707
|
||||
{
|
||||
var attribute = OptionAttributes.First(pair => pair.Key.GetGetMethod() == __originalMethod).Value;
|
||||
__result = attribute.GetValue();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace MiraAPI.GameOptions;
|
||||
|
||||
/// <summary>
|
||||
/// Singleton for option groups.
|
||||
/// Singleton for <see cref="AbstractOptionGroup"/>s.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The option group type.</typeparam>
|
||||
public static class OptionGroupSingleton<T> where T : AbstractOptionGroup
|
||||
@@ -11,7 +11,7 @@ public static class OptionGroupSingleton<T> where T : AbstractOptionGroup
|
||||
private static T? _instance;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance of the option group.
|
||||
/// Gets the instance of the <typeparamref name="T"/> group.
|
||||
/// </summary>
|
||||
#pragma warning disable CA1000
|
||||
public static T Instance => _instance ??= ModdedOptionsManager.Groups.OfType<T>().Single();
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
namespace MiraAPI.GameOptions;
|
||||
|
||||
/// <summary>
|
||||
/// Used to configure the specific visuals for option notifications.
|
||||
/// </summary>
|
||||
public record struct OptionNotifConfiguration
|
||||
{
|
||||
#pragma warning disable S1133
|
||||
[Obsolete("Default constructor is not supported")]
|
||||
#pragma warning restore S1133
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
public OptionNotifConfiguration()
|
||||
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
|
||||
{
|
||||
throw new NotImplementedException("Default constructor is not supported.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="OptionNotifConfiguration"/> struct based on a group.
|
||||
/// </summary>
|
||||
/// <param name="group">The <see cref="AbstractOptionGroup"/> in which you are configuring.</param>
|
||||
public OptionNotifConfiguration(AbstractOptionGroup group)
|
||||
{
|
||||
PopUpIconTmp = group.Configuration.PopUpIconTmp;
|
||||
PopUpTextColor = group.Configuration.PopUpTextColor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="OptionNotifConfiguration"/> struct from scratch.
|
||||
/// </summary>
|
||||
/// <param name="color">The text <see cref="Color"/> for the configuration.</param>
|
||||
/// <param name="asset">The <see cref="TMP_SpriteAsset"/> icon for the configuration.</param>
|
||||
public OptionNotifConfiguration(Color color, TMP_SpriteAsset asset = null!)
|
||||
{
|
||||
PopUpIconTmp = asset;
|
||||
PopUpTextColor = color;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="TMP_SpriteAsset"/> for the icon on the options pop-up.
|
||||
/// </summary>
|
||||
public TMP_SpriteAsset PopUpIconTmp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="Color"/> for the text on the options pop-up.
|
||||
/// </summary>
|
||||
[HideFromIl2Cpp]
|
||||
public Color PopUpTextColor { get; set; }
|
||||
}
|
||||
@@ -11,23 +11,24 @@ using Object = UnityEngine.Object;
|
||||
namespace MiraAPI.GameOptions.OptionTypes;
|
||||
|
||||
/// <summary>
|
||||
/// An option for selecting an enum value.
|
||||
/// An option for selecting an <see langword="enum"/> value.
|
||||
/// </summary>
|
||||
public class ModdedEnumOption : ModdedOption<int>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the string values of the enum.
|
||||
/// </summary>
|
||||
public string[]? Values { get; }
|
||||
public string[] Values { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ModdedEnumOption"/> class.
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the option.</param>
|
||||
/// <param name="defaultValue">The default value as an int.</param>
|
||||
/// <param name="enumType">The Enum type.</param>
|
||||
/// <param name="values">An option list of string values to use in place of the enum name.</param>
|
||||
public ModdedEnumOption(string title, int defaultValue, Type enumType, string[]? values = null) : base(title, defaultValue)
|
||||
/// <param name="enumType">The <see cref="Enum"/> type.</param>
|
||||
/// <param name="values">An option list of string values to use in place of the <see langword="enum"/> name.</param>
|
||||
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
||||
public ModdedEnumOption(string title, int defaultValue, Type enumType, string[]? values = null, bool includeInPreset=true) : base(title, defaultValue, includeInPreset)
|
||||
{
|
||||
Values = values ?? Enum.GetNames(enumType);
|
||||
Data = ScriptableObject.CreateInstance<StringGameSetting>();
|
||||
@@ -37,15 +38,17 @@ public class ModdedEnumOption : ModdedOption<int>
|
||||
data.Type = global::OptionTypes.String;
|
||||
data.Values = values is null ?
|
||||
Enum.GetNames(enumType).Select(CustomStringName.CreateAndRegister).ToArray()
|
||||
: values.Select(CustomStringName.CreateAndRegister).ToArray();
|
||||
: [.. values.Select(CustomStringName.CreateAndRegister)];
|
||||
|
||||
data.Index = Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container)
|
||||
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, PlayerOption playerOpt, Transform container)
|
||||
{
|
||||
var stringOption = Object.Instantiate(stringOpt, container);
|
||||
stringOption.name =
|
||||
$"{ParentMod!.OptionsTitleText}.EnumOption.{TranslationController.Instance.GetString(StringName)}";
|
||||
|
||||
stringOption.SetUpFromData(Data, 20);
|
||||
stringOption.OnValueChanged = (Il2CppSystem.Action<OptionBehaviour>)ValueChanged;
|
||||
@@ -87,7 +90,13 @@ public class ModdedEnumOption : ModdedOption<int>
|
||||
/// <inheritdoc />
|
||||
protected override void OnValueChanged(int newValue)
|
||||
{
|
||||
HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, Data?.GetValueString(newValue), false);
|
||||
ModdedOptionsManager.AddSettingsChangeMessage(
|
||||
HudManager.Instance.Notifier,
|
||||
StringName,
|
||||
Data.GetValueString(newValue),
|
||||
Configuration.PopUpTextColor,
|
||||
Configuration.PopUpIconTmp,
|
||||
false);
|
||||
if (!OptionBehaviour)
|
||||
{
|
||||
return;
|
||||
@@ -101,23 +110,24 @@ public class ModdedEnumOption : ModdedOption<int>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An option for selecting an enum value.
|
||||
/// An option for selecting an <see langword="enum"/> value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The enum type.</typeparam>
|
||||
/// <typeparam name="T">The <see cref="Enum"/> type.</typeparam>
|
||||
public class ModdedEnumOption<T> : ModdedOption<T> where T : Enum
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the string values of the enum.
|
||||
/// Gets the string values of the <see langword="enum"/>.
|
||||
/// </summary>
|
||||
public string[]? Values { get; }
|
||||
public string[] Values { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ModdedEnumOption{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the option.</param>
|
||||
/// <param name="defaultValue">The default value as an int.</param>
|
||||
/// <param name="values">An option list of string values to use in place of the enum name.</param>
|
||||
public ModdedEnumOption(string title, T defaultValue, string[]? values = null) : base(title, defaultValue)
|
||||
/// <param name="defaultValue">The default value as an <see langword="int"/>.</param>
|
||||
/// <param name="values">An option list of string values to use in place of the <see langword="enum"/> name.</param>
|
||||
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
||||
public ModdedEnumOption(string title, T defaultValue, string[]? values = null, bool includeInPreset=true) : base(title, defaultValue, includeInPreset)
|
||||
{
|
||||
Values = values ?? Enum.GetNames(typeof(T));
|
||||
Data = ScriptableObject.CreateInstance<StringGameSetting>();
|
||||
@@ -127,15 +137,17 @@ public class ModdedEnumOption<T> : ModdedOption<T> where T : Enum
|
||||
data.Type = global::OptionTypes.String;
|
||||
data.Values = values is null ?
|
||||
Enum.GetNames(typeof(T)).Select(CustomStringName.CreateAndRegister).ToArray()
|
||||
: values.Select(CustomStringName.CreateAndRegister).ToArray();
|
||||
: [.. values.Select(CustomStringName.CreateAndRegister)];
|
||||
|
||||
data.Index = Convert.ToInt32(Value, NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container)
|
||||
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, PlayerOption playerOpt, Transform container)
|
||||
{
|
||||
var stringOption = Object.Instantiate(stringOpt, container);
|
||||
stringOption.name =
|
||||
$"{ParentMod!.OptionsTitleText}.EnumOption.{TranslationController.Instance.GetString(StringName)}";
|
||||
|
||||
stringOption.SetUpFromData(Data, 20);
|
||||
stringOption.OnValueChanged = (Il2CppSystem.Action<OptionBehaviour>)ValueChanged;
|
||||
@@ -177,7 +189,13 @@ public class ModdedEnumOption<T> : ModdedOption<T> where T : Enum
|
||||
/// <inheritdoc />
|
||||
protected override void OnValueChanged(T newValue)
|
||||
{
|
||||
HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, Data.GetValueString(Convert.ToInt32(newValue, NumberFormatInfo.InvariantInfo)), false);
|
||||
ModdedOptionsManager.AddSettingsChangeMessage(
|
||||
HudManager.Instance.Notifier,
|
||||
StringName,
|
||||
Data.GetValueString(Convert.ToInt32(newValue, NumberFormatInfo.InvariantInfo)),
|
||||
Configuration.PopUpTextColor,
|
||||
Configuration.PopUpIconTmp,
|
||||
false);
|
||||
if (!OptionBehaviour)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -32,10 +32,82 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
/// </summary>
|
||||
public MiraNumberSuffixes SuffixType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating what zero appears as.
|
||||
/// </summary>
|
||||
public string ZeroWordValue { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating what a negative one appears as.
|
||||
/// </summary>
|
||||
public string NegativeWordValue { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether zero is infinity.
|
||||
/// </summary>
|
||||
public bool ZeroInfinity { get; }
|
||||
public bool ZeroInfinity => ZeroWordValue == "∞";
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether holding shift will divide the increment.
|
||||
/// </summary>
|
||||
public bool ShiftIncrement { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ModdedNumberOption"/> class.
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the option.</param>
|
||||
/// <param name="defaultValue">The default value as a float.</param>
|
||||
/// <param name="min">The minimum value.</param>
|
||||
/// <param name="max">The maximum value.</param>
|
||||
/// <param name="increment">The increment.</param>
|
||||
/// <param name="suffixType">The suffix type.</param>
|
||||
/// <param name="formatString">Optional format string for the option screen.</param>
|
||||
/// <param name="zeroBehavior">Determines what is shown for zero. Options: ∞, #, or a word value (such as Off).</param>
|
||||
/// <param name="negativeBehavior">Determines what is shown for negative 1. Options: ∞, #, or a word value (such as Off).</param>
|
||||
/// <param name="halfIncrements">Whether increments can be split in half.</param>
|
||||
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
||||
public ModdedNumberOption(
|
||||
string title,
|
||||
float defaultValue,
|
||||
float min,
|
||||
float max,
|
||||
float increment,
|
||||
string zeroBehavior,
|
||||
string negativeBehavior,
|
||||
MiraNumberSuffixes suffixType,
|
||||
string? formatString = null,
|
||||
bool halfIncrements = false,
|
||||
bool includeInPreset = true) : base(title, defaultValue, includeInPreset)
|
||||
{
|
||||
Min = min;
|
||||
Max = max;
|
||||
Increment = increment;
|
||||
SuffixType = suffixType;
|
||||
ZeroWordValue = zeroBehavior;
|
||||
NegativeWordValue = negativeBehavior;
|
||||
ShiftIncrement = halfIncrements;
|
||||
|
||||
Value = Mathf.Clamp(defaultValue, min, max);
|
||||
|
||||
Data = ScriptableObject.CreateInstance<FloatGameSetting>();
|
||||
|
||||
var data = (FloatGameSetting)Data;
|
||||
data.Type = global::OptionTypes.Float;
|
||||
data.Title = StringName;
|
||||
data.Value = Value;
|
||||
data.Increment = Increment;
|
||||
data.ValidRange = new FloatRange(Min, Max);
|
||||
data.FormatString = formatString ??
|
||||
(defaultValue.IsInteger() &&
|
||||
Increment.IsInteger() &&
|
||||
Value.IsInteger() &&
|
||||
Min.IsInteger() &&
|
||||
Max.IsInteger() ? "0" : "0.0");
|
||||
|
||||
data.ZeroIsInfinity = ZeroInfinity;
|
||||
data.SuffixType = (NumberSuffixes)SuffixType;
|
||||
data.OptionName = FloatOptionNames.Invalid;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ModdedNumberOption"/> class.
|
||||
@@ -48,6 +120,7 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
/// <param name="suffixType">The suffix type.</param>
|
||||
/// <param name="formatString">Optional format string for the option screen.</param>
|
||||
/// <param name="zeroInfinity">Whether zero is infinity or not.</param>
|
||||
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
||||
public ModdedNumberOption(
|
||||
string title,
|
||||
float defaultValue,
|
||||
@@ -56,13 +129,16 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
float increment,
|
||||
MiraNumberSuffixes suffixType,
|
||||
string? formatString = null,
|
||||
bool zeroInfinity = false) : base(title, defaultValue)
|
||||
bool zeroInfinity = false,
|
||||
bool includeInPreset = true) : base(title, defaultValue, includeInPreset)
|
||||
{
|
||||
Min = min;
|
||||
Max = max;
|
||||
Increment = increment;
|
||||
SuffixType = suffixType;
|
||||
ZeroInfinity = zeroInfinity;
|
||||
ZeroWordValue = zeroInfinity ? "∞" : "#";
|
||||
NegativeWordValue = "#";
|
||||
ShiftIncrement = increment != 1f;
|
||||
|
||||
Value = Mathf.Clamp(defaultValue, min, max);
|
||||
|
||||
@@ -91,9 +167,18 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
ToggleOption toggleOpt,
|
||||
NumberOption numberOpt,
|
||||
StringOption stringOpt,
|
||||
PlayerOption playerOpt,
|
||||
Transform container)
|
||||
{
|
||||
var numberOption = Object.Instantiate(numberOpt, Vector3.zero, Quaternion.identity, container);
|
||||
numberOption.name =
|
||||
$"{ParentMod!.OptionsTitleText}.NumberOption.{TranslationController.Instance.GetString(StringName)}";
|
||||
var optionComponent = numberOption.gameObject.AddComponent<MiraNumberOptionComponent>();
|
||||
optionComponent.NumberOption = this;
|
||||
optionComponent.DefaultIncrement = Increment;
|
||||
optionComponent.ShiftIncrementToggle = ShiftIncrement;
|
||||
optionComponent.NegativeValue = NegativeWordValue;
|
||||
optionComponent.ZeroValue = ZeroWordValue;
|
||||
|
||||
numberOption.SetUpFromData(Data, 20);
|
||||
numberOption.OnValueChanged = (Il2CppSystem.Action<OptionBehaviour>)ValueChanged;
|
||||
@@ -140,9 +225,12 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
protected override void OnValueChanged(float newValue)
|
||||
{
|
||||
Value = Mathf.Clamp(newValue, Min, Max);
|
||||
HudManager.Instance.Notifier.AddSettingsChangeMessage(
|
||||
ModdedOptionsManager.AddSettingsChangeMessage(
|
||||
HudManager.Instance.Notifier,
|
||||
StringName,
|
||||
Data.GetValueString(Value),
|
||||
Data.GetValueString(newValue),
|
||||
Configuration.PopUpTextColor,
|
||||
Configuration.PopUpIconTmp,
|
||||
false);
|
||||
|
||||
if (OptionBehaviour is NumberOption opt)
|
||||
@@ -152,7 +240,7 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts the option to an int.
|
||||
/// Implicitly converts the option to an <see langword="int"/>.
|
||||
/// </summary>
|
||||
/// <param name="option">The option.</param>
|
||||
/// <returns>Integer value.</returns>
|
||||
|
||||
@@ -16,29 +16,19 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
{
|
||||
private IMiraPlugin? _parentMod;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique identifier of the option.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public uint Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the title of the option.
|
||||
/// </summary>
|
||||
public string Title { get; }
|
||||
/// <inheritdoc />
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the StringName object of the option.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public StringNames StringName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the BaseGameSetting data of the option.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public BaseGameSetting Data { get; protected set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the parent mod of the option.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public IMiraPlugin? ParentMod
|
||||
{
|
||||
get => _parentMod;
|
||||
@@ -46,6 +36,7 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
{
|
||||
if (_parentMod != null || value == null) return;
|
||||
_parentMod = value;
|
||||
|
||||
var entry = _parentMod.GetConfigFile().Bind(ConfigDefinition, DefaultValue);
|
||||
Value = entry.Value;
|
||||
}
|
||||
@@ -66,19 +57,16 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
/// </summary>
|
||||
public Action<T>? ChangedEvent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the visibility of the option.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public Func<bool> Visible { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the option behaviour of the option.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public bool IncludeInPreset { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public OptionBehaviour? OptionBehaviour { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the config definition of the option.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public ConfigDefinition? ConfigDefinition { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -86,7 +74,8 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
/// </summary>
|
||||
/// <param name="title">The option title.</param>
|
||||
/// <param name="defaultValue">The default value.</param>
|
||||
protected ModdedOption(string title, T defaultValue)
|
||||
/// <param name="includeInPreset">Whether to include the option in the preset.</param>
|
||||
protected ModdedOption(string title, T defaultValue, bool includeInPreset = true)
|
||||
{
|
||||
Id = ModdedOptionsManager.NextId;
|
||||
Title = title;
|
||||
@@ -94,6 +83,7 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
Value = defaultValue;
|
||||
StringName = CustomStringName.CreateAndRegister(Title);
|
||||
Visible = () => true;
|
||||
IncludeInPreset = includeInPreset;
|
||||
}
|
||||
|
||||
internal void ValueChanged(OptionBehaviour optionBehaviour)
|
||||
@@ -105,7 +95,8 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
/// Sets the value of the option.
|
||||
/// </summary>
|
||||
/// <param name="newValue">The new value.</param>
|
||||
public void SetValue(T newValue)
|
||||
/// <param name="sendRpc">Whether to send the value to other players.</param>
|
||||
public void SetValue(T newValue, bool sendRpc = true)
|
||||
{
|
||||
var oldVal = Value;
|
||||
Value = newValue;
|
||||
@@ -115,35 +106,57 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
ChangedEvent?.Invoke(Value);
|
||||
}
|
||||
|
||||
if (AmongUsClient.Instance.AmHost)
|
||||
if (sendRpc && AmongUsClient.Instance.AmHost)
|
||||
{
|
||||
if (ParentMod?.GetConfigFile().TryGetEntry<T>(ConfigDefinition, out var entry) == true)
|
||||
{
|
||||
entry.Value = Value;
|
||||
}
|
||||
|
||||
Rpc<SyncOptionsRpc>.Instance.Send(PlayerControl.LocalPlayer, [GetNetData()]);
|
||||
Rpc<SyncOptionsRpc>.Instance.Send(PlayerControl.LocalPlayer, [GetNetData()], true);
|
||||
}
|
||||
|
||||
OnValueChanged(newValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the float data of the option.
|
||||
/// </summary>
|
||||
/// <returns>A float object representing the option's value.</returns>
|
||||
/// <inheritdoc />
|
||||
public void SaveToPreset(ConfigFile presetConfig, bool saveDefault=false)
|
||||
{
|
||||
if (ConfigDefinition is null)
|
||||
{
|
||||
Error($"Attempted to save {Title} to preset, but ConfigDefinition is null.");
|
||||
return;
|
||||
}
|
||||
Bind(presetConfig);
|
||||
presetConfig[ConfigDefinition].BoxedValue = saveDefault ? DefaultValue : Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Bind(ConfigFile config)
|
||||
{
|
||||
config.Bind(ConfigDefinition, DefaultValue);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void LoadFromPreset(ConfigFile presetConfig)
|
||||
{
|
||||
if (presetConfig.TryGetEntry(ConfigDefinition, out ConfigEntry<T> entry))
|
||||
{
|
||||
SetValue(entry.Value, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Error($"Attempted to load {Title} from preset, but ConfigDefinition is not found in preset.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract float GetFloatData();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the net data of the option.
|
||||
/// </summary>
|
||||
/// <returns>A NetData object representing this option's data.</returns>
|
||||
/// <inheritdoc />
|
||||
public abstract NetData GetNetData();
|
||||
|
||||
/// <summary>
|
||||
/// Handles incoming net data.
|
||||
/// </summary>
|
||||
/// <param name="data">The NetData's byte array.</param>
|
||||
/// <inheritdoc />
|
||||
public abstract void HandleNetData(byte[] data);
|
||||
|
||||
/// <summary>
|
||||
@@ -159,18 +172,12 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
/// <returns>The value.</returns>
|
||||
public abstract T GetValueFromOptionBehaviour(OptionBehaviour optionBehaviour);
|
||||
|
||||
/// <summary>
|
||||
/// Creates the option behaviour.
|
||||
/// </summary>
|
||||
/// <param name="toggleOpt">The ToggleOption prefab.</param>
|
||||
/// <param name="numberOpt">The NumberOption prefab.</param>
|
||||
/// <param name="stringOpt">The StringOption prefab.</param>
|
||||
/// <param name="container">The options container.</param>
|
||||
/// <returns>A new OptionBehaviour for this modded option.</returns>
|
||||
/// <inheritdoc />
|
||||
public abstract OptionBehaviour CreateOption(
|
||||
ToggleOption toggleOpt,
|
||||
NumberOption numberOpt,
|
||||
StringOption stringOpt,
|
||||
PlayerOption playerOpt,
|
||||
Transform container);
|
||||
|
||||
/// <summary>
|
||||
@@ -182,4 +189,10 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
{
|
||||
return option.Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public AbstractOptionGroup ParentGroup { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual OptionNotifConfiguration Configuration => new(ParentGroup);
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Il2CppSystem.Collections.Generic;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.Utilities;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.GameOptions.OptionTypes;
|
||||
|
||||
/// <summary>
|
||||
/// An option for selecting an ingame player. It returns an index of the values list, NOT A PLAYER ID. To get a player out of this, index the <see cref="Values"/> list.
|
||||
/// </summary>
|
||||
public class ModdedPlayerOption : ModdedOption<int>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the included players.
|
||||
/// </summary>
|
||||
public List<NetworkedPlayerInfo> Values { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a filter for the players included in the option.
|
||||
/// </summary>
|
||||
public Func<NetworkedPlayerInfo, bool>? PlayerFilter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the option includes a "None" option. If None is selected, value will return -1.
|
||||
/// </summary>
|
||||
public bool AllowNone { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ModdedPlayerOption"/> class.
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the option.</param>
|
||||
/// <param name="allowNone">Whether the option includes a none option. If None is selected, value will return -1.</param>
|
||||
public ModdedPlayerOption(string title, bool allowNone = true) : base(title, allowNone ? -1 : 0, false)
|
||||
{
|
||||
Data = ScriptableObject.CreateInstance<PlayerSelectionGameSetting>();
|
||||
var data = (PlayerSelectionGameSetting)Data;
|
||||
|
||||
data.Title = StringName;
|
||||
data.Type = global::OptionTypes.Player;
|
||||
|
||||
Values = new List<NetworkedPlayerInfo>();
|
||||
AllowNone = allowNone;
|
||||
Value = DefaultValue;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override OptionBehaviour CreateOption(
|
||||
ToggleOption toggleOpt,
|
||||
NumberOption numberOpt,
|
||||
StringOption stringOpt,
|
||||
PlayerOption playerOpt,
|
||||
Transform container)
|
||||
{
|
||||
var playerOption = Object.Instantiate(playerOpt, container);
|
||||
playerOption.name =
|
||||
$"{ParentMod!.OptionsTitleText}.PlayerOption.{TranslationController.Instance.GetString(StringName)}";
|
||||
|
||||
var filteredList = GetFilteredPlayers();
|
||||
Values = filteredList.ToIl2CppList();
|
||||
|
||||
playerOption.SetUpFromData(Data, 20);
|
||||
playerOption.OnValueChanged = (Il2CppSystem.Action<OptionBehaviour>)ValueChanged;
|
||||
|
||||
playerOption.Title = StringName;
|
||||
playerOption.TitleText.text = TranslationController.Instance.GetString(StringName);
|
||||
playerOption.Values = Values;
|
||||
playerOption.Value = Value;
|
||||
playerOption.playerIndex = filteredList.FindIndex(p => p.PlayerId == Value);
|
||||
|
||||
OptionBehaviour = playerOption;
|
||||
ModdedOptionsManager.CreatedPlayerOptions.TryAdd(playerOption, this);
|
||||
|
||||
playerOption.SetValueText();
|
||||
playerOption.AdjustButtonsActiveState();
|
||||
|
||||
return playerOption;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a player ran through the filter.
|
||||
/// </summary>
|
||||
/// <returns>A list of filtered players.</returns>
|
||||
public System.Collections.Generic.List<NetworkedPlayerInfo> GetFilteredPlayers()
|
||||
{
|
||||
return GameData.Instance.AllPlayers.ToArray()
|
||||
.Where(x => PlayerFilter?.Invoke(x) ?? true)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a player from the value. If <see cref="AllowNone"/> is enabled and none is enabled this will return <see langword="null"/>.
|
||||
/// </summary>
|
||||
/// <returns>A player or <see langword="null"/> if chosen none.</returns>
|
||||
public NetworkedPlayerInfo? GetPlayerValue()
|
||||
{
|
||||
return Value < 0 ? null : Values[Value];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override float GetFloatData()
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override NetData GetNetData()
|
||||
{
|
||||
return new NetData(Id, BitConverter.GetBytes(Value));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void HandleNetData(byte[] data)
|
||||
{
|
||||
SetValue(BitConverter.ToInt32(data));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int GetValueFromOptionBehaviour(OptionBehaviour optionBehaviour)
|
||||
{
|
||||
return optionBehaviour.GetInt();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnValueChanged(int newValue)
|
||||
{
|
||||
ModdedOptionsManager.AddSettingsChangeMessage(
|
||||
HudManager.Instance.Notifier,
|
||||
StringName,
|
||||
Data.GetValueString(newValue),
|
||||
Configuration.PopUpTextColor,
|
||||
Configuration.PopUpIconTmp,
|
||||
false);
|
||||
if (!OptionBehaviour)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (OptionBehaviour is PlayerOption opt)
|
||||
{
|
||||
opt.Value = newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,8 @@ public class ModdedToggleOption : ModdedOption<bool>
|
||||
/// </summary>
|
||||
/// <param name="title">The option title.</param>
|
||||
/// <param name="defaultValue">The default value.</param>
|
||||
public ModdedToggleOption(string title, bool defaultValue) : base(title, defaultValue)
|
||||
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
||||
public ModdedToggleOption(string title, bool defaultValue, bool includeInPreset=true) : base(title, defaultValue, includeInPreset)
|
||||
{
|
||||
Data = ScriptableObject.CreateInstance<CheckboxGameSetting>();
|
||||
|
||||
@@ -25,9 +26,11 @@ public class ModdedToggleOption : ModdedOption<bool>
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container)
|
||||
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, PlayerOption playerOpt, Transform container)
|
||||
{
|
||||
var toggleOption = Object.Instantiate(toggleOpt, Vector3.zero, Quaternion.identity, container);
|
||||
toggleOption.name =
|
||||
$"{ParentMod!.OptionsTitleText}.ToggleOption.{TranslationController.Instance.GetString(StringName)}";
|
||||
|
||||
toggleOption.SetUpFromData(Data, 20);
|
||||
|
||||
@@ -68,7 +71,13 @@ public class ModdedToggleOption : ModdedOption<bool>
|
||||
/// <inheritdoc />
|
||||
protected override void OnValueChanged(bool newValue)
|
||||
{
|
||||
HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, newValue ? "On" : "Off", false);
|
||||
ModdedOptionsManager.AddSettingsChangeMessage(
|
||||
HudManager.Instance.Notifier,
|
||||
StringName,
|
||||
newValue ? "On" : "Off",
|
||||
Configuration.PopUpTextColor,
|
||||
Configuration.PopUpIconTmp,
|
||||
false);
|
||||
if (!OptionBehaviour)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
/// <summary>
|
||||
/// The location of the custom button on the screen.
|
||||
/// The location of the <see cref="CustomActionButton"/> on the screen.
|
||||
/// </summary>
|
||||
public enum ButtonLocation
|
||||
{
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
/// <summary>
|
||||
/// The uses mode for <see cref="CustomActionButton"/>s.
|
||||
/// </summary>
|
||||
public enum ButtonUsesMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Uses per game.
|
||||
/// </summary>
|
||||
PerGame,
|
||||
|
||||
/// <summary>
|
||||
/// Uses per round.
|
||||
/// </summary>
|
||||
PerRound,
|
||||
}
|
||||
@@ -2,8 +2,13 @@
|
||||
using System.Globalization;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Mira;
|
||||
using MiraAPI.Keybinds;
|
||||
using MiraAPI.LocalSettings;
|
||||
using MiraAPI.Patches;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Rewired;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
@@ -12,7 +17,7 @@ using Object = UnityEngine.Object;
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
/// <summary>
|
||||
/// Class for making custom action buttons. More customizable than the default Action/Ability buttons in the base game.
|
||||
/// Class for making custom action buttons. More customizable than the default <see cref="ActionButton"/>/<see cref="AbilityButton"/>s in the base game.
|
||||
/// </summary>
|
||||
public abstract class CustomActionButton
|
||||
{
|
||||
@@ -31,40 +36,66 @@ public abstract class CustomActionButton
|
||||
/// </summary>
|
||||
public abstract float Cooldown { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the timer should stop decreasing when the player is venting.
|
||||
/// Note that both cooldown decrease and effect timer decrease is disabled.
|
||||
/// </summary>
|
||||
public virtual bool PauseTimerInVent => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sprite of the button. Use <see cref="LoadableResourceAsset"/> to load a sprite from a resource path. Use <see cref="LoadableBundleAsset{T}"/> to load a sprite from an asset bundle.
|
||||
/// </summary>
|
||||
public abstract LoadableAsset<Sprite> Sprite { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the button's effect duration in seconds. If the button has no effect, set to 0.
|
||||
/// Gets the format string for the cooldown timer.
|
||||
/// </summary>
|
||||
public virtual string CooldownTimerFormatString => "0";
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the button has an effect ability. By default <see langword="true"/> if <see cref="EffectDuration"/> is greater than 0.
|
||||
/// </summary>
|
||||
public virtual bool HasEffect => EffectDuration > 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the button's effect duration in seconds. If 0, the effect needs to be ended manually.
|
||||
/// </summary>
|
||||
public virtual float EffectDuration => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum amount of uses the button has. If the button has infinite uses, set to 0.
|
||||
/// Gets a value indicating whether the button has limited uses.
|
||||
/// </summary>
|
||||
public virtual int MaxUses => 0;
|
||||
public bool LimitedUses => ZeroIsInfinite ? MaxUses > 0 : MaxUses >= 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the button's text outline color.
|
||||
/// Gets the maximum number of uses the button has. If the button has infinite uses, set to 0 or -1 based on what value that ZeroIsInfinite is set to.
|
||||
/// </summary>
|
||||
public virtual int MaxUses => ZeroIsInfinite ? 0 : -1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value indicating uses mode.
|
||||
/// </summary>
|
||||
public virtual ButtonUsesMode UsesMode => ButtonUsesMode.PerGame;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the keybind for this button. If <see langword="null"/>, no keybind will be added.
|
||||
/// </summary>
|
||||
public virtual BaseKeybind? Keybind => null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the button's text outline <see cref="Color"/>.
|
||||
/// </summary>
|
||||
public virtual Color TextOutlineColor => Color.clear;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the location of the button on the screen.
|
||||
/// Gets or sets the <see cref="ButtonLocation"/> on the screen.
|
||||
/// </summary>
|
||||
public virtual ButtonLocation Location { get; set; } = ButtonLocation.BottomLeft;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the button has an effect ability.
|
||||
/// Gets or sets a value indicating whether limited uses are determined via zero or a negative number of uses.
|
||||
/// </summary>
|
||||
public bool HasEffect => EffectDuration > 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the button has limited uses.
|
||||
/// </summary>
|
||||
public bool LimitedUses => MaxUses > 0;
|
||||
public virtual bool ZeroIsInfinite { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the effect is currently active, if there is one.
|
||||
@@ -87,10 +118,20 @@ public abstract class CustomActionButton
|
||||
public float Timer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the button object in game. This is created by Mira API automatically.
|
||||
/// Gets or sets the <see cref="ActionButton"/> object in game. This is created by Mira API automatically.
|
||||
/// </summary>
|
||||
public ActionButton? Button { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="GameObject"/> used for the keybind icon.
|
||||
/// </summary>
|
||||
public GameObject? KeybindIcon { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the keybind icon text.
|
||||
/// </summary>
|
||||
private TextMeshPro? KeybindText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The method used to create the button.
|
||||
/// </summary>
|
||||
@@ -162,6 +203,59 @@ public abstract class CustomActionButton
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
if (Keybind != null)
|
||||
{
|
||||
Keybind.OnActivate(() =>
|
||||
{
|
||||
if (Enabled(PlayerControl.LocalPlayer.Data.Role))
|
||||
{
|
||||
// Invoke the generic button click event.
|
||||
var genericEvent = new MiraButtonClickEvent(this);
|
||||
MiraEventManager.InvokeEvent(genericEvent);
|
||||
if (genericEvent.IsCancelled)
|
||||
{
|
||||
MiraEventManager.InvokeEvent(new MiraButtonCancelledEvent(this));
|
||||
}
|
||||
|
||||
// Invoke the button click event for specific button.
|
||||
var eventType = CustomButtonManager.ButtonEventTypes[GetType()];
|
||||
var @event = (MiraCancelableEvent)Activator.CreateInstance(eventType, this, genericEvent)!;
|
||||
var specificInvoked = MiraEventManager.InvokeEvent(@event, eventType);
|
||||
if (@event.IsCancelled)
|
||||
{
|
||||
var cancelEventType = CustomButtonManager.ButtonCancelledEventTypes[GetType()];
|
||||
var cancelEvent = (MiraEvent)Activator.CreateInstance(cancelEventType, this)!;
|
||||
MiraEventManager.InvokeEvent(cancelEvent, cancelEventType);
|
||||
}
|
||||
|
||||
if (specificInvoked)
|
||||
{
|
||||
if (!@event.IsCancelled)
|
||||
{
|
||||
ClickHandler();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!genericEvent.IsCancelled)
|
||||
{
|
||||
ClickHandler();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
KeybindIcon =
|
||||
Helpers.CreateKeybindIcon(
|
||||
Button.gameObject,
|
||||
Keybind.CurrentKey,
|
||||
new Vector3(0.4f, 0.45f, -9f)
|
||||
);
|
||||
KeybindText = KeybindIcon.transform.GetChild(0).GetComponent<TextMeshPro>();
|
||||
HudManagerPatches.ModdedKeybindIcons.Add(KeybindText);
|
||||
Button.usesRemainingSprite.transform.localPosition = new(-0.341f, 0.45f, -0.1f);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -176,9 +270,12 @@ public abstract class CustomActionButton
|
||||
return;
|
||||
}
|
||||
|
||||
this.Location = location;
|
||||
Location = location;
|
||||
|
||||
if (!moveButton) return;
|
||||
if (!moveButton)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (HudManagerPatches.BottomLeft == null || HudManagerPatches.BottomRight == null)
|
||||
{
|
||||
@@ -218,18 +315,18 @@ public abstract class CustomActionButton
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A utility function to change the outline color of the button's text.
|
||||
/// A utility function to change the outline <see cref="Color"/> of the button's text.
|
||||
/// </summary>
|
||||
/// <param name="color">The new color.</param>
|
||||
/// <param name="color">The new <see cref="Color"/>.</param>
|
||||
public virtual void SetTextOutline(Color color)
|
||||
{
|
||||
Button?.buttonLabelText.SetOutlineColor(color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A utility function to override the sprite of the button.
|
||||
/// A utility function to override the <see cref="UnityEngine.Sprite"/> of the button.
|
||||
/// </summary>
|
||||
/// <param name="sprite">The new sprite to override with.</param>
|
||||
/// <param name="sprite">The new <see cref="UnityEngine.Sprite"/> to override with.</param>
|
||||
public virtual void OverrideSprite(Sprite sprite)
|
||||
{
|
||||
if (Button != null)
|
||||
@@ -317,7 +414,7 @@ public abstract class CustomActionButton
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A utility function that runs with the local PlayerControl's FixedUpdate if the button is enabled.
|
||||
/// A utility function that runs with the local player's <see cref="PlayerControl.FixedUpdate"/> if the button is enabled.
|
||||
/// </summary>
|
||||
/// <param name="playerControl">the local PlayerControl.</param>
|
||||
protected virtual void FixedUpdate(PlayerControl playerControl)
|
||||
@@ -331,10 +428,10 @@ public abstract class CustomActionButton
|
||||
|
||||
/// <summary>
|
||||
/// This method determines if the button should be active or not.
|
||||
/// True means the button is active, false means the button is disabled.
|
||||
/// <see langword="true"/> means the button is active, <see langword="false"/> means the button is disabled.
|
||||
/// </summary>
|
||||
/// <param name="role">The role of the local player.</param>
|
||||
/// <returns>True if the button is enabled, false otherwise.</returns>
|
||||
/// <param name="role">The <see cref="RoleBehaviour"/> of the local player.</param>
|
||||
/// <returns><see langword="true"/> if the button is enabled, <see langword="false"/> otherwise.</returns>
|
||||
public abstract bool Enabled(RoleBehaviour? role);
|
||||
|
||||
/// <summary>
|
||||
@@ -345,6 +442,13 @@ public abstract class CustomActionButton
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the effect can be ended early by the player.
|
||||
/// Always <see langword="false"/> by default.
|
||||
/// </summary>
|
||||
/// <returns>Can the effect be canceled.</returns>
|
||||
public virtual bool IsEffectCancellable() => false;
|
||||
|
||||
/// <summary>
|
||||
/// When the button is usable, this method is called to determine if the button can be clicked.
|
||||
/// By default, it takes into account the timer, effect, and uses.
|
||||
@@ -353,7 +457,7 @@ public abstract class CustomActionButton
|
||||
/// <returns>A value that represents whether the button can be clicked or not.</returns>
|
||||
public virtual bool CanClick()
|
||||
{
|
||||
return Timer <= 0 && !EffectActive && CanUse();
|
||||
return (EffectActive ? IsEffectCancellable() : Timer <= 0) && CanUse();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -363,16 +467,17 @@ public abstract class CustomActionButton
|
||||
/// <returns>A value that represents whether the button should light up or not.</returns>
|
||||
public virtual bool CanUse()
|
||||
{
|
||||
return PlayerControl.LocalPlayer.moveable && (!LimitedUses || UsesLeft > 0);
|
||||
return PlayerControl.LocalPlayer.moveable &&
|
||||
((EffectActive && IsEffectCancellable()) || (!EffectActive && (!LimitedUses || UsesLeft > 0)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called on the HudManager.SetHudActive method. It determines whether the button should be visible or not.
|
||||
/// The default behavior is to show the button if the <paramref name="visible"/> parameter and the <see cref="Enabled"/> method return true.
|
||||
/// This method is called on the <see cref="HudManager.SetHudActive(PlayerControl, RoleBehaviour, bool)"/> method. It determines whether the button should be visible or not.
|
||||
/// The default behavior is to show the button if the <paramref name="visible"/> parameter and the <see cref="Enabled"/> method return <see langword="true"/>.
|
||||
/// It can be overridden for custom behavior.
|
||||
/// </summary>
|
||||
/// <param name="visible">Passed in from HudManager.SetHudActive, should hud be active.</param>
|
||||
/// <param name="role">Passed in from HudManager.SetHudActive, the current role of the player.</param>
|
||||
/// <param name="visible">Passed in from <see cref="HudManager.SetHudActive(PlayerControl, RoleBehaviour, bool)"/>, should hud be active.</param>
|
||||
/// <param name="role">Passed in from <see cref="HudManager.SetHudActive(PlayerControl, RoleBehaviour, bool)"/>, the current role of the player.</param>
|
||||
public virtual void SetActive(bool visible, RoleBehaviour role)
|
||||
{
|
||||
Button?.ToggleVisible(visible && Enabled(role));
|
||||
@@ -385,6 +490,12 @@ public abstract class CustomActionButton
|
||||
/// </summary>
|
||||
public virtual void ClickHandler()
|
||||
{
|
||||
if (EffectActive && IsEffectCancellable())
|
||||
{
|
||||
ResetCooldownAndOrEffect();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CanClick())
|
||||
{
|
||||
return;
|
||||
@@ -410,21 +521,29 @@ public abstract class CustomActionButton
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called on the PlayerControl.FixedUpdate method. It is a wrapper for the <see cref="FixedUpdate"/> method.
|
||||
/// This method is called on the <see cref="PlayerControl.FixedUpdate"/> method. It is a wrapper for the <see cref="FixedUpdate"/> method.
|
||||
/// By default, it handles the cooldown and effect timers, and sets the button to enabled or disabled.
|
||||
/// It can be overridden for custom behavior.
|
||||
/// </summary>
|
||||
/// <param name="playerControl">The local PlayerControl.</param>
|
||||
public virtual void FixedUpdateHandler(PlayerControl playerControl)
|
||||
{
|
||||
if (Keybind != null && KeybindText != null)
|
||||
{
|
||||
KeybindText.text = Keybind.CurrentKey.ToString();
|
||||
KeybindIcon?.SetActive(ActiveInputManager.currentControlType is ActiveInputManager.InputType.Keyboard &&
|
||||
LocalSettingsTabSingleton<MiraApiSettings>.Instance.ShowKeybinds.Value &&
|
||||
Keybind.CurrentKey != KeyboardKeyCode.None);
|
||||
}
|
||||
|
||||
if (Timer >= 0)
|
||||
{
|
||||
if (!TimerPaused)
|
||||
if (!TimerPaused && (!PauseTimerInVent || !playerControl.inVent))
|
||||
{
|
||||
Timer -= Time.deltaTime;
|
||||
}
|
||||
}
|
||||
else if (HasEffect && EffectActive)
|
||||
else if (HasEffect && EffectActive && EffectDuration > 0)
|
||||
{
|
||||
EffectActive = false;
|
||||
Timer = Cooldown;
|
||||
@@ -442,16 +561,16 @@ public abstract class CustomActionButton
|
||||
Button!.SetDisabled();
|
||||
}
|
||||
|
||||
if (EffectActive)
|
||||
if (EffectActive && EffectDuration > 0)
|
||||
{
|
||||
Button.SetFillUp(Timer, EffectDuration);
|
||||
|
||||
Button.cooldownTimerText.text = Mathf.CeilToInt(Timer).ToString(NumberFormatInfo.InvariantInfo);
|
||||
Button.cooldownTimerText.text = Timer.ToString(CooldownTimerFormatString, NumberFormatInfo.InvariantInfo);
|
||||
Button.cooldownTimerText.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Button.SetCoolDown(Timer, Cooldown);
|
||||
Button.SetCooldownFormat(Timer, Cooldown, CooldownTimerFormatString);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -460,39 +579,39 @@ public abstract class CustomActionButton
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom action button that has a target object.
|
||||
/// Custom action button that has a target <typeparamref name="T"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the target object.</typeparam>
|
||||
public abstract class CustomActionButton<T> : CustomActionButton where T : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the target object of the button.
|
||||
/// Gets or sets the target <typeparamref name="T"/> of the button.
|
||||
/// </summary>
|
||||
public T? Target { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the distance the player must be from the target object to use the button.
|
||||
/// Gets the distance the player must be from the target <typeparamref name="T"/> to use the button.
|
||||
/// </summary>
|
||||
public virtual float Distance => PlayerControl.LocalPlayer.Data.Role.GetAbilityDistance();
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the target object is valid.
|
||||
/// Determines if the target <typeparamref name="T"/> is valid.
|
||||
/// </summary>
|
||||
/// <param name="target">The target object being checked.</param>
|
||||
/// <returns>True if the target object is valid, false otherwise.</returns>
|
||||
/// <param name="target">The target <typeparamref name="T"/> being checked.</param>
|
||||
/// <returns><see langword="true"/> if the target <typeparamref name="T"/> is valid, <see langword="false"/> otherwise.</returns>
|
||||
public virtual bool IsTargetValid(T? target)
|
||||
{
|
||||
return target != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The method used to get the target object.
|
||||
/// The method used to get the target <typeparamref name="T"/>.
|
||||
/// </summary>
|
||||
/// <returns>The target object or null if it isn't found.</returns>
|
||||
/// <returns>The target <typeparamref name="T"/> or <see langword="null"/> if it isn't found.</returns>
|
||||
public abstract T? GetTarget();
|
||||
|
||||
/// <summary>
|
||||
/// Sets the outline of the target object.
|
||||
/// Sets the outline of the target <typeparamref name="T"/>.
|
||||
/// </summary>
|
||||
/// <param name="active">Should the outline be active.</param>
|
||||
public abstract void SetOutline(bool active);
|
||||
|
||||
@@ -8,12 +8,12 @@ using MiraAPI.PluginLoading;
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
/// <summary>
|
||||
/// Custom button manager for handling custom buttons.
|
||||
/// Custom button manager for handling <see cref="CustomActionButton"/>s.
|
||||
/// </summary>
|
||||
public static class CustomButtonManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a list of all registered custom buttons.
|
||||
/// Gets a list of all registered custom <see cref="CustomActionButton"/>s.
|
||||
/// </summary>
|
||||
public static ReadOnlyCollection<CustomActionButton> Buttons { get; internal set; } = new([]);
|
||||
|
||||
@@ -29,7 +29,7 @@ public static class CustomButtonManager
|
||||
}
|
||||
|
||||
CustomButtons.Add(button);
|
||||
pluginInfo.Buttons.Add(button);
|
||||
pluginInfo.InternalButtons.Add(button);
|
||||
typeof(CustomButtonSingleton<>).MakeGenericType(buttonType)
|
||||
#pragma warning disable S3011
|
||||
.GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)!
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
/// <summary>
|
||||
/// A utility class to get the instance of a custom action button.
|
||||
/// A utility class to get the instance of a <see cref="CustomActionButton"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the button you are trying to access.</typeparam>
|
||||
public static class CustomButtonSingleton<T> where T : CustomActionButton
|
||||
@@ -12,7 +12,7 @@ public static class CustomButtonSingleton<T> where T : CustomActionButton
|
||||
private static T? _instance;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance of the button.
|
||||
/// Gets the instance of the <typeparamref name="T"/> button.
|
||||
/// </summary>
|
||||
[SuppressMessage("Design", "CA1000:Do not declare static members on generic types", Justification = "This is a utility class to get the instance of a custom action button.")]
|
||||
public static T Instance => _instance ??= CustomButtonManager.CustomButtons.OfType<T>().Single();
|
||||
|
||||
@@ -15,9 +15,9 @@ using UnityEngine.Events;
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
/// <summary>
|
||||
/// Custom Player Menu using the ShapeshifterPanel as a base.
|
||||
/// Custom Player Menu using the <see cref="ShapeshifterPanel"/> as a base.
|
||||
/// </summary>
|
||||
/// <param name="il2CppPtr">Used by Il2Cpp. Do not use constructor, this is a MonoBehaviour.</param>
|
||||
/// <param name="il2CppPtr">Used by Il2Cpp. Do not use constructor, this is a <see cref="MonoBehaviour"/>.</param>
|
||||
[RegisterInIl2Cpp]
|
||||
[SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "Unity Convention")]
|
||||
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Unity Convention")]
|
||||
@@ -34,9 +34,9 @@ public class CustomPlayerMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr)
|
||||
public List<ShapeshifterPanel> potentialVictims;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a CustomPlayerMenu.
|
||||
/// Creates a <see cref="CustomPlayerMenu"/>.
|
||||
/// </summary>
|
||||
/// <returns>New CustomPlayerMenu object.</returns>
|
||||
/// <returns>New <see cref="CustomPlayerMenu"/> object.</returns>
|
||||
public static CustomPlayerMenu Create()
|
||||
{
|
||||
var shapeShifterRole = RoleManager.Instance.GetRole(RoleTypes.Shapeshifter);
|
||||
@@ -84,7 +84,7 @@ public class CustomPlayerMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr)
|
||||
/// Begins/opens the custom player menu.
|
||||
/// </summary>
|
||||
/// <param name="playerMatch">Function to determine if player should show in the custom menu.</param>
|
||||
/// <param name="onClick">Onclick action for player.</param>
|
||||
/// <param name="onClick"><see cref="PassiveButton.OnClick"/> action for player.</param>
|
||||
[HideFromIl2Cpp]
|
||||
public void Begin(Func<PlayerControl, bool> playerMatch, Action<PlayerControl?> onClick)
|
||||
{
|
||||
@@ -96,7 +96,7 @@ public class CustomPlayerMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr)
|
||||
onClick(null);
|
||||
}));
|
||||
|
||||
DestroyableSingleton<DebugAnalytics>.Instance.Analytics.MinigameOpened(PlayerControl.LocalPlayer.Data, TaskType);
|
||||
DebugAnalytics.Instance.Analytics.MinigameOpened(PlayerControl.LocalPlayer.Data, TaskType);
|
||||
var list = PlayerControl.AllPlayerControls.ToArray().Where(playerMatch).ToList();
|
||||
potentialVictims = [];
|
||||
var list2 = new Il2CppSystem.Collections.Generic.List<UiElement>();
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="CustomActionButton"/> that has multiple target objects.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the target objects.</typeparam>
|
||||
public abstract class MultiTargetButton<T> : CustomActionButton where T : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the list of targets of the button.
|
||||
/// </summary>
|
||||
public T[] Targets { get; protected set; } = [];
|
||||
|
||||
/// <inheritdoc cref="CustomActionButton{T}.Distance"/>
|
||||
public virtual float Distance => PlayerControl.LocalPlayer.Data.Role.GetAbilityDistance();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum amount of targets the button can have.
|
||||
/// </summary>
|
||||
public virtual int MaxTargets { get; } = int.MaxValue;
|
||||
|
||||
/// <inheritdoc cref="CustomActionButton{T}.IsTargetValid"/>
|
||||
public virtual bool IsTargetValid(T target)
|
||||
{
|
||||
return target != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The method used to get the target objects.
|
||||
/// </summary>
|
||||
/// <returns>The list of target objects.</returns>
|
||||
public abstract T[] GetTargets();
|
||||
|
||||
/// <summary>
|
||||
/// Sets the outline of the target <typeparamref name="T"/>.
|
||||
/// </summary>
|
||||
/// <param name="target">The target <typeparamref name="T"/> to set the oultine.</param>
|
||||
/// <param name="active">Should the outline be active.</param>
|
||||
public abstract void SetOutline(T target, bool active);
|
||||
|
||||
/// <inheritdoc cref="CustomActionButton{T}.CanUse"/>
|
||||
public override bool CanUse()
|
||||
{
|
||||
var newTargets = GetTargets();
|
||||
foreach (var target in Targets)
|
||||
{
|
||||
if (!newTargets.Contains(target))
|
||||
{
|
||||
SetOutline(target, false);
|
||||
}
|
||||
}
|
||||
|
||||
Targets = newTargets
|
||||
.Where(IsTargetValid)
|
||||
.Take(MaxTargets)
|
||||
.ToArray();
|
||||
Targets.Do(t => SetOutline(t, true));
|
||||
|
||||
return base.CanUse() && Targets.Length > 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="CustomActionButton{T}.CanClick"/>
|
||||
public override bool CanClick()
|
||||
{
|
||||
return base.CanClick() && Targets.Length > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this to reset the button's targets after used.
|
||||
/// </summary>
|
||||
public virtual void ResetTarget()
|
||||
{
|
||||
Targets.Do(t => SetOutline(t, false));
|
||||
Targets = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using Rewired;
|
||||
|
||||
namespace MiraAPI.Keybinds;
|
||||
|
||||
/// <summary>
|
||||
/// Base keybind class.
|
||||
/// </summary>
|
||||
public class BaseKeybind
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Rewired <see cref="InputAction"/> assinged for this keybind.
|
||||
/// </summary>
|
||||
public InputAction? RewiredInputAction { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the unique identifier for this keybind. Used in Rewired.
|
||||
/// </summary>
|
||||
public string Id { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently assigned keycode.
|
||||
/// </summary>
|
||||
public KeyboardKeyCode CurrentKey => KeybindUtils.GetKeycodeByKeybind(this);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the handler of the keybind. Invoked when the keybind is activated.
|
||||
/// </summary>
|
||||
protected Action Handler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BaseKeybind"/> class.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier for this keybind.</param>
|
||||
public BaseKeybind(string id)
|
||||
{
|
||||
Id = id;
|
||||
Handler = () => { };
|
||||
}
|
||||
|
||||
public BaseKeybind()
|
||||
{
|
||||
Handler = () => { };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggers the keybind, invoking its handler.
|
||||
/// </summary>
|
||||
public void Invoke()
|
||||
{
|
||||
Handler.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an <see cref="Action"/> that will be invoked when the keybind is used.
|
||||
/// </summary>
|
||||
/// <param name="action">The <see cref="Action"/> to add.</param>
|
||||
public void OnActivate(Action action)
|
||||
{
|
||||
Handler += action;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes an <see cref="Action"/> that would be invoked when the keybind is used.
|
||||
/// Not recommended to use - add checks in the method added in <see cref="OnActivate"/> itself rather than removing it from the keybind.
|
||||
/// </summary>
|
||||
/// <param name="action">The <see cref="Action"/> to remove.</param>
|
||||
public void RemoveOnActivate(Action action)
|
||||
{
|
||||
Handler -= action;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.Utilities;
|
||||
using Rewired;
|
||||
|
||||
namespace MiraAPI.Keybinds;
|
||||
|
||||
/// <summary>
|
||||
/// Lets you register and manage mod <see cref="MiraKeybind"/>s with conflict checks and rebinding support.
|
||||
/// </summary>
|
||||
public static class KeybindManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a list of all registered <see cref="MiraKeybind"/>s.
|
||||
/// </summary>
|
||||
public static List<MiraKeybind> Keybinds { get; } = new();
|
||||
|
||||
[HideFromIl2Cpp]
|
||||
internal static Dictionary<Type, VanillaKeybind> VanillaKeybinds { get; set; } = [];
|
||||
|
||||
internal static void RewiredInit()
|
||||
{
|
||||
try
|
||||
{
|
||||
var instance = KeybindUtils.RewiredInputManager!;
|
||||
foreach (var keybind in Keybinds)
|
||||
{
|
||||
if (instance.userData.actions.ToArray().Any(x => x.name == keybind.Id))
|
||||
{
|
||||
Warning($"Keybind of id {keybind.Id} already exists. Skipping it");
|
||||
continue;
|
||||
}
|
||||
|
||||
keybind.RewiredInputAction = instance.userData.RegisterModBind(
|
||||
keybind.Id,
|
||||
keybind.Name,
|
||||
keybind.SourcePluginName,
|
||||
keybind.DefaultKey,
|
||||
modifiers: keybind.ModifierKeys);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Error($"Error while registering keybinds in Rewired: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all conflicts where <see cref="MiraKeybind"/>s use the same key.
|
||||
/// </summary>
|
||||
/// <returns>A list of pairs of keybinds that conflict.</returns>
|
||||
public static Dictionary<KeyboardKeyCode, List<MiraKeybind>> GetConflicts()
|
||||
{
|
||||
var conflicts = new Dictionary<KeyboardKeyCode, List<MiraKeybind>>();
|
||||
foreach (var keybind in Keybinds)
|
||||
{
|
||||
var all = GetKeybindsForKey(keybind.CurrentKey, true);
|
||||
if (all.Length > 1)
|
||||
{
|
||||
if (!conflicts.TryGetValue(keybind.CurrentKey, out var group))
|
||||
{
|
||||
conflicts.Add(keybind.CurrentKey, new List<MiraKeybind>());
|
||||
group = conflicts[keybind.CurrentKey];
|
||||
}
|
||||
|
||||
if (!group.Contains(keybind))
|
||||
{
|
||||
group.Add(keybind);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return conflicts;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all <see cref="MiraKeybind"/>s for a specified keycode.
|
||||
/// </summary>
|
||||
/// <param name="keyCode">The key to look for.</param>
|
||||
/// /// <param name="exclusiveCheck">Should only exlusive keybinds be present.</param>
|
||||
/// <returns>The list of <see cref="MiraKeybind"/>s.</returns>
|
||||
public static MiraKeybind[] GetKeybindsForKey(KeyboardKeyCode keyCode, bool exclusiveCheck = false)
|
||||
{
|
||||
var all = new List<MiraKeybind>();
|
||||
foreach (var keybind in Keybinds)
|
||||
{
|
||||
if (keybind.CurrentKey == keyCode && (keybind.Exclusive || !exclusiveCheck))
|
||||
{
|
||||
all.Add(keybind);
|
||||
}
|
||||
}
|
||||
|
||||
return all.ToArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using Rewired;
|
||||
|
||||
namespace MiraAPI.Keybinds;
|
||||
|
||||
/// <summary>
|
||||
/// Collection of keybind-related utility classes.
|
||||
/// </summary>
|
||||
public static class KeybindUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Rewired <see cref="InputManager_Base"/> instance.
|
||||
/// </summary>
|
||||
public static InputManager_Base? RewiredInputManager { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the currently assigned keycode of a <see cref="BaseKeybind"/>.
|
||||
/// </summary>
|
||||
/// <param name="keybind">The <see cref="BaseKeybind"/> to get the keycode from.</param>
|
||||
/// <returns>The currently assigned keycode.</returns>
|
||||
public static KeyboardKeyCode GetKeycodeByKeybind(BaseKeybind keybind)
|
||||
{
|
||||
if (keybind.RewiredInputAction == null)
|
||||
{
|
||||
return KeyboardKeyCode.None;
|
||||
}
|
||||
|
||||
return GetKeycodeByActionId(keybind.RewiredInputAction.id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the keycode for an action with <see cref="ReInput"/>.
|
||||
/// </summary>
|
||||
/// <param name="actionId">The action ID.</param>
|
||||
/// <returns>The keyboard keycode.</returns>
|
||||
public static KeyboardKeyCode GetKeycodeByActionId(int actionId)
|
||||
{
|
||||
return GetActionElementMap(actionId)?.keyboardKeyCode ?? KeyboardKeyCode.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="ActionElementMap"/> by id with <see cref="ReInput"/>.
|
||||
/// </summary>
|
||||
/// <param name="actionId">The action ID.</param>
|
||||
/// <returns>The keyboard keycode.</returns>
|
||||
public static ActionElementMap? GetActionElementMap(int actionId)
|
||||
{
|
||||
var player = ReInput.players.GetPlayer(0);
|
||||
return player.controllers.maps.GetFirstElementMapWithAction(ControllerType.Keyboard, actionId, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="InputAction"/> by id.
|
||||
/// </summary>
|
||||
/// <param name="id">The action identifier name.</param>
|
||||
/// <returns>The keyboard keycode.</returns>
|
||||
public static InputAction? GetInputActionById(int id)
|
||||
{
|
||||
return RewiredInputManager?.userData?.GetActionById(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds and returns an unused KeyCode that is not equal to the excluded key.
|
||||
/// </summary>
|
||||
/// <param name="exclude">The KeyCode to skip during the search.</param>
|
||||
/// <returns>
|
||||
/// The first available KeyCode not currently used by any registered keybind,
|
||||
/// or <see cref="KeyboardKeyCode.None"/> if none are available.
|
||||
/// </returns>
|
||||
public static KeyboardKeyCode FindAvailableKey(KeyboardKeyCode exclude)
|
||||
{
|
||||
foreach (KeyboardKeyCode key in Enum.GetValues<KeyboardKeyCode>())
|
||||
{
|
||||
if (key == exclude) continue;
|
||||
bool used = KeybindManager.Keybinds.Exists(e => e.DefaultKey == key);
|
||||
if (!used) return key;
|
||||
}
|
||||
return KeyboardKeyCode.None;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Rewired;
|
||||
|
||||
namespace MiraAPI.Keybinds;
|
||||
|
||||
/// <summary>
|
||||
/// Class containing all default <see cref="MiraKeybind"/>s.
|
||||
/// Recommended for cross-mod compatibility.
|
||||
/// </summary>
|
||||
[RegisterCustomKeybinds]
|
||||
public static class MiraGlobalKeybinds
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the keybind for primary abilities.
|
||||
/// </summary>
|
||||
public static MiraKeybind PrimaryAbility { get; } = new("Primary Ability", KeyboardKeyCode.T);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the keybind for secondary abilities.
|
||||
/// </summary>
|
||||
public static MiraKeybind SecondaryAbility { get; } = new("Secondary Ability", KeyboardKeyCode.Y);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the keybind for Tetiary abilities.
|
||||
/// </summary>
|
||||
public static MiraKeybind TertiaryAbility { get; } = new("Tertiary Ability", KeyboardKeyCode.U);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the keybind for primary modifier abilities.
|
||||
/// </summary>
|
||||
public static MiraKeybind ModifierPrimaryAbility { get; } = new("Modifier Primary Ability", KeyboardKeyCode.I);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the keybind for secondary modifier abilities.
|
||||
/// </summary>
|
||||
public static MiraKeybind ModifierSecondaryAbility { get; } = new("Modifier Secondary Ability", KeyboardKeyCode.O);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the keybind for Tetiary modifier abilities.
|
||||
/// </summary>
|
||||
public static MiraKeybind ModifierTertiaryAbility { get; } = new("Modifier Tertiary Ability", KeyboardKeyCode.P);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using System.Globalization;
|
||||
using Rewired;
|
||||
|
||||
namespace MiraAPI.Keybinds;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a registered keybind.
|
||||
/// </summary>
|
||||
public class MiraKeybind : BaseKeybind
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets name of the keybind.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default keycode of this keybind.
|
||||
/// </summary>
|
||||
public KeyboardKeyCode DefaultKey { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ModifierKey"/>s assigned to this keybind.
|
||||
/// Due to Rewired limitations, there can only be 3 <see cref="ModifierKey"/>s.
|
||||
/// </summary>
|
||||
public ModifierKey[] ModifierKeys { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this keybind should be checked for conflicts with other exclusive keybinds using the same key.
|
||||
/// </summary>
|
||||
public bool Exclusive { get; }
|
||||
|
||||
internal string? SourcePluginName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MiraKeybind"/> class.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the keybind.</param>
|
||||
/// <param name="defaultKeycode">The default keycode.</param>
|
||||
/// <param name="modifierKeys">Up to 3 optional <see cref="ModifierKey"/>s.</param>
|
||||
/// <param name="exclusive">Is exclusive.</param>
|
||||
public MiraKeybind(
|
||||
string name,
|
||||
KeyboardKeyCode? defaultKeycode,
|
||||
ModifierKey[]? modifierKeys = null,
|
||||
bool exclusive = true) : base(name.ToLower(CultureInfo.InvariantCulture).Replace(' ', '_'))
|
||||
{
|
||||
Name = name;
|
||||
DefaultKey = defaultKeycode ?? KeyboardKeyCode.None;
|
||||
ModifierKeys = modifierKeys ?? [];
|
||||
Exclusive = exclusive;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Name} ({Id})";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace MiraAPI.Keybinds;
|
||||
|
||||
/// <summary>
|
||||
/// Used to mark a class for <see cref="MiraKeybind"/>s registration.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class RegisterCustomKeybindsAttribute : Attribute;
|
||||
@@ -0,0 +1,24 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace MiraAPI.Keybinds;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a vanilla keybind.
|
||||
/// </summary>
|
||||
public class VanillaKeybind : BaseKeybind
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ActionButton"/> this keybind is binded to.
|
||||
/// </summary>
|
||||
public ActionButton? Button { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="VanillaKeybind"/> class.
|
||||
/// </summary>
|
||||
/// <param name="id">The keybind id.</param>
|
||||
public VanillaKeybind(int id)
|
||||
{
|
||||
RewiredInputAction = KeybindUtils.GetInputActionById(id);
|
||||
Id = RewiredInputAction != null ? RewiredInputAction.name : id.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace MiraAPI.Keybinds;
|
||||
|
||||
/// <summary>
|
||||
/// Singleton for getting a <see cref="VanillaKeybind"/> by <see cref="ActionButton"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"><see cref="AccountButton"/> type.</typeparam>
|
||||
public static class VanillaKeybinding<T> where T : ActionButton
|
||||
{
|
||||
private static VanillaKeybind? _instance;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance of the <see cref="VanillaKeybind"/>.
|
||||
/// </summary>
|
||||
#pragma warning disable CA1000
|
||||
public static VanillaKeybind Instance => _instance ??= KeybindManager.VanillaKeybinds[typeof(T)];
|
||||
#pragma warning restore CA1000
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using BepInEx.Configuration;
|
||||
using MiraAPI.LocalSettings.SettingTypes;
|
||||
|
||||
namespace MiraAPI.LocalSettings.Attributes;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="LocalEnumSetting"/> for the <see cref="ConfigEntry{T}"/>.
|
||||
/// </summary>
|
||||
/// <param name="names">Optional custom <see langword="enum"/> names.</param>
|
||||
/// <inheritdoc/>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class LocalEnumSettingAttribute(
|
||||
string? name = null,
|
||||
string? description = null,
|
||||
string[]? names = null
|
||||
) : LocalSettingAttribute(name, description)
|
||||
{
|
||||
private readonly string? _name = name;
|
||||
private readonly string? _description = description;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override LocalEnumSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase)
|
||||
{
|
||||
return new LocalEnumSetting(tab, configEntryBase, configEntryBase.SettingType, _name, _description, names);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using BepInEx.Configuration;
|
||||
using MiraAPI.LocalSettings.SettingTypes;
|
||||
using MiraAPI.Utilities;
|
||||
|
||||
namespace MiraAPI.LocalSettings.Attributes;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="LocalNumberSetting"/> for the <see cref="ConfigEntry{T}"/>.
|
||||
/// </summary>
|
||||
/// <param name="min">Minimum range.</param>
|
||||
/// <param name="max">Maximum range.</param>
|
||||
/// <param name="increment">Increment per use.</param>
|
||||
/// <param name="suffixType">Suffix for the value.</param>
|
||||
/// <param name="formatString">Format string used when formating.</param>
|
||||
/// <inheritdoc/>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class LocalNumberSettingAttribute(
|
||||
string? name = null,
|
||||
string? description = null,
|
||||
float min = 1,
|
||||
float max = 5,
|
||||
float increment = 1,
|
||||
MiraNumberSuffixes suffixType = MiraNumberSuffixes.None,
|
||||
string? formatString = null
|
||||
) : LocalSettingAttribute(name, description)
|
||||
{
|
||||
private readonly string? _name = name;
|
||||
private readonly string? _description = description;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override LocalNumberSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase)
|
||||
{
|
||||
return new LocalNumberSetting(tab, configEntryBase, _name, _description, new FloatRange(min, max), increment, suffixType, formatString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using BepInEx.Configuration;
|
||||
|
||||
namespace MiraAPI.LocalSettings.Attributes;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for all local settings attributes.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the setting. Defaults to entry key.</param>
|
||||
/// <param name="description">The description of the setting. Defalts to entry description.</param>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public abstract class LocalSettingAttribute(
|
||||
string? name = null,
|
||||
string? description = null
|
||||
) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the created <see cref="ILocalSetting"/> object.
|
||||
/// </summary>
|
||||
/// <param name="tab">Gets the tab where the setting is located.</param>
|
||||
/// <param name="configEntryBase">Gets the config entry the setting is attached to.</param>
|
||||
/// <returns>The created <see cref="ILocalSetting"/>.</returns>
|
||||
public abstract ILocalSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace MiraAPI.LocalSettings.Attributes;
|
||||
|
||||
/// <summary>
|
||||
/// Attribute for local setting buttons.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class LocalSettingsButtonAttribute : Attribute
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using BepInEx.Configuration;
|
||||
using MiraAPI.LocalSettings.SettingTypes;
|
||||
using MiraAPI.Utilities;
|
||||
|
||||
namespace MiraAPI.LocalSettings.Attributes;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="LocalSliderSetting"/> for the <see cref="ConfigEntry{T}"/>.
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
/// <param name="min">Minimum range.</param>
|
||||
/// <param name="max">Maximum range.</param>
|
||||
/// <param name="roundValue">Should the value be rounded.</param>
|
||||
/// <param name="suffixType">Suffix for the value.</param>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class LocalSliderSettingAttribute(
|
||||
string? name = null,
|
||||
float min = 0,
|
||||
float max = 100,
|
||||
string? description = null,
|
||||
bool displayValue = false,
|
||||
string? formatString = null,
|
||||
bool roundValue = false,
|
||||
MiraNumberSuffixes suffixType = MiraNumberSuffixes.None
|
||||
) : LocalSettingAttribute(name, description)
|
||||
{
|
||||
private readonly string? _name = name;
|
||||
private readonly string? _description = description;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override LocalSliderSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase)
|
||||
{
|
||||
return new LocalSliderSetting(tab, configEntryBase, _name, _description, new FloatRange(min, max), displayValue, suffixType, formatString, roundValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using BepInEx.Configuration;
|
||||
using MiraAPI.LocalSettings.SettingTypes;
|
||||
|
||||
namespace MiraAPI.LocalSettings.Attributes;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="LocalToggleSetting"/> for the <see cref="ConfigEntry{T}"/>.
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class LocalToggleSettingAttribute(
|
||||
string? name = null,
|
||||
string? description = null
|
||||
) : LocalSettingAttribute(name, description)
|
||||
{
|
||||
private readonly string? _name = name;
|
||||
private readonly string? _description = description;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override LocalToggleSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase)
|
||||
{
|
||||
return new LocalToggleSetting(tab, configEntryBase, _name, _description);
|
||||
}
|
||||
}
|
||||
Loaded 100 of 244 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user