Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0098c3d
Made saves be stored in Userpath\Saves. Ability to rename save files in
Mar 28, 2024
443e76f
Better keyboard functionality. Made InputField more portable
Mar 28, 2024
2afc94d
Added on screen keyboard for renaming saves
Mar 28, 2024
2e4e191
Merge branch 'dev' into better_saves
echoslabs Mar 30, 2024
084d84b
Fixed crash when renaming file to one that already exists
Mar 30, 2024
ceeffb3
Fix spelling of ControllerConfirm
axiand Mar 31, 2024
0d2176d
Fix missing directory error for first launch
axiand Mar 31, 2024
a6a327d
Refactor: Centralize text input handling in OnScreenKeyboardMenu
axiand Mar 31, 2024
a81e471
Reorder pushing and adding menu items, also format
axiand Mar 31, 2024
5fe86be
Fix typo, catch errors during file rename
axiand Mar 31, 2024
4c20d3e
Show user-friendly error message for rename failure. Handle deletion …
axiand Mar 31, 2024
1fd2406
Adjust loc strings, make files when loading if they don't exist yet
axiand Mar 31, 2024
63d5c73
Adjust strings again
axiand Mar 31, 2024
56c4b1d
Convert some hard-coded strings to loc keys
axiand Mar 31, 2024
4900f23
Resolve warnings in keyboard handler
axiand Mar 31, 2024
311ac91
quick fix: prevent cancel button from interrupting
axiand Apr 1, 2024
84d5cca
Add basic instructions for the keyboard
axiand Apr 1, 2024
f7de62d
Merge branch 'better_saves' of https://github.com/echoslabs/FujiFork …
Apr 1, 2024
0c8c57c
Fixed problem with level card moving while paused Removed ContollerCo…
Apr 1, 2024
f4be342
Added more dictionaries for keys.Allows onscreenkeybaord to have more…
Apr 1, 2024
3a0b66d
Changed defualt keyboard type back to all keys
Apr 1, 2024
cdeb70a
fix save file bug, also im making this commit on the site so someone …
axiand Apr 2, 2024
cdc9128
Changing save rename keyboard to restrict to alphanumeric keys
jasminegamedev Apr 2, 2024
ac0997d
Merge branch 'dev' into pr/75
jasminegamedev Apr 2, 2024
85b0806
Fixed problem with space showing " " instead of word Space
Apr 3, 2024
9fcafe6
Merge branch 'dev' into pr/75
jasminegamedev May 1, 2024
dc15d9e
Deleting extra icons
jasminegamedev May 1, 2024
fb8503a
Merge branch 'dev' into better_saves
jasminegamedev Jun 25, 2024
5a5e62c
Updating to work with new controls system
jasminegamedev Jun 25, 2024
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
10 changes: 8 additions & 2 deletions Content/Text/English.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"Create": "Create",
"Delete": "Delete",
"Copy": "Copy",
"Rename": "Rename",
"NewName": "New Name",
"Bind": "Bind",
"Reset": "Reset",
"Clear": "Clear",
Expand Down Expand Up @@ -95,8 +97,11 @@
"Skin.desc": "Choose a Skin to Wear",
"SaveCreateFile": "Create new file?",
"SaveDeleteFile": "Delete this file?",
"SaveDeleteDefaultFile": "Cannot fully delete default save file:'{0}'. Reset it to default instead?",
"SaveDeleteDefaultFile": "The file {0} cannot be deleted.\n\nThis may happen because the file is the only existing file,\nor because it is currently loaded.\n\nDo you want to reset to the default file instead?",
"SaveCopyFile": "Copy this file?",
"SaveRenameFile": "Renaming file: {0}",
"SaveRenameFailed": "Failed to rename... Check your log file for details\n(does the file already exist?)",
"OSKUserInstructions": "Press Enter on keyboard, or Back on controller to confirm.",
"FujiOptions": "Fuji Options...",
"FujiOptions.desc": "Configure Options for the Fuji Mod Loader",
"FujiWriteLog": "Write Log File",
Expand All @@ -122,7 +127,8 @@
"ModOptions": "Mod Options",
"ConfirmDisableMod": "Continue & Disable Mod",
"ModSafeDisableErrorMessage": "This mod can't be disabled because it would disable the level you're currently in.\nTry going to the main menu first.",
"QuitToMainMenu": "Quit to Main Menu"
"QuitToMainMenu": "Quit to Main Menu",
"KeyboardSpace": "Space"
},
"Dialog": {
"Granny1": [
Expand Down
7 changes: 5 additions & 2 deletions Source/Data/Controls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace Celeste64;
[DisallowHooks]
public static class Controls
{

#region Default Controls
[DefaultStickBinding(StickDirection.Up, Keys.Up)]
[DefaultStickBinding(StickDirection.Up, Buttons.Up)]
Expand Down Expand Up @@ -95,6 +94,11 @@ public static class Controls
[DefaultBinding(Buttons.RightShoulder)]
public static VirtualButton CreateFile { get; private set; } = new("CreateFile");


[DefaultBinding(Keys.R)]
[DefaultBinding(Buttons.West)]
public static VirtualButton RenameFile { get; private set; } = new("RenameFile");

[DefaultBinding(Keys.V)]
[DefaultBinding(Buttons.LeftShoulder)]
public static VirtualButton ResetBindings { get; private set; } = new("ResetBindings");
Expand Down Expand Up @@ -503,7 +507,6 @@ internal static void ResetBinding(VirtualButton virtualButton, bool forControlle
internal static void ResetAllBindings(bool forController, GameMod? mod = null)
{
ControlsConfig_V01 config;
IEnumerable<ControlsConfigBinding> defaultBindings;
Type settingsType;
object? settingsObject;

Expand Down
6 changes: 3 additions & 3 deletions Source/Data/Save.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public static SkinInfo GetSkin()

public static void SaveToFile()
{
var savePath = Path.Join(App.UserPath, Instance.FileName);
var tempPath = Path.Join(App.UserPath, Instance.FileName + ".backup");
var savePath = Path.Join(App.UserPath, "Saves", Instance.FileName);
var tempPath = Path.Join(App.UserPath, "Saves", Instance.FileName + ".backup");

// first save to a temporary file
{
Expand All @@ -135,7 +135,7 @@ public static void SaveToFile()
internal static void LoadSaveByFileName(string fileName)
{
if (fileName == string.Empty) fileName = DefaultFileName;
var saveFile = Path.Join(App.UserPath, fileName);
var saveFile = Path.Join(App.UserPath, "Saves", fileName);

if (File.Exists(saveFile))
Instance = Instance.Deserialize<Save_V02>(File.ReadAllText(saveFile)) ?? new();
Expand Down
43 changes: 42 additions & 1 deletion Source/Helpers/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,47 @@ private static List<string> GetEnumOptions()
}
}

public class InputField : Item
{
public OnScreenKeyboardMenu keyboardMenu;

private Action<string> setter;
private Func<string> getter;

public Menu RootMenu { get; protected set; }

private string fieldText;
public override string Label => $"{LocString} : {getter()}";

public void SetFieldText(string text)
{
fieldText = text;
setter(fieldText);
}

public string GetFieldText()
{
return getter();
}

public override bool Pressed()
{
RootMenu.PushSubMenu(keyboardMenu);
return true;
}

public InputField(Loc.Localized locString, Action<string> set, Func<string> get, Menu rootMenu, Dictionary<string, string>? characters = null)
{
LocString = locString;
setter = set;
getter = get;
RootMenu = rootMenu;
fieldText = getter();
if (characters == null) characters = KeyboardHandler.AllCharactersList;
keyboardMenu = new OnScreenKeyboardMenu(rootMenu, this, characters);
}
}

public int Index;
public string Title = string.Empty;
public bool Focused = true;
Expand All @@ -298,7 +339,7 @@ private static List<string> GetEnumOptions()
public string DownSound = Sfx.ui_move;

public bool IsInMainMenu => submenus.Count <= 0;
protected Menu CurrentMenu => GetDeepestActiveSubmenu(this);
public Menu CurrentMenu => GetDeepestActiveSubmenu(this);

protected virtual int maxItemsCount { get; set; } = 12;
protected int scrolledAmount = 0;
Expand Down
79 changes: 59 additions & 20 deletions Source/Mod/Data/SaveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,65 @@ internal sealed class SaveManager
{
internal static SaveManager Instance = new();

[DisallowHooks]
internal string GetLastLoadedSave()
{
if (File.Exists(Path.Join(App.UserPath, "save.metadata")))
return File.ReadAllText(Path.Join(App.UserPath, "save.metadata"));
if (File.Exists(Path.Join(App.UserPath, "Saves", "save.metadata")))
return File.ReadAllText(Path.Join(App.UserPath, "Saves", "save.metadata"));
else
{
File.WriteAllText(Path.Join(App.UserPath, "save.metadata"), Save.DefaultFileName);
Directory.CreateDirectory(Path.Join(App.UserPath, "Saves")); // Perform upgrade path for first-time launch
File.WriteAllText(Path.Join(App.UserPath, "Saves", "save.metadata"), Save.DefaultFileName);
return Save.DefaultFileName;
}
}

[DisallowHooks]
internal void SetLastLoadedSave(string save_name)
{
if (File.Exists(Path.Join(App.UserPath, "save.metadata")))
File.WriteAllText(Path.Join(App.UserPath, "save.metadata"), save_name);
if (File.Exists(Path.Join(App.UserPath, "Saves", "save.metadata")))
File.WriteAllText(Path.Join(App.UserPath, "Saves", "save.metadata"), save_name);
}

[DisallowHooks]
internal List<string> GetSaves()
{
List<string> saves = new List<string>();

foreach (string savefile in Directory.GetFiles(App.UserPath))
foreach (string file in Directory.GetFiles(Path.Join(App.UserPath)))
{
string saveFileName = Path.GetFileName(file);
if (saveFileName.StartsWith("save") && saveFileName.EndsWith(".json"))
{
if (saveFileName == "save.json" && !Path.Exists(Path.Join(App.UserPath, "Saves", saveFileName)))
File.Copy(Path.Join(App.UserPath, saveFileName), Path.Join(App.UserPath, "Saves", saveFileName));
else if (!Path.Exists(Path.Join(App.UserPath, "Saves", saveFileName)))
File.Move(Path.Join(App.UserPath, saveFileName), Path.Join(App.UserPath, "Saves", saveFileName));
}
}

foreach (string savefile in Directory.GetFiles(Path.Join(App.UserPath, "Saves")))
{
var saveFileName = Path.GetFileName(savefile);
if (saveFileName.EndsWith(".json") && saveFileName.StartsWith("save"))
if (saveFileName.EndsWith(".json"))
saves.Add(saveFileName);
}

return saves;
}

[DisallowHooks]
internal void CopySave(string filename)
{
if (File.Exists(Path.Join(App.UserPath, filename)))
if (File.Exists(Path.Join(App.UserPath, "Saves", filename)))
{
string new_file_name = $"{filename.Split(".json")[0]}(copy).json";
File.Copy(Path.Join(App.UserPath, filename), Path.Join(App.UserPath, new_file_name));
File.Copy(Path.Join(App.UserPath, "Saves", filename), Path.Join(App.UserPath, "Saves", new_file_name));
}
}

[DisallowHooks]
internal void NewSave(string? name = null)
{
if (string.IsNullOrEmpty(name)) name = $"save_{GetSaveCount()}.json";
var savePath = Path.Join(App.UserPath, name);
var tempPath = Path.Join(App.UserPath, name + ".backup");
var savePath = Path.Join(App.UserPath, "Saves", name);
var tempPath = Path.Join(App.UserPath, "Saves", name + ".backup");

// first save to a temporary file
{
Expand All @@ -69,18 +78,45 @@ internal void NewSave(string? name = null)
}
}

[DisallowHooks]
internal bool ChangeFileName(string originalFileName, string newFileName)
{
bool success = true;

foreach (string file in GetSaves())
{
if (file == originalFileName)
{
try
{
if (!newFileName.EndsWith(".json"))
newFileName += ".json";
File.Move(Path.Join(App.UserPath, "Saves", file), Path.Join(App.UserPath, "Saves", newFileName));
if (file == Save.Instance.FileName)
LoadSaveByFileName(newFileName);
}
catch (Exception e)
{
Log.Error($"Failed to rename save file {originalFileName} to {newFileName}");
Log.Error(e.ToString());

success = false;
}
}
}

return success;
}

internal int GetSaveCount()
{
return GetSaves().Count;
}

[DisallowHooks]
internal void DeleteSave(string save)
{
if (File.Exists(Path.Join(App.UserPath, save)))
if (File.Exists(Path.Join(App.UserPath, "Saves", save)))
{
File.Delete(Path.Join(App.UserPath, save));
File.Delete(Path.Join(App.UserPath, "Saves", save));
}

if (save == Save.DefaultFileName)
Expand All @@ -89,9 +125,12 @@ internal void DeleteSave(string save)
}
}

[DisallowHooks]
internal void LoadSaveByFileName(string fileName)
{
if (!GetSaves().Contains(fileName)) // Make file if it doesn't exist yet
{
NewSave(fileName);
}
Save.LoadSaveByFileName(fileName);
Instance.SetLastLoadedSave(fileName);
}
Expand Down
1 change: 1 addition & 0 deletions Source/Mod/Menu/ControlsMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public ControlsMenu(Menu? rootMenu, bool isForController)
Add(new InputBind(Controls.CopyFile.Name, Controls.CopyFile, rootMenu, isForController) { RequiresBinding = true });
Add(new InputBind(Controls.CreateFile.Name, Controls.CreateFile, rootMenu, isForController) { RequiresBinding = true });
Add(new InputBind(Controls.DeleteFile.Name, Controls.DeleteFile, rootMenu, isForController) { RequiresBinding = true });
Add(new InputBind(Controls.RenameFile.Name, Controls.RenameFile, rootMenu, isForController) { RequiresBinding = true });
Add(new InputBind(Controls.ResetBindings.Name, Controls.ResetBindings, rootMenu, isForController) { RequiresBinding = true });
Add(new InputBind(Controls.ClearBindings.Name, Controls.ClearBindings, rootMenu, isForController) { RequiresBinding = true });
Add(new InputBind(Controls.Menu.Name + "Up", Controls.Menu.Vertical.Negative, rootMenu, isForController) { DeadZone = 0.5f, RequiresBinding = true });
Expand Down
Loading