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 <iostream>
00028 #include <sstream>
00029
00030 #include "wx/sizer.h"
00031 #include "wx/button.h"
00032 #include "wx/intl.h"
00033
00034 #include "wx/clipbrd.h"
00035 #include "wx/dataobj.h"
00036
00037 #include "ewx.h"
00038
00039 #include "dic.h"
00040 #include "dic_search.h"
00041 #include "training.h"
00042 #include "player.h"
00043 #include "game.h"
00044
00045 #include "configdb.h"
00046 #include "auxframes.h"
00047 #include "mainframe.h"
00048 #include "searchpanel.h"
00049
00050
00051
00052
00053
00054 AuxFrame::AuxFrame(wxFrame* parent, int _id, wxString _name, wxString _classname):
00055 wxFrame(parent, -1, wxU("Eliot: ") + _name, wxPoint(-1, -1), wxSize(-1, -1),
00056 wxRESIZE_BORDER | wxCAPTION | wxFRAME_FLOAT_ON_PARENT, _classname)
00057 {
00058 frameid = (frames_id_t)_id;
00059 name = _name;
00060 classname = _classname;
00061 show = config.getFrameShow(classname);
00062 }
00063
00064 AuxFrame::~AuxFrame()
00065 {
00066 wxPoint p = GetPosition();
00067 wxSize s = GetClientSize();
00068 config.setFramePos(classname, p);
00069 config.setFrameSize(classname, s);
00070 config.setFrameShow(classname, show);
00071 }
00072
00073 void
00074 AuxFrame::SwitchDisplay()
00075 {
00076 if (show == 0)
00077 {
00078 Show(TRUE);
00079 Raise();
00080 show = 1;
00081 Reload();
00082 }
00083 else
00084 {
00085 Show(FALSE);
00086 show = 0;
00087 }
00088 }
00089
00090 void
00091 AuxFrame::Reload()
00092 {
00093 #define MINW 50
00094 #define MINH 50
00095
00096 wxSize size;
00097
00098
00099 Move(config.getFramePos(classname));
00100 size = config.getFrameSize(classname);
00101
00102 if (size.GetWidth() < MINW)
00103 size.SetWidth(MINW);
00104 if (size.GetHeight() < MINH)
00105 size.SetHeight(MINH);
00106
00107 SetClientSize(size);
00108 Refresh();
00109 if (show)
00110 {
00111 Show(FALSE);
00112 Show(TRUE);
00113 }
00114 }
00115
00116
00117
00118
00119
00120 BoardFrame::BoardFrame(wxFrame* parent, Game& iGame):
00121 AuxFrame(parent, ID_Frame_Board, wxT("Grille"), FRAMEBOARD)
00122 {
00123 board = new GfxBoard(this, iGame);
00124 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
00125 sizer->Add(board, 1, wxEXPAND, 0);
00126 SetAutoLayout(TRUE);
00127 SetSizer(sizer);
00128 sizer->Fit(this);
00129 sizer->SetSizeHints(this);
00130 }
00131
00132 void
00133 BoardFrame::Refresh(refresh_t force)
00134 {
00135
00136 if (force == REFRESH)
00137 board->Refresh(GfxBoard::BOARD_REFRESH);
00138 else
00139 board->Refresh(GfxBoard::BOARD_FORCE_REFRESH);
00140 }
00141
00142
00143
00144
00145
00146 BagFrame::BagFrame(wxFrame* parent, Game& iGame):
00147 AuxFrame(parent, ID_Frame_Bag, wxT("sac"), FRAMEBAG),
00148 m_game(iGame)
00149 {
00150 tiles = new wxListCtrl(this, -1);
00151 tiles->SetSingleStyle(wxLC_LIST);
00152
00153
00154
00155
00156 #ifdef DEBUG
00157 wxFont font(8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
00158 wxFONTWEIGHT_NORMAL, false, wxString(wxT("Courier New")), wxFONTENCODING_SYSTEM);
00159 tiles->SetFont(font);
00160 #endif
00161
00162 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
00163 sizer->Add(tiles, 1, wxEXPAND | wxALL, 1);
00164 SetAutoLayout(TRUE);
00165 SetSizer(sizer);
00166 sizer->Fit(this);
00167 }
00168
00169 void
00170 BagFrame::Refresh(refresh_t force)
00171 {
00172
00173 int n,index;
00174 wxString buf;
00175 #ifdef DEBUG
00176 wxChar format[] = wxT("%c:%2d[%2d]");
00177 #else
00178 wxChar format[] = wxT("%c:%2d");
00179 #endif
00180
00181 tiles->ClearAll();
00182
00183 std::list<Tile>::const_iterator it;
00184 const std::list<Tile>& allTiles = Tile::getAllTiles();
00185 for (index = 0, it = allTiles.begin(); it != allTiles.end(); index++, it++)
00186 {
00187 n = m_game.getBag().in(*it);
00188 #ifdef DEBUG
00189 buf.Printf(format, it->toChar(), n, n - it->maxNumber());
00190 #else
00191 buf.Printf(format, it->toChar(), n);
00192 #endif
00193 tiles->InsertItem(index,buf);
00194 }
00195 }
00196
00197
00198
00199
00200
00201 SearchFrame::SearchFrame(wxFrame *parent, Dictionary _dic):
00202 AuxFrame(parent, ID_Frame_Search, wxT("recherche"), FRAMESEARCH)
00203 {
00204 panel = new SearchPanel(this, _dic);
00205 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
00206 sizer->Add(panel, 1, wxEXPAND, 0);
00207 SetAutoLayout(TRUE);
00208 SetSizer(sizer);
00209 sizer->Fit(this);
00210 }
00211
00212 void
00213 SearchFrame::Refresh(refresh_t force)
00214 {
00215
00216 }
00217
00218
00219
00220
00221
00222 enum
00223 {
00224 Word_Id,
00225 Result_Id,
00226 };
00227
00228 BEGIN_EVENT_TABLE(VerifFrame, AuxFrame)
00229 EVT_TEXT(Word_Id, VerifFrame::OnText)
00230 END_EVENT_TABLE()
00231
00232 VerifFrame::VerifFrame(wxFrame* parent, Dictionary _dic):
00233
00234 AuxFrame(parent, ID_Frame_Verif, wxT("verification"), FRAMEVERIF)
00235 {
00236 dic = _dic;
00237 word = new wxTextCtrl(this, Word_Id, wxT(""));
00238 word->SetFont(config.getFont(LISTFONT));
00239
00240 word->SetToolTip(wxT("Mot a verifier"));
00241 result = new wxStaticText(this, Result_Id, wxT(""));
00242 result->SetFont(config.getFont(LISTFONT));
00243 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00244 sizer->Add(word, 1, wxEXPAND | wxALL, 1);
00245 sizer->Add(result, 1, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL, 1);
00246
00247 SetAutoLayout(TRUE);
00248 SetSizer(sizer);
00249 sizer->Fit(this);
00250 sizer->SetSizeHints(this);
00251 }
00252
00253 void
00254 VerifFrame::verif()
00255 {
00256 if (dic == NULL)
00257 {
00258 result->SetLabel(wxT("pas de dictionnaire"));
00259 return;
00260 }
00261 if (Dic_search_word(dic, word->GetValue().mb_str()))
00262 result->SetLabel(wxT("existe"));
00263 else
00264 result->SetLabel(wxT("n'existe pas"));
00265 }
00266
00267 void
00268 VerifFrame::OnText(wxCommandEvent&)
00269 {
00270 verif();
00271 }
00272
00273 void
00274 VerifFrame::Refresh(refresh_t force)
00275 {
00276
00277 }
00278
00279
00280
00281
00282
00283 enum {
00284 ListBoxID,
00285 ButtonCopyID
00286 };
00287
00288 BEGIN_EVENT_TABLE(AuxFrameList, AuxFrame)
00289 EVT_BUTTON (ButtonCopyID , AuxFrameList::OnCopy)
00290 END_EVENT_TABLE()
00291
00292 AuxFrameList::AuxFrameList(wxFrame* parent, int _id, wxString _name, wxString _classname, Game *g):
00293 AuxFrame(parent, _id, _name, _classname)
00294
00295 {
00296 game = g;
00297 savedword = "";
00298
00299 wxBoxSizer *sizer_v = new wxBoxSizer(wxVERTICAL);
00300 listbox = new wxListBox(this, ListBoxID);
00301 listbox->SetFont(config.getFont(LISTFONT));
00302 listbox->SetToolTip(name);
00303 sizer_v->Add(listbox, 1, wxEXPAND | wxALL, 1);
00304
00305 button = new wxButton(this, ButtonCopyID, wxT("Copier"), wxPoint(0, 0), wxSize(-1, -1));
00306 sizer_v->Add(button, 0, wxEXPAND | wxALL, 1);
00307
00308 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
00309 sizer->Add(sizer_v, 1, wxEXPAND, 0);
00310
00311 SetAutoLayout(TRUE);
00312 SetSizer(sizer);
00313 sizer->Fit(this);
00314 sizer->SetSizeHints(this);
00315 }
00316
00317 void
00318 AuxFrameList::OnCopy(wxCommandEvent& event)
00319 {
00320 wxString textdata;
00321
00322 if (wxTheClipboard->Open())
00323 {
00324 textdata = wxT("");
00325 for (int i = 0; i < listbox->GetCount(); i++)
00326 {
00327 textdata << listbox->GetString(i) << wxT("\n");
00328 }
00329 wxTextDataObject* ptr = new wxTextDataObject(textdata);
00330 wxTheClipboard->AddData(ptr);
00331 wxTheClipboard->Close();
00332 }
00333 }
00334
00335 void
00336 AuxFrameList::Waiting()
00337 {
00338 listbox->Clear();
00339 listbox->Show(TRUE);
00340 }
00341
00342 void
00343 AuxFrameList::Refresh(refresh_t force)
00344 {
00345
00346 if (game == NULL)
00347 {
00348 listbox->Clear();
00349 listbox->Append(wxT("Pas de partie en cours"));
00350
00351 return;
00352 }
00353 if (game->getDic() == NULL)
00354 {
00355 listbox->Clear();
00356 listbox->Append(wxT("Pas de dictionnaire"));
00357
00358 return;
00359 }
00360 if (show == 0)
00361 {
00362
00363 return;
00364 }
00365 noresult = true;
00366 refresh();
00367 if (noresult == true)
00368 {
00369
00370 listbox->Clear();
00371 listbox->Append(wxT("Aucun resultat"));
00372 }
00373
00374 }
00375
00376
00377
00378
00379
00380 void
00381 Plus1Frame::refresh()
00382 {
00383 std::string rack;
00384
00385 rack = game->getCurrentPlayer().getCurrentRack().toString();
00386
00387
00388 if (savedword == rack)
00389 {
00390 noresult = false;
00391
00392 return;
00393 }
00394 savedword = rack;
00395
00396 char buff[DIC_LETTERS][RES_7PL1_MAX][DIC_WORD_MAX];
00397 Dic_search_7pl1(game->getDic(), rack.c_str(), buff, config.getJokerPlus1());
00398
00399 listbox->Clear();
00400 wxString res[DIC_LETTERS*(RES_7PL1_MAX+1)];
00401 int resnum = 0;
00402 res[resnum++] = wxString(wxT("Tirage: ")) + wxString(wxU(rack.c_str()));
00403 for (int i = 0; i < DIC_LETTERS; i++)
00404 {
00405 if (i && buff[i][0][0])
00406 {
00407 res[resnum++] = wxString(wxT("+")) + (wxChar)(i + 'A' - 1);
00408 noresult = false;
00409 }
00410 for (int j = 0; j < RES_7PL1_MAX && buff[i][j][0]; j++)
00411 {
00412 res[resnum++] = wxString(wxT(" ")) + wxU(buff[i][j]);
00413 noresult = false;
00414 }
00415 }
00416 listbox->Set(resnum, res);
00417
00418 }
00419
00420
00421
00422
00423
00424 void
00425 BenjFrame::refresh()
00426 {
00427 std::string word;
00428
00429 if (game->getMode() != Game::kTRAINING)
00430 return;
00431
00432 word = ((Training*)game)->getTestPlayWord();
00433 if (savedword == word)
00434 {
00435 noresult = false;
00436 return;
00437 }
00438 savedword = word;
00439
00440 char wordlist[RES_BENJ_MAX][DIC_WORD_MAX];
00441 Dic_search_Benj(game->getDic(), word.c_str(), wordlist);
00442
00443 wxString res[RES_BENJ_MAX];
00444 int resnum = 0;
00445 for (int i = 0; (i < RES_BENJ_MAX) && (wordlist[i][0]); i++)
00446 {
00447 res[resnum++] = wxU(wordlist[i]);
00448
00449 noresult = false;
00450 }
00451 listbox->Set(resnum, res);
00452 }
00453
00454
00455
00456
00457
00458
00459 void
00460 RaccFrame::refresh()
00461 {
00462 std::string word;
00463
00464 if (game->getMode() != Game::kTRAINING)
00465 return;
00466
00467 word = ((Training*)game)->getTestPlayWord();
00468 if (savedword == word)
00469 {
00470 noresult = false;
00471 return;
00472 }
00473 savedword = word;
00474
00475 char wordlist[RES_RACC_MAX][DIC_WORD_MAX];
00476 Dic_search_Racc(game->getDic(), word.c_str(), wordlist);
00477
00478 wxString res[RES_RACC_MAX];
00479 int resnum = 0;
00480 for (int i = 0; (i < RES_RACC_MAX) && (wordlist[i][0]); i++)
00481 {
00482 res[resnum++] = wxU(wordlist[i]);
00483
00484 noresult = false;
00485 }
00486 listbox->Set(resnum, res);
00487 }
00488
00489
00490
00491
00492
00493 AuxFrameText::AuxFrameText(wxFrame* parent, int _id, wxString _name, wxString _classname, int _style):
00494 AuxFrame(parent, _id, _name, _classname)
00495
00496 {
00497 wxBoxSizer *sizer_v = new wxBoxSizer(wxVERTICAL);
00498 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
00499
00500 wxFont font(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
00501 wxFONTWEIGHT_NORMAL, false, wxString(wxT("Courier New")), wxFONTENCODING_SYSTEM);
00502
00503 textbox = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, _style);
00504 textbox->SetFont(font);
00505
00506 sizer_v->Add(textbox, 1, wxEXPAND | wxALL, 1);
00507 sizer->Add(sizer_v, 1, wxEXPAND, 0);
00508
00509 SetAutoLayout(TRUE);
00510 SetSizer(sizer);
00511 sizer->Fit(this);
00512 sizer->SetSizeHints(this);
00513 }
00514
00515
00516
00517
00518
00519 GameFrame::GameFrame(wxFrame* parent, Game& iGame):
00520 AuxFrameText(parent, ID_Frame_Game, wxT("partie"), FRAMEGAME, wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP),
00521 m_game(iGame)
00522 {
00523 textbox->Clear();
00524 textbox->AppendText(wxT(""));
00525 }
00526
00527 void
00528 GameFrame::Refresh(refresh_t force)
00529 {
00530 std::ostringstream mos;
00531 m_game.save(mos);
00532 #ifdef DEBUG
00533 mos << std::string(30,'-') << std::endl;
00534 mos << "Player History\n";
00535 mos << m_game.getPlayer(0).toString();
00536 mos << std::string(30,'-') << std::endl;
00537 mos << "Game History\n";
00538 mos << m_game.getHistory().toString();
00539 #endif
00540 textbox->Clear();
00541 textbox->AppendText( wxU( mos.str().c_str() ) );
00542 }
00543
00544
00545
00546
00547
00548 BEGIN_EVENT_TABLE(ResultFrame, AuxFrame)
00549 END_EVENT_TABLE()
00550
00551 ResultFrame::ResultFrame(wxFrame* parent, Game* iGame):
00552 AuxFrame(parent, ID_Frame_Result, wxT("recherche"), FRAMERESULT)
00553 {
00554 reslist = new GfxResult(this, (MainFrame*)parent, iGame);
00555
00556 wxBoxSizer *sizer_v = new wxBoxSizer(wxVERTICAL);
00557 wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
00558
00559 sizer_v->Add(reslist, 1, wxEXPAND, 0);
00560 sizer->Add (sizer_v, 1, wxEXPAND | wxALL, 2);
00561
00562 SetAutoLayout(TRUE);
00563 SetSizer(sizer);
00564 sizer->Fit(this);
00565 sizer->SetSizeHints(this);
00566
00567 }
00568
00569 void
00570 ResultFrame::Refresh(refresh_t WXUNUSED(force))
00571 {
00572 if (reslist != NULL)
00573 {
00574 reslist->Show(false);
00575
00576 reslist->Refresh();
00577 reslist->Show(true);
00578 }
00579 }
00580
00581 void
00582 ResultFrame::Search()
00583 {
00584 if (reslist != NULL)
00585 {
00586 reslist->Search();
00587 }
00588 }
00589
00590 int
00591 ResultFrame::GetSelected()
00592 {
00593 if (reslist != NULL)
00594 {
00595 return reslist->GetSelected();
00596 }
00597 return -1;
00598 }
00599
00600 void
00601 ResultFrame::OnSize(wxSizeEvent& e)
00602 {
00603 int w,h;
00604 GetClientSize(&w,&h);
00605
00606 }
00607
00608
00609
00610
00611
00612
00613
00614
00615