Variants are not singletons anymore.
[tagua/yd.git] / src / newgame.cpp
blobae867c87677948ba8104bfc82cb862d6ec3e4b22
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #include <iostream>
12 #include <QComboBox>
13 #include <QHBoxLayout>
14 #include "common.h"
15 #include "variants.h"
16 #include "tagua.h"
17 #include "newgame.h"
18 #include "foreach.h"
20 NewGame::NewGame(QWidget* parent, bool allowCurrent)
21 : QDialog(parent)
22 , m_custom_opt_widget(NULL)
23 , m_custom_opt_layout(NULL) {
24 setupUi(this);
26 std::cout << "allow current = " << allowCurrent << std::endl;
27 m_allow_current = allowCurrent;
28 connect(cmbVariant, SIGNAL(currentIndexChanged(const QString&)),
29 this, SLOT(variantChanged(const QString&)));
31 m_custom_opt_layout = new QHBoxLayout(widgetCustom);
33 QStringList variants = Variants::instance().all();
34 foreach (QString variant, variants) {
35 cmbVariant->addItem(variant, QVariant(variant));
39 QString NewGame::variant() const {
40 QString res = cmbVariant->itemData(cmbVariant->currentIndex()).toString();
41 return res;
44 bool NewGame::playFromCurrent() const {
45 return rdCurrent->isChecked();
48 bool NewGame::isCustom() const {
49 return rdCustom->isChecked();
52 void NewGame::variantChanged(const QString& var) {
53 std::cout << "var = " << var << std::endl;
54 bool enabled = m_allow_current && var == "Chess";
55 rdCurrent->setEnabled(enabled);
56 if (!enabled)
57 rdStandard->setChecked(true);
59 if(m_custom_opt_widget)
60 delete m_custom_opt_widget;
61 m_custom_options = OptList();
62 VariantPtr vi = Variants::instance().get(var);
63 if(vi) {
64 m_custom_options = vi->positionOptions();
65 m_custom_opt_widget = new OptionWidget(m_custom_options, widgetCustom);
66 m_custom_opt_layout->addWidget(m_custom_opt_widget);