Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to show true LastArea in FileSelect #811

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion Celeste.Mod.mm/Content/Dialog/English.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@
MODOPTIONS_COREMODULE_WARNONEVERESTYAMLERRORS= Warn On everest.yaml Errors
MODOPTIONS_COREMODULE_WARNONEVERESTYAMLERRORS_DESC= Useful for mod makers
MODOPTIONS_COREMODULE_COLORIZEDLOGGING= Colorized Console Logging
MODOPTIONS_COREMODULE_COLORIZEDLOGGING_DESC= Useful for mod developers
MODOPTIONS_COREMODULE_COLORIZEDLOGGING_DESC= Useful for mod developers
MODOPTIONS_COREMODULE_TRUELASTAREAINFILESELECT= Show True LastArea in FileSelect
MODOPTIONS_COREMODULE_TRUELASTAREAINFILESELECT_DESC= When a map is unavailable, show its SID instead of defaulting to Vanilla levels
MODOPTIONS_COREMODULE_MENUNAV_SUBHEADER= MENU NAVIGATION
MODOPTIONS_COREMODULE_MENUPAGEUP= Page Up in Menus
MODOPTIONS_COREMODULE_MENUPAGEDOWN= Page Down in Menus
Expand Down
4 changes: 4 additions & 0 deletions Celeste.Mod.mm/Mod/Core/CoreModuleSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ public bool ColorizedLogging {
}
}

[SettingSubText("MODOPTIONS_COREMODULE_TRUELASTAREAINFILESELECT_DESC")]
[SettingInGame(false)]
public bool TrueLastAreaInFileSelect { get; set; } = false;

// Keep in sync with https://github.com/EverestAPI/Olympus/blob/main/src/scenes/options.lua :: mirrorPreferences
public string MirrorPreferences { get; set; } = "gb,jade,otobot,wegfan";

Expand Down
39 changes: 39 additions & 0 deletions Celeste.Mod.mm/Patches/OuiFileSelectSlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,34 @@ public override void Render() {
}
}

public string GetFurthestAreaName() {
if (!CoreModule.Settings.TrueLastAreaInFileSelect || string.IsNullOrEmpty(SaveData.TrueLastAreaSID)) {
return Dialog.Clean(AreaData.Areas[FurthestArea].Name);
}

float maxSize = 580;
float fullnameExtraSize = ActiveFont.Measure('[').X + ActiveFont.Measure(']').X;
float truncatedExtraSize = 3f * ActiveFont.Measure('.').X + fullnameExtraSize;

int truncatedStart = SaveData.TrueLastAreaSID.Length;
float size = 0f;

while (truncatedStart > 0) {
float newSize = size + ActiveFont.Measure(SaveData.TrueLastAreaSID[truncatedStart - 1]).X;
if (newSize + truncatedExtraSize > maxSize)
break;
size = newSize;
truncatedStart -= 1;
}

for (int i = 0; i < truncatedStart; i++) {
size += ActiveFont.Measure(SaveData.TrueLastAreaSID[i]).X;
if (size + fullnameExtraSize > maxSize)
return "[..." + SaveData.TrueLastAreaSID[truncatedStart..] + "]";
}
return "[" + SaveData.TrueLastAreaSID + "]";
}

// very similar to MoveTo, except the easing is different if the slot was already moving.
// used for scrolling, since using MoveTo can look weird if holding up or down in file select.
internal void ScrollTo(float x, float y) {
Expand Down Expand Up @@ -350,6 +378,7 @@ public static void PatchFileSelectSlotRender(ILContext context, CustomAttribute
FieldDefinition f_totalGoldenStrawberries = declaringType.FindField("totalGoldenStrawberries");
FieldDefinition f_totalHeartGems = declaringType.FindField("totalHeartGems");
FieldDefinition f_totalCassettes = declaringType.FindField("totalCassettes");
MethodDefinition m_GetFurthestAreaName = declaringType.FindMethod("GetFurthestAreaName");

ILCursor cursor = new ILCursor(context);
// SaveData.TotalStrawberries replaced by SaveData.TotalStrawberries_Safe with MonoModLinkFrom
Expand Down Expand Up @@ -407,6 +436,16 @@ public static void PatchFileSelectSlotRender(ILContext context, CustomAttribute
cursor.RemoveRange(8);
// Replace with `this.farewellStamp`
cursor.Emit(OpCodes.Ldfld, f_farewellStamp);

// Replace Dialog.Clean(AreaData.Areas[FurthestArea].Name)
cursor.GotoNext(instr => instr.MatchLdfld("Celeste.AreaData", "Name"),
instr => instr.MatchLdnull(),
instr => instr.MatchCall("Celeste.Dialog", "Clean"));
cursor.Index -= 4;
cursor.RemoveRange(7);
// Replace with this.GetFurthestAreaName()
cursor.Emit(OpCodes.Ldarg_0);
cursor.Emit(OpCodes.Callvirt, m_GetFurthestAreaName);
}

public static void PatchOuiFileSelectSlotOnContinueSelected(ILContext context, CustomAttribute attrib) {
Expand Down
7 changes: 6 additions & 1 deletion Celeste.Mod.mm/Patches/SaveData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public LevelSetStats LevelSetStats {
[MonoModLinkFrom("Celeste.AreaKey Celeste.SaveData::LastArea")]
public AreaKey LastArea_Safe;

[XmlIgnore]
public string TrueLastAreaSID = null;

// We want use CurrentSession_Safe instead of CurrentSession to avoid breaking vanilla Celeste.

[MonoModLinkFrom("Celeste.Session Celeste.SaveData::CurrentSession_Unsafe")]
Expand Down Expand Up @@ -499,8 +502,10 @@ public static bool TryDeleteModSaveData(int slot) {
CurrentSession_Unsafe = null;

// Fix areas with missing SID (f.e. deleted or renamed maps).
if (AreaData.Get(LastArea) == null)
if (AreaData.Get(LastArea) == null) {
TrueLastAreaSID = LastArea.GetSID();
LastArea = AreaKey.Default;
}

// Fix out of bounds areas.
if (LastArea.ID < 0 || LastArea.ID >= AreaData.Areas.Count)
Expand Down