@@ -33,6 +33,12 @@ private class MaskCallbackInfo
3333 // Which view should we send it to.
3434 private readonly GUIView m_SourceView ;
3535
36+ // Current drop-down reference
37+ public MaskFieldDropDown m_DropDown ;
38+
39+ // validation flag for masks that are changed externally
40+ private bool m_Validate = false ;
41+
3642 public MaskCallbackInfo ( int controlID )
3743 {
3844 m_ControlID = controlID ;
@@ -77,6 +83,31 @@ internal void SetMaskValueDelegate(object userData, string[] options, int select
7783 if ( m_SourceView )
7884 m_SourceView . SendEvent ( EditorGUIUtility . CommandEvent ( kMaskMenuChangedMessage ) ) ;
7985 }
86+
87+ public void UpdateFlagChanges ( int mask , int [ ] optionMaskValues )
88+ {
89+ var evt = Event . current ;
90+
91+ if ( evt . type == EventType . ExecuteCommand )
92+ {
93+ m_Validate = true ;
94+ }
95+ // This code is responsible for verifying whether the incoming mask value differs from the one that is currently selected in the dropdown menu.
96+ // When these values do not match, it serves as confirmation that the incoming value has been modified.
97+ // Subsequently, we proceed to update the dropdown menu to reflect these changes.
98+ else if ( evt . type == EventType . Repaint && m_Validate )
99+ {
100+ if ( m_DropDown == null )
101+ {
102+ return ;
103+ }
104+
105+ if ( mask != m_NewMask )
106+ m_DropDown . UpdateMaskValues ( mask , optionMaskValues ) ;
107+
108+ m_Validate = false ;
109+ }
110+ }
80111 }
81112
82113 /// Make a field for a generic mask.
@@ -117,6 +148,10 @@ internal static int DoMaskField(Rect position, int controlID, int mask, string[]
117148
118149 GetMenuOptions ( mask , flagNames , flagValues , out var buttonText , out var buttonTextMixed , out var optionNames , out var optionMaskValues , out _ , enumType ) ;
119150
151+ // This checks and update flags changes that are modified out of dropdown menu
152+ if ( MaskCallbackInfo . m_Instance != null )
153+ MaskCallbackInfo . m_Instance . UpdateFlagChanges ( mask , optionMaskValues ) ;
154+
120155 Event evt = Event . current ;
121156 if ( evt . type == EventType . Repaint )
122157 {
@@ -126,7 +161,8 @@ internal static int DoMaskField(Rect position, int controlID, int mask, string[]
126161 else if ( ( evt . type == EventType . MouseDown && position . Contains ( evt . mousePosition ) ) || evt . MainActionKeyForControl ( controlID ) )
127162 {
128163 MaskCallbackInfo . m_Instance = new MaskCallbackInfo ( controlID ) ;
129- PopupWindowWithoutFocus . Show ( position , new MaskFieldDropDown ( optionNames , flagValues , optionMaskValues , mask , MaskCallbackInfo . m_Instance . SetMaskValueDelegate ) ) ;
164+ MaskCallbackInfo . m_Instance . m_DropDown = new MaskFieldDropDown ( optionNames , flagValues , optionMaskValues , mask , MaskCallbackInfo . m_Instance . SetMaskValueDelegate ) ;
165+ PopupWindowWithoutFocus . Show ( position , MaskCallbackInfo . m_Instance . m_DropDown ) ;
130166 }
131167
132168 return mask ;
0 commit comments