2020using System . Diagnostics ;
2121using System . Drawing ;
2222using System . Linq ;
23+ using System . Reflection ;
2324using System . Text . RegularExpressions ;
2425using System . Windows . Forms ;
2526using GNU . Gettext ;
@@ -122,6 +123,8 @@ public partial class MapViewer : Form
122123 private double lastUpdateTime ;
123124
124125 private bool MapCustomizationVisible = false ;
126+
127+ private Form GameForm ;
125128 #endregion
126129
127130 public MapViewer ( Simulator simulator , Viewer viewer )
@@ -139,9 +142,9 @@ public MapViewer(Simulator simulator, Viewer viewer)
139142 MapThemeProvider = new MapThemeProvider ( ) ;
140143 nodes = simulator . TDB . TrackDB . TrackNodes ;
141144
145+ ViewWindow = new RectangleF ( 0 , 0 , 5000f , 5000f ) ;
142146 InitializeForm ( ) ;
143147
144- ViewWindow = new RectangleF ( 0 , 0 , 5000f , 5000f ) ;
145148 mapResolutionUpDown . Accelerations . Add ( new NumericUpDownAcceleration ( 1 , 100 ) ) ;
146149 selectedTrainList = new List < Train > ( ) ;
147150
@@ -153,6 +156,8 @@ public MapViewer(Simulator simulator, Viewer viewer)
153156 AddNewMessage ( e . Time , e . Message ) ;
154157 } ;
155158
159+ GameForm = ( Form ) System . Windows . Forms . Control . FromHandle ( Viewer . Game . Window . Handle ) ; // qqq
160+
156161 // Initialise the timer used to handle user input
157162 UITimer = new Timer ( ) ;
158163 UITimer . Interval = 100 ;
@@ -193,6 +198,110 @@ void InitializeForm()
193198 float [ ] dashPattern = { 4 , 2 } ;
194199 ZoomTargetPen . DashPattern = dashPattern ;
195200 pathPen . DashPattern = dashPattern ;
201+
202+ setDefaults ( this ) ;
203+ }
204+
205+ //
206+ // set the defaults for all the map controls which have a property in UserSettings.c
207+ // properties are stored in the registry or in a .ini file
208+ //
209+ private void setDefaults ( System . Windows . Forms . Control controlToSet )
210+ {
211+ foreach ( System . Windows . Forms . Control control in controlToSet . Controls )
212+ {
213+ // recursive call to find deeper controls
214+ setDefaults ( control ) ;
215+ }
216+
217+ string name = "Map_" + controlToSet . Name ;
218+ PropertyInfo property = Viewer . Settings . GetProperty ( name ) ;
219+ if ( property != null )
220+ {
221+ if ( controlToSet is CheckBox checkBox )
222+ {
223+ checkBox . Checked = ( bool ) property . GetValue ( Viewer . Settings ) ;
224+ checkBox . CheckedChanged += c_ControlChanged ;
225+ }
226+ if ( controlToSet is NumericUpDown numericUpDown )
227+ {
228+ numericUpDown . Value = ( int ) property . GetValue ( Viewer . Settings , null ) ;
229+ numericUpDown . ValueChanged += c_ControlChanged ;
230+ }
231+ if ( controlToSet is Button button )
232+ {
233+ if ( name . Equals ( "Map_rotateThemesButton" ) )
234+ {
235+ ThemeName = ( string ) property . GetValue ( Viewer . Settings , null ) ;
236+ Theme = MapThemeProvider . GetTheme ( ThemeName ) ;
237+
238+ ApplyThemeRecursively ( this ) ;
239+ MapCanvasColor = Theme . MapCanvasColor ;
240+ TrackPen . Color = Theme . TrackColor ;
241+ }
242+ button . Click += c_ControlChanged ;
243+ }
244+ if ( controlToSet is RadioButton radioButton )
245+ {
246+ radioButton . Checked = ( bool ) property . GetValue ( Viewer . Settings ) ;
247+ radioButton . CheckedChanged += c_ControlChanged ;
248+ }
249+ if ( controlToSet is MapViewer mapViewer )
250+ {
251+ Size size = new Size (
252+ ( ( int [ ] ) property . GetValue ( Viewer . Settings , null ) ) [ 2 ] ,
253+ ( ( int [ ] ) property . GetValue ( Viewer . Settings , null ) ) [ 3 ] ) ;
254+ Size = size ;
255+
256+ StartPosition = FormStartPosition . Manual ;
257+ this . Location = new System . Drawing . Point (
258+ ( ( int [ ] ) property . GetValue ( Viewer . Settings , null ) ) [ 0 ] ,
259+ ( ( int [ ] ) property . GetValue ( Viewer . Settings , null ) ) [ 1 ] ) ;
260+
261+ mapViewer . Resize += c_ControlChanged ;
262+ mapViewer . Move += c_ControlChanged ;
263+ }
264+ }
265+ }
266+
267+ //
268+ // save the setting of a map control
269+ //
270+ void c_ControlChanged ( object sender , EventArgs e )
271+ {
272+ if ( sender is CheckBox checkBox )
273+ {
274+ string name = "Map_" + checkBox . Name ;
275+ Viewer . Settings . GetProperty ( name ) . SetValue ( Viewer . Settings , checkBox . CheckState == CheckState . Checked , null ) ;
276+ Viewer . Settings . Save ( name ) ;
277+ }
278+ if ( sender is NumericUpDown numericUpDown )
279+ {
280+ string name = "Map_" + numericUpDown . Name ;
281+ Viewer . Settings . GetProperty ( name ) . SetValue ( Viewer . Settings , ( int ) numericUpDown . Value , null ) ;
282+ Viewer . Settings . Save ( name ) ;
283+ }
284+ if ( sender is Button button )
285+ {
286+ string name = "Map_" + button . Name ;
287+ Viewer . Settings . GetProperty ( name ) . SetValue ( Viewer . Settings , ThemeName , null ) ;
288+ Viewer . Settings . Save ( name ) ;
289+ }
290+ if ( sender is RadioButton radioButton )
291+ {
292+ string name = "Map_" + radioButton . Name ;
293+ Viewer . Settings . GetProperty ( name ) . SetValue ( Viewer . Settings , radioButton . Checked , null ) ;
294+ Viewer . Settings . Save ( name ) ;
295+ }
296+ if ( sender is MapViewer mapViewer )
297+ {
298+ string name = "Map_" + mapViewer . Name ;
299+
300+ int X = this . Bounds . X ;
301+ int Y = this . Bounds . Y ;
302+ Viewer . Settings . GetProperty ( name ) . SetValue ( Viewer . Settings , new int [ ] { X , Y , Size . Width , Size . Height } , null ) ;
303+ Viewer . Settings . Save ( name ) ;
304+ }
196305 }
197306
198307 #region initData
@@ -1233,6 +1342,13 @@ void UITimer_Tick(object sender, EventArgs e)
12331342 }
12341343 Visible = true ;
12351344
1345+ if ( Viewer . MapViewerEnabledSetToTrue )
1346+ {
1347+ GenerateView ( ) ;
1348+ GameForm . Focus ( ) ;
1349+ Viewer . MapViewerEnabledSetToTrue = false ;
1350+ }
1351+
12361352 if ( Program . Simulator . GameTime - lastUpdateTime < 1 )
12371353 return ;
12381354
0 commit comments