This repository has been archived by the owner on Nov 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.Skins.cs
97 lines (77 loc) · 1.96 KB
/
Main.Skins.cs
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
using System.Collections.Generic;
using System.Linq;
using Godot;
public partial class Main
{
[Export]
SkinViewer SkinViewer;
[Export]
ItemList SkinList;
List<(MinecraftSkin skin, ImageTexture tex)> Skins = new();
async void SkinsMain()
{
var p = Profiles.First();
SkinList.Clear();
foreach (var s in p.MCProfile.Skins)
{
var ss = await WebCache.Get(s.Url);
var tex = ss.LoadTexture("png");
var i = SkinList.AddItem(s.Alias);
SkinList.SetItemIcon(i, tex);
Skins.Add((s, tex));
}
{
var i = SkinList.AddItem("Reset Skin");
SkinList.SetItemIcon(i, NewInstanceIcon);
}
{
var i = SkinList.AddItem("Upload Skin");
SkinList.SetItemIcon(i, NewInstanceIcon);
}
}
void OnSkinSelected(int i)
{
if (i < 0 || i >= Skins.Count) return;
var s = Skins[i];
SkinViewer.ShowSkin(s.skin, s.tex);
}
async void OnSkinActivated(int i)
{
if (i < 0 || i >= Skins.Count)
{
if (i == Skins.Count)
{
GD.Print("Reset");
}
else if (i == Skins.Count + 1)
{
GD.Print("Upload");
var fd = new FileDialog();
fd.FileMode = FileDialog.FileModeEnum.OpenFile;
fd.Access = FileDialog.AccessEnum.Filesystem;
fd.Filters = new string[] {"*.png"};
AddChild(fd);
fd.Popup(new Rect2I(Vector2I.Zero, DisplayServer.WindowGetSize()));
string variant = MinecraftSkin.VariantClassic;
var vb = fd.AddButton("Variant: CLASSIC", true, "chgange_variant");
fd.CustomAction += (StringName act) =>
{
if(act != "chgange_variant") return;
var isSlim = variant == MinecraftSkin.VariantSlim;
variant = isSlim ? MinecraftSkin.VariantClassic : MinecraftSkin.VariantSlim;
vb.Text = "Variant: " + variant;
};
fd.FileSelected += async (string f) =>
{
GD.Print(f);
var fs = System.IO.File.OpenRead(f);
var p = Profiles.First();
await Minecraft.UploadSkin(p.MCToken, variant, fs);
};
}
return;
};
var s = Skins[i];
SkinViewer.ShowSkin(s.skin, s.tex);
}
}