1
1
using System ;
2
2
using System . Collections . Generic ;
3
- using UGF . EditorTools . Runtime . Ids ;
4
3
using UnityEngine . UIElements ;
5
4
6
5
namespace UGF . DebugTools . Runtime . UI
7
6
{
8
7
public class DebugUIMenuElement : DebugUIElement
9
8
{
10
9
public string DisplayName { get ; }
11
- public IDictionary < GlobalId , DebugUIElement > Menus { get ; }
12
- public GlobalId Selected { get { return m_selected ?? throw new ArgumentException ( "Value not specified." ) ; } }
13
- public bool HasSelected { get { return m_selected != null ; } }
10
+ public IReadOnlyList < DebugUIMenu > Menus { get ; }
11
+ public int Selected { get { return m_selected ?? throw new ArgumentException ( "Value not specified." ) ; } }
12
+ public bool HasSelected { get { return m_selected . HasValue ; } }
14
13
14
+ public static string NoneMenuName { get ; } = "None" ;
15
15
public static string UssClassName { get ; } = "ugf-debugtools-menu" ;
16
16
public static string EnabledUssClassName { get ; } = "ugf-debugtools-menu--enabled" ;
17
17
public static string DisabledUssClassName { get ; } = "ugf-debugtools-menu--disabled" ;
@@ -24,9 +24,9 @@ public class DebugUIMenuElement : DebugUIElement
24
24
25
25
private readonly VisualElement m_headerContent ;
26
26
private readonly VisualElement m_bodyContent ;
27
- private GlobalId ? m_selected ;
27
+ private int ? m_selected ;
28
28
29
- public DebugUIMenuElement ( string displayName , IDictionary < GlobalId , DebugUIElement > menus )
29
+ public DebugUIMenuElement ( string displayName , IReadOnlyList < DebugUIMenu > menus )
30
30
{
31
31
if ( string . IsNullOrEmpty ( displayName ) ) throw new ArgumentException ( "Value cannot be null or empty." , nameof ( displayName ) ) ;
32
32
@@ -47,7 +47,7 @@ public DebugUIMenuElement(string displayName, IDictionary<GlobalId, DebugUIEleme
47
47
} ;
48
48
49
49
var toggle = new Toggle ( ) ;
50
- var selection = new PopupField < GlobalId ? > ( OnSelectionCreateList ( ) , 0 , OnSelectionNameFormat , OnSelectionNameFormat ) ;
50
+ var selection = new PopupField < int ? > ( OnSelectionCreateList ( ) , 0 , OnSelectionNameFormat , OnSelectionNameFormat ) ;
51
51
52
52
Add ( header ) ;
53
53
Add ( body ) ;
@@ -59,11 +59,13 @@ public DebugUIMenuElement(string displayName, IDictionary<GlobalId, DebugUIEleme
59
59
m_headerContent . Add ( new Label ( DisplayName ) ) ;
60
60
m_bodyContent . Add ( selection ) ;
61
61
62
- foreach ( ( _ , DebugUIElement element ) in Menus )
62
+ for ( int i = 0 ; i < Menus . Count ; i ++ )
63
63
{
64
- element . AddToClassList ( BodyContentNotSelectedUssClassName ) ;
64
+ DebugUIMenu menu = Menus [ i ] ;
65
65
66
- m_bodyContent . Add ( element ) ;
66
+ menu . Element . AddToClassList ( BodyContentNotSelectedUssClassName ) ;
67
+
68
+ m_bodyContent . Add ( menu . Element ) ;
67
69
}
68
70
69
71
toggle . RegisterValueChangedCallback ( OnToggle ) ;
@@ -79,28 +81,28 @@ public DebugUIMenuElement(string displayName, IDictionary<GlobalId, DebugUIEleme
79
81
m_bodyContent . AddToClassList ( BodyContentUssClassName ) ;
80
82
}
81
83
82
- public void SetSelected ( GlobalId id )
84
+ public void SetSelected ( int index )
83
85
{
84
- if ( ! id . IsValid ( ) ) throw new ArgumentException ( "Value should be valid." , nameof ( id ) ) ;
86
+ if ( index < 0 || index >= Menus . Count ) throw new ArgumentOutOfRangeException ( nameof ( index ) ) ;
85
87
86
88
ClearSelected ( ) ;
87
89
88
- m_selected = id ;
90
+ m_selected = index ;
89
91
90
- DebugUIElement element = Menus [ m_selected . Value ] ;
92
+ DebugUIMenu menu = Menus [ m_selected . Value ] ;
91
93
92
- element . RemoveFromClassList ( BodyContentNotSelectedUssClassName ) ;
93
- element . AddToClassList ( BodyContentSelectedUssClassName ) ;
94
+ menu . Element . RemoveFromClassList ( BodyContentNotSelectedUssClassName ) ;
95
+ menu . Element . AddToClassList ( BodyContentSelectedUssClassName ) ;
94
96
}
95
97
96
98
public bool ClearSelected ( )
97
99
{
98
100
if ( m_selected . HasValue )
99
101
{
100
- DebugUIElement element = Menus [ m_selected . Value ] ;
102
+ DebugUIMenu menu = Menus [ m_selected . Value ] ;
101
103
102
- element . RemoveFromClassList ( BodyContentSelectedUssClassName ) ;
103
- element . AddToClassList ( BodyContentNotSelectedUssClassName ) ;
104
+ menu . Element . RemoveFromClassList ( BodyContentSelectedUssClassName ) ;
105
+ menu . Element . AddToClassList ( BodyContentNotSelectedUssClassName ) ;
104
106
105
107
m_selected = null ;
106
108
return true ;
@@ -118,7 +120,7 @@ private void OnToggle(ChangeEvent<bool> changeEvent)
118
120
m_bodyContent . visible = changeEvent . newValue ;
119
121
}
120
122
121
- private void OnSelectionChange ( ChangeEvent < GlobalId ? > changeEvent )
123
+ private void OnSelectionChange ( ChangeEvent < int ? > changeEvent )
122
124
{
123
125
if ( changeEvent . newValue . HasValue )
124
126
{
@@ -130,18 +132,18 @@ private void OnSelectionChange(ChangeEvent<GlobalId?> changeEvent)
130
132
}
131
133
}
132
134
133
- private string OnSelectionNameFormat ( GlobalId ? id )
135
+ private string OnSelectionNameFormat ( int ? id )
134
136
{
135
- return id . HasValue ? Menus [ id . Value ] . name : "None" ;
137
+ return id . HasValue ? Menus [ id . Value ] . Name : NoneMenuName ;
136
138
}
137
139
138
- private List < GlobalId ? > OnSelectionCreateList ( )
140
+ private List < int ? > OnSelectionCreateList ( )
139
141
{
140
- var list = new List < GlobalId ? > { default } ;
142
+ var list = new List < int ? > { default } ;
141
143
142
- foreach ( ( GlobalId id , _ ) in Menus )
144
+ for ( int i = 0 ; i < Menus . Count ; i ++ )
143
145
{
144
- list . Add ( id ) ;
146
+ list . Add ( i ) ;
145
147
}
146
148
147
149
return list ;
0 commit comments