-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrmMain.cs
More file actions
169 lines (144 loc) · 5.51 KB
/
FrmMain.cs
File metadata and controls
169 lines (144 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MSFS2020Ctrls.Layout;
using MSFS2020Ctrls.MSFS;
namespace MSFS2020Ctrls
{
public partial class FrmMain : Form
{
/// <summary>
/// Checks if a rectangle is visible on any screen
/// </summary>
/// <param name="formRect"></param>
/// <returns>True if visible</returns>
private static bool IsOnScreen( Rectangle formRect )
{
Screen[] screens = Screen.AllScreens;
foreach ( Screen screen in screens ) {
if ( screen.WorkingArea.Contains( formRect ) ) {
return true;
}
}
return false;
}
public FrmMain( )
{
InitializeComponent( );
var lang = LangPak.GetLanguagePacks();
foreach ( var l in lang ) {
cbxLang.Items.Add( l );
}
if ( cbxLang.Items.Count > 0 )
cbxLang.SelectedIndex = 0;
foreach(var item in cbxLang.Items ) {
if (item.ToString()== AppSettings.Instance.MyLanguageChoice ) {
cbxLang.SelectedItem = item;
}
}
btShowForm.Enabled = false;
btPrint.Enabled = false;
// some applic initialization
// Assign Size property - check if on screen, else use defaults
if ( IsOnScreen( new Rectangle( AppSettings.Instance.FormLocation, AppSettings.Instance.FormSize ) ) ) {
// this.Size = AppSettings.Instance.FormSize;
this.Location = AppSettings.Instance.FormLocation;
}
string version = Application.ProductVersion; // get the version information
// BETA VERSION; TODO - comment out if not longer
//lblTitle.Text += " - V " + version.Substring( 0, version.IndexOf( ".", version.IndexOf( "." ) + 1 ) ); // PRODUCTION
this.Text += " - V " + version + " beta"; // BETA
// set the one from the kbd driver if found
bool exists = Support.KbdLayout.Instance.KbdLayoutExists(Support.InputTransform.KbdLayoutID);
Support.KbdLayout.Instance.SetKbdLayout( Support.InputTransform.KbdLayoutID ); // gets the default one if not found
if ( exists )
lblLang.Text = Support.InputTransform.LocaleString;
else
lblLang.Text = "("+Support.InputTransform.LocaleString+")";
btLoad.Focus( );
}
private void FmrMain_FormClosing( object sender, FormClosingEventArgs e )
{
// don't record minimized, maximized forms
if ( this.WindowState == FormWindowState.Normal ) {
AppSettings.Instance.FormSize = this.Size;
AppSettings.Instance.FormLocation = this.Location;
}
AppSettings.Instance.MyLanguageChoice = cbxLang.SelectedItem.ToString();
AppSettings.Instance.Save( );
}
private List<DeviceEntry>m_devices = new List<DeviceEntry>();
private void btLoad_Click( object sender, EventArgs e )
{
DeviceEntry.DeviceReset( ); // reset Joystick enumeration
clbDevices.Items.Clear( );
// load all..
var x = MsFiles.GetControlProfiles();
m_devices = new List<DeviceEntry>( );
RTB.Text = $"Collected MSFS2020 Game Control Data:\n";
foreach ( var f in x ) {
var dev = Controller.FromXmlFile( f );
m_devices.Add( dev );
clbDevices.Items.Add( dev );
RTB.Text += $"\n{dev.DeviceProfileName} - \n";
RTB.Text += $" {dev.DeviceName}\n";
RTB.Text += $" {dev.NumberOfActionMaps} Map(s); {dev.NumberOfActions} Actions\n";
}
RTB.Text += $"--- \n";
RTB.Text += $"{m_devices.Count} Device Configuration Files\n";
int sum = m_devices.Sum(d=> d.NumberOfActions);
RTB.Text += $"{sum} Action Entries\n";
btShowForm.Enabled = true;
btPrint.Enabled = true;
}
private void btShowForm_Click( object sender, EventArgs e )
{
string fName = (cbxLang.SelectedItem as LangPak.LangPakEntry).LangFile;
MSFS.LangPak.Instance.LoadLanguage( fName );
ActionItemList alist = new ActionItemList();
foreach ( var dev in clbDevices.CheckedItems ) {
var cDev = dev as DeviceEntry;
cDev.GetForLayout( alist );
}
if ( alist.Count < 1 ) return;
var LAYOUT = new FormLayout { ActionList = alist };
LAYOUT.ShowDialog( this );
LAYOUT = null; // get rid and create a new one next time..
}
private void btPrint_Click( object sender, EventArgs e )
{
string fName = (cbxLang.SelectedItem as LangPak.LangPakEntry).LangFile;
MSFS.LangPak.Instance.LoadLanguage( fName );
var rtf = new Support.RTFformatter();
rtf.SetTab( 200 ); rtf.SetTab( 6000 ); rtf.SetTab( 8000 ); rtf.SetTab( 10000 );
//rtf.WriteTab( "1" ); rtf.WriteTab( "2" ); rtf.WriteTab( "3" ); rtf.WriteTab( "4" ); rtf.WriteLn( ); // TAB preview
foreach ( var dev in clbDevices.CheckedItems ) {
var cDev = dev as DeviceEntry;
cDev.AsRTF( rtf );
}
var PRINT = new FrmPrint{ RTF= rtf.RTFtext };
PRINT.ShowDialog( this );
PRINT = null;
}
private void button1_Click( object sender, EventArgs e )
{
Support.KeyboardCls.MyLayoutName( );
}
private void button1_Click_1( object sender, EventArgs e )
{
var kle = new Support.KLE_File();
var x = new Support.KbdLayoutFile();
x.MapKLIDs = new List<string>( ) { "00000411" };
x.MapDescription = "Keyboard Layout for ja";
x.MapComment = "Japanese Layout";
x.MapKeys= kle.GetKeyLabels( "KBDJPN.json" );
x.ToJson( "ja.json" );
}
}
}