Merge remote-tracking branch 'origin/master' into dotnet7

This commit is contained in:
Wojtek Figat
2023-02-06 10:02:13 +01:00
158 changed files with 1077 additions and 905 deletions

View File

@@ -354,7 +354,7 @@ bool CookAssetsStep::Process(CookingData& data, CacheData& cache, Asset* asset)
if (asset->WaitForLoaded())
{
LOG(Error, "Failed to load asset \'{0}\'", asset->ToString());
return false;
return true;
}
// Switch based on an asset type
@@ -1132,7 +1132,10 @@ bool CookAssetsStep::Perform(CookingData& data)
// Cook asset
if (Process(data, cache, assetRef.Get()))
{
cache.Save();
return true;
}
data.Stats.CookedAssets++;
// Auto save build cache after every few cooked assets (reduces next build time if cooking fails later)

View File

@@ -322,7 +322,7 @@ namespace FlaxEditor.CustomEditors.Editors
internal static ContextMenuBase CreatePicker(Tag value, Tag[] values, PickerData pickerData)
{
// Initialize search popup
var menu = Utilities.Utils.CreateSearchPopup(out var searchBox, out var tree, 40.0f);
var menu = Utilities.Utils.CreateSearchPopup(out var searchBox, out var tree, 42.0f);
// Add tag drop panel
var addTagDropPanel = new DropPanel
@@ -333,6 +333,7 @@ namespace FlaxEditor.CustomEditors.Editors
ArrowImageClosed = new SpriteBrush(FlaxEngine.GUI.Style.Current.ArrowRight),
Parent = menu,
HeaderTextMargin = new Margin(2.0f),
HeaderHeight = 18.0f,
AnchorPreset = AnchorPresets.TopLeft,
Bounds = new Rectangle(2, 2, menu.Width - 4, 30),
IsClosed = true,
@@ -408,7 +409,7 @@ namespace FlaxEditor.CustomEditors.Editors
var buttonAddTag = new Button
{
Parent = addButtonPanel,
Size = new Float2(100, 20),
Size = new Float2(100, 18),
Text = "Add Tag",
AnchorPreset = AnchorPresets.MiddleCenter,
};

View File

@@ -275,12 +275,16 @@ namespace FlaxEditor.CustomEditors
// Workaround for DefaultValueAttribute that doesn't support certain value types storage
if (Type.Type == typeof(sbyte))
_defaultValue = Convert.ToSByte(_defaultValue);
else if (Type.Type == typeof(short))
_defaultValue = Convert.ToInt16(_defaultValue);
else if (Type.Type == typeof(ushort))
_defaultValue = Convert.ToUInt16(_defaultValue);
else if (Type.Type == typeof(uint))
_defaultValue = Convert.ToUInt32(_defaultValue);
else if (Type.Type == typeof(ulong))
_defaultValue = Convert.ToUInt64(_defaultValue);
else if (Type.Type == typeof(long))
_defaultValue = Convert.ToInt64(_defaultValue);
}
}
}

View File

@@ -50,7 +50,8 @@ namespace FlaxEditor
private bool _isAfterInit, _areModulesInited, _areModulesAfterInitEnd, _isHeadlessMode;
private string _projectToOpen;
private float _lastAutoSaveTimer;
private AutoSavePopup _autoSavePopup;
private Button _saveNowButton;
private Button _cancelSaveButton;
private bool _autoSaveNow;
private Guid _startupSceneCmdLine;
@@ -498,28 +499,6 @@ namespace FlaxEditor
{
var timeSinceLastSave = Time.UnscaledGameTime - _lastAutoSaveTimer;
var timeToNextSave = options.AutoSaveFrequency * 60.0f - timeSinceLastSave;
var countDownDuration = 4.0f;
// Show auto save popup
if (timeToNextSave <= options.AutoSaveReminderTime && timeToNextSave >= 0)
{
if (_autoSavePopup == null)
{
_autoSavePopup = AutoSavePopup.Show(Instance.Windows.MainWindow.GUI, timeToNextSave);
_autoSavePopup.SaveNowButton.Clicked += () => _autoSaveNow = true;
_autoSavePopup.CancelSaveButton.Clicked += () =>
{
Log("Auto save canceled");
_autoSavePopup.HidePopup();
_lastAutoSaveTimer = Time.UnscaledGameTime; // Reset timer
};
}
else if (!_autoSavePopup.Visible && !_autoSavePopup.UserClosed)
_autoSavePopup.ShowPopup();
if (_autoSavePopup.Visible)
_autoSavePopup.UpdateTime(timeToNextSave);
}
if (timeToNextSave <= 0.0f || _autoSaveNow)
{
@@ -530,14 +509,76 @@ namespace FlaxEditor
if (options.AutoSaveContent)
SaveContent();
// Hide auto save popup and reset user closed
_autoSavePopup.HidePopup();
_autoSavePopup.UserClosed = false;
_autoSaveNow = false;
// Hide save now and cancel save buttons
if (_saveNowButton != null && _cancelSaveButton != null)
{
_saveNowButton.Visible = false;
_cancelSaveButton.Visible = false;
}
}
else if (timeToNextSave < countDownDuration)
else if (timeToNextSave <= options.AutoSaveReminderTime)
{
msg = string.Format("Auto save in {0}s...", Mathf.CeilToInt(timeToNextSave));
// Create save now and cancel save buttons if needed
if (_saveNowButton == null)
{
_saveNowButton = new Button
{
Parent = UI.StatusBar,
Height = 14,
Width = 60,
AnchorPreset = AnchorPresets.MiddleLeft,
BackgroundColor = Color.Transparent,
BorderColor = Color.Transparent,
BackgroundColorHighlighted = Color.Transparent,
BackgroundColorSelected = Color.Transparent,
BorderColorHighlighted = Color.Transparent,
Text = "Save Now",
TooltipText = "Saves now and restarts the auto save timer."
};
_saveNowButton.LocalX += 120;
_saveNowButton.Clicked += () => _autoSaveNow = true;
_saveNowButton.HoverBegin += () => _saveNowButton.TextColor = Style.Current.BackgroundHighlighted;
_saveNowButton.HoverEnd += () => _saveNowButton.TextColor = UI.StatusBar.TextColor;
}
if (_cancelSaveButton == null)
{
_cancelSaveButton = new Button
{
Parent = UI.StatusBar,
Height = 14,
Width = 70,
AnchorPreset = AnchorPresets.MiddleLeft,
BackgroundColor = Color.Transparent,
BorderColor = Color.Transparent,
BackgroundColorHighlighted = Color.Transparent,
BackgroundColorSelected = Color.Transparent,
BorderColorHighlighted = Color.Transparent,
Text = "Cancel",
TooltipText = "Cancels this auto save."
};
_cancelSaveButton.LocalX += 180;
_cancelSaveButton.Clicked += () =>
{
Log("Auto save canceled");
_saveNowButton.Visible = false;
_cancelSaveButton.Visible = false;
_lastAutoSaveTimer = Time.UnscaledGameTime; // Reset timer
};
_cancelSaveButton.HoverBegin += () => _cancelSaveButton.TextColor = Style.Current.BackgroundHighlighted;
_cancelSaveButton.HoverEnd += () => _cancelSaveButton.TextColor = UI.StatusBar.TextColor;
}
// Show save now and cancel save buttons
if (!_saveNowButton.Visible || !_cancelSaveButton.Visible)
{
_saveNowButton.Visible = true;
_cancelSaveButton.Visible = true;
}
}
}
if (StateMachine.EditingSceneState.AutoSaveStatus != msg)
@@ -545,6 +586,14 @@ namespace FlaxEditor
StateMachine.EditingSceneState.AutoSaveStatus = msg;
UI.UpdateStatusBar();
}
if (UI?.StatusBar?.Text != null && !UI.StatusBar.Text.Contains("Auto") &&
_saveNowButton != null && _cancelSaveButton != null &&
(_saveNowButton.Visible || _cancelSaveButton.Visible))
{
_saveNowButton.Visible = false;
_cancelSaveButton.Visible = false;
}
}
private void InitProject()

View File

@@ -1,169 +0,0 @@
using FlaxEngine;
using FlaxEngine.GUI;
namespace FlaxEditor.GUI
{
/// <summary>
/// Popup menu for reminding of an upcoming auto save.
/// </summary>
public class AutoSavePopup : ContainerControl
{
/// <summary>
/// Gets or sets the value for if the user has manually closed this popup.
/// </summary>
public bool UserClosed { get; set; }
/// <summary>
/// The save now button. Used to skip the last remaining auto save time.
/// </summary>
public Button SaveNowButton => _saveNowButton;
/// <summary>
/// Button that should be used to cancel the auto save.
/// </summary>
public Button CancelSaveButton => _cancelSaveButton;
private int _timeRemaining;
private Panel _backgroundPanel;
private Label _timeLabel;
private Button _saveNowButton;
private Button _cancelSaveButton;
private Color _defaultTextColor;
private bool _isMoved = false;
/// <summary>
/// Initialize the AutoSavePopup.
/// </summary>
/// <param name="initialTime">The initial time to set the time label to.</param>
public AutoSavePopup(float initialTime)
{
UpdateTime(initialTime);
_backgroundPanel = new Panel(ScrollBars.None)
{
Parent = this,
AnchorPreset = AnchorPresets.StretchAll,
BackgroundColor = Color.Transparent,
};
_timeLabel = new Label(0, 0, 25, 10)
{
Parent = _backgroundPanel,
Text = _timeRemaining.ToString(),
HorizontalAlignment = TextAlignment.Near,
VerticalAlignment = TextAlignment.Near,
AutoWidth = true,
Height = 14,
AnchorPreset = AnchorPresets.MiddleLeft,
};
_saveNowButton = new Button
{
Parent = _backgroundPanel,
Height = 14,
Width = 60,
AnchorPreset = AnchorPresets.MiddleRight,
BackgroundColor = Color.Transparent,
BorderColor = Color.Transparent,
BackgroundColorHighlighted = Color.Transparent,
BackgroundColorSelected = Color.Transparent,
BorderColorHighlighted = Color.Transparent,
Text = "Save Now",
TooltipText = "Saves now and restarts the auto save timer."
};
_saveNowButton.LocalX -= 85;
_cancelSaveButton = new Button
{
Parent = _backgroundPanel,
Height = 14,
Width = 70,
AnchorPreset = AnchorPresets.MiddleRight,
BackgroundColor = Color.Transparent,
BorderColor = Color.Transparent,
BackgroundColorHighlighted = Color.Transparent,
BackgroundColorSelected = Color.Transparent,
BorderColorHighlighted = Color.Transparent,
Text = "Cancel Save",
TooltipText = "Cancels this auto save."
};
_cancelSaveButton.LocalX -= 5;
_defaultTextColor = _saveNowButton.TextColor;
}
/// <summary>
/// Updates the time label
/// </summary>
/// <param name="time">The time to change the label to.</param>
public void UpdateTime(float time)
{
_timeRemaining = Mathf.CeilToInt(time);
if (_timeLabel != null)
_timeLabel.Text = "Auto Save in: " + _timeRemaining;
}
/// <inheritdoc />
public override void Update(float deltaTime)
{
if (IsMouseOver)
{
_saveNowButton.TextColor = _saveNowButton.IsMouseOver ? Style.Current.BackgroundHighlighted : _defaultTextColor;
_cancelSaveButton.TextColor = _cancelSaveButton.IsMouseOver ? Style.Current.BackgroundHighlighted : _defaultTextColor;
}
// Move if the progress bar is visible
if (Editor.Instance.UI.ProgressVisible && !_isMoved)
{
_isMoved = true;
LocalX -= 280;
}
else if (!Editor.Instance.UI.ProgressVisible && _isMoved)
{
LocalX += 280;
_isMoved = false;
}
base.Update(deltaTime);
}
/// <summary>
/// Creates and shows the AutoSavePopup
/// </summary>
/// <param name="parentControl">The parent control.</param>
/// <param name="initialTime">The time to start at.</param>
/// <returns></returns>
public static AutoSavePopup Show(ContainerControl parentControl, float initialTime)
{
var popup = new AutoSavePopup(initialTime)
{
Parent = parentControl,
Height = Editor.Instance.UI.StatusBar.Height,
Width = 250,
AnchorPreset = AnchorPresets.BottomRight,
};
popup.ShowPopup();
return popup;
}
/// <summary>
/// Shows the popup by changing its visibility
/// </summary>
public void ShowPopup()
{
Visible = true;
UserClosed = false;
_saveNowButton.TextColor = _defaultTextColor;
_cancelSaveButton.TextColor = _defaultTextColor;
}
/// <summary>
/// Hides the popup by changing its visibility
/// </summary>
public void HidePopup()
{
Visible = false;
if (_containsFocus)
Defocus();
}
}
}

View File

@@ -78,6 +78,7 @@ void ViewportIconsRenderer::DrawIcons(RenderContext& renderContext, Actor* actor
draw.PerInstanceRandom = 0;
draw.LODBias = 0;
draw.ForcedLOD = -1;
draw.SortOrder = 0;
draw.VertexColors = nullptr;
if (const auto scene = SceneObject::Cast<Scene>(actor))

View File

@@ -1521,6 +1521,7 @@ namespace FlaxEditor.Viewport
new ViewFlagOptions(ViewFlags.PointLights, "Point Lights"),
new ViewFlagOptions(ViewFlags.SpotLights, "Spot Lights"),
new ViewFlagOptions(ViewFlags.SkyLights, "Sky Lights"),
new ViewFlagOptions(ViewFlags.Sky, "Sky"),
new ViewFlagOptions(ViewFlags.Fog, "Fog"),
new ViewFlagOptions(ViewFlags.SpecularLight, "Specular Light"),
new ViewFlagOptions(ViewFlags.Decals, "Decals"),

View File

@@ -428,8 +428,12 @@ namespace FlaxEditor.Viewport.Previews
case KeyboardKeys.F:
// Pay respect..
ViewportCamera.SetArcBallView(_previewModel.Box);
break;
return true;
case KeyboardKeys.Spacebar:
PlayAnimation = !PlayAnimation;
return true;
}
return base.OnKeyDown(key);
}

View File

@@ -2,8 +2,10 @@
using FlaxEditor.GUI.ContextMenu;
using FlaxEditor.Viewport.Cameras;
using FlaxEditor.Viewport.Widgets;
using FlaxEngine;
using FlaxEngine.GUI;
using System;
using Object = FlaxEngine.Object;
namespace FlaxEditor.Viewport.Previews
@@ -14,10 +16,12 @@ namespace FlaxEditor.Viewport.Previews
/// <seealso cref="AssetPreview" />
public class ParticleSystemPreview : AssetPreview
{
private bool _playSimulation = false;
private ParticleEffect _previewEffect;
private ContextMenuButton _showBoundsButton;
private ContextMenuButton _showOriginButton;
private ContextMenuButton _showParticleCounterButton;
private ViewportWidgetButton _playPauseButton;
private StaticModel _boundsModel;
private StaticModel _originModel;
private bool _showParticlesCounter;
@@ -39,7 +43,25 @@ namespace FlaxEditor.Viewport.Previews
/// <summary>
/// Gets or sets a value indicating whether to play the particles simulation in editor.
/// </summary>
public bool PlaySimulation { get; set; } = false;
public bool PlaySimulation
{
get => _playSimulation;
set
{
if (_playSimulation == value)
return;
_playSimulation = value;
PlaySimulationChanged?.Invoke();
if (_playPauseButton != null)
_playPauseButton.Icon = value ? Editor.Instance.Icons.Pause64 : Editor.Instance.Icons.Play64;
}
}
/// <summary>
/// Occurs when particles simulation playback state gets changed.
/// </summary>
public event Action PlaySimulationChanged;
/// <summary>
/// Gets or sets a value indicating whether to show particle effect bounding box.
@@ -161,11 +183,22 @@ namespace FlaxEditor.Viewport.Previews
// Link actors for rendering
Task.AddCustomActor(_previewEffect);
if (useWidgets)
if (!useWidgets)
return;
_showBoundsButton = ViewWidgetShowMenu.AddButton("Bounds", () => ShowBounds = !ShowBounds);
_showOriginButton = ViewWidgetShowMenu.AddButton("Origin", () => ShowOrigin = !ShowOrigin);
_showParticleCounterButton = ViewWidgetShowMenu.AddButton("Particles Counter", () => ShowParticlesCounter = !ShowParticlesCounter);
// Play/Pause widget
{
_showBoundsButton = ViewWidgetShowMenu.AddButton("Bounds", () => ShowBounds = !ShowBounds);
_showOriginButton = ViewWidgetShowMenu.AddButton("Origin", () => ShowOrigin = !ShowOrigin);
_showParticleCounterButton = ViewWidgetShowMenu.AddButton("Particles Counter", () => ShowParticlesCounter = !ShowParticlesCounter);
var playPauseWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
_playPauseButton = new ViewportWidgetButton(null, Editor.Instance.Icons.Pause64)
{
TooltipText = "Simulation playback play (F5) or pause (F6)",
Parent = playPauseWidget,
};
_playPauseButton.Clicked += button => PlaySimulation = !PlaySimulation;
playPauseWidget.Parent = this;
}
}
@@ -200,7 +233,7 @@ namespace FlaxEditor.Viewport.Previews
// Manually update simulation
if (PlaySimulation)
{
_previewEffect.UpdateSimulation();
_previewEffect.UpdateSimulation(true);
}
// Keep bounds matching the model
@@ -228,6 +261,34 @@ namespace FlaxEditor.Viewport.Previews
}
}
/// <inheritdoc />
public override bool OnKeyDown(KeyboardKeys key)
{
switch (key)
{
case KeyboardKeys.F:
ViewportCamera.SetArcBallView(_previewEffect.Box);
return true;
case KeyboardKeys.Spacebar:
PlaySimulation = !PlaySimulation;
return true;
}
var inputOptions = Editor.Instance.Options.Options.Input;
if (inputOptions.Play.Process(this, key))
{
PlaySimulation = true;
return true;
}
if (inputOptions.Pause.Process(this, key))
{
PlaySimulation = false;
return true;
}
return base.OnKeyDown(key);
}
/// <inheritdoc />
public override void OnDestroy()
{
@@ -239,6 +300,7 @@ namespace FlaxEditor.Viewport.Previews
_showBoundsButton = null;
_showOriginButton = null;
_showParticleCounterButton = null;
_playPauseButton = null;
base.OnDestroy();
}

View File

@@ -430,7 +430,7 @@ namespace FlaxEditor.Windows
writer.WriteAttributeString("MovementSpeed", Viewport.MovementSpeed.ToString());
writer.WriteAttributeString("OrthographicScale", Viewport.OrthographicScale.ToString());
writer.WriteAttributeString("UseOrthographicProjection", Viewport.UseOrthographicProjection.ToString());
writer.WriteAttributeString("ViewFlags", ((long)Viewport.Task.View.Flags).ToString());
writer.WriteAttributeString("ViewFlags", ((ulong)Viewport.Task.View.Flags).ToString());
}
/// <inheritdoc />
@@ -463,7 +463,7 @@ namespace FlaxEditor.Windows
if (bool.TryParse(node.GetAttribute("UseOrthographicProjection"), out value1))
Viewport.UseOrthographicProjection = value1;
if (long.TryParse(node.GetAttribute("ViewFlags"), out long value3))
if (ulong.TryParse(node.GetAttribute("ViewFlags"), out ulong value3))
Viewport.Task.ViewFlags = (ViewFlags)value3;
// Reset view flags if opening with different engine version (ViewFlags enum could be modified)