Skip to content

Commit

Permalink
同步部分更改
Browse files Browse the repository at this point in the history
  • Loading branch information
mxyx0412 committed Jan 10, 2025
1 parent 10f059e commit 6f58c9d
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 202 deletions.
6 changes: 2 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[*.cs]
charset = utf-8
dotnet_diagnostic.IDE0007.severity = silent
dotnet_diagnostic.IDE0022.severity = silent
dotnet_diagnostic.IDE0023.severity = silent
dotnet_diagnostic.IDE0028.severity = none
dotnet_diagnostic.IDE0031.severity = silent
dotnet_diagnostic.IDE0046.severity = silent
dotnet_diagnostic.IDE0058.severity = silent
dotnet_diagnostic.IDE0061.severity = silent
dotnet_diagnostic.IDE0305.severity = silent
dotnet_diagnostic.IDE1006.severity = silent
Expand All @@ -16,10 +18,6 @@ dotnet_analyzer_diagnostic.severity = suggestion

[*.cs]
#### 命名样式 ####

# IDE0058:
dotnet_diagnostic.IDE0058.severity = silent

# 命名规则

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
Expand Down
14 changes: 14 additions & 0 deletions TheOtherRoles/Helper/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,20 @@ public static bool Contains<T, TKey>(this IEnumerable<T> list, T item, Func<T, T
return list.Any(x => keySelector(x).Equals(keySelector(item)));
}

public static int Count<T>(this Il2CppSystem.Collections.Generic.List<T> list, Func<T, bool> func = null)
{
int count = 0;
foreach (T obj in list)
if (func == null || func(obj))
count++;
return count;
}
public static Color HexToColor(string hex)
{
_ = ColorUtility.TryParseHtmlString("#" + hex, out var color);
return color;
}

public static string readTextFromResources(string path)
{
var assembly = Assembly.GetExecutingAssembly();
Expand Down
9 changes: 3 additions & 6 deletions TheOtherRoles/Modules/KeyboardHandler.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using TheOtherRoles.Buttons;
using TheOtherRoles.Patches;
using TheOtherRoles.Utilities;
using UnityEngine;
using Random = System.Random;

namespace TheOtherRoles.Modules;

[HarmonyPatch(typeof(KeyboardJoystick), nameof(KeyboardJoystick.Update))]
public class KeyboardHandler
{
//private static readonly string passwordHash = "d1f51dfdfd8d38027fd2ca9dfeb299399b5bdee58e6c0b3b5e9a45cd4e502848";
private static readonly Random random = new((int)DateTime.Now.Ticks);
private static readonly List<PlayerControl> bots = new();

private static void Postfix(KeyboardJoystick __instance)
Expand All @@ -35,7 +32,7 @@ private static void Postfix(KeyboardJoystick __instance)
playerControl.GetComponent<DummyBehaviour>().enabled = true;
playerControl.NetTransform.enabled = false;
playerControl.SetName(RandomString(6));
playerControl.SetColor((byte)random.Next(Palette.PlayerColors.Length));
playerControl.SetColor((byte)rnd.Next(Palette.PlayerColors.Length));
GameData.Instance.RpcSetTasks(playerControl.PlayerId, Array.Empty<byte>());
}
// 强制开始会议或结束会议
Expand Down Expand Up @@ -63,7 +60,7 @@ private static void Postfix(KeyboardJoystick __instance)
public static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray());
return new string(Enumerable.Repeat(chars, length).Select(s => s[rnd.Next(s.Length)]).ToArray());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using static UnityEngine.UI.Button;
using Object = UnityEngine.Object;

namespace TheOtherRoles.Patches;
namespace TheOtherRoles.Options;

[HarmonyPatch(typeof(OptionsMenuBehaviour), nameof(OptionsMenuBehaviour.Start))]
public static class StartOptionMenuPatch
Expand All @@ -19,50 +19,42 @@ public static void UpdateCustomText(this ToggleButtonBehaviour button, Color col
button.onState = false;
button.Background.color = color;
if (text != null)
{
button.Text.text = text;
}

if (button.Rollover)
{
button.Rollover.ChangeOutColor(color);
}
}

public static void UpdateToggleText(this ToggleButtonBehaviour button, bool on, string text)
{
button.onState = on;
Color color = on ? new Color(0f, 1f, 0.16470589f, 1f) : Color.white;
var color = on ? new Color(0f, 1f, 0.16470589f, 1f) : Color.white;
button.Background.color = color;
button.Text.text = text + ": " + DestroyableSingleton<TranslationController>.Instance.GetString(button.onState
? StringNames.SettingsOn : StringNames.SettingsOff, new Il2CppReferenceArray<Il2CppSystem.Object>(0));
if (button.Rollover)
{
button.Rollover.ChangeOutColor(color);
}
}

public static void UpdateButtonText(this ToggleButtonBehaviour button, string text, string state)
{
button.onState = false;
Color color = Color.white;
var color = Color.white;
button.Background.color = color;
button.Text.text = text + ": " + state;
if (button.Rollover)
{
button.Rollover.ChangeOutColor(color);
}
}

private static ToggleButtonBehaviour AddButton(Vector2 pos, string name, Action onClicked, GameObject nebulaTab, GameObject toggleButtonTemplate)
private static ToggleButtonBehaviour AddButton(int index, string name, Action onClicked, GameObject nebulaTab, GameObject toggleButtonTemplate)
{
GameObject button = Object.Instantiate(toggleButtonTemplate, null);
var button = Object.Instantiate(toggleButtonTemplate, null);
button.transform.SetParent(nebulaTab.transform);
button.transform.localScale = new Vector3(1f, 1f, 1f);
button.transform.localPosition = new Vector3(1.3f * ((pos.x * 2f) - 1f), 1.6f - (0.5f * pos.y), 0f);
button.transform.localPosition = new Vector3(1.3f * (index % 2 * 2 - 1), 1.6f - 0.5f * (index / 2), 0f);
button.name = name;
ToggleButtonBehaviour result = button.GetComponent<ToggleButtonBehaviour>();
PassiveButton passiveButton = button.GetComponent<PassiveButton>();
var result = button.GetComponent<ToggleButtonBehaviour>();
var passiveButton = button.GetComponent<PassiveButton>();
passiveButton.OnClick = new ButtonClickedEvent();
passiveButton.OnClick.AddListener((UnityAction)onClicked);
return result;
Expand All @@ -80,7 +72,7 @@ public static void Postfix(OptionsMenuBehaviour __instance)

PassiveButton passiveButton;

//ÔO¶¨í—Ä¿¤ò×·¼Ó¤¹¤ë
//設定項目を追加する

GameObject nebulaTab = new("NebulaTab");
nebulaTab.transform.SetParent(__instance.transform);
Expand All @@ -92,18 +84,20 @@ public static void Postfix(OptionsMenuBehaviour __instance)
keyBindingTab.transform.localScale = new Vector3(1f, 1f, 1f);
keyBindingTab.SetActive(false);

GameObject applyButtonTemplate = tabs[1].Content.transform.GetChild(0).FindChild("ApplyButton").gameObject;
GameObject toggleButtonTemplate = tabs[0].Content.transform.FindChild("MiscGroup").FindChild("StreamerModeButton").gameObject;
var applyButtonTemplate = tabs[1].Content.transform.GetChild(0).FindChild("ApplyButton").gameObject;
var toggleButtonTemplate = tabs[0].Content.transform.FindChild("MiscGroup").FindChild("StreamerModeButton").gameObject;

var buttonIndex = 0;

//EnableSoundEffects
enableSoundEffects = AddButton(new Vector2(0, 0), "EnableSoundEffects", () =>
enableSoundEffects = AddButton(buttonIndex++, "EnableSoundEffects", () =>
{
enableSoundEffects.UpdateToggleText(!enableSoundEffects.onState, GetString("EnableSoundEffectsText"));
ModOption.enableSoundEffects = Main.EnableSoundEffects.Value = enableSoundEffects.onState;
}, nebulaTab, toggleButtonTemplate);

//ToggleCursor
toggleCursor = AddButton(new Vector2(0, 1), "ToggleCursor", () =>
toggleCursor = AddButton(buttonIndex++, "ToggleCursor", () =>
{
enableCursor(false);
toggleCursor.UpdateToggleText(!toggleCursor.onState, GetString("ToggleCursorText"));
Expand All @@ -112,33 +106,33 @@ public static void Postfix(OptionsMenuBehaviour __instance)
}, nebulaTab, toggleButtonTemplate);

//ShowFPS
showKeyReminder = AddButton(new Vector2(1, 0), "ShowKeyReminder", () =>
showFPS = AddButton(buttonIndex++, "ShowFPS", () =>
{
showKeyReminder.UpdateToggleText(!showKeyReminder.onState, GetString("ShowKeyReminder"));
ModOption.showKeyReminder = Main.ShowKeyReminder.Value = showKeyReminder.onState;
showFPS.UpdateToggleText(!showFPS.onState, GetString("ShowFPS"));
ModOption.showFPS = Main.ShowFPS.Value = showFPS.onState;
}, nebulaTab, toggleButtonTemplate);

//ShowFPS
showFPS = AddButton(new Vector2(1, 1), "ShowFPS", () =>
//ShowKeyReminder
showKeyReminder = AddButton(buttonIndex++, "ShowKeyReminder", () =>
{
showFPS.UpdateToggleText(!showFPS.onState, GetString("ShowFPS"));
ModOption.showFPS = Main.ShowFPS.Value = showFPS.onState;
showKeyReminder.UpdateToggleText(!showKeyReminder.onState, GetString("ShowKeyReminder"));
ModOption.showKeyReminder = Main.ShowKeyReminder.Value = showKeyReminder.onState;
}, nebulaTab, toggleButtonTemplate);

//LocalHats
localHats = AddButton(new Vector2(0, 2), "LocalHats", () =>
localHats = AddButton(buttonIndex++, "LocalHats", () =>
{
localHats.UpdateToggleText(!localHats.onState, GetString("LocalHatsText"));
ModOption.localHats = Main.LocalHats.Value = localHats.onState;
}, nebulaTab, toggleButtonTemplate);

//¥­©`¸î¤êµ±¤Æ¥Ü¥¿¥ó
//キー割り当てボタン
GameObject TextObject;

List<ToggleButtonBehaviour> allKeyBindingButtons = new();
int selectedKeyBinding = -1;
var selectedKeyBinding = -1;

GameObject defaultButton = Object.Instantiate(applyButtonTemplate, null);
var defaultButton = Object.Instantiate(applyButtonTemplate, null);
defaultButton.transform.SetParent(keyBindingTab.transform);
defaultButton.transform.localScale = new Vector3(1f, 1f, 1f);
defaultButton.transform.localPosition = new Vector3(0f, -2.5f, 0f);
Expand All @@ -155,9 +149,9 @@ public static void Postfix(OptionsMenuBehaviour __instance)
selectedKeyBinding = -1;
//_ = SoundManager.Instance.PlaySound(Module.MetaScreen.getSelectClip(), false, 0.8f);

for (int i = 0; i < ModInputManager.allInputs.Count; i++)
for (var i = 0; i < ModInputManager.allInputs.Count; i++)
{
ModInputManager.ModInput input = ModInputManager.allInputs[i];
var input = ModInputManager.allInputs[i];
input.resetToDefault();
allKeyBindingButtons[i].UpdateCustomText(Color.white, GetString("keyBinding." + input.identifier) + ": " + ModInputManager.allKeyCodes[input.keyCode].displayKey);
}
Expand All @@ -166,14 +160,14 @@ public static void Postfix(OptionsMenuBehaviour __instance)

foreach (var input in ModInputManager.allInputs)
{
int index = allKeyBindingButtons.Count;
var index = allKeyBindingButtons.Count;

GameObject inputButton = Object.Instantiate(toggleButtonTemplate, null);
var inputButton = Object.Instantiate(toggleButtonTemplate, null);
inputButton.transform.SetParent(keyBindingTab.transform);
inputButton.transform.localScale = new Vector3(1f, 1f, 1f);
inputButton.transform.localPosition = new Vector3(1.3f * ((index % 2 * 2) - 1), 1.5f - (0.5f * (index / 2)), 0f);
inputButton.transform.localPosition = new Vector3(1.3f * (index % 2 * 2 - 1), 1.5f - 0.5f * (index / 2), 0f);
inputButton.name = input.identifier;
ToggleButtonBehaviour inputToggleButton = inputButton.GetComponent<ToggleButtonBehaviour>();
var inputToggleButton = inputButton.GetComponent<ToggleButtonBehaviour>();
inputToggleButton.BaseText = 0;
inputToggleButton.Text.text = GetString("keyBinding." + input.identifier) + ": " + ModInputManager.allKeyCodes[input.keyCode].displayKey;
passiveButton = inputButton.GetComponent<PassiveButton>();
Expand All @@ -197,7 +191,7 @@ public static void Postfix(OptionsMenuBehaviour __instance)
allKeyBindingButtons.Add(inputToggleButton);
}

GameObject keyBindingButton = Object.Instantiate(applyButtonTemplate, null);
var keyBindingButton = Object.Instantiate(applyButtonTemplate, null);
keyBindingButton.transform.SetParent(nebulaTab.transform);
keyBindingButton.transform.localScale = new Vector3(1f, 1f, 1f);
keyBindingButton.transform.localPosition = new Vector3(0f, -1.5f, 0f);
Expand Down Expand Up @@ -228,14 +222,12 @@ IEnumerator getEnumerator()

if (keyBindingTab.gameObject.active && Input.anyKeyDown && selectedKeyBinding != -1)
{
foreach (KeyValuePair<KeyCode, ModInputManager.KeyCodeData> entry in ModInputManager.allKeyCodes)
foreach (var entry in ModInputManager.allKeyCodes)
{
if (!Input.GetKeyDown(entry.Key))
{
continue;
}

ModInputManager.ModInput input = ModInputManager.allInputs[selectedKeyBinding];
var input = ModInputManager.allInputs[selectedKeyBinding];
input.changeKeyCode(entry.Key);
allKeyBindingButtons[selectedKeyBinding].UpdateCustomText(Color.white, GetString("keyBinding." + input.identifier) + ": " + ModInputManager.allKeyCodes[input.keyCode].displayKey);
selectedKeyBinding = -1;
Expand All @@ -256,20 +248,20 @@ IEnumerator getEnumerator()
: __instance.StartCoroutine(getEnumerator().WrapToIl2Cpp());


//¥¿¥Ö¤ò×·¼Ó¤¹¤ë
//タブを追加する

tabs[^1] = Object.Instantiate(tabs[1], null);
TabGroup nebulaButton = tabs[^1];
var nebulaButton = tabs[^1];
nebulaButton.gameObject.name = "NebulaButton";
nebulaButton.transform.SetParent(tabs[0].transform.parent);
nebulaButton.transform.localScale = new Vector3(1f, 1f, 1f);
nebulaButton.Content = nebulaTab;
GameObject textObj = nebulaButton.transform.FindChild("Text_TMP").gameObject;
var textObj = nebulaButton.transform.FindChild("Text_TMP").gameObject;
textObj.GetComponent<TextTranslatorTMP>().enabled = false;
textObj.GetComponent<TMP_Text>().text = "modOptionsTitle".Translate();

tabs.Add(Object.Instantiate(tabs[1], null));
TabGroup keyBindingTabButton = tabs[^1];
var keyBindingTabButton = tabs[^1];
keyBindingTabButton.gameObject.name = "KeyBindingButton";
keyBindingTabButton.transform.SetParent(tabs[0].transform.parent);
keyBindingTabButton.transform.localScale = new Vector3(1f, 1f, 1f);
Expand All @@ -295,14 +287,14 @@ IEnumerator getEnumerator()
float y = tabs[0].transform.localPosition.y, z = tabs[0].transform.localPosition.z;
if (tabs.Count == 4)
{
for (int i = 0; i < 3; i++)
for (var i = 0; i < 3; i++)
{
tabs[i].transform.localPosition = new Vector3(1.7f * (i - 1), y, z);
}
}
else if (tabs.Count == 5)
{
for (int i = 0; i < 4; i++)
for (var i = 0; i < 4; i++)
{
tabs[i].transform.localPosition = new Vector3(1.62f * (i - 1.5f), y, z);
}
Expand Down
4 changes: 2 additions & 2 deletions TheOtherRoles/Options/CustomOptionHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ public static void Load()
eraserCanEraseAnyone = Create(10162, Types.Impostor, "eraserCanEraseAnyone", false, eraserSpawnRate);
erasercanEraseGuess = Create(10163, Types.Impostor, "erasercanEraseGuess", false, eraserSpawnRate);

poucherSpawnRate = Create(10320, Types.Impostor, cs(Palette.ImpostorRed, "Poucher"), rates, null, true, () =>
poucherSpawnRate = Create(10320, Types.Impostor, cs(Palette.ImpostorRed, "Poucher"), rates, null, true, false, () =>
{
if (modifierPoucher.selection > 0) poucherSpawnRate.selection = 0;
});
Expand Down Expand Up @@ -1272,7 +1272,7 @@ public static void Load()
modifierDisperser = Create(40100, Types.Modifier, cs(Palette.ImpostorRed, "Disperser"), rates, null, true);
modifierDisperserDispersesToVent = Create(40101, Types.Modifier, "modifierDisperserDispersesToVent", true, modifierDisperser);

modifierPoucher = Create(40370, Types.Modifier, cs(Palette.ImpostorRed, "Poucher"), rates, null, true, () =>
modifierPoucher = Create(40370, Types.Modifier, cs(Palette.ImpostorRed, "Poucher"), rates, null, true, false, () =>
{
poucherSpawnRate.selection = 0;
});
Expand Down
Loading

0 comments on commit 6f58c9d

Please sign in to comment.