Example #1
0
void CPHackSettings::SavePHackData(wxCommandEvent& event)
{
	PHack_Data.PHackSZNear = PHackSZNear->GetValue();
	PHack_Data.PHackSZFar = PHackSZFar->GetValue();

	PHack_Data.PHZNear = PHackZNear->GetValue().char_str();
	PHack_Data.PHZFar = PHackZFar->GetValue().char_str();

	AcceptAndClose();
	event.Skip();
}
Example #2
0
void CPatchAddEdit::SavePatchData(wxCommandEvent& event)
{
	if (!UpdateTempEntryData(itCurEntry))
		return;

	if (selection == -1)
	{
		PatchEngine::Patch newPatch;
		newPatch.name = WxStrToStr(EditPatchName->GetValue());
		newPatch.entries = tempEntries;
		newPatch.active = true;

		onFrame->push_back(newPatch);
	}
	else
	{
		onFrame->at(selection).name = WxStrToStr(EditPatchName->GetValue());
		onFrame->at(selection).entries = tempEntries;
	}

	AcceptAndClose();
	event.Skip();
}
Example #3
0
void wxDialogBase::OnButton(wxCommandEvent& event)
{
    const int id = event.GetId();
    if ( id == GetAffirmativeId() )
    {
        AcceptAndClose();
    }
    else if ( id == wxID_APPLY )
    {
        if ( Validate() )
            TransferDataFromWindow();

        // TODO: disable the Apply button until things change again
    }
    else if ( id == GetEscapeId() ||
                (id == wxID_CANCEL && GetEscapeId() == wxID_ANY) )
    {
        EndDialog(wxID_CANCEL);
    }
    else // not a standard button
    {
        event.Skip();
    }
}
Example #4
0
void CARCodeAddEdit::SaveCheatData(wxCommandEvent& WXUNUSED (event))
{
	std::vector<ActionReplay::AREntry> decryptedLines;
	std::vector<std::string> encryptedLines;

	// Split the entered cheat into lines.
	std::vector<std::string> userInputLines;
	SplitString(WxStrToStr(EditCheatCode->GetValue()), '\n', userInputLines);

	for (size_t i = 0;  i < userInputLines.size();  i++)
	{
		// Make sure to ignore unneeded whitespace characters.
		std::string line_str = StripSpaces(userInputLines[i]);

		if (line_str == "")
			continue;

		// Let's parse the current line.  Is it in encrypted or decrypted form?
		std::vector<std::string> pieces;
		SplitString(line_str, ' ', pieces);

		if (pieces.size() == 2 && pieces[0].size() == 8 && pieces[1].size() == 8)
		{
			// Decrypted code line.
			u32 addr = std::stoul(pieces[0], nullptr, 16);
			u32 value = std::stoul(pieces[1], nullptr, 16);

			decryptedLines.push_back(ActionReplay::AREntry(addr, value));
			continue;
		}
		else if (pieces.size() == 1)
		{
			SplitString(line_str, '-', pieces);

			if (pieces.size() == 3 && pieces[0].size() == 4 && pieces[1].size() == 4 && pieces[2].size() == 5)
			{
				// Encrypted code line.  We'll have to decode it later.
				encryptedLines.push_back(pieces[0] + pieces[1] + pieces[2]);
				continue;
			}
		}

		// If the above-mentioned conditions weren't met, then something went wrong.
		if (!PanicYesNoT("Unable to parse line %u of the entered AR code as a valid "
						"encrypted or decrypted code.  Make sure you typed it correctly.\n"
						"Would you like to ignore this line and continue parsing?", (unsigned) (i + 1)))
		{
			return;
		}
	}

	// If the entered code was in encrypted form, we decode it here.
	if (encryptedLines.size())
	{
		// TODO: what if both decrypted AND encrypted lines are entered into a single AR code?
		ActionReplay::DecryptARCode(encryptedLines, decryptedLines);
	}

	// Codes with no lines appear to be deleted/hidden from the list.  Let's prevent that.
	if (!decryptedLines.size())
	{
		PanicAlertT("The resulting decrypted AR code doesn't contain any lines.");
		return;
	}


	if (selection == wxNOT_FOUND)
	{
		// Add a new AR cheat code.
		ActionReplay::ARCode newCheat;

		newCheat.name = WxStrToStr(EditCheatName->GetValue());
		newCheat.ops = decryptedLines;
		newCheat.active = true;

		arCodes.push_back(newCheat);
	}
	else
	{
		// Update the currently-selected AR cheat code.
		arCodes.at(selection).name = WxStrToStr(EditCheatName->GetValue());
		arCodes.at(selection).ops = decryptedLines;
	}

	AcceptAndClose();
}
// wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
void GameDetailsDialog::OnOkClick( wxCommandEvent& WXUNUSED(event) )
{
    // Validate date
    wxString temp = date_ctrl->GetValue();
    temp.Trim(true);
    temp.Trim(false);
    const char *s = temp.c_str();
    bool ok=false;
    wxString err_msg = "Illegal date: valid format is yyyy.mm.dd, eg 1999.12.31";
    if( temp=="?" || strlen(s)==0 )
        ok = true;
    else if( strlen(s) == 4 )
    {
        int yyyy = atoi(&s[0]);
        bool yyyy_unknown = (s[0]=='?' && s[1]=='?' && s[2]=='?' && s[3]=='?');
        ok = yyyy_unknown || (1000<=yyyy && yyyy<=2999);
    }
    else if( 8<=strlen(s) && strlen(s)<=10 )
    {
        if( s[4]=='.' )
        {
            ok = true;
            int dd_offset = 8;
            if( s[6]=='.' && s[7]!='.' && strlen(s)<10 )
                dd_offset = 7;  // yyyy.m.d or yyyy.m.dd (len=8 or 9)
            else if( s[6]!='.' && s[7]=='.' && strlen(s)>8 )
                dd_offset = 8;  // yyyy.mm.d or yyyy.mm.dd (len=9 or 10)
            else
                ok = false;
            if( ok )
            {
                int yyyy = atoi(&s[0]);
                int mm   = atoi(&s[5]);
                int dd   = atoi(&s[dd_offset]);
                bool yyyy_unknown = (s[0]=='?' && s[1]=='?' && s[2]=='?' && s[3]=='?');
                bool mm_unknown   = (s[5]=='?' && (s[6]=='?'||s[6]=='.') );
                bool dd_unknown   = (s[dd_offset]=='?' && (s[dd_offset+1]=='?'||s[dd_offset+1]=='\0') );
                bool yyyy_ok = yyyy_unknown || (1000<=yyyy && yyyy<=2999);
                bool mm_ok   = mm_unknown   || (1<=mm && mm<=12);
                bool dd_ok   = dd_unknown   || (1<=dd && dd<=31);
                ok = (yyyy_ok && mm_ok && dd_ok);
                if( ok )
                {
                    if( mm == 2 )
                    {
                        bool leap=false;
                        if( yyyy%400 == 0 )
                            leap = true;            //  eg 1600,2000,2400 are leap (also yyyy_unknown as then yyyy==0)
                        else if( yyyy%100 == 0 )
                            leap = false;           //  eg 1700,1800,1900,2100 aren't leap
                        else if( yyyy%4 == 0 )
                            leap = true;            //  eg 1996,2004,2008,2012 are leap
                        ok = (dd <= (leap?29:28));  //  (also dd_unknown is okay as then dd==0)
                    }
                    else if( mm==4 || mm==6 || mm==9 || mm==11 )
                    {
                        ok = dd<=30;  // (also dd_unknown is okay as then dd==0)
                    }
                    if( !ok )
                        err_msg = "Illegal date: there aren't that many days in that month";
                }
            }
        }
    }

    // Validate round
    if( ok )
    {
        temp = round_ctrl->GetValue();
        temp.Trim(true);
        temp.Trim(false);
        if( temp!="?" && temp!='-' )  // both of these explicitly allowed
        {
            s = temp.c_str();
            if( *s )
            {
                int r = atoi(s);
                if( r <= 0 )
                    ok = false;
                while( ok && *s )
                {  // allow digits and '.' characters, '.' must be followed by a digit
                    if( *s!='.' && !isdigit(*s) )
                        ok = false;
                    if( *s=='.' && !isdigit(*(s+1)) )
                        ok = false;
                    s++;
                }
                if( !ok )
                    err_msg = "Illegal round";
            }
        }
    }
/*
    // Validate board number
    if( ok )
    {
        temp = board_nbr_ctrl->GetValue();
        temp.Trim(true);
        temp.Trim(false);
        s = temp.c_str();
        if( temp!="?" && *s )
        {
            int r = atoi(s);
            if( r <= 0 )
            {
                ok = false;
                err_msg = "Illegal board number";
            }
        }
    }
  */
    // Validate result

    // Validate ECO
    if( ok )
    {
        temp = eco_ctrl->GetValue();
        temp.Trim(true);
        temp.Trim(false);
        if( temp != "?" )
        {
            s = temp.c_str();
            ok = (strlen(s)==0);
            // Allow "" (empty) or "A00" (alpha,digit,digit)
            // But also allow say "A000" or "AA00" (possible future formats?)
            if( 3<=strlen(s) && strlen(s)<=4 )
            {
                ok = true;
                for( int i=0; ok && *s; i++ )
                {
                    if( i==0 )
                        ok = (bool)isalpha(*s);
                    else if( i==1 )
                    {
                        if( strlen(s) == 4 )
                            ok = (bool)(isalpha(*s) || isdigit(*s));
                        else  // if( strlen(s) == 3 )
                            ok = (bool)isdigit(*s);
                    }
                    else
                        ok = (bool)isdigit(*s);
                    s++;
                }           
            }
            if( !ok )
                err_msg = "Illegal ECO code";
        }
    }

    // Validate white elo
    if( ok )
    {
        temp = white_elo_ctrl->GetValue();
        temp.Trim(true);
        temp.Trim(false);
        s = temp.c_str();
        if( temp!="?" && *s )
        {
            int r = atoi(s);
            if( r<=0 || r>10000 )
            {
                ok = false;
                err_msg = "Illegal white elo";
            }
        }
    }


    // Validate black elo
    if( ok )
    {
        temp = black_elo_ctrl->GetValue();
        temp.Trim(true);
        temp.Trim(false);
        s = temp.c_str();
        if( temp!="?" && *s )
        {
            int r = atoi(s);
            if( r<=0 || r>10000 )
            {
                ok = false;
                err_msg = "Illegal black elo";
            }
        }
    }
    if( ok )
        AcceptAndClose();
    else
        wxMessageBox( err_msg, "Error in game details", wxOK|wxICON_ERROR );
}
// wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
void GamePrefixDialog::OnOkClick( wxCommandEvent& WXUNUSED(event) )
{
    AcceptAndClose();
}