22using System . Drawing ;
33using System . Windows . Forms ;
44using System . Linq ;
5+ using System . Collections . Generic ;
56
67namespace WinFormsApp1
78{
@@ -24,6 +25,11 @@ public partial class Form1 : Form
2425 private Button quickInventoryButton ;
2526 private Button quickMapButton ;
2627
28+ // UI elements that should be disabled until game starts
29+ private List < Control > gameRequiredControls ;
30+ private List < ToolStripItem > gameRequiredMenuItems ;
31+ private List < ToolStripItem > gameRequiredToolbarItems ;
32+
2733 public Form1 ( )
2834 {
2935 InitializeComponent ( ) ;
@@ -78,10 +84,81 @@ private void InitializeGameUI()
7884 // Apply default theme
7985 ApplyTheme ( "Classic" ) ;
8086
87+ // Initialize game-required controls tracking
88+ InitializeGameStateControls ( ) ;
89+
8190 // Set focus to input
8291 inputTextBox . Focus ( ) ;
8392 }
8493
94+ private void InitializeGameStateControls ( )
95+ {
96+ gameRequiredControls = new List < Control > ( ) ;
97+ gameRequiredMenuItems = new List < ToolStripItem > ( ) ;
98+ gameRequiredToolbarItems = new List < ToolStripItem > ( ) ;
99+
100+ // Initially disable game-dependent UI elements
101+ SetGameControlsEnabled ( false ) ;
102+ }
103+
104+ private void SetGameControlsEnabled ( bool enabled )
105+ {
106+ // Find and manage toolbar items
107+ foreach ( ToolStripItem item in toolStrip . Items )
108+ {
109+ if ( item . Text == "Save" || item . Text == "Load" || item . Text == "Inventory" || item . Text == "Map" )
110+ {
111+ item . Enabled = enabled ;
112+ }
113+ }
114+
115+ // Find and manage menu items
116+ foreach ( ToolStripMenuItem mainMenu in menuStrip . Items )
117+ {
118+ if ( mainMenu . Text . Contains ( "Character" ) || mainMenu . Text . Contains ( "World" ) )
119+ {
120+ mainMenu . Enabled = enabled ;
121+ }
122+ else if ( mainMenu . Text . Contains ( "Game" ) )
123+ {
124+ foreach ( ToolStripItem subItem in mainMenu . DropDownItems )
125+ {
126+ if ( subItem . Text . Contains ( "Save" ) || subItem . Text . Contains ( "Load" ) )
127+ {
128+ subItem . Enabled = enabled ;
129+ }
130+ }
131+ }
132+ }
133+
134+ // Manage quick action buttons
135+ if ( quickInventoryButton != null ) quickInventoryButton . Enabled = enabled ;
136+ if ( quickMapButton != null ) quickMapButton . Enabled = enabled ;
137+
138+ // Find and manage side panel quick action buttons
139+ var quickActionsPanel = sidePanel ? . Controls . OfType < GroupBox > ( ) . FirstOrDefault ( g => g . Text == "Quick Actions" ) ;
140+ if ( quickActionsPanel != null )
141+ {
142+ foreach ( Control control in quickActionsPanel . Controls )
143+ {
144+ if ( control is TableLayoutPanel layout )
145+ {
146+ foreach ( Control button in layout . Controls )
147+ {
148+ if ( button is Button btn && ( btn . Text == "Stats" || btn . Text == "Save" || btn . Text == "Load" ) )
149+ {
150+ btn . Enabled = enabled ;
151+ }
152+ }
153+ }
154+ }
155+ }
156+
157+ // Enable/disable input controls
158+ if ( inputTextBox != null ) inputTextBox . Enabled = enabled ;
159+ if ( submitButton != null ) submitButton . Enabled = enabled ;
160+ }
161+
85162 private void CreateMenuStrip ( )
86163 {
87164 menuStrip = new MenuStrip ( ) ;
@@ -363,10 +440,11 @@ private GroupBox CreateStatsPanel()
363440 AutoSizeMode = AutoSizeMode . GrowAndShrink ,
364441 ColumnCount = 2 ,
365442 RowCount = 8 , // Increased to accommodate more stats
366- Dock = DockStyle . Top
443+ Location = new Point ( 0 , 0 ) ,
444+ Width = statsContainer . Width - 10 // Account for padding
367445 } ;
368446
369- // Set column styles
447+ // Set column styles to prevent overflow
370448 statsLayout . ColumnStyles . Add ( new ColumnStyle ( SizeType . AutoSize ) ) ;
371449 statsLayout . ColumnStyles . Add ( new ColumnStyle ( SizeType . AutoSize ) ) ;
372450
@@ -997,5 +1075,15 @@ protected override void OnFormClosing(FormClosingEventArgs e)
9971075 }
9981076 base . OnFormClosing ( e ) ;
9991077 }
1078+
1079+ public void EnableGameControls ( bool enabled )
1080+ {
1081+ if ( this . InvokeRequired )
1082+ {
1083+ this . Invoke ( new Action ( ( ) => EnableGameControls ( enabled ) ) ) ;
1084+ return ;
1085+ }
1086+ SetGameControlsEnabled ( enabled ) ;
1087+ }
10001088 }
10011089}
0 commit comments