Skip to content

Commit

Permalink
removed EaseInDecorator
Browse files Browse the repository at this point in the history
  • Loading branch information
nhruo123 committed Jun 6, 2023
1 parent d278e42 commit 1df6495
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 112 deletions.
4 changes: 2 additions & 2 deletions Celeste.Mod.mm/Content/Dialog/English.txt
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@
MODOPTIONS_MODTOGGLE_TOGGLEDEPS= Toggle Dependencies Automatically
MODOPTIONS_MODTOGGLE_TOGGLEDEPS_MESSAGE1= When you enable a mod, all its dependencies will be enabled.
MODOPTIONS_MODTOGGLE_TOGGLEDEPS_MESSAGE2= When you disable a mod, all mods that depend on it will be disabled.
MODOPTIONS_MODTOGGLE_TOGGLEFAVORITES= Disable All ignores favorites
MODOPTIONS_MODTOGGLE_TOGGLEFAVORITES_MESSAGE= Press {0} to add or remove items from the favorite list.
MODOPTIONS_MODTOGGLE_TOGGLEFAVORITES= 'Disable All' ignores favorites
MODOPTIONS_MODTOGGLE_TOGGLEFAVORITES_MESSAGE= Press {0} to add or remove mods from the favorite list.
MODOPTIONS_MODTOGGLE_MESSAGE_1= If you enable or disable mods, your blacklist.txt will be replaced,
MODOPTIONS_MODTOGGLE_MESSAGE_2= and Celeste will restart to apply changes.
MODOPTIONS_MODTOGGLE_MESSAGE_3= Highlighted mods are used by other enabled mods as a dependency.
Expand Down
43 changes: 21 additions & 22 deletions Celeste.Mod.mm/Mod/UI/OuiModToggler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,15 @@ class OuiModToggler : OuiGenericMenu, OuiModOptions.ISubmenu {
private Dictionary<string, HashSet<string>> favoritesDependenciesMods;

private bool toggleDependencies = true;

private bool disableAllIgnoresFavorites = true;

private TextMenuExt.SubHeaderExt restartMessage1;
private TextMenuExt.SubHeaderExt restartMessage2;

// maps each filename to Everest modules
private Dictionary<string, EverestModuleMetadata[]> modYamls;

// maps each mode name to its Everest module
private Dictionary<string, EverestModuleMetadata> modNames;

// maps each mod name to its newest Everest module
private Dictionary<string, string> modFilenameByModName;

private Dictionary<string, TextMenu.OnOff> modToggles;
private Task modLoadingTask;
Expand Down Expand Up @@ -202,7 +199,7 @@ protected override void addOptionsToMenu(TextMenu menu) {

MainThreadHelper.Do(() => {
modToggles = new Dictionary<string, TextMenu.OnOff>();
modNames = buildModNames(modYamls);
modFilenameByModName = buildModNames(modYamls);

// remove the "loading..." message
menu.Remove(loading);
Expand Down Expand Up @@ -248,19 +245,20 @@ protected override void addOptionsToMenu(TextMenu menu) {
TextMenu.Item toggleDependenciesButton;
menu.Add(toggleDependenciesButton = new TextMenu.OnOff(Dialog.Clean("MODOPTIONS_MODTOGGLE_TOGGLEDEPS"), true)
.Change(value => toggleDependencies = value));

toggleDependenciesButton.AddDescription(menu, Dialog.Clean("MODOPTIONS_MODTOGGLE_TOGGLEDEPS_MESSAGE2"));
toggleDependenciesButton.AddDescription(menu, Dialog.Clean("MODOPTIONS_MODTOGGLE_TOGGLEDEPS_MESSAGE1"));

TextMenu.Item toggleFavoritesButton;
menu.Add(toggleFavoritesButton = new TextMenu.OnOff(Dialog.Clean("MODOPTIONS_MODTOGGLE_TOGGLEFAVORITES"), disableAllIgnoresFavorites)
.Change(value => disableAllIgnoresFavorites = value));

TextMenuExt.EaseInDecorator<TextMenuExt.SubMenuWithInputs> favoriteToolTip =
new TextMenuExt.EaseInDecorator<TextMenuExt.SubMenuWithInputs>(
new TextMenuExt.SubMenuWithInputs(
string.Format(Dialog.Get("MODOPTIONS_MODTOGGLE_TOGGLEFAVORITES_MESSAGE"), "|"), '|',
new Monocle.VirtualButton[] { Input.MenuJournal }, () => Input.GuiInputController()) { TextColor = Color.Gray }
, false, menu);
TextMenuExt.EaseInSubMenuWithInputs favoriteToolTip = new TextMenuExt.EaseInSubMenuWithInputs(
string.Format(Dialog.Get("MODOPTIONS_MODTOGGLE_TOGGLEFAVORITES_MESSAGE"), "|"),
'|',
new Monocle.VirtualButton[] { Input.MenuJournal },
false
) {TextColor = Color.Gray};

menu.Add(favoriteToolTip);

Expand Down Expand Up @@ -392,23 +390,25 @@ private void addFileToMenu(TextMenu menu, string file) {
modToggles[file] = option;
}

private Dictionary<string, EverestModuleMetadata> buildModNames(Dictionary<string, EverestModuleMetadata[]> modYamls) {
Dictionary<string, EverestModuleMetadata> modNames = new();
private Dictionary<string, string> buildModNames(Dictionary<string, EverestModuleMetadata[]> modYamls) {
Dictionary<string, EverestModuleMetadata> everestModulesByModName = new();

foreach (KeyValuePair<string, EverestModuleMetadata[]> pair in modYamls) {
foreach (EverestModuleMetadata currentModule in pair.Value) {
if (modNames.TryGetValue(currentModule.Name, out EverestModuleMetadata previousModule)) {
if (everestModulesByModName.TryGetValue(currentModule.Name, out EverestModuleMetadata previousModule)) {
if (previousModule.Version < currentModule.Version) {
modNames[currentModule.Name] = currentModule;
everestModulesByModName[currentModule.Name] = currentModule;
}
} else {
modNames[currentModule.Name] = currentModule;
everestModulesByModName[currentModule.Name] = currentModule;
}
}
}


return modNames;
return everestModulesByModName
.Select(tuple => new KeyValuePair<string, string>(tuple.Key, Path.GetFileName(tuple.Value.PathArchive ?? tuple.Value.PathDirectory)))
.ToDictionary(x=> x.Key, x=>x.Value);
}

private void updateHighlightedMods() {
Expand Down Expand Up @@ -487,7 +487,6 @@ private void addToFavorites(string modFileName) {
favoritedMods.Add(modFileName);
Logger.Log(LogLevel.Verbose, "OuiModToggler", $"{modFileName} was added to favorites");

// I guess we silently fail?
if (TryGetModDependenciesFileNames(modFileName, out List<string> dependenciesFileNames)) {
foreach (string dependenciesFileName in dependenciesFileNames) {
addToFavoritesDependencies(dependenciesFileName, modFileName);
Expand All @@ -511,7 +510,7 @@ private void addToFavoritesDependencies(string modFileName, string dependentModF
Logger.Log(LogLevel.Verbose, "OuiModToggler", $"{modFileName} was added as a favorite dependency of {dependentModFileName}");


// we want to add A as the favorite mod that is dependent on all of modFileName dependencies as well
// we want to walk the dependence graph and add all the sub-dependencies as dependencies of the original dependentModFileName
if (TryGetModDependenciesFileNames(modFileName, out List<string> dependenciesFileNames)) {
foreach (string dependencyFileName in dependenciesFileNames) {
addToFavoritesDependencies(dependencyFileName, dependentModFileName);
Expand Down Expand Up @@ -595,8 +594,8 @@ private bool TryGetModDependenciesFileNames(string modFilename, out List<string>
foreach (EverestModuleMetadata metadata in metadatas) {
// iterate over each loaded mod to ensure its present
foreach (string dependencyName in metadata.Dependencies.Select((dep) => dep.Name)) {
if (modNames.TryGetValue(dependencyName, out EverestModuleMetadata dependency)) {
dependenciesFileNames.Add(Path.GetFileName(dependency.PathArchive ?? dependency.PathDirectory));
if (modFilenameByModName.TryGetValue(dependencyName, out string dependencyFileName)) {
dependenciesFileNames.Add(dependencyFileName);
}
}
}
Expand Down
105 changes: 17 additions & 88 deletions Celeste.Mod.mm/Mod/UI/TextMenuExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1365,10 +1365,7 @@ public class SubMenuWithInputs : TextMenu.Item, IItemExt {
public bool IconOutline { get; set; }
public Vector2 Offset { get; set; }

private Func<bool> controllerModeCallback;

public SubMenuWithInputs(string text, char separator, VirtualButton[] buttons, Func<bool> controllerModeCallback) {
this.controllerModeCallback = controllerModeCallback;
public SubMenuWithInputs(string text, char separator, VirtualButton[] buttons) {

string[] parts = text.Split(separator);
Items = new object[parts.Length * 2 - 1];
Expand Down Expand Up @@ -1402,7 +1399,7 @@ public override void Render(Vector2 position, bool highlighted) {
VirtualButton virtualButton = item as VirtualButton;
MTexture buttonTexture = null;

if (controllerModeCallback()) {
if (Input.GuiInputController()) {
buttonTexture = Input.GuiButton(virtualButton, Input.PrefixMode.Attached);
} else if (virtualButton.Binding.Keyboard.Count > 0) {
buttonTexture = Input.GuiKey(virtualButton.Binding.Keyboard[0]);
Expand All @@ -1417,101 +1414,33 @@ public override void Render(Vector2 position, bool highlighted) {
}
}

// this is full of boilerplate code might be replaceable with DispatchProxy once we upgrade .NET
// https://learn.microsoft.com/en-us/dotnet/api/system.reflection.dispatchproxy?view=net-7.0
public class EaseInDecorator<T> : TextMenu.Item, IItemExt where T : TextMenu.Item, IItemExt {
private T inner;
private float uneasedAlpha;
private TextMenu containingMenu;

// TODO: this was copy pasted from EaseInSubHeaderExt, find a way to abstract away the EaseIn behavior
public class EaseInSubMenuWithInputs : SubMenuWithInputs {
public bool FadeVisible { get; set; } = true;
private float uneasedAlpha;

public EaseInDecorator(T inner, bool initiallyVisible, TextMenu containingMenu) {
this.inner = inner;
this.containingMenu = containingMenu;

public EaseInSubMenuWithInputs(
string text,
char separator,
VirtualButton[] buttons,
bool initiallyVisible
) : base(text, separator, buttons) {
FadeVisible = initiallyVisible;
Alpha = FadeVisible ? 1 : 0;
uneasedAlpha = Alpha;
}

public Color TextColor { get => inner.TextColor; set => inner.TextColor = value; }
public string Icon { get => inner.Icon; set => inner.Icon = value; }
public float? IconWidth { get => inner.IconWidth; set => inner.IconWidth = value; }
public bool IconOutline { get => inner.IconOutline; set => inner.IconOutline = value; }
public Vector2 Offset { get => inner.Offset; set => inner.Offset = value; }
public float Alpha { get => inner.Alpha; set => inner.Alpha = value; }
new public bool Selectable { get => inner.Selectable; set => inner.Selectable = value; }
new public bool Visible { get => inner.Visible; set => inner.Visible = value; }

new public bool Disabled { get => inner.Disabled; set => inner.Disabled = value; }
new public bool IncludeWidthInMeasurement { get => inner.IncludeWidthInMeasurement; set => inner.IncludeWidthInMeasurement = value; }
new public bool AboveAll { get => inner.AboveAll; set => inner.AboveAll = value; }
new public TextMenu Container { get => inner.Container; set => inner.Container = value; }
new public Wiggler SelectWiggler { get => inner.SelectWiggler; set => inner.SelectWiggler = value; }
new public Wiggler ValueWiggler { get => inner.ValueWiggler; set => inner.ValueWiggler = value; }
new public Action OnEnter { get => inner.OnEnter; set => inner.OnEnter = value; }
new public Action OnLeave { get => inner.OnLeave; set => inner.OnLeave = value; }
new public Action OnPressed { get => inner.OnPressed; set => inner.OnPressed = value; }
new public Action OnAltPressed { get => inner.OnAltPressed; set => inner.OnAltPressed = value; }
new public Action OnUpdate { get => inner.OnUpdate; set => inner.OnUpdate = value; }


new public float Width => inner.Width;

new public bool Hoverable => inner.Hoverable;


public override void Added() {
inner.Added();
}

public new TextMenu.Item AltPressed(Action onPressed) {
return inner.AltPressed(onPressed);
}

public override void ConfirmPressed() {
inner.ConfirmPressed();
}

public new TextMenu.Item Enter(Action onEnter) {
return inner.Enter(onEnter);
}

public override float Height() {
return MathHelper.Lerp(-containingMenu.ItemSpacing, inner.Height(), inner.Alpha);
}

public new TextMenu.Item Leave(Action onLeave) {
return inner.Leave(onLeave);
}

public override void LeftPressed() {
inner.LeftPressed();
}

public override float LeftWidth() {
return inner.LeftWidth();
}

public new TextMenu.Item Pressed(Action onPressed) {
return inner.Pressed(onPressed);
}

public override void Render(Vector2 position, bool highlighted) {
inner.Render(position, highlighted);
}

public override void RightPressed() {
inner.RightPressed();
}
if (Container != null) {
return MathHelper.Lerp(-Container.ItemSpacing, base.Height(), Alpha);
} else {
return base.Height();
}

public override float RightWidth() {
return inner.RightWidth();
}

public override void Update() {
inner.Update();
base.Update();

// gradually make the sub-header fade in or out. (~333ms fade)
float targetAlpha = FadeVisible ? 1 : 0;
Expand Down

0 comments on commit 1df6495

Please sign in to comment.