mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-01-30 20:34:27 +01:00
- Fixed a bug due to the reject sign '-' preventing to load a saved training game
- Qt interface: Loading and saving a game is now supported (it only works in training mode, due to limitations in the core)
This commit is contained in:
parent
f0b41f7ee7
commit
d8780822c2
5 changed files with 177 additions and 89 deletions
|
@ -477,7 +477,7 @@ int Game::helperSetRackManual(unsigned int p, bool iCheck, const wstring &iLette
|
||||||
{
|
{
|
||||||
ASSERT(p < getNPlayers(), "Wrong player number");
|
ASSERT(p < getNPlayers(), "Wrong player number");
|
||||||
|
|
||||||
if (!m_dic.validateLetters(iLetters, L"+"))
|
if (!m_dic.validateLetters(iLetters, L"+-"))
|
||||||
return 3;
|
return 3;
|
||||||
|
|
||||||
PlayedRack pld;
|
PlayedRack pld;
|
||||||
|
|
|
@ -140,8 +140,18 @@ void PlayedRack::setManual(const wstring& iLetters)
|
||||||
if (iLetters.empty())
|
if (iLetters.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Handle the reject sign
|
||||||
|
unsigned int begin;
|
||||||
|
if (iLetters[0] == L'-')
|
||||||
|
{
|
||||||
|
setReject();
|
||||||
|
begin = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
begin = 0;
|
||||||
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
for (i = 0; i < iLetters.size() && iLetters[i] != L'+'; i++)
|
for (i = begin; i < iLetters.size() && iLetters[i] != L'+'; i++)
|
||||||
{
|
{
|
||||||
addOld(Tile(iLetters[i]));
|
addOld(Tile(iLetters[i]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
#include <QtGui/QMessageBox>
|
#include <QtGui/QMessageBox>
|
||||||
#include <QtGui/QFileDialog>
|
#include <QtGui/QFileDialog>
|
||||||
#include <QtGui/QDockWidget>
|
#include <QtGui/QDockWidget>
|
||||||
|
@ -28,6 +30,7 @@
|
||||||
#include "dic.h"
|
#include "dic.h"
|
||||||
#include "encoding.h"
|
#include "encoding.h"
|
||||||
#include "header.h"
|
#include "header.h"
|
||||||
|
#include "game_factory.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "freegame.h"
|
#include "freegame.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
@ -119,67 +122,6 @@ MainWindow::~MainWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_action_About_triggered()
|
|
||||||
{
|
|
||||||
QString msg;
|
|
||||||
msg.sprintf("Eliot %s\n\n", VERSION);
|
|
||||||
msg += _q( \
|
|
||||||
"Copyright (C) 1999-2008 - Antoine Fraboulet & Olivier Teuliere\n\n" \
|
|
||||||
"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.");
|
|
||||||
// QMessageBox::about() doesn't add the nice information icon, so we create
|
|
||||||
// the box manually (not much work...)
|
|
||||||
QMessageBox *aboutBox = new QMessageBox(QMessageBox::Information,
|
|
||||||
_q("About Eliot"), msg, QMessageBox::Ok, this);
|
|
||||||
aboutBox->exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_action_Bag_triggered()
|
|
||||||
{
|
|
||||||
if (m_bagWindow == NULL)
|
|
||||||
{
|
|
||||||
// Create the bag window
|
|
||||||
BagWidget *bagWidget = new BagWidget(NULL);
|
|
||||||
bagWidget->setGame(m_game);
|
|
||||||
m_bagWindow = new AuxWindow(*bagWidget, m_ui.action_Bag);
|
|
||||||
QObject::connect(this, SIGNAL(gameChanged(const Game*)),
|
|
||||||
bagWidget, SLOT(setGame(const Game*)));
|
|
||||||
QObject::connect(this, SIGNAL(gameUpdated()),
|
|
||||||
bagWidget, SLOT(refresh()));
|
|
||||||
// XXX
|
|
||||||
m_bagWindow->move(20, 20);
|
|
||||||
}
|
|
||||||
if (m_bagWindow->isVisible())
|
|
||||||
m_bagWindow->hide();
|
|
||||||
else
|
|
||||||
m_bagWindow->show();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_action_ChooseDic_triggered()
|
|
||||||
{
|
|
||||||
QString fileName =
|
|
||||||
QFileDialog::getOpenFileName(this, _q("Choose a dictionary"), "", "*.dawg");
|
|
||||||
if (!fileName.isEmpty())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Dictionary *dic = new Dictionary(qtl(fileName));
|
|
||||||
delete m_dic;
|
|
||||||
m_dic = dic;
|
|
||||||
emit dicChanged(fileName, qfw(m_dic->getHeader().getName()));
|
|
||||||
}
|
|
||||||
catch (std::exception &e)
|
|
||||||
{
|
|
||||||
displayErrorMsg(e.what());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::destroyCurrentGame()
|
void MainWindow::destroyCurrentGame()
|
||||||
{
|
{
|
||||||
if (m_game == NULL)
|
if (m_game == NULL)
|
||||||
|
@ -197,7 +139,16 @@ void MainWindow::destroyCurrentGame()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_action_New_Game_triggered()
|
void MainWindow::displayErrorMsg(QString iMsg, QString iContext)
|
||||||
|
{
|
||||||
|
if (iContext == "")
|
||||||
|
iContext = PACKAGE_NAME;
|
||||||
|
|
||||||
|
QMessageBox::warning(this, iContext, iMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::on_action_GameNew_triggered()
|
||||||
{
|
{
|
||||||
if (m_dic == NULL)
|
if (m_dic == NULL)
|
||||||
{
|
{
|
||||||
|
@ -229,7 +180,47 @@ void MainWindow::on_action_New_Game_triggered()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_action_Preferences_triggered()
|
void MainWindow::on_action_GameLoad_triggered()
|
||||||
|
{
|
||||||
|
if (m_dic == NULL)
|
||||||
|
{
|
||||||
|
displayErrorMsg(_q("You have to select a dictionary first!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString fileName = QFileDialog::getOpenFileName(this, _q("Load a game"));
|
||||||
|
if (fileName != "")
|
||||||
|
{
|
||||||
|
destroyCurrentGame();
|
||||||
|
m_game = GameFactory::Instance()->load(qtl(fileName), *m_dic);
|
||||||
|
if (m_game == NULL)
|
||||||
|
{
|
||||||
|
displayErrorMsg(_q("Error while loading the game"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_ui.groupBoxPlayers->show();
|
||||||
|
emit gameChangedNonConst(m_game);
|
||||||
|
emit gameChanged(m_game);
|
||||||
|
emit gameUpdated();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::on_action_GameSaveAs_triggered()
|
||||||
|
{
|
||||||
|
if (m_game == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString fileName = QFileDialog::getSaveFileName(this, _q("Save a game"));
|
||||||
|
if (fileName != "")
|
||||||
|
{
|
||||||
|
ofstream fout(qtl(fileName));
|
||||||
|
m_game->save(fout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::on_action_SettingsPreferences_triggered()
|
||||||
{
|
{
|
||||||
if (m_prefsDialog == NULL)
|
if (m_prefsDialog == NULL)
|
||||||
m_prefsDialog = new PrefsDialog(this);
|
m_prefsDialog = new PrefsDialog(this);
|
||||||
|
@ -237,11 +228,63 @@ void MainWindow::on_action_Preferences_triggered()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::displayErrorMsg(QString iMsg, QString iContext)
|
void MainWindow::on_action_SettingsChooseDic_triggered()
|
||||||
{
|
{
|
||||||
if (iContext == "")
|
QString fileName =
|
||||||
iContext = PACKAGE_NAME;
|
QFileDialog::getOpenFileName(this, _q("Choose a dictionary"), "", "*.dawg");
|
||||||
|
if (!fileName.isEmpty())
|
||||||
QMessageBox::warning(this, iContext, iMsg);
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary *dic = new Dictionary(qtl(fileName));
|
||||||
|
delete m_dic;
|
||||||
|
m_dic = dic;
|
||||||
|
emit dicChanged(fileName, qfw(m_dic->getHeader().getName()));
|
||||||
|
}
|
||||||
|
catch (std::exception &e)
|
||||||
|
{
|
||||||
|
displayErrorMsg(e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::on_action_WindowsBag_triggered()
|
||||||
|
{
|
||||||
|
if (m_bagWindow == NULL)
|
||||||
|
{
|
||||||
|
// Create the bag window
|
||||||
|
BagWidget *bagWidget = new BagWidget(NULL);
|
||||||
|
bagWidget->setGame(m_game);
|
||||||
|
m_bagWindow = new AuxWindow(*bagWidget, m_ui.action_WindowsBag);
|
||||||
|
QObject::connect(this, SIGNAL(gameChanged(const Game*)),
|
||||||
|
bagWidget, SLOT(setGame(const Game*)));
|
||||||
|
QObject::connect(this, SIGNAL(gameUpdated()),
|
||||||
|
bagWidget, SLOT(refresh()));
|
||||||
|
// XXX
|
||||||
|
m_bagWindow->move(20, 20);
|
||||||
|
}
|
||||||
|
if (m_bagWindow->isVisible())
|
||||||
|
m_bagWindow->hide();
|
||||||
|
else
|
||||||
|
m_bagWindow->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::on_action_HelpAbout_triggered()
|
||||||
|
{
|
||||||
|
QString msg;
|
||||||
|
msg.sprintf("Eliot %s\n\n", VERSION);
|
||||||
|
msg += _q( \
|
||||||
|
"Copyright (C) 1999-2008 - Antoine Fraboulet & Olivier Teuliere\n\n" \
|
||||||
|
"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.");
|
||||||
|
// QMessageBox::about() doesn't add the nice information icon, so we create
|
||||||
|
// the box manually (not much work...)
|
||||||
|
QMessageBox *aboutBox = new QMessageBox(QMessageBox::Information,
|
||||||
|
_q("About Eliot"), msg, QMessageBox::Ok, this);
|
||||||
|
aboutBox->exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,11 +54,13 @@ public slots:
|
||||||
void displayErrorMsg(QString iMsg, QString iContext = "");
|
void displayErrorMsg(QString iMsg, QString iContext = "");
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_action_About_triggered();
|
void on_action_GameNew_triggered();
|
||||||
void on_action_Bag_triggered();
|
void on_action_GameLoad_triggered();
|
||||||
void on_action_ChooseDic_triggered();
|
void on_action_GameSaveAs_triggered();
|
||||||
void on_action_New_Game_triggered();
|
void on_action_SettingsChooseDic_triggered();
|
||||||
void on_action_Preferences_triggered();
|
void on_action_SettingsPreferences_triggered();
|
||||||
|
void on_action_WindowsBag_triggered();
|
||||||
|
void on_action_HelpAbout_triggered();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Current dictionary
|
/// Current dictionary
|
||||||
|
|
|
@ -70,29 +70,32 @@
|
||||||
<property name="title" >
|
<property name="title" >
|
||||||
<string>_("&Game")</string>
|
<string>_("&Game")</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="action_New_Game" />
|
<addaction name="action_GameNew" />
|
||||||
|
<addaction name="action_GameLoad" />
|
||||||
<addaction name="separator" />
|
<addaction name="separator" />
|
||||||
<addaction name="action_Quit" />
|
<addaction name="action_GameSaveAs" />
|
||||||
|
<addaction name="separator" />
|
||||||
|
<addaction name="action_GameQuit" />
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuHelp" >
|
<widget class="QMenu" name="menuHelp" >
|
||||||
<property name="title" >
|
<property name="title" >
|
||||||
<string>&Settings</string>
|
<string>&Settings</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="action_ChooseDic" />
|
<addaction name="action_SettingsChooseDic" />
|
||||||
<addaction name="action_Preferences" />
|
<addaction name="action_SettingsPreferences" />
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menu_Help" >
|
<widget class="QMenu" name="menu_Help" >
|
||||||
<property name="title" >
|
<property name="title" >
|
||||||
<string>_("&Help")</string>
|
<string>_("&Help")</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="action_About" />
|
<addaction name="action_HelpAbout" />
|
||||||
<addaction name="separator" />
|
<addaction name="separator" />
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menu_Windows" >
|
<widget class="QMenu" name="menu_Windows" >
|
||||||
<property name="title" >
|
<property name="title" >
|
||||||
<string>_("&Windows")</string>
|
<string>_("&Windows")</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="action_Bag" />
|
<addaction name="action_WindowsBag" />
|
||||||
</widget>
|
</widget>
|
||||||
<addaction name="menuFile" />
|
<addaction name="menuFile" />
|
||||||
<addaction name="menuHelp" />
|
<addaction name="menuHelp" />
|
||||||
|
@ -111,12 +114,12 @@
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</attribute>
|
</attribute>
|
||||||
</widget>
|
</widget>
|
||||||
<action name="action_ChooseDic" >
|
<action name="action_SettingsChooseDic" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string>_("Choose dictionary...")</string>
|
<string>_("Choose dictionary...")</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="action_About" >
|
<action name="action_HelpAbout" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string>_("&About...")</string>
|
<string>_("&About...")</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -124,37 +127,67 @@
|
||||||
<string>About Eliot</string>
|
<string>About Eliot</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="action_Quit" >
|
<action name="action_GameQuit" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string>_("&Quit")</string>
|
<string>_("&Quit")</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="action_New_Game" >
|
<action name="action_GameNew" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string>_("&New game...")</string>
|
<string>_("New...")</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut" >
|
<property name="shortcut" >
|
||||||
<string>Ctrl+N</string>
|
<string>Ctrl+N</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="action_Bag" >
|
<action name="action_WindowsBag" >
|
||||||
<property name="checkable" >
|
<property name="checkable" >
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string>_("&Bag")</string>
|
<string>_("&Bag")</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="shortcut" >
|
||||||
|
<string>Ctrl+B</string>
|
||||||
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="action_Preferences" >
|
<action name="action_SettingsPreferences" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string>_("Preferences...")</string>
|
<string>_("Preferences...")</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="shortcut" >
|
||||||
|
<string>Ctrl+P</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="action_GameSave" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>_("Save")</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut" >
|
||||||
|
<string>Ctrl+S</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="action_GameLoad" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>_("Load...")</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut" >
|
||||||
|
<string>Ctrl+O</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="action_GameSaveAs" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>_("Save as...")</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut" >
|
||||||
|
<string>Ctrl+S</string>
|
||||||
|
</property>
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections>
|
||||||
<connection>
|
<connection>
|
||||||
<sender>action_Quit</sender>
|
<sender>action_GameQuit</sender>
|
||||||
<signal>triggered()</signal>
|
<signal>triggered()</signal>
|
||||||
<receiver>MainWindow</receiver>
|
<receiver>MainWindow</receiver>
|
||||||
<slot>close()</slot>
|
<slot>close()</slot>
|
||||||
|
|
Loading…
Add table
Reference in a new issue