QTfrontend/ui/widget/gamecfgwidget.cpp
branchwebgl
changeset 8444 75db7bb8dce8
parent 8434 4821897a0f10
child 8453 06541556df53
equal deleted inserted replaced
8340:46a9fde631f4 8444:75db7bb8dce8
    22 #include <QGridLayout>
    22 #include <QGridLayout>
    23 #include <QSpinBox>
    23 #include <QSpinBox>
    24 #include <QLabel>
    24 #include <QLabel>
    25 #include <QMessageBox>
    25 #include <QMessageBox>
    26 #include <QTableView>
    26 #include <QTableView>
       
    27 #include <QScrollBar>
       
    28 #include <QTabWidget>
    27 #include <QPushButton>
    29 #include <QPushButton>
       
    30 #include <QDebug>
       
    31 #include <QList>
    28 
    32 
    29 #include "gamecfgwidget.h"
    33 #include "gamecfgwidget.h"
    30 #include "igbox.h"
    34 #include "igbox.h"
    31 #include "DataManager.h"
    35 #include "DataManager.h"
    32 #include "hwconsts.h"
    36 #include "hwconsts.h"
    33 #include "ammoSchemeModel.h"
    37 #include "ammoSchemeModel.h"
    34 #include "proto.h"
    38 #include "proto.h"
    35 #include "GameStyleModel.h"
    39 #include "GameStyleModel.h"
       
    40 #include "themeprompt.h"
    36 
    41 
    37 GameCFGWidget::GameCFGWidget(QWidget* parent) :
    42 GameCFGWidget::GameCFGWidget(QWidget* parent) :
    38     QGroupBox(parent)
    43     QGroupBox(parent)
    39     , mainLayout(this)
    44     , mainLayout(this)
    40     , seedRegexp("\\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\}")
    45     , seedRegexp("\\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\}")
    41 {
    46 {
    42     mainLayout.setMargin(0);
    47     mainLayout.setMargin(0);
    43 //  mainLayout.setSizeConstraint(QLayout::SetMinimumSize);
    48     setMinimumHeight(310);
    44 
    49     setMaximumHeight(447);
    45     pMapContainer = new HWMapContainer(this);
    50     setMinimumWidth(470);
    46     mainLayout.addWidget(pMapContainer, 0, 0);
    51     setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    47 
    52 
    48     IconedGroupBox *GBoxOptions = new IconedGroupBox(this);
    53     // Easy containers for the map/game options in either stacked or tabbed mode
    49     GBoxOptions->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    54 
    50     mainLayout.addWidget(GBoxOptions, 1, 0);
    55     mapContainerFree = new QWidget();
    51 
    56     mapContainerTabbed = new QWidget();
    52     QGridLayout *GBoxOptionsLayout = new QGridLayout(GBoxOptions);
    57     optionsContainerFree = new QWidget();
    53 
    58     optionsContainerTabbed = new QWidget();
    54     GBoxOptions->setTitle(tr("Game Options"));
    59     tabbed = false;
    55     GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Style"), GBoxOptions), 1, 0);
    60 
    56 
    61     // Container for when in tabbed mode
    57     Scripts = new QComboBox(GBoxOptions);
    62 
       
    63     tabs = new QTabWidget(this);
       
    64     tabs->setFixedWidth(470);
       
    65     tabs->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
       
    66     tabs->addTab(mapContainerTabbed, tr("Map"));
       
    67     tabs->addTab(optionsContainerTabbed, tr("Game options"));
       
    68     tabs->setObjectName("gameCfgWidgetTabs");
       
    69     mainLayout.addWidget(tabs, 1);
       
    70     tabs->setVisible(false);
       
    71 
       
    72     // Container for when in stacked mode
       
    73 
       
    74     StackContainer = new QWidget();
       
    75     StackContainer->setObjectName("gameStackContainer");
       
    76     mainLayout.addWidget(StackContainer, 1);
       
    77     QVBoxLayout * stackLayout = new QVBoxLayout(StackContainer);
       
    78 
       
    79     // Map options
       
    80 
       
    81     pMapContainer = new HWMapContainer(mapContainerFree);
       
    82     stackLayout->addWidget(mapContainerFree, 0, Qt::AlignHCenter);
       
    83     pMapContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
    84     pMapContainer->setFixedSize(width() - 14, 278);
       
    85     mapContainerFree->setFixedSize(pMapContainer->width(), pMapContainer->height());
       
    86 
       
    87     // Horizontal divider
       
    88 
       
    89     QFrame * divider = new QFrame();
       
    90     divider->setFrameShape(QFrame::HLine);
       
    91     divider->setFrameShadow(QFrame::Plain);
       
    92     stackLayout->addWidget(divider, 0, Qt::AlignBottom);
       
    93     //stackLayout->setRowMinimumHeight(1, 10);
       
    94 
       
    95     // Game options
       
    96 
       
    97     optionsContainerTabbed->setContentsMargins(0, 0, 0, 0);
       
    98     optionsContainerFree->setFixedSize(width() - 14, 140);
       
    99     stackLayout->addWidget(optionsContainerFree, 0, Qt::AlignHCenter);
       
   100 
       
   101     OptionsInnerContainer = new QWidget(optionsContainerFree);
       
   102     m_childWidgets << OptionsInnerContainer;
       
   103     OptionsInnerContainer->setFixedSize(optionsContainerFree->width(), optionsContainerFree->height());
       
   104     OptionsInnerContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
       
   105     GBoxOptionsLayout = new QGridLayout(OptionsInnerContainer);
       
   106 
       
   107     GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Style"), this), 1, 0);
       
   108 
       
   109     Scripts = new QComboBox(this);
    58     GBoxOptionsLayout->addWidget(Scripts, 1, 1);
   110     GBoxOptionsLayout->addWidget(Scripts, 1, 1);
    59 
   111 
    60     Scripts->setModel(DataManager::instance().gameStyleModel());
   112     Scripts->setModel(DataManager::instance().gameStyleModel());
    61     m_curScript = Scripts->currentText();
   113     m_curScript = Scripts->currentText();
    62     connect(Scripts, SIGNAL(currentIndexChanged(int)), this, SLOT(scriptChanged(int)));
   114     connect(Scripts, SIGNAL(currentIndexChanged(int)), this, SLOT(scriptChanged(int)));
    63 
   115 
    64     QWidget *SchemeWidget = new QWidget(GBoxOptions);
   116     QWidget *SchemeWidget = new QWidget(this);
    65     GBoxOptionsLayout->addWidget(SchemeWidget, 2, 0, 1, 2);
   117     GBoxOptionsLayout->addWidget(SchemeWidget, 2, 0, 1, 2);
    66 
   118 
    67     QGridLayout *SchemeWidgetLayout = new QGridLayout(SchemeWidget);
   119     QGridLayout *SchemeWidgetLayout = new QGridLayout(SchemeWidget);
    68     SchemeWidgetLayout->setMargin(0);
   120     SchemeWidgetLayout->setMargin(0);
    69 
   121 
    74     SchemeWidgetLayout->addWidget(new QLabel(QLabel::tr("Scheme"), SchemeWidget), 0, 0);
   126     SchemeWidgetLayout->addWidget(new QLabel(QLabel::tr("Scheme"), SchemeWidget), 0, 0);
    75 
   127 
    76     QPixmap pmEdit(":/res/edit.png");
   128     QPixmap pmEdit(":/res/edit.png");
    77 
   129 
    78     QPushButton * goToSchemePage = new QPushButton(SchemeWidget);
   130     QPushButton * goToSchemePage = new QPushButton(SchemeWidget);
    79     goToSchemePage->setToolTip(tr("Edit schemes"));
   131     goToSchemePage->setWhatsThis(tr("Edit schemes"));
    80     goToSchemePage->setIconSize(pmEdit.size());
   132     goToSchemePage->setIconSize(pmEdit.size());
    81     goToSchemePage->setIcon(pmEdit);
   133     goToSchemePage->setIcon(pmEdit);
    82     goToSchemePage->setMaximumWidth(pmEdit.width() + 6);
   134     goToSchemePage->setMaximumWidth(pmEdit.width() + 6);
    83     SchemeWidgetLayout->addWidget(goToSchemePage, 0, 3);
   135     SchemeWidgetLayout->addWidget(goToSchemePage, 0, 3);
    84     connect(goToSchemePage, SIGNAL(clicked()), this, SLOT(jumpToSchemes()));
   136     connect(goToSchemePage, SIGNAL(clicked()), this, SLOT(jumpToSchemes()));
    89     SchemeWidgetLayout->addWidget(WeaponsName, 1, 2);
   141     SchemeWidgetLayout->addWidget(WeaponsName, 1, 2);
    90 
   142 
    91     connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int)));
   143     connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int)));
    92 
   144 
    93     QPushButton * goToWeaponPage = new QPushButton(SchemeWidget);
   145     QPushButton * goToWeaponPage = new QPushButton(SchemeWidget);
    94     goToWeaponPage->setToolTip(tr("Edit weapons"));
   146     goToWeaponPage->setWhatsThis(tr("Edit weapons"));
    95     goToWeaponPage->setIconSize(pmEdit.size());
   147     goToWeaponPage->setIconSize(pmEdit.size());
    96     goToWeaponPage->setIcon(pmEdit);
   148     goToWeaponPage->setIcon(pmEdit);
    97     goToWeaponPage->setMaximumWidth(pmEdit.width() + 6);
   149     goToWeaponPage->setMaximumWidth(pmEdit.width() + 6);
    98     SchemeWidgetLayout->addWidget(goToWeaponPage, 1, 3);
   150     SchemeWidgetLayout->addWidget(goToWeaponPage, 1, 3);
    99     connect(goToWeaponPage, SIGNAL(clicked()), this, SLOT(jumpToWeapons()));
   151     connect(goToWeaponPage, SIGNAL(clicked()), this, SLOT(jumpToWeapons()));
   100 
   152 
   101     bindEntries = new QCheckBox(SchemeWidget);
   153     bindEntries = new QCheckBox(SchemeWidget);
   102     bindEntries->setToolTip(tr("When this option is enabled selecting a game scheme will auto-select a weapon"));
   154     bindEntries->setWhatsThis(tr("Game scheme will auto-select a weapon"));
   103     bindEntries->setChecked(true);
   155     bindEntries->setChecked(true);
   104     bindEntries->setMaximumWidth(42);
   156     bindEntries->setMaximumWidth(42);
   105     bindEntries->setStyleSheet( "QCheckBox::indicator:checked   { image: url(\":/res/lock.png\"); }"
   157     bindEntries->setStyleSheet( "QCheckBox::indicator:checked   { image: url(\":/res/lock.png\"); }"
   106                                 "QCheckBox::indicator:unchecked { image: url(\":/res/unlock.png\");   }" );
   158                                 "QCheckBox::indicator:unchecked { image: url(\":/res/unlock.png\");   }" );
   107     SchemeWidgetLayout->addWidget(bindEntries, 0, 1, 0, 1, Qt::AlignVCenter);
   159     SchemeWidgetLayout->addWidget(bindEntries, 0, 1, 0, 1, Qt::AlignVCenter);
   114     connect(pMapContainer, SIGNAL(newTemplateFilter(int)), this, SLOT(templateFilterChanged(int)));
   166     connect(pMapContainer, SIGNAL(newTemplateFilter(int)), this, SLOT(templateFilterChanged(int)));
   115     connect(pMapContainer, SIGNAL(drawMapRequested()), this, SIGNAL(goToDrawMap()));
   167     connect(pMapContainer, SIGNAL(drawMapRequested()), this, SIGNAL(goToDrawMap()));
   116     connect(pMapContainer, SIGNAL(drawnMapChanged(const QByteArray &)), this, SLOT(onDrawnMapChanged(const QByteArray &)));
   168     connect(pMapContainer, SIGNAL(drawnMapChanged(const QByteArray &)), this, SLOT(onDrawnMapChanged(const QByteArray &)));
   117 
   169 
   118     connect(&DataManager::instance(), SIGNAL(updated()), this, SLOT(updateModelViews()));
   170     connect(&DataManager::instance(), SIGNAL(updated()), this, SLOT(updateModelViews()));
       
   171 }
       
   172 
       
   173 void GameCFGWidget::setTabbed(bool tabbed)
       
   174 {
       
   175     if (tabbed && !this->tabbed)
       
   176     { // Make tabbed
       
   177         tabs->setCurrentIndex(0);
       
   178         StackContainer->setVisible(false);
       
   179         tabs->setVisible(true);
       
   180         pMapContainer->setParent(mapContainerTabbed);
       
   181         OptionsInnerContainer->setParent(optionsContainerTabbed);
       
   182         pMapContainer->setVisible(true);
       
   183         setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
       
   184         this->tabbed = true;
       
   185     }
       
   186     else if (!tabbed && this->tabbed)
       
   187     { // Make stacked
       
   188         pMapContainer->setParent(mapContainerFree);
       
   189         OptionsInnerContainer->setParent(optionsContainerFree);
       
   190         tabs->setVisible(false);
       
   191         StackContainer->setVisible(true);
       
   192         pMapContainer->setVisible(true);
       
   193         setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
   194         this->tabbed = false;
       
   195     }
       
   196 
       
   197     // Restore scrollbar palettes, since Qt seems to forget them easily when switching parents
       
   198     QList<QScrollBar *> allSBars = findChildren<QScrollBar *>();
       
   199     QPalette pal = palette();
       
   200     pal.setColor(QPalette::WindowText, QColor(0xff, 0xcc, 0x00));
       
   201     pal.setColor(QPalette::Button, QColor(0x00, 0x35, 0x1d));
       
   202     pal.setColor(QPalette::Base, QColor(0x00, 0x35, 0x1d));
       
   203     pal.setColor(QPalette::Window, QColor(0x00, 0x00, 0x00));
       
   204 
       
   205     for (int i = 0; i < allSBars.size(); ++i)
       
   206         allSBars.at(i)->setPalette(pal);
   119 }
   207 }
   120 
   208 
   121 void GameCFGWidget::jumpToSchemes()
   209 void GameCFGWidget::jumpToSchemes()
   122 {
   210 {
   123     emit goToSchemes(GameSchemes->currentIndex());
   211     emit goToSchemes(GameSchemes->currentIndex());
   184     if (schemeData(23).toBool())
   272     if (schemeData(23).toBool())
   185         result |= 0x01000000;       // more wind
   273         result |= 0x01000000;       // more wind
   186     if (schemeData(24).toBool())
   274     if (schemeData(24).toBool())
   187         result |= 0x02000000;       // tag team
   275         result |= 0x02000000;       // tag team
   188     if (schemeData(25).toBool())
   276     if (schemeData(25).toBool())
   189         result |= 0x04000000;       // bottom border
   277         result |= 0x04000000;       // bottom
   190 
   278 
   191     return result;
   279     return result;
   192 }
   280 }
   193 
   281 
   194 quint32 GameCFGWidget::getInitHealth() const
   282 quint32 GameCFGWidget::getInitHealth() const
   233     bcfg << QString("e$ropepct %1").arg(schemeData(39).toInt()).toUtf8();
   321     bcfg << QString("e$ropepct %1").arg(schemeData(39).toInt()).toUtf8();
   234     bcfg << QString("e$getawaytime %1").arg(schemeData(40).toInt()).toUtf8();
   322     bcfg << QString("e$getawaytime %1").arg(schemeData(40).toInt()).toUtf8();
   235     bcfg << QString("e$template_filter %1").arg(pMapContainer->getTemplateFilter()).toUtf8();
   323     bcfg << QString("e$template_filter %1").arg(pMapContainer->getTemplateFilter()).toUtf8();
   236     bcfg << QString("e$mapgen %1").arg(mapgen).toUtf8();
   324     bcfg << QString("e$mapgen %1").arg(mapgen).toUtf8();
   237 
   325 
       
   326 
       
   327 
   238     switch (mapgen)
   328     switch (mapgen)
   239     {
   329     {
   240         case MAPGEN_MAZE:
   330         case MAPGEN_MAZE:
   241             bcfg << QString("e$maze_size %1").arg(pMapContainer->getMazeSize()).toUtf8();
   331             bcfg << QString("e$maze_size %1").arg(pMapContainer->getMazeSize()).toUtf8();
   242             break;
   332             break;
   269 void GameCFGWidget::setNetAmmo(const QString& name, const QString& ammo)
   359 void GameCFGWidget::setNetAmmo(const QString& name, const QString& ammo)
   270 {
   360 {
   271     bool illegal = ammo.size() != cDefaultAmmoStore->size();
   361     bool illegal = ammo.size() != cDefaultAmmoStore->size();
   272     if (illegal)
   362     if (illegal)
   273     {
   363     {
   274         QMessageBox illegalMsg(this);
   364         QMessageBox illegalMsg(parentWidget());
   275         illegalMsg.setIcon(QMessageBox::Warning);
   365         illegalMsg.setIcon(QMessageBox::Warning);
   276         illegalMsg.setWindowTitle(QMessageBox::tr("Error"));
   366         illegalMsg.setWindowTitle(QMessageBox::tr("Error"));
   277         illegalMsg.setText(QMessageBox::tr("Cannot use the ammo '%1'!").arg(name));
   367         illegalMsg.setText(QMessageBox::tr("Cannot use the ammo '%1'!").arg(name));
   278         illegalMsg.setWindowModality(Qt::WindowModal);
   368         illegalMsg.setWindowModality(Qt::WindowModal);
   279         illegalMsg.exec();
   369         illegalMsg.exec();
   323             return;
   413             return;
   324         }
   414         }
   325         if (param == "SEED")
   415         if (param == "SEED")
   326         {
   416         {
   327             pMapContainer->setSeed(value);
   417             pMapContainer->setSeed(value);
   328             if (!seedRegexp.exactMatch(value))
       
   329             {
       
   330                 pMapContainer->seedEdit->setVisible(true);
       
   331             }
       
   332             return;
   418             return;
   333         }
   419         }
   334         if (param == "THEME")
   420         if (param == "THEME")
   335         {
   421         {
   336             pMapContainer->setTheme(value);
   422             pMapContainer->setTheme(value);
   375     if (slValue.size() == 5)
   461     if (slValue.size() == 5)
   376     {
   462     {
   377         if (param == "FULLMAPCONFIG")
   463         if (param == "FULLMAPCONFIG")
   378         {
   464         {
   379             QString seed = slValue[3];
   465             QString seed = slValue[3];
   380             if (!seedRegexp.exactMatch(seed))
       
   381                 pMapContainer->seedEdit->setVisible(true);
       
   382 
   466 
   383             pMapContainer->setAllMapParameters(
   467             pMapContainer->setAllMapParameters(
   384                 slValue[0],
   468                 slValue[0],
   385                 (MapGenerator)slValue[1].toUInt(),
   469                 (MapGenerator)slValue[1].toUInt(),
   386                 slValue[2].toUInt(),
   470                 slValue[2].toUInt(),
   584             Scripts->setCurrentIndex(idx);
   668             Scripts->setCurrentIndex(idx);
   585         else
   669         else
   586             Scripts->setCurrentIndex(0);
   670             Scripts->setCurrentIndex(0);
   587     }
   671     }
   588 }
   672 }
       
   673 
       
   674 bool GameCFGWidget::isMaster()
       
   675 {
       
   676     return m_master;
       
   677 }
       
   678 
       
   679 void GameCFGWidget::setMaster(bool master)
       
   680 {
       
   681     if (master == m_master) return;
       
   682     m_master = master;
       
   683 
       
   684     pMapContainer->setMaster(master);
       
   685 
       
   686     foreach (QWidget *widget, m_childWidgets)
       
   687         widget->setEnabled(master);
       
   688 }