Skip to content

Commit

Permalink
docs(WelcomeScreen): Explain the loading exception (#351)
Browse files Browse the repository at this point in the history
People were asking what to do when the mod fails to load, so I explained
it some more in this change.
The reasonings behind the changes are explained in the commit messages. 

The change that _might_ break the popup is the removal of `gui.allocator
= RectAllocator.LeftAlign;` in
02170b9.
I tested the resulting popup, so it's unlikely that it would break as
the error-window size is constant, from what I understand.

This PR closes #342.
  • Loading branch information
shpaass authored Nov 9, 2024
2 parents 6a8cd05 + 758cec3 commit ae5dbb2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Yafc.UI/ImGui/ImGuiBuilding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public void BuildText(string? text, TextBlockDisplayStyle? displayStyle = null,
}
}

public void BuildWrappedText(string text) => BuildText(text, TextBlockDisplayStyle.WrappedText);

public Vector2 GetTextDimensions(out TextCache? cache, string? text, Font? font = null, bool wrap = false, float maxWidth = float.MaxValue) {
if (string.IsNullOrEmpty(text)) {
cache = null;
Expand Down
40 changes: 24 additions & 16 deletions Yafc/Windows/WelcomeScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,30 @@ protected override void BuildContents(ImGui gui) {
}
else if (errorMessage != null) {
errorScroll.Build(gui);
bool thereIsAModToDisable = (errorMod != null);

using (gui.EnterRow()) {
if (thereIsAModToDisable) {
gui.BuildWrappedText("YAFC was unable to load the project. You can disable the problematic mod once by clicking on 'Disable & reload' button, or you can disable it " +
"permanently for YAFC by copying the mod-folder, disabling the mod in the copy by editing mod-list.json, and pointing YAFC to the copy.");
}
else {
gui.BuildWrappedText("YAFC cannot proceed because it was unable to load the project.");
}
}

using (gui.EnterRow()) {
gui.BuildText("This error is critical. Unable to load project.");
if (gui.BuildLink("More info")) {
ShowDropDown(gui, gui.lastRect, ProjectErrorMoreInfo, new Padding(0.5f), 30f);
}
}

using (gui.EnterRow()) {
if (gui.BuildButton("Copy to clipboard", SchemeColor.Grey)) {
_ = SDL.SDL_SetClipboardText(errorMessage);
}
if (errorMod != null && gui.BuildButton("Disable & reload").WithTooltip(gui, "Disable this mod until you close YAFC or change the mod folder.")) {
FactorioDataSource.DisableMod(errorMod);
if (thereIsAModToDisable && gui.BuildButton("Disable & reload").WithTooltip(gui, "Disable this mod until you close YAFC or change the mod folder.")) {
FactorioDataSource.DisableMod(errorMod!);
errorMessage = null;
LoadProject();
}
Expand Down Expand Up @@ -202,24 +214,20 @@ protected override void BuildContents(ImGui gui) {
}

private void ProjectErrorMoreInfo(ImGui gui) {
gui.allocator = RectAllocator.LeftAlign;
gui.BuildText("Check that these mods load in Factorio", TextBlockDisplayStyle.WrappedText);

string factorioLoadedPassage = "YAFC only supports loading mods that were loaded in Factorio before. If you add or remove mods or change startup settings, " +
"you need to load those in Factorio and then close the game because Factorio writes some files only when exiting";
gui.BuildText(factorioLoadedPassage, TextBlockDisplayStyle.WrappedText);
gui.BuildText("Check that Factorio loads mods from the same folder as YAFC", TextBlockDisplayStyle.WrappedText);
gui.BuildWrappedText("Check that these mods load in Factorio.");
gui.BuildWrappedText("YAFC only supports loading mods that were loaded in Factorio before. If you add or remove mods or change startup settings, " +
"you need to load those in Factorio and then close the game because Factorio saves mod-list.json only when exiting.");
gui.BuildWrappedText("Check that Factorio loads mods from the same folder as YAFC.");
gui.BuildWrappedText("If that doesn't help, try removing the mods that have several versions, or are disabled, or don't have the required dependencies.");

string modRemovalPassage = "If that doesn't help, try removing all the mods that are present but aren't loaded because they are disabled, " +
"don't have required dependencies, or (especially) have several versions";
gui.BuildText(modRemovalPassage, TextBlockDisplayStyle.WrappedText);

if (gui.BuildLink("If that doesn't help either, create a github issue")) {
// The whole line is underlined if the allocator is not set to LeftAlign
gui.allocator = RectAllocator.LeftAlign;
if (gui.BuildLink("If all else fails, then create an issue on GitHub")) {
Ui.VisitLink(AboutScreen.Github);
}

string gameSavePassage = "For these types of errors simple mod list will not be enough. You need to attach a 'New game' save game for syncing mods, mod versions and mod settings.";
gui.BuildText(gameSavePassage, TextBlockDisplayStyle.WrappedText);
gui.BuildWrappedText("Please attach a new-game save file to sync mods, versions, and settings.");
}

private static void DoLanguageList(ImGui gui, Dictionary<string, string> list, bool enabled) {
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Date:
- (SA) Add support for the capture-spawner technology trigger.
- Add the remaining research triggers and the mining-with-fluid research effect to the dependency/milestone
analysis.
- Explain what to do if Yafc fails to load a mod.
Internal changes:
- Using the LuaContext after it is freed now produces a better error.
----------------------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit ae5dbb2

Please sign in to comment.