2004-04-08 09:43:06 +00:00
/* Eliot */
/* Copyright (C) 1999 Antoine Fraboulet */
/* */
2005-12-26 15:28:57 +00:00
/* This file is part of Eliot. */
/* */
/* Eliot is free software; you can redistribute it and/or modify */
2004-04-08 09:43:06 +00:00
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License, or */
/* (at your option) any later version. */
/* */
2005-12-26 15:28:57 +00:00
/* Eliot is distributed in the hope that it will be useful, */
2004-04-08 09:43:06 +00:00
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program; if not, write to the Free Software */
2005-10-23 14:53:42 +00:00
/* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
2004-04-08 09:43:06 +00:00
2005-12-26 15:28:57 +00:00
/**
* \ file mainframe . cc
* \ brief Main frame for the Eliot GUI
* \ author Antoine Fraboulet
* \ date 2005
*/
2008-01-08 13:52:32 +00:00
# include "config.h"
2004-04-08 09:43:06 +00:00
# include <stdlib.h>
# include <stdio.h>
# include <iostream>
2005-02-05 11:14:56 +00:00
# include <fstream>
2008-01-08 13:52:32 +00:00
# include <exception>
2004-04-08 09:43:06 +00:00
using namespace std ;
2005-01-01 15:42:55 +00:00
# include "wx/intl.h"
# include "wx/menu.h"
# include "wx/statusbr.h"
# include "wx/sizer.h"
# include "wx/filedlg.h"
# include "wx/msgdlg.h"
2004-04-08 09:43:06 +00:00
# include "ewx.h"
# include "dic.h"
2005-03-29 07:00:39 +00:00
# include "game.h"
2008-01-08 13:52:32 +00:00
# include "training.h"
2005-03-29 07:00:39 +00:00
# include "game_factory.h"
2005-11-05 15:48:59 +00:00
# include "player.h"
2004-04-08 09:43:06 +00:00
# include "configdb.h"
# include "confdimdlg.h"
# include "confsearch.h"
# include "printout.h"
# include "mainframe.h"
# ifdef ENABLE_SAVE_POSTSCRIPT
# include "wx/dcps.h"
# endif
enum
{
2005-02-05 11:14:56 +00:00
Menu_Game_New = 1000 ,
2008-01-08 13:52:32 +00:00
Menu_Game_NewJoker ,
2005-02-05 11:14:56 +00:00
Menu_Game_Open ,
Menu_Game_Save ,
Menu_Game_Print ,
Menu_Game_PrintPreview ,
Menu_Game_PrintPS ,
Menu_Conf_Game = 2000 ,
Menu_Conf_Game_Dic ,
Menu_Conf_Game_Tiles ,
Menu_Conf_Game_Search ,
Menu_Conf_Print ,
Menu_Conf_Aspect = 2100 ,
2005-12-26 15:28:57 +00:00
Menu_Conf_Tile ,
Menu_Conf_Aspect_BoardColour_DrawTiles ,
2005-02-05 11:14:56 +00:00
Menu_Conf_Aspect_Font ,
Menu_Conf_Aspect_Font_Search = 2110 ,
Menu_Conf_Aspect_Font_Board = 2111 ,
Menu_Conf_Aspect_Font_Default = 2112 ,
Menu_Conf_Aspect_BoardColour = 2200 ,
Menu_Conf_Aspect_BoardColour_Lines = 2201 ,
Menu_Conf_Aspect_BoardColour_Wx2 = 2202 ,
Menu_Conf_Aspect_BoardColour_Wx3 = 2203 ,
Menu_Conf_Aspect_BoardColour_Lx2 = 2204 ,
Menu_Conf_Aspect_BoardColour_Lx3 = 2205 ,
Menu_Conf_Aspect_BoardColour_Background = 2206 ,
Menu_Conf_Aspect_BoardColour_Letters = 2207 ,
Menu_Conf_Aspect_BoardColour_TestLetters = 2208 ,
2005-12-26 15:28:57 +00:00
Menu_Conf_Aspect_BoardColour_TileBack = 2209 ,
Menu_Conf_Aspect_BoardColour_TestTileBack = 2210 ,
Menu_Conf_Aspect_BoardColour_Default = 2211 ,
2004-04-08 09:43:06 +00:00
# define IDBASE 3300
2005-02-05 11:14:56 +00:00
Menu_ShowVerif = ( IDBASE + ID_Frame_Verif ) ,
Menu_ShowSearch = ( IDBASE + ID_Frame_Search ) ,
Menu_ShowPlus1 = ( IDBASE + ID_Frame_Plus1 ) ,
Menu_ShowRacc = ( IDBASE + ID_Frame_Racc ) ,
Menu_ShowBenj = ( IDBASE + ID_Frame_Benj ) ,
Menu_ShowBag = ( IDBASE + ID_Frame_Bag ) ,
2005-12-26 22:59:57 +00:00
Menu_ShowBoard = ( IDBASE + ID_Frame_Board ) ,
Menu_ShowGame = ( IDBASE + ID_Frame_Game ) ,
Menu_ShowResult = ( IDBASE + ID_Frame_Result ) ,
2005-02-05 11:14:56 +00:00
Button_SetRack = 10000 ,
Button_SetNew ,
Button_SetManual ,
Button_Search ,
Button_Play ,
Button_PlayBack ,
ListCtrl_ID = 11000 ,
Rack_ID ,
2008-01-08 13:52:32 +00:00
Status_ID
2004-04-08 09:43:06 +00:00
} ;
BEGIN_EVENT_TABLE ( MainFrame , wxFrame )
2005-02-05 11:14:56 +00:00
//
EVT_MENU ( Menu_Game_New , MainFrame : : OnMenuGameNew )
2008-01-08 13:52:32 +00:00
EVT_MENU ( Menu_Game_NewJoker , MainFrame : : OnMenuGameNew )
2005-02-05 11:14:56 +00:00
EVT_MENU ( Menu_Game_Open , MainFrame : : OnMenuGameOpen )
EVT_MENU ( Menu_Game_Save , MainFrame : : OnMenuGameSave )
EVT_MENU ( Menu_Game_Print , MainFrame : : OnMenuGamePrint )
EVT_MENU ( Menu_Game_PrintPreview , MainFrame : : OnMenuGamePrintPreview )
EVT_MENU ( Menu_Game_PrintPS , MainFrame : : OnMenuGamePrintPS )
2008-01-08 13:52:32 +00:00
EVT_MENU ( wxID_EXIT , MainFrame : : OnMenuGameQuit )
2005-02-05 11:14:56 +00:00
//
EVT_MENU ( Menu_Conf_Game_Dic , MainFrame : : OnMenuConfGameDic )
EVT_MENU ( Menu_Conf_Game_Search , MainFrame : : OnMenuConfGameSearch )
//
EVT_MENU ( Menu_Conf_Print , MainFrame : : OnMenuConfPrint )
//
EVT_MENU_RANGE ( Menu_Conf_Aspect_Font_Search , Menu_Conf_Aspect_Font_Default , MainFrame : : OnMenuConfAspectFont )
EVT_MENU_RANGE ( Menu_Conf_Aspect_BoardColour_Lines , Menu_Conf_Aspect_BoardColour_Default , MainFrame : : OnMenuConfAspectBoardColour )
2005-12-26 22:59:57 +00:00
EVT_MENU_RANGE ( Menu_ShowVerif , Menu_ShowResult , MainFrame : : OnMenuShowFrame )
2005-02-05 11:14:56 +00:00
//
2008-01-08 13:52:32 +00:00
EVT_MENU ( wxID_ABOUT , MainFrame : : OnMenuHelpAbout )
2005-02-05 11:14:56 +00:00
//
EVT_BUTTON ( Button_Play , MainFrame : : OnPlay )
EVT_BUTTON ( Button_SetRack , MainFrame : : OnSetRack )
EVT_BUTTON ( Button_SetNew , MainFrame : : OnSetRack )
EVT_BUTTON ( Button_Search , MainFrame : : OnSearch )
EVT_BUTTON ( Button_PlayBack , MainFrame : : OnPlay )
//
2006-01-01 19:33:51 +00:00
EVT_TEXT_ENTER ( Rack_ID , MainFrame : : OnTextEnter )
2005-02-05 11:14:56 +00:00
//
EVT_CLOSE ( MainFrame : : OnCloseWindow )
//
2006-01-01 19:33:51 +00:00
//EVT_MENU(Menu_Help, MainFrame::OnMenuHelp)
2004-04-08 09:43:06 +00:00
END_EVENT_TABLE ( )
2005-12-26 22:59:57 +00:00
// ******************************
//
// ******************************
2008-01-08 13:52:32 +00:00
MainFrame : : MainFrame ( wxPoint __UNUSED__ pos_ , wxSize size_ )
: wxFrame ( ( wxFrame * ) NULL , - 1 , wxT ( APPNAME ) , wxPoint ( - 1 , - 1 ) ,
size_ , wxDEFAULT_FRAME_STYLE , wxT ( APPNAME ) ) ,
m_dic ( NULL ) , m_game ( NULL )
2004-04-08 09:43:06 +00:00
{
2006-08-11 22:17:54 +00:00
# if defined(ENABLE_RESLIST_IN_MAIN)
2005-12-26 22:59:57 +00:00
reslist = NULL ;
2006-08-11 22:17:54 +00:00
# endif
2005-12-26 22:59:57 +00:00
statusbar = NULL ;
2008-01-08 13:52:32 +00:00
for ( int i = 0 ; i < MAX_FRAME_ID ; i + + )
auxframes_ptr [ i ] = NULL ;
2005-12-26 22:59:57 +00:00
wxBoxSizer * listsizer = new wxBoxSizer ( wxVERTICAL ) ;
2005-02-05 11:14:56 +00:00
rack = new wxTextCtrl ( this , Rack_ID , wxU ( " " ) , wxPoint ( - 1 , - 1 ) , wxSize ( - 1 , - 1 ) , wxTE_PROCESS_ENTER ) ;
2008-01-08 13:52:32 +00:00
listsizer - > Add ( rack , 0 , wxEXPAND | wxALL , 1 ) ;
rack - > SetToolTip ( _ ( " Rack " ) ) ;
rack - > Enable ( false ) ;
2005-12-26 22:59:57 +00:00
# ifdef ENABLE_RESLIST_IN_MAIN
reslist = new GfxResult ( this , ( MainFrame * ) this , m_game ) ;
listsizer - > Add ( reslist , 1 , wxEXPAND | wxLEFT | wxRIGHT , 1 ) ;
2004-04-08 09:43:06 +00:00
# endif
2005-02-05 11:14:56 +00:00
InitMenu ( ) ;
statusbar = CreateStatusBar ( 2 , 0 , Status_ID ) ;
int ww [ 2 ] = { - 1 , 160 } ;
statusbar - > SetStatusWidths ( 2 , ww ) ;
UpdateStatusBar ( ) ;
2008-01-08 13:52:32 +00:00
b_rackrandomset = new wxButton ( this , Button_SetRack , _ ( " Rack " ) ) ;
2006-08-11 22:17:54 +00:00
b_rackrandomnew = new wxButton ( this , Button_SetNew , _ ( " Complement " ) ) ;
2008-01-08 13:52:32 +00:00
b_search = new wxButton ( this , Button_Search , _ ( " Search " ) ) ;
b_back = new wxButton ( this , Button_PlayBack , _ ( " Back " ) ) ;
b_play = new wxButton ( this , Button_Play , _ ( " Play " ) ) ;
b_rackrandomset - > SetToolTip ( _ ( " Random rack " ) ) ;
b_rackrandomset - > Enable ( false ) ;
b_rackrandomnew - > SetToolTip ( _ ( " Random complement of the rack " ) ) ;
b_rackrandomnew - > Enable ( false ) ;
b_search - > SetToolTip ( _ ( " Search with the current rack " ) ) ;
b_search - > Enable ( false ) ;
b_back - > SetToolTip ( _ ( " Go back one turn " ) ) ;
b_back - > Enable ( false ) ;
b_play - > SetToolTip ( _ ( " Play the selected word " ) ) ;
b_play - > Enable ( false ) ;
2005-02-05 11:14:56 +00:00
wxBoxSizer * buttonsizer = new wxBoxSizer ( wxHORIZONTAL ) ;
buttonsizer - > Add ( b_rackrandomset , 1 , wxEXPAND | wxTOP | wxBOTTOM | wxLEFT , 1 ) ;
buttonsizer - > Add ( b_rackrandomnew , 1 , wxEXPAND | wxTOP | wxBOTTOM , 1 ) ;
buttonsizer - > Add ( b_search , 1 , wxEXPAND | wxTOP | wxBOTTOM , 1 ) ;
buttonsizer - > Add ( b_back , 1 , wxEXPAND | wxTOP | wxBOTTOM , 1 ) ;
buttonsizer - > Add ( b_play , 1 , wxEXPAND | wxTOP | wxBOTTOM | wxRIGHT , 1 ) ;
wxBoxSizer * mainsizer = new wxBoxSizer ( wxVERTICAL ) ;
mainsizer - > Add ( listsizer , 1 , wxEXPAND | wxVERTICAL , 0 ) ;
mainsizer - > Add ( buttonsizer , 0 , wxEXPAND , 0 ) ;
SetAutoLayout ( TRUE ) ;
SetSizer ( mainsizer ) ;
mainsizer - > Fit ( this ) ;
mainsizer - > SetSizeHints ( this ) ;
SetClientSize ( size_ ) ;
Move ( config . getFramePos ( wxT ( APPNAME ) ) ) ;
2005-03-29 07:00:39 +00:00
2008-01-10 10:23:36 +00:00
wxString dicpath = config . getDicPath ( ) ;
try
{
Dictionary * dic = new Dictionary ( dicpath . mb_str ( ) . data ( ) ) ;
m_dic = dic ;
m_game = GameFactory : : Instance ( ) - > createTraining ( * m_dic ) ;
if ( m_game )
{
m_game - > start ( ) ;
}
}
catch ( std : : exception & e )
{
wxCommandEvent event ;
// This will also start a new training game indirectly
OnMenuConfGameDic ( event ) ;
}
2005-03-29 07:00:39 +00:00
InitFrames ( ) ;
2004-04-08 09:43:06 +00:00
}
2005-12-26 22:59:57 +00:00
// ******************************
//
// ******************************
2004-04-08 09:43:06 +00:00
MainFrame : : ~ MainFrame ( )
{
2005-02-05 11:14:56 +00:00
config . setFramePos ( wxT ( APPNAME ) , GetPosition ( ) ) ;
config . setFrameSize ( wxT ( APPNAME ) , GetClientSize ( ) ) ;
2004-04-08 09:43:06 +00:00
2005-03-29 07:00:39 +00:00
if ( m_game ! = NULL )
2008-01-08 13:52:32 +00:00
{
GameFactory : : Instance ( ) - > releaseGame ( * m_game ) ;
m_game = NULL ;
}
delete m_dic ;
2004-04-08 09:43:06 +00:00
}
2005-12-26 22:59:57 +00:00
// ******************************
//
// ******************************
2004-04-08 09:43:06 +00:00
void
MainFrame : : InitMenu ( )
{
2005-02-05 11:14:56 +00:00
// menus
wxMenu * menu_game = new wxMenu ;
2008-01-12 20:42:25 +00:00
menu_game - > Append ( Menu_Game_New , _ ( " &New game \t Ctrl+N " ) , _ ( " Start a new game " ) ) ;
menu_game - > Append ( Menu_Game_NewJoker , _ ( " New &joker game \t Ctrl+J " ) , _ ( " Start a new joker game " ) ) ;
2005-02-05 11:14:56 +00:00
menu_game - > AppendSeparator ( ) ;
2008-01-12 20:42:25 +00:00
menu_game - > Append ( Menu_Game_Open , _ ( " &Load... \t Ctrl+L " ) , _ ( " Load a game " ) ) ;
menu_game - > Append ( Menu_Game_Save , _ ( " &Save as... \t Ctrl+S " ) , _ ( " Save the current game " ) ) ;
2005-02-05 11:14:56 +00:00
menu_game - > AppendSeparator ( ) ;
2008-01-12 20:42:25 +00:00
menu_game - > Append ( Menu_Game_Print , _ ( " &Print... \t Ctrl+P " ) , _ ( " Print this game " ) ) ;
2008-01-08 13:52:32 +00:00
menu_game - > Append ( Menu_Game_PrintPreview , _ ( " Print pre&view... " ) , _ ( " Print preview of the game " ) ) ;
# ifdef ENABLE_SAVE_POSTSCRIPT
menu_game - > Append ( Menu_Game_PrintPS , _ ( " Print in PostS&cript... " ) , _ ( " Print in a PostScript file " ) ) ;
2004-04-08 09:43:06 +00:00
# endif
2008-01-08 13:52:32 +00:00
menu_game - > AppendSeparator ( ) ;
2008-01-12 20:42:25 +00:00
menu_game - > Append ( wxID_EXIT , _ ( " &Quit \t Ctrl+Q " ) , _ ( " Quit Eliot " ) ) ;
2005-02-05 11:14:56 +00:00
//
wxMenu * menu_conf_game = new wxMenu ;
2008-01-12 20:42:25 +00:00
menu_conf_game - > Append ( Menu_Conf_Game_Dic , _ ( " &Dictionary... \t Ctrl+D " ) , _ ( " Choose a dictionary " ) ) ;
2008-01-08 13:52:32 +00:00
menu_conf_game - > Append ( Menu_Conf_Game_Search , _ ( " &Search... " ) , _ ( " Search options " ) ) ;
2005-12-26 15:28:57 +00:00
//
2005-02-05 11:14:56 +00:00
wxMenu * menu_conf_board_colour = new wxMenu ;
2008-01-08 13:52:32 +00:00
menu_conf_board_colour - > Append ( Menu_Conf_Aspect_BoardColour_Background , _ ( " &Background... " ) , _ ( " Background color " ) ) ;
menu_conf_board_colour - > Append ( Menu_Conf_Aspect_BoardColour_Lines , _ ( " L&ines... " ) , _ ( " Color of the lines " ) ) ;
2005-02-05 11:14:56 +00:00
menu_conf_board_colour - > AppendSeparator ( ) ;
2008-01-08 13:52:32 +00:00
menu_conf_board_colour - > Append ( Menu_Conf_Aspect_BoardColour_Letters , _ ( " &Played letters... " ) , _ ( " Color of the letters played on the board " ) ) ;
menu_conf_board_colour - > Append ( Menu_Conf_Aspect_BoardColour_TestLetters , _ ( " &Temporary letters... " ) , _ ( " Color of the letters of the temporary word " ) ) ;
menu_conf_board_colour - > Append ( Menu_Conf_Aspect_BoardColour_TileBack , _ ( " B&ackground of played letters... " ) , _ ( " Background color of the letters played on the board " ) ) ;
menu_conf_board_colour - > Append ( Menu_Conf_Aspect_BoardColour_TestTileBack , _ ( " Ba&ckground of temporary letters... " ) , _ ( " Background color of the temporary letters on the board " ) ) ;
2005-02-05 11:14:56 +00:00
menu_conf_board_colour - > AppendSeparator ( ) ;
2008-01-08 13:52:32 +00:00
menu_conf_board_colour - > Append ( Menu_Conf_Aspect_BoardColour_Wx2 , _ ( " Double &letter... " ) , _ ( " Color of the \" double letter \" squares " ) ) ;
menu_conf_board_colour - > Append ( Menu_Conf_Aspect_BoardColour_Wx3 , _ ( " Triple l&etter... " ) , _ ( " Color of the \" triple letter \" squares " ) ) ;
menu_conf_board_colour - > Append ( Menu_Conf_Aspect_BoardColour_Lx2 , _ ( " Double &word... " ) , _ ( " Color of the \" double word \" squares " ) ) ;
menu_conf_board_colour - > Append ( Menu_Conf_Aspect_BoardColour_Lx3 , _ ( " Triple w&ord... " ) , _ ( " Color of the \" triple word \" squares " ) ) ;
2005-02-05 11:14:56 +00:00
menu_conf_board_colour - > AppendSeparator ( ) ;
2008-01-08 13:52:32 +00:00
menu_conf_board_colour - > Append ( Menu_Conf_Aspect_BoardColour_Default , _ ( " &Default colors " ) , _ ( " Restore the default colors " ) ) ;
2005-02-05 11:14:56 +00:00
//
wxMenu * menu_conf_board_font = new wxMenu ;
2008-01-08 13:52:32 +00:00
menu_conf_board_font - > Append ( Menu_Conf_Aspect_Font_Search , _ ( " &Search letters... " ) , _ ( " Font for the search " ) ) ;
2005-02-05 11:14:56 +00:00
//
wxMenu * menu_conf = new wxMenu ;
2008-01-08 13:52:32 +00:00
menu_conf - > Append ( Menu_Conf_Game , _ ( " &Game " ) , menu_conf_game , _ ( " Configuration of the game " ) ) ;
menu_conf - > Append ( Menu_Conf_Aspect_Font , _ ( " &Fonts " ) , menu_conf_board_font , _ ( " Configuration of the fonts " ) ) ;
menu_conf - > Append ( Menu_Conf_Aspect_BoardColour , _ ( " &Colors " ) , menu_conf_board_colour , _ ( " Configuration of the colors " ) ) ;
menu_conf - > Append ( Menu_Conf_Print , _ ( " &Printing... " ) , _ ( " Configuration of the printing parameters " ) ) ;
2005-02-05 11:14:56 +00:00
//
wxMenu * menu_frame = new wxMenu ;
2008-01-08 13:52:32 +00:00
menu_frame - > AppendCheckItem ( Menu_ShowBoard , _ ( " &Board " ) , _ ( " Game board " ) ) ;
2008-01-12 20:42:25 +00:00
menu_frame - > AppendCheckItem ( Menu_ShowBag , _ ( " Ba&g \t Ctrl+B " ) , _ ( " Remaining letters in the bag " ) ) ;
2008-01-08 13:52:32 +00:00
menu_frame - > AppendCheckItem ( Menu_ShowVerif , _ ( " &Check " ) , _ ( " Check a word in the dictionary " ) ) ;
menu_frame - > AppendCheckItem ( Menu_ShowSearch , _ ( " &Search " ) , _ ( " Search in the dictionary " ) ) ;
2005-02-05 11:14:56 +00:00
menu_frame - > AppendSeparator ( ) ;
2008-01-08 13:52:32 +00:00
menu_frame - > AppendCheckItem ( Menu_ShowPlus1 , _ ( " &Rack + 1 " ) , _ ( " Letters of the rack plus one " ) ) ;
2008-01-12 20:42:25 +00:00
menu_frame - > AppendCheckItem ( Menu_ShowRacc , _ ( " &Extensions " ) , _ ( " One-letter extensions on a word of the search " ) ) ;
menu_frame - > AppendCheckItem ( Menu_ShowBenj , _ ( " &Benjamins " ) , _ ( " Benjamins (3-letter extensions) on a word of the search " ) ) ;
2005-02-05 11:14:56 +00:00
menu_frame - > AppendSeparator ( ) ;
2008-01-12 20:42:25 +00:00
menu_frame - > AppendCheckItem ( Menu_ShowGame , _ ( " Game &history \t Ctrl+H " ) , _ ( " Game history " ) ) ;
2005-12-26 22:59:57 +00:00
# ifndef ENABLE_RESLIST_IN_MAIN
2008-01-08 13:52:32 +00:00
menu_frame - > Append ( Menu_ShowResult , _ ( " R&esults " ) , _ ( " Results " ) ) ;
2005-12-26 22:59:57 +00:00
# endif
2005-02-05 11:14:56 +00:00
//
2008-01-08 13:52:32 +00:00
wxMenu * menu_help = new wxMenu ;
menu_help - > Append ( wxID_ABOUT , _ ( " &About... " ) , _ ( " About Eliot " ) ) ;
2005-02-05 11:14:56 +00:00
//
wxMenuBar * menu_bar = new wxMenuBar ;
2008-01-08 13:52:32 +00:00
menu_bar - > Append ( menu_game , _ ( " &Game " ) ) ;
menu_bar - > Append ( menu_conf , _ ( " &Settings " ) ) ;
menu_bar - > Append ( menu_frame , _ ( " &Windows " ) ) ;
menu_bar - > Append ( menu_help , _ ( " &Help " ) ) ;
2005-02-05 11:14:56 +00:00
SetMenuBar ( menu_bar ) ;
2004-04-08 09:43:06 +00:00
}
2005-12-26 22:59:57 +00:00
// *******************
2008-01-08 13:52:32 +00:00
//
2005-12-26 22:59:57 +00:00
// *******************
2004-04-08 09:43:06 +00:00
void
MainFrame : : OnCloseWindow ( wxCloseEvent & )
{
2005-02-05 11:14:56 +00:00
this - > Destroy ( ) ;
2004-04-08 09:43:06 +00:00
}
2005-12-26 22:59:57 +00:00
// *******************
// NEW
// *******************
2004-04-08 09:43:06 +00:00
void
2008-01-08 13:52:32 +00:00
MainFrame : : OnMenuGameNew ( wxCommandEvent & event )
2004-04-08 09:43:06 +00:00
{
2005-02-05 11:14:56 +00:00
if ( m_dic = = NULL )
2008-01-08 13:52:32 +00:00
{
wxMessageBox ( _ ( " No dictionary selected " ) , _ ( " Eliot: error " ) ,
2005-03-29 07:00:39 +00:00
wxICON_INFORMATION | wxOK ) ;
2005-02-05 11:14:56 +00:00
return ;
2008-01-08 13:52:32 +00:00
}
2005-03-29 07:00:39 +00:00
2006-08-11 22:17:54 +00:00
// TODO("selection du type de partie dans OnMenuGameNew\n");
2005-12-26 22:59:57 +00:00
2005-03-29 07:00:39 +00:00
if ( m_game ! = NULL )
2008-01-08 13:52:32 +00:00
{
GameFactory : : Instance ( ) - > releaseGame ( * m_game ) ;
m_game = NULL ;
}
m_game = GameFactory : : Instance ( ) - > createTraining ( * m_dic ) ;
// Joker game?
if ( event . GetId ( ) = = Menu_Game_NewJoker )
m_game - > setVariant ( Game : : kJOKER ) ;
2005-03-29 07:00:39 +00:00
2005-02-05 11:14:56 +00:00
m_game - > start ( ) ;
2008-01-08 13:52:32 +00:00
rack - > SetValue ( wxT ( " " ) ) ;
2005-12-26 22:59:57 +00:00
InitFrames ( ) ;
# ifdef ENABLE_RESLIST_IN_MAIN
reslist - > SetGame ( m_game ) ;
# endif
2008-01-08 13:52:32 +00:00
// Re-enable the main buttons
b_rackrandomset - > Enable ( true ) ;
b_rackrandomnew - > Enable ( true ) ;
b_search - > Enable ( true ) ;
b_back - > Enable ( true ) ;
b_play - > Enable ( true ) ;
rack - > Enable ( true ) ;
2005-02-05 11:14:56 +00:00
UpdateStatusBar ( ) ;
2005-12-26 22:59:57 +00:00
UpdateFrames ( AuxFrame : : FORCE_REFRESH ) ;
2004-04-08 09:43:06 +00:00
}
2005-12-26 22:59:57 +00:00
// *******************
// OPEN
// *******************
2004-04-08 09:43:06 +00:00
void
MainFrame : : OnMenuGameOpen ( wxCommandEvent & )
{
2008-01-08 13:52:32 +00:00
wxFileDialog dialog ( this , _ ( " Load a game " ) , wxT ( " " ) , wxT ( " " ) , wxT ( " * " ) , wxOPEN ) ;
2005-02-05 11:14:56 +00:00
if ( m_dic = = NULL )
2004-04-08 09:43:06 +00:00
{
2008-01-08 13:52:32 +00:00
wxMessageBox ( _ ( " No dictionary selected " ) , _ ( " Eliot: error " ) ,
2005-02-05 11:14:56 +00:00
wxICON_INFORMATION | wxOK ) ;
return ;
}
2005-12-26 22:59:57 +00:00
if ( dialog . ShowModal ( ) ! = wxID_OK )
2008-01-08 13:52:32 +00:00
{
return ;
}
2005-12-26 22:59:57 +00:00
if ( m_game ! = NULL )
2008-01-08 13:52:32 +00:00
{
GameFactory : : Instance ( ) - > releaseGame ( * m_game ) ;
m_game = NULL ;
}
2005-12-26 22:59:57 +00:00
FILE * fin ;
2006-01-01 19:33:51 +00:00
if ( ( fin = fopen ( dialog . GetPath ( ) . mb_str ( ) , " rb " ) ) = = NULL )
2008-01-08 13:52:32 +00:00
{
wxString txt ;
txt < < _ ( " Cannot open " ) < < dialog . GetPath ( ) ;
wxMessageDialog msg ( this , txt , _ ( " Load a game " ) ) ;
msg . ShowModal ( ) ;
return ;
}
2005-12-26 22:59:57 +00:00
2008-01-08 13:52:32 +00:00
m_game = Game : : load ( fin , * m_dic ) ;
2005-12-26 22:59:57 +00:00
fclose ( fin ) ;
if ( m_game = = NULL )
2008-01-08 13:52:32 +00:00
{
wxMessageDialog msg ( this ,
_ ( " Error while loading the game " ) ,
_ ( " Invalid game " ) ) ;
msg . ShowModal ( ) ;
return ;
}
2005-12-26 22:59:57 +00:00
if ( m_game - > getHistory ( ) . getSize ( ) = = 0 )
2006-01-22 12:23:52 +00:00
{
2008-01-08 13:52:32 +00:00
wxMessageDialog msg ( this ,
_ ( " Error while loading the game " ) ,
_ ( " The game is empty " ) ) ;
msg . ShowModal ( ) ;
return ;
2006-01-22 12:23:52 +00:00
}
2005-12-26 22:59:57 +00:00
2008-01-08 13:52:32 +00:00
std : : wstring r = m_game - > getCurrentPlayer ( ) . getCurrentRack ( ) . toString ( ) ;
2005-02-05 11:14:56 +00:00
rack - > SetValue ( wxU ( r . c_str ( ) ) ) ;
2005-12-26 22:59:57 +00:00
// update gfxboard and all frames
InitFrames ( ) ;
// update status bar
# ifdef ENABLE_RESLIST_IN_MAIN
reslist - > SetGame ( m_game ) ;
# endif
2005-02-05 11:14:56 +00:00
UpdateStatusBar ( ) ;
2005-12-26 22:59:57 +00:00
UpdateFrames ( AuxFrame : : FORCE_REFRESH ) ;
2004-04-08 09:43:06 +00:00
}
2005-12-26 22:59:57 +00:00
// *******************
// SAVE
// *******************
2004-04-08 09:43:06 +00:00
void
MainFrame : : OnMenuGameSave ( wxCommandEvent & WXUNUSED ( event ) )
{
2008-01-08 13:52:32 +00:00
wxFileDialog dialog ( this , _ ( " Save the game " ) , wxT ( " " ) , wxT ( " " ) , wxT ( " * " ) , wxSAVE | wxOVERWRITE_PROMPT ) ;
2005-02-05 11:14:56 +00:00
if ( dialog . ShowModal ( ) = = wxID_OK )
2004-04-08 09:43:06 +00:00
{
2005-02-05 11:14:56 +00:00
ofstream fout ( dialog . GetPath ( ) . mb_str ( ) ) ;
if ( fout . rdstate ( ) = = ios : : failbit )
2004-08-07 18:10:42 +00:00
{
2005-02-05 11:14:56 +00:00
wxString txt ;
2008-01-08 13:52:32 +00:00
txt < < _ ( " Cannot create " ) < < dialog . GetPath ( ) ;
wxMessageDialog msg ( this , txt , _ ( " Save the game " ) ) ;
2005-02-05 11:14:56 +00:00
msg . ShowModal ( ) ;
return ;
2004-08-07 18:10:42 +00:00
}
2005-02-05 11:14:56 +00:00
m_game - > save ( fout ) ;
fout . close ( ) ;
2004-04-08 09:43:06 +00:00
}
}
2005-12-26 22:59:57 +00:00
// *******************
// PRINT
// *******************
2004-04-08 09:43:06 +00:00
void
MainFrame : : OnMenuGamePrint ( wxCommandEvent & WXUNUSED ( event ) )
{
2005-02-05 11:14:56 +00:00
// TODO: gray out the menu instead...
if ( m_game = = NULL )
{
2008-01-08 13:52:32 +00:00
wxMessageBox ( _ ( " No on going game " ) , _ ( " Eliot: error " ) ,
2005-02-05 11:14:56 +00:00
wxICON_INFORMATION | wxOK ) ;
return ;
}
wxPrintDialogData printDialogData ( config . getPrintData ( ) ) ;
wxPrinter printer ( & printDialogData ) ;
GamePrintout printout ( * m_game ) ;
if ( ! printer . Print ( this , & printout , TRUE ) )
2008-01-08 13:52:32 +00:00
{
wxMessageBox ( _ ( " Printing not done " ) , _ ( " Printing " ) ,
wxOK | wxICON_ERROR ) ;
}
2004-04-08 09:43:06 +00:00
}
void
MainFrame : : OnMenuGamePrintPreview ( wxCommandEvent & WXUNUSED ( event ) )
{
2005-02-05 11:14:56 +00:00
// TODO: gray out the menu instead...
if ( m_game = = NULL )
{
2008-01-08 13:52:32 +00:00
wxMessageBox ( _ ( " No on going game " ) , _ ( " Eliot: error " ) ,
2005-02-05 11:14:56 +00:00
wxICON_INFORMATION | wxOK ) ;
return ;
}
wxPrintData printdata = config . getPrintData ( ) ;
2004-04-08 09:43:06 +00:00
2005-02-05 11:14:56 +00:00
wxString msg ;
wxPrintPreview * preview = new wxPrintPreview ( new GamePrintout ( * m_game ) ,
new GamePrintout ( * m_game ) , & printdata ) ;
if ( ! preview - > Ok ( ) )
2004-04-08 09:43:06 +00:00
{
2005-02-05 11:14:56 +00:00
delete preview ;
2008-01-08 13:52:32 +00:00
msg < < _ ( " Print preview problem. \n " )
< < _ ( " The printer may not be correctly initialized " ) ;
wxMessageBox ( msg , _ ( " Print preview " ) , wxOK ) ;
2005-02-05 11:14:56 +00:00
return ;
2004-04-08 09:43:06 +00:00
}
2008-01-08 13:52:32 +00:00
wxPreviewFrame * frame = new wxPreviewFrame ( preview , this , _ ( " Printing " ) ,
2005-02-05 11:14:56 +00:00
wxPoint ( - 1 , - 1 ) , wxSize ( 600 , 550 ) ) ;
frame - > Centre ( wxBOTH ) ;
frame - > Initialize ( ) ;
frame - > Show ( TRUE ) ;
2004-04-08 09:43:06 +00:00
}
void
MainFrame : : OnMenuGamePrintPS ( wxCommandEvent & WXUNUSED ( event ) )
{
# ifdef ENABLE_SAVE_POSTSCRIPT
2005-02-05 11:14:56 +00:00
// TODO: gray out the menu instead...
if ( m_game = = NULL )
2004-04-08 09:43:06 +00:00
{
2008-01-08 13:52:32 +00:00
wxMessageBox ( _ ( " No on going game " ) , _ ( " Eliot: error " ) ,
2005-02-05 11:14:56 +00:00
wxICON_INFORMATION | wxOK ) ;
return ;
}
2008-01-08 13:52:32 +00:00
wxFileDialog dialog ( this , _ ( " Print to a PostScript file " ) , wxT ( " " ) , wxT ( " " ) , wxT ( " *.ps " ) , wxSAVE | wxOVERWRITE_PROMPT ) ;
2005-02-05 11:14:56 +00:00
if ( dialog . ShowModal ( ) = = wxID_OK )
{
wxPrintData printdataPS ;
printdataPS . SetPrintMode ( wxPRINT_MODE_FILE ) ;
printdataPS . SetFilename ( dialog . GetPath ( ) ) ;
printdataPS . SetPaperId ( wxPAPER_A4 ) ;
printdataPS . SetQuality ( wxPRINT_QUALITY_HIGH ) ;
printdataPS . SetOrientation ( wxPORTRAIT ) ;
wxPostScriptDC printps ( printdataPS ) ;
if ( printps . Ok ( ) )
2004-08-07 18:10:42 +00:00
{
2005-02-05 11:14:56 +00:00
wxPrintDialogData printDialogData ( printdataPS ) ;
wxPostScriptPrinter printer ( & printDialogData ) ;
GamePrintout printout ( * m_game ) ;
if ( ! printer . Print ( this , & printout , FALSE ) )
2004-08-07 18:10:42 +00:00
{
2008-01-08 13:52:32 +00:00
wxMessageBox ( _ ( " Printing not done " ) ,
_ ( " PostScript printing " ) , wxOK | wxICON_ERROR ) ;
2004-08-07 18:10:42 +00:00
}
}
2005-02-05 11:14:56 +00:00
else
2004-08-07 18:10:42 +00:00
{
2008-01-08 13:52:32 +00:00
wxMessageBox ( _ ( " Cannot initialize PostScript printer " ) ,
_ ( " PostScript printing " ) , wxOK | wxICON_ERROR ) ;
2004-08-07 18:10:42 +00:00
}
2004-04-08 09:43:06 +00:00
}
# endif
}
2008-01-08 13:52:32 +00:00
void
MainFrame : : OnMenuGameQuit ( wxCommandEvent & WXUNUSED ( event ) )
{
Close ( TRUE ) ;
}
2005-12-26 22:59:57 +00:00
// *******************
2008-01-08 13:52:32 +00:00
// Dictionary Loading
2005-12-26 22:59:57 +00:00
// *******************
2004-04-08 09:43:06 +00:00
void
MainFrame : : OnMenuConfGameDic ( wxCommandEvent & WXUNUSED ( event ) )
{
2008-01-08 13:52:32 +00:00
wxFileDialog dialog ( this , _ ( " Choose a dictionary " ) , wxT ( " " ) , wxT ( " *.dawg " ) , wxT ( " *.dawg " ) , wxOPEN ) ;
2005-02-05 11:14:56 +00:00
if ( dialog . ShowModal ( ) = = wxID_OK )
2004-04-08 09:43:06 +00:00
{
2005-02-05 11:14:56 +00:00
wxString dicpath = dialog . GetPath ( ) ;
2008-01-08 13:52:32 +00:00
try
2004-08-07 18:10:42 +00:00
{
2008-01-08 13:52:32 +00:00
Dictionary * dic = new Dictionary ( dicpath . mb_str ( ) . data ( ) ) ;
delete m_dic ;
2005-02-05 11:14:56 +00:00
m_dic = dic ;
config . setDicPath ( dialog . GetPath ( ) , : : wxFileNameFromPath ( dialog . GetPath ( ) ) ) ;
2008-01-08 13:52:32 +00:00
wxCommandEvent event ;
OnMenuGameNew ( event ) ;
2004-08-07 18:10:42 +00:00
}
2008-01-08 13:52:32 +00:00
catch ( std : : exception & e )
2004-08-07 18:10:42 +00:00
{
2008-01-08 13:52:32 +00:00
wxMessageDialog dlg ( NULL , wxU ( e . what ( ) ) , wxT ( APPNAME ) ) ;
2005-02-05 11:14:56 +00:00
dlg . ShowModal ( ) ;
2004-08-07 18:10:42 +00:00
}
2004-04-08 09:43:06 +00:00
}
}
2005-12-26 22:59:57 +00:00
// ****************
// MENU CONF SEARCH
// ****************
2004-04-08 09:43:06 +00:00
void
MainFrame : : OnMenuConfGameSearch ( wxCommandEvent & WXUNUSED ( event ) )
{
2005-02-05 11:14:56 +00:00
ConfSearchDlg dlg ( this ) ;
dlg . ShowModal ( ) ;
2004-04-08 09:43:06 +00:00
}
// ****************
// MENU CONF PRINT
// ****************
void
MainFrame : : OnMenuConfPrint ( wxCommandEvent & WXUNUSED ( event ) )
{
2005-02-05 11:14:56 +00:00
ConfDimDlg dlg ( this , config . getPrintData ( ) , config . getPageSetupData ( ) ) ;
if ( dlg . ShowModal ( ) = = wxID_OK )
2004-04-08 09:43:06 +00:00
{
2005-02-05 11:14:56 +00:00
config . setPrintData ( dlg . getPrintData ( ) ) ;
config . setPageSetupData ( dlg . getPageSetupData ( ) ) ;
2004-04-08 09:43:06 +00:00
}
}
// ****************
// MENU CONF FONTS
// ****************
void
MainFrame : : OnMenuConfAspectFont ( wxCommandEvent & event )
{
2005-02-05 11:14:56 +00:00
int id ;
wxString attr ;
2004-04-08 09:43:06 +00:00
2005-02-05 11:14:56 +00:00
id = event . GetId ( ) ;
if ( ! GetMenuBar ( ) - > FindItem ( id ) )
return ;
2004-04-08 09:43:06 +00:00
2005-02-05 11:14:56 +00:00
switch ( id )
2004-04-08 09:43:06 +00:00
{
2005-12-26 22:59:57 +00:00
case Menu_Conf_Aspect_Font_Search : attr = wxString ( LISTFONT ) ; break ;
case Menu_Conf_Aspect_Font_Board : attr = wxString ( BOARDFONT ) ; break ;
2005-02-05 11:14:56 +00:00
case Menu_Conf_Aspect_Font_Default : attr = wxU ( " Default " ) ; break ;
default : INCOMPLETE ; break ;
2004-04-08 09:43:06 +00:00
}
2005-02-05 11:14:56 +00:00
if ( attr = = wxU ( " Default " ) )
config . setFontDefault ( ) ;
else
config . setFont ( attr , config . ChooseFont ( this , config . getFont ( attr ) ) ) ;
2004-04-08 09:43:06 +00:00
2005-12-26 22:59:57 +00:00
UpdateFrames ( AuxFrame : : FORCE_REFRESH ) ;
2004-04-08 09:43:06 +00:00
}
// ************************
// MENU CONF BOARD COLOURS
// ************************
void
MainFrame : : OnMenuConfAspectBoardColour ( wxCommandEvent & event )
{
2005-02-05 11:14:56 +00:00
int id ;
wxString attr ;
2004-04-08 09:43:06 +00:00
2005-02-05 11:14:56 +00:00
id = event . GetId ( ) ;
if ( ! GetMenuBar ( ) - > FindItem ( id ) )
return ;
2004-04-08 09:43:06 +00:00
2005-02-05 11:14:56 +00:00
switch ( id )
2004-04-08 09:43:06 +00:00
{
2005-12-26 15:28:57 +00:00
case Menu_Conf_Aspect_BoardColour_Lines : attr = wxString ( BCOLOURLINES ) ; break ;
case Menu_Conf_Aspect_BoardColour_Wx2 : attr = wxString ( BCOLOURWX2 ) ; break ;
case Menu_Conf_Aspect_BoardColour_Wx3 : attr = wxString ( BCOLOURWX3 ) ; break ;
case Menu_Conf_Aspect_BoardColour_Lx2 : attr = wxString ( BCOLOURLX2 ) ; break ;
case Menu_Conf_Aspect_BoardColour_Lx3 : attr = wxString ( BCOLOURLX3 ) ; break ;
case Menu_Conf_Aspect_BoardColour_Background : attr = wxString ( BCOLOURBACKGROUND ) ; break ;
case Menu_Conf_Aspect_BoardColour_Letters : attr = wxString ( BCOLOURLETTERS ) ; break ;
case Menu_Conf_Aspect_BoardColour_TestLetters : attr = wxString ( BCOLOURTSTLETTERS ) ; break ;
2008-01-08 13:52:32 +00:00
case Menu_Conf_Aspect_BoardColour_TileBack : attr = wxString ( BTILEBACKGROUND ) ; break ;
case Menu_Conf_Aspect_BoardColour_TestTileBack : attr = wxString ( BTSTTILEBACKGROUND ) ; break ;
2005-12-26 15:28:57 +00:00
case Menu_Conf_Aspect_BoardColour_Default : attr = wxU ( " Default " ) ; break ;
2005-02-05 11:14:56 +00:00
default : INCOMPLETE ; break ;
2004-04-08 09:43:06 +00:00
}
2005-02-05 11:14:56 +00:00
if ( attr = = wxU ( " Default " ) )
config . setColourDefault ( ) ;
else
config . setColour ( attr , config . ChooseColour ( this , config . getColour ( attr ) ) ) ;
2004-04-08 09:43:06 +00:00
2005-12-26 22:59:57 +00:00
UpdateFrames ( AuxFrame : : FORCE_REFRESH ) ;
2004-04-08 09:43:06 +00:00
}
//**************************************************************************************
2008-01-08 13:52:32 +00:00
// MENU HELP
2004-04-08 09:43:06 +00:00
//**************************************************************************************
void
2008-01-08 13:52:32 +00:00
MainFrame : : OnMenuHelpAbout ( wxCommandEvent & WXUNUSED ( event ) )
2004-04-08 09:43:06 +00:00
{
2005-02-05 11:14:56 +00:00
wxString msg ;
2008-01-08 13:52:32 +00:00
msg . Printf ( wxT ( " Eliot %s \n \n " ) , wxT ( VERSION ) ) ;
msg < < wxT ( " Copyright (C) 1999-2007 - Antoine Fraboulet & Olivier Teuliere \n \n " ) ;
msg < < _ ( " This program is free software; you can redistribute it and/or modify " \
" it under the terms of the GNU General Public License as published by " \
" the Free Software Foundation; either version 2 of the License, or " \
" (at your option) any later version. " ) ;
wxMessageBox ( msg , _ ( " About Eliot " ) , wxICON_INFORMATION | wxOK ) ;
2004-04-08 09:43:06 +00:00
}
//**************************************************************************************
// BUTTONS
//**************************************************************************************
void
MainFrame : : OnSetRack ( wxCommandEvent & event )
{
2005-02-05 11:14:56 +00:00
int id ;
2006-01-01 19:33:51 +00:00
2005-02-05 11:14:56 +00:00
Game : : set_rack_mode mode = Game : : RACK_NEW ;
2005-12-26 22:59:57 +00:00
debug ( " OnSetRack " ) ;
2005-02-05 11:14:56 +00:00
switch ( ( id = event . GetId ( ) ) )
2008-01-08 13:52:32 +00:00
{
2005-12-26 22:59:57 +00:00
case Button_SetRack :
2008-01-08 13:52:32 +00:00
mode = Game : : RACK_ALL ;
debug ( " PlayedRack::RACK_ALL \n " ) ;
break ;
2005-12-26 22:59:57 +00:00
case Button_SetNew :
2008-01-08 13:52:32 +00:00
mode = Game : : RACK_NEW ;
debug ( " PlayedRack::RACK_NEW \n " ) ;
break ;
2005-12-26 22:59:57 +00:00
case Button_SetManual :
2008-01-08 13:52:32 +00:00
mode = Game : : RACK_MANUAL ;
debug ( " PlayedRack::RACK_MANUAL \n " ) ;
break ;
2005-02-05 11:14:56 +00:00
default :
2008-01-08 13:52:32 +00:00
return ;
}
2005-12-26 22:59:57 +00:00
SetRack ( mode ) ;
2004-04-08 09:43:06 +00:00
}
void
MainFrame : : OnSearch ( wxCommandEvent & WXUNUSED ( event ) )
{
2006-01-01 19:33:51 +00:00
debug ( " MainFrame::OnSearch \n " ) ;
2006-08-11 22:17:54 +00:00
// check if rack has been set manually
SetRack ( Game : : RACK_MANUAL , rack - > GetValue ( ) ) ;
2005-02-05 11:14:56 +00:00
Search ( ) ;
2004-04-08 09:43:06 +00:00
}
void
2005-12-26 22:59:57 +00:00
MainFrame : : OnTextEnter ( wxCommandEvent & WXUNUSED ( event ) )
2004-04-08 09:43:06 +00:00
{
2005-12-26 22:59:57 +00:00
debug ( " MainFrame::OnTextEnter -> %s \n " , ( const char * ) rack - > GetValue ( ) . mb_str ( ) ) ;
SetRack ( Game : : RACK_MANUAL , rack - > GetValue ( ) ) ;
Search ( ) ;
2004-04-08 09:43:06 +00:00
}
void
MainFrame : : OnPlay ( wxCommandEvent & event )
{
2005-12-26 22:59:57 +00:00
int dir = 1 ;
2005-02-05 11:14:56 +00:00
int id = event . GetId ( ) ;
switch ( id )
2008-01-08 13:52:32 +00:00
{
2005-02-05 11:14:56 +00:00
case Button_Play :
2008-01-08 13:52:32 +00:00
dir = 1 ;
2005-02-05 11:14:56 +00:00
break ;
2005-12-26 22:59:57 +00:00
case Button_PlayBack :
2008-01-08 13:52:32 +00:00
dir = - 1 ;
2005-12-26 22:59:57 +00:00
break ;
default :
break ;
2008-01-08 13:52:32 +00:00
}
2005-12-26 22:59:57 +00:00
Play ( dir ) ;
2004-04-08 09:43:06 +00:00
}
//*********************************
// SPECIAL FRAMES
//*********************************
void
MainFrame : : InitFrames ( )
{
2005-12-26 22:59:57 +00:00
debug ( " InitFrames start : \n " ) ;
if ( m_game = = NULL )
2008-01-08 13:52:32 +00:00
{
debug ( " m_game == NULL \n " ) ;
return ;
}
for ( int i = 0 ; i < MAX_FRAME_ID ; i + + )
{
debug ( " delete frame %d \n " , i ) ;
delete auxframes_ptr [ i ] ;
}
auxframes_ptr [ ID_Frame_Verif ] = new VerifFrame ( this , m_game - > getDic ( ) ) ;
2005-12-26 22:59:57 +00:00
debug ( " 0 : Verif \n " ) ;
2008-01-08 13:52:32 +00:00
auxframes_ptr [ ID_Frame_Search ] = new SearchFrame ( this , m_game - > getDic ( ) ) ;
2005-12-26 22:59:57 +00:00
debug ( " 1 : Search \n " ) ;
2008-01-08 13:52:32 +00:00
auxframes_ptr [ ID_Frame_Plus1 ] = new Plus1Frame ( this , m_game ) ;
2005-12-26 22:59:57 +00:00
debug ( " 2 : Plus1 \n " ) ;
2008-01-08 13:52:32 +00:00
auxframes_ptr [ ID_Frame_Racc ] = new RaccFrame ( this , m_game ) ;
2005-12-26 22:59:57 +00:00
debug ( " 3 : Racc \n " ) ;
2008-01-08 13:52:32 +00:00
auxframes_ptr [ ID_Frame_Benj ] = new BenjFrame ( this , m_game ) ;
2005-12-26 22:59:57 +00:00
debug ( " 4 : Benj \n " ) ;
2008-01-08 13:52:32 +00:00
auxframes_ptr [ ID_Frame_Bag ] = new BagFrame ( this , * m_game ) ;
2005-12-26 22:59:57 +00:00
debug ( " 5 : Bag \n " ) ;
2008-01-08 13:52:32 +00:00
auxframes_ptr [ ID_Frame_Board ] = new BoardFrame ( this , * m_game ) ;
2005-12-26 22:59:57 +00:00
debug ( " 6 : Board \n " ) ;
2008-01-08 13:52:32 +00:00
auxframes_ptr [ ID_Frame_Game ] = new GameFrame ( this , * m_game ) ;
2005-12-26 22:59:57 +00:00
debug ( " 7 : Game \n " ) ;
# ifndef ENABLE_RESLIST_IN_MAIN
2008-01-08 13:52:32 +00:00
auxframes_ptr [ ID_Frame_Result ] = new ResultFrame ( this , m_game ) ;
2005-12-26 22:59:57 +00:00
debug ( " 8 : Result \n " ) ;
# endif
2008-01-08 13:52:32 +00:00
2005-12-26 22:59:57 +00:00
for ( int i = MIN_FRAME_ID ; i < MAX_FRAME_ID ; i + + )
2004-04-08 09:43:06 +00:00
{
2008-01-08 13:52:32 +00:00
if ( auxframes_ptr [ i ] ! = NULL )
{
auxframes_ptr [ i ] - > Reload ( ) ;
debug ( " reload %d \n " , i ) ;
}
2004-04-08 09:43:06 +00:00
}
2008-01-08 13:52:32 +00:00
// Check the corresponding menu item if the window is visible
GetMenuBar ( ) - > Check ( Menu_ShowVerif , auxframes_ptr [ ID_Frame_Verif ] - > IsShown ( ) ) ;
GetMenuBar ( ) - > Check ( Menu_ShowSearch , auxframes_ptr [ ID_Frame_Search ] - > IsShown ( ) ) ;
GetMenuBar ( ) - > Check ( Menu_ShowPlus1 , auxframes_ptr [ ID_Frame_Plus1 ] - > IsShown ( ) ) ;
GetMenuBar ( ) - > Check ( Menu_ShowRacc , auxframes_ptr [ ID_Frame_Racc ] - > IsShown ( ) ) ;
GetMenuBar ( ) - > Check ( Menu_ShowBenj , auxframes_ptr [ ID_Frame_Benj ] - > IsShown ( ) ) ;
GetMenuBar ( ) - > Check ( Menu_ShowBag , auxframes_ptr [ ID_Frame_Bag ] - > IsShown ( ) ) ;
GetMenuBar ( ) - > Check ( Menu_ShowBoard , auxframes_ptr [ ID_Frame_Board ] - > IsShown ( ) ) ;
GetMenuBar ( ) - > Check ( Menu_ShowGame , auxframes_ptr [ ID_Frame_Game ] - > IsShown ( ) ) ;
# ifndef ENABLE_RESLIST_IN_MAIN
GetMenuBar ( ) - > Check ( Menu_ShowResult , auxframes_ptr [ ID_Frame_Result ] - > IsShown ( ) ) ;
# endif
2005-12-26 22:59:57 +00:00
debug ( " InitFrames end ok. \n " ) ;
2004-04-08 09:43:06 +00:00
}
void
MainFrame : : OnMenuShowFrame ( wxCommandEvent & event )
{
2005-02-05 11:14:56 +00:00
int id ;
id = event . GetId ( ) ;
2008-01-08 13:52:32 +00:00
2005-02-05 11:14:56 +00:00
if ( ! GetMenuBar ( ) - > FindItem ( id ) )
return ;
id - = IDBASE ;
2008-01-08 13:52:32 +00:00
2005-02-05 11:14:56 +00:00
if ( ( id < 0 ) | | ( id > = MAX_FRAME_ID ) )
2004-04-08 09:43:06 +00:00
{
2008-01-08 13:52:32 +00:00
INCOMPLETE ;
return ;
2004-04-08 09:43:06 +00:00
}
2008-01-08 13:52:32 +00:00
2005-02-05 11:14:56 +00:00
if ( auxframes_ptr [ id ] = = NULL )
2004-04-08 09:43:06 +00:00
{
2008-01-08 13:52:32 +00:00
debug ( " ShowFrame: auxframes_ptr[%d] == NULL \n " , id ) ;
return ;
2004-04-08 09:43:06 +00:00
}
2005-02-05 11:14:56 +00:00
auxframes_ptr [ id ] - > SwitchDisplay ( ) ;
2005-12-26 22:59:57 +00:00
debug ( " ShowFrame: SwitchDisplay frame %d \n " , id ) ;
2004-04-08 09:43:06 +00:00
}
2005-12-26 22:59:57 +00:00
// *********************************
// UPDATES
// *********************************
2004-04-08 09:43:06 +00:00
void
2005-12-26 22:59:57 +00:00
MainFrame : : UpdateFrames ( AuxFrame : : refresh_t force )
2004-04-08 09:43:06 +00:00
{
2005-02-05 11:14:56 +00:00
for ( int id = 0 ; id < MAX_FRAME_ID ; id + + )
2004-04-08 09:43:06 +00:00
{
2008-01-08 13:52:32 +00:00
if ( auxframes_ptr [ id ] )
{
auxframes_ptr [ id ] - > Refresh ( force ) ;
}
2005-12-26 22:59:57 +00:00
}
# ifdef ENABLE_RESLIST_IN_MAIN
if ( reslist )
{
2008-01-08 13:52:32 +00:00
reslist - > Refresh ( ) ;
2004-04-08 09:43:06 +00:00
}
2005-12-26 22:59:57 +00:00
# endif
}
void
MainFrame : : UpdateStatusBar ( )
{
wxString text ;
if ( statusbar )
{
2008-01-08 13:52:32 +00:00
text = config . getDicName ( ) + wxT ( " " ) + config . getTileName ( ) ;
statusbar - > SetStatusText ( text , 0 ) ;
if ( m_game )
{
text = wxT ( " " ) ;
text < < _ ( " turn: " ) < < wxT ( " " ) < < ( m_game - > getHistory ( ) . getSize ( ) + 1 ) < < wxT ( " " ) ;
text < < _ ( " points: " ) < < wxT ( " " ) < < ( m_game - > getCurrentPlayer ( ) . getPoints ( ) ) ;
statusbar - > SetStatusText ( text , 1 ) ;
}
2005-12-26 22:59:57 +00:00
}
}
// *********************************
// ACTIONS
// *********************************
// Can come from a
// BUTTON ALL -> mode = Game::RACK_ALL, srack = empty
// BUTTON NEW -> mode = Game::RACK_NEW, srack = empty
// TEXT_ENTER -> mode = Game::RACK_MANUAL, srack = letters
// Play -> mode = Game::RACK_MANUAL, srack = letters
void
MainFrame : : SetRack ( Game : : set_rack_mode mode , wxString srack )
{
wxString msg ;
bool check = config . getRackChecking ( ) ;
2008-01-08 13:52:32 +00:00
if ( m_game = = NULL )
{
return ;
}
2006-01-22 12:23:52 +00:00
static_cast < Training * > ( m_game ) - > removeTestPlay ( ) ;
2008-01-08 13:52:32 +00:00
int res = static_cast < Training * > ( m_game ) - > setRack ( mode , check , srack . c_str ( ) ) ;
2005-12-26 22:59:57 +00:00
switch ( res )
2008-01-08 13:52:32 +00:00
{
2005-12-26 22:59:57 +00:00
case 0x00 : /* ok */
2008-01-08 13:52:32 +00:00
debug ( " SetRack Ok :: " ) ;
break ;
2005-12-26 22:59:57 +00:00
case 0x01 :
2008-01-08 13:52:32 +00:00
msg = _ ( " The bag doesn't contain enough letters \n for a new rack. " ) ;
wxMessageBox ( msg , _ ( " Rack validation " ) , wxICON_ERROR | wxOK ) ;
2005-12-26 22:59:57 +00:00
return ;
case 0x02 :
2008-01-08 13:52:32 +00:00
msg = _ ( " The rack must contain at least 2 consonants and 2 vowels. " ) ;
wxMessageBox ( msg , _ ( " Rack validation " ) , wxICON_ERROR | wxOK ) ;
2005-12-26 22:59:57 +00:00
return ;
case 0x03 :
2008-01-08 13:52:32 +00:00
msg = _ ( " The rack contains invalid letters for the current dictionary " ) ;
wxMessageBox ( msg , _ ( " Rack validation " ) , wxICON_ERROR | wxOK ) ;
2005-12-26 22:59:57 +00:00
break ;
2008-01-08 13:52:32 +00:00
default :
statusbar - > SetStatusText ( _ ( " The rack has been modified manually " ) , 0 ) ;
break ;
}
2005-12-26 22:59:57 +00:00
2006-01-22 12:23:52 +00:00
std : : wstring r = m_game - > getCurrentPlayer ( ) . getCurrentRack ( ) . toString ( ) ;
debug ( " MainFrame::SetRack : setvalue %ls \n " , r . c_str ( ) ) ;
2005-12-26 22:59:57 +00:00
rack - > SetValue ( wxU ( r . c_str ( ) ) ) ;
UpdateFrames ( ) ;
UpdateStatusBar ( ) ;
2004-04-08 09:43:06 +00:00
}
2005-12-26 22:59:57 +00:00
void
MainFrame : : Search ( )
{
2008-01-08 13:52:32 +00:00
if ( m_game = = NULL )
2006-10-08 12:39:13 +00:00
{
return ;
}
static_cast < Training * > ( m_game ) - > removeTestPlay ( ) ;
2005-12-26 22:59:57 +00:00
# ifdef ENABLE_RESLIST_IN_MAIN
reslist - > Search ( ) ;
# else
if ( auxframes_ptr [ ID_Frame_Result ] )
2008-01-08 13:52:32 +00:00
{
( ( ResultFrame * ) ( auxframes_ptr [ ID_Frame_Result ] ) ) - > Search ( ) ;
}
2005-12-26 22:59:57 +00:00
# endif
UpdateFrames ( ) ;
UpdateStatusBar ( ) ;
}
void
MainFrame : : Play ( int n )
{
2006-10-08 12:39:13 +00:00
if ( m_game = = NULL )
{
return ;
}
static_cast < Training * > ( m_game ) - > removeTestPlay ( ) ;
2005-12-26 22:59:57 +00:00
if ( n < 0 )
2008-01-08 13:52:32 +00:00
{
debug ( " MainFrame::Play back %d \n " , n ) ;
m_game - > back ( - n ) ;
}
2005-12-26 22:59:57 +00:00
else
2008-01-08 13:52:32 +00:00
{
int n = 0 ;
debug ( " MainFrame::Play +%d \n " , n ) ;
2005-12-26 22:59:57 +00:00
# ifdef ENABLE_RESLIST_IN_MAIN
2008-01-08 13:52:32 +00:00
n = reslist - > GetSelected ( ) ;
2005-12-26 22:59:57 +00:00
# else
2008-01-08 13:52:32 +00:00
n = ( ( ResultFrame * ) auxframes_ptr [ ID_Frame_Result ] ) - > GetSelected ( ) ;
2005-12-26 22:59:57 +00:00
# endif
2008-01-08 13:52:32 +00:00
if ( n > - 1 )
{
static_cast < Training * > ( m_game ) - > playResult ( n ) ;
}
}
2005-12-26 22:59:57 +00:00
wxString r = wxU ( m_game - > getCurrentPlayer ( ) . getCurrentRack ( ) . toString ( ) . c_str ( ) ) ;
rack - > SetValue ( r ) ;
UpdateFrames ( ) ;
UpdateStatusBar ( ) ;
}
void
MainFrame : : TestPlay ( int n )
{
2006-10-08 12:39:13 +00:00
if ( m_game = = NULL )
{
return ;
}
static_cast < Training * > ( m_game ) - > removeTestPlay ( ) ;
static_cast < Training * > ( m_game ) - > testPlay ( n ) ;
2005-12-26 22:59:57 +00:00
UpdateFrames ( ) ;
UpdateStatusBar ( ) ;
}
/****************************************************************/
/****************************************************************/
2008-01-08 13:52:32 +00:00
/// Local Variables: / mode: c++ / mode: hs-minor / c-basic-offset: 4 /
//indent-tabs-mode: nil / End: