2013-10-01 13:02:19 +00:00
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Data ;
using System.Drawing ;
2013-10-02 15:09:49 +00:00
using System.IO ;
2013-10-01 13:02:19 +00:00
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using System.Windows.Forms ;
2013-10-20 00:00:59 +00:00
using BizHawk.Client.Core ;
2013-10-05 00:38:46 +00:00
using BizHawk.Emulation.Consoles.Nintendo.SNES ;
using BizHawk.Emulation.Consoles.Nintendo ;
using BizHawk.Emulation.Consoles.Sega ;
2013-10-02 15:09:49 +00:00
namespace BizHawk.MultiClient
2013-10-01 13:02:19 +00:00
{
2013-10-06 20:02:34 +00:00
public partial class Cheats : Form
2013-10-01 13:02:19 +00:00
{
2013-10-04 16:06:08 +00:00
public const string NAME = "NamesColumn" ;
public const string ADDRESS = "AddressColumn" ;
public const string VALUE = "ValueColumn" ;
public const string COMPARE = "CompareColumn" ;
public const string ON = "OnColumn" ;
public const string DOMAIN = "DomainColumn" ;
2013-10-05 03:40:36 +00:00
public const string SIZE = "SizeColumn" ;
public const string ENDIAN = "EndianColumn" ;
public const string TYPE = "DisplayTypeColumn" ;
2013-10-04 16:06:08 +00:00
private readonly Dictionary < string , int > DefaultColumnWidths = new Dictionary < string , int >
{
{ NAME , 128 } ,
{ ADDRESS , 60 } ,
{ VALUE , 59 } ,
{ COMPARE , 59 } ,
2013-10-04 22:21:09 +00:00
{ ON , 28 } ,
2013-10-04 16:06:08 +00:00
{ DOMAIN , 55 } ,
2013-10-05 03:40:36 +00:00
{ SIZE , 55 } ,
{ ENDIAN , 55 } ,
{ TYPE , 55 } ,
2013-10-04 16:06:08 +00:00
} ;
private int defaultWidth ;
private int defaultHeight ;
private string _sortedColumn = "" ;
private bool _sortReverse = false ;
2013-10-06 20:02:34 +00:00
public Cheats ( )
2013-10-01 13:02:19 +00:00
{
InitializeComponent ( ) ;
2013-10-04 01:35:58 +00:00
Closing + = ( o , e ) = > SaveConfigSettings ( ) ;
CheatListView . QueryItemText + = CheatListView_QueryItemText ;
CheatListView . QueryItemBkColor + = CheatListView_QueryItemBkColor ;
CheatListView . VirtualMode = true ;
2013-10-04 16:06:08 +00:00
_sortedColumn = "" ;
_sortReverse = false ;
TopMost = Global . Config . CheatsAlwaysOnTop ;
2013-10-01 13:02:19 +00:00
}
2013-10-06 16:40:51 +00:00
public void UpdateValues ( )
{
if ( ! IsHandleCreated | | IsDisposed )
{
return ;
}
else
{
UpdateListView ( ) ;
}
}
public void Restart ( )
{
if ( ! IsHandleCreated | | IsDisposed )
{
return ;
}
else
{
NewList ( ) ;
ToggleGameGenieButton ( ) ;
}
}
2013-10-02 15:09:49 +00:00
private void UpdateListView ( )
{
2013-10-20 00:00:59 +00:00
CheatListView . ItemCount = GlobalWinF . CheatList . Count ;
TotalLabel . Text = GlobalWinF . CheatList . CheatCount . ToString ( )
+ ( GlobalWinF . CheatList . CheatCount = = 1 ? " cheat " : " cheats " )
+ GlobalWinF . CheatList . ActiveCount . ToString ( ) + " active" ;
2013-10-02 15:09:49 +00:00
}
public void LoadFileFromRecent ( string path )
{
bool ask_result = true ;
2013-10-20 00:00:59 +00:00
if ( GlobalWinF . CheatList . Changes )
2013-10-02 15:09:49 +00:00
{
ask_result = AskSave ( ) ;
}
if ( ask_result )
{
2013-10-20 00:00:59 +00:00
bool load_result = GlobalWinF . CheatList . Load ( path , append : false ) ;
2013-10-02 15:09:49 +00:00
if ( ! load_result )
{
2013-10-17 00:21:45 +00:00
ToolHelpers . HandleLoadError ( Global . Config . RecentWatches , path ) ;
2013-10-02 15:09:49 +00:00
}
else
{
Global . Config . RecentWatches . Add ( path ) ;
UpdateListView ( ) ;
2013-10-04 23:50:26 +00:00
UpdateMessageLabel ( ) ;
2013-10-02 15:09:49 +00:00
}
}
}
2013-10-04 23:50:26 +00:00
private void UpdateMessageLabel ( bool saved = false )
2013-10-04 22:21:09 +00:00
{
2013-10-04 23:50:26 +00:00
string message = String . Empty ;
2013-10-05 01:30:59 +00:00
if ( saved )
2013-10-04 22:21:09 +00:00
{
2013-10-20 00:00:59 +00:00
message = Path . GetFileName ( GlobalWinF . CheatList . CurrentFileName ) + " saved." ;
2013-10-05 01:30:59 +00:00
}
else
{
2013-10-20 00:00:59 +00:00
message = Path . GetFileName ( GlobalWinF . CheatList . CurrentFileName ) + ( GlobalWinF . CheatList . Changes ? " *" : String . Empty ) ;
2013-10-04 22:21:09 +00:00
}
2013-10-04 23:50:26 +00:00
MessageLabel . Text = message ;
2013-10-04 22:21:09 +00:00
}
2013-10-02 15:09:49 +00:00
public bool AskSave ( )
{
if ( Global . Config . SupressAskSave ) //User has elected to not be nagged
{
return true ;
}
2013-10-20 00:00:59 +00:00
if ( GlobalWinF . CheatList . Changes )
2013-10-02 15:09:49 +00:00
{
2013-10-20 00:00:59 +00:00
GlobalWinF . Sound . StopSound ( ) ;
2013-10-02 15:09:49 +00:00
DialogResult result = MessageBox . Show ( "Save Changes?" , "Cheats" , MessageBoxButtons . YesNoCancel , MessageBoxIcon . Question , MessageBoxDefaultButton . Button3 ) ;
2013-10-20 00:00:59 +00:00
GlobalWinF . Sound . StartSound ( ) ;
2013-10-02 15:09:49 +00:00
if ( result = = DialogResult . Yes )
{
2013-10-20 00:00:59 +00:00
GlobalWinF . CheatList . Save ( ) ;
2013-10-02 15:09:49 +00:00
}
else if ( result = = DialogResult . No )
{
return true ;
}
else if ( result = = DialogResult . Cancel )
{
return false ;
}
}
return true ;
}
2013-10-03 15:27:51 +00:00
private void LoadFile ( FileInfo file , bool append )
{
if ( file ! = null )
{
bool result = true ;
2013-10-20 00:00:59 +00:00
if ( GlobalWinF . CheatList . Changes )
2013-10-03 15:27:51 +00:00
{
result = AskSave ( ) ;
}
if ( result )
{
2013-10-20 00:00:59 +00:00
GlobalWinF . CheatList . Load ( file . FullName , append ) ;
2013-10-03 15:27:51 +00:00
UpdateListView ( ) ;
2013-10-05 01:30:59 +00:00
UpdateMessageLabel ( ) ;
2013-10-20 00:00:59 +00:00
Global . Config . RecentCheats . Add ( GlobalWinF . CheatList . CurrentFileName ) ;
2013-10-03 15:27:51 +00:00
}
}
}
2013-10-01 13:02:19 +00:00
private void NewCheatForm_Load ( object sender , EventArgs e )
{
2013-10-04 16:06:08 +00:00
LoadConfigSettings ( ) ;
2013-10-06 16:40:51 +00:00
ToggleGameGenieButton ( ) ;
2013-10-05 20:22:55 +00:00
CheatEditor . SetAddEvent ( AddCheat ) ;
CheatEditor . SetEditEvent ( EditCheat ) ;
2013-10-06 18:44:51 +00:00
UpdateValues ( ) ;
2013-10-05 20:22:55 +00:00
}
2013-10-06 16:40:51 +00:00
protected override void OnClosing ( CancelEventArgs e )
{
if ( ! Global . Config . CheatsAutoSaveOnClose )
{
if ( ! AskSave ( ) )
e . Cancel = true ;
}
base . OnClosing ( e ) ;
}
private void ToggleGameGenieButton ( )
{
GameGenieToolbarSeparator . Visible =
LoadGameGenieToolbarItem . Visible =
2013-10-20 00:00:59 +00:00
( ( GlobalWinF . Emulator is NES )
| | ( GlobalWinF . Emulator is Genesis )
| | ( GlobalWinF . Emulator . SystemId = = "GB" )
2013-10-06 16:40:51 +00:00
| | ( Global . Game . System = = "GG" )
2013-10-20 00:00:59 +00:00
| | ( GlobalWinF . Emulator is LibsnesCore ) ) ;
2013-10-06 16:40:51 +00:00
}
2013-10-05 20:22:55 +00:00
private void AddCheat ( )
{
2013-10-20 00:00:59 +00:00
GlobalWinF . CheatList . Add ( CheatEditor . Cheat ) ;
2013-10-05 20:22:55 +00:00
UpdateListView ( ) ;
UpdateMessageLabel ( ) ;
}
private void EditCheat ( )
{
MessageBox . Show ( "Edit clicked" ) ;
2013-10-02 15:09:49 +00:00
}
2013-10-04 01:35:58 +00:00
public void SaveConfigSettings ( )
{
2013-10-05 20:22:55 +00:00
SaveColumnInfo ( ) ;
Global . Config . CheatsWndx = Location . X ;
Global . Config . CheatsWndy = Location . Y ;
Global . Config . CheatsWidth = Right - Left ;
Global . Config . CheatsHeight = Bottom - Top ;
2013-10-04 01:35:58 +00:00
}
2013-10-04 16:06:08 +00:00
private void LoadConfigSettings ( )
{
//Size and Positioning
defaultWidth = Size . Width ; //Save these first so that the user can restore to its original size
defaultHeight = Size . Height ;
if ( Global . Config . CheatsSaveWindowPosition & & Global . Config . CheatsWndx > = 0 & & Global . Config . CheatsWndy > = 0 )
{
Location = new Point ( Global . Config . CheatsWndx , Global . Config . CheatsWndy ) ;
}
if ( Global . Config . CheatsWidth > = 0 & & Global . Config . CheatsHeight > = 0 )
{
Size = new Size ( Global . Config . CheatsWidth , Global . Config . CheatsHeight ) ;
}
LoadColumnInfo ( ) ;
}
private void LoadColumnInfo ( )
{
CheatListView . Columns . Clear ( ) ;
2013-10-05 03:40:36 +00:00
ToolHelpers . AddColumn ( CheatListView , NAME , Global . Config . CheatsColumnShow [ NAME ] , GetColumnWidth ( NAME ) ) ;
ToolHelpers . AddColumn ( CheatListView , ADDRESS , Global . Config . CheatsColumnShow [ ADDRESS ] , GetColumnWidth ( ADDRESS ) ) ;
ToolHelpers . AddColumn ( CheatListView , VALUE , Global . Config . CheatsColumnShow [ VALUE ] , GetColumnWidth ( VALUE ) ) ;
ToolHelpers . AddColumn ( CheatListView , COMPARE , Global . Config . CheatsColumnShow [ COMPARE ] , GetColumnWidth ( COMPARE ) ) ;
ToolHelpers . AddColumn ( CheatListView , ON , Global . Config . CheatsColumnShow [ ON ] , GetColumnWidth ( ON ) ) ;
ToolHelpers . AddColumn ( CheatListView , DOMAIN , Global . Config . CheatsColumnShow [ DOMAIN ] , GetColumnWidth ( DOMAIN ) ) ;
ToolHelpers . AddColumn ( CheatListView , SIZE , Global . Config . CheatsColumnShow [ SIZE ] , GetColumnWidth ( SIZE ) ) ;
ToolHelpers . AddColumn ( CheatListView , ENDIAN , Global . Config . CheatsColumnShow [ ENDIAN ] , GetColumnWidth ( ENDIAN ) ) ;
ToolHelpers . AddColumn ( CheatListView , TYPE , Global . Config . CheatsColumnShow [ TYPE ] , GetColumnWidth ( TYPE ) ) ;
2013-10-04 16:06:08 +00:00
}
private int GetColumnWidth ( string columnName )
{
var width = Global . Config . CheatsColumnWidths [ columnName ] ;
if ( width = = - 1 )
{
width = DefaultColumnWidths [ columnName ] ;
}
return width ;
}
2013-10-04 01:35:58 +00:00
private void CheatListView_QueryItemText ( int index , int column , out string text )
{
text = "" ;
2013-10-20 00:00:59 +00:00
if ( index > = GlobalWinF . CheatList . Count | | GlobalWinF . CheatList [ index ] . IsSeparator )
2013-10-04 01:35:58 +00:00
{
return ;
}
2013-10-04 16:06:08 +00:00
string columnName = CheatListView . Columns [ column ] . Name ;
switch ( columnName )
{
case NAME :
2013-10-20 00:00:59 +00:00
text = GlobalWinF . CheatList [ index ] . Name ;
2013-10-04 16:06:08 +00:00
break ;
case ADDRESS :
2013-10-20 00:00:59 +00:00
text = GlobalWinF . CheatList [ index ] . AddressStr ;
2013-10-04 16:06:08 +00:00
break ;
case VALUE :
2013-10-20 00:00:59 +00:00
text = GlobalWinF . CheatList [ index ] . ValueStr ;
2013-10-04 16:06:08 +00:00
break ;
case COMPARE :
2013-10-20 00:00:59 +00:00
text = GlobalWinF . CheatList [ index ] . CompareStr ;
2013-10-04 16:06:08 +00:00
break ;
case ON :
2013-10-20 00:00:59 +00:00
text = GlobalWinF . CheatList [ index ] . Enabled ? "*" : "" ;
2013-10-04 16:06:08 +00:00
break ;
case DOMAIN :
2013-10-20 00:00:59 +00:00
text = GlobalWinF . CheatList [ index ] . Domain . Name ;
2013-10-04 16:06:08 +00:00
break ;
2013-10-05 03:40:36 +00:00
case SIZE :
2013-10-20 00:00:59 +00:00
text = GlobalWinF . CheatList [ index ] . Size . ToString ( ) ;
2013-10-05 03:40:36 +00:00
break ;
case ENDIAN :
2013-10-20 00:00:59 +00:00
text = GlobalWinF . CheatList [ index ] . BigEndian . Value ? "Big" : "Little" ;
2013-10-05 03:40:36 +00:00
break ;
case TYPE :
2013-10-20 00:00:59 +00:00
text = Watch . DisplayTypeToString ( GlobalWinF . CheatList [ index ] . Type ) ;
2013-10-05 03:40:36 +00:00
break ;
2013-10-04 16:06:08 +00:00
}
2013-10-04 01:35:58 +00:00
}
private void CheatListView_QueryItemBkColor ( int index , int column , ref Color color )
{
2013-10-20 00:00:59 +00:00
if ( index < GlobalWinF . CheatList . Count )
2013-10-04 01:35:58 +00:00
{
2013-10-20 00:00:59 +00:00
if ( GlobalWinF . CheatList [ index ] . IsSeparator )
2013-10-04 01:35:58 +00:00
{
2013-10-04 16:06:08 +00:00
color = BackColor ;
2013-10-04 01:35:58 +00:00
}
2013-10-20 00:00:59 +00:00
else if ( GlobalWinF . CheatList [ index ] . Enabled )
2013-10-04 01:35:58 +00:00
{
color = Color . LightCyan ;
}
2013-10-04 16:06:08 +00:00
}
}
private List < int > SelectedIndices
{
get
{
var selected = new List < int > ( ) ;
ListView . SelectedIndexCollection indices = CheatListView . SelectedIndices ;
foreach ( int index in indices )
2013-10-04 01:35:58 +00:00
{
2013-10-04 16:06:08 +00:00
selected . Add ( index ) ;
2013-10-04 01:35:58 +00:00
}
2013-10-04 16:06:08 +00:00
return selected ;
}
}
2013-10-05 03:40:36 +00:00
2013-10-06 16:40:51 +00:00
private List < Cheat > SelectedItems
2013-10-04 16:06:08 +00:00
{
get
{
2013-10-06 16:40:51 +00:00
var selected = new List < Cheat > ( ) ;
2013-10-04 16:06:08 +00:00
if ( SelectedIndices . Any ( ) )
{
foreach ( int index in SelectedIndices )
{
2013-10-20 00:00:59 +00:00
if ( ! GlobalWinF . CheatList [ index ] . IsSeparator )
2013-10-04 16:06:08 +00:00
{
2013-10-20 00:00:59 +00:00
selected . Add ( GlobalWinF . CheatList [ index ] ) ;
2013-10-04 16:06:08 +00:00
}
}
}
return selected ;
}
}
2013-10-06 16:40:51 +00:00
private List < Cheat > SelectedCheats
2013-10-04 16:06:08 +00:00
{
get
{
return SelectedItems . Where ( x = > ! x . IsSeparator ) . ToList ( ) ;
2013-10-04 01:35:58 +00:00
}
}
2013-10-04 23:50:26 +00:00
private void MoveUp ( )
{
var indices = CheatListView . SelectedIndices ;
if ( indices . Count = = 0 | | indices [ 0 ] = = 0 )
{
return ;
}
foreach ( int index in indices )
{
2013-10-20 00:00:59 +00:00
var cheat = GlobalWinF . CheatList [ index ] ;
GlobalWinF . CheatList . Remove ( GlobalWinF . CheatList [ index ] ) ;
GlobalWinF . CheatList . Insert ( index - 1 , cheat ) ;
2013-10-04 23:50:26 +00:00
}
UpdateMessageLabel ( ) ;
var newindices = new List < int > ( ) ;
for ( int i = 0 ; i < indices . Count ; i + + )
{
newindices . Add ( indices [ i ] - 1 ) ;
}
CheatListView . SelectedIndices . Clear ( ) ;
foreach ( int newi in newindices )
{
CheatListView . SelectItem ( newi , true ) ;
}
UpdateListView ( ) ;
}
private void MoveDown ( )
{
var indices = CheatListView . SelectedIndices ;
if ( indices . Count = = 0 )
{
return ;
}
foreach ( int index in indices )
{
2013-10-20 00:00:59 +00:00
var cheat = GlobalWinF . CheatList [ index ] ;
2013-10-04 23:50:26 +00:00
2013-10-20 00:00:59 +00:00
if ( index < GlobalWinF . CheatList . Count - 1 )
2013-10-04 23:50:26 +00:00
{
2013-10-20 00:00:59 +00:00
GlobalWinF . CheatList . Remove ( GlobalWinF . CheatList [ index ] ) ;
GlobalWinF . CheatList . Insert ( index + 1 , cheat ) ;
2013-10-04 23:50:26 +00:00
}
}
UpdateMessageLabel ( ) ;
var newindices = new List < int > ( ) ;
for ( int i = 0 ; i < indices . Count ; i + + )
{
newindices . Add ( indices [ i ] + 1 ) ;
}
CheatListView . SelectedIndices . Clear ( ) ;
foreach ( int newi in newindices )
{
CheatListView . SelectItem ( newi , true ) ;
}
UpdateListView ( ) ;
}
private void Remove ( )
{
if ( SelectedIndices . Any ( ) )
{
foreach ( int index in SelectedIndices )
{
2013-10-20 00:00:59 +00:00
GlobalWinF . CheatList . Remove ( GlobalWinF . CheatList [ SelectedIndices [ 0 ] ] ) ; //SelectedIndices[0] used since each iteration will make this the correct list index
2013-10-04 23:50:26 +00:00
}
CheatListView . SelectedIndices . Clear ( ) ;
}
UpdateListView ( ) ;
}
2013-10-05 00:38:46 +00:00
private void Toggle ( )
{
SelectedCheats . ForEach ( x = > x . Toggle ( ) ) ;
2013-10-14 01:37:09 +00:00
ToolHelpers . UpdateCheatRelatedTools ( ) ;
2013-10-20 00:00:59 +00:00
GlobalWinF . CheatList . FlagChanges ( ) ;
2013-10-05 00:38:46 +00:00
}
2013-10-05 03:40:36 +00:00
private void SaveColumnInfo ( )
{
if ( CheatListView . Columns [ NAME ] ! = null )
{
Global . Config . CheatsColumnIndices [ NAME ] = CheatListView . Columns [ NAME ] . DisplayIndex ;
Global . Config . CheatsColumnWidths [ NAME ] = CheatListView . Columns [ NAME ] . Width ;
}
if ( CheatListView . Columns [ ADDRESS ] ! = null )
{
Global . Config . CheatsColumnIndices [ ADDRESS ] = CheatListView . Columns [ ADDRESS ] . DisplayIndex ;
Global . Config . CheatsColumnWidths [ ADDRESS ] = CheatListView . Columns [ ADDRESS ] . Width ;
}
if ( CheatListView . Columns [ VALUE ] ! = null )
{
Global . Config . CheatsColumnIndices [ VALUE ] = CheatListView . Columns [ VALUE ] . DisplayIndex ;
Global . Config . CheatsColumnWidths [ VALUE ] = CheatListView . Columns [ VALUE ] . Width ;
}
if ( CheatListView . Columns [ COMPARE ] ! = null )
{
Global . Config . CheatsColumnIndices [ COMPARE ] = CheatListView . Columns [ COMPARE ] . DisplayIndex ;
Global . Config . CheatsColumnWidths [ COMPARE ] = CheatListView . Columns [ COMPARE ] . Width ;
}
if ( CheatListView . Columns [ ON ] ! = null )
{
Global . Config . CheatsColumnIndices [ ON ] = CheatListView . Columns [ ON ] . DisplayIndex ;
Global . Config . CheatsColumnWidths [ ON ] = CheatListView . Columns [ ON ] . Width ;
}
if ( CheatListView . Columns [ DOMAIN ] ! = null )
{
Global . Config . CheatsColumnIndices [ DOMAIN ] = CheatListView . Columns [ DOMAIN ] . DisplayIndex ;
Global . Config . CheatsColumnWidths [ DOMAIN ] = CheatListView . Columns [ DOMAIN ] . Width ;
}
if ( CheatListView . Columns [ SIZE ] ! = null )
{
Global . Config . CheatsColumnIndices [ SIZE ] = CheatListView . Columns [ SIZE ] . DisplayIndex ;
Global . Config . CheatsColumnWidths [ SIZE ] = CheatListView . Columns [ SIZE ] . Width ;
}
if ( CheatListView . Columns [ ENDIAN ] ! = null )
{
Global . Config . CheatsColumnIndices [ ENDIAN ] = CheatListView . Columns [ ENDIAN ] . DisplayIndex ;
Global . Config . CheatsColumnWidths [ ENDIAN ] = CheatListView . Columns [ ENDIAN ] . Width ;
}
if ( CheatListView . Columns [ TYPE ] ! = null )
{
Global . Config . CheatsColumnIndices [ TYPE ] = CheatListView . Columns [ TYPE ] . DisplayIndex ;
Global . Config . CheatsColumnWidths [ TYPE ] = CheatListView . Columns [ TYPE ] . Width ;
}
}
private void DoColumnToggle ( string column )
{
Global . Config . CheatsColumnShow [ column ] ^ = true ;
SaveColumnInfo ( ) ;
LoadColumnInfo ( ) ;
}
2013-10-05 20:22:55 +00:00
private void DoSelectedIndexChange ( )
{
2013-10-05 23:16:35 +00:00
if ( SelectedCheats . Any ( ) )
2013-10-05 20:22:55 +00:00
{
2013-10-05 23:16:35 +00:00
var cheat = SelectedCheats [ 0 ] ;
CheatEditor . SetCheat ( cheat ) ;
CheatGroupBox . Text = "Editing Cheat " + cheat . Name + " - " + cheat . AddressStr ;
2013-10-05 20:22:55 +00:00
}
else
{
CheatEditor . ClearForm ( ) ;
2013-10-05 23:16:35 +00:00
CheatGroupBox . Text = "New Cheat" ;
2013-10-05 20:22:55 +00:00
}
}
2013-10-06 16:40:51 +00:00
private void NewList ( )
{
bool result = true ;
2013-10-20 00:00:59 +00:00
if ( GlobalWinF . CheatList . Changes )
2013-10-06 16:40:51 +00:00
{
result = AskSave ( ) ;
}
if ( result )
{
2013-10-20 00:00:59 +00:00
GlobalWinF . CheatList . NewList ( ) ;
2013-10-06 16:40:51 +00:00
UpdateListView ( ) ;
UpdateMessageLabel ( ) ;
}
}
2013-10-02 15:09:49 +00:00
#region Events
#region File
private void FileSubMenu_DropDownOpened ( object sender , EventArgs e )
{
2013-10-20 00:00:59 +00:00
SaveMenuItem . Enabled = GlobalWinF . CheatList . Changes ;
2013-10-02 15:09:49 +00:00
}
2013-10-05 03:40:36 +00:00
private void RecentSubMenu_DropDownOpened ( object sender , EventArgs e )
{
RecentSubMenu . DropDownItems . Clear ( ) ;
2013-10-17 00:21:45 +00:00
RecentSubMenu . DropDownItems . AddRange (
ToolHelpers . GenerateRecentMenu ( Global . Config . RecentCheats , LoadFileFromRecent )
) ;
2013-10-05 03:40:36 +00:00
}
private void NewMenuItem_Click ( object sender , EventArgs e )
{
2013-10-06 16:40:51 +00:00
NewList ( ) ;
2013-10-05 03:40:36 +00:00
}
private void OpenMenuItem_Click ( object sender , EventArgs e )
{
bool append = sender = = AppendMenuItem ;
2013-10-20 00:00:59 +00:00
LoadFile ( CheatList . GetFileFromUser ( GlobalWinF . CheatList . CurrentFileName ) , append ) ;
2013-10-05 03:40:36 +00:00
}
2013-10-05 01:30:59 +00:00
private void SaveMenuItem_Click ( object sender , EventArgs e )
{
2013-10-20 00:00:59 +00:00
if ( GlobalWinF . CheatList . Changes )
2013-10-05 01:30:59 +00:00
{
2013-10-20 00:00:59 +00:00
if ( GlobalWinF . CheatList . Save ( ) )
2013-10-05 01:30:59 +00:00
{
UpdateMessageLabel ( saved : true ) ;
}
}
else
{
SaveAsMenuItem_Click ( sender , e ) ;
}
}
private void SaveAsMenuItem_Click ( object sender , EventArgs e )
{
2013-10-20 00:00:59 +00:00
if ( GlobalWinF . CheatList . SaveAs ( ) )
2013-10-05 01:30:59 +00:00
{
UpdateMessageLabel ( saved : true ) ;
}
}
2013-10-02 15:09:49 +00:00
private void ExitMenuItem_Click ( object sender , EventArgs e )
{
Close ( ) ;
}
#endregion
#region Cheats
private void CheatsSubMenu_DropDownOpened ( object sender , EventArgs e )
{
2013-10-04 23:50:26 +00:00
RemoveCheatMenuItem . Enabled =
2013-10-05 00:38:46 +00:00
DuplicateMenuItem . Enabled =
2013-10-04 23:50:26 +00:00
MoveUpMenuItem . Enabled =
MoveDownMenuItem . Enabled =
2013-10-05 00:38:46 +00:00
ToggleMenuItem . Enabled =
2013-10-04 23:50:26 +00:00
SelectedIndices . Any ( ) ;
2013-10-01 13:02:19 +00:00
2013-10-20 00:00:59 +00:00
DisableAllCheatsMenuItem . Enabled = GlobalWinF . CheatList . ActiveCount > 0 ;
2013-10-05 00:38:46 +00:00
GameGenieSeparator . Visible =
OpenGameGenieEncoderDecoderMenuItem . Visible =
2013-10-20 00:00:59 +00:00
( ( GlobalWinF . Emulator is NES )
| | ( GlobalWinF . Emulator is Genesis )
| | ( GlobalWinF . Emulator . SystemId = = "GB" )
2013-10-05 00:38:46 +00:00
| | ( Global . Game . System = = "GG" )
2013-10-20 00:00:59 +00:00
| | ( GlobalWinF . Emulator is LibsnesCore ) ) ;
2013-10-04 23:50:26 +00:00
}
private void RemoveCheatMenuItem_Click ( object sender , EventArgs e )
{
Remove ( ) ;
2013-10-01 13:02:19 +00:00
}
2013-10-02 15:09:49 +00:00
2013-10-05 00:38:46 +00:00
private void DuplicateMenuItem_Click ( object sender , EventArgs e )
{
if ( CheatListView . SelectedIndices . Count > 0 )
{
foreach ( int index in CheatListView . SelectedIndices )
{
2013-10-20 00:00:59 +00:00
GlobalWinF . CheatList . Add ( new Cheat ( GlobalWinF . CheatList [ index ] ) ) ;
2013-10-05 00:38:46 +00:00
}
}
UpdateListView ( ) ;
UpdateMessageLabel ( ) ;
}
2013-10-04 16:06:08 +00:00
private void InsertSeparatorMenuItem_Click ( object sender , EventArgs e )
{
if ( SelectedIndices . Any ( ) )
{
2013-10-20 00:00:59 +00:00
GlobalWinF . CheatList . Insert ( SelectedIndices . Max ( ) , Cheat . Separator ) ;
2013-10-04 16:06:08 +00:00
}
else
{
2013-10-20 00:00:59 +00:00
GlobalWinF . CheatList . Add ( Cheat . Separator ) ;
2013-10-04 16:06:08 +00:00
}
2013-10-05 01:30:59 +00:00
2013-10-04 16:06:08 +00:00
UpdateListView ( ) ;
2013-10-05 01:30:59 +00:00
UpdateMessageLabel ( ) ;
2013-10-04 16:06:08 +00:00
}
2013-10-04 23:50:26 +00:00
private void MoveUpMenuItem_Click ( object sender , EventArgs e )
{
MoveUp ( ) ;
}
private void MoveDownMenuItem_Click ( object sender , EventArgs e )
{
MoveDown ( ) ;
}
private void SelectAllMenuItem_Click ( object sender , EventArgs e )
{
2013-10-20 00:00:59 +00:00
for ( int i = 0 ; i < GlobalWinF . CheatList . Count ; i + + )
2013-10-04 23:50:26 +00:00
{
CheatListView . SelectItem ( i , true ) ;
}
}
2013-10-05 00:38:46 +00:00
private void ToggleMenuItem_Click ( object sender , EventArgs e )
{
Toggle ( ) ;
}
2013-10-04 23:50:26 +00:00
private void DisableAllCheatsMenuItem_Click ( object sender , EventArgs e )
{
2013-10-20 00:00:59 +00:00
GlobalWinF . CheatList . DisableAll ( ) ;
2013-10-04 23:50:26 +00:00
}
2013-10-05 00:38:46 +00:00
private void OpenGameGenieEncoderDecoderMenuItem_Click ( object sender , EventArgs e )
{
2013-10-20 00:00:59 +00:00
GlobalWinF . MainForm . LoadGameGenieEC ( ) ;
2013-10-05 00:38:46 +00:00
}
2013-10-02 15:09:49 +00:00
#endregion
#region Options
private void OptionsSubMenu_DropDownOpened ( object sender , EventArgs e )
{
2013-10-05 23:16:35 +00:00
AlwaysLoadCheatsMenuItem . Checked = Global . Config . LoadCheatFileByGame ;
AutoSaveCheatsMenuItem . Checked = Global . Config . CheatsAutoSaveOnClose ;
2013-10-05 03:40:36 +00:00
DisableCheatsOnLoadMenuItem . Checked = Global . Config . DisableCheatsOnLoad ;
AutoloadMenuItem . Checked = Global . Config . RecentCheats . AutoLoad ;
2013-10-04 16:06:08 +00:00
SaveWindowPositionMenuItem . Checked = Global . Config . CheatsSaveWindowPosition ;
2013-10-05 03:40:36 +00:00
AlwaysOnTopMenuItem . Checked = Global . Config . CheatsAlwaysOnTop ;
}
2013-10-05 23:16:35 +00:00
private void AlwaysLoadCheatsMenuItem_Click ( object sender , EventArgs e )
{
Global . Config . LoadCheatFileByGame ^ = true ;
}
private void AutoSaveCheatsMenuItem_Click ( object sender , EventArgs e )
{
Global . Config . CheatsAutoSaveOnClose ^ = true ;
}
2013-10-05 03:40:36 +00:00
private void CheatsOnOffLoadMenuItem_Click ( object sender , EventArgs e )
{
Global . Config . DisableCheatsOnLoad ^ = true ;
}
private void AutoloadMenuItem_Click ( object sender , EventArgs e )
{
Global . Config . RecentCheats . AutoLoad ^ = true ;
2013-10-04 16:06:08 +00:00
}
2013-10-02 15:09:49 +00:00
2013-10-04 16:06:08 +00:00
private void SaveWindowPositionMenuItem_Click ( object sender , EventArgs e )
{
Global . Config . CheatsSaveWindowPosition ^ = true ;
}
private void AlwaysOnTopMenuItem_Click ( object sender , EventArgs e )
{
Global . Config . CheatsAlwaysOnTop ^ = true ;
2013-10-02 15:09:49 +00:00
}
2013-10-05 03:40:36 +00:00
private void RestoreWindowSizeMenuItem_Click ( object sender , EventArgs e )
{
Size = new Size ( defaultWidth , defaultHeight ) ;
Global . Config . CheatsSaveWindowPosition = true ;
Global . Config . CheatsAlwaysOnTop = TopMost = false ;
Global . Config . DisableCheatsOnLoad = false ;
2013-10-06 22:16:12 +00:00
Global . Config . LoadCheatFileByGame = true ;
Global . Config . CheatsAutoSaveOnClose = true ;
2013-10-05 03:40:36 +00:00
Global . Config . CheatsColumnIndices = new Dictionary < string , int >
{
{ "NamesColumn" , 0 } ,
{ "AddressColumn" , 1 } ,
{ "ValueColumn" , 2 } ,
{ "CompareColumn" , 3 } ,
{ "OnColumn" , 4 } ,
{ "DomainColumn" , 5 } ,
{ "SizeColumn" , 6 } ,
{ "EndianColumn" , 7 } ,
{ "DisplayTypeColumn" , 8 } ,
} ;
Global . Config . CheatsColumnIndices = new Dictionary < string , int >
{
{ "NamesColumn" , 0 } ,
{ "AddressColumn" , 1 } ,
{ "ValueColumn" , 2 } ,
{ "CompareColumn" , 3 } ,
{ "OnColumn" , 4 } ,
{ "DomainColumn" , 5 } ,
{ "SizeColumn" , 6 } ,
{ "EndianColumn" , 7 } ,
{ "DisplayTypeColumn" , 8 } ,
} ;
Global . Config . CheatsColumnShow = new Dictionary < string , bool > ( )
{
{ "NamesColumn" , true } ,
{ "AddressColumn" , true } ,
{ "ValueColumn" , true } ,
{ "CompareColumn" , true } ,
2013-10-05 23:16:35 +00:00
{ "OnColumn" , false } ,
2013-10-05 03:40:36 +00:00
{ "DomainColumn" , true } ,
{ "SizeColumn" , true } ,
{ "EndianColumn" , false } ,
{ "DisplayTypeColumn" , false } ,
} ;
LoadColumnInfo ( ) ;
}
2013-10-02 15:09:49 +00:00
#endregion
#region Columns
private void ColumnsSubMenu_DropDownOpened ( object sender , EventArgs e )
{
2013-10-05 03:40:36 +00:00
ShowNameMenuItem . Checked = Global . Config . CheatsColumnShow [ NAME ] ;
ShowAddressMenuItem . Checked = Global . Config . CheatsColumnShow [ ADDRESS ] ;
ShowValueMenuItem . Checked = Global . Config . CheatsColumnShow [ VALUE ] ;
ShowCompareMenuItem . Checked = Global . Config . CheatsColumnShow [ COMPARE ] ;
ShowOnMenuItem . Checked = Global . Config . CheatsColumnShow [ ON ] ;
ShowDomainMenuItem . Checked = Global . Config . CheatsColumnShow [ DOMAIN ] ;
ShowSizeMenuItem . Checked = Global . Config . CheatsColumnShow [ SIZE ] ;
ShowEndianMenuItem . Checked = Global . Config . CheatsColumnShow [ ENDIAN ] ;
ShowDisplayTypeMenuItem . Checked = Global . Config . CheatsColumnShow [ TYPE ] ;
}
private void ShowNameMenuItem_Click ( object sender , EventArgs e )
{
DoColumnToggle ( NAME ) ;
}
private void ShowAddressMenuItem_Click ( object sender , EventArgs e )
{
DoColumnToggle ( ADDRESS ) ;
}
private void ShowValueMenuItem_Click ( object sender , EventArgs e )
{
DoColumnToggle ( VALUE ) ;
}
private void ShowCompareMenuItem_Click ( object sender , EventArgs e )
{
DoColumnToggle ( COMPARE ) ;
}
2013-10-02 15:09:49 +00:00
2013-10-05 03:40:36 +00:00
private void ShowOnMenuItem_Click ( object sender , EventArgs e )
{
DoColumnToggle ( ON ) ;
}
private void ShowDomainMenuItem_Click ( object sender , EventArgs e )
{
DoColumnToggle ( DOMAIN ) ;
}
private void ShowSizeMenuItem_Click ( object sender , EventArgs e )
{
DoColumnToggle ( SIZE ) ;
}
private void ShowEndianMenuItem_Click ( object sender , EventArgs e )
{
DoColumnToggle ( ENDIAN ) ;
}
private void ShowDisplayTypeMenuItem_Click ( object sender , EventArgs e )
{
DoColumnToggle ( TYPE ) ;
2013-10-02 15:09:49 +00:00
}
#endregion
2013-10-05 21:37:01 +00:00
#region ListView and Dialog Events
2013-10-05 20:22:55 +00:00
private void CheatListView_Click ( object sender , EventArgs e )
{
DoSelectedIndexChange ( ) ;
}
private void CheatListView_ColumnReordered ( object sender , ColumnReorderedEventArgs e )
{
Global . Config . CheatsColumnIndices [ NAME ] = CheatListView . Columns [ NAME ] . DisplayIndex ;
Global . Config . CheatsColumnIndices [ ADDRESS ] = CheatListView . Columns [ ADDRESS ] . DisplayIndex ;
Global . Config . CheatsColumnIndices [ VALUE ] = CheatListView . Columns [ VALUE ] . DisplayIndex ;
Global . Config . CheatsColumnIndices [ COMPARE ] = CheatListView . Columns [ COMPARE ] . DisplayIndex ;
Global . Config . CheatsColumnIndices [ ON ] = CheatListView . Columns [ ON ] . DisplayIndex ;
Global . Config . CheatsColumnIndices [ DOMAIN ] = CheatListView . Columns [ DOMAIN ] . DisplayIndex ;
Global . Config . CheatsColumnIndices [ SIZE ] = CheatListView . Columns [ SIZE ] . DisplayIndex ;
Global . Config . CheatsColumnIndices [ ENDIAN ] = CheatListView . Columns [ ENDIAN ] . DisplayIndex ;
Global . Config . CheatsColumnIndices [ TYPE ] = CheatListView . Columns [ TYPE ] . DisplayIndex ;
}
private void CheatListView_DoubleClick ( object sender , EventArgs e )
{
Toggle ( ) ;
}
private void CheatListView_KeyDown ( object sender , KeyEventArgs e )
{
if ( e . KeyCode = = Keys . Delete & & ! e . Control & & ! e . Alt & & ! e . Shift )
{
Remove ( ) ;
}
else if ( e . KeyCode = = Keys . A & & e . Control & & ! e . Alt & & ! e . Shift ) //Select All
{
SelectAllMenuItem_Click ( null , null ) ;
}
}
private void CheatListView_SelectedIndexChanged ( object sender , EventArgs e )
{
DoSelectedIndexChange ( ) ;
}
2013-10-05 21:37:01 +00:00
private void CheatListView_ColumnClick ( object sender , ColumnClickEventArgs e )
{
var column = CheatListView . Columns [ e . Column ] ;
if ( column . Name ! = _sortedColumn )
{
_sortReverse = false ;
}
2013-10-20 00:00:59 +00:00
GlobalWinF . CheatList . Sort ( column . Name , _sortReverse ) ;
2013-10-05 21:37:01 +00:00
_sortedColumn = column . Name ;
_sortReverse ^ = true ;
UpdateListView ( ) ;
}
2013-10-05 20:22:55 +00:00
private void NewCheatForm_DragDrop ( object sender , DragEventArgs e )
{
string [ ] filePaths = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
if ( Path . GetExtension ( filePaths [ 0 ] ) = = ( ".cht" ) )
{
LoadFile ( new FileInfo ( filePaths [ 0 ] ) , append : false ) ;
UpdateListView ( ) ;
UpdateMessageLabel ( ) ;
}
}
private void NewCheatForm_DragEnter ( object sender , DragEventArgs e )
{
e . Effect = e . Data . GetDataPresent ( DataFormats . FileDrop ) ? DragDropEffects . Copy : DragDropEffects . None ;
}
2013-10-14 01:37:09 +00:00
private void contextMenuStrip1_Opening ( object sender , CancelEventArgs e )
{
ToggleContextMenuItem . Enabled =
RemoveContextMenuItem . Enabled =
SelectedCheats . Any ( ) ;
2013-10-20 00:00:59 +00:00
DisableAllContextMenuItem . Enabled = GlobalWinF . CheatList . ActiveCount > 0 ;
2013-10-14 01:37:09 +00:00
}
2013-10-05 20:22:55 +00:00
#endregion
2013-10-02 15:09:49 +00:00
#endregion
2013-10-01 13:02:19 +00:00
}
}