Skip to content

Commit e35b139

Browse files
authored
Fast Texturing Tool Undo/Redo (#3720)
- Add Undo Scopes to new Fast Texturing Tool so you can undo/redo - Save FastTextureSettings in OnClose instead of on ENTER shortcut so that it saves even when closed via X or clicking away from the window https://files.facepunch.com/CarsonKompon/2026/January/07_10-06-WaterloggedSableantelope.mp4
1 parent 3f98609 commit e35b139

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

game/addons/tools/Code/Editor/RectEditor/FastTextureWindow.cs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Editor.MeshEditor;
2-
using Sandbox;
32
using Sandbox.UI;
43

54
namespace Editor.RectEditor;
@@ -11,6 +10,8 @@ public class FastTextureWindow : Window
1110
private List<Material> OriginalMaterials { get; set; } = new();
1211
public RectView _RectView { get; private set; }
1312

13+
private IDisposable _undoScope;
14+
1415
public FastTextureWindow() : base()
1516
{
1617
Size = new Vector2( 700, 850 );
@@ -57,10 +58,22 @@ private void InitializeWithFaces( MeshFace[] faces, Material material )
5758
OriginalUVs.Clear();
5859
OriginalMaterials.Clear();
5960

61+
List<MeshComponent> components = new();
6062
foreach ( var face in faces )
6163
{
6264
OriginalUVs.Add( face.TextureCoordinates.ToArray() );
6365
OriginalMaterials.Add( face.Material );
66+
if ( face.Component.IsValid() && !components.Contains( face.Component ) )
67+
{
68+
components.Add( face.Component );
69+
}
70+
}
71+
72+
if ( _undoScope == null )
73+
{
74+
_undoScope = SceneEditorSession.Active.UndoScope( "Fast Texture Tool" )
75+
.WithComponentChanges( components )
76+
.Push();
6477
}
6578

6679
if ( material != null )
@@ -214,6 +227,18 @@ public void Cancel()
214227

215228
[Shortcut( "editor.confirm", "ENTER" )]
216229
public void Confirm()
230+
{
231+
Close();
232+
}
233+
234+
[Shortcut( "editor.fasttexture.resetuvs", "Shift+R" )]
235+
public void ResetUVs()
236+
{
237+
_RectView?.ResetUV();
238+
Update();
239+
}
240+
241+
protected override bool OnClose()
217242
{
218243
var meshRect = Document?.Rectangles.OfType<Document.MeshRectangle>().FirstOrDefault();
219244
if ( meshRect != null )
@@ -224,14 +249,10 @@ public void Confirm()
224249

225250
Settings.FastTextureSettings.Save();
226251

227-
Close();
228-
}
252+
_undoScope?.Dispose();
253+
_undoScope = null;
229254

230-
[Shortcut( "editor.fasttexture.resetuvs", "Shift+R" )]
231-
public void ResetUVs()
232-
{
233-
_RectView?.ResetUV();
234-
Update();
255+
return base.OnClose();
235256
}
236257
}
237258

0 commit comments

Comments
 (0)