|
| 1 | +package funkin.ui.options; |
| 2 | + |
| 3 | +#if FEATURE_NEWGROUNDS |
| 4 | +import funkin.api.newgrounds.NewgroundsClient; |
| 5 | +#end |
| 6 | +import funkin.ui.Page.PageName; |
| 7 | + |
| 8 | +/** |
| 9 | + * Our default Page when we enter the OptionsState, a bit of the root |
| 10 | + */ |
| 11 | +class SaveDataMenu extends Page<OptionsState.OptionsMenuPageName> |
| 12 | +{ |
| 13 | + var items:TextMenuList; |
| 14 | + |
| 15 | + public function new() |
| 16 | + { |
| 17 | + super(); |
| 18 | + |
| 19 | + add(items = new TextMenuList()); |
| 20 | + |
| 21 | + #if FEATURE_NEWGROUNDS |
| 22 | + if (NewgroundsClient.instance.isLoggedIn()) |
| 23 | + { |
| 24 | + createItem("LOAD FROM NEWGROUNDS", function() { |
| 25 | + openConfirmPrompt("This will overwrite |
| 26 | + \nALL your save data. |
| 27 | + \nAre you sure? |
| 28 | + ", "Overwrite", function() { |
| 29 | + funkin.save.Save.instance.loadFromNewgrounds(); |
| 30 | + |
| 31 | + FlxG.switchState(() -> new funkin.InitState()); |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + createItem("SAVE TO NEWGROUNDS", function() { |
| 36 | + openConfirmPrompt("This will overwrite |
| 37 | + \nALL save data saved |
| 38 | + \non Newgrounds. |
| 39 | + \nAre you sure? |
| 40 | + ", "Overwrite", function() { |
| 41 | + funkin.save.Save.instance.saveToNewgrounds(); |
| 42 | + }); |
| 43 | + }); |
| 44 | + } |
| 45 | + #end |
| 46 | + |
| 47 | + createItem("CLEAR SAVE DATA", function() { |
| 48 | + openConfirmPrompt("This will delete |
| 49 | + \nALL your save data. |
| 50 | + \nAre you sure? |
| 51 | + ", "Delete", function() { |
| 52 | + // Clear the save data. |
| 53 | + funkin.save.Save.clearData(); |
| 54 | + |
| 55 | + FlxG.switchState(() -> new funkin.InitState()); |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + createItem("EXIT", exit); |
| 60 | + } |
| 61 | + |
| 62 | + function createItem(name:String, callback:Void->Void, fireInstantly = false) |
| 63 | + { |
| 64 | + var item = items.createItem(0, 100 + items.length * 100, name, BOLD, callback); |
| 65 | + item.fireInstantly = fireInstantly; |
| 66 | + item.screenCenter(X); |
| 67 | + return item; |
| 68 | + } |
| 69 | + |
| 70 | + override function update(elapsed:Float) |
| 71 | + { |
| 72 | + enabled = (prompt == null); |
| 73 | + super.update(elapsed); |
| 74 | + } |
| 75 | + |
| 76 | + override function set_enabled(value:Bool) |
| 77 | + { |
| 78 | + items.enabled = value; |
| 79 | + return super.set_enabled(value); |
| 80 | + } |
| 81 | + |
| 82 | + var prompt:Prompt; |
| 83 | + |
| 84 | + function openConfirmPrompt(text:String, yesText:String, onYes:Void->Void):Void |
| 85 | + { |
| 86 | + if (prompt != null) return; |
| 87 | + |
| 88 | + prompt = new Prompt(text, Custom(yesText, "Cancel")); |
| 89 | + prompt.create(); |
| 90 | + prompt.createBgFromMargin(100, 0xFFFAFD6D); |
| 91 | + prompt.back.scrollFactor.set(0, 0); |
| 92 | + add(prompt); |
| 93 | + |
| 94 | + prompt.onYes = function() { |
| 95 | + onYes(); |
| 96 | + |
| 97 | + if (prompt != null) |
| 98 | + { |
| 99 | + prompt.close(); |
| 100 | + prompt.destroy(); |
| 101 | + prompt = null; |
| 102 | + } |
| 103 | + }; |
| 104 | + |
| 105 | + prompt.onNo = function() { |
| 106 | + prompt.close(); |
| 107 | + prompt.destroy(); |
| 108 | + prompt = null; |
| 109 | + } |
| 110 | + } |
| 111 | +} |
0 commit comments