This repository has been archived by the owner on Jul 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpriteLib.xaml.cs
125 lines (105 loc) · 3.8 KB
/
SpriteLib.xaml.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
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace RustGuiEditor
{
/// <summary>
/// Логика взаимодействия для SpriteLib.xaml
/// </summary>
public partial class SpriteLib : Window
{
private List<string> sprites = new List<string>();
public string SpritePath { get; private set; }
public static string FromGameToLocal(string gamePath)
{
var path = "Sprite\\" + gamePath.Substring(0, gamePath.Length - 4).Replace('/', '\\') + ".png";
return path;
}
public static Uri FromGameToUri(string gamePath)
{
return new Uri(Path.Combine(Environment.CurrentDirectory, FromGameToLocal(gamePath)));
}
public static string FromLocalToGame(string localPath)
{
var path = localPath.Substring(7, localPath.Length - 7 - 4).Replace('\\', '/') + ".tga";
return path;
}
public SpriteLib()
{
InitializeComponent();
foreach (var i in Directory.EnumerateFiles("Sprite", "*.*", SearchOption.AllDirectories))
{
sprites.Add(i);
}
RefreshList();
}
void RefreshList()
{
spriteList.Items.Clear();
var searchText = spriteSearch.Text;
if (searchText.Length == 0)
{
foreach (var i in sprites)
spriteList.Items.Add(i);
}
else
{
foreach (var i in sprites)
if (i.Contains(searchText))
spriteList.Items.Add(i);
}
}
private void SpriteList_Selected(object sender, RoutedEventArgs e)
{
if (spriteList.SelectedIndex == -1)
{
spritePreview.Source = null;
return;
}
var path = (string)spriteList.SelectedValue;
spritePreview.Source = new BitmapImage(new Uri(Path.Combine(Environment.CurrentDirectory, path)));
}
private void SpriteSearch_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
RefreshList();
}
private void SetPreviewFill(object sender, RoutedEventArgs e)
{
Resources["previewStretch"] = Stretch.Fill;
}
private void SetPreviewNone(object sender, RoutedEventArgs e)
{
Resources["previewStretch"] = Stretch.None;
}
private void SaveButton(object sender, RoutedEventArgs e)
{
if (spriteList.SelectedIndex == -1)
{
MessageBox.Show("Ничего не выбрано", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
SpritePath = FromLocalToGame((string)spriteList.SelectedValue);
DialogResult = true;
}
private void CancelButton(object sender, RoutedEventArgs e)
{
SpritePath = null;
DialogResult = false;
}
private void CopyButton(object sender, RoutedEventArgs e)
{
if (spriteList.SelectedIndex == -1)
{
MessageBox.Show("Ничего не выбрано", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
var path = (string)spriteList.SelectedValue;
path = path.Substring(7, path.Length - 7 - 4).Replace('\\', '/') + ".tga";
Clipboard.SetText(path);
MessageBox.Show("Скопировано: " + path, "Копировать", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
}