1998-07-24 15:43:32 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: scoredg.cpp
|
|
|
|
// Purpose: Forty Thieves patience game
|
|
|
|
// Author: Chris Breeze
|
|
|
|
// Modified by:
|
|
|
|
// Created: 21/07/97
|
|
|
|
// Copyright: (c) 1993-1998 Chris Breeze
|
2004-05-25 08:44:56 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-07-24 15:43:32 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "scorefil.h"
|
|
|
|
#include "scoredg.h"
|
|
|
|
|
2004-07-28 05:36:45 -04:00
|
|
|
// adjust USE_GRID_FOR_SCORE with O or 1 to your preferences
|
|
|
|
// by default it takes wxGrid component for score display if available in target port
|
|
|
|
#define USE_GRID_FOR_SCORE wxUSE_GRID
|
2004-03-23 16:23:17 -05:00
|
|
|
|
|
|
|
#if USE_GRID_FOR_SCORE
|
|
|
|
#include "wx/grid.h"
|
|
|
|
#else
|
1998-07-24 15:43:32 -04:00
|
|
|
class ScoreCanvas : public wxScrolledWindow
|
|
|
|
{
|
|
|
|
public:
|
2004-05-25 08:44:56 -04:00
|
|
|
ScoreCanvas(wxWindow* parent, ScoreFile* scoreFile, const wxPoint& pos, wxSize& size);
|
|
|
|
virtual ~ScoreCanvas();
|
1998-07-24 15:43:32 -04:00
|
|
|
|
2004-05-25 08:44:56 -04:00
|
|
|
void OnDraw(wxDC& dc);
|
1998-07-24 15:43:32 -04:00
|
|
|
|
|
|
|
private:
|
2004-05-25 08:44:56 -04:00
|
|
|
wxFont *m_font;
|
|
|
|
wxString m_text;
|
1998-07-24 15:43:32 -04:00
|
|
|
};
|
|
|
|
|
2004-03-23 16:23:17 -05:00
|
|
|
ScoreCanvas::ScoreCanvas(wxWindow* parent, ScoreFile* scoreFile, const wxPoint& pos, wxSize& size) :
|
2004-05-25 08:44:56 -04:00
|
|
|
wxScrolledWindow(parent, wxID_ANY, pos, size, wxSUNKEN_BORDER)
|
1998-07-24 15:43:32 -04:00
|
|
|
{
|
2004-03-23 16:23:17 -05:00
|
|
|
SetBackgroundColour(*wxWHITE);
|
1998-07-24 15:43:32 -04:00
|
|
|
#ifdef __WXGTK__
|
2004-05-25 08:44:56 -04:00
|
|
|
m_font = wxTheFontList->FindOrCreateFont(12, wxROMAN, wxNORMAL, wxNORMAL);
|
1998-07-24 15:43:32 -04:00
|
|
|
#else
|
2004-05-25 08:44:56 -04:00
|
|
|
m_font = wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxNORMAL);
|
1998-07-24 15:43:32 -04:00
|
|
|
#endif
|
|
|
|
|
2004-03-23 16:23:17 -05:00
|
|
|
wxArrayString players;
|
2004-05-25 08:44:56 -04:00
|
|
|
scoreFile->GetPlayerList( players);
|
|
|
|
|
|
|
|
wxString os;
|
|
|
|
|
|
|
|
os << wxT("Player\tWins\tGames\tScore\n");
|
|
|
|
for (unsigned int i = 0; i < players.Count(); i++)
|
|
|
|
{
|
|
|
|
int wins, games, score;
|
|
|
|
scoreFile->ReadPlayersScore(players[i], wins, games, score);
|
|
|
|
int average = 0;
|
|
|
|
if (games > 0)
|
|
|
|
{
|
|
|
|
average = (2 * score + games) / (2 * games);
|
|
|
|
}
|
|
|
|
|
|
|
|
os << players[i] << wxT('\t')
|
|
|
|
<< wins << wxT('\t')
|
|
|
|
<< games << wxT('\t')
|
|
|
|
<< average << wxT('\n');
|
|
|
|
}
|
|
|
|
os << wxT('\0');
|
|
|
|
m_text = os;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ScoreCanvas::~ScoreCanvas()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScoreCanvas::OnDraw(wxDC& dc)
|
|
|
|
{
|
2004-05-25 08:44:56 -04:00
|
|
|
dc.SetFont(* m_font);
|
|
|
|
|
|
|
|
const wxChar* str = m_text;
|
|
|
|
unsigned int tab = 0;
|
|
|
|
unsigned int tabstops[] = { 5, 100, 150, 200 };
|
|
|
|
|
|
|
|
// get the line spacing for the current font
|
|
|
|
int lineSpacing;
|
|
|
|
{
|
|
|
|
long w, h;
|
|
|
|
dc.GetTextExtent(wxT("Testing"), &w, &h);
|
|
|
|
lineSpacing = (int)h;
|
|
|
|
}
|
|
|
|
|
|
|
|
int y = 0;
|
|
|
|
while (*str)
|
|
|
|
{
|
|
|
|
wxChar text[256];
|
|
|
|
wxChar* dest = text;
|
|
|
|
|
|
|
|
while (*str && *str >= ' ') *dest++ = *str++;
|
|
|
|
*dest = '\0';
|
|
|
|
|
|
|
|
dc.DrawText(text, tabstops[tab], y);
|
|
|
|
|
|
|
|
if (*str == '\t')
|
|
|
|
{
|
|
|
|
if (tab < sizeof(tabstops) / sizeof(tabstops[0]) - 1)
|
|
|
|
{
|
|
|
|
tab++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (*str == '\n')
|
|
|
|
{
|
|
|
|
tab = 0;
|
|
|
|
y += lineSpacing;
|
|
|
|
}
|
|
|
|
if (*str) str++;
|
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
2004-03-23 16:23:17 -05:00
|
|
|
#endif
|
1998-07-24 15:43:32 -04:00
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(ScoreDialog, wxDialog)
|
1999-02-05 18:55:04 -05:00
|
|
|
EVT_CLOSE(ScoreDialog::OnCloseWindow)
|
2015-04-23 07:49:01 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
1998-07-24 15:43:32 -04:00
|
|
|
|
2004-03-23 16:23:17 -05:00
|
|
|
ScoreDialog::ScoreDialog(wxWindow* parent, ScoreFile* file) :
|
2004-05-25 08:44:56 -04:00
|
|
|
wxDialog(parent, wxID_ANY, _("Scores"),
|
|
|
|
wxDefaultPosition, wxSize(400, 300)),
|
|
|
|
m_scoreFile(file)
|
1998-07-24 15:43:32 -04:00
|
|
|
{
|
2004-03-23 16:23:17 -05:00
|
|
|
// create grid with players
|
|
|
|
wxArrayString players;
|
2004-05-25 08:44:56 -04:00
|
|
|
file->GetPlayerList(players);
|
|
|
|
|
2004-03-23 16:23:17 -05:00
|
|
|
wxSize sz = wxSize(400, 300);
|
|
|
|
|
|
|
|
#if USE_GRID_FOR_SCORE
|
2004-05-25 08:44:56 -04:00
|
|
|
wxGrid* list = new wxGrid(this, wxID_ANY, wxDefaultPosition, sz, 0);
|
2004-03-23 16:23:17 -05:00
|
|
|
list->CreateGrid(players.Count(), 4);
|
2004-05-25 08:44:56 -04:00
|
|
|
for (unsigned int i = 0; i < players.Count(); i++)
|
|
|
|
{
|
|
|
|
int wins, games, score;
|
2004-03-23 16:23:17 -05:00
|
|
|
wxString string_value;
|
|
|
|
|
2004-05-25 08:44:56 -04:00
|
|
|
file->ReadPlayersScore(players[i], wins, games, score);
|
|
|
|
int average = 0;
|
|
|
|
if (games > 0)
|
|
|
|
{
|
|
|
|
average = (2 * score + games) / (2 * games);
|
|
|
|
}
|
2004-03-23 16:23:17 -05:00
|
|
|
list->SetCellValue(i,0,players[i]);
|
2009-07-23 16:30:22 -04:00
|
|
|
string_value.Printf( wxT("%u"), wins );
|
2004-03-23 16:23:17 -05:00
|
|
|
list->SetCellValue(i,1,string_value);
|
2009-07-23 16:30:22 -04:00
|
|
|
string_value.Printf( wxT("%u"), games );
|
2004-03-23 16:23:17 -05:00
|
|
|
list->SetCellValue(i,2,string_value);
|
2009-07-23 16:30:22 -04:00
|
|
|
string_value.Printf( wxT("%u"), average );
|
2004-03-23 16:23:17 -05:00
|
|
|
list->SetCellValue(i,3,string_value);
|
|
|
|
}
|
2009-07-23 16:30:22 -04:00
|
|
|
list->SetColLabelValue(0, wxT("Players"));
|
|
|
|
list->SetColLabelValue(1, wxT("Wins"));
|
|
|
|
list->SetColLabelValue(2, wxT("Games"));
|
|
|
|
list->SetColLabelValue(3, wxT("Score"));
|
2011-12-23 12:38:30 -05:00
|
|
|
list->EnableEditing(false);
|
2004-03-23 16:23:17 -05:00
|
|
|
list->AutoSizeColumns();
|
|
|
|
list->AutoSizeRows();
|
|
|
|
list->SetRowLabelSize(0);
|
|
|
|
list->EnableDragRowSize(false);
|
|
|
|
list->EnableDragColSize(false);
|
|
|
|
list->EnableDragGridSize(false);
|
2004-07-28 05:36:45 -04:00
|
|
|
list->ClearSelection();
|
|
|
|
list->EnableEditing(false);
|
|
|
|
sz.x = wxDefaultCoord;
|
2004-03-23 16:23:17 -05:00
|
|
|
#else
|
2004-05-25 08:44:56 -04:00
|
|
|
ScoreCanvas* list = new ScoreCanvas(this, m_scoreFile, wxDefaultPosition, sz);
|
2004-03-23 16:23:17 -05:00
|
|
|
#endif
|
|
|
|
|
2006-10-31 03:50:17 -05:00
|
|
|
list->SetInitialSize(sz);
|
2004-07-28 05:36:45 -04:00
|
|
|
|
2004-03-23 16:23:17 -05:00
|
|
|
// locate and resize with sizers
|
|
|
|
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
topsizer->Add( list, 1, wxALL|wxGROW, 10 );
|
2005-01-31 13:18:18 -05:00
|
|
|
wxButton *button = new wxButton(this, wxID_OK);
|
2004-07-28 05:36:45 -04:00
|
|
|
topsizer->Add( button, 0, wxALIGN_CENTER_HORIZONTAL|wxALL , 10 );
|
|
|
|
button->SetFocus();
|
2004-03-23 16:23:17 -05:00
|
|
|
|
|
|
|
SetSizer( topsizer );
|
|
|
|
|
|
|
|
GetSizer()->Fit(this);
|
|
|
|
GetSizer()->SetSizeHints(this);
|
2004-05-25 08:44:56 -04:00
|
|
|
|
2004-03-23 16:23:17 -05:00
|
|
|
CentreOnParent();
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScoreDialog::Display()
|
|
|
|
{
|
2004-07-28 05:36:45 -04:00
|
|
|
ShowModal();
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
2003-09-18 09:33:34 -04:00
|
|
|
void ScoreDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
|
1998-07-24 15:43:32 -04:00
|
|
|
{
|
1999-02-05 18:55:04 -05:00
|
|
|
EndModal(wxID_OK);
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|