Skip to content

Commit

Permalink
Play time modern UI rehaul
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 508f6f13e9a3121c83a400ffb66f17b57da8d4522867a27e5aea0b9eb2d96b81
  • Loading branch information
librarianmage committed Jul 6, 2022
2 parents 8af838e + 1aa37dc commit 2f7eae8
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions selectors.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using HarmonyLib;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using XRL;
using XRL.World;
using XRL.CharacterBuilds.Qud.UI;
using XRL.UI;
using System.Threading.Tasks;

namespace QudGendersUnleashed.PronounAndGenderSelectorPatches
{
Expand Down Expand Up @@ -31,12 +34,14 @@ public static MethodBase TargetMethod()
}
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{

MethodInfo oldMethod = AccessTools.Method(typeof(PronounSet), nameof(PronounSet.GetAllGenericPersonalSingular));
MethodInfo newMethod = AccessTools.Method(typeof(PronounSet), nameof(PronounSet.GetAllPersonal));
return HarmonyLib.Transpilers.MethodReplacer(instructions, oldMethod, newMethod);
}
}

// Technically unused
[HarmonyPatch(typeof(PronounAndGenderSets))]
[HarmonyPatch(nameof(PronounAndGenderSets.ShowChangePronounSet))]
public static class PlaytimePronounPatch
Expand All @@ -50,6 +55,81 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
}


[HarmonyPatch(typeof(StatusScreen))]
[HarmonyPatch(nameof(StatusScreen.Show))]
public static class StatusScreenPatch
{
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
MethodInfo oldMethod = AccessTools.Method(typeof(PronounAndGenderSets), nameof(PronounAndGenderSets.ShowChangePronounSet));
MethodInfo newMethod = AccessTools.Method(typeof(StatusScreenPatch), nameof(StatusScreenPatch.ChangePronounSet));
return HarmonyLib.Transpilers.MethodReplacer(instructions, oldMethod, newMethod);
}

public static void ChangePronounSet(GameObject Player)
{
Task<PronounSet> newPronounTask = OnChoosePronounSetAsync(Player);
newPronounTask.Wait();
PronounSet newPronoun = newPronounTask.Result;

if (newPronoun != null)
{
Player.SetPronounSet(newPronoun.Register());
}
}

public static async Task<PronounSet> OnChoosePronounSetAsync(GameObject Player)
{
List<PronounSet> availablePronounSets = PronounSet.GetAllPersonal();
IEnumerable<string> pronounNames = availablePronounSets.Select((PronounSet pronounSet) => pronounSet.Name);

PronounSet currentPronounSet = Player.GetPronounSet();
int indexCurrentPronounSet = availablePronounSets.FindIndex(p => p == currentPronounSet);

List<string> options = new List<string>();
options.Add("<from gender>");
options.AddRange(pronounNames);
options.Add("<create new>");

int index = await Popup.AsyncShowOptionsList(
Title: "Change Pronoun Set",
Options: options.ToArray(),
AllowEscape: true,
defaultSelected: indexCurrentPronounSet + 1);

if (index > -1)
{
if (options[index] != "<create new>")
{
if (index == 0)
{
// Selected <from gender>
Gender playerGender = Player.GetGender();
return new PronounSet(playerGender);
}
else
{
return availablePronounSets[index - 1];
}
}

int basePronounIndex = await Popup.AsyncShowOptionsList(
Title: "Select Base Set",
Options: pronounNames.ToArray(),
RespectOptionNewlines: false,
AllowEscape: true);

if (basePronounIndex > -1)
{
PronounSet original = availablePronounSets[basePronounIndex];
PronounSet newPronounSet = new PronounSet(original);
if (await newPronounSet.CustomizeAsync())
{
return newPronounSet;
}
}
}
return null;
}
}
}

0 comments on commit 2f7eae8

Please sign in to comment.