Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 13 additions & 33 deletions Code/ForceVariant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
Variant.Invincible,
};

private static Dictionary<TextMenu.Item, int> itemList = new();
private static Hook enableHook, disableHook, aPressHook;

Check warning on line 50 in Code/ForceVariant.cs

View workflow job for this annotation

GitHub Actions / build

The field 'ForceVariants.disableHook' is never used

Check warning on line 50 in Code/ForceVariant.cs

View workflow job for this annotation

GitHub Actions / build

The field 'ForceVariants.enableHook' is never used

Check warning on line 50 in Code/ForceVariant.cs

View workflow job for this annotation

GitHub Actions / build

The field 'ForceVariants.aPressHook' is never used

Check warning on line 50 in Code/ForceVariant.cs

View workflow job for this annotation

GitHub Actions / build

The field 'ForceVariants.disableHook' is never used

Check warning on line 50 in Code/ForceVariant.cs

View workflow job for this annotation

GitHub Actions / build

The field 'ForceVariants.enableHook' is never used

Check warning on line 50 in Code/ForceVariant.cs

View workflow job for this annotation

GitHub Actions / build

The field 'ForceVariants.aPressHook' is never used
private static TextMenu variantMenu;

private static bool[] Variants_Default { get; set; } = new bool[] { false, false, false, false, false, false, false, false, false, false, false };
Expand Down Expand Up @@ -142,49 +141,20 @@
On.Celeste.ChangeRespawnTrigger.OnEnter += OnChangeRespawn;
On.Celeste.Level.AssistMode += Level_AssistMode;
On.Celeste.Level.VariantMode += Level_VariantMode;

Delegate optionChanged = new Action<Action<TextMenu.Option<bool>>, TextMenu.Option<bool>>(OnChange);
disableHook = new Hook(
typeof(TextMenu.Option<bool>).GetMethod("LeftPressed", BindingFlags.Instance | BindingFlags.Public),
optionChanged);

enableHook = new Hook(
typeof(TextMenu.Option<bool>).GetMethod("RightPressed", BindingFlags.Instance | BindingFlags.Public),
optionChanged);

aPressHook = new Hook(
typeof(TextMenu.Option<bool>).GetMethod("ConfirmPressed", BindingFlags.Instance | BindingFlags.Public),
optionChanged);
}

internal static void Unload() {
On.Celeste.ChangeRespawnTrigger.OnEnter -= OnChangeRespawn;
On.Celeste.Level.AssistMode -= Level_AssistMode;
On.Celeste.Level.VariantMode -= Level_VariantMode;
On.Celeste.TextMenu.Close -= TextMenu_Close;

enableHook?.Dispose();
disableHook?.Dispose();
aPressHook?.Dispose();
enableHook = disableHook = aPressHook = null;
}

private static void OnChangeRespawn(On.Celeste.ChangeRespawnTrigger.orig_OnEnter orig, ChangeRespawnTrigger self, Player player) {
orig(self, player);
SaveToSession();
}

private static void OnChange(Action<TextMenu.Option<bool>> orig, TextMenu.Option<bool> self) {
orig(self);

if (itemList.ContainsKey(self)) {
bool value = self.Index >= 1;
int index = itemList[self];
Variants_Default[index] = value;

}
}

private static void Level_VariantMode(On.Celeste.Level.orig_VariantMode orig, Level self, int returnIndex, bool minimal) {
orig(self, returnIndex, minimal);
List<Entity> list = self.Entities.ToAdd;
Expand All @@ -200,22 +170,32 @@
private static void OnVariantMenu(TextMenu menu, bool assist) {
variantMenu = menu;
IsaSession session = GrabBagModule.Session;
itemList = new Dictionary<TextMenu.Item, int>();

On.Celeste.TextMenu.Close += TextMenu_Close;

int index = assist ? 8 : 0;
for (int i = 0; i < menu.Items.Count; ++i) {
TextMenu.Item item = menu.Items[i];
if (item is not TextMenu.OnOff) {
if (item is not TextMenu.OnOff onoff) {
continue;
}

Variant v = (!assist && bingoUIMenuModified) ? Variant.NoGrabbing : menuLayout[index++];
itemList.Add(item, (int)v);

onoff.OnValueChange = OnChangeVariant(onoff.OnValueChange, onoff, v);
}
}

private static Action<bool> OnChangeVariant(Action<bool> orig, TextMenu.Option<bool> self, Variant v) {
return val => {
orig(val);

bool value = self.Index >= 1;
int index = (int)v;
Variants_Default[index] = value;
};
}

private static void TextMenu_Close(On.Celeste.TextMenu.orig_Close orig, TextMenu self) {
orig(self);
if (variantMenu != self) {
Expand Down
Loading