mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-24 05:45:36 +03:00
0.2: Edit stats, clear stats features added
This commit is contained in:
parent
7f47d2de56
commit
27e4174be6
@ -153,16 +153,32 @@ RankSystem::RankStats* RankSystem::findEntryInRank(const char* unique, const cha
|
||||
|
||||
while ( a )
|
||||
{
|
||||
if ( strcmp( a->getUnique() ,unique ) == 0 )
|
||||
if ( strcmp( a->getUnique(), unique ) == 0 )
|
||||
return a;
|
||||
|
||||
a = a->prev;
|
||||
}
|
||||
|
||||
a = new RankStats( unique ,name,this );
|
||||
if ( a == 0 ) return 0;
|
||||
put_after( a , 0 );
|
||||
return a;
|
||||
}
|
||||
|
||||
RankSystem::RankStats* RankSystem::findEntryInRankByUnique(const char* unique)
|
||||
{
|
||||
RankStats* a = head;
|
||||
|
||||
while ( a )
|
||||
{
|
||||
if ( strcmp( a->getUnique(), unique ) == 0 )
|
||||
return a;
|
||||
|
||||
a = a->prev;
|
||||
}
|
||||
|
||||
return NULL; // none found
|
||||
}
|
||||
RankSystem::RankStats* RankSystem::findEntryInRankByPos(int position)
|
||||
{
|
||||
RankStats* a = head;
|
||||
@ -175,12 +191,14 @@ RankSystem::RankStats* RankSystem::findEntryInRankByPos(int position)
|
||||
a = a->prev;
|
||||
}
|
||||
|
||||
return a;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void RankSystem::updatePos( RankStats* rr , Stats* s )
|
||||
int RankSystem::updatePos( RankStats* rr , Stats* s )
|
||||
{
|
||||
rr->addStats( s );
|
||||
RankStats* rrFirst = rr;
|
||||
if (s != NULL)
|
||||
rr->addStats( s );
|
||||
if ( calc.code ) {
|
||||
calc.physAddr1[0] = rr->kills;
|
||||
calc.physAddr1[1] = rr->deaths;
|
||||
@ -230,7 +248,7 @@ void RankSystem::updatePos( RankStats* rr , Stats* s )
|
||||
put_after( rr, aa );
|
||||
}
|
||||
}
|
||||
|
||||
return rrFirst->getPosition();
|
||||
}
|
||||
|
||||
bool RankSystem::loadRank( const char* filename )
|
||||
|
@ -67,8 +67,8 @@ public:
|
||||
inline const char* getName() const { return name ? name : ""; }
|
||||
inline const char* getUnique() const { return unique ? unique : ""; }
|
||||
inline int getPosition() const { return id; }
|
||||
inline void updatePosition( Stats* points ) {
|
||||
parent->updatePos( this , points );
|
||||
inline int updatePosition( Stats* points ) {
|
||||
return parent->updatePos( this , points );
|
||||
}
|
||||
};
|
||||
|
||||
@ -90,7 +90,7 @@ private:
|
||||
void put_before( RankStats* a, RankStats* ptr );
|
||||
void put_after( RankStats* a, RankStats* ptr );
|
||||
void unlink( RankStats* ptr );
|
||||
void updatePos( RankStats* r , Stats* s );
|
||||
int updatePos( RankStats* r , Stats* s );
|
||||
|
||||
public:
|
||||
|
||||
@ -100,6 +100,7 @@ public:
|
||||
void saveRank( const char* filename );
|
||||
bool loadRank( const char* filename );
|
||||
RankStats* findEntryInRank(const char* unique, const char* name );
|
||||
RankStats* findEntryInRankByUnique(const char* unique);
|
||||
RankStats* findEntryInRankByPos(int position);
|
||||
//bool loadCalc(const char* filename, char* error);
|
||||
inline int getRankNum( ) const { return rankNum; }
|
||||
|
@ -16,6 +16,9 @@
|
||||
#define IDC_LIST 1010
|
||||
#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_EDIT_NAME 1100
|
||||
#define IDC_EDIT_POSITION 1101
|
||||
#define IDC_EDIT_AUTHID 1102
|
||||
@ -43,7 +46,7 @@
|
||||
#define _APS_NO_MFC 1
|
||||
#define _APS_NEXT_RESOURCE_VALUE 130
|
||||
#define _APS_NEXT_COMMAND_VALUE 32775
|
||||
#define _APS_NEXT_CONTROL_VALUE 1030
|
||||
#define _APS_NEXT_CONTROL_VALUE 1032
|
||||
#define _APS_NEXT_SYMED_VALUE 110
|
||||
#endif
|
||||
#endif
|
||||
|
@ -110,7 +110,7 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
||||
bool LoadRankFromFile(HWND hDlg) {
|
||||
if ( !g_rank.begin() )
|
||||
{
|
||||
if (!g_rank.loadRank("csstats.dat")) {
|
||||
if (!g_rank.loadRank(STATS_FILENAME)) {
|
||||
HWND listbox = GetDlgItem(hDlg, IDC_LIST);
|
||||
SendMessage( // returns LRESULT in lResult
|
||||
listbox, // handle to destination control
|
||||
@ -156,15 +156,18 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
return 0;
|
||||
}
|
||||
|
||||
LRESULT InitWinCSXBox(HWND hDlg) {
|
||||
// Load the stats
|
||||
if (!LoadRankFromFile(hDlg))
|
||||
return TRUE;
|
||||
|
||||
// This part copies the occurring authids into the lefthand listbox.
|
||||
int index = 10, len = 0;
|
||||
void UpdateListBox(HWND hDlg) {
|
||||
HWND listbox = GetDlgItem(hDlg, IDC_LIST);
|
||||
|
||||
// Clear first if there's anything in here already
|
||||
SendMessage(listbox, LB_RESETCONTENT, NULL, NULL);
|
||||
|
||||
if (g_rank.front() == NULL) {
|
||||
MessageBox(hDlg, "The stats file is empty", "Emptiness...", MB_OK);
|
||||
return;
|
||||
}
|
||||
// This part copies the occurring authids into the lefthand listbox.
|
||||
int index = 10, len = 0;
|
||||
char tempbuffer[1024];
|
||||
|
||||
for (RankSystem::iterator b = g_rank.front(); b; --b) {
|
||||
@ -179,19 +182,52 @@ LRESULT InitWinCSXBox(HWND hDlg) {
|
||||
0, // = (WPARAM) () wParam;
|
||||
(LPARAM) tempbuffer // = (LPARAM) () lParam;
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT InitWinCSXBox(HWND hDlg) {
|
||||
// Load the stats
|
||||
if (!LoadRankFromFile(hDlg))
|
||||
return TRUE;
|
||||
|
||||
UpdateListBox(hDlg);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void ClearStatsfields(HWND hDlg) {
|
||||
SetDlgItemText(hDlg, IDC_EDIT_POSITION, "");
|
||||
SetDlgItemText(hDlg, IDC_EDIT_NAME, "");
|
||||
SetDlgItemText(hDlg, IDC_EDIT_AUTHID, "");
|
||||
SetDlgItemText(hDlg, IDC_EDIT_FRAGS, "");
|
||||
SetDlgItemText(hDlg, IDC_EDIT_DEATHS, "");
|
||||
SetDlgItemText(hDlg, IDC_EDIT_HS, "");
|
||||
SetDlgItemText(hDlg, IDC_EDIT_TKS, "");
|
||||
SetDlgItemText(hDlg, IDC_EDIT_SHOTS, "");
|
||||
SetDlgItemText(hDlg, IDC_EDIT_HITS, "");
|
||||
SetDlgItemText(hDlg, IDC_EDIT_DAMAGE, "");
|
||||
SetDlgItemText(hDlg, IDC_EDIT_PLANTS, "");
|
||||
SetDlgItemText(hDlg, IDC_EDIT_EXPLOSIONS, "");
|
||||
SetDlgItemText(hDlg, IDC_EDIT_DEFUSIONS, "");
|
||||
SetDlgItemText(hDlg, IDC_EDIT_DEFUSED, "");
|
||||
}
|
||||
|
||||
void ListboxItemSelected(HWND hDlg) {
|
||||
HWND hwndList = GetDlgItem(hDlg, IDC_LIST); // Get the handle of the listbox
|
||||
LRESULT nItem = SendMessage(hwndList, LB_GETCURSEL, 0, 0); // Get the item # that's selected. First item is prolly 0...
|
||||
|
||||
if (nItem == LB_ERR) {
|
||||
// Error, reset the form items...
|
||||
//MessageBox(hDlg, "Error: Couldn't find the selected record in the listbox!", "Oh fiddlesticks!", MB_OK);
|
||||
ClearStatsfields(hDlg);
|
||||
return;
|
||||
}
|
||||
// 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);
|
||||
ClearStatsfields(hDlg);
|
||||
return;
|
||||
}
|
||||
// Copy data into form
|
||||
SetDlgItemInt(hDlg, IDC_EDIT_POSITION, stats->getPosition(), 0);
|
||||
SetDlgItemText(hDlg, IDC_EDIT_NAME, stats->getName());
|
||||
@ -209,6 +245,111 @@ void ListboxItemSelected(HWND hDlg) {
|
||||
SetDlgItemInt(hDlg, IDC_EDIT_DEFUSED, stats->bDefused, 0);
|
||||
}
|
||||
|
||||
void SaveChanges(HWND hDlg) {
|
||||
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;
|
||||
}
|
||||
|
||||
char name[32];
|
||||
GetDlgItemText(hDlg, IDC_EDIT_NAME, name, sizeof(name));
|
||||
int frags = GetDlgItemInt(hDlg, IDC_EDIT_FRAGS, &success, false);
|
||||
if (!success)
|
||||
goto BadEnd;
|
||||
int deaths = GetDlgItemInt(hDlg, IDC_EDIT_DEATHS, &success, false);
|
||||
if (!success)
|
||||
goto BadEnd;
|
||||
int hs = GetDlgItemInt(hDlg, IDC_EDIT_HS, &success, false);
|
||||
if (!success)
|
||||
goto BadEnd;
|
||||
int tks = GetDlgItemInt(hDlg, IDC_EDIT_TKS, &success, false);
|
||||
if (!success)
|
||||
goto BadEnd;
|
||||
int shots = GetDlgItemInt(hDlg, IDC_EDIT_SHOTS, &success, false);
|
||||
if (!success)
|
||||
goto BadEnd;
|
||||
int hits = GetDlgItemInt(hDlg, IDC_EDIT_HITS, &success, false);
|
||||
if (!success)
|
||||
goto BadEnd;
|
||||
int damage = GetDlgItemInt(hDlg, IDC_EDIT_DAMAGE, &success, false);
|
||||
if (!success)
|
||||
goto BadEnd;
|
||||
int plants = GetDlgItemInt(hDlg, IDC_EDIT_PLANTS, &success, false);
|
||||
if (!success)
|
||||
goto BadEnd;
|
||||
int explosions = GetDlgItemInt(hDlg, IDC_EDIT_EXPLOSIONS, &success, false);
|
||||
if (!success)
|
||||
goto BadEnd;
|
||||
int defusions = GetDlgItemInt(hDlg, IDC_EDIT_DEFUSIONS, &success, false);
|
||||
if (!success)
|
||||
goto BadEnd;
|
||||
int defused = GetDlgItemInt(hDlg, IDC_EDIT_DEFUSED, &success, false);
|
||||
if (!success)
|
||||
goto BadEnd;
|
||||
|
||||
// Update stats in memory
|
||||
entry->setName(name);
|
||||
entry->kills = frags;
|
||||
entry->deaths = deaths;
|
||||
entry->hs = hs;
|
||||
entry->tks = tks;
|
||||
entry->shots = shots;
|
||||
entry->hits = hits;
|
||||
entry->damage = damage;
|
||||
entry->bPlants = plants;
|
||||
entry->bExplosions = explosions;
|
||||
entry->bDefusions = defusions;
|
||||
entry->bDefused = defused;
|
||||
|
||||
int newPosition = entry->updatePosition(NULL); // Updates rank (prolly just calculates "frags - deaths" and moves up/down in rank)
|
||||
|
||||
g_rank.saveRank(STATS_FILENAME); // Save changes to file
|
||||
|
||||
// Now update our listbox
|
||||
UpdateListBox(hDlg);
|
||||
|
||||
char buffer[256];
|
||||
_snprintf(buffer, 255, "New rank of %s: %d", name, newPosition);
|
||||
MessageBox(hDlg, buffer, "Update succeeded", MB_OK);
|
||||
|
||||
// In the listbox, we need to reselect the item we just updated. Use the new name.
|
||||
HWND listbox = GetDlgItem(hDlg, IDC_LIST);
|
||||
if (SendMessage(listbox, LB_SELECTSTRING, newPosition - 1, (LPARAM)name) == LB_ERR)
|
||||
MessageBox(hDlg, "Error selecting item!", "Oh fiddlesticks!", MB_OK);
|
||||
else {
|
||||
// Update
|
||||
ListboxItemSelected(hDlg);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
BadEnd:
|
||||
MessageBox(hDlg, "Update failed", "Oh fiddlesticks!", MB_OK);
|
||||
}
|
||||
|
||||
void ClearStats(HWND hDlg) {
|
||||
if (MessageBox(hDlg, "Are you sure? If you continue the whole csstats.dat will be wiped out!", "Omg!", MB_OKCANCEL | MB_DEFBUTTON2 | MB_ICONWARNING) != IDOK)
|
||||
return;
|
||||
g_rank.clear();
|
||||
g_rank.saveRank(STATS_FILENAME);
|
||||
|
||||
// Now update our listbox
|
||||
UpdateListBox(hDlg);
|
||||
|
||||
// Update
|
||||
ListboxItemSelected(hDlg);
|
||||
}
|
||||
|
||||
// Message handler for WinCSXBox.
|
||||
LRESULT CALLBACK WinCSXBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
@ -239,6 +380,12 @@ LRESULT CALLBACK WinCSXBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam
|
||||
case IDC_ABOUT:
|
||||
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hDlg, (DLGPROC)AboutBox);
|
||||
break;
|
||||
case IDC_BUTTON_SAVECHANGES:
|
||||
SaveChanges(hDlg);
|
||||
break;
|
||||
case IDC_BUTTON_CLEARSTATS:
|
||||
ClearStats(hDlg);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
// Constants
|
||||
#define MAX_LOADSTRING 100
|
||||
#define VERSION "0.2"
|
||||
#define STATS_FILENAME "csstats.dat"
|
||||
|
||||
// Global Variables:
|
||||
HINSTANCE hInst; // current instance
|
||||
|
@ -71,12 +71,13 @@ STYLE DS_ABSALIGN | DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION |
|
||||
CAPTION "WinCSX"
|
||||
FONT 8, "System", 0, 0, 0x0
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "Close",IDOK,157,168,88,26,WS_GROUP
|
||||
DEFPUSHBUTTON "Close",IDOK,206,168,39,26,WS_GROUP
|
||||
LISTBOX IDC_LIST,4,5,94,189,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_AUTHID,109,48,87,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_FRAGS,109,78,40,12,ES_AUTOHSCROLL
|
||||
EDITTEXT IDC_EDIT_DEATHS,157,78,40,12,ES_AUTOHSCROLL
|
||||
@ -103,6 +104,9 @@ BEGIN
|
||||
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
|
||||
END
|
||||
|
||||
IDD_ABOUTBOX DIALOGEX 0, 0, 186, 95
|
||||
@ -112,7 +116,7 @@ CAPTION "About"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "OK",IDOK,109,68,50,14
|
||||
LTEXT "WinCSX 0.2",IDC_STATIC,18,20,66,8
|
||||
LTEXT "WinCSX 0.3",IDC_STATIC,18,20,66,8
|
||||
LTEXT "By JGHG",IDC_STATIC,18,28,66,8
|
||||
LTEXT "2005",IDC_STATIC,18,36,66,8
|
||||
LTEXT "http://www.amxmodx.org/",IDC_STATIC,18,44,88,8
|
||||
|
Loading…
Reference in New Issue
Block a user