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

This commit is contained in:
Wojtek Figat
2025-07-04 12:05:19 +02:00
25 changed files with 241 additions and 75 deletions

View File

@@ -604,6 +604,9 @@ namespace FlaxEditor.CustomEditors.Editors
root.SortChildrenRecursive();
root.Expand(true);
if (Input.GetKey(KeyboardKeys.Shift))
root.ExpandAll(true);
return menu;
}
}

View File

@@ -227,9 +227,8 @@ namespace FlaxEditor.GUI
{
int order = -1 * SortScore.CompareTo(otherItem.SortScore);
if (order == 0)
{
order = string.Compare(Name, otherItem.Name, StringComparison.Ordinal);
}
return order;
}
return base.Compare(other);
@@ -509,7 +508,7 @@ namespace FlaxEditor.GUI
OnSearchFilterChanged();
}
private List<Item> GetVisibleItems()
private List<Item> GetVisibleItems(bool ignoreFoldedCategories)
{
var result = new List<Item>();
var items = ItemsPanel.Children;
@@ -523,7 +522,7 @@ namespace FlaxEditor.GUI
for (int i = 0; i < _categoryPanels.Count; i++)
{
var category = _categoryPanels[i];
if (!category.Visible)
if (!category.Visible || (ignoreFoldedCategories && category is DropPanel panel && panel.IsClosed))
continue;
for (int j = 0; j < category.Children.Count; j++)
{
@@ -535,6 +534,12 @@ namespace FlaxEditor.GUI
return result;
}
private void ExpandToItem(Item item)
{
if (item.Parent is DropPanel dropPanel)
dropPanel.Open(false);
}
/// <inheritdoc />
protected override void OnShow()
{
@@ -564,7 +569,7 @@ namespace FlaxEditor.GUI
Hide();
return true;
case KeyboardKeys.Backspace:
// Alow the user to quickly focus the searchbar
// Allow the user to quickly focus the searchbar
if (_searchBox != null && !_searchBox.IsFocused)
{
_searchBox.Focus();
@@ -582,14 +587,25 @@ namespace FlaxEditor.GUI
}
// Get the next item
var items = GetVisibleItems();
bool controlDown = Root.GetKey(KeyboardKeys.Control);
var items = GetVisibleItems(!controlDown);
var focusedIndex = items.IndexOf(focusedItem);
// If the user hasn't selected anything yet and is holding control, focus first folded item
if (focusedIndex == -1 && controlDown)
focusedIndex = GetVisibleItems(true).Count - 1;
int delta = key == KeyboardKeys.ArrowDown ? -1 : 1;
int nextIndex = Mathf.Wrap(focusedIndex - delta, 0, items.Count - 1);
var nextItem = items[nextIndex];
// Focus the next item
nextItem.Focus();
// Allow the user to expand groups while scrolling
if (controlDown)
ExpandToItem(nextItem);
_scrollPanel.ScrollViewTo(nextItem);
return true;
case KeyboardKeys.Return:
@@ -601,7 +617,7 @@ namespace FlaxEditor.GUI
else
{
// Select first item if no item is focused (most likely to be the best result), saves the user from pressing arrow down first
var visibleItems = GetVisibleItems();
var visibleItems = GetVisibleItems(true);
if (visibleItems.Count > 0)
{
OnClickItem(visibleItems[0]);

View File

@@ -76,9 +76,13 @@ namespace FlaxEditor.SceneGraph.Actors
// Skip removing this terrain file sif it's still referenced
var sceneReferences = Editor.GetAssetReferences(e.SceneId);
if (sceneReferences != null && sceneReferences.Contains(e.TerrainId))
{
Debug.Log($"Skip removing files used by terrain {e.TerrainId} on scene {e.SceneId} as it's still in use");
continue;
}
// Delete files
Debug.Log($"Removing files used by removed terrain {e.TerrainId} on scene {e.SceneId}");
foreach (var file in e.Files)
{
if (file != null && File.Exists(file))

View File

@@ -19,6 +19,7 @@ namespace FlaxEditor.States
private readonly List<Guid> _scenesToLoad = new List<Guid>();
private readonly List<Scene> _scenesToUnload = new List<Scene>();
private Guid _lastSceneFromRequest;
private bool _sameSceneReload = false;
internal ChangingScenesState(Editor editor)
: base(editor)
@@ -164,10 +165,22 @@ namespace FlaxEditor.States
{
Assert.AreEqual(Guid.Empty, _lastSceneFromRequest, "Invalid state.");
// Bind events
Level.SceneLoaded += OnSceneEvent;
Level.SceneLoadError += OnSceneEvent;
Level.SceneUnloaded += OnSceneEvent;
// Bind events, only bind loading event and error if re-loading the same scene to avoid issues.
if (_scenesToUnload.Count == 1 && _scenesToLoad.Count == 1)
{
if (_scenesToLoad[0] == _scenesToUnload[0].ID)
{
Level.SceneLoaded += OnSceneEvent;
Level.SceneLoadError += OnSceneEvent;
_sameSceneReload = true;
}
}
if (!_sameSceneReload)
{
Level.SceneLoaded += OnSceneEvent;
Level.SceneLoadError += OnSceneEvent;
Level.SceneUnloaded += OnSceneEvent;
}
// Push scenes changing requests
for (int i = 0; i < _scenesToUnload.Count; i++)
@@ -210,9 +223,18 @@ namespace FlaxEditor.States
}
// Unbind events
Level.SceneLoaded -= OnSceneEvent;
Level.SceneLoadError -= OnSceneEvent;
Level.SceneUnloaded -= OnSceneEvent;
if (_sameSceneReload)
{
Level.SceneLoaded -= OnSceneEvent;
Level.SceneLoadError -= OnSceneEvent;
_sameSceneReload = false;
}
else
{
Level.SceneLoaded -= OnSceneEvent;
Level.SceneLoadError -= OnSceneEvent;
Level.SceneUnloaded -= OnSceneEvent;
}
}
private void OnSceneEvent(Scene scene, Guid sceneId)

View File

@@ -40,6 +40,11 @@ namespace FlaxEditor.Surface
[HideInEditor]
public class SurfaceNode : SurfaceControl
{
/// <summary>
/// The box to draw a highlight around. Drawing will be skipped if null.
/// </summary>
internal Box highlightBox;
/// <summary>
/// Flag used to discard node values setting during event sending for node UI flushing.
/// </summary>
@@ -1102,6 +1107,9 @@ namespace FlaxEditor.Surface
Render2D.DrawSprite(icon, new Rectangle(-7, -7, 16, 16), new Color(0.9f, 0.9f, 0.9f));
Render2D.DrawSprite(icon, new Rectangle(-6, -6, 14, 14), new Color(0.894117647f, 0.0784313725f, 0.0f));
}
if (highlightBox != null)
Render2D.DrawRectangle(highlightBox.Bounds, style.BorderHighlighted, 2f);
}
/// <inheritdoc />

View File

@@ -427,7 +427,7 @@ namespace FlaxEditor.Surface
_cmDistributeNodesHorizontallyButton = _cmFormatNodesMenu.ContextMenu.AddButton("Distribute horizontally", Editor.Instance.Options.Options.Input.NodesDistributeHorizontal, () => { DistributeNodes(SelectedNodes, false); });
_cmDistributeNodesVerticallyButton = _cmFormatNodesMenu.ContextMenu.AddButton("Distribute vertically", Editor.Instance.Options.Options.Input.NodesDistributeVertical, () => { DistributeNodes(SelectedNodes, true); });
_cmRemoveNodeConnectionsButton = menu.AddButton("Remove all connections to that node(s)", () =>
_cmRemoveNodeConnectionsButton = menu.AddButton("Remove all connections", () =>
{
var nodes = ((List<SurfaceNode>)menu.Tag);
@@ -453,8 +453,10 @@ namespace FlaxEditor.Surface
MarkAsEdited();
});
_cmRemoveNodeConnectionsButton.Enabled = CanEdit;
_cmRemoveBoxConnectionsButton = menu.AddButton("Remove all connections to that box", () =>
bool anyConnection = SelectedNodes.Any(n => n.GetBoxes().Any(b => b.HasAnyConnection));
_cmRemoveNodeConnectionsButton.Enabled = CanEdit && anyConnection;
_cmRemoveBoxConnectionsButton = menu.AddButton("Remove all socket connections", () =>
{
var boxUnderMouse = (Box)_cmRemoveBoxConnectionsButton.Tag;
if (Undo != null)
@@ -475,6 +477,16 @@ namespace FlaxEditor.Surface
var boxUnderMouse = GetChildAtRecursive(location) as Box;
_cmRemoveBoxConnectionsButton.Enabled = boxUnderMouse != null && boxUnderMouse.HasAnyConnection;
_cmRemoveBoxConnectionsButton.Tag = boxUnderMouse;
if (boxUnderMouse != null)
{
boxUnderMouse.ParentNode.highlightBox = boxUnderMouse;
menu.VisibleChanged += (c) =>
{
if (!c.Visible)
boxUnderMouse.ParentNode.highlightBox = null;
};
}
}
controlUnderMouse?.OnShowSecondaryContextMenu(menu, controlUnderMouse.PointFromParent(location));

View File

@@ -225,6 +225,10 @@ namespace FlaxEditor.Surface
_rootControl.DrawComments();
// Reset input flags here because this is the closest to Update we have
WasBoxSelecting = IsBoxSelecting;
WasMovingSelection = IsMovingSelection;
if (IsBoxSelecting)
{
DrawSelection();

View File

@@ -590,9 +590,6 @@ namespace FlaxEditor.Surface
// Cache flags and state
if (_leftMouseDown && button == MouseButton.Left)
{
WasBoxSelecting = IsBoxSelecting;
WasMovingSelection = _isMovingSelection;
_leftMouseDown = false;
EndMouseCapture();
Cursor = CursorType.Default;

View File

@@ -447,6 +447,10 @@ namespace FlaxEditor.Windows
/// </summary>
public void Clear()
{
lock (_locker)
{
_pendingEntries.Clear();
}
if (_entriesPanel == null)
return;
RemoveEntries();
@@ -735,10 +739,10 @@ namespace FlaxEditor.Windows
}
/// <inheritdoc />
public override void OnPlayBegin()
public override void OnPlayBeginning()
{
// Clear on Play
if (_clearOnPlayButton.Checked)
if (Editor.Options.Options.Interface.DebugLogClearOnPlay)
{
Clear();
}

View File

@@ -27,6 +27,7 @@ namespace FlaxEditor.Windows
private Panel _sceneTreePanel;
private bool _isUpdatingSelection;
private bool _isMouseDown;
private bool _blockSceneTreeScroll = false;
private DragAssets _dragAssets;
private DragActorType _dragActorType;
@@ -111,6 +112,34 @@ namespace FlaxEditor.Windows
InputActions.Add(options => options.LockFocusSelection, () => Editor.Windows.EditWin.Viewport.LockFocusSelection());
InputActions.Add(options => options.Rename, RenameSelection);
}
/// <inheritdoc />
public override void OnPlayBeginning()
{
base.OnPlayBeginning();
_blockSceneTreeScroll = true;
}
/// <inheritdoc />
public override void OnPlayBegin()
{
base.OnPlayBegin();
_blockSceneTreeScroll = false;
}
/// <inheritdoc />
public override void OnPlayEnding()
{
base.OnPlayEnding();
_blockSceneTreeScroll = true;
}
/// <inheritdoc />
public override void OnPlayEnd()
{
base.OnPlayEnd();
_blockSceneTreeScroll = true;
}
/// <summary>
/// Enables or disables vertical and horizontal scrolling on the scene tree panel.
@@ -270,7 +299,7 @@ namespace FlaxEditor.Windows
_tree.Select(nodes);
// For single node selected scroll view so user can see it
if (nodes.Count == 1)
if (nodes.Count == 1 && !_blockSceneTreeScroll)
{
nodes[0].ExpandAllParents(true);
_sceneTreePanel.ScrollViewTo(nodes[0]);
@@ -280,6 +309,12 @@ namespace FlaxEditor.Windows
_isUpdatingSelection = false;
}
/// <inheritdoc />
public override void OnEditorStateChanged()
{
_blockSceneTreeScroll = Editor.StateMachine.ReloadingScriptsState.IsActive;
}
private bool ValidateDragAsset(AssetItem assetItem)
{
if (assetItem.IsOfType<SceneAsset>())

View File

@@ -20,6 +20,11 @@ namespace FlaxEditor.Windows.Search
/// </summary>
protected Image _icon;
/// <summary>
/// The color of the accent strip.
/// </summary>
protected Color _accentColor;
/// <summary>
/// The item name.
/// </summary>
@@ -56,7 +61,7 @@ namespace FlaxEditor.Windows.Search
var icon = new Image
{
Size = new Float2(logoSize),
Location = new Float2(5, (height - logoSize) / 2)
Location = new Float2(7, (height - logoSize) / 2)
};
_icon = icon;
@@ -74,6 +79,20 @@ namespace FlaxEditor.Windows.Search
typeLabel.TextColor = Style.Current.ForegroundGrey;
}
/// <inheritdoc />
public override bool OnMouseDown(Float2 location, MouseButton button)
{
// Select and focus the item on right click to prevent the search from being cleared
if (button == MouseButton.Right)
{
_finder.SelectedItem = this;
_finder.Hand = true;
Focus();
return true;
}
return base.OnMouseUp(location, button);
}
/// <inheritdoc />
public override bool OnMouseUp(Float2 location, MouseButton button)
{
@@ -86,6 +105,15 @@ namespace FlaxEditor.Windows.Search
return base.OnMouseUp(location, button);
}
/// <inheritdoc />
public override void Draw()
{
if (IsMouseOver)
Render2D.FillRectangle(new Rectangle(Float2.Zero, Size), Style.Current.BackgroundHighlighted);
base.Draw();
}
/// <inheritdoc />
public override void OnMouseEnter(Float2 location)
{
@@ -93,12 +121,7 @@ namespace FlaxEditor.Windows.Search
var root = RootWindow;
if (root != null)
{
root.Cursor = CursorType.Hand;
}
_finder.SelectedItem = this;
_finder.Hand = true;
}
/// <inheritdoc />
@@ -128,6 +151,7 @@ namespace FlaxEditor.Windows.Search
{
_asset = item;
_asset.AddReference(this);
_accentColor = Editor.Instance.ContentDatabase.GetProxy(item).AccentColor;
}
/// <inheritdoc />
@@ -176,9 +200,7 @@ namespace FlaxEditor.Windows.Search
{
string importLocation = System.IO.Path.GetDirectoryName(importPath);
if (!string.IsNullOrEmpty(importLocation) && System.IO.Directory.Exists(importLocation))
{
cm.AddButton("Show import location", () => FileSystem.ShowFileExplorer(importLocation));
}
}
}
cm.AddSeparator();
@@ -212,6 +234,10 @@ namespace FlaxEditor.Windows.Search
// Draw icon
var iconRect = _icon.Bounds;
_asset.DrawThumbnail(ref iconRect);
// Draw color strip
var rect = iconRect with { Width = 2, Height = Height, Location = new Float2(2, 0) };
Render2D.FillRectangle(rect, _accentColor);
}
/// <inheritdoc />