QTfrontend/game.cpp
branchwebgl
changeset 8444 75db7bb8dce8
parent 8330 aaefa587e277
parent 8434 4821897a0f10
child 8833 c13ebed437cb
equal deleted inserted replaced
8340:46a9fde631f4 8444:75db7bb8dce8
    20 #include <QByteArray>
    20 #include <QByteArray>
    21 #include <QUuid>
    21 #include <QUuid>
    22 #include <QColor>
    22 #include <QColor>
    23 #include <QStringListModel>
    23 #include <QStringListModel>
    24 #include <QTextStream>
    24 #include <QTextStream>
    25 
    25 #include <utility>
       
    26 
       
    27 #include "hwform.h"
       
    28 #include "ui/page/pageoptions.h"
    26 #include "game.h"
    29 #include "game.h"
    27 #include "hwconsts.h"
    30 #include "hwconsts.h"
    28 #include "gameuiconfig.h"
    31 #include "gameuiconfig.h"
    29 #include "gamecfgwidget.h"
    32 #include "gamecfgwidget.h"
    30 #include "teamselect.h"
    33 #include "teamselect.h"
    31 #include "proto.h"
    34 #include "proto.h"
       
    35 #include "binds.h"
    32 #include "campaign.h"
    36 #include "campaign.h"
    33 
    37 
    34 #include <QTextStream>
    38 #include <QTextStream>
    35 #include "ThemeModel.h"
    39 #include "ThemeModel.h"
    36 
    40 
    71                 emit HaveRecord(rtNeither, demo);
    75                 emit HaveRecord(rtNeither, demo);
    72     }
    76     }
    73     SetGameState(gsStopped);
    77     SetGameState(gsStopped);
    74 }
    78 }
    75 
    79 
       
    80 void HWGame::addKeyBindings(QByteArray * buf)
       
    81 {
       
    82     for(int i = 0; i < BINDS_NUMBER; i++)
       
    83     {
       
    84         QString value = config->value(QString("Binds/%1").arg(cbinds[i].action), cbinds[i].strbind).toString();
       
    85         if (value.isEmpty() || value == "default") continue;
       
    86 
       
    87         QString bind = QString("edbind " + value + " " + cbinds[i].action);
       
    88         HWProto::addStringToBuffer(*buf, bind);
       
    89     }
       
    90 }
       
    91 
    76 void HWGame::commonConfig()
    92 void HWGame::commonConfig()
    77 {
    93 {
    78     QByteArray buf;
    94     QByteArray buf;
    79     QString gt;
    95     QString gt;
    80     switch (gameType)
    96     switch (gameType)
    87             break;
   103             break;
    88         default:
   104         default:
    89             gt = "TL";
   105             gt = "TL";
    90     }
   106     }
    91     HWProto::addStringToBuffer(buf, gt);
   107     HWProto::addStringToBuffer(buf, gt);
       
   108 
       
   109     addKeyBindings(&buf);
    92 
   110 
    93     buf += gamecfg->getFullConfig();
   111     buf += gamecfg->getFullConfig();
    94 
   112 
    95     if (m_pTeamSelWidget)
   113     if (m_pTeamSelWidget)
    96     {
   114     {
   100             HWProto::addStringToBuffer(buf, QString("eammprob %1").arg(ammostr.mid(cAmmoNumber, cAmmoNumber)));
   118             HWProto::addStringToBuffer(buf, QString("eammprob %1").arg(ammostr.mid(cAmmoNumber, cAmmoNumber)));
   101             HWProto::addStringToBuffer(buf, QString("eammdelay %1").arg(ammostr.mid(2 * cAmmoNumber, cAmmoNumber)));
   119             HWProto::addStringToBuffer(buf, QString("eammdelay %1").arg(ammostr.mid(2 * cAmmoNumber, cAmmoNumber)));
   102             HWProto::addStringToBuffer(buf, QString("eammreinf %1").arg(ammostr.mid(3 * cAmmoNumber, cAmmoNumber)));
   120             HWProto::addStringToBuffer(buf, QString("eammreinf %1").arg(ammostr.mid(3 * cAmmoNumber, cAmmoNumber)));
   103             if(gamecfg->schemeData(15).toBool() || !gamecfg->schemeData(21).toBool()) HWProto::addStringToBuffer(buf, QString("eammstore"));
   121             if(gamecfg->schemeData(15).toBool() || !gamecfg->schemeData(21).toBool()) HWProto::addStringToBuffer(buf, QString("eammstore"));
   104             HWProto::addStringListToBuffer(buf,
   122             HWProto::addStringListToBuffer(buf,
   105                                            team.teamGameConfig(gamecfg->getInitHealth()));
   123                                            team.teamGameConfig(gamecfg->getInitHealth(), config));
   106             ;
   124             ;
   107         }
   125         }
   108     }
   126     }
       
   127 
   109     RawSendIPC(buf);
   128     RawSendIPC(buf);
   110 }
   129 }
   111 
   130 
   112 void HWGame::SendConfig()
   131 void HWGame::SendConfig()
   113 {
   132 {
   116 
   135 
   117 void HWGame::SendQuickConfig()
   136 void HWGame::SendQuickConfig()
   118 {
   137 {
   119     QByteArray teamscfg;
   138     QByteArray teamscfg;
   120     ThemeModel * themeModel = DataManager::instance().themeModel();
   139     ThemeModel * themeModel = DataManager::instance().themeModel();
       
   140 
       
   141     addKeyBindings(&teamscfg);
   121 
   142 
   122     HWProto::addStringToBuffer(teamscfg, "TL");
   143     HWProto::addStringToBuffer(teamscfg, "TL");
   123     HWProto::addStringToBuffer(teamscfg, QString("etheme %1")
   144     HWProto::addStringToBuffer(teamscfg, QString("etheme %1")
   124                                .arg((themeModel->rowCount() > 0) ? themeModel->index(rand() % themeModel->rowCount()).data().toString() : "steel"));
   145                                .arg((themeModel->rowCount() > 0) ? themeModel->index(rand() % themeModel->rowCount()).data().toString() : "steel"));
   125     HWProto::addStringToBuffer(teamscfg, "eseed " + QUuid::createUuid().toString());
   146     HWProto::addStringToBuffer(teamscfg, "eseed " + QUuid::createUuid().toString());
   130     team1.setDifficulty(0);
   151     team1.setDifficulty(0);
   131     team1.setColor(0);
   152     team1.setColor(0);
   132     team1.setNumHedgehogs(4);
   153     team1.setNumHedgehogs(4);
   133     HWNamegen::teamRandomNames(team1,true);
   154     HWNamegen::teamRandomNames(team1,true);
   134     HWProto::addStringListToBuffer(teamscfg,
   155     HWProto::addStringListToBuffer(teamscfg,
   135                                    team1.teamGameConfig(100));
   156                                    team1.teamGameConfig(100, config));
   136 
   157 
   137     HWTeam team2;
   158     HWTeam team2;
   138     team2.setDifficulty(4);
   159     team2.setDifficulty(4);
   139     team2.setColor(1);
   160     team2.setColor(1);
   140     team2.setNumHedgehogs(4);
   161     team2.setNumHedgehogs(4);
   141     do
   162     do
   142         HWNamegen::teamRandomNames(team2,true);
   163         HWNamegen::teamRandomNames(team2,true);
   143     while(!team2.name().compare(team1.name()) || !team2.hedgehog(0).Hat.compare(team1.hedgehog(0).Hat));
   164     while(!team2.name().compare(team1.name()) || !team2.hedgehog(0).Hat.compare(team1.hedgehog(0).Hat));
   144     HWProto::addStringListToBuffer(teamscfg,
   165     HWProto::addStringListToBuffer(teamscfg,
   145                                    team2.teamGameConfig(100));
   166                                    team2.teamGameConfig(100, config));
   146 
   167 
   147     HWProto::addStringToBuffer(teamscfg, QString("eammloadt %1").arg(cDefaultAmmoStore->mid(0, cAmmoNumber)));
   168     HWProto::addStringToBuffer(teamscfg, QString("eammloadt %1").arg(cDefaultAmmoStore->mid(0, cAmmoNumber)));
   148     HWProto::addStringToBuffer(teamscfg, QString("eammprob %1").arg(cDefaultAmmoStore->mid(cAmmoNumber, cAmmoNumber)));
   169     HWProto::addStringToBuffer(teamscfg, QString("eammprob %1").arg(cDefaultAmmoStore->mid(cAmmoNumber, cAmmoNumber)));
   149     HWProto::addStringToBuffer(teamscfg, QString("eammdelay %1").arg(cDefaultAmmoStore->mid(2 * cAmmoNumber, cAmmoNumber)));
   170     HWProto::addStringToBuffer(teamscfg, QString("eammdelay %1").arg(cDefaultAmmoStore->mid(2 * cAmmoNumber, cAmmoNumber)));
   150     HWProto::addStringToBuffer(teamscfg, QString("eammreinf %1").arg(cDefaultAmmoStore->mid(3 * cAmmoNumber, cAmmoNumber)));
   171     HWProto::addStringToBuffer(teamscfg, QString("eammreinf %1").arg(cDefaultAmmoStore->mid(3 * cAmmoNumber, cAmmoNumber)));
   151     HWProto::addStringToBuffer(teamscfg, QString("eammstore"));
   172     HWProto::addStringToBuffer(teamscfg, QString("eammstore"));
   152     HWProto::addStringToBuffer(teamscfg, QString("eammstore"));
   173     HWProto::addStringToBuffer(teamscfg, QString("eammstore"));
       
   174 
   153     RawSendIPC(teamscfg);
   175     RawSendIPC(teamscfg);
   154 }
   176 }
   155 
   177 
   156 void HWGame::SendTrainingConfig()
   178 void HWGame::SendTrainingConfig()
   157 {
   179 {
   158     QByteArray traincfg;
   180     QByteArray traincfg;
   159     HWProto::addStringToBuffer(traincfg, "TL");
   181     HWProto::addStringToBuffer(traincfg, "TL");
   160     HWProto::addStringToBuffer(traincfg, "eseed " + QUuid::createUuid().toString());
   182     HWProto::addStringToBuffer(traincfg, "eseed " + QUuid::createUuid().toString());
   161     HWProto::addStringToBuffer(traincfg, "escript " + training);
   183     HWProto::addStringToBuffer(traincfg, "escript " + training);
   162 
   184 
       
   185     addKeyBindings(&traincfg);
       
   186 
   163     RawSendIPC(traincfg);
   187     RawSendIPC(traincfg);
   164 }
   188 }
   165 
   189 
   166 void HWGame::SendCampaignConfig()
   190 void HWGame::SendCampaignConfig()
   167 {
   191 {
   168     QByteArray campaigncfg;
   192     QByteArray campaigncfg;
   169     HWProto::addStringToBuffer(campaigncfg, "TL");
   193     HWProto::addStringToBuffer(campaigncfg, "TL");
   170     HWProto::addStringToBuffer(campaigncfg, "eseed " + QUuid::createUuid().toString());
   194     HWProto::addStringToBuffer(campaigncfg, "eseed " + QUuid::createUuid().toString());
   171 
   195 
   172     HWProto::addStringToBuffer(campaigncfg, "escript " + campaignScript);
   196     HWProto::addStringToBuffer(campaigncfg, "escript " + campaignScript);
       
   197 
       
   198     addKeyBindings(&campaigncfg);
   173 
   199 
   174     RawSendIPC(campaigncfg);
   200     RawSendIPC(campaigncfg);
   175 }
   201 }
   176 
   202 
   177 void HWGame::SendNetConfig()
   203 void HWGame::SendNetConfig()
   272                 sendCampaignVar(msg.right(msg.size() - 3));
   298                 sendCampaignVar(msg.right(msg.size() - 3));
   273             else if (msg.at(2) == '!')
   299             else if (msg.at(2) == '!')
   274                 writeCampaignVar(msg.right(msg.size() - 3));
   300                 writeCampaignVar(msg.right(msg.size() - 3));
   275             break;
   301             break;
   276         }
   302         }
       
   303         case 'W':
       
   304         {
       
   305             // fetch new window resolution via IPC and save it in the settings
       
   306             int size = msg.size();
       
   307             QString newResolution = QString().append(msg.mid(2)).left(size - 4);
       
   308             QStringList wh = newResolution.split('x');
       
   309             config->Form->ui.pageOptions->windowWidthEdit->setText(wh[0]);
       
   310             config->Form->ui.pageOptions->windowHeightEdit->setText(wh[1]);
       
   311             break;
       
   312         }
   277         default:
   313         default:
   278         {
   314         {
   279             if (gameType == gtNet && !netSuspend)
   315             if (gameType == gtNet && !netSuspend)
   280             {
   316             {
   281                 emit SendNet(msg);
   317                 emit SendNet(msg);
   311 }
   347 }
   312 
   348 
   313 QStringList HWGame::getArguments()
   349 QStringList HWGame::getArguments()
   314 {
   350 {
   315     QStringList arguments;
   351     QStringList arguments;
   316     QRect resolution = config->vid_Resolution();
   352     std::pair<QRect, QRect> resolutions = config->vid_ResolutionPair();
   317     QString nick = config->netNick().toUtf8().toBase64();
   353     QString nick = config->netNick().toUtf8().toBase64();
   318 
   354 
   319     arguments << "--internal"; //Must be passed as first argument
   355     arguments << "--internal"; //Must be passed as first argument
   320     arguments << "--port";
   356     arguments << "--port";
   321     arguments << QString("%1").arg(ipc_port);
   357     arguments << QString("%1").arg(ipc_port);
   327     arguments << tr("en.txt");
   363     arguments << tr("en.txt");
   328     arguments << "--frame-interval";
   364     arguments << "--frame-interval";
   329     arguments << QString::number(config->timerInterval());
   365     arguments << QString::number(config->timerInterval());
   330     arguments << "--volume";
   366     arguments << "--volume";
   331     arguments << QString::number(config->volume());
   367     arguments << QString::number(config->volume());
       
   368     arguments << "--fullscreen-width";
       
   369     arguments << QString::number(resolutions.first.width());
       
   370     arguments << "--fullscreen-height";
       
   371     arguments << QString::number(resolutions.first.height());
   332     arguments << "--width";
   372     arguments << "--width";
   333     arguments << QString::number(resolution.width());
   373     arguments << QString::number(resolutions.second.width());
   334     arguments << "--height";
   374     arguments << "--height";
   335     arguments << QString::number(resolution.height());
   375     arguments << QString::number(resolutions.second.height());
   336     arguments << "--raw-quality";
   376     arguments << "--raw-quality";
   337     arguments << QString::number(config->translateQuality());
   377     arguments << QString::number(config->translateQuality());
   338     arguments << "--stereo";
   378     arguments << "--stereo";
   339     arguments << QString::number(config->stereoMode());
   379     arguments << QString::number(config->stereoMode());
   340     if (config->vid_Fullscreen())
   380     if (config->vid_Fullscreen())