Skip to content

Commit 036d8e3

Browse files
authored
Merge branch 'master' into hammer-scene-prefabs
2 parents b7717bf + 4bcacf0 commit 036d8e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4165
-2974
lines changed

engine/Sandbox.Engine/Editor/Gizmos/Gizmo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static void Select( bool allowUnselect = true, bool allowMultiSelect = tr
8888
return;
8989
}
9090

91-
if ( Active.Selection.Contains( Object ) )
91+
if ( Object is not null && Active.Selection.Contains( Object ) )
9292
{
9393
Active.Selection.Remove( Object );
9494
return;

engine/Sandbox.System/Utility/SelectionSystem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Sandbox;
88
public class SelectionSystem : IEnumerable<object>
99
{
1010
// Value is always false and unused - we only need the ordered key collection
11-
private OrderedDictionary<object, bool> _list { get; } = new();
11+
private readonly OrderedDictionary<object, bool> _list = new();
1212

1313
// Random hash code that changes when the collection is modified
1414
int _hashCode = Random.Shared.Int( 0, 4096 );
@@ -120,6 +120,7 @@ public virtual bool Remove( object obj )
120120
/// <returns>True if the object is selected</returns>
121121
public virtual bool Contains( object obj )
122122
{
123+
if ( obj is null ) return false;
123124
return _list.ContainsKey( obj );
124125
}
125126

engine/Sandbox.Tools/EditorShortcuts.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ internal static void RegisterShortcuts()
2828
{
2929
Entries.Clear();
3030

31-
3231
var methods = EditorTypeLibrary.GetMethodsWithAttribute<ShortcutAttribute>( false );
3332

3433
foreach ( var method in methods )
@@ -46,7 +45,6 @@ internal static void RegisterShortcuts()
4645
method.Attribute.Type = ShortcutType.Window;
4746
}
4847

49-
5048
var entry = new Entry( method.Method, method.Attribute, group );
5149
Entries.Add( entry );
5250
}

engine/Sandbox.Tools/MeshEditor/PrimitiveBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,6 @@ public Face AddFace( params Vector3[] positions )
9191
/// <summary>
9292
/// The material to use for this whole primitive.
9393
/// </summary>
94+
[Hide]
9495
public Material Material { get; set; } = Material.Load( "materials/dev/reflectivity_30.vmat" );
9596
}

engine/Sandbox.Tools/Qt/Graphic/Paint.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,17 @@ internal static IDisposable Start( QPainter e, StateFlag flags = StateFlag.None,
595595

596596
public static Rect DrawIcon( Rect rect, string iconName, float pixelHeight, TextFlag alignment = TextFlag.Center )
597597
{
598+
if ( string.IsNullOrEmpty( iconName ) )
599+
return rect;
600+
601+
if ( iconName.Contains( '.' ) )
602+
{
603+
var innerRect = rect.Align( new Vector2( pixelHeight, pixelHeight ), alignment );
604+
605+
Draw( innerRect, iconName, Pen.a );
606+
return innerRect;
607+
}
608+
598609
// save and restore the font
599610
var of = fontInfo;
600611

@@ -615,12 +626,12 @@ public static void Draw( Rect r, Pixmap pixmap, float alpha = 1.0f )
615626
Current.drawPixmap( r, pixmap.ptr, src, alpha );
616627
}
617628

618-
public static void Draw( Rect r, string image )
629+
public static void Draw( Rect r, string image, float alpha = 1.0f )
619630
{
620631
// find the image, and resize it to this size to make it nice
621632
var pixmap = LoadImage( image, (int)(r.Size.x * _dpiScale), (int)(r.Size.y * _dpiScale) );
622633

623-
Draw( r, pixmap );
634+
Draw( r, pixmap, alpha );
624635
}
625636

626637
public static IDisposable ToPixmap( Pixmap pixmap )
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
3+
namespace Editor;
4+
5+
/// <summary>
6+
/// A material icon label
7+
/// </summary>
8+
public class IconLabel : Widget
9+
{
10+
public string Icon { get; set; }
11+
public float IconSize { get; set; } = 12.0f;
12+
public Color Background { get; set; }
13+
public Color Foreground { get; set; }
14+
15+
public Action<bool> OnToggled { get; set; }
16+
17+
public IconLabel( string icon, Widget parent = null ) : base( parent )
18+
{
19+
Icon = icon;
20+
21+
Background = Color.Transparent;
22+
Foreground = Theme.Text;
23+
24+
FixedHeight = Theme.RowHeight;
25+
FixedWidth = Theme.RowHeight;
26+
}
27+
28+
protected override Vector2 SizeHint()
29+
{
30+
return MinimumWidth;
31+
}
32+
33+
protected override void OnPaint()
34+
{
35+
Paint.ClearBrush();
36+
Paint.ClearPen();
37+
38+
var bg = Background;
39+
var fg = Foreground;
40+
41+
Paint.SetBrush( bg );
42+
Paint.DrawRect( LocalRect, 2.0f );
43+
44+
Paint.ClearBrush();
45+
Paint.ClearPen();
46+
47+
Paint.Pen = fg;
48+
if ( !Enabled ) Paint.Pen = fg.WithAlphaMultiplied( 0.25f );
49+
50+
Paint.DrawIcon( LocalRect, Icon, IconSize, TextFlag.Center );
51+
}
52+
}

game/addons/tools/Code/MeshEditor/Primitives/Block.cs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,24 @@ namespace Editor.MeshEditor;
44
[Title( "Block" ), Icon( "rectangle" )]
55
public class BlockPrimitive : PrimitiveBuilder
66
{
7-
public bool Top { get; set; } = true;
8-
public bool Bottom { get; set; } = true;
9-
public bool Left { get; set; } = true;
10-
public bool Right { get; set; } = true;
11-
public bool Front { get; set; } = true;
12-
public bool Back { get; set; } = true;
7+
[Flags]
8+
public enum Side
9+
{
10+
[Hide]
11+
None = 0,
12+
13+
Top = 1 << 0,
14+
Bottom = 1 << 1,
15+
Left = 1 << 2,
16+
Right = 1 << 3,
17+
Front = 1 << 4,
18+
Back = 1 << 5,
19+
20+
[Hide]
21+
All = Top | Bottom | Left | Right | Front | Back
22+
}
23+
24+
public Side Sides { get; set; } = Side.All;
1325
public bool Hollow { get; set; } = false;
1426

1527
[Hide] private BBox _box;
@@ -32,9 +44,10 @@ public override void Build( PolygonMesh mesh )
3244
maxs = _box.Maxs;
3345
}
3446

35-
if ( Top )
47+
bool Has( Side s ) => (Sides & s) != 0;
48+
49+
if ( Has( Side.Top ) )
3650
{
37-
// x planes - top first
3851
mesh.AddFace(
3952
new Vector3( mins.x, mins.y, maxs.z ),
4053
new Vector3( maxs.x, mins.y, maxs.z ),
@@ -43,9 +56,8 @@ public override void Build( PolygonMesh mesh )
4356
);
4457
}
4558

46-
if ( Bottom )
59+
if ( Has( Side.Bottom ) )
4760
{
48-
// x planes - bottom
4961
mesh.AddFace(
5062
new Vector3( mins.x, maxs.y, mins.z ),
5163
new Vector3( maxs.x, maxs.y, mins.z ),
@@ -54,9 +66,8 @@ public override void Build( PolygonMesh mesh )
5466
);
5567
}
5668

57-
if ( Left )
69+
if ( Has( Side.Left ) )
5870
{
59-
// y planes - left
6071
mesh.AddFace(
6172
new Vector3( mins.x, maxs.y, mins.z ),
6273
new Vector3( mins.x, mins.y, mins.z ),
@@ -65,9 +76,8 @@ public override void Build( PolygonMesh mesh )
6576
);
6677
}
6778

68-
if ( Right )
79+
if ( Has( Side.Right ) )
6980
{
70-
// y planes - right
7181
mesh.AddFace(
7282
new Vector3( maxs.x, maxs.y, maxs.z ),
7383
new Vector3( maxs.x, mins.y, maxs.z ),
@@ -76,9 +86,8 @@ public override void Build( PolygonMesh mesh )
7686
);
7787
}
7888

79-
if ( Front )
89+
if ( Has( Side.Front ) )
8090
{
81-
// x planes - farthest
8291
mesh.AddFace(
8392
new Vector3( maxs.x, maxs.y, mins.z ),
8493
new Vector3( mins.x, maxs.y, mins.z ),
@@ -87,9 +96,8 @@ public override void Build( PolygonMesh mesh )
8796
);
8897
}
8998

90-
if ( Back )
99+
if ( Has( Side.Back ) )
91100
{
92-
// x planes - nearest
93101
mesh.AddFace(
94102
new Vector3( maxs.x, mins.y, maxs.z ),
95103
new Vector3( mins.x, mins.y, maxs.z ),

0 commit comments

Comments
 (0)