-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCustomAssetPreview.cs
More file actions
206 lines (191 loc) · 8.26 KB
/
Copy pathCustomAssetPreview.cs
File metadata and controls
206 lines (191 loc) · 8.26 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
namespace CustomStreamMaker
{
public partial class CustomAssetPreview : Form
{
internal StreamEditor streamEditor;
List<CustomAsset> assetList;
CustomAsset currentPreview;
bool isDeleting;
bool isSearchTouched;
public CustomAssetPreview(StreamEditor streamEditor)
{
assetList = CustomAssetExtractor.customAssets;
InitializeComponent();
isSearchTouched = false;
this.streamEditor = streamEditor;
}
internal void ReloadAssetListView(string searchTxt = null)
{
int i;
string searcher;
CustomAssetType filter = CustomAssetType.None;
CustomAssetsListView.BeginUpdate();
CustomAssetsListView.Items.Clear();
for (i = 0; i < assetList.Count; i++)
{
var filePath = assetList[i].filePath.Replace("?", "");
ListViewItem item = CustomAssetsListView.Items.Add(assetList[i].customAssetType.ToString());
item.SubItems.Add(assetList[i].fileName);
item.SubItems.Add(filePath);
}
if (!string.IsNullOrWhiteSpace(searchTxt))
{
if (searchTxt.StartsWith("s:"))
{
searcher = searchTxt.Substring(0, 2);
filter = CustomAssetType.Sprite;
searchTxt = searchTxt.Replace(searcher, "");
}
else if (searchTxt.StartsWith("b:"))
{
searcher = searchTxt.Substring(0, 2);
filter = CustomAssetType.Background;
searchTxt = searchTxt.Replace(searcher, "");
}
for (i = CustomAssetsListView.Items.Count - 1; i >= 0; i--)
{
if (filter != CustomAssetType.None && filter.ToString() != CustomAssetsListView.Items[i].SubItems[0].Text)
{
CustomAssetsListView.Items[i].Remove();
continue;
}
if (!CustomAssetsListView.Items[i].SubItems[1].Text.Contains(searchTxt) && !string.IsNullOrWhiteSpace(searchTxt))
{
CustomAssetsListView.Items[i].Remove();
}
}
}
CustomAssetsListView.EndUpdate();
}
private void CustomAssetPreview_Load(object sender, EventArgs e)
{
ReloadAssetListView();
SearchBar.Text = "Search Here";
}
private void DisablePreview()
{
CustomAssetsPreviewPic.Image = null;
currentPreview = null;
}
private void DeleteSelected()
{
var path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\CustomStreamMaker\CustomAnimationClips";
if (CustomAssetsListView.SelectedItems.Count == 0)
return;
for (int i = 0; i <= CustomAssetsListView.SelectedItems.Count; i++)
{
if (CustomAssetsListView.SelectedItems.Count == 0) break;
isDeleting = true;
i = 0;
var item = CustomAssetsListView.SelectedItems[0];
CustomAsset selectedAsset = assetList.Find(a => a.filePath == item.SubItems[2].Text
&& a.fileName == item.SubItems[1].Text
&& a.customAssetType == (CustomAssetType)Enum.Parse(typeof(CustomAssetType), item.SubItems[0].Text));
if (currentPreview == selectedAsset)
{
CustomAssetsPreviewPic.Image?.Dispose();
DisablePreview();
}
var bundleName = Path.GetFileNameWithoutExtension(selectedAsset.filePath);
var pathToCache = Path.Combine(path, bundleName, selectedAsset.fileName);
if (selectedAsset.customAssetFileType != CustomAssetFileType.ImageFile && File.Exists(pathToCache))
File.Delete(Path.Combine(path, bundleName, selectedAsset.fileName));
assetList.Remove(selectedAsset);
CustomAssetsListView.Items.Remove(item);
}
streamEditor.CheckUnvalidCustomAssets();
CustomAssetExtractor.CheckForEmptyAnimFolder();
CustomAssetExtractor.SaveCustomAssets();
isDeleting = false;
}
private void DeleteCachedAssetIfSprite(CustomAsset customAsset)
{
if (customAsset.customAssetType != CustomAssetType.Sprite)
return;
var customPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\CustomStreamMaker\CustomAnimationClips";
var filePathToSprite = Path.Combine(customPath, Path.GetFileNameWithoutExtension(customAsset.filePath), customAsset.fileName);
if (!File.Exists(filePathToSprite))
return;
File.Delete(filePathToSprite);
}
private void CustomAssetsListView_SelectedIndexChanged(object sender, EventArgs e)
{
if (isDeleting)
return;
CustomAssetsPreviewPic.Image?.Dispose();
if (CustomAssetsListView.SelectedItems.Count == 0)
{
DisablePreview();
return;
}
var item = CustomAssetsListView.SelectedItems[0];
CustomAsset selectedAsset = assetList.Find(a => a.filePath == item.SubItems[2].Text
&& a.fileName == item.SubItems[1].Text
&& a.customAssetType == (CustomAssetType)Enum.Parse(typeof(CustomAssetType), item.SubItems[0].Text));
if (selectedAsset != null)
{
if (selectedAsset.customAssetType == CustomAssetType.Background)
{
CustomAssetsPreviewPic.Image = AssetExtractor.GetCachedBackground(selectedAsset.fileName);
}
else CustomAssetsPreviewPic.Image = AssetExtractor.GetCachedSprite(selectedAsset.fileName);
currentPreview = selectedAsset;
}
else { currentPreview = null; }
}
private void CustomAssetsListView_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
var confirm = MessageBox.Show("Are you sure you want to delete these assets?\nThis action can't be undone.", "Wait!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (confirm != DialogResult.Yes)
return;
DeleteSelected();
}
}
private void CustomAssetPreview_Click(object sender, EventArgs e)
{
CustomAssetsListView.SelectedIndices.Clear();
}
private void AddBackground_Button_Click(object sender, EventArgs e)
{
CustomAssetExtractor.ImportImage();
ReloadAssetListView();
}
private void AddAnimation_AssetLz4_Click(object sender, EventArgs e)
{
CustomAssetExtractor.ImportSpriteFromAssetBundle(true);
ReloadAssetListView();
}
private void AddAnimation_AddressableLz4_Click(object sender, EventArgs e)
{
CustomAssetExtractor.ImportSpriteFromAddressable(true);
ReloadAssetListView();
}
private void CustomAssetPreview_FormClosing(object sender, FormClosingEventArgs e)
{
CustomAssetExtractor.SaveCustomAssets();
streamEditor.customAssetPreview = null;
Dispose();
}
private void SearchBar_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
ReloadAssetListView(SearchBar.Text);
}
}
private void SearchBar_Enter(object sender, EventArgs e)
{
if (!isSearchTouched)
{
isSearchTouched = true;
SearchBar.Text = string.Empty;
}
}
}
}