00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdlib.h>
00028 #include <stdio.h>
00029 #include <iostream>
00030 #include <fstream>
00031
00032 using namespace std;
00033
00034 #include "wx/intl.h"
00035 #include "wx/menu.h"
00036 #include "wx/statusbr.h"
00037 #include "wx/sizer.h"
00038 #include "wx/filedlg.h"
00039 #include "wx/msgdlg.h"
00040
00041 #include "ewx.h"
00042
00043 #include "dic.h"
00044 #include "game.h"
00045 #include "game_factory.h"
00046 #include "player.h"
00047
00048 #include "configdb.h"
00049 #include "confdimdlg.h"
00050 #include "confsearch.h"
00051 #include "printout.h"
00052 #include "mainframe.h"
00053
00054 #ifdef ENABLE_SAVE_POSTSCRIPT
00055 #include "wx/dcps.h"
00056 #endif
00057
00058 enum
00059 {
00060 Menu_Game_New = 1000,
00061 Menu_Game_Open,
00062 Menu_Game_Save,
00063 Menu_Game_Print,
00064 Menu_Game_PrintPreview,
00065 Menu_Game_PrintPS,
00066
00067 Menu_Conf_Game = 2000,
00068 Menu_Conf_Game_Dic,
00069 Menu_Conf_Game_Tiles,
00070 Menu_Conf_Game_Search,
00071 Menu_Conf_Print,
00072 Menu_Conf_Aspect = 2100,
00073 Menu_Conf_Tile,
00074 Menu_Conf_Aspect_BoardColour_DrawTiles,
00075 Menu_Conf_Aspect_Font,
00076 Menu_Conf_Aspect_Font_Search = 2110,
00077 Menu_Conf_Aspect_Font_Board = 2111,
00078 Menu_Conf_Aspect_Font_Default = 2112,
00079 Menu_Conf_Aspect_BoardColour = 2200,
00080 Menu_Conf_Aspect_BoardColour_Lines = 2201,
00081 Menu_Conf_Aspect_BoardColour_Wx2 = 2202,
00082 Menu_Conf_Aspect_BoardColour_Wx3 = 2203,
00083 Menu_Conf_Aspect_BoardColour_Lx2 = 2204,
00084 Menu_Conf_Aspect_BoardColour_Lx3 = 2205,
00085 Menu_Conf_Aspect_BoardColour_Background = 2206,
00086 Menu_Conf_Aspect_BoardColour_Letters = 2207,
00087 Menu_Conf_Aspect_BoardColour_TestLetters = 2208,
00088 Menu_Conf_Aspect_BoardColour_TileBack = 2209,
00089 Menu_Conf_Aspect_BoardColour_TestTileBack = 2210,
00090 Menu_Conf_Aspect_BoardColour_Default = 2211,
00091
00092 #define IDBASE 3300
00093 Menu_ShowVerif = (IDBASE + ID_Frame_Verif),
00094 Menu_ShowSearch = (IDBASE + ID_Frame_Search),
00095 Menu_ShowPlus1 = (IDBASE + ID_Frame_Plus1),
00096 Menu_ShowRacc = (IDBASE + ID_Frame_Racc),
00097 Menu_ShowBenj = (IDBASE + ID_Frame_Benj),
00098 Menu_ShowBag = (IDBASE + ID_Frame_Bag),
00099 Menu_ShowBoard = (IDBASE + ID_Frame_Board),
00100 Menu_ShowGame = (IDBASE + ID_Frame_Game),
00101 Menu_ShowResult = (IDBASE + ID_Frame_Result),
00102
00103 Menu_Quit_Apropos = 4000,
00104 Menu_Quit_Confirm,
00105
00106 Button_SetRack = 10000,
00107 Button_SetNew,
00108 Button_SetManual,
00109 Button_Search,
00110 Button_Play,
00111 Button_PlayBack,
00112
00113 ListCtrl_ID = 11000,
00114 Rack_ID,
00115 Status_ID,
00116 };
00117
00118 BEGIN_EVENT_TABLE(MainFrame, wxFrame)
00119
00120 EVT_MENU(Menu_Game_New, MainFrame::OnMenuGameNew)
00121 EVT_MENU(Menu_Game_Open, MainFrame::OnMenuGameOpen)
00122 EVT_MENU(Menu_Game_Save, MainFrame::OnMenuGameSave)
00123 EVT_MENU(Menu_Game_Print, MainFrame::OnMenuGamePrint)
00124 EVT_MENU(Menu_Game_PrintPreview, MainFrame::OnMenuGamePrintPreview)
00125 EVT_MENU(Menu_Game_PrintPS, MainFrame::OnMenuGamePrintPS)
00126
00127 EVT_MENU(Menu_Conf_Game_Dic, MainFrame::OnMenuConfGameDic)
00128 EVT_MENU(Menu_Conf_Game_Search, MainFrame::OnMenuConfGameSearch)
00129
00130 EVT_MENU(Menu_Conf_Print, MainFrame::OnMenuConfPrint)
00131
00132 EVT_MENU_RANGE(Menu_Conf_Aspect_Font_Search, Menu_Conf_Aspect_Font_Default, MainFrame::OnMenuConfAspectFont)
00133 EVT_MENU_RANGE(Menu_Conf_Aspect_BoardColour_Lines, Menu_Conf_Aspect_BoardColour_Default, MainFrame::OnMenuConfAspectBoardColour)
00134 EVT_MENU_RANGE(Menu_ShowVerif, Menu_ShowResult, MainFrame::OnMenuShowFrame)
00135
00136 EVT_MENU(Menu_Quit_Apropos, MainFrame::OnMenuQuitApropos)
00137 EVT_MENU(Menu_Quit_Confirm, MainFrame::OnMenuQuitConfirm)
00138
00139 EVT_BUTTON(Button_Play, MainFrame::OnPlay)
00140 EVT_BUTTON(Button_SetRack, MainFrame::OnSetRack)
00141 EVT_BUTTON(Button_SetNew, MainFrame::OnSetRack)
00142 EVT_BUTTON(Button_Search, MainFrame::OnSearch)
00143 EVT_BUTTON(Button_PlayBack, MainFrame::OnPlay)
00144
00145 EVT_TEXT_ENTER(Rack_ID, MainFrame::OnTextEnter)
00146
00147 EVT_CLOSE(MainFrame::OnCloseWindow)
00148
00149
00150 END_EVENT_TABLE()
00151
00152
00153
00154
00155
00156 MainFrame::MainFrame(wxPoint pos_, wxSize size_)
00157 : wxFrame((wxFrame *) NULL, -1, wxT("Eliot"), wxPoint(-1, -1),
00158 size_, wxDEFAULT_FRAME_STYLE, wxT("Eliot")),
00159 m_dic(NULL), m_game(NULL)
00160 {
00161 reslist = NULL;
00162 statusbar = NULL;
00163 for(int i=0 ; i < MAX_FRAME_ID; i++)
00164 auxframes_ptr[i] = NULL;
00165
00166 wxString dicpath = config.getDicPath();
00167 Dic_load(&m_dic, dicpath.mb_str());
00168 if (m_dic == NULL)
00169 {
00170 wxCommandEvent event;
00171 OnMenuConfGameDic(event);
00172 }
00173 m_game = GameFactory::Instance()->createTraining(m_dic);
00174 if (m_game)
00175 {
00176 m_game->start();
00177 }
00178
00179 wxBoxSizer *listsizer = new wxBoxSizer(wxVERTICAL);
00180 rack = new wxTextCtrl(this, Rack_ID, wxU(""), wxPoint(-1, -1), wxSize(-1, -1), wxTE_PROCESS_ENTER);
00181 listsizer->Add(rack , 0 , wxEXPAND | wxALL, 1);
00182 rack->SetToolTip(wxT("Tirage"));
00183 #ifdef ENABLE_RESLIST_IN_MAIN
00184 reslist = new GfxResult(this,(MainFrame*)this,m_game);
00185 listsizer->Add(reslist, 1, wxEXPAND | wxLEFT | wxRIGHT, 1);
00186 #endif
00187
00188 InitMenu();
00189
00190 statusbar = CreateStatusBar(2, 0, Status_ID);
00191 int ww[2] = {-1, 160};
00192 statusbar->SetStatusWidths(2, ww);
00193 UpdateStatusBar();
00194
00195 b_rackrandomset = new wxButton(this, Button_SetRack, wxT(" Tirage "));
00196 b_rackrandomnew = new wxButton(this, Button_SetNew, wxT(" Complement "));
00197 b_search = new wxButton(this, Button_Search, wxT(" Rechercher "));
00198 b_back = new wxButton(this, Button_PlayBack, wxT(" Arriere "));
00199 b_play = new wxButton(this, Button_Play, wxT(" Jouer "));
00200
00201 b_rackrandomset->SetToolTip(wxT("Tirage aleatoire"));
00202 b_rackrandomnew->SetToolTip(wxT("Complement aleatoire du tirage"));
00203 b_search->SetToolTip( wxT("Recherche sur le tirage courant"));
00204 b_back->SetToolTip( wxT("Revenir un coup en arriere"));
00205 b_play->SetToolTip( wxT("Jouer le mot selectionne"));
00206
00207 wxBoxSizer *buttonsizer = new wxBoxSizer(wxHORIZONTAL);
00208 buttonsizer->Add(b_rackrandomset, 1, wxEXPAND | wxTOP | wxBOTTOM | wxLEFT , 1);
00209 buttonsizer->Add(b_rackrandomnew, 1, wxEXPAND | wxTOP | wxBOTTOM , 1);
00210 buttonsizer->Add(b_search, 1, wxEXPAND | wxTOP | wxBOTTOM , 1);
00211 buttonsizer->Add(b_back, 1, wxEXPAND | wxTOP | wxBOTTOM , 1);
00212 buttonsizer->Add(b_play, 1, wxEXPAND | wxTOP | wxBOTTOM | wxRIGHT, 1);
00213
00214 wxBoxSizer *mainsizer = new wxBoxSizer(wxVERTICAL);
00215 mainsizer->Add(listsizer , 1, wxEXPAND | wxVERTICAL, 0);
00216 mainsizer->Add(buttonsizer, 0, wxEXPAND , 0);
00217
00218 SetAutoLayout(TRUE);
00219 SetSizer(mainsizer);
00220 mainsizer->Fit(this);
00221 mainsizer->SetSizeHints(this);
00222
00223 SetClientSize(size_);
00224 Move(config.getFramePos(wxT(APPNAME)));
00225
00226 InitFrames();
00227 }
00228
00229
00230
00231
00232
00233 MainFrame::~MainFrame()
00234 {
00235 config.setFramePos(wxT(APPNAME), GetPosition());
00236 config.setFrameSize(wxT(APPNAME), GetClientSize());
00237
00238 if (m_game != NULL)
00239 {
00240 GameFactory::Instance()->releaseGame(*m_game);
00241 m_game = NULL;
00242 }
00243
00244 if (m_dic)
00245 {
00246 Dic_destroy(m_dic);
00247 }
00248 }
00249
00250
00251
00252
00253
00254 void
00255 MainFrame::InitMenu()
00256 {
00257
00258 wxMenu *menu_game = new wxMenu;
00259
00260 menu_game->Append(Menu_Game_New, wxT("Nouvelle"), wxT("Demarrer une nouvelle partie"));
00261 menu_game->Append(Menu_Game_Open, wxT("Charger..."), wxT("Charger une partie"));
00262 menu_game->Append(Menu_Game_Save, wxT("Sauver..."), wxT("Sauver cette partie"));
00263 menu_game->AppendSeparator();
00264 menu_game->Append(Menu_Game_Print, wxT("Imprimer..."), wxT("Imprimer cette partie"));
00265
00266 menu_game->Append(Menu_Game_PrintPreview, wxT("Preimpression"), wxT("Preimpression de la partie"));
00267 #ifdef ENABLE_SAVE_POSTSCRIPT
00268 menu_game->AppendSeparator();
00269 menu_game->Append(Menu_Game_PrintPS, wxT("Imprimer du PostScript"), wxT("Imprimer dans un fichier PostScript"));
00270 #endif
00271
00272 wxMenu *menu_conf_game = new wxMenu;
00273 menu_conf_game->Append(Menu_Conf_Game_Dic, wxT("Dictionnaire"), wxT("Choix du dictionnaire"));
00274 menu_conf_game->Append(Menu_Conf_Game_Search, wxT("Recherche"), wxT("Options de recherche"));
00275
00276 wxMenu *menu_tileback = new wxMenu;
00277 menu_tileback->Append(Menu_Conf_Aspect_BoardColour_Letters , wxT("Lettres jouees"), wxT("Lettres jouees sur la grille"));
00278 menu_tileback->Append(Menu_Conf_Aspect_BoardColour_TestLetters , wxT("Lettres provisoires"), wxT("Lettres du mot a jouer"));
00279 menu_tileback->AppendSeparator();
00280
00281 menu_tileback->Append(Menu_Conf_Aspect_BoardColour_TileBack , wxT("Fonds lettres jouees"), wxT("Fonds des pions sur la grille"));
00282 menu_tileback->Append(Menu_Conf_Aspect_BoardColour_TestTileBack, wxT("Fonds lettres provisoires"), wxT("Fonds des pions sur la grille"));
00283
00284 wxMenu *menu_conf_board_colour = new wxMenu;
00285 menu_conf_board_colour->Append(Menu_Conf_Aspect_BoardColour_Background, wxT("Fond"), wxT("Couleur du fond"));
00286 menu_conf_board_colour->Append(Menu_Conf_Aspect_BoardColour_Lines, wxT("Lignes"), wxT("Couleur des lignes"));
00287 menu_conf_board_colour->Append(Menu_Conf_Tile, wxT("Pions et lettres"), menu_tileback, wxT("Pions et lettres"));
00288 menu_conf_board_colour->AppendSeparator();
00289
00290 menu_conf_board_colour->Append(Menu_Conf_Aspect_BoardColour_Letters, wxT("Lettres jouees"), wxT("Lettres jouees sur la grille"));
00291
00292 menu_conf_board_colour->Append(Menu_Conf_Aspect_BoardColour_TestLetters, wxT("Lettres provisoires"), wxT("Lettres du mot a jouer"));
00293 menu_conf_board_colour->AppendSeparator();
00294 menu_conf_board_colour->Append(Menu_Conf_Aspect_BoardColour_Wx2, wxT("Mot compte double"), wxT("Mot compte double"));
00295 menu_conf_board_colour->Append(Menu_Conf_Aspect_BoardColour_Wx3, wxT("Mot compte triple"), wxT("Mot compte triple"));
00296 menu_conf_board_colour->Append(Menu_Conf_Aspect_BoardColour_Lx2, wxT("Lettre compte double"), wxT("Lettre compte double"));
00297 menu_conf_board_colour->Append(Menu_Conf_Aspect_BoardColour_Lx3, wxT("Lettre compte triple"), wxT("Lettre compte triple"));
00298 menu_conf_board_colour->AppendSeparator();
00299 menu_conf_board_colour->Append(Menu_Conf_Aspect_BoardColour_Default, wxT("Couleurs d'origine"), wxT("Retrouver les couleurs d'origine"));
00300
00301 wxMenu *menu_conf_board_font = new wxMenu;
00302
00303 menu_conf_board_font->Append(Menu_Conf_Aspect_Font_Search, wxT("Lettres de recherche"), wxT("Police de caracteres pour les recherches"));
00304
00305 menu_conf_board_font->Append(Menu_Conf_Aspect_Font_Board, wxT("Lettres de la grille"), wxT("Police de caracteres de la grille"));
00306
00307 wxMenu *menu_conf = new wxMenu;
00308 menu_conf->Append(Menu_Conf_Game, wxT("Jeu"), menu_conf_game, wxT("Configuration du jeu"));
00309 menu_conf->Append(Menu_Conf_Aspect_Font, wxT("Fonte des lettres"), menu_conf_board_font, wxT("Modification des fontes"));
00310 menu_conf->Append(Menu_Conf_Aspect_BoardColour, wxT("Couleurs de la grille"), menu_conf_board_colour, wxT("Modification des couleurs"));
00311 menu_conf->Append(Menu_Conf_Print, wxT("Impression"), wxT("Dimensions de la partie"));
00312
00313 wxMenu *menu_frame = new wxMenu;
00314 menu_frame->Append(Menu_ShowBoard, wxT("Grille"), wxT("Grille de jeu"));
00315
00316 menu_frame->Append(Menu_ShowVerif, wxT("Verification"), wxT("Verification d'un mot dans le dictionnaire"));
00317 menu_frame->Append(Menu_ShowSearch, wxT("Recherche"), wxT("Recherche dans le dictionnaire"));
00318 menu_frame->AppendSeparator();
00319 menu_frame->Append(Menu_ShowPlus1, wxT("Tirage + 1"), wxT("Lettres du tirage plus une"));
00320 menu_frame->Append(Menu_ShowRacc, wxT("Raccords"), wxT("Raccords sur un mot de la recherche"));
00321 menu_frame->Append(Menu_ShowBenj, wxT("Benjamins"), wxT("Benjamins sur un mot de la recherche"));
00322 menu_frame->AppendSeparator();
00323 menu_frame->Append(Menu_ShowBag, wxT("Sac"), wxT("Lettres restantes dans le sac"));
00324 menu_frame->AppendSeparator();
00325 menu_frame->Append(Menu_ShowGame, wxT("Partie"), wxT("Partie"));
00326 #ifndef ENABLE_RESLIST_IN_MAIN
00327 menu_frame->Append(Menu_ShowResult, wxT("Resultats"), wxT("Resultats"));
00328 #endif
00329
00330 wxMenu *menu_quit = new wxMenu;
00331 menu_quit->Append(Menu_Quit_Apropos, wxT("A propos..."), wxT("A propos d'Eliot"));
00332 menu_quit->Append(Menu_Quit_Confirm, wxT("Quitter"), wxT("Quitter"));
00333
00334 wxMenuBar *menu_bar = new wxMenuBar;
00335 menu_bar->Append(menu_game, wxT("Partie"));
00336 menu_bar->Append(menu_conf, wxT("Configuration"));
00337
00338 menu_bar->Append(menu_frame, wxT("Fenetres"));
00339 menu_bar->Append(menu_quit, wxT("Quitter"));
00340
00341 SetMenuBar(menu_bar);
00342 }
00343
00344
00345
00346
00347
00348 void
00349 MainFrame::OnCloseWindow(wxCloseEvent&)
00350 {
00351 this->Destroy();
00352 }
00353
00354
00355
00356
00357
00358 void
00359 MainFrame::OnMenuGameNew(wxCommandEvent&)
00360 {
00361 if (m_dic == NULL)
00362 {
00363
00364 wxMessageBox(wxT("Il n'y a pas de dictionnaire selectionne"), wxT("Eliot: erreur"),
00365 wxICON_INFORMATION | wxOK);
00366 return;
00367 }
00368
00369 TODO("selection du type de partie dans OnMenuGameNew\n");
00370
00371 if (m_game != NULL)
00372 {
00373 GameFactory::Instance()->releaseGame(*m_game);
00374 m_game = NULL;
00375 }
00376
00377 m_game = GameFactory::Instance()->createTraining(m_dic);
00378 m_game->start();
00379 rack->SetValue(wxU(""));
00380 InitFrames();
00381 #ifdef ENABLE_RESLIST_IN_MAIN
00382 reslist->SetGame(m_game);
00383 #endif
00384 UpdateStatusBar();
00385 UpdateFrames(AuxFrame::FORCE_REFRESH);
00386 }
00387
00388
00389
00390
00391
00392 void
00393 MainFrame::OnMenuGameOpen(wxCommandEvent&)
00394 {
00395 wxString txt;
00396 wxFileDialog dialog(this, wxT("Ouvrir une partie"), wxT(""), wxT(""), wxT("*"), wxOPEN);
00397 if (m_dic == NULL)
00398 {
00399
00400 wxMessageBox(wxT("Il n'y a pas de dictionnaire selectionne"), wxT("Eliot: erreur"),
00401 wxICON_INFORMATION | wxOK);
00402 return;
00403 }
00404 if (dialog.ShowModal() != wxID_OK)
00405 {
00406 return;
00407 }
00408
00409 if (m_game != NULL)
00410 {
00411 GameFactory::Instance()->releaseGame(*m_game);
00412 m_game = NULL;
00413 }
00414
00415 FILE* fin;
00416
00417 if ((fin = fopen(dialog.GetPath().mb_str(), "rb")) == NULL)
00418 {
00419 txt << wxT("Impossible d'ouvrir") << dialog.GetPath();
00420 wxMessageDialog msg(this, txt, wxT("Ouverture d'une partie"));
00421 msg.ShowModal();
00422 return ;
00423 }
00424
00425 m_game = Game::load(fin, m_dic);
00426 fclose(fin);
00427
00428 if (m_game == NULL)
00429 {
00430 wxMessageDialog msg(this,
00431 wxT("Erreur pendant la lecture de la partie"),
00432 wxT("chargement de partie"));
00433 msg.ShowModal();
00434 return;
00435 }
00436
00437 if (m_game->getHistory().getSize() == 0)
00438 {
00439 wxMessageDialog msg(this,
00440 wxT("Erreur pendant la lecture de la partie"),
00441 wxT("La partie est vide"));
00442 msg.ShowModal();
00443 return;
00444 }
00445
00446 std::string r = "";
00447
00448 if (m_game->getHistory().getSize() >= 0)
00449 {
00450 r = m_game->getCurrentPlayer().getCurrentRack().toString();
00451 }
00452
00453 rack->SetValue(wxU(r.c_str()));
00454
00455 InitFrames();
00456
00457 #ifdef ENABLE_RESLIST_IN_MAIN
00458 reslist->SetGame(m_game);
00459 #endif
00460 UpdateStatusBar();
00461 UpdateFrames(AuxFrame::FORCE_REFRESH);
00462 }
00463
00464
00465
00466
00467
00468 void
00469 MainFrame::OnMenuGameSave(wxCommandEvent& WXUNUSED(event))
00470 {
00471 wxFileDialog dialog(this, wxT("Sauver une partie"), wxT(""), wxT(""), wxT("*"), wxSAVE|wxOVERWRITE_PROMPT);
00472 if (dialog.ShowModal() == wxID_OK)
00473 {
00474 ofstream fout(dialog.GetPath().mb_str());
00475 if (fout.rdstate() == ios::failbit)
00476 {
00477 wxString txt;
00478
00479 txt << wxT("Impossible de creer ") << dialog.GetPath();
00480 wxMessageDialog msg(this, txt, wxT("Sauvegarde de la partie"));
00481 msg.ShowModal();
00482 return ;
00483 }
00484 m_game->save(fout);
00485 fout.close();
00486 }
00487 }
00488
00489
00490
00491
00492
00493 void
00494 MainFrame::OnMenuGamePrint(wxCommandEvent& WXUNUSED(event))
00495 {
00496
00497 if (m_game == NULL)
00498 {
00499 wxMessageBox(wxT("Pas de partie en cours"), wxT("Eliot: erreur"),
00500 wxICON_INFORMATION | wxOK);
00501 return;
00502 }
00503 wxPrintDialogData printDialogData(config.getPrintData());
00504 wxPrinter printer(&printDialogData);
00505 GamePrintout printout(*m_game);
00506 if (!printer.Print(this, &printout, TRUE))
00507
00508 wxMessageBox(wxT("Impression non effectuee."));
00509 }
00510
00511 void
00512 MainFrame::OnMenuGamePrintPreview(wxCommandEvent& WXUNUSED(event))
00513 {
00514
00515 if (m_game == NULL)
00516 {
00517 wxMessageBox(wxT("Pas de partie en cours"), wxT("Eliot: erreur"),
00518 wxICON_INFORMATION | wxOK);
00519 return;
00520 }
00521 wxPrintData printdata = config.getPrintData();
00522
00523 wxString msg;
00524 wxPrintPreview *preview = new wxPrintPreview(new GamePrintout(*m_game),
00525 new GamePrintout(*m_game), & printdata);
00526 if (!preview->Ok())
00527 {
00528 delete preview;
00529
00530 msg << wxT("Probleme de previsualisation.\n")
00531
00532 << wxT("Il se peut que l'imprimante par defaut soit mal initialisee");
00533
00534 wxMessageBox(msg, wxT("Impression (previsualisation)"), wxOK);
00535 return;
00536 }
00537 wxPreviewFrame *frame = new wxPreviewFrame(preview, this, wxT("Impression"),
00538 wxPoint(-1, -1), wxSize(600, 550));
00539 frame->Centre(wxBOTH);
00540 frame->Initialize();
00541 frame->Show(TRUE);
00542 }
00543
00544 void
00545 MainFrame::OnMenuGamePrintPS(wxCommandEvent& WXUNUSED(event))
00546 {
00547 #ifdef ENABLE_SAVE_POSTSCRIPT
00548
00549 if (m_game == NULL)
00550 {
00551 wxMessageBox(wxT("Pas de partie en cours"), wxT("Eliot: erreur"),
00552 wxICON_INFORMATION | wxOK);
00553 return;
00554 }
00555 wxString txt;
00556 wxFileDialog dialog(this, wxT("Imprimer dans un fichier PostScript"), wxT(""), wxT(""), wxT("*.ps"), wxSAVE|wxOVERWRITE_PROMPT);
00557 if (dialog.ShowModal() == wxID_OK)
00558 {
00559 wxPrintData printdataPS;
00560 printdataPS.SetPrintMode(wxPRINT_MODE_FILE);
00561 printdataPS.SetFilename(dialog.GetPath());
00562 printdataPS.SetPaperId(wxPAPER_A4);
00563 printdataPS.SetQuality(wxPRINT_QUALITY_HIGH);
00564 printdataPS.SetOrientation(wxPORTRAIT);
00565
00566 wxPostScriptDC printps(printdataPS);
00567 if (printps.Ok())
00568 {
00569 wxPrintDialogData printDialogData(printdataPS);
00570 wxPostScriptPrinter printer(&printDialogData);
00571 GamePrintout printout(*m_game);
00572 if (!printer.Print(this, &printout, FALSE))
00573 {
00574
00575 wxMessageBox(wxT("Impression non effectuee."));
00576 }
00577 else
00578 {
00579 wxString msg;
00580
00581 msg << wxT("Dessin effectue dans ") << dialog.GetPath() << wxT("\n");
00582 wxMessageBox(msg, wxT("Sauvegarde PostScript"), wxOK);
00583 }
00584 }
00585 else
00586 {
00587 wxString msg;
00588 msg << wxT("impossible d'initialiser le traitement PostScript.\n");
00589 wxMessageBox(msg, wxT("Sauvegarde PostScript"), wxOK);
00590 }
00591 }
00592 #endif
00593 }
00594
00595
00596
00597
00598
00599
00600 void
00601 MainFrame::OnMenuConfGameDic(wxCommandEvent& WXUNUSED(event))
00602 {
00603 wxString txt, msg, dicpath;
00604 wxFileDialog dialog(this, wxT("Choisir un dictionnaire"), wxT(""), wxT("*.dawg"), wxT("*.dawg"), wxOPEN);
00605 if (dialog.ShowModal() == wxID_OK)
00606 {
00607 wxString dicpath = dialog.GetPath();
00608 Dictionary dic;
00609 int res = Dic_load(&dic, dicpath.mb_str());
00610 if (res == 0)
00611 {
00612 if (m_dic)
00613 {
00614 Dic_destroy(m_dic);
00615 }
00616
00617 m_dic = dic;
00618 config.setDicPath(dialog.GetPath(), ::wxFileNameFromPath(dialog.GetPath()));
00619 }
00620 else
00621 {
00622 switch (res)
00623 {
00624 case 0: break;
00625
00626 case 1: msg << wxT("chargement: probleme d'ouverture de ") << dicpath << wxT("\n"); break;
00627
00628 case 2: msg << wxT("chargement: mauvais en-tete de dictionnaire\n"); break;
00629
00630 case 3: msg << wxT("chargement: probleme 3 d'allocation memoire\n"); break;
00631
00632 case 4: msg << wxT("chargement: probleme 4 d'allocation memoire\n"); break;
00633
00634 case 5: msg << wxT("chargement: probleme de lecture des arcs du dictionnaire\n"); break;
00635
00636 default: msg << wxT("chargement: probleme non-repertorie\n"); break;
00637 }
00638 wxMessageDialog dlg(NULL, msg, wxT(APPNAME));
00639 dlg.ShowModal();
00640 }
00641 }
00642 UpdateStatusBar();
00643 UpdateFrames();
00644 }
00645
00646
00647
00648
00649
00650 void
00651 MainFrame::OnMenuConfGameSearch(wxCommandEvent& WXUNUSED(event))
00652 {
00653 ConfSearchDlg dlg(this);
00654 dlg.ShowModal();
00655 }
00656
00657
00658
00659
00660
00661 void
00662 MainFrame::OnMenuConfPrint(wxCommandEvent& WXUNUSED(event))
00663 {
00664 ConfDimDlg dlg(this, config.getPrintData(), config.getPageSetupData());
00665 if (dlg.ShowModal() == wxID_OK)
00666 {
00667 config.setPrintData(dlg.getPrintData());
00668 config.setPageSetupData(dlg.getPageSetupData());
00669 }
00670 }
00671
00672
00673
00674
00675
00676 void
00677 MainFrame::OnMenuConfAspectFont(wxCommandEvent& event)
00678 {
00679 int id;
00680 wxString attr;
00681
00682 id = event.GetId();
00683 if (! GetMenuBar()->FindItem(id))
00684 return;
00685
00686 switch (id)
00687 {
00688 case Menu_Conf_Aspect_Font_Search: attr = wxString(LISTFONT); break;
00689 case Menu_Conf_Aspect_Font_Board: attr = wxString(BOARDFONT); break;
00690 case Menu_Conf_Aspect_Font_Default: attr = wxU("Default"); break;
00691 default: INCOMPLETE; break;
00692 }
00693
00694 if (attr == wxU("Default"))
00695 config.setFontDefault();
00696 else
00697 config.setFont(attr, config.ChooseFont(this, config.getFont(attr)));
00698
00699 UpdateFrames(AuxFrame::FORCE_REFRESH);
00700 }
00701
00702
00703
00704
00705
00706 void
00707 MainFrame::OnMenuConfAspectBoardColour(wxCommandEvent& event)
00708 {
00709 int id;
00710 wxString attr;
00711
00712 id = event.GetId();
00713 if (! GetMenuBar()->FindItem(id))
00714 return;
00715
00716 switch (id)
00717 {
00718 case Menu_Conf_Aspect_BoardColour_Lines: attr = wxString(BCOLOURLINES); break;
00719 case Menu_Conf_Aspect_BoardColour_Wx2: attr = wxString(BCOLOURWX2); break;
00720 case Menu_Conf_Aspect_BoardColour_Wx3: attr = wxString(BCOLOURWX3); break;
00721 case Menu_Conf_Aspect_BoardColour_Lx2: attr = wxString(BCOLOURLX2); break;
00722 case Menu_Conf_Aspect_BoardColour_Lx3: attr = wxString(BCOLOURLX3); break;
00723 case Menu_Conf_Aspect_BoardColour_Background: attr = wxString(BCOLOURBACKGROUND); break;
00724 case Menu_Conf_Aspect_BoardColour_Letters: attr = wxString(BCOLOURLETTERS); break;
00725 case Menu_Conf_Aspect_BoardColour_TestLetters: attr = wxString(BCOLOURTSTLETTERS); break;
00726 case Menu_Conf_Aspect_BoardColour_TileBack: attr = wxString(BTILEBACKGROUND); break;
00727 case Menu_Conf_Aspect_BoardColour_TestTileBack: attr = wxString(BTSTTILEBACKGROUND); break;
00728 case Menu_Conf_Aspect_BoardColour_Default: attr = wxU("Default"); break;
00729 default: INCOMPLETE; break;
00730 }
00731
00732 if (attr == wxU("Default"))
00733 config.setColourDefault();
00734 else
00735 config.setColour(attr, config.ChooseColour(this, config.getColour(attr)));
00736
00737 UpdateFrames(AuxFrame::FORCE_REFRESH);
00738 }
00739
00740
00741
00742
00743
00744 void
00745 MainFrame::OnMenuQuitApropos(wxCommandEvent& WXUNUSED(event))
00746 {
00747 wxString msg;
00748
00749 msg << wxT("Eliot\nCopyright Antoine Fraboulet 1999-2004\n\n");
00750 msg << wxT("This program is free software; you can redistribute it and/or modify\n");
00751 msg << wxT("it under the terms of the GNU General Public License as published by\n");
00752 msg << wxT("the Free Software Foundation; either version 2 of the License, or\n");
00753 msg << wxT("(at your option) any later version.\n\n");
00754 msg << wxT("Version ") << wxT(VERSION) << wxT("\n");
00755 wxMessageBox(msg, wxT("A propos d'Eliot"), wxICON_INFORMATION | wxOK);
00756 }
00757
00758 void
00759 MainFrame::OnMenuQuitConfirm(wxCommandEvent& WXUNUSED(event))
00760 {
00761 Close(TRUE);
00762 }
00763
00764
00765
00766
00767
00768
00769 void
00770 MainFrame::OnSetRack(wxCommandEvent& event)
00771 {
00772 int id;
00773
00774 Game::set_rack_mode mode = Game::RACK_NEW;
00775 debug("OnSetRack ");
00776 switch ((id = event.GetId()))
00777 {
00778 case Button_SetRack:
00779 mode = Game::RACK_ALL;
00780 debug("PlayedRack::RACK_ALL\n");
00781 break;
00782 case Button_SetNew:
00783 mode = Game::RACK_NEW;
00784 debug("PlayedRack::RACK_NEW\n");
00785 break;
00786 case Button_SetManual:
00787 mode = Game::RACK_MANUAL;
00788 debug("PlayedRack::RACK_MANUAL\n");
00789 break;
00790 default:
00791 return;
00792 }
00793 SetRack(mode);
00794 }
00795
00796 void
00797 MainFrame::OnSearch(wxCommandEvent& WXUNUSED(event))
00798 {
00799 debug("MainFrame::OnSearch\n");
00800 Search();
00801 }
00802
00803 void
00804 MainFrame::OnTextEnter(wxCommandEvent& WXUNUSED(event))
00805 {
00806 debug("MainFrame::OnTextEnter -> %s\n",(const char*)rack->GetValue().mb_str());
00807 SetRack(Game::RACK_MANUAL,rack->GetValue());
00808 Search();
00809 }
00810
00811 void
00812 MainFrame::OnPlay(wxCommandEvent& event)
00813 {
00814 int dir = 1;
00815 int id = event.GetId();
00816 switch (id)
00817 {
00818 case Button_Play:
00819 dir = 1;
00820 break;
00821 case Button_PlayBack:
00822 dir = -1;
00823 break;
00824 default:
00825 break;
00826 }
00827 Play(dir);
00828 }
00829
00830
00831
00832
00833
00834 void
00835 MainFrame::InitFrames()
00836 {
00837 debug("InitFrames start : \n");
00838 if (m_game == NULL)
00839 {
00840 debug("m_game == NULL\n");
00841 return;
00842 }
00843
00844 for(int i=0 ; i < MAX_FRAME_ID; i++)
00845 {
00846 if (auxframes_ptr[i] != NULL)
00847 {
00848 debug(" delete frame %d\n",i);
00849 delete auxframes_ptr[i];
00850 }
00851 }
00852
00853 auxframes_ptr[ ID_Frame_Verif ] = new VerifFrame (this, m_game->getDic());
00854 debug("0 : Verif\n");
00855 auxframes_ptr[ ID_Frame_Search ] = new SearchFrame(this, m_game->getDic());
00856 debug("1 : Search\n");
00857 auxframes_ptr[ ID_Frame_Plus1 ] = new Plus1Frame (this, m_game);
00858 debug("2 : Plus1\n");
00859 auxframes_ptr[ ID_Frame_Racc ] = new RaccFrame (this, m_game);
00860 debug("3 : Racc\n");
00861 auxframes_ptr[ ID_Frame_Benj ] = new BenjFrame (this, m_game);
00862 debug("4 : Benj\n");
00863 auxframes_ptr[ ID_Frame_Bag ] = new BagFrame (this, *m_game);
00864 debug("5 : Bag\n");
00865 auxframes_ptr[ ID_Frame_Board ] = new BoardFrame (this, *m_game);
00866 debug("6 : Board\n");
00867 auxframes_ptr[ ID_Frame_Game ] = new GameFrame (this, *m_game);
00868 debug("7 : Game\n");
00869 #ifndef ENABLE_RESLIST_IN_MAIN
00870 auxframes_ptr[ ID_Frame_Result ] = new ResultFrame(this, m_game);
00871 debug("8 : Result\n");
00872 #endif
00873
00874 for (int i = MIN_FRAME_ID; i < MAX_FRAME_ID; i++)
00875 {
00876 if (auxframes_ptr[i] != NULL)
00877 {
00878 auxframes_ptr[i]->Reload();
00879 debug("reload %d\n",i);
00880 }
00881 }
00882 debug("InitFrames end ok.\n");
00883 }
00884
00885 void
00886 MainFrame::OnMenuShowFrame(wxCommandEvent& event)
00887 {
00888 int id;
00889 id = event.GetId();
00890
00891 if (!GetMenuBar()->FindItem(id))
00892 return;
00893 id -= IDBASE;
00894
00895 if ((id < 0) || (id >= MAX_FRAME_ID))
00896 {
00897 INCOMPLETE;
00898 return;
00899 }
00900
00901 if (auxframes_ptr[id] == NULL)
00902 {
00903 debug("ShowFrame: auxframes_ptr[%d] == NULL\n", id);
00904 return;
00905 }
00906 auxframes_ptr[id]->SwitchDisplay();
00907 debug("ShowFrame: SwitchDisplay frame %d\n",id);
00908 }
00909
00910
00911
00912
00913
00914 void
00915 MainFrame::UpdateFrames(AuxFrame::refresh_t force)
00916 {
00917 for (int id = 0; id < MAX_FRAME_ID; id++)
00918 {
00919 if (auxframes_ptr[id])
00920 {
00921 auxframes_ptr[id]->Refresh(force);
00922 }
00923 }
00924 #ifdef ENABLE_RESLIST_IN_MAIN
00925 if (reslist)
00926 {
00927 reslist->Refresh();
00928 }
00929 #endif
00930 }
00931
00932 void
00933 MainFrame::UpdateStatusBar()
00934 {
00935 wxString text;
00936 if (statusbar)
00937 {
00938 text = config.getDicName() + wxT(" ") + config.getTileName();
00939 statusbar->SetStatusText(text, 0);
00940
00941 if (m_game)
00942 {
00943 text = wxT("");
00944 text << wxT("coup:") << (m_game->getHistory().getSize() + 1) << wxT(" ");
00945 text << wxT("points:") << (m_game->getCurrentPlayer().getPoints());
00946 statusbar->SetStatusText(text, 1);
00947 }
00948 }
00949 }
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961 void
00962 MainFrame::SetRack(Game::set_rack_mode mode, wxString srack)
00963 {
00964 int res = 0;
00965 std::string str;
00966 wxString msg;
00967 bool check = config.getRackChecking();
00968
00969 str = (const char*)srack.mb_str();
00970 res = ((Training*)m_game)->setRack(mode, check, str);
00971
00972 switch (res)
00973 {
00974 case 0x00:
00975 debug("SetRack Ok :: ");
00976 break;
00977 case 0x01:
00978 msg = wxT("Le sac ne contient pas assez de lettres\npour assurer le tirage.");
00979 wxMessageBox(msg, wxT("Correction du tirage"), wxICON_INFORMATION | wxOK);
00980 return;
00981 case 0x02:
00982 msg = wxT("Le tirage doit contenir au moins 2 consonnes et 2 voyelles.\n");
00983 wxMessageBox(msg, wxT("Correction du tirage"), wxICON_INFORMATION | wxOK);
00984 return;
00985 case 0x03:
00986 msg = wxT("Le tirage doit contenir au moins 2 consonnes et 2 voyelles\n");
00987 msg += wxT("mais le sac ne contient plus assez de lettres.\n\n");
00988 wxMessageBox(msg, wxT("Correction du tirage"), wxICON_INFORMATION | wxOK);
00989 break;
00990 default:
00991 statusbar->SetStatusText(wxT("Le tirage a ete modifie manuellement"), 0);
00992 break;
00993 }
00994
00995 std::string r = m_game->getCurrentPlayer().getCurrentRack().toString();
00996 debug("MainFrame::SetRack : setvalue %s\n",r.c_str());
00997 rack->SetValue(wxU(r.c_str()));
00998 UpdateFrames();
00999 UpdateStatusBar();
01000 }
01001
01002 void
01003 MainFrame::Search()
01004 {
01005 ((Training*)m_game)->removeTestPlay();
01006 #ifdef ENABLE_RESLIST_IN_MAIN
01007 reslist->Search();
01008 #else
01009 if (auxframes_ptr[ ID_Frame_Result ])
01010 {
01011 ((ResultFrame*)(auxframes_ptr[ ID_Frame_Result ]))->Search();
01012 }
01013 #endif
01014 UpdateFrames();
01015 UpdateStatusBar();
01016 }
01017
01018 void
01019 MainFrame::Play(int n)
01020 {
01021 ((Training*)m_game)->removeTestPlay();
01022 if (n < 0)
01023 {
01024 debug("MainFrame::Play back %d\n",n);
01025 m_game->back(- n);
01026 }
01027 else
01028 {
01029 int n=0;
01030 debug("MainFrame::Play +%d\n",n);
01031 #ifdef ENABLE_RESLIST_IN_MAIN
01032 n = reslist->GetSelected();
01033 #else
01034 n = auxframes_ptr[ ID_Frame_Result ]->GetSelected();
01035 #endif
01036 if (n > -1)
01037 {
01038 ((Training*)m_game)->playResult(n);
01039 }
01040 }
01041 wxString r = wxU(m_game->getCurrentPlayer().getCurrentRack().toString().c_str());
01042 rack->SetValue(r);
01043 UpdateFrames();
01044 UpdateStatusBar();
01045 }
01046
01047 void
01048 MainFrame::TestPlay(int n)
01049 {
01050 ((Training*)m_game)->removeTestPlay();
01051 ((Training*)m_game)->testPlay(n);
01052 UpdateFrames();
01053 UpdateStatusBar();
01054 }
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064