You're breathtaking!
This commit is contained in:
49
Source/Editor/Content/Create/CreateFileEntry.cs
Normal file
49
Source/Editor/Content/Create/CreateFileEntry.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright (c) 2012-2020 Wojciech Figat. All rights reserved.
|
||||
|
||||
namespace FlaxEditor.Content.Create
|
||||
{
|
||||
/// <summary>
|
||||
/// File create entry.
|
||||
/// </summary>
|
||||
public abstract class CreateFileEntry : IFileEntryAction
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public string SourceUrl { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string ResultUrl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this entry has settings to modify.
|
||||
/// </summary>
|
||||
public virtual bool HasSettings => Settings != null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the settings object to modify.
|
||||
/// </summary>
|
||||
public virtual object Settings => null;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CreateFileEntry"/> class.
|
||||
/// </summary>
|
||||
/// <param name="outputType">The output file type.</param>
|
||||
/// <param name="resultUrl">The result file url.</param>
|
||||
protected CreateFileEntry(string outputType, string resultUrl)
|
||||
{
|
||||
SourceUrl = outputType;
|
||||
ResultUrl = resultUrl;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the result file.
|
||||
/// </summary>
|
||||
/// <returns>True if failed, otherwise false.</returns>
|
||||
public abstract bool Create();
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Execute()
|
||||
{
|
||||
return Create();
|
||||
}
|
||||
}
|
||||
}
|
||||
124
Source/Editor/Content/Create/CreateFilesDialog.cs
Normal file
124
Source/Editor/Content/Create/CreateFilesDialog.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
// Copyright (c) 2012-2020 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FlaxEditor.CustomEditors;
|
||||
using FlaxEditor.GUI.Dialogs;
|
||||
using FlaxEditor.GUI.Tree;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.GUI;
|
||||
|
||||
namespace FlaxEditor.Content.Create
|
||||
{
|
||||
/// <summary>
|
||||
/// Dialog used to edit new file settings.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.GUI.Dialogs.Dialog" />
|
||||
public class CreateFilesDialog : Dialog
|
||||
{
|
||||
private CreateFileEntry _entry;
|
||||
private CustomEditorPresenter _settingsEditor;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CreateFilesDialog"/> class.
|
||||
/// </summary>
|
||||
/// <param name="entry">The entry to edit it's settings.</param>
|
||||
public CreateFilesDialog(CreateFileEntry entry)
|
||||
: base("Create file settings")
|
||||
{
|
||||
_entry = entry ?? throw new ArgumentNullException();
|
||||
|
||||
const float TotalWidth = 520;
|
||||
const float EditorHeight = 250;
|
||||
Width = TotalWidth;
|
||||
|
||||
// Header and help description
|
||||
var headerLabel = new Label
|
||||
{
|
||||
Text = "Asset Options",
|
||||
AnchorPreset = AnchorPresets.HorizontalStretchTop,
|
||||
Offsets = new Margin(0, 0, 0, 40),
|
||||
Parent = this,
|
||||
Font = new FontReference(Style.Current.FontTitle)
|
||||
};
|
||||
var infoLabel = new Label
|
||||
{
|
||||
Text = "Specify options for creating new asset",
|
||||
HorizontalAlignment = TextAlignment.Near,
|
||||
Margin = new Margin(7),
|
||||
AnchorPreset = AnchorPresets.HorizontalStretchTop,
|
||||
Offsets = new Margin(10, -20, 45, 70),
|
||||
Parent = this
|
||||
};
|
||||
|
||||
// Buttons
|
||||
const float ButtonsWidth = 60;
|
||||
const float ButtonsHeight = 24;
|
||||
const float ButtonsMargin = 8;
|
||||
var createButton = new Button
|
||||
{
|
||||
Text = "Create",
|
||||
AnchorPreset = AnchorPresets.BottomRight,
|
||||
Offsets = new Margin(-ButtonsWidth - ButtonsMargin, ButtonsWidth, -ButtonsHeight - ButtonsMargin, ButtonsHeight),
|
||||
Parent = this
|
||||
};
|
||||
createButton.Clicked += OnCreate;
|
||||
var cancelButton = new Button
|
||||
{
|
||||
Text = "Cancel",
|
||||
AnchorPreset = AnchorPresets.BottomRight,
|
||||
Offsets = new Margin(-ButtonsWidth - ButtonsMargin - ButtonsWidth - ButtonsMargin, ButtonsWidth, -ButtonsHeight - ButtonsMargin, ButtonsHeight),
|
||||
Parent = this
|
||||
};
|
||||
cancelButton.Clicked += OnCancel;
|
||||
|
||||
// Panel for settings editor
|
||||
var panel = new Panel(ScrollBars.Vertical)
|
||||
{
|
||||
AnchorPreset = AnchorPresets.HorizontalStretchTop,
|
||||
Offsets = new Margin(2, 2, infoLabel.Bottom + 2, EditorHeight),
|
||||
Parent = this
|
||||
};
|
||||
|
||||
// Settings editor
|
||||
_settingsEditor = new CustomEditorPresenter(null);
|
||||
_settingsEditor.Panel.Parent = panel;
|
||||
|
||||
_dialogSize = new Vector2(TotalWidth, panel.Bottom);
|
||||
|
||||
_settingsEditor.Select(_entry.Settings);
|
||||
}
|
||||
|
||||
private void OnCreate()
|
||||
{
|
||||
Editor.Instance.ContentImporting.LetThemBeCreatedxD(_entry);
|
||||
Close(DialogResult.OK);
|
||||
}
|
||||
|
||||
private void OnCancel()
|
||||
{
|
||||
Close(DialogResult.Cancel);
|
||||
}
|
||||
|
||||
private void OnSelectedChanged(List<TreeNode> before, List<TreeNode> after)
|
||||
{
|
||||
var selection = new List<object>(after.Count);
|
||||
for (int i = 0; i < after.Count; i++)
|
||||
{
|
||||
if (after[i].Tag is CreateFileEntry fileEntry && fileEntry.HasSettings)
|
||||
selection.Add(fileEntry.Settings);
|
||||
}
|
||||
|
||||
_settingsEditor.Select(selection);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void SetupWindowSettings(ref CreateWindowSettings settings)
|
||||
{
|
||||
base.SetupWindowSettings(ref settings);
|
||||
|
||||
settings.MinimumSize = new Vector2(300, 400);
|
||||
settings.HasSizingFrame = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
106
Source/Editor/Content/Create/ParticleEmitterCreateEntry.cs
Normal file
106
Source/Editor/Content/Create/ParticleEmitterCreateEntry.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
// Copyright (c) 2012-2020 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using FlaxEngine;
|
||||
|
||||
namespace FlaxEditor.Content.Create
|
||||
{
|
||||
/// <summary>
|
||||
/// Particle emitter asset creating handler. Allows to specify asset template.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.Create.CreateFileEntry" />
|
||||
public class ParticleEmitterCreateEntry : CreateFileEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// Types of the emitter templates that can be created.
|
||||
/// </summary>
|
||||
public enum Templates
|
||||
{
|
||||
/// <summary>
|
||||
/// The empty asset.
|
||||
/// </summary>
|
||||
Empty,
|
||||
|
||||
/// <summary>
|
||||
/// The simple particle system that uses constant emission rate.
|
||||
/// </summary>
|
||||
ConstantBurst,
|
||||
|
||||
/// <summary>
|
||||
/// The simple periodic burst particle system.
|
||||
/// </summary>
|
||||
PeriodicBurst,
|
||||
|
||||
/// <summary>
|
||||
/// The layers and tags settings.
|
||||
/// </summary>
|
||||
Smoke,
|
||||
|
||||
/// <summary>
|
||||
/// The GPU sparks with depth-buffer collisions.
|
||||
/// </summary>
|
||||
Sparks,
|
||||
|
||||
/// <summary>
|
||||
/// The ribbon spiral particles.
|
||||
/// </summary>
|
||||
RibbonSpiral,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The create options.
|
||||
/// </summary>
|
||||
public class Options
|
||||
{
|
||||
/// <summary>
|
||||
/// The template.
|
||||
/// </summary>
|
||||
[Tooltip("Particle emitter template.")]
|
||||
public Templates Template = Templates.ConstantBurst;
|
||||
}
|
||||
|
||||
private readonly Options _options = new Options();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override object Settings => _options;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ParticleEmitterCreateEntry"/> class.
|
||||
/// </summary>
|
||||
/// <param name="resultUrl">The result file url.</param>
|
||||
public ParticleEmitterCreateEntry(string resultUrl)
|
||||
: base("Settings", resultUrl)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Create()
|
||||
{
|
||||
string templateName;
|
||||
switch (_options.Template)
|
||||
{
|
||||
case Templates.Empty:
|
||||
return Editor.CreateAsset(Editor.NewAssetType.ParticleEmitter, ResultUrl);
|
||||
case Templates.ConstantBurst:
|
||||
templateName = "Constant Burst";
|
||||
break;
|
||||
case Templates.PeriodicBurst:
|
||||
templateName = "Periodic Burst";
|
||||
break;
|
||||
case Templates.Smoke:
|
||||
templateName = "Smoke";
|
||||
break;
|
||||
case Templates.Sparks:
|
||||
templateName = "Sparks";
|
||||
break;
|
||||
case Templates.RibbonSpiral:
|
||||
templateName = "Ribbon Spiral";
|
||||
break;
|
||||
default: throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
var templatePath = Path.Combine(Globals.EngineContentFolder, "Editor/Particles", templateName + ".flax");
|
||||
return Editor.Instance.ContentEditing.CloneAssetFile(templatePath, ResultUrl, Guid.NewGuid());
|
||||
}
|
||||
}
|
||||
}
|
||||
156
Source/Editor/Content/Create/SettingsCreateEntry.cs
Normal file
156
Source/Editor/Content/Create/SettingsCreateEntry.cs
Normal file
@@ -0,0 +1,156 @@
|
||||
// Copyright (c) 2012-2020 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using FlaxEditor.Content.Settings;
|
||||
using FlaxEditor.Scripting;
|
||||
using FlaxEngine;
|
||||
|
||||
namespace FlaxEditor.Content.Create
|
||||
{
|
||||
/// <summary>
|
||||
/// Engine settings asset creating handler. Allows to specify type of the settings to create (e.g. <see cref="GameSettings"/>, <see cref="TimeSettings"/>, etc.).
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.Create.CreateFileEntry" />
|
||||
public class SettingsCreateEntry : CreateFileEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// Types of the settings assets that can be created.
|
||||
/// </summary>
|
||||
public enum SettingsTypes
|
||||
{
|
||||
/// <summary>
|
||||
/// The game settings.
|
||||
/// </summary>
|
||||
GameSettings,
|
||||
|
||||
/// <summary>
|
||||
/// The audio settings.
|
||||
/// </summary>
|
||||
AudioSettings,
|
||||
|
||||
/// <summary>
|
||||
/// The time settings.
|
||||
/// </summary>
|
||||
TimeSettings,
|
||||
|
||||
/// <summary>
|
||||
/// The layers and tags settings.
|
||||
/// </summary>
|
||||
LayersAndTagsSettings,
|
||||
|
||||
/// <summary>
|
||||
/// The physics settings.
|
||||
/// </summary>
|
||||
PhysicsSettings,
|
||||
|
||||
/// <summary>
|
||||
/// The graphics settings.
|
||||
/// </summary>
|
||||
GraphicsSettings,
|
||||
|
||||
/// <summary>
|
||||
/// The navigation settings.
|
||||
/// </summary>
|
||||
NavigationSettings,
|
||||
|
||||
/// <summary>
|
||||
/// The build settings.
|
||||
/// </summary>
|
||||
BuildSettings,
|
||||
|
||||
/// <summary>
|
||||
/// The input settings.
|
||||
/// </summary>
|
||||
InputSettings,
|
||||
|
||||
/// <summary>
|
||||
/// The Windows settings.
|
||||
/// </summary>
|
||||
WindowsPlatformSettings,
|
||||
|
||||
/// <summary>
|
||||
/// The UWP settings.
|
||||
/// </summary>
|
||||
UWPPlatformSettings,
|
||||
|
||||
/// <summary>
|
||||
/// The Linux settings.
|
||||
/// </summary>
|
||||
LinuxPlatformSettings,
|
||||
|
||||
/// <summary>
|
||||
/// The PS4 settings
|
||||
/// </summary>
|
||||
PS4PlatformSettings,
|
||||
|
||||
/// <summary>
|
||||
/// The Xbox Scarlett settings
|
||||
/// </summary>
|
||||
XboxScarlettPlatformSettings,
|
||||
|
||||
/// <summary>
|
||||
/// The Android settings
|
||||
/// </summary>
|
||||
AndroidPlatformSettings,
|
||||
}
|
||||
|
||||
private static readonly Type[] _types =
|
||||
{
|
||||
typeof(GameSettings),
|
||||
typeof(AudioSettings),
|
||||
typeof(TimeSettings),
|
||||
typeof(LayersAndTagsSettings),
|
||||
typeof(PhysicsSettings),
|
||||
typeof(GraphicsSettings),
|
||||
typeof(NavigationSettings),
|
||||
typeof(BuildSettings),
|
||||
typeof(InputSettings),
|
||||
typeof(WindowsPlatformSettings),
|
||||
typeof(UWPPlatformSettings),
|
||||
typeof(LinuxPlatformSettings),
|
||||
TypeUtils.GetManagedType(GameSettings.PS4PlatformSettingsTypename),
|
||||
TypeUtils.GetManagedType(GameSettings.XboxScarlettPlatformSettingsTypename),
|
||||
typeof(AndroidPlatformSettings),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The create options.
|
||||
/// </summary>
|
||||
public class Options
|
||||
{
|
||||
/// <summary>
|
||||
/// The type.
|
||||
/// </summary>
|
||||
[Tooltip("Type of the settings asset to create")]
|
||||
public SettingsTypes Type = SettingsTypes.GameSettings;
|
||||
}
|
||||
|
||||
private readonly Options _options = new Options();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override object Settings => _options;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SettingsCreateEntry"/> class.
|
||||
/// </summary>
|
||||
/// <param name="resultUrl">The result file url.</param>
|
||||
public SettingsCreateEntry(string resultUrl)
|
||||
: base("Settings", resultUrl)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Create()
|
||||
{
|
||||
// Create settings asset object and serialize it to pure json asset
|
||||
var type = _types[(int)_options.Type];
|
||||
if (type == null)
|
||||
{
|
||||
MessageBox.Show("Cannot create " + _options.Type + " settings. Platform not supported.");
|
||||
return true;
|
||||
}
|
||||
var data = Activator.CreateInstance(type);
|
||||
return Editor.SaveJsonAsset(ResultUrl, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
52
Source/Editor/Content/Create/VisualScriptCreateEntry.cs
Normal file
52
Source/Editor/Content/Create/VisualScriptCreateEntry.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) 2012-2020 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using FlaxEngine;
|
||||
|
||||
namespace FlaxEditor.Content.Create
|
||||
{
|
||||
/// <summary>
|
||||
/// Visual Script asset creating handler. Allows to specify base class to inherit from.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.Create.CreateFileEntry" />
|
||||
public class VisualScriptCreateEntry : CreateFileEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// The create options.
|
||||
/// </summary>
|
||||
public class Options
|
||||
{
|
||||
/// <summary>
|
||||
/// The template.
|
||||
/// </summary>
|
||||
[TypeReference(typeof(FlaxEngine.Object), nameof(IsValid))]
|
||||
[Tooltip("The base class of the new Visual Script to inherit from.")]
|
||||
public Type BaseClass = typeof(Script);
|
||||
|
||||
private static bool IsValid(Type type)
|
||||
{
|
||||
return type.IsPublic && !type.IsSealed && !type.IsGenericType;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Options _options = new Options();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override object Settings => _options;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="VisualScriptCreateEntry"/> class.
|
||||
/// </summary>
|
||||
/// <param name="resultUrl">The result file url.</param>
|
||||
public VisualScriptCreateEntry(string resultUrl)
|
||||
: base("Settings", resultUrl)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Create()
|
||||
{
|
||||
return Editor.CreateVisualScript(ResultUrl, _options.BaseClass?.FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user