1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
| using Godot; using System.Collections.Generic; using System.Linq;
public partial class Archives : Node2D { private List<string> SaveFiles; private int SaveFileIndex = 25; public override void _Ready() {
var HFContainer = new HFlowContainer { Name = "HFlowContainer" }; HFContainer.Size = new Vector2(1600, 800); HFContainer.SetPosition(new Vector2(130, 180)); AddChild(HFContainer);
SaveFiles = GetSaveFiles().Take(SaveFileIndex).ToList();
for (int i = 0; i < 25; i++) { string ButtonName = "空存档"; if (i < SaveFiles.Count()){ ButtonName = SaveFiles[i]; } var button = new Button { Text = ButtonName }; button.SetCustomMinimumSize(new Vector2(300, 170)); HFContainer.AddChild(button); }
} public void ChangeScrollBarLong(){ var scrollContainer = GetNode<HScrollBar>("HScrollBar"); scrollContainer.MaxValue += 50; }
public async void SaveScrollBarChange(float value){
var HFlowContainer = GetNode<HFlowContainer>("HFlowContainer"); HFlowContainer.SetPosition(new Vector2(130, 180-value*20));
int level = (int)(value / 10); int NowLevel = SaveFileIndex / 10; GD.Print(level); GD.Print(NowLevel);
if (level > NowLevel) { SaveFileIndex+=5; for (int i = SaveFileIndex; i < SaveFileIndex+5; i++) { await ToSignal(GetTree().CreateTimer(0.3f), "timeout");
string ButtonName = "空存档"; if (i < SaveFiles.Count()){ ButtonName = SaveFiles[i]; } var button = new Button { Text = ButtonName }; button.SetCustomMinimumSize(new Vector2(300, 170)); HFlowContainer.AddChild(button); } } }
public override void _Process(double delta) { }
private static List<string> GetSaveFiles() { using var dir = DirAccess.Open("user://save");
string[] files = dir.GetFiles(); List<string> fileList = new List<string>(files);
fileList.RemoveAll(file => !file.EndsWith(".res")); return fileList; } }
|