-
Notifications
You must be signed in to change notification settings - Fork 1
/
OptionType.cs
123 lines (103 loc) · 2.84 KB
/
OptionType.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Editor;
using Sandbox;
namespace QuickSwitcher;
[Flags]
public enum OptionType
{
Asset,
Action,
All
}
public static class OptionTypeExtension
{
public static Color GetColor( this OptionType type )
{
return type switch
{
OptionType.Asset => Theme.White,
OptionType.Action => Theme.Primary,
_ => Color.White
};
}
}
public record Option( OptionType Type, string Name, string ActionText, Pixmap Icon );
public record AssetOption( OptionType Type, string Name, string ActionText, Pixmap Icon, Asset asset )
: Option( Type, Name, ActionText, Icon );
public record ActionOption(
OptionType Type,
string Name,
string ActionText,
Pixmap Icon,
Action action )
: Option( Type, Name, ActionText, Icon )
{
public static List<ActionOption> All()
{
List<ActionOption> options = new();
foreach ( var entry in CreateAsset.BuiltIn )
{
var asset = AssetType.Find( entry.Name );
if ( entry.Name == "Particles" )
{
asset = AssetType.ParticleSystem;
}
if ( asset is null )
{
Log.Warning( $"{entry.Name} is null" );
continue;
}
options.Add(
new ActionOption( OptionType.Action, $"New {asset.FriendlyName}..", "Action", asset.Icon64, () =>
{
var extension = Path.GetExtension( entry.Default ).Trim( '.' );
var fd = new FileDialog( null );
fd.Title = $"Create {entry.Name}";
fd.Directory = Project.Current.RootDirectory.FullName;
fd.DefaultSuffix = $".{extension}";
fd.SelectFile( $"untitled.{extension}" );
fd.SetFindFile();
fd.SetModeSave();
fd.SetNameFilter( $"{entry.Name} (*.{extension})" );
if ( !fd.Execute() )
return;
CreateAsset.Create( entry, fd.SelectedFile );
} ) );
}
foreach ( var gameResource in EditorTypeLibrary.GetAttributes<GameResourceAttribute>().OrderBy( x => x.Name ) )
{
void CreateResource( string s )
{
var asset = AssetSystem.CreateResource( gameResource.Extension, s );
MainAssetBrowser.Instance?.UpdateAssetList();
MainAssetBrowser.Instance?.FocusOnAsset( asset );
EditorUtility.InspectorObject = asset;
}
var asset = AssetType.FromType( gameResource.TargetType );
options.Add( new ActionOption(
OptionType.Action,
$"New {asset.FriendlyName}..",
"Action",
asset.Icon64,
() =>
{
var fd = new FileDialog( null );
fd.Title = $"Create {gameResource.Name}";
fd.Directory = Project.Current.RootDirectory.FullName;
fd.DefaultSuffix = $".{gameResource.Extension}";
fd.SelectFile( $"untitled.{gameResource.Extension}" );
fd.SetFindFile();
fd.SetModeSave();
fd.SetNameFilter( $"{gameResource.Name} (*.{gameResource.Extension})" );
if ( !fd.Execute() )
return;
CreateResource( fd.SelectedFile );
}
) );
}
return options;
}
}