1998-07-24 15:43:32 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: forty.cpp
|
|
|
|
// Purpose: Forty Thieves patience game
|
|
|
|
// Author: Chris Breeze
|
|
|
|
// Modified by:
|
|
|
|
// Created: 21/07/97
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1993-1998 Chris Breeze
|
2004-06-02 05:14:59 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-07-24 15:43:32 -04:00
|
|
|
//---------------------------------------------------------------------------
|
2004-05-25 07:20:37 -04:00
|
|
|
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0
|
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 "canvas.h"
|
|
|
|
#include "forty.h"
|
2002-03-06 12:50:52 -05:00
|
|
|
#include "card.h"
|
1998-07-24 15:43:32 -04:00
|
|
|
#include "scoredg.h"
|
|
|
|
|
2002-06-12 09:19:08 -04:00
|
|
|
#if wxUSE_HTML
|
2004-07-23 04:56:51 -04:00
|
|
|
#include "wx/textfile.h"
|
2002-06-12 09:19:08 -04:00
|
|
|
#include "wx/html/htmlwin.h"
|
|
|
|
#endif
|
|
|
|
|
2005-01-31 13:18:18 -05:00
|
|
|
#include "wx/stockitem.h"
|
|
|
|
|
1998-07-24 15:43:32 -04:00
|
|
|
BEGIN_EVENT_TABLE(FortyFrame, wxFrame)
|
2005-01-31 13:18:18 -05:00
|
|
|
EVT_MENU(wxID_NEW, FortyFrame::NewGame)
|
2004-06-02 05:14:59 -04:00
|
|
|
EVT_MENU(wxID_EXIT, FortyFrame::Exit)
|
|
|
|
EVT_MENU(wxID_ABOUT, FortyFrame::About)
|
|
|
|
EVT_MENU(wxID_HELP_CONTENTS, FortyFrame::Help)
|
2005-01-31 13:18:18 -05:00
|
|
|
EVT_MENU(wxID_UNDO, FortyFrame::Undo)
|
|
|
|
EVT_MENU(wxID_REDO, FortyFrame::Redo)
|
2004-06-02 05:14:59 -04:00
|
|
|
EVT_MENU(SCORES, FortyFrame::Scores)
|
|
|
|
EVT_MENU(RIGHT_BUTTON_UNDO, FortyFrame::ToggleRightButtonUndo)
|
|
|
|
EVT_MENU(HELPING_HAND, FortyFrame::ToggleHelpingHand)
|
|
|
|
EVT_MENU(LARGE_CARDS, FortyFrame::ToggleCardSize)
|
1999-02-05 18:55:04 -05:00
|
|
|
EVT_CLOSE(FortyFrame::OnCloseWindow)
|
1998-07-24 15:43:32 -04:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
// Create a new application object
|
2004-06-02 05:14:59 -04:00
|
|
|
IMPLEMENT_APP (FortyApp)
|
1998-07-24 15:43:32 -04:00
|
|
|
|
|
|
|
wxColour* FortyApp::m_backgroundColour = 0;
|
|
|
|
wxColour* FortyApp::m_textColour = 0;
|
|
|
|
wxBrush* FortyApp::m_backgroundBrush = 0;
|
|
|
|
|
2002-04-07 17:12:45 -04:00
|
|
|
FortyApp::~FortyApp()
|
|
|
|
{
|
|
|
|
delete m_backgroundColour;
|
|
|
|
delete m_textColour;
|
|
|
|
delete m_backgroundBrush;
|
|
|
|
delete Card::m_symbolBmap;
|
|
|
|
delete Card::m_pictureBmap;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1998-07-24 15:43:32 -04:00
|
|
|
bool FortyApp::OnInit()
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
bool largecards = false;
|
2004-08-07 17:59:45 -04:00
|
|
|
#ifndef __WXWINCE__
|
|
|
|
m_helpFile = wxGetCwd() + wxFILE_SEP_PATH + wxT("about.htm");
|
|
|
|
if (!wxFileExists(m_helpFile))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
m_helpFile = wxPathOnly(argv[0]) + wxFILE_SEP_PATH + wxT("about.htm");
|
|
|
|
}
|
2004-03-23 16:23:17 -05:00
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
wxSize size(668,510);
|
2002-03-06 12:50:52 -05:00
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
if ((argc > 1) && (!wxStrcmp(argv[1],_T("-L"))))
|
|
|
|
{
|
|
|
|
largecards = true;
|
|
|
|
size = wxSize(1000,750);
|
|
|
|
}
|
2002-03-06 12:50:52 -05:00
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
FortyFrame* frame = new FortyFrame(
|
|
|
|
0,
|
|
|
|
_T("Forty Thieves"),
|
|
|
|
wxDefaultPosition,
|
|
|
|
size,
|
|
|
|
largecards
|
|
|
|
);
|
1998-07-24 15:43:32 -04:00
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
// Show the frame
|
|
|
|
frame->Show(true);
|
1998-07-24 15:43:32 -04:00
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
frame->GetCanvas()->ShowPlayerDialog();
|
2002-03-21 08:10:17 -05:00
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
return true;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
1998-12-09 12:43:07 -05:00
|
|
|
const wxColour& FortyApp::BackgroundColour()
|
1998-07-24 15:43:32 -04:00
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
if (!m_backgroundColour)
|
|
|
|
{
|
|
|
|
m_backgroundColour = new wxColour(0, 128, 0);
|
|
|
|
}
|
1998-12-09 12:43:07 -05:00
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
return *m_backgroundColour;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
1998-12-09 12:43:07 -05:00
|
|
|
const wxBrush& FortyApp::BackgroundBrush()
|
1998-07-24 15:43:32 -04:00
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
if (!m_backgroundBrush)
|
|
|
|
{
|
|
|
|
m_backgroundBrush = new wxBrush(BackgroundColour(), wxSOLID);
|
|
|
|
}
|
1998-12-09 12:43:07 -05:00
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
return *m_backgroundBrush;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
1998-12-09 12:43:07 -05:00
|
|
|
const wxColour& FortyApp::TextColour()
|
1998-07-24 15:43:32 -04:00
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
if (!m_textColour)
|
|
|
|
{
|
2006-06-07 09:26:00 -04:00
|
|
|
m_textColour = new wxColour(*wxBLACK);
|
2004-06-02 05:14:59 -04:00
|
|
|
}
|
1998-12-09 12:43:07 -05:00
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
return *m_textColour;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// My frame constructor
|
2004-03-23 16:23:17 -05:00
|
|
|
FortyFrame::FortyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos, const wxSize& size, bool largecards):
|
2004-06-02 05:14:59 -04:00
|
|
|
wxFrame(frame, wxID_ANY, title, pos, size)
|
1998-07-24 15:43:32 -04:00
|
|
|
{
|
1999-12-09 05:32:18 -05:00
|
|
|
#ifdef __WXMAC__
|
2004-06-02 05:14:59 -04:00
|
|
|
wxApp::s_macAboutMenuItemId = wxID_ABOUT ;
|
1999-12-09 05:32:18 -05:00
|
|
|
#endif
|
2004-06-02 05:14:59 -04:00
|
|
|
// set the icon
|
1998-07-24 15:43:32 -04:00
|
|
|
#ifdef __WXMSW__
|
2004-06-02 05:14:59 -04:00
|
|
|
SetIcon(wxIcon(_T("CardsIcon")));
|
1998-07-24 15:43:32 -04:00
|
|
|
#else
|
|
|
|
#ifdef GTK_TBD
|
2004-06-02 05:14:59 -04:00
|
|
|
SetIcon(wxIcon(Cards_bits, Cards_width, Cards_height));
|
1998-07-24 15:43:32 -04:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
// Make a menu bar
|
|
|
|
wxMenu* gameMenu = new wxMenu;
|
2005-01-31 13:18:18 -05:00
|
|
|
gameMenu->Append(wxID_NEW, wxGetStockLabel(wxID_NEW), _T("Start a new game"));
|
2004-06-02 05:14:59 -04:00
|
|
|
gameMenu->Append(SCORES, _T("&Scores..."), _T("Displays scores"));
|
2005-01-31 13:18:18 -05:00
|
|
|
gameMenu->Append(wxID_EXIT, wxGetStockLabel(wxID_EXIT), _T("Exits Forty Thieves"));
|
2004-06-02 05:14:59 -04:00
|
|
|
|
|
|
|
wxMenu* editMenu = new wxMenu;
|
2005-01-31 13:18:18 -05:00
|
|
|
editMenu->Append(wxID_UNDO, wxGetStockLabel(wxID_UNDO), _T("Undo the last move"));
|
|
|
|
editMenu->Append(wxID_REDO, wxGetStockLabel(wxID_REDO), _T("Redo a move that has been undone"));
|
2004-06-02 05:14:59 -04:00
|
|
|
|
|
|
|
wxMenu* optionsMenu = new wxMenu;
|
|
|
|
optionsMenu->Append(RIGHT_BUTTON_UNDO,
|
|
|
|
_T("&Right button undo"),
|
|
|
|
_T("Enables/disables right mouse button undo and redo"),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
optionsMenu->Append(HELPING_HAND,
|
|
|
|
_T("&Helping hand"),
|
|
|
|
_T("Enables/disables hand cursor when a card can be moved"),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
optionsMenu->Append(LARGE_CARDS,
|
|
|
|
_T("&Large cards"),
|
|
|
|
_T("Enables/disables large cards for high resolution displays"),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
optionsMenu->Check(HELPING_HAND, true);
|
|
|
|
optionsMenu->Check(RIGHT_BUTTON_UNDO, true);
|
|
|
|
optionsMenu->Check(LARGE_CARDS, largecards ? true : false);
|
|
|
|
|
|
|
|
wxMenu* helpMenu = new wxMenu;
|
|
|
|
helpMenu->Append(wxID_HELP_CONTENTS, _T("&Help Contents"), _T("Displays information about playing the game"));
|
|
|
|
helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About Forty Thieves"));
|
|
|
|
|
|
|
|
m_menuBar = new wxMenuBar;
|
|
|
|
m_menuBar->Append(gameMenu, _T("&Game"));
|
|
|
|
m_menuBar->Append(editMenu, _T("&Edit"));
|
|
|
|
m_menuBar->Append(optionsMenu, _T("&Options"));
|
|
|
|
m_menuBar->Append(helpMenu, _T("&Help"));
|
|
|
|
|
|
|
|
SetMenuBar(m_menuBar);
|
|
|
|
|
|
|
|
if (largecards)
|
|
|
|
Card::SetScale(1.3);
|
|
|
|
|
|
|
|
m_canvas = new FortyCanvas(this, wxDefaultPosition, size);
|
|
|
|
|
|
|
|
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
topsizer->Add( m_canvas, 1, wxEXPAND | wxALL, 0);
|
|
|
|
SetSizer( topsizer );
|
|
|
|
topsizer->SetSizeHints( this );
|
|
|
|
|
2004-07-19 05:39:38 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2004-06-02 05:14:59 -04:00
|
|
|
CreateStatusBar();
|
2004-07-19 05:39:38 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
1999-02-05 18:55:04 -05:00
|
|
|
void FortyFrame::OnCloseWindow(wxCloseEvent& event)
|
1998-07-24 15:43:32 -04:00
|
|
|
{
|
1999-02-12 03:22:29 -05:00
|
|
|
if (m_canvas->OnCloseCanvas() )
|
1999-02-05 18:55:04 -05:00
|
|
|
{
|
|
|
|
this->Destroy();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
event.Veto();
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FortyFrame::NewGame(wxCommandEvent&)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
m_canvas->NewGame();
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FortyFrame::Exit(wxCommandEvent&)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
Close(true);
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-03-23 03:57:45 -05:00
|
|
|
FortyFrame::Help(wxCommandEvent& event)
|
1998-07-24 15:43:32 -04:00
|
|
|
{
|
2002-06-12 09:19:08 -04:00
|
|
|
#if wxUSE_HTML
|
2004-08-07 17:59:45 -04:00
|
|
|
if (wxFileExists(wxGetApp().GetHelpFile()))
|
2002-06-12 09:19:08 -04:00
|
|
|
{
|
2004-03-23 16:23:17 -05:00
|
|
|
FortyAboutDialog dialog(this, wxID_ANY, wxT("Forty Thieves Instructions"));
|
2002-06-12 09:19:08 -04:00
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2004-03-23 03:57:45 -05:00
|
|
|
About(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FortyFrame::About(wxCommandEvent&)
|
|
|
|
{
|
2002-06-12 09:19:08 -04:00
|
|
|
wxMessageBox(
|
2002-12-22 14:57:17 -05:00
|
|
|
_T("Forty Thieves\n\n")
|
2004-03-23 03:57:45 -05:00
|
|
|
_T("A free card game written with the wxWidgets toolkit\n")
|
|
|
|
_T("Author: Chris Breeze (c) 1992-2004\n")
|
|
|
|
_T("email: chris@breezesys.com"),
|
2002-12-22 14:57:17 -05:00
|
|
|
_T("About Forty Thieves"),
|
2004-03-23 03:57:45 -05:00
|
|
|
wxOK|wxICON_INFORMATION, this
|
2002-06-12 09:19:08 -04:00
|
|
|
);
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
2004-03-23 03:57:45 -05:00
|
|
|
|
1998-07-24 15:43:32 -04:00
|
|
|
void
|
|
|
|
FortyFrame::Undo(wxCommandEvent&)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
m_canvas->Undo();
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FortyFrame::Redo(wxCommandEvent&)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
m_canvas->Redo();
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FortyFrame::Scores(wxCommandEvent&)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
m_canvas->UpdateScores();
|
|
|
|
ScoreDialog scores(this, m_canvas->GetScoreFile());
|
|
|
|
scores.Display();
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FortyFrame::ToggleRightButtonUndo(wxCommandEvent& event)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
bool checked = m_menuBar->IsChecked(event.GetId());
|
|
|
|
m_canvas->EnableRightButtonUndo(checked);
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FortyFrame::ToggleHelpingHand(wxCommandEvent& event)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
bool checked = m_menuBar->IsChecked(event.GetId());
|
|
|
|
m_canvas->EnableHelpingHand(checked);
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
2002-03-06 12:50:52 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
FortyFrame::ToggleCardSize(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
bool checked = m_menuBar->IsChecked(event.GetId());
|
|
|
|
Card::SetScale(checked ? 1.3 : 1);
|
|
|
|
m_canvas->LayoutGame();
|
|
|
|
m_canvas->Refresh();
|
|
|
|
}
|
|
|
|
|
2002-06-12 09:19:08 -04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// stAboutDialog
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
FortyAboutDialog::FortyAboutDialog( wxWindow *parent, wxWindowID id, const wxString &title,
|
|
|
|
const wxPoint &position, const wxSize& size, long style ) :
|
|
|
|
wxDialog( parent, id, title, position, size, style )
|
|
|
|
{
|
|
|
|
AddControls(this);
|
|
|
|
|
|
|
|
Centre(wxBOTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FortyAboutDialog::AddControls(wxWindow* parent)
|
|
|
|
{
|
|
|
|
#if wxUSE_HTML
|
|
|
|
wxString htmlText;
|
2004-08-07 17:59:45 -04:00
|
|
|
wxString htmlFile = wxGetApp().GetHelpFile();
|
2002-06-12 09:19:08 -04:00
|
|
|
|
|
|
|
{
|
2004-07-23 04:56:51 -04:00
|
|
|
wxTextFile file(htmlFile);
|
|
|
|
if (file.Exists())
|
2002-06-12 09:19:08 -04:00
|
|
|
{
|
2004-07-23 04:56:51 -04:00
|
|
|
file.Open();
|
2004-10-05 11:38:40 -04:00
|
|
|
for ( htmlText = file.GetFirstLine();
|
|
|
|
!file.Eof();
|
2004-07-23 04:56:51 -04:00
|
|
|
htmlText << file.GetNextLine() << _T("\n") ) ;
|
2002-06-12 09:19:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-31 13:18:18 -05:00
|
|
|
if (htmlText.empty())
|
2002-06-12 09:19:08 -04:00
|
|
|
{
|
|
|
|
htmlText.Printf(wxT("<html><head><title>Warning</title></head><body><P>Sorry, could not find resource for About dialog<P></body></html>"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Customize the HTML
|
2002-12-22 14:57:17 -05:00
|
|
|
htmlText.Replace(wxT("$DATE$"), _T(__DATE__));
|
2002-06-12 09:19:08 -04:00
|
|
|
|
|
|
|
wxSize htmlSize(400, 290);
|
|
|
|
|
|
|
|
// Note: in later versions of wxWin this will be fixed so wxRAISED_BORDER
|
|
|
|
// does the right thing. Meanwhile, this is a workaround.
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
long borderStyle = wxDOUBLE_BORDER;
|
|
|
|
#else
|
|
|
|
long borderStyle = wxRAISED_BORDER;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
wxHtmlWindow* html = new wxHtmlWindow(this, ID_ABOUT_HTML_WINDOW, wxDefaultPosition, htmlSize, borderStyle);
|
|
|
|
html -> SetBorders(10);
|
|
|
|
html -> SetPage(htmlText);
|
2004-10-05 11:38:40 -04:00
|
|
|
|
2002-06-12 09:19:08 -04:00
|
|
|
//// Start of sizer-based control creation
|
|
|
|
|
|
|
|
wxSizer *item0 = new wxBoxSizer( wxVERTICAL );
|
|
|
|
|
|
|
|
wxWindow *item1 = parent->FindWindow( ID_ABOUT_HTML_WINDOW );
|
|
|
|
wxASSERT( item1 );
|
|
|
|
item0->Add( item1, 0, wxALIGN_CENTRE|wxALL, 5 );
|
|
|
|
|
2005-01-31 13:18:18 -05:00
|
|
|
wxButton *item2 = new wxButton( parent, wxID_CLOSE );
|
2002-06-12 09:19:08 -04:00
|
|
|
item2->SetDefault();
|
|
|
|
item2->SetFocus();
|
2006-08-24 12:33:28 -04:00
|
|
|
SetAffirmativeId(wxID_CLOSE);
|
2002-06-12 09:19:08 -04:00
|
|
|
|
|
|
|
item0->Add( item2, 0, wxALIGN_RIGHT|wxALL, 5 );
|
|
|
|
|
|
|
|
parent->SetSizer( item0 );
|
|
|
|
parent->Layout();
|
|
|
|
item0->Fit( parent );
|
|
|
|
item0->SetSizeHints( parent );
|
|
|
|
#endif
|
|
|
|
|
2004-03-23 16:23:17 -05:00
|
|
|
return true;
|
2002-06-12 09:19:08 -04:00
|
|
|
}
|