Skip to content
This repository has been archived by the owner on Sep 8, 2019. It is now read-only.

Commit

Permalink
Copy & Paste Achievement Conditions. (#31)
Browse files Browse the repository at this point in the history
* Reworked memory caret to move freely and wrap.

* Added mouse wheel scroll to mem viewer.

* Increased range of pg up/down keys on mem viewer.

* Copy & Paste feature for achievement conditions.
replaced Clone Selected.
  • Loading branch information
GameDragon2k committed Dec 1, 2017
1 parent 7dce8f3 commit 4676e7e
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 77 deletions.
78 changes: 54 additions & 24 deletions RA_Integration/RA_Dlg_AchEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,16 +857,21 @@ INT_PTR Dlg_AchievementEditor::AchievementEditorProc( HWND hDlg, UINT uMsg, WPAR
SetWindowPos(hItem, NULL, nBtnMainXOffset, (winRect.bottom - winRect.top) + nBtnMainYOffset,
NULL, NULL, SWP_NOSIZE | SWP_NOZORDER);

hItem = GetDlgItem(hDlg, IDC_RA_CLONECOND);
hItem = GetDlgItem(hDlg, IDC_RA_DELETECOND);
GetWindowRect(hItem, &itemRect);
SetWindowPos(hItem, NULL, nBtnMainXOffset + 78, (winRect.bottom - winRect.top) + nBtnMainYOffset,
NULL, NULL, SWP_NOSIZE | SWP_NOZORDER);

hItem = GetDlgItem(hDlg, IDC_RA_DELETECOND);
hItem = GetDlgItem(hDlg, IDC_RA_COPYCOND);
GetWindowRect(hItem, &itemRect);
SetWindowPos(hItem, NULL, nBtnMainXOffset + 156, (winRect.bottom - winRect.top) + nBtnMainYOffset,
NULL, NULL, SWP_NOSIZE | SWP_NOZORDER);

hItem = GetDlgItem(hDlg, IDC_RA_PASTECOND);
GetWindowRect(hItem, &itemRect);
SetWindowPos(hItem, NULL, nBtnMainXOffset + 156, (winRect.bottom - winRect.top) + nBtnMainYOffset + 20,
NULL, NULL, SWP_NOSIZE | SWP_NOZORDER);

hItem = GetDlgItem(hDlg, IDC_RA_CHK_SHOW_DECIMALS);
GetWindowRect(hItem, &itemRect);
SetWindowPos(hItem, NULL, (winRect.right - winRect.left) + nChkXOffset, (winRect.bottom - winRect.top) + nChkYOffset,
Expand All @@ -876,6 +881,8 @@ INT_PTR Dlg_AchievementEditor::AchievementEditorProc( HWND hDlg, UINT uMsg, WPAR
GetWindowRect(hItem, &itemRect);
SetWindowPos(hItem, NULL, (winRect.right - winRect.left) + nBtnCloseXOffset, (winRect.bottom - winRect.top) + nBtnCloseYOffset,
NULL, NULL, SWP_NOSIZE | SWP_NOZORDER);

InvalidateRect(m_hAchievementEditorDlg, NULL, TRUE);
}
break;

Expand Down Expand Up @@ -1089,37 +1096,60 @@ INT_PTR Dlg_AchievementEditor::AchievementEditorProc( HWND hDlg, UINT uMsg, WPAR
ListView_EnsureVisible( hList, nNewID, FALSE );
}
break;
case IDC_RA_CLONECOND:
case IDC_RA_COPYCOND:
{
HWND hList = GetDlgItem( hDlg, IDC_RA_LBX_CONDITIONS );
int nSel = ListView_GetNextItem( hList, -1, LVNI_SELECTED );
Achievement* pActiveAch = ActiveAchievement();
if( pActiveAch != NULL )
{
if( nSel == -1 || nSel > static_cast<int>( pActiveAch->NumConditions( GetSelectedConditionGroup() ) ) )
return FALSE;
unsigned int uSelectedCount = ListView_GetSelectedCount( hList );

if (uSelectedCount > 0)
{
m_ConditionClipboard.Clear();

Condition& CondToClone = pActiveAch->GetCondition( GetSelectedConditionGroup(), static_cast<size_t>( nSel ) );
for (int i = ListView_GetNextItem(hList, -1, LVNI_SELECTED); i >= 0; i = ListView_GetNextItem(hList, i, LVNI_SELECTED))
{
Condition& CondToCopy = pActiveAch->GetCondition(GetSelectedConditionGroup(), static_cast<size_t>( i ) );

Condition NewCondition;
NewCondition.Set( CondToClone );
Condition NewCondition;
NewCondition.Set( CondToCopy );

const size_t nNewID = pActiveAch->AddCondition( GetSelectedConditionGroup(), NewCondition ) - 1;
m_ConditionClipboard.Add( NewCondition );
}

// Disable all achievement tracking:
//g_pActiveAchievements->SetPaused( true );
//CheckDlgButton( HWndAchievementsDlg, IDC_RA_CHKACHPROCESSINGACTIVE, FALSE );
m_ConditionClipboard.Count();
}
else
return FALSE;
}
}
break;
case IDC_RA_PASTECOND:
{
HWND hList = GetDlgItem(hDlg, IDC_RA_LBX_CONDITIONS);
Achievement* pActiveAch = ActiveAchievement();

// Update this achievement entry as 'modified':
pActiveAch->SetModified( TRUE );
g_AchievementsDialog.OnEditAchievement( *pActiveAch );
if ( pActiveAch != NULL )
{
if (m_ConditionClipboard.Count() > 0)
{
for (int i = 0; i < m_ConditionClipboard.Count(); i++)
{
const size_t nNewID = pActiveAch->AddCondition( GetSelectedConditionGroup(), m_ConditionClipboard.GetAt(i) ) - 1;
ListView_SetItemState(hList, nNewID, LVIS_FOCUSED | LVIS_SELECTED, -1);
ListView_EnsureVisible(hList, nNewID, FALSE);
}

LoadAchievement( pActiveAch, FALSE );
pActiveAch->ClearDirtyFlag();
// Update this achievement entry as 'modified':
pActiveAch->SetModified(TRUE);
g_AchievementsDialog.OnEditAchievement(*pActiveAch);

// Select last item
ListView_SetItemState( hList, nNewID, LVIS_FOCUSED|LVIS_SELECTED, -1 );
ListView_EnsureVisible( hList, nNewID, FALSE );
LoadAchievement(pActiveAch, FALSE);
pActiveAch->ClearDirtyFlag();
}
else
return FALSE;
}
}
break;
Expand Down Expand Up @@ -1666,7 +1696,7 @@ void Dlg_AchievementEditor::LoadAchievement( Achievement* pCheevo, BOOL bAttempt
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_ACH_DESC ), FALSE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_ACH_POINTS ), FALSE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_ADDCOND ), FALSE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_CLONECOND ), FALSE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_COPYCOND ), FALSE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_DELETECOND ), FALSE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_LBX_CONDITIONS ), FALSE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_ACH_GROUP ), FALSE );
Expand Down Expand Up @@ -1707,7 +1737,7 @@ void Dlg_AchievementEditor::LoadAchievement( Achievement* pCheevo, BOOL bAttempt
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_ACH_DESC ), TRUE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_ACH_POINTS ), TRUE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_ADDCOND ), TRUE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_CLONECOND ), TRUE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_COPYCOND ), TRUE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_DELETECOND ), TRUE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_LBX_CONDITIONS ), TRUE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_ACH_GROUP ), TRUE );
Expand Down Expand Up @@ -1781,7 +1811,7 @@ void Dlg_AchievementEditor::LoadAchievement( Achievement* pCheevo, BOOL bAttempt
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_ACH_DESC ), TRUE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_ACH_POINTS ), TRUE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_ADDCOND ), TRUE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_CLONECOND ), TRUE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_COPYCOND ), TRUE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_DELETECOND ), TRUE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_LBX_CONDITIONS ), TRUE );
EnableWindow( GetDlgItem( m_hAchievementEditorDlg, IDC_RA_ACH_GROUP ), TRUE );
Expand Down
2 changes: 2 additions & 0 deletions RA_Integration/RA_Dlg_AchEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class Dlg_AchievementEditor
size_t GetSelectedConditionGroup() const;
void SetSelectedConditionGroup( size_t nGrp ) const;

ConditionSet m_ConditionClipboard;

private:
void RepopulateGroupList( Achievement* pCheevo );
void PopulateConditions( Achievement* pCheevo );
Expand Down
101 changes: 51 additions & 50 deletions RA_Integration/RA_Dlg_Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ INT_PTR CALLBACK MemoryViewerControl::s_MemoryDrawProc( HWND hDlg, UINT uMsg, WP
case WM_ERASEBKGND:
return TRUE;

case WM_MOUSEWHEEL:
if (GET_WHEEL_DELTA_WPARAM(wParam) > 0 && m_nAddressOffset > (0x40))
setAddress(m_nAddressOffset - 32);
else if (GET_WHEEL_DELTA_WPARAM(wParam) < 0 && m_nAddressOffset + (0x40) < g_MemManager.TotalBankSize())
setAddress(m_nAddressOffset + 32);
return FALSE;

case WM_LBUTTONUP:
OnClick( { GET_X_LPARAM( lParam ), GET_Y_LPARAM( lParam ) } );
return FALSE;
Expand Down Expand Up @@ -132,11 +139,11 @@ bool MemoryViewerControl::OnKeyDown( UINT nChar )
return true;

case VK_PRIOR: // Page up (!)
moveAddress(-0x40, 0);
moveAddress(-(m_nDisplayedLines << 4), 0);
return true;

case VK_NEXT: // Page down (!)
moveAddress(0x40, 0);
moveAddress((m_nDisplayedLines << 4), 0);
return true;

case VK_HOME:
Expand Down Expand Up @@ -171,20 +178,16 @@ void MemoryViewerControl::moveAddress(int offset, int nibbleOff)
{
// Going left
m_nEditNibble--;
if (m_nEditNibble == -1)
if (m_nEditAddress == 0 && m_nEditNibble == -1)
{
m_nEditAddress -= (maxNibble + 1) >> 1;
m_nEditNibble = maxNibble;
}
if (m_nEditAddress < m_nAddressOffset) //(m_nAddressOffset == 0 && (m_nEditAddress >= (unsigned int)(m_nDisplayedLines << 4)))
{
m_nEditAddress += (maxNibble + 1) >> 1;
m_nEditNibble = 0;
MessageBeep((UINT)-1);
return;
}
if (m_nEditAddress < m_nAddressOffset)
if (m_nEditNibble == -1)
{
setAddress(m_nAddressOffset - 16);
m_nEditAddress -= (maxNibble + 1) >> 1;
m_nEditNibble = maxNibble;
}
}
else
Expand All @@ -196,63 +199,53 @@ void MemoryViewerControl::moveAddress(int offset, int nibbleOff)
m_nEditNibble = 0;
m_nEditAddress += (maxNibble + 1) >> 1;
}
if (m_nEditAddress > ( m_nAddressOffset + 0xf ))
if ( m_nEditAddress >= g_MemManager.TotalBankSize() )
{
// Undo this movement.
m_nEditAddress -= (maxNibble + 1) >> 1;
m_nEditNibble = maxNibble;
MessageBeep((UINT)-1);
}
if (m_nEditAddress >= (m_nAddressOffset + (m_nDisplayedLines << 4)))
{
setAddress(m_nAddressOffset + 16);
return;
}
}
}
else
{
m_nEditAddress += offset;
if (offset < 0 && m_nEditAddress >(m_nAddressOffset - 1 + (m_nDisplayedLines << 4)))
{
m_nEditAddress -= offset;
MessageBeep((UINT)-1);
return;
}
if (offset > 0 && (m_nEditAddress < m_nAddressOffset))
{
m_nEditAddress -= offset;
MessageBeep((UINT)-1);
return;
}
if (m_nEditAddress >= g_MemManager.TotalBankSize())
{
m_nEditAddress -= offset;
MessageBeep((UINT)-1);
return;
}
if (m_nEditAddress < m_nAddressOffset)

if (offset < 0)
{
if (offset & 15)
setAddress((m_nAddressOffset + offset - 16) & ~15);
else
setAddress(m_nAddressOffset + offset);

if (m_nEditAddress >(m_nAddressOffset - 1 + (m_nDisplayedLines << 4)) && (signed)m_nEditAddress < (0x10))
{
m_nEditAddress -= offset;
MessageBeep((UINT)-1);
return;
}
}
else if (m_nEditAddress > (m_nAddressOffset - 1 + (m_nDisplayedLines << 4)))
else
{
if (offset & 15)
setAddress((m_nAddressOffset + offset + 16) & ~15);
else
setAddress(m_nAddressOffset + offset);
if (m_nEditAddress >= g_MemManager.TotalBankSize())
{
m_nEditAddress -= offset;
MessageBeep((UINT)-1);
return;
}
}
}

if (m_nEditAddress + (0x40) < m_nAddressOffset)
setAddress((m_nEditAddress & ~(0xf)) + (0x40));
else if (m_nEditAddress >= (m_nAddressOffset + (m_nDisplayedLines << 4) - (0x40)))
setAddress( (m_nEditAddress & ~(0xf)) - (m_nDisplayedLines << 4) + (0x50) );

SetCaretPos();
}

void MemoryViewerControl::setAddress( unsigned int address )
{
m_nAddressOffset = address;
g_MemoryDialog.SetWatchingAddress( address );
//g_MemoryDialog.SetWatchingAddress( address );

SetCaretPos();
Invalidate();
Expand Down Expand Up @@ -387,7 +380,15 @@ void MemoryViewerControl::SetCaretPos()

int subAddress = (m_nEditAddress - m_nAddressOffset);

const int nYSpacing = 4;
int linePosition = (subAddress & ~(0xF)) / (0x10) + 4;

if ( linePosition < 0 || linePosition > m_nDisplayedLines - 1)
{
destroyEditCaret();
return;
}

const int nYSpacing = linePosition;

int x = 3 + ( 10*m_szFontSize.cx ) + ( m_nEditNibble*m_szFontSize.cx );
int y = 3 + ( nYSpacing*m_szFontSize.cy );
Expand Down Expand Up @@ -435,7 +436,7 @@ void MemoryViewerControl::OnClick( POINT point )
int y = point.y - m_szFontSize.cy; // Adjust for header
int line = ((y-3)/m_szFontSize.cy);

if( line == -1 )
if( line == -1 || line >= m_nDisplayedLines)
return; // clicked on header

int rowLengthPx = m_nDataStartXOffset;
Expand Down Expand Up @@ -554,7 +555,7 @@ void MemoryViewerControl::RenderMemViewer( HWND hTarget )
wchar_t buffer[ 64 ];
ComboBox_GetText( GetDlgItem( g_MemoryDialog.GetHWND(), IDC_RA_WATCHING ), buffer, 64 );
unsigned int nWatchedAddress = wcstol( buffer, nullptr, 16 );
m_nAddressOffset = ( nWatchedAddress - ( nWatchedAddress & 0xf ) );
//m_nAddressOffset = ( nWatchedAddress - ( nWatchedAddress & 0xf ) );

int addr = m_nAddressOffset;
addr -= ( 0x40 ); // Offset will be this quantity (push up four lines)...
Expand Down Expand Up @@ -844,7 +845,7 @@ INT_PTR Dlg_Memory::MemoryProc( HWND hDlg, UINT nMsg, WPARAM wParam, LPARAM lPar
lpmmi->ptMinTrackSize.x = nDlgMemoryMinX;
lpmmi->ptMinTrackSize.y = nDlgMemoryMinY;
}
break;
return TRUE;

case WM_SIZE:
{
Expand All @@ -856,7 +857,7 @@ INT_PTR Dlg_Memory::MemoryProc( HWND hDlg, UINT nMsg, WPARAM wParam, LPARAM lPar
SetWindowPos(hItem, NULL, 0, 0,
itemRect.right - itemRect.left, (winRect.bottom - itemRect.top) + nDlgMemViewerGapY, SWP_NOMOVE | SWP_NOZORDER);
}
break;
return TRUE;

case WM_COMMAND:
{
Expand Down
4 changes: 3 additions & 1 deletion RA_Integration/RA_Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
#define IDC_RA_VOTE_POS 1525
#define IDC_RA_CHK_SHOW_DECIMALS 1526
#define IDC_RA_DELETECOND 1527
#define IDC_RA_CLONECOND 1528
#define IDC_RA_COPYCOND 1528
#define IDC_RA_ACH_ID 1529
#define IDC_RA_DEL_ACH 1530
#define IDC_RA_DELETECOND2 1530
#define IDC_RA_PASTECOND 1530
#define IDC_RA_CHKACHPROCESSINGACTIVE 1531
#define IDC_RA_GOTOWIKI 1532
#define IDC_RA_GAMEHASH 1533
Expand Down
5 changes: 3 additions & 2 deletions RA_Integration/RA_Shared.rc
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ BEGIN
EDITTEXT IDC_RA_ACH_DESC,50,45,284,12,ES_AUTOHSCROLL
CONTROL "",IDC_RA_LBX_CONDITIONS,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,50,74,343,80
DEFPUSHBUTTON "Add New Requirement",IDC_RA_ADDCOND,50,159,48,24,BS_MULTILINE
DEFPUSHBUTTON "Clone Selected",IDC_RA_CLONECOND,102,159,47,24,BS_MULTILINE
DEFPUSHBUTTON "Delete Selected",IDC_RA_DELETECOND,154,159,48,24,BS_MULTILINE
DEFPUSHBUTTON "Copy",IDC_RA_COPYCOND,154,159,32,12,BS_MULTILINE
DEFPUSHBUTTON "Paste",IDC_RA_PASTECOND,154,171,32,12,BS_MULTILINE
DEFPUSHBUTTON "Delete Selected",IDC_RA_DELETECOND,102,159,48,24,BS_MULTILINE
CONTROL "Show Decimal Values",IDC_RA_CHK_SHOW_DECIMALS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,255,173,79,10
PUSHBUTTON "Close",IDCLOSE,343,168,50,15
PUSHBUTTON "Upload Badge",IDC_RA_UPLOAD_BADGE,275,7,59,15,BS_MULTILINE
Expand Down

0 comments on commit 4676e7e

Please sign in to comment.