@@ -40,9 +40,11 @@ public ScriptsWindow(WindowManager windowManager, Map map, EditorState editorSta
4040 private XNALabel lblParameterDescription ;
4141 private EditorNumberTextBox tbParameterValue ;
4242 private MenuButton btnEditorPresetValues ;
43+ private EditorButton btnEditorPresetValuesWindow ;
4344 private XNALabel lblActionDescriptionValue ;
4445
4546 private SelectScriptActionWindow selectScriptActionWindow ;
47+ private SelectScriptActionPresetOptionWindow selectScriptActionPresetOptionWindow ;
4648 private XNAContextMenu actionListContextMenu ;
4749
4850 private SelectBuildingTargetWindow selectBuildingTargetWindow ;
@@ -61,6 +63,7 @@ public override void Initialize()
6163 lblParameterDescription = FindChild < XNALabel > ( nameof ( lblParameterDescription ) ) ;
6264 tbParameterValue = FindChild < EditorNumberTextBox > ( nameof ( tbParameterValue ) ) ;
6365 btnEditorPresetValues = FindChild < MenuButton > ( nameof ( btnEditorPresetValues ) ) ;
66+ btnEditorPresetValuesWindow = FindChild < EditorButton > ( nameof ( btnEditorPresetValuesWindow ) ) ;
6467 lblActionDescriptionValue = FindChild < XNALabel > ( nameof ( lblActionDescriptionValue ) ) ;
6568
6669 var presetValuesContextMenu = new XNAContextMenu ( WindowManager ) ;
@@ -69,6 +72,9 @@ public override void Initialize()
6972 btnEditorPresetValues . ContextMenu . OptionSelected += ContextMenu_OptionSelected ;
7073 btnEditorPresetValues . LeftClick += BtnEditorPresetValues_LeftClick ;
7174
75+ btnEditorPresetValuesWindow . LeftClick += BtnEditorPresetValuesWindow_LeftClick ;
76+ btnEditorPresetValuesWindow . Disable ( ) ;
77+
7278 tbName . TextChanged += TbName_TextChanged ;
7379 tbParameterValue . TextChanged += TbParameterValue_TextChanged ;
7480 lbScriptTypes . SelectedIndexChanged += LbScriptTypes_SelectedIndexChanged ;
@@ -78,6 +84,10 @@ public override void Initialize()
7884 var selectScriptActionDarkeningPanel = DarkeningPanel . InitializeAndAddToParentControlWithChild ( WindowManager , Parent , selectScriptActionWindow ) ;
7985 selectScriptActionDarkeningPanel . Hidden += SelectScriptActionDarkeningPanel_Hidden ;
8086
87+ selectScriptActionPresetOptionWindow = new SelectScriptActionPresetOptionWindow ( WindowManager , map ) ;
88+ var selectScriptActionPresetDarkeningPanel = DarkeningPanel . InitializeAndAddToParentControlWithChild ( WindowManager , Parent , selectScriptActionPresetOptionWindow ) ;
89+ selectScriptActionPresetDarkeningPanel . Hidden += SelectScriptActionPresetDarkeningPanel_Hidden ;
90+
8191 selectBuildingTargetWindow = new SelectBuildingTargetWindow ( WindowManager , map ) ;
8292 var buildingTargetWindowDarkeningPanel = DarkeningPanel . InitializeAndAddToParentControlWithChild ( WindowManager , Parent , selectBuildingTargetWindow ) ;
8393 buildingTargetWindowDarkeningPanel . Hidden += BuildingTargetWindowDarkeningPanel_Hidden ;
@@ -216,6 +226,18 @@ private void BtnEditorPresetValues_LeftClick(object sender, EventArgs e)
216226 }
217227 }
218228
229+ private void BtnEditorPresetValuesWindow_LeftClick ( object sender , EventArgs e )
230+ {
231+ if ( editedScript == null )
232+ return ;
233+
234+ if ( lbActions . SelectedItem == null )
235+ return ;
236+
237+ var item = selectScriptActionPresetOptionWindow . GetMatchingItem ( tbParameterValue . Text ) ;
238+ selectScriptActionPresetOptionWindow . Open ( item ) ;
239+ }
240+
219241 private void BtnAddScript_LeftClick ( object sender , EventArgs e )
220242 {
221243 map . Scripts . Add ( new Script ( map . GetNewUniqueInternalId ( ) ) { Name = "New script" } ) ;
@@ -355,6 +377,18 @@ private void SelectScriptActionDarkeningPanel_Hidden(object sender, EventArgs e)
355377 LbActions_SelectedIndexChanged ( this , EventArgs . Empty ) ;
356378 }
357379
380+
381+ private void SelectScriptActionPresetDarkeningPanel_Hidden ( object sender , EventArgs e )
382+ {
383+ if ( lbActions . SelectedItem == null || editedScript == null )
384+ {
385+ return ;
386+ }
387+
388+ if ( selectScriptActionPresetOptionWindow . SelectedObject != null )
389+ tbParameterValue . Text = selectScriptActionPresetOptionWindow . GetSelectedItemText ( ) ;
390+ }
391+
358392 private void LbActions_SelectedIndexChanged ( object sender , EventArgs e )
359393 {
360394 if ( lbActions . SelectedItem == null || editedScript == null )
@@ -378,7 +412,23 @@ private void LbActions_SelectedIndexChanged(object sender, EventArgs e)
378412 lblParameterDescription . Text = action == null ? "Parameter:" : action . ParamDescription + ":" ;
379413 lblActionDescriptionValue . Text = GetActionDescriptionFromIndex ( entry . Action ) ;
380414
381- FillPresetContextMenu ( entry , action ) ;
415+ string text = null ;
416+
417+ if ( action . UseWindowSelection && action . PresetOptions . Count > 0 )
418+ {
419+ btnEditorPresetValues . Disable ( ) ;
420+ btnEditorPresetValuesWindow . Enable ( ) ;
421+ text = selectScriptActionPresetOptionWindow . FillPresetOptions ( entry , action ) ;
422+ }
423+ else
424+ {
425+ btnEditorPresetValues . Enable ( ) ;
426+ btnEditorPresetValuesWindow . Disable ( ) ;
427+ text = FillPresetContextMenu ( entry , action ) ;
428+ }
429+
430+ if ( text != null )
431+ tbParameterValue . Text = text ;
382432 }
383433
384434 private void SetParameterEntryText ( ScriptActionEntry scriptActionEntry , ScriptAction action )
@@ -431,7 +481,7 @@ private string GetBuildingWithPropertyText(int argument)
431481 return GetBuildingWithPropertyText ( index , property ) ;
432482 }
433483
434- private void FillPresetContextMenu ( ScriptActionEntry entry , ScriptAction action )
484+ private string FillPresetContextMenu ( ScriptActionEntry entry , ScriptAction action )
435485 {
436486 btnEditorPresetValues . ContextMenu . ClearItems ( ) ;
437487
@@ -468,7 +518,9 @@ private void FillPresetContextMenu(ScriptActionEntry entry, ScriptAction action)
468518
469519 var fittingItem = btnEditorPresetValues . ContextMenu . Items . Find ( item => item . Text . StartsWith ( entry . Argument . ToString ( ) ) ) ;
470520 if ( fittingItem != null )
471- tbParameterValue . Text = fittingItem . Text ;
521+ return fittingItem . Text ;
522+
523+ return null ;
472524 }
473525
474526 private void LbScriptTypes_SelectedIndexChanged ( object sender , EventArgs e ) => RefreshSelectedScript ( ) ;
@@ -532,9 +584,9 @@ private void EditScript(Script script)
532584 for ( int i = 0 ; i < editedScript . Actions . Count ; i ++ )
533585 {
534586 var actionEntry = editedScript . Actions [ i ] ;
535- lbActions . AddItem ( new XNAListBoxItem ( )
536- {
537- Text = GetActionEntryText ( i , actionEntry ) ,
587+ lbActions . AddItem ( new XNAListBoxItem ( )
588+ {
589+ Text = GetActionEntryText ( i , actionEntry ) ,
538590 Tag = actionEntry
539591 } ) ;
540592 }
@@ -546,7 +598,7 @@ private string GetActionEntryText(int index, ScriptActionEntry entry)
546598 {
547599 ScriptAction action = GetScriptAction ( entry . Action ) ;
548600 if ( action == null )
549- return "#" + index + " - Unknown (" + entry . Argument . ToString ( CultureInfo . InvariantCulture ) + ")" ;
601+ return "#" + index + " - Unknown (" + entry . Argument . ToString ( CultureInfo . InvariantCulture ) + ")" ;
550602
551603 return "#" + index + " - " + action . Name + " (" + entry . Argument . ToString ( CultureInfo . InvariantCulture ) + ")" ;
552604 }
0 commit comments