From 3f2a8ccfc594c17887634ebff6e4d0f069dfcffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Bergstr=C3=B6m?= Date: Thu, 27 Jan 2005 08:58:01 +0000 Subject: [PATCH] 0.4 = added delete button --- dlls/csx/source/WinCSX/CRank.h | 3 ++ dlls/csx/source/WinCSX/Resource.h | 6 ++-- dlls/csx/source/WinCSX/WinCSX.cpp | 53 +++++++++++++++++++++++++++++-- dlls/csx/source/WinCSX/WinCSX.rc | 29 +++++++++-------- 4 files changed, 72 insertions(+), 19 deletions(-) diff --git a/dlls/csx/source/WinCSX/CRank.h b/dlls/csx/source/WinCSX/CRank.h index c3db0990..8fd17b7d 100755 --- a/dlls/csx/source/WinCSX/CRank.h +++ b/dlls/csx/source/WinCSX/CRank.h @@ -70,6 +70,9 @@ public: inline int updatePosition( Stats* points ) { return parent->updatePos( this , points ); } + inline void MarkToDelete() { + this->score = (1<<31); + } }; private: diff --git a/dlls/csx/source/WinCSX/Resource.h b/dlls/csx/source/WinCSX/Resource.h index 8b0c234a..8fec3fcb 100755 --- a/dlls/csx/source/WinCSX/Resource.h +++ b/dlls/csx/source/WinCSX/Resource.h @@ -17,8 +17,8 @@ #define IDC_BUTTON_ABOUT 1029 #define IDC_ABOUT 1029 #define IDC_BUTTON_SAVECHANGES 1030 -#define IDC_BUTTON1 1031 #define IDC_BUTTON_CLEARSTATS 1031 +#define IDC_BUTTON_DELETE 1032 #define IDC_EDIT_NAME 1100 #define IDC_EDIT_POSITION 1101 #define IDC_EDIT_AUTHID 1102 @@ -44,9 +44,9 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NO_MFC 1 -#define _APS_NEXT_RESOURCE_VALUE 130 +#define _APS_NEXT_RESOURCE_VALUE 131 #define _APS_NEXT_COMMAND_VALUE 32775 -#define _APS_NEXT_CONTROL_VALUE 1032 +#define _APS_NEXT_CONTROL_VALUE 1033 #define _APS_NEXT_SYMED_VALUE 110 #endif #endif diff --git a/dlls/csx/source/WinCSX/WinCSX.cpp b/dlls/csx/source/WinCSX/WinCSX.cpp index f3ee9407..e437db03 100755 --- a/dlls/csx/source/WinCSX/WinCSX.cpp +++ b/dlls/csx/source/WinCSX/WinCSX.cpp @@ -219,7 +219,9 @@ void ListboxItemSelected(HWND hDlg) { // Retrieve complete stats record of this position. Position in listbox should be same as rank in our records! RankSystem::RankStats* stats = g_rank.findEntryInRankByPos((int)nItem + 1); if (stats == NULL) { - MessageBox(hDlg, "Error: Couldn't find the record by position!", "Oh fiddlesticks!", MB_OK); + char msg[] = "Error: Couldn't find the record by position! (nItem = %d)"; + sprintf(msg, msg, nItem); + MessageBox(hDlg, msg, "Oh fiddlesticks!", MB_OK); ClearStatsfields(hDlg); return; } @@ -345,6 +347,50 @@ void ClearStats(HWND hDlg) { ListboxItemSelected(hDlg); } +void DeleteRecord(HWND hDlg) { + if (MessageBox(hDlg, "Are you sure?", "Omg!", MB_OKCANCEL | MB_DEFBUTTON2 | MB_ICONWARNING) != IDOK) + return; + + BOOL success; + int position = GetDlgItemInt(hDlg, IDC_EDIT_POSITION, &success, false); + if (!success) + goto BadEnd; + + char authid[32]; // "primary key" + GetDlgItemText(hDlg, IDC_EDIT_AUTHID, authid, sizeof(authid)); + RankSystem::RankStats* entry = g_rank.findEntryInRankByUnique(authid); + if (!entry) { + char buffer[256]; + sprintf(buffer, "Authid %s not found!", authid); + MessageBox(hDlg, buffer, "Update failed", MB_OK); + return; + } + + // Mark this record to delete it. + entry->MarkToDelete(); + + // Save ranks from memory to disk. + g_rank.saveRank(STATS_FILENAME); // Save changes to file + + // Clear memory. + g_rank.clear(); + + // Reload from disk into memory. + LoadRankFromFile(hDlg); + + // Update list box. + UpdateListBox(hDlg); + + MessageBox(hDlg, "Deleted record", "Delete succeeded", MB_OK); + + return; + +BadEnd: + MessageBox(hDlg, "Delete failed", "Oh fiddlesticks!", MB_OK); + + return; +} + // Message handler for WinCSXBox. LRESULT CALLBACK WinCSXBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { @@ -381,6 +427,10 @@ LRESULT CALLBACK WinCSXBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam case IDC_BUTTON_CLEARSTATS: ClearStats(hDlg); break; + case IDC_BUTTON_DELETE: + DeleteRecord(hDlg); + //DialogBox(hInst, (LPCTSTR)IDD_DELETEBOX, hDlg, (DLGPROC)DeleteBox); + break; } break; } @@ -408,4 +458,3 @@ LRESULT CALLBACK AboutBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) return FALSE; } - diff --git a/dlls/csx/source/WinCSX/WinCSX.rc b/dlls/csx/source/WinCSX/WinCSX.rc index 9b6000da..72819aa4 100755 --- a/dlls/csx/source/WinCSX/WinCSX.rc +++ b/dlls/csx/source/WinCSX/WinCSX.rc @@ -65,29 +65,29 @@ END // Dialog // -IDD_WINCSXBOX DIALOGEX 22, 17, 256, 203 +IDD_WINCSXBOX DIALOGEX 22, 17, 253, 204 STYLE DS_ABSALIGN | DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "WinCSX" FONT 8, "System", 0, 0, 0x0 BEGIN - DEFPUSHBUTTON "Close",IDOK,206,168,39,26,WS_GROUP - LISTBOX IDC_LIST,4,5,94,189,LBS_HASSTRINGS | + DEFPUSHBUTTON "Close",IDOK,206,168,39,27,WS_GROUP + LISTBOX IDC_LIST,4,5,94,190,LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP EDITTEXT IDC_EDIT_NAME,109,18,87,12,ES_AUTOHSCROLL - EDITTEXT IDC_EDIT_POSITION,206,18,40,12,ES_AUTOHSCROLL + EDITTEXT IDC_EDIT_POSITION,206,18,39,12,ES_AUTOHSCROLL EDITTEXT IDC_EDIT_AUTHID,109,48,87,12,ES_AUTOHSCROLL | ES_READONLY - EDITTEXT IDC_EDIT_DAMAGE,206,48,40,12,ES_AUTOHSCROLL + EDITTEXT IDC_EDIT_DAMAGE,206,48,39,12,ES_AUTOHSCROLL EDITTEXT IDC_EDIT_FRAGS,109,78,40,12,ES_AUTOHSCROLL EDITTEXT IDC_EDIT_DEATHS,157,78,40,12,ES_AUTOHSCROLL - EDITTEXT IDC_EDIT_TKS,206,78,40,12,ES_AUTOHSCROLL + EDITTEXT IDC_EDIT_TKS,206,78,39,12,ES_AUTOHSCROLL EDITTEXT IDC_EDIT_SHOTS,109,108,40,12,ES_AUTOHSCROLL EDITTEXT IDC_EDIT_HITS,157,108,40,12,ES_AUTOHSCROLL - EDITTEXT IDC_EDIT_HS,206,108,40,12,ES_AUTOHSCROLL + EDITTEXT IDC_EDIT_HS,206,108,39,12,ES_AUTOHSCROLL EDITTEXT IDC_EDIT_PLANTS,109,138,40,12,ES_AUTOHSCROLL EDITTEXT IDC_EDIT_EXPLOSIONS,157,137,40,12,ES_AUTOHSCROLL - EDITTEXT IDC_EDIT_DEFUSIONS,206,137,40,12,ES_AUTOHSCROLL + EDITTEXT IDC_EDIT_DEFUSIONS,206,137,39,12,ES_AUTOHSCROLL EDITTEXT IDC_EDIT_DEFUSED,109,168,40,12,ES_AUTOHSCROLL LTEXT "Name (last used)",IDC_STATIC,109,5,56,8 LTEXT "Damage",IDC_STATIC,206,35,28,8 @@ -103,10 +103,10 @@ BEGIN LTEXT "Explosions",IDC_STATIC,157,125,38,8 LTEXT "Defused",IDC_STATIC,109,155,28,8 LTEXT "Defusions",IDC_STATIC,206,125,34,8 - PUSHBUTTON "About",IDC_ABOUT,109,184,40,10 - PUSHBUTTON "Save record changes",IDC_BUTTON_SAVECHANGES,156,155,89, - 10 - PUSHBUTTON "Clear stats",IDC_BUTTON_CLEARSTATS,157,168,39,26 + PUSHBUTTON "About",IDC_ABOUT,109,185,40,10 + PUSHBUTTON "Save",IDC_BUTTON_SAVECHANGES,157,155,39,8 + PUSHBUTTON "Clear stats",IDC_BUTTON_CLEARSTATS,157,168,39,27 + PUSHBUTTON "Delete",IDC_BUTTON_DELETE,206,155,39,8 END IDD_ABOUTBOX DIALOGEX 0, 0, 186, 95 @@ -162,7 +162,7 @@ BEGIN IDD_WINCSXBOX, DIALOG BEGIN LEFTMARGIN, 4 - RIGHTMARGIN, 251 + RIGHTMARGIN, 248 VERTGUIDE, 98 VERTGUIDE, 109 VERTGUIDE, 157 @@ -170,7 +170,7 @@ BEGIN VERTGUIDE, 206 VERTGUIDE, 245 TOPMARGIN, 5 - BOTTOMMARGIN, 194 + BOTTOMMARGIN, 195 HORZGUIDE, 18 HORZGUIDE, 35 HORZGUIDE, 48 @@ -181,6 +181,7 @@ BEGIN HORZGUIDE, 125 HORZGUIDE, 137 HORZGUIDE, 155 + HORZGUIDE, 163 HORZGUIDE, 168 END END