Applied patch [ 914126 ] Cleaning of the forty demo
Also made configurable between use of grid and canvas git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26310 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -38,12 +38,12 @@ BEGIN_EVENT_TABLE(FortyCanvas, wxScrolledWindow)
|
|||||||
EVT_MOUSE_EVENTS(FortyCanvas::OnMouseEvent)
|
EVT_MOUSE_EVENTS(FortyCanvas::OnMouseEvent)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
FortyCanvas::FortyCanvas(wxWindow* parent, int x, int y, int w, int h) :
|
FortyCanvas::FortyCanvas(wxWindow* parent, const wxPoint& pos, const wxSize& size) :
|
||||||
wxScrolledWindow(parent, -1, wxPoint(x, y), wxSize(w, h)),
|
wxScrolledWindow(parent, wxID_ANY, pos, size),
|
||||||
m_helpingHand(TRUE),
|
m_helpingHand(true),
|
||||||
m_rightBtnUndo(TRUE),
|
m_rightBtnUndo(true),
|
||||||
m_playerDialog(0),
|
m_playerDialog(0),
|
||||||
m_leftBtnDown(FALSE)
|
m_leftBtnDown(false)
|
||||||
{
|
{
|
||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
m_font = wxTheFontList->FindOrCreateFont(12, wxROMAN, wxNORMAL, wxNORMAL);
|
m_font = wxTheFontList->FindOrCreateFont(12, wxROMAN, wxNORMAL, wxNORMAL);
|
||||||
@@ -116,7 +116,7 @@ void FortyCanvas::OnDraw(wxDC& dc)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// user cancelled the dialog - exit the app
|
// user cancelled the dialog - exit the app
|
||||||
((wxFrame*)GetParent())->Close(TRUE);
|
((wxFrame*)GetParent())->Close(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -148,7 +148,7 @@ void FortyCanvas::ShowPlayerDialog()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// user cancelled the dialog - exit the app
|
// user cancelled the dialog - exit the app
|
||||||
((wxFrame*)GetParent())->Close(TRUE);
|
((wxFrame*)GetParent())->Close(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,9 +162,9 @@ bool FortyCanvas::OnCloseCanvas()
|
|||||||
wxMessageBox(_T("Are you sure you want to\nabandon the current game?"),
|
wxMessageBox(_T("Are you sure you want to\nabandon the current game?"),
|
||||||
_T("Warning"), wxYES_NO | wxICON_QUESTION) == wxNO)
|
_T("Warning"), wxYES_NO | wxICON_QUESTION) == wxNO)
|
||||||
{
|
{
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FortyCanvas::OnMouseEvent(wxMouseEvent& event)
|
void FortyCanvas::OnMouseEvent(wxMouseEvent& event)
|
||||||
@@ -180,7 +180,7 @@ void FortyCanvas::OnMouseEvent(wxMouseEvent& event)
|
|||||||
{
|
{
|
||||||
if (m_leftBtnDown)
|
if (m_leftBtnDown)
|
||||||
{
|
{
|
||||||
m_leftBtnDown = FALSE;
|
m_leftBtnDown = false;
|
||||||
ReleaseMouse();
|
ReleaseMouse();
|
||||||
m_game->LButtonUp(dc, mouseX, mouseY);
|
m_game->LButtonUp(dc, mouseX, mouseY);
|
||||||
}
|
}
|
||||||
@@ -190,7 +190,7 @@ void FortyCanvas::OnMouseEvent(wxMouseEvent& event)
|
|||||||
{
|
{
|
||||||
if (!m_leftBtnDown)
|
if (!m_leftBtnDown)
|
||||||
{
|
{
|
||||||
m_leftBtnDown = TRUE;
|
m_leftBtnDown = true;
|
||||||
CaptureMouse();
|
CaptureMouse();
|
||||||
m_game->LButtonDown(dc, mouseX, mouseY);
|
m_game->LButtonDown(dc, mouseX, mouseY);
|
||||||
}
|
}
|
||||||
@@ -199,14 +199,14 @@ void FortyCanvas::OnMouseEvent(wxMouseEvent& event)
|
|||||||
{
|
{
|
||||||
if (m_leftBtnDown)
|
if (m_leftBtnDown)
|
||||||
{
|
{
|
||||||
m_leftBtnDown = FALSE;
|
m_leftBtnDown = false;
|
||||||
ReleaseMouse();
|
ReleaseMouse();
|
||||||
m_game->LButtonUp(dc, mouseX, mouseY);
|
m_game->LButtonUp(dc, mouseX, mouseY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (event.RightDown() && !event.LeftIsDown())
|
else if (event.RightDown() && !event.LeftIsDown())
|
||||||
{
|
{
|
||||||
// only allow right button undo if m_rightBtnUndo is TRUE
|
// only allow right button undo if m_rightBtnUndo is true
|
||||||
if (m_rightBtnUndo)
|
if (m_rightBtnUndo)
|
||||||
{
|
{
|
||||||
if (event.ControlDown() || event.ShiftDown())
|
if (event.ControlDown() || event.ShiftDown())
|
||||||
|
@@ -21,7 +21,7 @@ class PlayerSelectionDialog;
|
|||||||
class FortyCanvas: public wxScrolledWindow
|
class FortyCanvas: public wxScrolledWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FortyCanvas(wxWindow* parent, int x, int y, int w, int h);
|
FortyCanvas(wxWindow* parent, const wxPoint& pos, const wxSize& size);
|
||||||
virtual ~FortyCanvas();
|
virtual ~FortyCanvas();
|
||||||
|
|
||||||
virtual void OnDraw(wxDC& dc);
|
virtual void OnDraw(wxDC& dc);
|
||||||
|
@@ -111,11 +111,11 @@ Card::Card(int value, WayUp way_up) :
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
m_pipValue = 1 + (value - 1) % 13;
|
m_pipValue = 1 + (value - 1) % 13;
|
||||||
m_status = TRUE;
|
m_status = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_status = FALSE;
|
m_status = false;
|
||||||
}
|
}
|
||||||
} // Card::Card()
|
} // Card::Card()
|
||||||
|
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
scorefil.cpp
|
scorefil.cpp
|
||||||
</sources>
|
</sources>
|
||||||
<wx-lib>html</wx-lib>
|
<wx-lib>html</wx-lib>
|
||||||
|
<wx-lib>adv</wx-lib>
|
||||||
<wx-lib>core</wx-lib>
|
<wx-lib>core</wx-lib>
|
||||||
<wx-lib>base</wx-lib>
|
<wx-lib>base</wx-lib>
|
||||||
<win32-res>forty.rc</win32-res>
|
<win32-res>forty.rc</win32-res>
|
||||||
|
@@ -74,27 +74,30 @@ FortyApp::~FortyApp()
|
|||||||
|
|
||||||
bool FortyApp::OnInit()
|
bool FortyApp::OnInit()
|
||||||
{
|
{
|
||||||
bool largecards = FALSE;
|
bool largecards = false;
|
||||||
|
|
||||||
wxSize size(668,510);
|
wxSize size(668,510);
|
||||||
|
|
||||||
if ((argc > 1) && (!wxStrcmp(argv[1],_T("-L"))))
|
if ((argc > 1) && (!wxStrcmp(argv[1],_T("-L"))))
|
||||||
{
|
{
|
||||||
largecards = TRUE;
|
largecards = true;
|
||||||
size = wxSize(1000,750);
|
size = wxSize(1000,750);
|
||||||
}
|
}
|
||||||
|
|
||||||
FortyFrame* frame = new FortyFrame(
|
FortyFrame* frame = new FortyFrame(
|
||||||
0,
|
0,
|
||||||
_T("Forty Thieves"),
|
_T("Forty Thieves"),
|
||||||
-1, -1, size.x, size.y,largecards
|
wxDefaultPosition,
|
||||||
|
size,
|
||||||
|
largecards
|
||||||
);
|
);
|
||||||
|
|
||||||
// Show the frame
|
// Show the frame
|
||||||
frame->Show(TRUE);
|
frame->Show(true);
|
||||||
|
|
||||||
frame->GetCanvas()->ShowPlayerDialog();
|
frame->GetCanvas()->ShowPlayerDialog();
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const wxColour& FortyApp::BackgroundColour()
|
const wxColour& FortyApp::BackgroundColour()
|
||||||
@@ -128,8 +131,8 @@ const wxColour& FortyApp::TextColour()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// My frame constructor
|
// My frame constructor
|
||||||
FortyFrame::FortyFrame(wxFrame* frame, const wxString& title, int x, int y, int w, int h,bool largecards):
|
FortyFrame::FortyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos, const wxSize& size, bool largecards):
|
||||||
wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
|
wxFrame(frame, wxID_ANY, title, pos, size)
|
||||||
{
|
{
|
||||||
#ifdef __WXMAC__
|
#ifdef __WXMAC__
|
||||||
wxApp::s_macAboutMenuItemId = wxID_ABOUT ;
|
wxApp::s_macAboutMenuItemId = wxID_ABOUT ;
|
||||||
@@ -157,21 +160,21 @@ FortyFrame::FortyFrame(wxFrame* frame, const wxString& title, int x, int y, int
|
|||||||
optionsMenu->Append(RIGHT_BUTTON_UNDO,
|
optionsMenu->Append(RIGHT_BUTTON_UNDO,
|
||||||
_T("&Right button undo"),
|
_T("&Right button undo"),
|
||||||
_T("Enables/disables right mouse button undo and redo"),
|
_T("Enables/disables right mouse button undo and redo"),
|
||||||
TRUE
|
true
|
||||||
);
|
);
|
||||||
optionsMenu->Append(HELPING_HAND,
|
optionsMenu->Append(HELPING_HAND,
|
||||||
_T("&Helping hand"),
|
_T("&Helping hand"),
|
||||||
_T("Enables/disables hand cursor when a card can be moved"),
|
_T("Enables/disables hand cursor when a card can be moved"),
|
||||||
TRUE
|
true
|
||||||
);
|
);
|
||||||
optionsMenu->Append(LARGE_CARDS,
|
optionsMenu->Append(LARGE_CARDS,
|
||||||
_T("&Large cards"),
|
_T("&Large cards"),
|
||||||
_T("Enables/disables large cards for high resolution displays"),
|
_T("Enables/disables large cards for high resolution displays"),
|
||||||
TRUE
|
true
|
||||||
);
|
);
|
||||||
optionsMenu->Check(HELPING_HAND, TRUE);
|
optionsMenu->Check(HELPING_HAND, true);
|
||||||
optionsMenu->Check(RIGHT_BUTTON_UNDO, TRUE);
|
optionsMenu->Check(RIGHT_BUTTON_UNDO, true);
|
||||||
optionsMenu->Check(LARGE_CARDS, largecards ? TRUE : FALSE);
|
optionsMenu->Check(LARGE_CARDS, largecards ? true : false);
|
||||||
|
|
||||||
wxMenu* helpMenu = new wxMenu;
|
wxMenu* helpMenu = new wxMenu;
|
||||||
helpMenu->Append(wxID_HELP_CONTENTS, _T("&Help Contents"), _T("Displays information about playing the game"));
|
helpMenu->Append(wxID_HELP_CONTENTS, _T("&Help Contents"), _T("Displays information about playing the game"));
|
||||||
@@ -188,13 +191,12 @@ FortyFrame::FortyFrame(wxFrame* frame, const wxString& title, int x, int y, int
|
|||||||
if (largecards)
|
if (largecards)
|
||||||
Card::SetScale(1.3);
|
Card::SetScale(1.3);
|
||||||
|
|
||||||
m_canvas = new FortyCanvas(this, 0, 0, 400, 400);
|
m_canvas = new FortyCanvas(this, wxDefaultPosition, size);
|
||||||
wxLayoutConstraints* constr = new wxLayoutConstraints;
|
|
||||||
constr->left.SameAs(this, wxLeft);
|
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
|
||||||
constr->top.SameAs(this, wxTop);
|
topsizer->Add( m_canvas, 1, wxEXPAND | wxALL, 0);
|
||||||
constr->right.SameAs(this, wxRight);
|
SetSizer( topsizer );
|
||||||
constr->height.SameAs(this, wxHeight);
|
topsizer->SetSizeHints( this );
|
||||||
m_canvas->SetConstraints(constr);
|
|
||||||
|
|
||||||
CreateStatusBar();
|
CreateStatusBar();
|
||||||
}
|
}
|
||||||
@@ -222,7 +224,7 @@ FortyFrame::NewGame(wxCommandEvent&)
|
|||||||
void
|
void
|
||||||
FortyFrame::Exit(wxCommandEvent&)
|
FortyFrame::Exit(wxCommandEvent&)
|
||||||
{
|
{
|
||||||
Close(TRUE);
|
Close(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -231,7 +233,7 @@ FortyFrame::Help(wxCommandEvent& event)
|
|||||||
#if wxUSE_HTML
|
#if wxUSE_HTML
|
||||||
if (wxFileExists(wxT("about.htm")))
|
if (wxFileExists(wxT("about.htm")))
|
||||||
{
|
{
|
||||||
FortyAboutDialog dialog(this, -1, wxT("Forty Thieves Instructions"));
|
FortyAboutDialog dialog(this, wxID_ANY, wxT("Forty Thieves Instructions"));
|
||||||
if (dialog.ShowModal() == wxID_OK)
|
if (dialog.ShowModal() == wxID_OK)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -380,13 +382,12 @@ bool FortyAboutDialog::AddControls(wxWindow* parent)
|
|||||||
|
|
||||||
item0->Add( item2, 0, wxALIGN_RIGHT|wxALL, 5 );
|
item0->Add( item2, 0, wxALIGN_RIGHT|wxALL, 5 );
|
||||||
|
|
||||||
parent->SetAutoLayout( TRUE );
|
|
||||||
parent->SetSizer( item0 );
|
parent->SetSizer( item0 );
|
||||||
parent->Layout();
|
parent->Layout();
|
||||||
item0->Fit( parent );
|
item0->Fit( parent );
|
||||||
item0->SetSizeHints( parent );
|
item0->SetSizeHints( parent );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,7 +34,7 @@ class FortyCanvas;
|
|||||||
class FortyFrame: public wxFrame
|
class FortyFrame: public wxFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FortyFrame(wxFrame* frame, const wxString& title, int x, int y, int w, int h,bool largecards);
|
FortyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos, const wxSize& size, bool largecards);
|
||||||
virtual ~FortyFrame();
|
virtual ~FortyFrame();
|
||||||
|
|
||||||
void OnCloseWindow(wxCloseEvent& event);
|
void OnCloseWindow(wxCloseEvent& event);
|
||||||
|
@@ -35,7 +35,7 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
Game::Game(int wins, int games, int score) :
|
Game::Game(int wins, int games, int score) :
|
||||||
m_inPlay(FALSE),
|
m_inPlay(false),
|
||||||
m_moveIndex(0),
|
m_moveIndex(0),
|
||||||
m_redoIndex(0),
|
m_redoIndex(0),
|
||||||
m_bmap(0),
|
m_bmap(0),
|
||||||
@@ -181,7 +181,7 @@ void Game::DoMove(wxDC& dc, Pile* src, Pile* dest)
|
|||||||
|
|
||||||
if (!m_inPlay)
|
if (!m_inPlay)
|
||||||
{
|
{
|
||||||
m_inPlay = TRUE;
|
m_inPlay = true;
|
||||||
m_numGames++;
|
m_numGames++;
|
||||||
}
|
}
|
||||||
DisplayScore(dc);
|
DisplayScore(dc);
|
||||||
@@ -198,7 +198,7 @@ void Game::DoMove(wxDC& dc, Pile* src, Pile* dest)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This game is over
|
// This game is over
|
||||||
m_inPlay = FALSE;
|
m_inPlay = false;
|
||||||
|
|
||||||
// Redraw the score box to update games won
|
// Redraw the score box to update games won
|
||||||
DisplayScore(dc);
|
DisplayScore(dc);
|
||||||
@@ -212,7 +212,7 @@ void Game::DoMove(wxDC& dc, Pile* src, Pile* dest)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// user cancelled the dialog - exit the app
|
// user cancelled the dialog - exit the app
|
||||||
((wxFrame*)canvas->GetParent())->Close(TRUE);
|
((wxFrame*)canvas->GetParent())->Close(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -315,7 +315,7 @@ void Game::Deal()
|
|||||||
m_totalScore += m_currentScore;
|
m_totalScore += m_currentScore;
|
||||||
}
|
}
|
||||||
m_currentScore = 0;
|
m_currentScore = 0;
|
||||||
m_inPlay = FALSE;
|
m_inPlay = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -524,21 +524,21 @@ void Game::LButtonDblClk(wxDC& dc, int x, int y)
|
|||||||
// i.e. m_pack, discard and bases are empty
|
// i.e. m_pack, discard and bases are empty
|
||||||
bool Game::HaveYouWon()
|
bool Game::HaveYouWon()
|
||||||
{
|
{
|
||||||
if (m_pack->GetTopCard()) return FALSE;
|
if (m_pack->GetTopCard()) return false;
|
||||||
if (m_discard->GetTopCard()) return FALSE;
|
if (m_discard->GetTopCard()) return false;
|
||||||
for(int i = 0; i < 10; i++)
|
for(int i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
if (m_bases[i]->GetTopCard()) return FALSE;
|
if (m_bases[i]->GetTopCard()) return false;
|
||||||
}
|
}
|
||||||
m_numWins++;
|
m_numWins++;
|
||||||
m_totalScore += m_currentScore;
|
m_totalScore += m_currentScore;
|
||||||
m_currentScore = 0;
|
m_currentScore = 0;
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// See whether the card under the cursor can be moved somewhere else
|
// See whether the card under the cursor can be moved somewhere else
|
||||||
// Returns TRUE if it can be moved, FALSE otherwise
|
// Returns 'true' if it can be moved, 'false' otherwise
|
||||||
bool Game::CanYouGo(int x, int y)
|
bool Game::CanYouGo(int x, int y)
|
||||||
{
|
{
|
||||||
Pile* pile = WhichPile(x, y);
|
Pile* pile = WhichPile(x, y);
|
||||||
@@ -553,7 +553,7 @@ bool Game::CanYouGo(int x, int y)
|
|||||||
{
|
{
|
||||||
if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
|
if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
|
||||||
{
|
{
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(i = 0; i < 10; i++)
|
for(i = 0; i < 10; i++)
|
||||||
@@ -562,12 +562,12 @@ bool Game::CanYouGo(int x, int y)
|
|||||||
m_bases[i]->AcceptCard(card) &&
|
m_bases[i]->AcceptCard(card) &&
|
||||||
m_bases[i] != pile)
|
m_bases[i] != pile)
|
||||||
{
|
{
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -642,12 +642,12 @@ void Game::LButtonUp(wxDC& dc, int x, int y)
|
|||||||
|
|
||||||
bool Game::DropCard(int x, int y, Pile* pile, Card* card)
|
bool Game::DropCard(int x, int y, Pile* pile, Card* card)
|
||||||
{
|
{
|
||||||
bool retval = FALSE;
|
bool retval = false;
|
||||||
if (pile->Overlap(x, y))
|
if (pile->Overlap(x, y))
|
||||||
{
|
{
|
||||||
if (pile->AcceptCard(card))
|
if (pile->AcceptCard(card))
|
||||||
{
|
{
|
||||||
retval = TRUE;
|
retval = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
@@ -843,20 +843,20 @@ Base::Base(int x, int y) : Pile(x, y, 0, 12)
|
|||||||
|
|
||||||
bool Base::AcceptCard(Card* card)
|
bool Base::AcceptCard(Card* card)
|
||||||
{
|
{
|
||||||
bool retval = FALSE;
|
bool retval = false;
|
||||||
|
|
||||||
if (m_topCard >= 0)
|
if (m_topCard >= 0)
|
||||||
{
|
{
|
||||||
if (m_cards[m_topCard]->GetSuit() == card->GetSuit() &&
|
if (m_cards[m_topCard]->GetSuit() == card->GetSuit() &&
|
||||||
m_cards[m_topCard]->GetPipValue() - 1 == card->GetPipValue())
|
m_cards[m_topCard]->GetPipValue() - 1 == card->GetPipValue())
|
||||||
{
|
{
|
||||||
retval = TRUE;
|
retval = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// pile is empty - ACCEPT
|
// pile is empty - ACCEPT
|
||||||
retval = TRUE;
|
retval = true;
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@@ -877,20 +877,20 @@ Foundation::Foundation(int x, int y) : Pile(x, y, 0, 0)
|
|||||||
|
|
||||||
bool Foundation::AcceptCard(Card* card)
|
bool Foundation::AcceptCard(Card* card)
|
||||||
{
|
{
|
||||||
bool retval = FALSE;
|
bool retval = false;
|
||||||
|
|
||||||
if (m_topCard >= 0)
|
if (m_topCard >= 0)
|
||||||
{
|
{
|
||||||
if (m_cards[m_topCard]->GetSuit() == card->GetSuit() &&
|
if (m_cards[m_topCard]->GetSuit() == card->GetSuit() &&
|
||||||
m_cards[m_topCard]->GetPipValue() + 1 == card->GetPipValue())
|
m_cards[m_topCard]->GetPipValue() + 1 == card->GetPipValue())
|
||||||
{
|
{
|
||||||
retval = TRUE;
|
retval = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (card->GetPipValue() == 1)
|
else if (card->GetPipValue() == 1)
|
||||||
{
|
{
|
||||||
// It's an ace and the pile is empty - ACCEPT
|
// It's an ace and the pile is empty - ACCEPT
|
||||||
retval = TRUE;
|
retval = true;
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@@ -224,9 +224,9 @@ bool Pile::CanCardLeave(Card* card)
|
|||||||
{
|
{
|
||||||
for (int i = 0; i <= m_topCard; i++)
|
for (int i = 0; i <= m_topCard; i++)
|
||||||
{
|
{
|
||||||
if (card == m_cards[i]) return TRUE;
|
if (card == m_cards[i]) return true;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate how far x, y is from top card in the pile
|
// Calculate how far x, y is from top card in the pile
|
||||||
@@ -294,9 +294,9 @@ bool Pile::Overlap(int x, int y)
|
|||||||
if (x >= cardX - Card::GetWidth() && x <= cardX + Card::GetWidth() &&
|
if (x >= cardX - Card::GetWidth() && x <= cardX + Card::GetWidth() &&
|
||||||
y >= cardY - Card::GetHeight() && y <= cardY + Card::GetHeight())
|
y >= cardY - Card::GetHeight() && y <= cardY + Card::GetHeight())
|
||||||
{
|
{
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -66,7 +66,7 @@ public:
|
|||||||
virtual Card* RemoveTopCard(wxDC& pDC, int xOffset = 0, int yOffset = 0);
|
virtual Card* RemoveTopCard(wxDC& pDC, int xOffset = 0, int yOffset = 0);
|
||||||
|
|
||||||
// Functions to add a card to the top of a pile
|
// Functions to add a card to the top of a pile
|
||||||
virtual bool AcceptCard(Card*) { return FALSE; }
|
virtual bool AcceptCard(Card*) { return false; }
|
||||||
virtual void AddCard(Card* card); // Add card to top of pile
|
virtual void AddCard(Card* card); // Add card to top of pile
|
||||||
virtual void AddCard(wxDC& pDC, Card* card); // Add card + redraw it
|
virtual void AddCard(wxDC& pDC, Card* card); // Add card + redraw it
|
||||||
void SetPos(int x,int y) {m_x = x;m_y = y;};
|
void SetPos(int x,int y) {m_x = x;m_y = y;};
|
||||||
|
@@ -44,15 +44,12 @@ PlayerSelectionDialog::PlayerSelectionDialog(
|
|||||||
wxWindow* parent,
|
wxWindow* parent,
|
||||||
ScoreFile* file
|
ScoreFile* file
|
||||||
) :
|
) :
|
||||||
wxDialog(parent, -1, _T("Player Selection"),
|
wxDialog(parent, wxID_ANY, _T("Player Selection"),
|
||||||
wxDefaultPosition, wxSize(320, 200),
|
wxDefaultPosition, wxDefaultSize,
|
||||||
wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE),
|
wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE),
|
||||||
m_scoreFile(file)
|
m_scoreFile(file)
|
||||||
{
|
{
|
||||||
// enable constraints
|
wxStaticText* msg = new wxStaticText(this, wxID_ANY, _T("Please select a name or type a new one:"));
|
||||||
SetAutoLayout (TRUE);
|
|
||||||
|
|
||||||
wxStaticText* msg = new wxStaticText(this, -1, _T("Please select a name or type a new one:"));
|
|
||||||
|
|
||||||
wxListBox* list = new wxListBox(
|
wxListBox* list = new wxListBox(
|
||||||
this, ID_LISTBOX,
|
this, ID_LISTBOX,
|
||||||
@@ -68,63 +65,24 @@ PlayerSelectionDialog::PlayerSelectionDialog(
|
|||||||
list->Append(players[i]);
|
list->Append(players[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_textField = new wxTextCtrl(this, -1, _T(""), wxDefaultPosition, wxDefaultSize, 0);
|
m_textField = new wxTextCtrl(this, wxID_ANY, _T(""), wxDefaultPosition, wxDefaultSize, 0);
|
||||||
|
|
||||||
m_OK = new wxButton(this, wxID_OK, _T("OK"));
|
m_OK = new wxButton(this, wxID_OK, _T("OK"));
|
||||||
m_cancel = new wxButton(this, wxID_CANCEL, _T("Cancel"));
|
m_cancel = new wxButton(this, wxID_CANCEL, _T("Cancel"));
|
||||||
|
|
||||||
wxLayoutConstraints* layout;
|
wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
|
||||||
|
button_sizer->Add( m_OK, 0, wxALL, 10 );
|
||||||
|
button_sizer->Add( m_cancel, 0, wxALL, 10 );
|
||||||
|
|
||||||
// Constrain the msg at the top of the window
|
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
|
||||||
layout = new wxLayoutConstraints;
|
topsizer->Add( msg, 0, wxALL , 10 );
|
||||||
layout->left.SameAs (this, wxLeft, 10);
|
topsizer->Add( list, 1, wxEXPAND | wxLEFT | wxRIGHT, 10 );
|
||||||
layout->top.SameAs (this, wxTop, 10);
|
topsizer->Add( m_textField, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10 );
|
||||||
layout->height.AsIs();
|
topsizer->Add( button_sizer, 0, wxALIGN_LEFT );
|
||||||
layout->width.AsIs();
|
|
||||||
msg->SetConstraints(layout);
|
|
||||||
|
|
||||||
// Constrain the OK button
|
SetSizer( topsizer );
|
||||||
layout = new wxLayoutConstraints;
|
|
||||||
layout->left.SameAs (this, wxLeft, 10);
|
|
||||||
layout->bottom.SameAs (this, wxBottom, 10);
|
|
||||||
layout->height.AsIs();
|
|
||||||
layout->width.AsIs();
|
|
||||||
m_OK->SetConstraints(layout);
|
|
||||||
|
|
||||||
// Constrain the OK button
|
topsizer->SetSizeHints( this );
|
||||||
layout = new wxLayoutConstraints;
|
|
||||||
layout->left.RightOf (m_OK, 10);
|
|
||||||
layout->bottom.SameAs (this, wxBottom, 10);
|
|
||||||
layout->height.AsIs();
|
|
||||||
layout->width.AsIs();
|
|
||||||
m_cancel->SetConstraints(layout);
|
|
||||||
|
|
||||||
// Constrain the Name text entry field
|
|
||||||
layout = new wxLayoutConstraints;
|
|
||||||
layout->left.SameAs (this, wxLeft, 10);
|
|
||||||
layout->right.SameAs (this, wxRight, 10);
|
|
||||||
layout->bottom.SameAs (m_OK, wxTop, 10);
|
|
||||||
layout->height.AsIs();
|
|
||||||
m_textField->SetConstraints(layout);
|
|
||||||
|
|
||||||
// Constrain the list of players
|
|
||||||
layout = new wxLayoutConstraints;
|
|
||||||
layout->left.SameAs (this, wxLeft, 10);
|
|
||||||
layout->right.SameAs (this, wxRight, 10);
|
|
||||||
layout->top.Below (msg, 10);
|
|
||||||
layout->bottom.SameAs (m_textField, wxTop, 10);
|
|
||||||
list->SetConstraints(layout);
|
|
||||||
|
|
||||||
wxString prevPlayer = m_scoreFile->GetPreviousPlayer();
|
|
||||||
if ((prevPlayer.Length() > 0) && (list->FindString(prevPlayer) != -1))
|
|
||||||
{
|
|
||||||
list->SetStringSelection(prevPlayer);
|
|
||||||
m_textField->SetValue(prevPlayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_textField->SetFocus();
|
|
||||||
|
|
||||||
Layout();
|
|
||||||
|
|
||||||
CentreOnParent();
|
CentreOnParent();
|
||||||
}
|
}
|
||||||
@@ -142,7 +100,7 @@ const wxString& PlayerSelectionDialog::GetPlayersName()
|
|||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
m_player = "";
|
m_player = "";
|
||||||
Show(TRUE);
|
Show(true);
|
||||||
*/
|
*/
|
||||||
return m_player;
|
return m_player;
|
||||||
}
|
}
|
||||||
|
@@ -30,10 +30,15 @@
|
|||||||
#include "scorefil.h"
|
#include "scorefil.h"
|
||||||
#include "scoredg.h"
|
#include "scoredg.h"
|
||||||
|
|
||||||
|
#define USE_GRID_FOR_SCORE 0
|
||||||
|
|
||||||
|
#if USE_GRID_FOR_SCORE
|
||||||
|
#include "wx/grid.h"
|
||||||
|
#else
|
||||||
class ScoreCanvas : public wxScrolledWindow
|
class ScoreCanvas : public wxScrolledWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ScoreCanvas(wxWindow* parent, ScoreFile* scoreFile);
|
ScoreCanvas(wxWindow* parent, ScoreFile* scoreFile, const wxPoint& pos, wxSize& size);
|
||||||
virtual ~ScoreCanvas();
|
virtual ~ScoreCanvas();
|
||||||
|
|
||||||
void OnDraw(wxDC& dc);
|
void OnDraw(wxDC& dc);
|
||||||
@@ -43,10 +48,10 @@ private:
|
|||||||
wxString m_text;
|
wxString m_text;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ScoreCanvas::ScoreCanvas(wxWindow* parent, ScoreFile* scoreFile, const wxPoint& pos, wxSize& size) :
|
||||||
ScoreCanvas::ScoreCanvas(wxWindow* parent, ScoreFile* scoreFile) :
|
wxScrolledWindow(parent, -1, pos, size, wxSUNKEN_BORDER)
|
||||||
wxScrolledWindow(parent)
|
|
||||||
{
|
{
|
||||||
|
SetBackgroundColour(*wxWHITE);
|
||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
m_font = wxTheFontList->FindOrCreateFont(12, wxROMAN, wxNORMAL, wxNORMAL);
|
m_font = wxTheFontList->FindOrCreateFont(12, wxROMAN, wxNORMAL, wxNORMAL);
|
||||||
#else
|
#else
|
||||||
@@ -124,45 +129,72 @@ void ScoreCanvas::OnDraw(wxDC& dc)
|
|||||||
if (*str) str++;
|
if (*str) str++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(ScoreDialog, wxDialog)
|
BEGIN_EVENT_TABLE(ScoreDialog, wxDialog)
|
||||||
EVT_CLOSE(ScoreDialog::OnCloseWindow)
|
EVT_CLOSE(ScoreDialog::OnCloseWindow)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
ScoreDialog::ScoreDialog(
|
ScoreDialog::ScoreDialog(wxWindow* parent, ScoreFile* file) :
|
||||||
wxWindow* parent,
|
wxDialog(parent, wxID_ANY, _("Scores"),
|
||||||
ScoreFile* file
|
wxDefaultPosition, wxSize(400, 300),
|
||||||
) :
|
|
||||||
wxDialog(parent, -1, _("Scores"),
|
|
||||||
wxDefaultPosition, wxSize(310, 200),
|
|
||||||
wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE),
|
wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE),
|
||||||
m_scoreFile(file)
|
m_scoreFile(file)
|
||||||
{
|
{
|
||||||
// enable constraints
|
// create grid with players
|
||||||
SetAutoLayout (TRUE);
|
wxArrayString players;
|
||||||
|
file->GetPlayerList(players);
|
||||||
|
|
||||||
ScoreCanvas* list = new ScoreCanvas(this, m_scoreFile);
|
wxSize sz = wxSize(400, 300);
|
||||||
m_OK = new wxButton(this, wxID_OK, _("OK"));
|
|
||||||
|
|
||||||
wxLayoutConstraints* layout;
|
#if USE_GRID_FOR_SCORE
|
||||||
|
wxGrid* list = new wxGrid(this, wxID_ANY, wxDefaultPosition, sz, 0);
|
||||||
|
list->CreateGrid(players.Count(), 4);
|
||||||
|
for (unsigned int i = 0; i < players.Count(); i++)
|
||||||
|
{
|
||||||
|
int wins, games, score;
|
||||||
|
wxString string_value;
|
||||||
|
|
||||||
// Constrain the OK button
|
file->ReadPlayersScore(players[i], wins, games, score);
|
||||||
layout = new wxLayoutConstraints;
|
int average = 0;
|
||||||
layout->left.SameAs (this, wxLeft, 10);
|
if (games > 0)
|
||||||
layout->bottom.SameAs (this, wxBottom, 10);
|
{
|
||||||
layout->height.AsIs();
|
average = (2 * score + games) / (2 * games);
|
||||||
layout->width.AsIs();
|
}
|
||||||
m_OK->SetConstraints(layout);
|
list->SetCellValue(i,0,players[i]);
|
||||||
|
string_value.Printf( _T("%u"), wins );
|
||||||
|
list->SetCellValue(i,1,string_value);
|
||||||
|
string_value.Printf( _T("%u"), games );
|
||||||
|
list->SetCellValue(i,2,string_value);
|
||||||
|
string_value.Printf( _T("%u"), average );
|
||||||
|
list->SetCellValue(i,3,string_value);
|
||||||
|
}
|
||||||
|
list->SetColLabelValue(0, _T("Players"));
|
||||||
|
list->SetColLabelValue(1, _T("Wins"));
|
||||||
|
list->SetColLabelValue(2, _T("Games"));
|
||||||
|
list->SetColLabelValue(3, _T("Score"));
|
||||||
|
list->SetEditable(false);
|
||||||
|
list->AutoSizeColumns();
|
||||||
|
list->AutoSizeRows();
|
||||||
|
list->SetRowLabelSize(0);
|
||||||
|
list->EnableDragRowSize(false);
|
||||||
|
list->EnableDragColSize(false);
|
||||||
|
list->EnableDragGridSize(false);
|
||||||
|
#else
|
||||||
|
ScoreCanvas* list = new ScoreCanvas(this, m_scoreFile, wxDefaultPosition, sz);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Constrain the list of players
|
// locate and resize with sizers
|
||||||
layout = new wxLayoutConstraints;
|
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
|
||||||
layout->left.SameAs (this, wxLeft, 10);
|
topsizer->Add( list, 1, wxALL|wxGROW, 10 );
|
||||||
layout->right.SameAs (this, wxRight, 10);
|
topsizer->Add( new wxButton(this, wxID_OK, _("OK")), 0, wxALIGN_CENTER_HORIZONTAL|wxALL , 10 );
|
||||||
layout->top.SameAs (this, wxTop, 10);
|
|
||||||
layout->bottom.SameAs (m_OK, wxTop, 10);
|
|
||||||
list->SetConstraints(layout);
|
|
||||||
|
|
||||||
Layout();
|
SetSizer( topsizer );
|
||||||
|
|
||||||
|
GetSizer()->Fit(this);
|
||||||
|
GetSizer()->SetSizeHints(this);
|
||||||
|
|
||||||
|
CentreOnParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
ScoreDialog::~ScoreDialog()
|
ScoreDialog::~ScoreDialog()
|
||||||
@@ -171,7 +203,7 @@ ScoreDialog::~ScoreDialog()
|
|||||||
|
|
||||||
void ScoreDialog::Display()
|
void ScoreDialog::Display()
|
||||||
{
|
{
|
||||||
Show(TRUE);
|
Show(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScoreDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
|
void ScoreDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
|
||||||
|
Reference in New Issue
Block a user