44
55public partial class EventScene : Node
66{
7- public static readonly string LoadPath = "res://Scenes/ChestScene/ChestScene .tscn" ;
7+ public static readonly string LoadPath = "res://Scenes/EventScene/EventScene .tscn" ;
88 private PlayerPuppet _player ;
99
1010 [ Export ]
@@ -23,23 +23,25 @@ public partial class EventScene : Node
2323
2424 private EventTemplate _eventReference ;
2525
26- public static EventScene NewEventScene ( int eventId = 0 )
26+ public static EventScene NewEventScene ( )
2727 {
2828 EventScene result = GD . Load < PackedScene > ( LoadPath ) . Instantiate < EventScene > ( ) ;
2929 result . _player = GD . Load < PackedScene > ( PlayerPuppet . LoadPath ) . Instantiate < PlayerPuppet > ( ) ;
3030 result . PlayerMarker . AddChild ( result . _player ) ;
31- result . DisplayEvent ( eventId ) ;
31+ result . DisplayEvent ( ) ;
3232 return result ;
3333 }
3434
3535 //Eventually remove this, once integrated into game
3636 public override void _Ready ( )
3737 {
38+ GD . Print ( "loaded event" ) ;
3839 _player = GD . Load < PackedScene > ( PlayerPuppet . LoadPath ) . Instantiate < PlayerPuppet > ( ) ;
3940 PlayerMarker . AddChild ( _player ) ;
4041
42+ //int eventIndex = StageProducer.GlobalRng.RandiRange(0, EventDatabase.EventDictionary.Length);
4143 _eventReference = EventDatabase . EventDictionary [ 0 ] ;
42- DisplayEvent ( 0 ) ;
44+ DisplayEvent ( ) ;
4345 }
4446
4547 public override void _Process ( double delta )
@@ -54,7 +56,7 @@ public override void _Process(double delta)
5456 /// Displays the event with the given index.
5557 /// </summary>
5658 /// <param name="eventIndex">Index of the event in EventDatabase.</param>
57- public void DisplayEvent ( int eventIndex )
59+ public void DisplayEvent ( )
5860 {
5961 _eventDescription . Text = _eventReference . EventDescription ;
6062 EventSprite . Texture = _eventReference . Texture ;
@@ -65,18 +67,27 @@ public void DisplayEvent(int eventIndex)
6567 {
6668 Text = _eventReference . ButtonDescriptions [ i ] ,
6769 Theme = _buttonTheme ,
70+ SizeFlagsVertical = Control . SizeFlags . Expand | Control . SizeFlags . Fill ,
6871 } ;
6972
70- button . SizeFlagsVertical = Control . SizeFlags . Expand | Control . SizeFlags . Fill ;
73+ // Check if the button should be enabled
74+ bool isEnabled =
75+ _eventReference . OptionEnabledConditions == null
76+ || _eventReference . OptionEnabledConditions . Length <= i
77+ || _eventReference . OptionEnabledConditions [ i ] ? . Invoke ( ) != false ;
7178
72- int capturedIndex = i ; // was given a warning to capture the index
79+ button . Disabled = ! isEnabled ;
80+
81+ int capturedIndex = i ;
7382 button . Pressed += ( ) =>
7483 {
7584 GD . Print ( $ "Selected option: { _eventReference . ButtonDescriptions [ capturedIndex ] } ") ;
7685 _eventReference . OptionActions [ capturedIndex ] ? . Invoke ( ) ;
7786 AnyButtonPressed ( capturedIndex ) ;
7887 } ;
79- if ( capturedIndex == 0 )
88+
89+ // Automatically focus the first *enabled* button
90+ if ( capturedIndex == 0 && isEnabled )
8091 {
8192 button . CallDeferred ( "grab_focus" ) ;
8293 }
0 commit comments