2017-05-23 04:55:05 +00:00
using System ;
using System.Collections.Generic ;
using System.Drawing ;
using System.Linq ;
using System.Windows.Forms ;
using PKHeX.Core ;
using PKHeX.WinForms.Properties ;
using System.ComponentModel ;
2018-04-06 04:25:18 +00:00
using static PKHeX . Core . MessageStrings ;
2017-05-23 04:55:05 +00:00
namespace PKHeX.WinForms.Controls
{
2018-07-14 22:08:14 +00:00
public sealed partial class PKMEditor : UserControl , IMainEditor
2017-05-23 04:55:05 +00:00
{
public PKMEditor ( )
{
InitializeComponent ( ) ;
2017-06-18 01:37:19 +00:00
GB_OT . Click + = ClickGT ;
GB_nOT . Click + = ClickGT ;
GB_CurrentMoves . Click + = ClickMoves ;
GB_RelearnMoves . Click + = ClickMoves ;
2017-05-23 04:55:05 +00:00
2017-06-18 01:37:19 +00:00
TB_Nickname . Font = FontUtil . GetPKXFont ( 11 ) ;
2017-05-23 04:55:05 +00:00
TB_OT . Font = ( Font ) TB_Nickname . Font . Clone ( ) ;
TB_OTt2 . Font = ( Font ) TB_Nickname . Font . Clone ( ) ;
2018-03-11 02:03:09 +00:00
// Commonly reused Control arrays
Moves = new [ ] { CB_Move1 , CB_Move2 , CB_Move3 , CB_Move4 } ;
Relearn = new [ ] { CB_RelearnMove1 , CB_RelearnMove2 , CB_RelearnMove3 , CB_RelearnMove4 } ;
PPUps = new [ ] { CB_PPu1 , CB_PPu2 , CB_PPu3 , CB_PPu4 } ;
MovePP = new [ ] { TB_PP1 , TB_PP2 , TB_PP3 , TB_PP4 } ;
2018-05-27 17:24:28 +00:00
Markings = new [ ] { PB_Mark1 , PB_Mark2 , PB_Mark3 , PB_Mark4 , PB_Mark5 , PB_Mark6 } ;
2018-03-11 02:03:09 +00:00
ValidationRequired = Moves . Concat ( Relearn ) . Concat ( new [ ]
{
CB_Species , CB_Nature , CB_HeldItem , CB_Ability , // Main Tab
CB_MetLocation , CB_EggLocation , CB_Ball , // Met Tab
} ) . ToArray ( ) ;
2017-05-23 04:55:05 +00:00
relearnPB = new [ ] { PB_WarnRelearn1 , PB_WarnRelearn2 , PB_WarnRelearn3 , PB_WarnRelearn4 } ;
movePB = new [ ] { PB_WarnMove1 , PB_WarnMove2 , PB_WarnMove3 , PB_WarnMove4 } ;
2019-02-10 01:07:44 +00:00
2019-01-05 23:40:25 +00:00
foreach ( var c in WinFormsUtil . GetAllControlsOfType < ComboBox > ( this ) )
2017-06-18 04:49:14 +00:00
c . KeyDown + = WinFormsUtil . RemoveDropCB ;
2017-12-22 06:55:33 +00:00
2019-01-03 02:49:36 +00:00
Stats . MainEditor = this ;
2017-12-22 06:55:33 +00:00
LoadShowdownSet = LoadShowdownSetDefault ;
2018-04-28 16:34:54 +00:00
TID_Trainer . UpdatedID + = Update_ID ;
2018-12-20 06:10:32 +00:00
}
public void InitializeBinding ( )
{
ComboBox [ ] cbs =
{
CB_Nature ,
CB_Country , CB_SubRegion , CB_3DSReg , CB_Language , CB_Ball , CB_HeldItem , CB_Species , DEV_Ability ,
CB_EncounterType , CB_GameOrigin , CB_Ability , CB_MetLocation , CB_EggLocation , CB_Language ,
} ;
foreach ( var cb in cbs . Concat ( Moves . Concat ( Relearn ) ) )
cb . InitializeBinding ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-11-26 23:37:44 +00:00
private void UpdateStats ( )
{
Stats . UpdateStats ( ) ;
if ( pkm is PB7 )
SizeCP . TryResetStats ( ) ;
}
2018-02-27 05:22:35 +00:00
private void LoadPartyStats ( PKM pk ) = > Stats . LoadPartyStats ( pk ) ;
2018-07-27 02:34:27 +00:00
2018-02-27 05:22:35 +00:00
private void SavePartyStats ( PKM pk )
{
Stats . SavePartyStats ( pk ) ;
pk . Stat_Level = CurrentLevel ;
}
2019-02-10 01:07:44 +00:00
public PKM CurrentPKM { get = > PreparePKM ( ) ; set = > pkm = value ; }
2017-06-19 05:27:40 +00:00
public bool ModifyPKM { private get ; set ; } = true ;
2018-08-20 01:22:07 +00:00
private bool _hideSecret ;
2018-12-20 06:10:32 +00:00
public bool HideSecretValues
{
private get = > _hideSecret ;
set
{
_hideSecret = value ;
var sav = RequestSaveFile ;
if ( sav ! = null )
ToggleSecrets ( _hideSecret , sav . Generation ) ;
}
}
2019-02-09 21:15:37 +00:00
public DrawConfig Draw { private get ; set ; }
2018-02-27 05:22:35 +00:00
public bool Unicode { get ; set ; } = true ;
2019-01-03 02:49:36 +00:00
private bool _hax ;
public bool HaX { get = > _hax ; set = > _hax = Stats . HaX = value ; }
2017-06-19 05:27:40 +00:00
public byte [ ] LastData { private get ; set ; }
2018-05-13 19:49:26 +00:00
public PKM Data { get = > pkm ; set = > pkm = value ; }
2018-02-27 05:22:35 +00:00
public PKM pkm { get ; private set ; }
public bool FieldsLoaded { get ; private set ; }
public bool ChangingFields { get ; set ; }
2018-07-19 23:46:56 +00:00
public int CurrentLevel = > Util . ToInt32 ( ( HaX ? MT_Level : TB_Level ) . Text ) ;
2018-02-27 05:22:35 +00:00
2017-06-19 05:27:40 +00:00
private GameVersion origintrack ;
2017-06-18 01:37:19 +00:00
private Action GetFieldsfromPKM ;
private Func < PKM > GetPKMfromFields ;
2017-05-23 04:55:05 +00:00
private LegalityAnalysis Legality ;
2019-01-21 05:55:28 +00:00
private IReadOnlyList < string > gendersymbols = GameInfo . GenderSymbolUnicode ;
2017-06-19 05:27:40 +00:00
private readonly Image mixedHighlight = ImageUtil . ChangeOpacity ( Resources . slotSet , 0.5 ) ;
2018-08-02 04:22:49 +00:00
private HashSet < int > AllowedMoves = new HashSet < int > ( ) ;
2017-05-23 04:55:05 +00:00
public event EventHandler LegalityChanged ;
public event EventHandler UpdatePreviewSprite ;
public event EventHandler RequestShowdownImport ;
public event EventHandler RequestShowdownExport ;
public event ReturnSAVEventHandler SaveFileRequested ;
2017-12-16 22:11:41 +00:00
public delegate SaveFile ReturnSAVEventHandler ( object sender , EventArgs e ) ;
2017-05-23 04:55:05 +00:00
private readonly PictureBox [ ] movePB , relearnPB ;
2018-09-29 04:17:46 +00:00
private readonly ToolTip Tip3 = new ToolTip ( ) , NatureTip = new ToolTip ( ) , SpeciesIDTip = new ToolTip ( ) ;
2018-07-28 04:21:42 +00:00
public SaveFile RequestSaveFile = > SaveFileRequested ? . Invoke ( this , EventArgs . Empty ) ;
2019-02-10 01:07:44 +00:00
public bool PKMIsUnsaved = > FieldsLoaded & & LastData ? . Any ( b = > b ! = 0 ) = = true & & ! LastData . SequenceEqual ( CurrentPKM . Data ) ;
2017-05-23 04:55:05 +00:00
public bool IsEmptyOrEgg = > CHK_IsEgg . Checked | | CB_Species . SelectedIndex = = 0 ;
2018-03-11 02:03:09 +00:00
private readonly ComboBox [ ] Moves , Relearn , ValidationRequired , PPUps ;
private readonly MaskedTextBox [ ] MovePP ;
2018-05-27 17:24:28 +00:00
private readonly PictureBox [ ] Markings ;
2018-03-11 02:03:09 +00:00
2017-10-26 02:37:31 +00:00
private bool forceValidation ;
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
public PKM PreparePKM ( bool click = true )
2017-05-23 04:55:05 +00:00
{
if ( click )
2017-10-26 02:37:31 +00:00
{
forceValidation = true ;
2017-05-23 04:55:05 +00:00
ValidateChildren ( ) ;
2017-10-26 02:37:31 +00:00
forceValidation = false ;
}
2017-06-18 01:37:19 +00:00
PKM pk = GetPKMfromFields ( ) ;
2018-12-20 06:10:32 +00:00
return pk ? . Clone ( ) ? ? pkm ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2019-02-10 01:07:44 +00:00
public bool EditsComplete
2017-05-23 04:55:05 +00:00
{
2019-02-10 01:07:44 +00:00
get
{
if ( ModifierKeys = = ( Keys . Control | Keys . Shift | Keys . Alt ) )
return true ; // Override
2017-05-23 04:55:05 +00:00
2019-02-10 01:07:44 +00:00
var cb = Array . Find ( ValidationRequired , c = > c . BackColor = = Draw . InvalidSelection & & c . Items . Count ! = 0 ) ;
if ( cb ! = null )
tabMain . SelectedTab = WinFormsUtil . FindFirstControlOfType < TabPage > ( cb ) ;
else if ( ! Stats . Valid )
tabMain . SelectedTab = Tab_Stats ;
else if ( WinFormsUtil . GetIndex ( CB_Species ) = = 0 )
tabMain . SelectedTab = Tab_Main ;
else
return true ;
2017-05-23 04:55:05 +00:00
2019-02-10 01:07:44 +00:00
System . Media . SystemSounds . Exclamation . Play ( ) ;
return false ;
}
2017-05-23 04:55:05 +00:00
}
2018-12-20 06:10:32 +00:00
public void SetPKMFormatMode ( int Format , PKM pk )
2017-05-23 04:55:05 +00:00
{
2018-12-20 06:10:32 +00:00
// Load Extra Byte List
SetPKMFormatExtraBytes ( pk ) ;
2017-05-23 04:55:05 +00:00
switch ( Format )
{
case 1 :
2017-06-18 01:37:19 +00:00
GetFieldsfromPKM = PopulateFieldsPK1 ;
GetPKMfromFields = PreparePK1 ;
2017-05-23 04:55:05 +00:00
break ;
case 2 :
2017-06-18 01:37:19 +00:00
GetFieldsfromPKM = PopulateFieldsPK2 ;
GetPKMfromFields = PreparePK2 ;
2017-05-23 04:55:05 +00:00
break ;
case 3 :
2017-06-18 01:37:19 +00:00
GetFieldsfromPKM = PopulateFieldsPK3 ;
GetPKMfromFields = PreparePK3 ;
2017-05-23 04:55:05 +00:00
break ;
case 4 :
2017-06-18 01:37:19 +00:00
GetFieldsfromPKM = PopulateFieldsPK4 ;
GetPKMfromFields = PreparePK4 ;
2017-05-23 04:55:05 +00:00
break ;
case 5 :
2017-06-18 01:37:19 +00:00
GetFieldsfromPKM = PopulateFieldsPK5 ;
GetPKMfromFields = PreparePK5 ;
2017-05-23 04:55:05 +00:00
break ;
case 6 :
2017-06-18 01:37:19 +00:00
GetFieldsfromPKM = PopulateFieldsPK6 ;
GetPKMfromFields = PreparePK6 ;
2017-05-23 04:55:05 +00:00
break ;
case 7 :
2018-12-20 06:10:32 +00:00
switch ( pk )
2018-11-14 03:25:03 +00:00
{
case PK7 _ :
GetFieldsfromPKM = PopulateFieldsPK7 ;
GetPKMfromFields = PreparePK7 ;
break ;
case PB7 _ :
GetFieldsfromPKM = PopulateFieldsPB7 ;
GetPKMfromFields = PreparePB7 ;
break ;
}
2017-05-23 04:55:05 +00:00
break ;
}
2018-12-20 06:10:32 +00:00
}
2017-05-23 04:55:05 +00:00
2018-12-20 06:10:32 +00:00
private void SetPKMFormatExtraBytes ( PKM pk )
{
byte [ ] extraBytes = pk . ExtraBytes ;
2017-05-23 04:55:05 +00:00
GB_ExtraBytes . Visible = GB_ExtraBytes . Enabled = extraBytes . Length ! = 0 ;
2017-05-23 15:28:53 +00:00
CB_ExtraBytes . Items . Clear ( ) ;
foreach ( byte b in extraBytes )
CB_ExtraBytes . Items . Add ( $"0x{b:X2}" ) ;
2017-05-23 04:55:05 +00:00
if ( GB_ExtraBytes . Enabled )
CB_ExtraBytes . SelectedIndex = 0 ;
}
2018-07-27 02:34:27 +00:00
2017-10-28 21:26:27 +00:00
public void PopulateFields ( PKM pk , bool focus = true , bool skipConversionCheck = false ) = > LoadFieldsFromPKM ( pk , focus , skipConversionCheck ) ;
2018-07-27 02:34:27 +00:00
2017-10-28 21:26:27 +00:00
private void LoadFieldsFromPKM ( PKM pk , bool focus = true , bool skipConversionCheck = true )
2017-05-23 04:55:05 +00:00
{
2018-04-06 04:25:18 +00:00
if ( pk = = null ) { WinFormsUtil . Error ( MsgPKMLoadNull ) ; return ; }
2017-05-23 04:55:05 +00:00
if ( focus )
Tab_Main . Focus ( ) ;
2019-01-16 00:47:32 +00:00
if ( ! skipConversionCheck & & ! PKMConverter . TryMakePKMCompatible ( pk , pkm , out string c , out pk ) )
2017-10-28 21:26:27 +00:00
{ WinFormsUtil . Alert ( c ) ; return ; }
2019-02-10 01:07:44 +00:00
FieldsLoaded = false ;
2017-05-23 04:55:05 +00:00
2017-10-26 02:37:31 +00:00
pkm = pk . Clone ( ) ;
2017-05-23 04:55:05 +00:00
2017-06-18 01:37:19 +00:00
try { GetFieldsfromPKM ( ) ; }
2019-02-15 04:18:31 +00:00
catch { }
2017-05-23 04:55:05 +00:00
2019-02-02 18:19:41 +00:00
Stats . UpdateIVs ( null , EventArgs . Empty ) ;
UpdatePKRSInfected ( null , EventArgs . Empty ) ;
UpdatePKRSCured ( null , EventArgs . Empty ) ;
UpdateNatureModification ( null , EventArgs . Empty ) ;
2017-05-23 04:55:05 +00:00
if ( HaX ) // Load original values from pk not pkm
{
2019-02-09 21:17:00 +00:00
MT_Level . Text = ( pk . PartyStatsPresent ? pk . Stat_Level : Experience . GetLevel ( pk . EXP , pk . Species , pk . AltForm ) ) . ToString ( ) ;
2017-05-23 04:55:05 +00:00
TB_EXP . Text = pk . EXP . ToString ( ) ;
2019-01-16 00:47:32 +00:00
MT_Form . Text = Math . Max ( 0 , pk . AltForm ) . ToString ( ) ;
2019-01-12 18:54:38 +00:00
if ( pk . PartyStatsPresent ) // stats present
2018-02-27 05:22:35 +00:00
Stats . LoadPartyStats ( pk ) ;
2017-05-23 04:55:05 +00:00
}
2018-02-27 05:22:35 +00:00
FieldsLoaded = true ;
2017-05-23 04:55:05 +00:00
2017-06-18 01:37:19 +00:00
SetMarkings ( ) ;
UpdateLegality ( ) ;
2017-06-19 05:27:40 +00:00
UpdateSprite ( ) ;
LastData = PreparePKM ( ) ? . Data ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
public void UpdateLegality ( LegalityAnalysis la = null , bool skipMoveRepop = false )
2017-05-23 04:55:05 +00:00
{
2018-02-27 05:22:35 +00:00
if ( ! FieldsLoaded )
2017-05-23 04:55:05 +00:00
return ;
2017-11-07 03:31:24 +00:00
Legality = la ? ? new LegalityAnalysis ( pkm , RequestSaveFile . Personal ) ;
2017-05-23 04:55:05 +00:00
if ( ! Legality . Parsed | | HaX | | pkm . Species = = 0 )
{
PB_WarnMove1 . Visible = PB_WarnMove2 . Visible = PB_WarnMove3 . Visible = PB_WarnMove4 . Visible =
PB_WarnRelearn1 . Visible = PB_WarnRelearn2 . Visible = PB_WarnRelearn3 . Visible = PB_WarnRelearn4 . Visible = false ;
2019-02-02 18:19:41 +00:00
LegalityChanged ? . Invoke ( Legality . Valid , EventArgs . Empty ) ;
2017-05-23 04:55:05 +00:00
return ;
}
// Refresh Move Legality
for ( int i = 0 ; i < 4 ; i + + )
2017-06-21 00:57:23 +00:00
movePB [ i ] . Visible = ! Legality . Info ? . Moves [ i ] . Valid ? ? false ;
2017-05-23 04:55:05 +00:00
if ( pkm . Format > = 6 )
2018-07-27 02:34:27 +00:00
{
2017-05-23 04:55:05 +00:00
for ( int i = 0 ; i < 4 ; i + + )
2017-06-21 00:57:23 +00:00
relearnPB [ i ] . Visible = ! Legality . Info ? . Relearn [ i ] . Valid ? ? false ;
2018-07-27 02:34:27 +00:00
}
2017-05-23 04:55:05 +00:00
if ( skipMoveRepop )
return ;
// Resort moves
2018-02-27 05:22:35 +00:00
FieldsLoaded = false ;
2018-08-02 04:22:49 +00:00
ReloadMoves ( Legality . AllSuggestedMovesAndRelearn ) ;
2019-02-10 01:07:44 +00:00
FieldsLoaded = true ;
2019-02-02 18:19:41 +00:00
LegalityChanged ? . Invoke ( Legality . Valid , EventArgs . Empty ) ;
2018-08-02 04:22:49 +00:00
}
2018-09-14 05:10:35 +00:00
private IReadOnlyList < ComboItem > MoveDataAllowed = new List < ComboItem > ( ) ;
2018-08-02 04:57:15 +00:00
2018-08-02 04:22:49 +00:00
private void ReloadMoves ( IReadOnlyCollection < int > moves )
{
// check prior movepool to not needlessly refresh the dataset
if ( AllowedMoves . Count < = moves . Count & & moves . All ( AllowedMoves . Contains ) )
return ;
AllowedMoves = new HashSet < int > ( moves ) ;
2018-08-02 04:57:15 +00:00
MoveDataAllowed = GameInfo . Strings . MoveDataSource . OrderByDescending ( m = > AllowedMoves . Contains ( m . Value ) ) . ToList ( ) ;
// defer repop until dropdown is opened; handled by dropdown event
for ( int i = 0 ; i < IsMoveBoxOrdered . Count ; i + + )
IsMoveBoxOrdered [ i ] = false ;
}
private void SetMoveDataSource ( ComboBox c )
{
var index = WinFormsUtil . GetIndex ( c ) ;
c . DataSource = new BindingSource ( MoveDataAllowed , null ) ;
c . SelectedValue = index ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2019-01-21 05:55:28 +00:00
public void UpdateUnicode ( IReadOnlyList < string > symbols )
2017-05-23 04:55:05 +00:00
{
gendersymbols = symbols ;
if ( ! Unicode )
{
2019-02-09 21:15:37 +00:00
BTN_Shinytize . Text = Draw . ShinyDefault ;
2018-04-28 16:34:54 +00:00
TB_Nickname . Font = TB_OT . Font = TB_OTt2 . Font = GB_OT . Font ;
2017-05-23 04:55:05 +00:00
}
else
{
2019-02-09 21:15:37 +00:00
BTN_Shinytize . Text = Draw . ShinyUnicode ;
2017-06-18 01:37:19 +00:00
TB_Nickname . Font = TB_OT . Font = TB_OTt2 . Font = FontUtil . GetPKXFont ( 11 ) ;
2017-05-23 04:55:05 +00:00
}
2019-02-09 21:15:37 +00:00
2017-05-23 04:55:05 +00:00
// Switch active gender labels to new if they are active.
2019-02-09 21:15:37 +00:00
ReloadGender ( Label_Gender , gendersymbols ) ;
ReloadGender ( Label_OTGender , gendersymbols ) ;
ReloadGender ( Label_CTGender , gendersymbols ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2019-02-09 21:15:37 +00:00
private static string ReloadGender ( string text , IReadOnlyList < string > genders )
{
var index = PKX . GetGenderFromString ( text ) ;
if ( index > = 2 )
return text ;
return genders [ index ] ;
}
private static void ReloadGender ( Label l , IReadOnlyList < string > genders ) = > l . Text = ReloadGender ( l . Text , genders ) ;
2017-06-19 05:27:40 +00:00
private void UpdateSprite ( )
{
2019-02-10 01:07:44 +00:00
if ( FieldsLoaded & & ! forceValidation )
2019-02-02 18:19:41 +00:00
UpdatePreviewSprite ? . Invoke ( this , EventArgs . Empty ) ;
2017-06-19 05:27:40 +00:00
}
2017-05-23 04:55:05 +00:00
// General Use Functions //
2018-09-03 01:02:25 +00:00
2018-07-27 02:34:27 +00:00
2018-03-29 01:52:50 +00:00
private void SetDetailsOT ( ITrainerInfo SAV )
2017-05-23 04:55:05 +00:00
{
2019-02-02 18:19:41 +00:00
if ( string . IsNullOrWhiteSpace ( SAV . OT ) )
2017-05-23 04:55:05 +00:00
return ;
// Get Save Information
TB_OT . Text = SAV . OT ;
Label_OTGender . Text = gendersymbols [ SAV . Gender & 1 ] ;
2019-02-09 21:15:37 +00:00
Label_OTGender . ForeColor = Draw . GetGenderColor ( SAV . Gender & 1 ) ;
2018-04-28 16:34:54 +00:00
TID_Trainer . LoadInfo ( SAV ) ;
2017-05-23 04:55:05 +00:00
if ( SAV . Game > = 0 )
CB_GameOrigin . SelectedValue = SAV . Game ;
2018-12-20 06:10:32 +00:00
var lang = SAV . Language ;
if ( lang < = 0 )
lang = ( int ) LanguageID . English ;
CB_Language . SelectedValue = lang ;
2018-03-29 01:52:50 +00:00
if ( SAV . ConsoleRegion ! = 0 )
2017-05-23 04:55:05 +00:00
{
CB_3DSReg . SelectedValue = SAV . ConsoleRegion ;
CB_Country . SelectedValue = SAV . Country ;
CB_SubRegion . SelectedValue = SAV . SubRegion ;
}
2018-02-23 06:42:50 +00:00
// Copy OT trash bytes for sensitive games (Gen1/2)
if ( SAV is SAV1 s1 & & pkm is PK1 p1 ) p1 . OT_Trash = s1 . OT_Trash ;
else if ( SAV is SAV2 s2 & & pkm is PK2 p2 ) p2 . OT_Trash = s2 . OT_Trash ;
2019-02-02 18:19:41 +00:00
UpdateNickname ( null , EventArgs . Empty ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2018-03-29 01:52:50 +00:00
private void SetDetailsHT ( ITrainerInfo SAV )
2017-05-23 04:55:05 +00:00
{
2019-02-02 18:19:41 +00:00
if ( string . IsNullOrWhiteSpace ( SAV . OT ) )
2017-05-23 04:55:05 +00:00
return ;
if ( TB_OTt2 . Text . Length > 0 )
Label_CTGender . Text = gendersymbols [ SAV . Gender & 1 ] ;
}
2018-07-07 00:37:07 +00:00
2017-06-18 01:37:19 +00:00
private void SetForms ( )
2017-05-23 04:55:05 +00:00
{
2018-07-07 00:37:07 +00:00
int species = pkm . Species ;
var pi = RequestSaveFile ? . Personal [ species ] ? ? pkm . PersonalInfo ;
bool hasForms = FormConverter . HasFormSelection ( pi , species , pkm . Format ) ;
2017-05-23 04:55:05 +00:00
CB_Form . Enabled = CB_Form . Visible = Label_Form . Visible = hasForms ;
if ( HaX & & pkm . Format > = 4 )
2018-07-07 00:37:07 +00:00
Label_Form . Visible = true ; // show with value entry textbox
2017-05-23 04:55:05 +00:00
if ( ! hasForms )
return ;
2018-09-03 01:02:25 +00:00
var ds = PKX . GetFormList ( species , GameInfo . Strings . types , GameInfo . Strings . forms , gendersymbols , pkm . Format ) ;
if ( ds . Length = = 1 & & string . IsNullOrEmpty ( ds [ 0 ] ) ) // empty (Alolan Totems)
2017-05-23 04:55:05 +00:00
CB_Form . Enabled = CB_Form . Visible = Label_Form . Visible = false ;
2018-07-07 00:37:07 +00:00
else
CB_Form . DataSource = ds ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void SetAbilityList ( )
2017-05-23 04:55:05 +00:00
{
if ( pkm . Format < 3 ) // no abilities
return ;
2018-02-27 05:22:35 +00:00
if ( pkm . Format > 3 & & FieldsLoaded ) // has forms
2017-12-22 06:55:33 +00:00
pkm . AltForm = CB_Form . SelectedIndex ; // update pkm field for form specific abilities
2017-10-03 06:13:40 +00:00
2017-12-22 06:55:33 +00:00
int abil = CB_Ability . SelectedIndex ;
2017-05-23 04:55:05 +00:00
2018-02-27 05:22:35 +00:00
bool tmp = FieldsLoaded ;
FieldsLoaded = false ;
2017-12-22 06:55:33 +00:00
CB_Ability . DataSource = GetAbilityList ( pkm ) ;
CB_Ability . SelectedIndex = GetSafeIndex ( CB_Ability , abil ) ; // restore original index if available
2018-02-27 05:22:35 +00:00
FieldsLoaded = tmp ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-12-22 06:55:33 +00:00
private static int GetSafeIndex ( ComboBox cb , int index ) = > Math . Max ( 0 , Math . Min ( cb . Items . Count - 1 , index ) ) ;
2018-08-26 00:04:01 +00:00
private void UpdateIsShiny ( )
2017-05-23 04:55:05 +00:00
{
2017-12-22 06:55:33 +00:00
// Recalculate shininiess
2017-05-23 04:55:05 +00:00
bool isShiny = pkm . IsShiny ;
// Set the Controls
BTN_Shinytize . Visible = BTN_Shinytize . Enabled = ! isShiny ;
Label_IsShiny . Visible = isShiny ;
// Refresh Markings (for Shiny Star if applicable)
2017-06-18 01:37:19 +00:00
SetMarkings ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void SetMarkings ( )
2017-05-23 04:55:05 +00:00
{
double getOpacity ( bool b ) = > b ? 1 : 0.175 ;
2018-05-12 15:13:39 +00:00
Image changeOpacity ( PictureBox p , double opacity ) = > opacity = = 1 ? p . InitialImage
2018-02-27 05:22:35 +00:00
: ImageUtil . ChangeOpacity ( p . InitialImage , opacity ) ;
2018-05-27 17:24:28 +00:00
var pba = Markings ;
var markings = pkm . Markings ;
2017-05-23 04:55:05 +00:00
for ( int i = 0 ; i < pba . Length ; i + + )
2018-05-27 17:24:28 +00:00
pba [ i ] . Image = changeOpacity ( pba [ i ] , getOpacity ( markings [ i ] ! = 0 ) ) ;
2017-05-23 04:55:05 +00:00
2018-02-27 05:22:35 +00:00
PB_MarkShiny . Image = changeOpacity ( PB_MarkShiny , getOpacity ( ! BTN_Shinytize . Enabled ) ) ;
PB_MarkCured . Image = changeOpacity ( PB_MarkCured , getOpacity ( CHK_Cured . Checked ) ) ;
2017-05-23 04:55:05 +00:00
2018-02-27 05:22:35 +00:00
PB_MarkPentagon . Image = changeOpacity ( PB_MarkPentagon , getOpacity ( pkm . Gen6 ) ) ;
2018-12-05 02:38:47 +00:00
PB_Favorite . Image = changeOpacity ( PB_Favorite , getOpacity ( pkm is PB7 pb7 & & pb7 . Favorite ) ) ;
2017-05-23 04:55:05 +00:00
// Gen7 Markings
if ( pkm . Format ! = 7 )
return ;
2018-02-27 05:22:35 +00:00
PB_MarkAlola . Image = changeOpacity ( PB_MarkAlola , getOpacity ( pkm . Gen7 ) ) ;
PB_MarkVC . Image = changeOpacity ( PB_MarkVC , getOpacity ( pkm . VC ) ) ;
2019-01-05 23:40:25 +00:00
PB_MarkGO . Image = changeOpacity ( PB_MarkGO , getOpacity ( pkm . GO ) ) ;
2017-05-23 04:55:05 +00:00
for ( int i = 0 ; i < pba . Length ; i + + )
2018-07-27 02:34:27 +00:00
{
2019-02-09 21:15:37 +00:00
if ( Draw . GetMarkingColor ( markings [ i ] , out Color c ) )
2017-08-13 07:21:42 +00:00
pba [ i ] . Image = ImageUtil . ChangeAllColorTo ( pba [ i ] . Image , c ) ;
2018-07-27 02:34:27 +00:00
}
2017-08-13 07:21:42 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateGender ( )
2017-05-23 04:55:05 +00:00
{
2018-05-10 00:50:56 +00:00
int Gender = pkm . GetSaneGender ( ) ;
2017-05-23 04:55:05 +00:00
Label_Gender . Text = gendersymbols [ Gender ] ;
2019-02-09 21:15:37 +00:00
Label_Gender . ForeColor = Draw . GetGenderColor ( Gender ) ;
2017-05-23 04:55:05 +00:00
}
2017-06-18 01:37:19 +00:00
private void SetCountrySubRegion ( ComboBox CB , string type )
2017-05-23 04:55:05 +00:00
{
int index = CB . SelectedIndex ;
// fix for Korean / Chinese being swapped
2018-09-03 01:02:25 +00:00
string cl = GameInfo . CurrentLanguage ;
2017-05-23 04:55:05 +00:00
cl = cl = = "zh" ? "ko" : cl = = "ko" ? "zh" : cl ;
2019-02-15 19:47:35 +00:00
CB . DataSource = Util . GetCountryRegionList ( type , cl ) ;
2017-05-23 04:55:05 +00:00
2019-02-10 01:07:44 +00:00
if ( index > 0 & & index < CB . Items . Count )
2017-05-23 04:55:05 +00:00
CB . SelectedIndex = index ;
}
// Prompted Updates of PKM //
2017-06-18 01:37:19 +00:00
private void ClickFriendship ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2019-02-12 06:39:12 +00:00
if ( ModifierKeys = = Keys . Control ) // clear
TB_Friendship . Text = "0" ;
2017-05-23 04:55:05 +00:00
else
TB_Friendship . Text = TB_Friendship . Text = = "255" ? pkm . PersonalInfo . BaseFriendship . ToString ( ) : "255" ;
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void ClickLevel ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
if ( ModifierKeys = = Keys . Control )
( ( MaskedTextBox ) sender ) . Text = "100" ;
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void ClickGender ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
// Get Gender Threshold
int gt = pkm . PersonalInfo . Gender ;
if ( gt = = 255 | | gt = = 0 | | gt = = 254 ) // Single gender/genderless
return ;
2018-05-11 01:53:23 +00:00
int newGender = ( PKX . GetGenderFromString ( Label_Gender . Text ) & 1 ) ^ 1 ;
2017-09-06 16:12:56 +00:00
if ( pkm . Format < = 2 )
2017-09-23 23:50:38 +00:00
{
2018-02-27 05:22:35 +00:00
Stats . SetATKIVGender ( newGender ) ;
2018-08-26 00:04:01 +00:00
UpdateIsShiny ( ) ;
2017-09-23 23:50:38 +00:00
}
2017-05-23 04:55:05 +00:00
else if ( pkm . Format < = 4 )
{
2017-06-18 01:37:19 +00:00
pkm . Version = WinFormsUtil . GetIndex ( CB_GameOrigin ) ;
pkm . Nature = WinFormsUtil . GetIndex ( CB_Nature ) ;
2017-05-23 04:55:05 +00:00
pkm . AltForm = CB_Form . SelectedIndex ;
2017-06-18 01:37:19 +00:00
pkm . SetPIDGender ( newGender ) ;
2017-05-23 04:55:05 +00:00
TB_PID . Text = pkm . PID . ToString ( "X8" ) ;
}
pkm . Gender = newGender ;
Label_Gender . Text = gendersymbols [ pkm . Gender ] ;
2019-02-09 21:15:37 +00:00
Label_Gender . ForeColor = Draw . GetGenderColor ( pkm . Gender ) ;
2017-05-23 04:55:05 +00:00
2017-10-03 06:13:40 +00:00
if ( PKX . GetGenderFromString ( CB_Form . Text ) < 2 ) // Gendered Forms
CB_Form . SelectedIndex = PKX . GetGenderFromString ( Label_Gender . Text ) ;
2017-05-23 04:55:05 +00:00
2019-02-02 18:19:41 +00:00
UpdatePreviewSprite ( Label_Gender , EventArgs . Empty ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void ClickPPUps ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2018-05-12 19:28:48 +00:00
bool min = ModifierKeys . HasFlag ( Keys . Control ) ;
2019-02-10 01:07:44 +00:00
int getValue ( ComboBox cb , bool zero ) = > zero | | WinFormsUtil . GetIndex ( cb ) = = 0 ? 0 : 3 ;
CB_PPu1 . SelectedIndex = getValue ( CB_Move1 , min ) ;
CB_PPu2 . SelectedIndex = getValue ( CB_Move2 , min ) ;
CB_PPu3 . SelectedIndex = getValue ( CB_Move3 , min ) ;
CB_PPu4 . SelectedIndex = getValue ( CB_Move4 , min ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void ClickMarking ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2018-11-14 03:25:03 +00:00
int index = Array . IndexOf ( Markings , ( PictureBox ) sender ) ;
2018-05-27 17:24:28 +00:00
pkm . ToggleMarking ( index ) ;
2017-06-18 01:37:19 +00:00
SetMarkings ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2018-12-05 02:38:47 +00:00
private void ClickFavorite ( object sender , EventArgs e )
{
if ( pkm is PB7 pb7 )
pb7 . Favorite ^ = true ;
SetMarkings ( ) ;
}
2017-06-18 01:37:19 +00:00
private void ClickOT ( object sender , EventArgs e ) = > SetDetailsOT ( SaveFileRequested ? . Invoke ( this , e ) ) ;
private void ClickCT ( object sender , EventArgs e ) = > SetDetailsHT ( SaveFileRequested ? . Invoke ( this , e ) ) ;
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void ClickTRGender ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
Label lbl = sender as Label ;
if ( ! string . IsNullOrWhiteSpace ( lbl ? . Text ) ) // set gender label (toggle M/F)
{
2017-10-03 06:13:40 +00:00
int gender = PKX . GetGenderFromString ( lbl . Text ) ^ 1 ;
2017-05-23 04:55:05 +00:00
lbl . Text = gendersymbols [ gender ] ;
2019-02-09 21:15:37 +00:00
lbl . ForeColor = Draw . GetGenderColor ( gender ) ;
2017-05-23 04:55:05 +00:00
}
}
2018-07-27 02:34:27 +00:00
2018-08-29 04:13:45 +00:00
private void ClickBall ( object sender , EventArgs e )
{
pkm . Ball = WinFormsUtil . GetIndex ( CB_Ball ) ;
if ( ModifierKeys . HasFlag ( Keys . Alt ) )
2018-08-30 02:30:48 +00:00
{
2018-08-29 04:13:45 +00:00
CB_Ball . SelectedValue = ( int ) Ball . Poke ;
2018-08-30 02:30:48 +00:00
return ;
}
2018-08-30 03:36:32 +00:00
if ( ModifierKeys . HasFlag ( Keys . Shift ) )
{
CB_Ball . SelectedValue = BallRandomizer . ApplyBallLegalByColor ( pkm ) ;
return ;
}
2018-08-30 02:30:48 +00:00
2019-02-15 04:18:31 +00:00
using ( var frm = new BallBrowser ( ) )
2018-08-30 02:30:48 +00:00
{
2019-02-15 04:23:51 +00:00
frm . LoadBalls ( pkm ) ;
2019-02-15 04:18:31 +00:00
frm . ShowDialog ( ) ;
if ( frm . BallChoice > = 0 )
CB_Ball . SelectedValue = frm . BallChoice ;
2018-08-30 02:30:48 +00:00
}
2018-08-29 04:13:45 +00:00
}
2017-06-18 04:49:14 +00:00
private void ClickShinyLeaf ( object sender , EventArgs e ) = > ShinyLeaf . CheckAll ( ModifierKeys ! = Keys . Control ) ;
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void ClickMetLocation ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
if ( HaX )
return ;
2017-06-18 01:37:19 +00:00
pkm = PreparePKM ( ) ;
UpdateLegality ( skipMoveRepop : true ) ;
2017-05-23 04:55:05 +00:00
if ( Legality . Valid )
return ;
2017-06-30 02:32:29 +00:00
if ( ! SetSuggestedMetLocation ( ) )
2017-05-23 04:55:05 +00:00
return ;
2017-06-18 01:37:19 +00:00
pkm = PreparePKM ( ) ;
UpdateLegality ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void ClickGT ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
if ( ! GB_nOT . Visible )
return ;
if ( sender = = GB_OT )
{
pkm . CurrentHandler = 0 ;
GB_OT . BackgroundImage = mixedHighlight ;
GB_nOT . BackgroundImage = null ;
}
else if ( TB_OTt2 . Text . Length > 0 )
{
pkm . CurrentHandler = 1 ;
GB_OT . BackgroundImage = null ;
GB_nOT . BackgroundImage = mixedHighlight ;
}
TB_Friendship . Text = pkm . CurrentFriendship . ToString ( ) ;
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void ClickMoves ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2017-06-18 01:37:19 +00:00
UpdateLegality ( skipMoveRepop : true ) ;
2017-05-23 04:55:05 +00:00
if ( sender = = GB_CurrentMoves )
{
2017-06-18 01:37:19 +00:00
if ( ! SetSuggestedMoves ( random : ModifierKeys = = Keys . Control ) )
2017-05-23 04:55:05 +00:00
return ;
}
else if ( sender = = GB_RelearnMoves )
{
2017-06-18 01:37:19 +00:00
if ( ! SetSuggestedRelearnMoves ( ) )
return ;
}
else
{
return ;
}
UpdateLegality ( ) ;
}
2018-07-27 02:34:27 +00:00
2017-06-30 02:32:29 +00:00
private bool SetSuggestedMoves ( bool random = false , bool silent = false )
2017-06-18 01:37:19 +00:00
{
2018-05-20 21:29:13 +00:00
int [ ] m = pkm . GetMoveSet ( random ) ;
2018-05-28 00:57:45 +00:00
if ( m ? . Any ( z = > z ! = 0 ) ! = true )
2017-06-18 01:37:19 +00:00
{
2017-06-30 02:32:29 +00:00
if ( ! silent )
2018-04-06 04:25:18 +00:00
WinFormsUtil . Alert ( MsgPKMSuggestionFormat ) ;
2017-06-18 01:37:19 +00:00
return false ;
}
if ( pkm . Moves . SequenceEqual ( m ) )
return false ;
2017-06-30 02:32:29 +00:00
if ( ! silent )
{
2018-09-03 01:02:25 +00:00
var movestrings = m . Select ( v = > v > = GameInfo . Strings . Move . Count ? MsgProgramError : GameInfo . Strings . Move [ v ] ) ;
2019-02-07 07:28:02 +00:00
var msg = string . Join ( Environment . NewLine , movestrings ) ;
if ( DialogResult . Yes ! = WinFormsUtil . Prompt ( MessageBoxButtons . YesNo , MsgPKMSuggestionMoves , msg ) )
2017-06-30 02:32:29 +00:00
return false ;
}
2017-06-18 01:37:19 +00:00
2018-03-20 15:35:41 +00:00
pkm . SetMoves ( m ) ;
2018-03-19 16:03:27 +00:00
FieldsLoaded = false ;
2018-03-11 02:03:09 +00:00
LoadMoves ( pkm ) ;
2018-03-19 16:03:27 +00:00
FieldsLoaded = true ;
2017-06-18 01:37:19 +00:00
return true ;
}
2018-07-27 02:34:27 +00:00
2017-06-18 20:02:02 +00:00
private bool SetSuggestedRelearnMoves ( bool silent = false )
2017-06-18 01:37:19 +00:00
{
2017-06-30 02:32:29 +00:00
if ( pkm . Format < 6 )
return false ;
2017-05-23 04:55:05 +00:00
2019-02-07 07:28:02 +00:00
var m = pkm . GetSuggestedRelearnMoves ( Legality ) ;
2017-06-18 01:37:19 +00:00
if ( pkm . RelearnMoves . SequenceEqual ( m ) )
return false ;
2017-05-23 04:55:05 +00:00
2017-06-30 02:32:29 +00:00
if ( ! silent )
{
2018-09-03 01:02:25 +00:00
var movestrings = m . Select ( v = > v > = GameInfo . Strings . Move . Count ? MsgProgramError : GameInfo . Strings . Move [ v ] ) ;
2019-02-07 07:28:02 +00:00
var msg = string . Join ( Environment . NewLine , movestrings ) ;
if ( DialogResult . Yes ! = WinFormsUtil . Prompt ( MessageBoxButtons . YesNo , MsgPKMSuggestionRelearn , msg ) )
2017-06-30 02:32:29 +00:00
return false ;
}
2017-05-23 04:55:05 +00:00
2019-02-08 00:54:56 +00:00
CB_RelearnMove1 . SelectedValue = m [ 0 ] ;
CB_RelearnMove2 . SelectedValue = m [ 1 ] ;
CB_RelearnMove3 . SelectedValue = m [ 2 ] ;
CB_RelearnMove4 . SelectedValue = m [ 3 ] ;
2017-06-18 01:37:19 +00:00
return true ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-30 02:32:29 +00:00
private bool SetSuggestedMetLocation ( bool silent = false )
{
var encounter = Legality . GetSuggestedMetInfo ( ) ;
2018-07-27 02:34:27 +00:00
if ( encounter = = null | | ( pkm . Format > = 3 & & encounter . Location < 0 ) )
2017-06-30 02:32:29 +00:00
{
if ( ! silent )
2018-04-06 04:25:18 +00:00
WinFormsUtil . Alert ( MsgPKMSuggestionNone ) ;
2017-06-30 02:32:29 +00:00
return false ;
}
int level = encounter . Level ;
int location = encounter . Location ;
2017-08-29 01:12:57 +00:00
int minlvl = Legal . GetLowestLevel ( pkm , encounter . LevelMin ) ;
2017-06-30 02:32:29 +00:00
if ( minlvl = = 0 )
minlvl = level ;
if ( pkm . CurrentLevel > = minlvl & & pkm . Met_Level = = level & & pkm . Met_Location = = location )
return false ;
if ( minlvl < level )
minlvl = level ;
if ( ! silent )
{
2019-02-07 07:28:02 +00:00
var suggestions = GetSuggestionMessage ( pkm , level , location , minlvl ) ;
if ( suggestions . Count < = 1 ) // no suggestion
2017-06-30 02:32:29 +00:00
return false ;
2019-02-07 07:28:02 +00:00
var msg = string . Join ( Environment . NewLine , suggestions ) ;
if ( WinFormsUtil . Prompt ( MessageBoxButtons . YesNo , msg ) ! = DialogResult . Yes )
2017-06-30 02:32:29 +00:00
return false ;
}
if ( pkm . Format > = 3 )
{
TB_MetLevel . Text = level . ToString ( ) ;
CB_MetLocation . SelectedValue = location ;
2017-08-06 03:30:33 +00:00
if ( pkm . GenNumber = = 6 & & pkm . WasEgg & & ModifyPKM )
2018-03-26 02:05:49 +00:00
pkm . SetHatchMemory6 ( ) ;
2017-06-30 02:32:29 +00:00
}
if ( pkm . CurrentLevel < minlvl )
TB_Level . Text = minlvl . ToString ( ) ;
return true ;
}
2017-05-23 04:55:05 +00:00
2018-02-27 05:22:35 +00:00
public void UpdateIVsGB ( bool skipForm )
2017-05-23 04:55:05 +00:00
{
2018-04-16 23:01:30 +00:00
if ( ! FieldsLoaded )
return ;
2018-02-27 05:22:35 +00:00
Label_Gender . Text = gendersymbols [ pkm . Gender ] ;
2019-02-09 21:15:37 +00:00
Label_Gender . ForeColor = Draw . GetGenderColor ( pkm . Gender ) ;
2018-02-27 05:22:35 +00:00
if ( pkm . Species = = 201 & & ! skipForm ) // Unown
CB_Form . SelectedIndex = pkm . AltForm ;
2017-05-23 04:55:05 +00:00
2018-08-26 00:04:01 +00:00
UpdateIsShiny ( ) ;
2018-02-27 05:22:35 +00:00
UpdateSprite ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateBall ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2018-07-21 04:32:33 +00:00
PB_Ball . Image = SpriteUtil . GetBallSprite ( WinFormsUtil . GetIndex ( CB_Ball ) ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateEXPLevel ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2019-02-10 01:07:44 +00:00
if ( ChangingFields )
2018-09-03 01:02:25 +00:00
return ;
2018-02-27 05:22:35 +00:00
ChangingFields = true ;
2017-05-23 04:55:05 +00:00
if ( sender = = TB_EXP )
{
// Change the Level
uint EXP = Util . ToUInt32 ( TB_EXP . Text ) ;
2018-08-26 00:04:01 +00:00
int Species = pkm . Species ;
2018-11-27 00:55:16 +00:00
int Form = pkm . AltForm ;
int Level = Experience . GetLevel ( EXP , Species , Form ) ;
2017-05-23 04:55:05 +00:00
if ( Level = = 100 )
2018-11-27 00:55:16 +00:00
EXP = Experience . GetEXP ( 100 , Species , Form ) ;
2017-05-23 04:55:05 +00:00
TB_Level . Text = Level . ToString ( ) ;
if ( ! HaX )
TB_EXP . Text = EXP . ToString ( ) ;
else if ( Level < = 100 & & Util . ToInt32 ( MT_Level . Text ) < = 100 )
MT_Level . Text = Level . ToString ( ) ;
}
else
{
// Change the XP
int Level = Util . ToInt32 ( ( HaX ? MT_Level : TB_Level ) . Text ) ;
2017-06-21 05:57:22 +00:00
if ( Level < = 0 )
2018-07-27 02:34:27 +00:00
{
2017-06-21 05:57:22 +00:00
TB_Level . Text = "1" ;
2018-07-27 02:34:27 +00:00
}
2017-06-21 05:57:22 +00:00
else if ( Level > 100 )
2017-05-24 00:46:32 +00:00
{
TB_Level . Text = "100" ;
if ( ! HaX )
Level = 100 ;
}
2018-08-26 00:04:01 +00:00
if ( Level > byte . MaxValue )
MT_Level . Text = "255" ;
else if ( Level < = 100 )
2018-11-27 00:55:16 +00:00
TB_EXP . Text = Experience . GetEXP ( Level , pkm . Species , pkm . AltForm ) . ToString ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-02-27 05:22:35 +00:00
ChangingFields = false ;
if ( FieldsLoaded ) // store values back
2017-05-23 04:55:05 +00:00
{
pkm . EXP = Util . ToUInt32 ( TB_EXP . Text ) ;
pkm . Stat_Level = Util . ToInt32 ( ( HaX ? MT_Level : TB_Level ) . Text ) ;
}
2018-11-26 23:37:44 +00:00
UpdateStats ( ) ;
2017-06-18 01:37:19 +00:00
UpdateLegality ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateRandomPID ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
if ( pkm . Format < 3 )
return ;
2018-02-27 05:22:35 +00:00
if ( FieldsLoaded )
2017-06-18 01:37:19 +00:00
pkm . PID = Util . GetHexValue ( TB_PID . Text ) ;
2017-05-23 04:55:05 +00:00
if ( sender = = Label_Gender )
2017-06-18 01:37:19 +00:00
pkm . SetPIDGender ( pkm . Gender ) ;
else if ( sender = = CB_Nature & & pkm . Nature ! = WinFormsUtil . GetIndex ( CB_Nature ) )
pkm . SetPIDNature ( WinFormsUtil . GetIndex ( CB_Nature ) ) ;
2017-05-23 04:55:05 +00:00
else if ( sender = = BTN_RerollPID )
2017-06-18 01:37:19 +00:00
pkm . SetPIDGender ( pkm . Gender ) ;
2017-05-23 04:55:05 +00:00
else if ( sender = = CB_Ability & & CB_Ability . SelectedIndex ! = pkm . PIDAbility & & pkm . PIDAbility > - 1 )
2018-09-03 17:30:35 +00:00
pkm . SetAbilityIndex ( CB_Ability . SelectedIndex ) ;
2017-05-23 04:55:05 +00:00
TB_PID . Text = pkm . PID . ToString ( "X8" ) ;
2018-02-09 02:47:52 +00:00
if ( pkm . Format > = 6 & & 3 < = pkm . GenNumber & & pkm . GenNumber < = 5 )
2017-05-23 04:55:05 +00:00
TB_EC . Text = TB_PID . Text ;
2018-08-26 00:04:01 +00:00
Update_ID ( TB_EC , e ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateRandomEC ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
if ( pkm . Format < 6 )
return ;
2018-09-03 17:30:35 +00:00
pkm . SetRandomEC ( ) ;
2018-08-26 00:04:01 +00:00
TB_EC . Text = pkm . EncryptionConstant . ToString ( "X8" ) ;
Update_ID ( TB_EC , e ) ;
2017-06-18 01:37:19 +00:00
UpdateLegality ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void Update255_MTB ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2018-08-26 00:04:01 +00:00
if ( ! ( sender is MaskedTextBox tb ) )
return ;
2017-05-23 04:55:05 +00:00
if ( Util . ToInt32 ( tb . Text ) > byte . MaxValue )
tb . Text = "255" ;
2018-11-26 23:42:40 +00:00
if ( sender = = TB_Friendship & & int . TryParse ( TB_Friendship . Text , out var val ) )
{
pkm . CurrentFriendship = val ;
UpdateStats ( ) ;
}
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateForm ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2018-02-27 05:22:35 +00:00
if ( CB_Form = = sender & & FieldsLoaded )
2018-11-27 00:55:16 +00:00
{
2017-05-23 04:55:05 +00:00
pkm . AltForm = CB_Form . SelectedIndex ;
2018-11-27 00:55:16 +00:00
uint EXP = Experience . GetEXP ( pkm . CurrentLevel , pkm . Species , pkm . AltForm ) ;
TB_EXP . Text = EXP . ToString ( ) ;
}
2017-05-23 04:55:05 +00:00
2018-11-26 23:37:44 +00:00
UpdateStats ( ) ;
2017-06-18 01:37:19 +00:00
SetAbilityList ( ) ;
2017-05-23 04:55:05 +00:00
// Gender Forms
2018-02-27 05:22:35 +00:00
if ( WinFormsUtil . GetIndex ( CB_Species ) = = 201 & & FieldsLoaded )
2017-05-23 04:55:05 +00:00
{
if ( pkm . Format = = 3 )
{
2017-06-18 01:37:19 +00:00
pkm . SetPIDUnown3 ( CB_Form . SelectedIndex ) ;
2017-05-23 04:55:05 +00:00
TB_PID . Text = pkm . PID . ToString ( "X8" ) ;
}
else if ( pkm . Format = = 2 )
{
int desiredForm = CB_Form . SelectedIndex ;
while ( pkm . AltForm ! = desiredForm )
2018-04-16 23:01:30 +00:00
{
FieldsLoaded = false ;
2019-02-02 18:19:41 +00:00
Stats . UpdateRandomIVs ( null , EventArgs . Empty ) ;
2018-04-16 23:01:30 +00:00
FieldsLoaded = true ;
}
2017-05-23 04:55:05 +00:00
}
}
2018-06-20 00:27:44 +00:00
else if ( CB_Form . Enabled & & PKX . GetGenderFromString ( CB_Form . Text ) < 2 )
2017-05-23 04:55:05 +00:00
{
if ( CB_Form . Items . Count = = 2 ) // actually M/F; Pumpkaboo formes in German are S,M,L,XL
2018-06-07 01:59:01 +00:00
{
pkm . Gender = CB_Form . SelectedIndex ;
UpdateGender ( ) ;
}
2017-05-23 04:55:05 +00:00
}
2018-06-07 01:59:01 +00:00
else
2018-07-27 02:34:27 +00:00
{
2018-06-07 01:59:01 +00:00
UpdateGender ( ) ;
2018-07-27 02:34:27 +00:00
}
2017-05-23 04:55:05 +00:00
2018-02-27 05:22:35 +00:00
if ( ChangingFields )
2017-05-23 04:55:05 +00:00
return ;
2018-02-27 05:22:35 +00:00
ChangingFields = true ;
2019-01-16 00:47:32 +00:00
MT_Form . Text = Math . Max ( 0 , CB_Form . SelectedIndex ) . ToString ( ) ;
2018-02-27 05:22:35 +00:00
ChangingFields = false ;
2017-05-23 04:55:05 +00:00
2017-06-19 05:27:40 +00:00
UpdateSprite ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateHaXForm ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2018-02-27 05:22:35 +00:00
if ( ChangingFields )
2017-05-23 04:55:05 +00:00
return ;
2018-02-27 05:22:35 +00:00
ChangingFields = true ;
2017-05-23 04:55:05 +00:00
int form = pkm . AltForm = Util . ToInt32 ( MT_Form . Text ) ;
CB_Form . SelectedIndex = CB_Form . Items . Count > form ? form : - 1 ;
2018-02-27 05:22:35 +00:00
ChangingFields = false ;
2017-05-23 04:55:05 +00:00
2017-06-19 05:27:40 +00:00
UpdateSprite ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdatePP ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2018-03-11 02:03:09 +00:00
if ( ! ( sender is ComboBox cb ) )
return ;
int index = Array . IndexOf ( Moves , cb ) ;
2017-05-23 04:55:05 +00:00
if ( index < 0 )
2018-03-11 02:03:09 +00:00
index = Array . IndexOf ( PPUps , cb ) ;
2017-05-23 04:55:05 +00:00
if ( index < 0 )
return ;
2018-03-11 02:03:09 +00:00
int move = WinFormsUtil . GetIndex ( Moves [ index ] ) ;
var ppctrl = PPUps [ index ] ;
int ppups = ppctrl . SelectedIndex ;
if ( move < = 0 )
2018-04-09 13:10:26 +00:00
{
2018-03-11 02:03:09 +00:00
ppctrl . SelectedIndex = 0 ;
2018-04-09 13:10:26 +00:00
MovePP [ index ] . Text = 0. ToString ( ) ;
}
2018-03-11 02:03:09 +00:00
else
2018-07-27 02:34:27 +00:00
{
2018-03-11 02:03:09 +00:00
MovePP [ index ] . Text = pkm . GetMovePP ( move , ppups ) . ToString ( ) ;
2018-07-27 02:34:27 +00:00
}
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdatePKRSstrain ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
// Change the PKRS Days to the legal bounds.
int currentDuration = CB_PKRSDays . SelectedIndex ;
CB_PKRSDays . Items . Clear ( ) ;
2018-07-27 02:34:27 +00:00
int max = ( CB_PKRSStrain . SelectedIndex % 4 ) + 2 ;
foreach ( int day in Enumerable . Range ( 0 , max ) )
CB_PKRSDays . Items . Add ( day ) ;
2017-05-23 04:55:05 +00:00
// Set the days back if they're legal, else set it to 1. (0 always passes).
CB_PKRSDays . SelectedIndex = currentDuration < CB_PKRSDays . Items . Count ? currentDuration : 1 ;
2018-09-03 01:02:25 +00:00
if ( CB_PKRSStrain . SelectedIndex ! = 0 )
return ;
2017-05-23 04:55:05 +00:00
// Never Infected
CB_PKRSDays . SelectedIndex = 0 ;
CHK_Cured . Checked = false ;
CHK_Infected . Checked = false ;
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdatePKRSdays ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2018-09-03 01:02:25 +00:00
if ( CB_PKRSDays . SelectedIndex ! = 0 )
return ;
2017-05-23 04:55:05 +00:00
// If no days are selected
if ( CB_PKRSStrain . SelectedIndex = = 0 )
CHK_Cured . Checked = CHK_Infected . Checked = false ; // No Strain = Never Cured / Infected, triggers Strain update
else CHK_Cured . Checked = true ; // Any Strain = Cured
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdatePKRSCured ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
// Cured PokeRus is toggled
if ( CHK_Cured . Checked )
{
// Has Had PokeRus
Label_PKRSdays . Visible = CB_PKRSDays . Visible = false ;
CB_PKRSDays . SelectedIndex = 0 ;
Label_PKRS . Visible = CB_PKRSStrain . Visible = true ;
CHK_Infected . Checked = true ;
// If we're cured we have to have a strain infection.
if ( CB_PKRSStrain . SelectedIndex = = 0 )
CB_PKRSStrain . SelectedIndex = 1 ;
}
else if ( ! CHK_Infected . Checked )
{
// Not Infected, Disable the other
Label_PKRS . Visible = CB_PKRSStrain . Visible = false ;
CB_PKRSStrain . SelectedIndex = 0 ;
}
else
{
// Still Infected for a duration
Label_PKRSdays . Visible = CB_PKRSDays . Visible = true ;
CB_PKRSDays . SelectedValue = 1 ;
}
// if not cured yet, days > 0
if ( ! CHK_Cured . Checked & & CHK_Infected . Checked & & CB_PKRSDays . SelectedIndex = = 0 )
CB_PKRSDays . SelectedIndex + + ;
2017-06-18 01:37:19 +00:00
SetMarkings ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdatePKRSInfected ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2018-09-03 01:02:25 +00:00
if ( CHK_Cured . Checked & & ! CHK_Infected . Checked )
{ CHK_Cured . Checked = false ; return ; }
if ( CHK_Cured . Checked )
return ;
2017-05-23 04:55:05 +00:00
Label_PKRS . Visible = CB_PKRSStrain . Visible = CHK_Infected . Checked ;
if ( ! CHK_Infected . Checked ) { CB_PKRSStrain . SelectedIndex = 0 ; CB_PKRSDays . SelectedIndex = 0 ; Label_PKRSdays . Visible = CB_PKRSDays . Visible = false ; }
2018-01-25 16:48:49 +00:00
else if ( CB_PKRSStrain . SelectedIndex = = 0 )
{
CB_PKRSStrain . SelectedIndex = CB_PKRSDays . SelectedIndex = 1 ;
Label_PKRSdays . Visible = CB_PKRSDays . Visible = true ;
UpdatePKRSCured ( sender , e ) ;
}
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateCountry ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2017-09-30 05:58:25 +00:00
int index ;
if ( sender is ComboBox c & & ( index = WinFormsUtil . GetIndex ( c ) ) > 0 )
SetCountrySubRegion ( CB_SubRegion , $"sr_{index:000}" ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateSpecies ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
// Get Species dependent information
2018-02-27 05:22:35 +00:00
if ( FieldsLoaded )
2017-06-18 01:37:19 +00:00
pkm . Species = WinFormsUtil . GetIndex ( CB_Species ) ;
2018-09-29 04:17:46 +00:00
SpeciesIDTip . SetToolTip ( CB_Species , pkm . Species . ToString ( "000" ) ) ;
2017-06-18 01:37:19 +00:00
SetAbilityList ( ) ;
SetForms ( ) ;
2019-02-02 18:19:41 +00:00
UpdateForm ( null , EventArgs . Empty ) ;
2017-05-23 04:55:05 +00:00
2018-02-27 05:22:35 +00:00
if ( ! FieldsLoaded )
2017-05-23 04:55:05 +00:00
return ;
// Recalculate EXP for Given Level
2018-11-27 00:55:16 +00:00
uint EXP = Experience . GetEXP ( pkm . CurrentLevel , pkm . Species , pkm . AltForm ) ;
2017-05-23 04:55:05 +00:00
TB_EXP . Text = EXP . ToString ( ) ;
// Check for Gender Changes
2017-06-18 01:37:19 +00:00
UpdateGender ( ) ;
2017-05-23 04:55:05 +00:00
// If species changes and no nickname, set the new name == speciesName.
if ( ! CHK_Nicknamed . Checked )
2017-06-18 01:37:19 +00:00
UpdateNickname ( sender , e ) ;
2017-05-23 04:55:05 +00:00
2017-06-18 01:37:19 +00:00
UpdateLegality ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateOriginGame ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2017-06-18 01:37:19 +00:00
GameVersion Version = ( GameVersion ) WinFormsUtil . GetIndex ( CB_GameOrigin ) ;
2018-07-16 22:07:20 +00:00
if ( FieldsLoaded )
pkm . Version = ( int ) Version ;
2018-05-05 00:59:04 +00:00
2017-05-23 04:55:05 +00:00
// check if differs
2018-05-24 23:53:51 +00:00
var group = GameUtil . GetMetLocationVersionGroup ( Version ) ;
if ( group = = GameVersion . GSC & & pkm . Format > = 7 )
group = GameVersion . USUM ;
else if ( pkm . Format < 3 )
group = GameVersion . GSC ;
2017-05-23 04:55:05 +00:00
2018-05-24 23:53:51 +00:00
if ( group ! = origintrack )
ReloadMetLocations ( Version ) ;
origintrack = group ;
2017-05-23 04:55:05 +00:00
// Visibility logic for Gen 4 encounter type; only show for Gen 4 Pokemon.
if ( pkm . Format > = 4 )
{
2018-03-26 02:05:49 +00:00
bool g4 = pkm . Gen4 ;
2017-05-23 04:55:05 +00:00
CB_EncounterType . Visible = Label_EncounterType . Visible = g4 & & pkm . Format < 7 ;
if ( ! g4 )
CB_EncounterType . SelectedValue = 0 ;
}
2018-02-27 05:22:35 +00:00
if ( ! FieldsLoaded )
2017-05-23 04:55:05 +00:00
return ;
2018-05-24 23:53:51 +00:00
TID_Trainer . LoadIDValues ( pkm ) ;
2017-06-18 01:37:19 +00:00
UpdateLegality ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2018-05-24 23:53:51 +00:00
private void ReloadMetLocations ( GameVersion Version )
{
var met_list = GameInfo . GetLocationList ( Version , pkm . Format , egg : false ) ;
CB_MetLocation . DataSource = new BindingSource ( met_list , null ) ;
var egg_list = GameInfo . GetLocationList ( Version , pkm . Format , egg : true ) ;
CB_EggLocation . DataSource = new BindingSource ( egg_list , null ) ;
// Stretch C/XD met location dropdowns
int width = CB_EggLocation . DropDownWidth ;
if ( Version = = GameVersion . CXD & & pkm . Format = = 3 )
width * = 2 ;
CB_MetLocation . DropDownWidth = width ;
if ( FieldsLoaded )
{
SetMarkings ( ) ; // Set/Remove the Nativity marking when gamegroup changes too
int metLoc = EncounterSuggestion . GetSuggestedTransferLocation ( pkm ) ;
CB_MetLocation . SelectedValue = Math . Max ( 0 , metLoc ) ;
CB_EggLocation . SelectedIndex = CHK_AsEgg . Checked ? 1 : 0 ; // daycare : none
}
else
{
CB_GameOrigin . Focus ( ) ; // hacky validation forcing
}
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateExtraByteValue ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2018-03-11 02:03:09 +00:00
if ( CB_ExtraBytes . Items . Count = = 0 | | ! ( sender is MaskedTextBox mtb ) )
2017-05-23 04:55:05 +00:00
return ;
// Changed Extra Byte's Value
2018-03-11 02:03:09 +00:00
if ( Util . ToInt32 ( mtb . Text ) > byte . MaxValue )
mtb . Text = "255" ;
2017-05-23 04:55:05 +00:00
2018-03-11 02:03:09 +00:00
int value = Util . ToInt32 ( mtb . Text ) ;
2017-05-23 04:55:05 +00:00
int offset = Convert . ToInt32 ( CB_ExtraBytes . Text , 16 ) ;
pkm . Data [ offset ] = ( byte ) value ;
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateExtraByteIndex ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
if ( CB_ExtraBytes . Items . Count = = 0 )
return ;
// Byte changed, need to refresh the Text box for the byte's value.
TB_ExtraByte . Text = pkm . Data [ Convert . ToInt32 ( CB_ExtraBytes . Text , 16 ) ] . ToString ( ) ;
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateNatureModification ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2018-08-26 00:04:01 +00:00
string text = Stats . UpdateNatureModification ( pkm . Nature ) ;
2018-02-27 05:22:35 +00:00
NatureTip . SetToolTip ( CB_Nature , text ) ;
2017-05-23 04:55:05 +00:00
}
2018-02-27 05:22:35 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateIsNicknamed ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2018-02-27 05:22:35 +00:00
if ( ! FieldsLoaded )
2017-05-23 04:55:05 +00:00
return ;
pkm . Nickname = TB_Nickname . Text ;
if ( CHK_Nicknamed . Checked )
return ;
2017-06-18 01:37:19 +00:00
int species = WinFormsUtil . GetIndex ( CB_Species ) ;
2017-05-23 04:55:05 +00:00
if ( species < 1 | | species > pkm . MaxSpeciesID )
return ;
if ( CHK_IsEgg . Checked )
species = 0 ; // get the egg name.
2017-06-18 01:37:19 +00:00
if ( PKX . IsNicknamedAnyLanguage ( species , TB_Nickname . Text , pkm . Format ) )
2017-05-23 04:55:05 +00:00
CHK_Nicknamed . Checked = true ;
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateNickname ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2017-06-17 01:56:17 +00:00
if ( sender = = Label_Species )
{
switch ( ModifierKeys )
{
case Keys . Control : RequestShowdownImport ? . Invoke ( sender , e ) ; return ;
case Keys . Alt : RequestShowdownExport ? . Invoke ( sender , e ) ; return ;
default :
return ;
}
}
2017-05-23 04:55:05 +00:00
2017-06-18 01:37:19 +00:00
int lang = WinFormsUtil . GetIndex ( CB_Language ) ;
2017-05-23 04:55:05 +00:00
2019-02-10 01:07:44 +00:00
if ( CHK_Nicknamed . Checked )
2017-05-23 04:55:05 +00:00
return ;
// Fetch Current Species and set it as Nickname Text
2017-06-18 01:37:19 +00:00
int species = WinFormsUtil . GetIndex ( CB_Species ) ;
2017-05-23 04:55:05 +00:00
if ( species < 1 | | species > pkm . MaxSpeciesID )
2018-09-03 01:02:25 +00:00
{ TB_Nickname . Text = string . Empty ; return ; }
2017-05-23 04:55:05 +00:00
if ( CHK_IsEgg . Checked )
species = 0 ; // get the egg name.
// If name is that of another language, don't replace the nickname
2017-06-18 01:37:19 +00:00
if ( sender ! = CB_Language & & species ! = 0 & & ! PKX . IsNicknamedAnyLanguage ( species , TB_Nickname . Text , pkm . Format ) )
2017-05-23 04:55:05 +00:00
return ;
2017-06-18 01:37:19 +00:00
TB_Nickname . Text = PKX . GetSpeciesNameGeneration ( species , lang , pkm . Format ) ;
2018-09-03 17:30:35 +00:00
if ( pkm is _K12 pk )
pk . SetNotNicknamed ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateNicknameClick ( object sender , MouseEventArgs e )
2017-05-23 04:55:05 +00:00
{
TextBox tb = sender as TextBox ? ? TB_Nickname ;
// Special Character Form
if ( ModifierKeys ! = Keys . Control )
return ;
var SAV = RequestSaveFile ;
if ( SAV = = null ) // form did not provide the needed info
return ;
if ( tb = = TB_Nickname )
{
pkm . Nickname = tb . Text ;
2017-06-18 01:37:19 +00:00
var d = new TrashEditor ( tb , pkm . Nickname_Trash , SAV ) ;
2017-05-23 04:55:05 +00:00
d . ShowDialog ( ) ;
tb . Text = d . FinalString ;
pkm . Nickname_Trash = d . FinalBytes ;
}
else if ( tb = = TB_OT )
{
pkm . OT_Name = tb . Text ;
2017-06-18 01:37:19 +00:00
var d = new TrashEditor ( tb , pkm . OT_Trash , SAV ) ;
2017-05-23 04:55:05 +00:00
d . ShowDialog ( ) ;
tb . Text = d . FinalString ;
pkm . OT_Trash = d . FinalBytes ;
}
else if ( tb = = TB_OTt2 )
{
pkm . HT_Name = tb . Text ;
2017-06-18 01:37:19 +00:00
var d = new TrashEditor ( tb , pkm . HT_Trash , SAV ) ;
2017-05-23 04:55:05 +00:00
d . ShowDialog ( ) ;
tb . Text = d . FinalString ;
pkm . HT_Trash = d . FinalBytes ;
}
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateNotOT ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
if ( string . IsNullOrWhiteSpace ( TB_OTt2 . Text ) )
{
2017-06-18 01:37:19 +00:00
ClickGT ( GB_OT , null ) ; // Switch CT over to OT.
2018-09-03 01:02:25 +00:00
Label_CTGender . Text = string . Empty ;
2017-05-23 04:55:05 +00:00
TB_Friendship . Text = pkm . CurrentFriendship . ToString ( ) ;
}
else if ( string . IsNullOrWhiteSpace ( Label_CTGender . Text ) )
2018-07-27 02:34:27 +00:00
{
2017-05-23 04:55:05 +00:00
Label_CTGender . Text = gendersymbols [ 0 ] ;
2018-07-27 02:34:27 +00:00
}
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateIsEgg ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
// Display hatch counter if it is an egg, Display Friendship if it is not.
Label_HatchCounter . Visible = CHK_IsEgg . Checked & & pkm . Format > 1 ;
Label_Friendship . Visible = ! CHK_IsEgg . Checked & & pkm . Format > 1 ;
2018-02-27 05:22:35 +00:00
if ( ! FieldsLoaded )
2017-05-23 04:55:05 +00:00
return ;
pkm . IsEgg = CHK_IsEgg . Checked ;
if ( CHK_IsEgg . Checked )
{
TB_Friendship . Text = "1" ;
// If we are an egg, it won't have a met location.
CHK_AsEgg . Checked = true ;
GB_EggConditions . Enabled = true ;
CAL_MetDate . Value = new DateTime ( 2000 , 01 , 01 ) ;
// if egg wasn't originally obtained by OT => Link Trade, else => None
bool isTraded = false ;
var SAV = SaveFileRequested ? . Invoke ( this , e ) ;
if ( SAV ! = null )
2018-04-28 16:34:54 +00:00
isTraded = SAV . OT ! = TB_OT . Text | | SAV . TID ! = pkm . TID | | SAV . SID ! = pkm . SID ;
2017-05-23 04:55:05 +00:00
CB_MetLocation . SelectedIndex = isTraded ? 2 : 0 ;
if ( ! CHK_Nicknamed . Checked )
{
2017-06-18 01:37:19 +00:00
TB_Nickname . Text = PKX . GetSpeciesNameGeneration ( 0 , WinFormsUtil . GetIndex ( CB_Language ) , pkm . Format ) ;
2017-06-21 05:57:22 +00:00
if ( pkm . Format ! = 4 ) // eggs in gen4 do not have nickname flag
CHK_Nicknamed . Checked = true ;
2017-05-23 04:55:05 +00:00
}
2017-08-06 03:30:33 +00:00
// Wipe egg memories
if ( pkm . Format > = 6 & & ModifyPKM )
2018-03-11 02:03:09 +00:00
pkm . ClearMemories ( ) ;
2017-05-23 04:55:05 +00:00
}
else // Not Egg
{
if ( ! CHK_Nicknamed . Checked )
2019-02-02 18:19:41 +00:00
UpdateNickname ( null , EventArgs . Empty ) ;
2017-05-23 04:55:05 +00:00
TB_Friendship . Text = pkm . PersonalInfo . BaseFriendship . ToString ( ) ;
if ( CB_EggLocation . SelectedIndex = = 0 )
{
CAL_EggDate . Value = new DateTime ( 2000 , 01 , 01 ) ;
CHK_AsEgg . Checked = false ;
GB_EggConditions . Enabled = false ;
}
2017-06-18 01:37:19 +00:00
if ( TB_Nickname . Text = = PKX . GetSpeciesNameGeneration ( 0 , WinFormsUtil . GetIndex ( CB_Language ) , pkm . Format ) )
2017-05-23 04:55:05 +00:00
CHK_Nicknamed . Checked = false ;
}
2019-02-02 18:19:41 +00:00
UpdateNickname ( null , EventArgs . Empty ) ;
2017-06-19 05:27:40 +00:00
UpdateSprite ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateMetAsEgg ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
GB_EggConditions . Enabled = CHK_AsEgg . Checked ;
if ( CHK_AsEgg . Checked )
{
2018-02-27 05:22:35 +00:00
if ( ! FieldsLoaded )
2017-05-23 04:55:05 +00:00
return ;
CAL_EggDate . Value = DateTime . Now ;
CB_EggLocation . SelectedIndex = 1 ;
return ;
}
// Remove egg met data
CHK_IsEgg . Checked = false ;
CAL_EggDate . Value = new DateTime ( 2000 , 01 , 01 ) ;
CB_EggLocation . SelectedValue = 0 ;
2017-06-18 01:37:19 +00:00
UpdateLegality ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateShinyPID ( object sender , EventArgs e )
2017-06-03 10:02:22 +00:00
{
var ShinyPID = pkm . Format < = 2 | | ModifierKeys ! = Keys . Control ;
2017-06-18 01:37:19 +00:00
UpdateShiny ( ShinyPID ) ;
2017-06-03 10:02:22 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateShiny ( bool PID )
2017-05-23 04:55:05 +00:00
{
2017-06-18 01:37:19 +00:00
pkm . PID = Util . GetHexValue ( TB_PID . Text ) ;
pkm . Nature = WinFormsUtil . GetIndex ( CB_Nature ) ;
2017-10-03 06:13:40 +00:00
pkm . Gender = PKX . GetGenderFromString ( Label_Gender . Text ) ;
2017-05-23 04:55:05 +00:00
pkm . AltForm = CB_Form . SelectedIndex ;
2017-06-18 01:37:19 +00:00
pkm . Version = WinFormsUtil . GetIndex ( CB_GameOrigin ) ;
2017-05-23 04:55:05 +00:00
if ( pkm . Format > 2 )
2018-05-12 15:13:39 +00:00
{
2017-06-03 15:58:30 +00:00
if ( PID )
2017-06-03 10:02:22 +00:00
{
2018-10-27 15:53:09 +00:00
pkm . SetShiny ( ) ;
2017-06-03 10:02:22 +00:00
TB_PID . Text = pkm . PID . ToString ( "X8" ) ;
if ( pkm . GenNumber < 6 & & TB_EC . Visible )
TB_EC . Text = TB_PID . Text ;
}
else
{
2017-06-18 01:37:19 +00:00
pkm . SetShinySID ( ) ;
2018-04-28 16:34:54 +00:00
TID_Trainer . UpdateSID ( ) ;
2017-06-03 10:02:22 +00:00
}
}
2017-05-23 04:55:05 +00:00
else
{
2018-10-27 15:53:09 +00:00
pkm . SetShiny ( ) ;
2018-02-27 05:22:35 +00:00
Stats . LoadIVs ( pkm . IVs ) ;
2019-02-02 18:19:41 +00:00
Stats . UpdateIVs ( null , EventArgs . Empty ) ;
2017-05-23 04:55:05 +00:00
}
2018-08-26 00:04:01 +00:00
UpdateIsShiny ( ) ;
2019-02-02 18:19:41 +00:00
UpdatePreviewSprite ? . Invoke ( this , EventArgs . Empty ) ;
2017-06-18 01:37:19 +00:00
UpdateLegality ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateTSV ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
if ( pkm . Format < 6 )
return ;
2018-04-28 16:34:54 +00:00
TID_Trainer . UpdateTSV ( ) ;
2017-05-23 04:55:05 +00:00
2017-06-18 01:37:19 +00:00
pkm . PID = Util . GetHexValue ( TB_PID . Text ) ;
2017-05-23 04:55:05 +00:00
Tip3 . SetToolTip ( TB_PID , $"PSV: {pkm.PSV:d4}" ) ;
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void Update_ID ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2018-08-26 00:04:01 +00:00
if ( ! FieldsLoaded )
return ;
2017-05-23 04:55:05 +00:00
// Trim out nonhex characters
2018-08-26 00:04:01 +00:00
TB_PID . Text = ( pkm . PID = Util . GetHexValue ( TB_PID . Text ) ) . ToString ( "X8" ) ;
TB_EC . Text = ( pkm . EncryptionConstant = Util . GetHexValue ( TB_EC . Text ) ) . ToString ( "X8" ) ;
2017-05-23 04:55:05 +00:00
2018-08-26 00:04:01 +00:00
UpdateIsShiny ( ) ;
2017-06-19 05:27:40 +00:00
UpdateSprite ( ) ;
2018-07-07 00:37:07 +00:00
Stats . UpdateCharacteristic ( ) ; // If the EC is changed, EC%6 (Characteristic) might be changed.
2018-08-26 00:04:01 +00:00
if ( pkm . Format < = 4 )
2017-05-23 04:55:05 +00:00
{
2018-02-27 05:22:35 +00:00
FieldsLoaded = false ;
2017-06-18 01:37:19 +00:00
pkm . PID = Util . GetHexValue ( TB_PID . Text ) ;
2017-05-23 04:55:05 +00:00
CB_Nature . SelectedValue = pkm . Nature ;
Label_Gender . Text = gendersymbols [ pkm . Gender ] ;
2019-02-09 21:15:37 +00:00
Label_Gender . ForeColor = Draw . GetGenderColor ( pkm . Gender ) ;
2018-02-27 05:22:35 +00:00
FieldsLoaded = true ;
2017-05-23 04:55:05 +00:00
}
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateShadowID ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2018-02-27 05:22:35 +00:00
if ( ! FieldsLoaded )
2017-05-23 04:55:05 +00:00
return ;
FLP_Purification . Visible = NUD_ShadowID . Value > 0 ;
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdatePurification ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2018-02-27 05:22:35 +00:00
if ( ! FieldsLoaded )
2017-05-23 04:55:05 +00:00
return ;
2018-02-27 05:22:35 +00:00
FieldsLoaded = false ;
2017-05-23 04:55:05 +00:00
CHK_Shadow . Checked = NUD_Purification . Value > 0 ;
2018-02-27 05:22:35 +00:00
FieldsLoaded = true ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void UpdateShadowCHK ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2018-02-27 05:22:35 +00:00
if ( ! FieldsLoaded )
2017-05-23 04:55:05 +00:00
return ;
2018-02-27 05:22:35 +00:00
FieldsLoaded = false ;
2017-05-23 04:55:05 +00:00
NUD_Purification . Value = CHK_Shadow . Checked ? NUD_Purification . Maximum : 0 ;
2018-10-21 04:05:15 +00:00
( ( IShadowPKM ) pkm ) . Purification = ( int ) NUD_Purification . Value ;
2019-02-02 18:19:41 +00:00
UpdatePreviewSprite ? . Invoke ( this , EventArgs . Empty ) ;
2018-02-27 05:22:35 +00:00
FieldsLoaded = true ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2019-02-15 08:50:23 +00:00
private void ValidateComboBox ( ComboBox cb )
2017-05-23 04:55:05 +00:00
{
2018-05-27 17:24:28 +00:00
if ( cb . Text . Length = = 0 & & cb . Items . Count > 0 )
cb . SelectedIndex = 0 ;
else if ( cb . SelectedValue = = null )
2019-02-09 21:15:37 +00:00
cb . BackColor = Draw . InvalidSelection ;
2017-05-23 04:55:05 +00:00
else
cb . ResetBackColor ( ) ;
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void ValidateComboBox ( object sender , CancelEventArgs e )
2017-05-23 04:55:05 +00:00
{
2019-02-15 08:50:23 +00:00
if ( ! ( sender is ComboBox cb ) )
2017-05-23 04:55:05 +00:00
return ;
2019-02-15 08:50:23 +00:00
ValidateComboBox ( cb ) ;
2017-06-19 05:27:40 +00:00
UpdateSprite ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void ValidateComboBox2 ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2019-02-10 01:07:44 +00:00
if ( ! FieldsLoaded )
2017-05-23 04:55:05 +00:00
return ;
2018-07-07 00:37:07 +00:00
2017-06-18 01:37:19 +00:00
ValidateComboBox ( sender , null ) ;
2018-07-07 00:37:07 +00:00
if ( sender = = CB_Ability )
2017-05-23 04:55:05 +00:00
{
2018-07-07 00:37:07 +00:00
if ( pkm . Format > = 6 )
2017-05-23 04:55:05 +00:00
TB_AbilityNumber . Text = ( 1 < < CB_Ability . SelectedIndex ) . ToString ( ) ;
2018-07-07 00:37:07 +00:00
else if ( pkm . Format < = 5 & & CB_Ability . SelectedIndex < 2 ) // Format <= 5, not hidden
2017-06-18 01:37:19 +00:00
UpdateRandomPID ( sender , e ) ;
2018-07-07 00:37:07 +00:00
UpdateLegality ( ) ;
}
else if ( sender = = CB_Nature )
{
if ( pkm . Format < = 4 )
2017-06-18 01:37:19 +00:00
UpdateRandomPID ( sender , e ) ;
2018-08-26 00:04:01 +00:00
pkm . Nature = WinFormsUtil . GetIndex ( CB_Nature ) ;
2018-07-07 00:37:07 +00:00
UpdateNatureModification ( sender , EventArgs . Empty ) ;
Stats . UpdateIVs ( null , EventArgs . Empty ) ; // updating Nature will trigger stats to update as well
UpdateLegality ( ) ;
}
else if ( sender = = CB_HeldItem )
{
UpdateLegality ( ) ;
2017-05-23 04:55:05 +00:00
}
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void ValidateMove ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2019-02-10 01:07:44 +00:00
if ( ! FieldsLoaded )
2017-05-23 04:55:05 +00:00
return ;
2019-02-15 08:50:23 +00:00
ValidateComboBox ( ( ComboBox ) sender ) ;
2018-03-11 02:03:09 +00:00
if ( Moves . Contains ( sender ) ) // Move
2017-06-18 01:37:19 +00:00
UpdatePP ( sender , e ) ;
2017-05-23 04:55:05 +00:00
// Legality
2018-03-11 02:03:09 +00:00
pkm . Moves = Moves . Select ( WinFormsUtil . GetIndex ) . ToArray ( ) ;
pkm . RelearnMoves = Relearn . Select ( WinFormsUtil . GetIndex ) . ToArray ( ) ;
2017-06-18 01:37:19 +00:00
UpdateLegality ( skipMoveRepop : true ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void ValidateMovePaint ( object sender , DrawItemEventArgs e )
2017-05-23 04:55:05 +00:00
{
2018-09-03 01:02:25 +00:00
if ( e . Index < 0 )
return ;
2017-05-23 04:55:05 +00:00
2017-08-13 07:21:42 +00:00
var i = ( ComboItem ) ( ( ComboBox ) sender ) . Items [ e . Index ] ;
2019-02-09 21:15:37 +00:00
var valid = AllowedMoves . Contains ( i . Value ) & & ! HaX ;
var current = ( e . State & DrawItemState . Selected ) = = DrawItemState . Selected ;
2019-02-10 02:44:21 +00:00
var rec = new Rectangle ( e . Bounds . X - 1 , e . Bounds . Y , e . Bounds . Width + 1 , e . Bounds . Height + 0 ) ; // 1px left
2019-02-09 21:15:37 +00:00
var brush = Draw . Brushes . GetBackground ( valid , current ) ;
2019-02-10 02:44:21 +00:00
e . Graphics . FillRectangle ( brush , rec ) ;
2017-05-23 04:55:05 +00:00
2019-02-10 02:44:21 +00:00
const TextFormatFlags flags = TextFormatFlags . Left | TextFormatFlags . EndEllipsis | TextFormatFlags . ExpandTabs | TextFormatFlags . SingleLine ;
TextRenderer . DrawText ( e . Graphics , i . Text , e . Font , rec , Draw . GetText ( current ) , flags ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2019-02-10 02:44:21 +00:00
private void MeasureDropDownHeight ( object sender , MeasureItemEventArgs e ) = > e . ItemHeight = CB_RelearnMove1 . ItemHeight ;
2018-08-02 04:57:15 +00:00
private readonly IList < bool > IsMoveBoxOrdered = new bool [ 4 ] ;
private void ValidateMoveDropDown ( object sender , EventArgs e )
{
var s = ( ComboBox ) sender ;
var index = Array . IndexOf ( Moves , s ) ;
if ( IsMoveBoxOrdered [ index ] )
return ;
SetMoveDataSource ( s ) ;
IsMoveBoxOrdered [ index ] = true ;
}
2017-06-18 01:37:19 +00:00
private void ValidateLocation ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
2018-02-27 05:22:35 +00:00
if ( ! FieldsLoaded )
2017-05-23 04:55:05 +00:00
return ;
2019-02-15 08:50:23 +00:00
ValidateComboBox ( ( ComboBox ) sender ) ;
2017-06-18 01:37:19 +00:00
pkm . Met_Location = WinFormsUtil . GetIndex ( CB_MetLocation ) ;
pkm . Egg_Location = WinFormsUtil . GetIndex ( CB_EggLocation ) ;
UpdateLegality ( ) ;
2017-05-23 04:55:05 +00:00
}
// Secondary Windows for Ribbons/Amie/Memories
2018-09-03 01:02:25 +00:00
private void OpenRibbons ( object sender , EventArgs e ) = > new RibbonEditor ( pkm ) . ShowDialog ( ) ;
private void OpenMedals ( object sender , EventArgs e ) = > new SuperTrainingEditor ( pkm ) . ShowDialog ( ) ;
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void OpenHistory ( object sender , EventArgs e )
2017-05-23 04:55:05 +00:00
{
// Write back current values
pkm . HT_Name = TB_OTt2 . Text ;
pkm . OT_Name = TB_OT . Text ;
pkm . IsEgg = CHK_IsEgg . Checked ;
pkm . CurrentFriendship = Util . ToInt32 ( TB_Friendship . Text ) ;
new MemoryAmie ( pkm ) . ShowDialog ( ) ;
TB_Friendship . Text = pkm . CurrentFriendship . ToString ( ) ;
}
/// <summary>
/// Refreshes the interface for the current PKM format.
/// </summary>
2018-05-12 19:28:48 +00:00
/// <param name="sav">Save File context the editor is editing for</param>
/// <param name="pk">Pokémon data to edit</param>
2017-06-19 05:27:40 +00:00
public bool ToggleInterface ( SaveFile sav , PKM pk )
2017-05-23 04:55:05 +00:00
{
2019-02-15 08:50:23 +00:00
pkm = sav . GetCompatiblePKM ( pk ) ;
2018-07-07 00:37:07 +00:00
ToggleInterface ( pkm ) ;
2017-06-21 00:57:23 +00:00
return FinalizeInterface ( sav ) ;
}
2018-07-27 02:34:27 +00:00
2018-07-07 00:37:07 +00:00
private void ToggleInterface ( PKM t )
2017-06-21 00:57:23 +00:00
{
2018-07-07 00:37:07 +00:00
FLP_Purification . Visible = FLP_ShadowID . Visible = t is IShadowPKM ;
2018-12-05 02:38:47 +00:00
FLP_SizeCP . Visible = PB_Favorite . Visible = t is PB7 ;
2018-12-28 04:01:29 +00:00
BTN_Medals . Visible = BTN_History . Visible = t . Format > = 6 & & ! ( t is PB7 ) ;
BTN_Ribbons . Visible = t . Format > = 3 & & ! ( t is PB7 ) ;
2018-07-07 00:37:07 +00:00
ToggleInterface ( pkm . Format ) ;
2017-06-21 00:57:23 +00:00
}
2018-07-27 02:34:27 +00:00
2018-08-20 01:22:07 +00:00
private void ToggleSecrets ( bool hidden , int gen )
{
Label_EncryptionConstant . Visible = BTN_RerollEC . Visible = TB_EC . Visible = gen > = 6 & & ! hidden ;
BTN_RerollPID . Visible = Label_PID . Visible = TB_PID . Visible = gen > = 3 & & ! hidden ;
}
2017-06-21 00:57:23 +00:00
private void ToggleInterface ( int gen )
{
2018-08-20 01:22:07 +00:00
ToggleSecrets ( HideSecretValues , gen ) ;
2017-06-21 00:57:23 +00:00
FLP_Country . Visible = FLP_SubRegion . Visible = FLP_3DSRegion . Visible = gen > = 6 ;
2018-12-28 04:01:29 +00:00
GB_nOT . Visible = GB_RelearnMoves . Visible = gen > = 6 ;
2017-05-23 04:55:05 +00:00
2017-06-21 00:57:23 +00:00
PB_MarkPentagon . Visible = gen > = 6 ;
2019-01-05 23:40:25 +00:00
PB_MarkAlola . Visible = PB_MarkVC . Visible = PB_MarkGO . Visible = gen > = 7 ;
2017-05-23 04:55:05 +00:00
2017-06-21 00:57:23 +00:00
FLP_NSparkle . Visible = L_NSparkle . Visible = CHK_NSparkle . Visible = gen = = 5 ;
2017-05-23 04:55:05 +00:00
2017-06-21 00:57:23 +00:00
CB_Form . Visible = Label_Form . Visible = CHK_AsEgg . Visible = GB_EggConditions . Visible = PB_Mark5 . Visible = PB_Mark6 . Visible = gen > = 4 ;
FLP_ShinyLeaf . Visible = L_ShinyLeaf . Visible = ShinyLeaf . Visible = gen = = 4 ;
2017-05-23 04:55:05 +00:00
2017-06-21 00:57:23 +00:00
DEV_Ability . Enabled = DEV_Ability . Visible = gen > 3 & & HaX ;
CB_Ability . Visible = ! DEV_Ability . Enabled & & gen > = 3 ;
FLP_Nature . Visible = gen > = 3 ;
FLP_Ability . Visible = gen > = 3 ;
GB_ExtraBytes . Visible = GB_ExtraBytes . Enabled = gen > = 3 ;
GB_Markings . Visible = gen > = 3 ;
2018-02-27 05:22:35 +00:00
CB_Form . Enabled = gen > = 3 ;
2017-05-23 04:55:05 +00:00
2017-06-21 00:57:23 +00:00
FLP_FriendshipForm . Visible = gen > = 2 ;
FLP_HeldItem . Visible = gen > = 2 ;
2017-09-06 16:12:56 +00:00
CHK_IsEgg . Visible = gen > = 2 ;
2017-06-21 00:57:23 +00:00
FLP_PKRS . Visible = FLP_EggPKRSRight . Visible = gen > = 2 ;
Label_OTGender . Visible = gen > = 2 ;
2018-09-30 17:16:45 +00:00
FLP_CatchRate . Visible = gen = = 1 ;
2017-05-23 04:55:05 +00:00
// HaX override, needs to be after DEV_Ability enabled assignment.
2017-06-21 00:57:23 +00:00
TB_AbilityNumber . Visible = gen > = 6 & & DEV_Ability . Enabled ;
2017-05-23 04:55:05 +00:00
// Met Tab
2017-06-21 00:57:23 +00:00
FLP_MetDate . Visible = gen > = 4 ;
FLP_Fateful . Visible = FLP_Ball . Visible = FLP_OriginGame . Visible = gen > = 3 ;
FLP_MetLocation . Visible = FLP_MetLevel . Visible = gen > = 2 ;
2017-10-21 02:53:38 +00:00
FLP_EncounterType . Visible = gen > = 4 & & gen < = 6 ;
2017-06-21 00:57:23 +00:00
FLP_TimeOfDay . Visible = gen = = 2 ;
2018-05-12 15:13:39 +00:00
2018-06-03 05:04:32 +00:00
Contest . ToggleInterface ( pkm , gen ) ;
2018-11-14 03:25:03 +00:00
Stats . ToggleInterface ( pkm , gen ) ;
2017-05-23 04:55:05 +00:00
2017-06-19 05:27:40 +00:00
CenterSubEditors ( ) ;
}
2018-07-27 02:34:27 +00:00
2017-06-21 00:57:23 +00:00
private bool FinalizeInterface ( SaveFile sav )
2017-05-23 04:55:05 +00:00
{
2019-02-10 01:07:44 +00:00
FieldsLoaded = false ;
2017-06-19 05:27:40 +00:00
2017-05-23 04:55:05 +00:00
bool TranslationRequired = false ;
2017-06-21 00:57:23 +00:00
PopulateFilteredDataSources ( sav ) ;
2017-06-18 01:37:19 +00:00
PopulateFields ( pkm ) ;
2017-05-23 04:55:05 +00:00
// SAV Specific Limits
TB_OT . MaxLength = pkm . OTLength ;
TB_OTt2 . MaxLength = pkm . OTLength ;
TB_Nickname . MaxLength = pkm . NickLength ;
// Hide Unused Tabs
if ( pkm . Format = = 1 & & tabMain . TabPages . Contains ( Tab_Met ) )
2018-07-27 02:34:27 +00:00
{
2017-05-23 04:55:05 +00:00
tabMain . TabPages . Remove ( Tab_Met ) ;
2018-07-27 02:34:27 +00:00
}
2017-05-23 04:55:05 +00:00
else if ( pkm . Format ! = 1 & & ! tabMain . TabPages . Contains ( Tab_Met ) )
{
tabMain . TabPages . Insert ( 1 , Tab_Met ) ;
TranslationRequired = true ;
}
2018-11-14 03:25:03 +00:00
if ( ! HaX & & sav is SAV7b )
{
FLP_HeldItem . Visible = false ;
FLP_Country . Visible = false ;
FLP_SubRegion . Visible = false ;
FLP_3DSRegion . Visible = false ;
}
2017-05-23 04:55:05 +00:00
// Common HaX Interface
2018-02-27 05:22:35 +00:00
MT_Level . Enabled = MT_Level . Visible = MT_Form . Enabled = MT_Form . Visible = HaX ;
2017-05-23 04:55:05 +00:00
TB_Level . Visible = ! HaX ;
// pk2 save files do not have an Origin Game stored. Prompt the met location list to update.
if ( pkm . Format = = 2 )
2019-02-02 18:19:41 +00:00
UpdateOriginGame ( null , EventArgs . Empty ) ;
2017-05-23 04:55:05 +00:00
return TranslationRequired ;
}
2018-07-27 02:34:27 +00:00
2017-06-19 05:27:40 +00:00
private void CenterSubEditors ( )
2017-05-23 04:55:05 +00:00
{
// Recenter PKM SubEditors
2018-08-20 01:22:07 +00:00
FLP_PKMEditors . Location = new Point ( ( tabMain . TabPages [ 0 ] . Width - FLP_PKMEditors . Width ) / 2 , FLP_PKMEditors . Location . Y ) ;
2017-05-23 04:55:05 +00:00
}
2018-05-12 15:13:39 +00:00
2017-05-23 04:55:05 +00:00
// Loading Setup
2018-12-20 06:10:32 +00:00
public void TemplateFields ( ITrainerInfo info )
2017-05-23 04:55:05 +00:00
{
2017-05-23 15:28:53 +00:00
if ( CB_GameOrigin . Items . Count > 0 )
CB_GameOrigin . SelectedIndex = 0 ;
2017-05-23 04:55:05 +00:00
CB_Move1 . SelectedValue = 1 ;
2018-03-29 01:52:50 +00:00
SetDetailsOT ( info ) ;
2017-05-23 04:55:05 +00:00
CB_Ball . SelectedIndex = Math . Min ( 0 , CB_Ball . Items . Count - 1 ) ;
CAL_MetDate . Value = CAL_EggDate . Value = DateTime . Today ;
2018-11-03 02:33:30 +00:00
CB_Species . SelectedValue = RequestSaveFile ? . MaxSpeciesID ? ? pkm . MaxSpeciesID ;
2017-05-23 04:55:05 +00:00
CHK_Nicknamed . Checked = false ;
2017-06-19 05:27:40 +00:00
LastData = null ;
2019-01-05 06:46:52 +00:00
UpdateSprite ( ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-05-23 04:55:05 +00:00
public void EnableDragDrop ( DragEventHandler enter , DragEventHandler drop )
{
AllowDrop = true ;
DragDrop + = drop ;
foreach ( TabPage tab in tabMain . TabPages )
{
tab . AllowDrop = true ;
tab . DragEnter + = enter ;
tab . DragDrop + = drop ;
}
}
2017-12-22 06:55:33 +00:00
// ReSharper disable once FieldCanBeMadeReadOnly.Global
public Action < ShowdownSet > LoadShowdownSet ;
2018-07-27 02:34:27 +00:00
2017-12-22 06:55:33 +00:00
private void LoadShowdownSetDefault ( ShowdownSet Set )
2017-05-23 04:55:05 +00:00
{
2018-03-11 02:03:09 +00:00
var pk = PreparePKM ( ) ;
pk . ApplySetDetails ( Set ) ;
PopulateFields ( pk ) ;
2017-05-23 04:55:05 +00:00
}
2018-02-27 05:22:35 +00:00
2017-06-19 05:27:40 +00:00
public void ChangeLanguage ( SaveFile sav , PKM pk )
{
// Force an update to the met locations
2018-03-12 01:07:48 +00:00
origintrack = GameVersion . Invalid ;
2017-06-19 05:27:40 +00:00
InitializeLanguage ( sav ) ;
CenterSubEditors ( ) ;
PopulateFields ( pk ) ; // put data back in form
}
2018-07-27 02:34:27 +00:00
2017-06-19 05:27:40 +00:00
public void FlickerInterface ( )
{
tabMain . SelectedTab = Tab_Met ; // parent tab of CB_GameOrigin
tabMain . SelectedTab = Tab_Main ; // first tab
}
private void InitializeLanguage ( SaveFile SAV )
2017-05-23 04:55:05 +00:00
{
// Set the various ComboBox DataSources up with their allowed entries
2017-06-18 01:37:19 +00:00
SetCountrySubRegion ( CB_Country , "countries" ) ;
CB_3DSReg . DataSource = Util . GetUnsortedCBList ( "regions3ds" ) ;
2017-05-23 04:55:05 +00:00
2018-08-26 00:04:01 +00:00
CB_EncounterType . DataSource = new BindingSource ( GameInfo . EncounterTypeDataSource , null ) ;
2017-05-23 04:55:05 +00:00
CB_Nature . DataSource = new BindingSource ( GameInfo . NatureDataSource , null ) ;
2018-02-27 05:22:35 +00:00
// Sub editors
Stats . InitializeDataSources ( ) ;
2017-06-18 01:37:19 +00:00
PopulateFilteredDataSources ( SAV ) ;
2017-05-23 04:55:05 +00:00
}
2018-07-27 02:34:27 +00:00
2017-06-18 01:37:19 +00:00
private void PopulateFilteredDataSources ( SaveFile SAV )
2017-05-23 04:55:05 +00:00
{
2018-05-19 04:35:57 +00:00
GameInfo . Strings . SetItemDataSource ( SAV . Version , SAV . Generation , SAV . MaxItemID , SAV . HeldItems , HaX ) ;
2017-10-25 04:06:21 +00:00
if ( SAV . Generation > 1 )
CB_HeldItem . DataSource = new BindingSource ( GameInfo . ItemDataSource . Where ( i = > i . Value < = SAV . MaxItemID ) . ToList ( ) , null ) ;
2017-05-23 04:55:05 +00:00
2018-07-07 00:37:07 +00:00
CB_Language . DataSource = GameInfo . LanguageDataSource ( SAV . Generation ) ;
2017-05-23 04:55:05 +00:00
2017-10-25 04:06:21 +00:00
CB_Ball . DataSource = new BindingSource ( GameInfo . BallDataSource . Where ( b = > b . Value < = SAV . MaxBallID ) . ToList ( ) , null ) ;
CB_Species . DataSource = new BindingSource ( GameInfo . SpeciesDataSource . Where ( s = > s . Value < = SAV . MaxSpeciesID ) . ToList ( ) , null ) ;
DEV_Ability . DataSource = new BindingSource ( GameInfo . AbilityDataSource . Where ( a = > a . Value < = SAV . MaxAbilityID ) . ToList ( ) , null ) ;
2018-06-15 23:00:28 +00:00
var gamelist = GameUtil . GetVersionsWithinRange ( SAV , SAV . Generation ) . ToList ( ) ;
CB_GameOrigin . DataSource = new BindingSource ( GameInfo . VersionDataSource . Where ( g = > gamelist . Contains ( ( GameVersion ) g . Value ) ) . ToList ( ) , null ) ;
2017-05-23 04:55:05 +00:00
// Set the Move ComboBoxes too..
2018-09-14 05:10:35 +00:00
MoveDataAllowed = GameInfo . Strings . MoveDataSource = ( HaX ? GameInfo . HaXMoveDataSource : GameInfo . LegalMoveDataSource ) . Where ( m = > m . Value < = SAV . MaxMoveID ) . ToList ( ) ; // Filter Z-Moves if appropriate
2018-03-11 02:03:09 +00:00
foreach ( var cb in Moves . Concat ( Relearn ) )
2017-05-23 04:55:05 +00:00
{
cb . DataSource = new BindingSource ( GameInfo . MoveDataSource , null ) ;
}
}
2018-02-27 05:22:35 +00:00
2018-03-11 02:03:09 +00:00
private static List < string > GetSuggestionMessage ( PKM pkm , int level , int location , int minlvl )
2018-02-27 05:22:35 +00:00
{
2018-04-06 04:25:18 +00:00
var suggestion = new List < string > { MsgPKMSuggestionStart } ;
2018-03-11 02:03:09 +00:00
if ( pkm . Format > = 3 )
2018-02-27 05:22:35 +00:00
{
2018-03-11 02:03:09 +00:00
var met_list = GameInfo . GetLocationList ( ( GameVersion ) pkm . Version , pkm . Format , egg : false ) ;
2018-06-30 16:59:48 +00:00
var locstr = met_list . First ( loc = > loc . Value = = location ) . Text ;
2018-04-06 04:25:18 +00:00
suggestion . Add ( $"{MsgPKMSuggestionMetLocation} {locstr}" ) ;
suggestion . Add ( $"{MsgPKMSuggestionMetLevel} {level}" ) ;
2018-02-27 05:22:35 +00:00
}
2018-03-11 02:03:09 +00:00
if ( pkm . CurrentLevel < minlvl )
2018-04-06 04:25:18 +00:00
suggestion . Add ( $"{MsgPKMSuggestionLevel} {minlvl}" ) ;
2018-03-11 02:03:09 +00:00
return suggestion ;
2018-02-27 05:22:35 +00:00
}
2018-07-27 02:34:27 +00:00
2018-07-07 00:37:07 +00:00
private static IReadOnlyList < ComboItem > GetAbilityList ( PKM pkm )
{
var abils = pkm . PersonalInfo . Abilities ;
2018-09-03 01:02:25 +00:00
return GameInfo . GetAbilityList ( abils , pkm . Format ) ;
2018-07-07 00:37:07 +00:00
}
2017-05-23 04:55:05 +00:00
}
}