2014-07-06 00:14:57 +00:00
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Data ;
using System.Drawing ;
using System.Linq ;
using System.Text ;
using System.Windows.Forms ;
namespace SCJMapper_V2
{
partial class FormSettings : Form
{
private readonly AppSettings m_owner = null ; // owner class - access to settings
2014-08-02 22:10:55 +00:00
public Boolean Canceled { get ; set ; }
2015-12-26 22:16:25 +00:00
public String PasteString { get ; set ; } // used to copy, paste JS commands
2014-07-06 00:14:57 +00:00
/// <summary>
/// ctor - gets the owning class instance
/// </summary>
/// <param name="owner"></param>
public FormSettings ( AppSettings owner )
{
InitializeComponent ( ) ;
m_owner = owner ;
}
private void FormSettings_Load ( object sender , EventArgs e )
{
2014-08-02 20:28:13 +00:00
chkLbActionMaps . Items . Clear ( ) ;
for ( int i = 0 ; i < ActionMapsCls . ActionMaps . Length ; i + + ) {
chkLbActionMaps . Items . Add ( ActionMapsCls . ActionMaps [ i ] ) ;
}
2014-07-06 00:14:57 +00:00
LoadSettings ( ) ;
}
2015-12-26 22:16:25 +00:00
// Save from app settings into actuals
2014-07-06 00:14:57 +00:00
private void LoadSettings ( )
{
// SC path
2014-08-31 13:05:56 +00:00
txSCPath . Text = m_owner . UserSCPath ;
cbxUsePath . Checked = m_owner . UserSCPathUsed ;
2014-07-06 00:14:57 +00:00
//Ignore Buttons
txJS1 . Text = m_owner . IgnoreJS1 ;
txJS2 . Text = m_owner . IgnoreJS2 ;
txJS3 . Text = m_owner . IgnoreJS3 ;
txJS4 . Text = m_owner . IgnoreJS4 ;
txJS5 . Text = m_owner . IgnoreJS5 ;
txJS6 . Text = m_owner . IgnoreJS6 ;
txJS7 . Text = m_owner . IgnoreJS7 ;
txJS8 . Text = m_owner . IgnoreJS8 ;
2016-03-06 16:22:16 +00:00
txJS9 . Text = m_owner . IgnoreJS9 ;
txJS10 . Text = m_owner . IgnoreJS10 ;
txJS11 . Text = m_owner . IgnoreJS11 ;
txJS12 . Text = m_owner . IgnoreJS12 ;
2014-08-02 20:28:13 +00:00
// Ignore actionmaps
for ( int i = 0 ; i < chkLbActionMaps . Items . Count ; i + + ) {
if ( m_owner . IgnoreActionmaps . Contains ( "," + chkLbActionMaps . Items [ i ] . ToString ( ) + "," ) ) {
2015-12-26 22:16:25 +00:00
chkLbActionMaps . SetItemChecked ( i , true ) ;
2016-12-23 15:13:09 +00:00
} else {
chkLbActionMaps . SetItemChecked ( i , false ) ; // 20161223: fix checked items and Canceled
2014-08-02 20:28:13 +00:00
}
}
2014-09-19 23:07:53 +00:00
2014-11-16 23:36:17 +00:00
// DetectGamepad
cbxDetectGamepad . Checked = m_owner . DetectGamepad ;
2015-12-26 22:16:25 +00:00
// Use PTU
cbxPTU . Checked = m_owner . UsePTU ;
2016-07-01 15:57:58 +00:00
// Use CSV Listing
cbxCSVListing . Checked = m_owner . UseCSVListing ;
cbxListModifiers . Checked = m_owner . ListModifiers ;
2014-07-06 00:14:57 +00:00
}
2015-12-26 22:16:25 +00:00
// Save the current settings
2014-07-06 00:14:57 +00:00
private void SaveSettings ( )
{
// SC path
2014-08-31 13:05:56 +00:00
m_owner . UserSCPath = txSCPath . Text ;
m_owner . UserSCPathUsed = cbxUsePath . Checked ;
2014-07-06 00:14:57 +00:00
//Ignore Buttons
m_owner . IgnoreJS1 = txJS1 . Text ;
m_owner . IgnoreJS2 = txJS2 . Text ;
m_owner . IgnoreJS3 = txJS3 . Text ;
m_owner . IgnoreJS4 = txJS4 . Text ;
m_owner . IgnoreJS5 = txJS5 . Text ;
m_owner . IgnoreJS6 = txJS6 . Text ;
m_owner . IgnoreJS7 = txJS7 . Text ;
m_owner . IgnoreJS8 = txJS8 . Text ;
2016-03-06 16:22:16 +00:00
m_owner . IgnoreJS9 = txJS9 . Text ;
m_owner . IgnoreJS10 = txJS10 . Text ;
m_owner . IgnoreJS11 = txJS11 . Text ;
m_owner . IgnoreJS12 = txJS12 . Text ;
2014-07-06 00:14:57 +00:00
2014-08-02 20:28:13 +00:00
// Ignore actionmaps
String ignore = "," ;
for ( int i = 0 ; i < chkLbActionMaps . Items . Count ; i + + ) {
2016-12-23 15:13:09 +00:00
if ( chkLbActionMaps . GetItemCheckState ( i ) = = CheckState . Checked ) {
2014-08-02 20:28:13 +00:00
ignore + = chkLbActionMaps . Items [ i ] . ToString ( ) + "," ;
}
}
m_owner . IgnoreActionmaps = ignore ;
2014-09-19 23:07:53 +00:00
2014-11-16 23:36:17 +00:00
// DetectGamepad
if ( m_owner . DetectGamepad ! = cbxDetectGamepad . Checked ) {
MessageBox . Show ( "Changing the Gamepad option needs a restart of the application !!" , "Settings Notification" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
}
m_owner . DetectGamepad = cbxDetectGamepad . Checked ;
2015-12-26 22:16:25 +00:00
// Use PTU
if ( m_owner . UsePTU ! = cbxPTU . Checked ) {
MessageBox . Show ( "Changing to / from PTU folders needs a restart of the application !!" , "Settings Notification" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
}
m_owner . UsePTU = cbxPTU . Checked ;
2016-07-01 15:57:58 +00:00
// Use CSV Listing
m_owner . UseCSVListing = cbxCSVListing . Checked ;
m_owner . ListModifiers = cbxListModifiers . Checked ;
2014-07-06 00:14:57 +00:00
m_owner . Save ( ) ;
}
private void btDone_Click ( object sender , EventArgs e )
{
SaveSettings ( ) ;
2014-08-02 22:10:55 +00:00
Canceled = false ;
2014-07-06 00:14:57 +00:00
this . Hide ( ) ;
}
2014-08-02 22:10:55 +00:00
private void btCancel_Click ( object sender , EventArgs e )
{
LoadSettings ( ) ;
Canceled = true ;
this . Hide ( ) ;
}
2014-07-06 00:14:57 +00:00
// allow only numbers, blanks and del
private bool nonNumberEntered = false ;
private void txJS1_KeyDown ( object sender , KeyEventArgs e )
{
nonNumberEntered = false ;
// Determine whether the keystroke is a number from the top of the keyboard.
if ( e . KeyCode < Keys . D0 | | e . KeyCode > Keys . D9 ) {
if ( e . KeyCode < Keys . NumPad0 | | e . KeyCode > Keys . NumPad9 ) {
if ( e . KeyCode ! = Keys . Back ) {
if ( e . KeyCode ! = Keys . Space ) {
nonNumberEntered = true ;
}
}
}
}
//If shift key was pressed, it's not a number.
if ( Control . ModifierKeys = = Keys . Shift ) {
nonNumberEntered = true ;
}
}
private void txJS1_KeyPress ( object sender , KeyPressEventArgs e )
{
if ( nonNumberEntered = = true ) {
// Stop the character from being entered into the control since it is non-numerical.
e . Handled = true ;
}
}
private void FormSettings_FormClosing ( object sender , FormClosingEventArgs e )
{
SaveSettings ( ) ;
if ( e . CloseReason = = CloseReason . UserClosing ) {
e . Cancel = true ;
this . Hide ( ) ;
}
}
private void btChooseSCDir_Click ( object sender , EventArgs e )
{
if ( fbDlg . ShowDialog ( this ) = = System . Windows . Forms . DialogResult . OK ) {
txSCPath . Text = fbDlg . SelectedPath ;
}
}
2016-12-23 15:13:09 +00:00
2014-07-06 00:14:57 +00:00
}
}