QTfrontend/game.cpp
branchflibqtfrontend
changeset 8363 0b4ac686fc44
parent 8306 50fe80adbfcb
parent 8354 c25bee85d6f8
equal deleted inserted replaced
8306:50fe80adbfcb 8363:0b4ac686fc44
    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 #include "ThemeModel.h"
    37 #include "ThemeModel.h"
    34 #include "frontlibpoller.h"
    38 #include "frontlibpoller.h"
    35 
    39 
    36 QString training, campaign, campaignScript, campaignTeam; // TODO: Cleaner solution?
    40 QString training, campaign, campaignScript, campaignTeam; // TODO: Cleaner solution?
    53 
    57 
    54     if(m_conn)
    58     if(m_conn)
    55         flib_gameconn_destroy(m_conn);
    59         flib_gameconn_destroy(m_conn);
    56 }
    60 }
    57 
    61 
       
    62 void HWGame::addKeyBindings(QByteArray * buf)
       
    63 {
       
    64     for(int i = 0; i < BINDS_NUMBER; i++)
       
    65     {
       
    66         QString value = config->value(QString("Binds/%1").arg(cbinds[i].action), cbinds[i].strbind).toString();
       
    67         if (value.isEmpty() || value == "default") continue;
       
    68         
       
    69         QString bind = QString("edbind " + value + " " + cbinds[i].action);
       
    70         HWProto::addStringToBuffer(*buf, bind);
       
    71     }
       
    72 }
       
    73 
    58 void HWGame::commonConfig()
    74 void HWGame::commonConfig()
    59 {
    75 {
    60     QByteArray buf;
    76     QByteArray buf;
    61     QString gt;
    77     QString gt;
    62     switch (gameType)
    78     switch (gameType)
    69             break;
    85             break;
    70         default:
    86         default:
    71             gt = "TL";
    87             gt = "TL";
    72     }
    88     }
    73     HWProto::addStringToBuffer(buf, gt);
    89     HWProto::addStringToBuffer(buf, gt);
       
    90 
       
    91     addKeyBindings(&buf);
    74 
    92 
    75     buf += gamecfg->getFullConfig();
    93     buf += gamecfg->getFullConfig();
    76 
    94 
    77     if (m_pTeamSelWidget)
    95     if (m_pTeamSelWidget)
    78     {
    96     {
    82             HWProto::addStringToBuffer(buf, QString("eammprob %1").arg(ammostr.mid(cAmmoNumber, cAmmoNumber)));
   100             HWProto::addStringToBuffer(buf, QString("eammprob %1").arg(ammostr.mid(cAmmoNumber, cAmmoNumber)));
    83             HWProto::addStringToBuffer(buf, QString("eammdelay %1").arg(ammostr.mid(2 * cAmmoNumber, cAmmoNumber)));
   101             HWProto::addStringToBuffer(buf, QString("eammdelay %1").arg(ammostr.mid(2 * cAmmoNumber, cAmmoNumber)));
    84             HWProto::addStringToBuffer(buf, QString("eammreinf %1").arg(ammostr.mid(3 * cAmmoNumber, cAmmoNumber)));
   102             HWProto::addStringToBuffer(buf, QString("eammreinf %1").arg(ammostr.mid(3 * cAmmoNumber, cAmmoNumber)));
    85             if(gamecfg->schemeData(15).toBool() || !gamecfg->schemeData(21).toBool()) HWProto::addStringToBuffer(buf, QString("eammstore"));
   103             if(gamecfg->schemeData(15).toBool() || !gamecfg->schemeData(21).toBool()) HWProto::addStringToBuffer(buf, QString("eammstore"));
    86 //            HWProto::addStringListToBuffer(buf,
   104 //            HWProto::addStringListToBuffer(buf,
    87 //                                           team.teamGameConfig(gamecfg->getInitHealth()));
   105 //                                           team.teamGameConfig(gamecfg->getInitHealth(), config));
    88             ;
   106            ;
    89         }
   107         }
    90     }
   108     }
       
   109 
    91     //RawSendIPC(buf);
   110     //RawSendIPC(buf);
    92 }
   111 }
    93 
   112 
    94 void HWGame::SendConfig()
   113 void HWGame::SendConfig()
    95 {
   114 {
   101     QByteArray traincfg;
   120     QByteArray traincfg;
   102     HWProto::addStringToBuffer(traincfg, "TL");
   121     HWProto::addStringToBuffer(traincfg, "TL");
   103     HWProto::addStringToBuffer(traincfg, "eseed " + QUuid::createUuid().toString());
   122     HWProto::addStringToBuffer(traincfg, "eseed " + QUuid::createUuid().toString());
   104     HWProto::addStringToBuffer(traincfg, "escript " + training);
   123     HWProto::addStringToBuffer(traincfg, "escript " + training);
   105 
   124 
   106    //RawSendIPC(traincfg);
   125     addKeyBindings(&traincfg);
       
   126 
       
   127     //RawSendIPC(traincfg);
   107 }
   128 }
   108 
   129 
   109 void HWGame::SendCampaignConfig()
   130 void HWGame::SendCampaignConfig()
   110 {
   131 {
   111     QByteArray campaigncfg;
   132     QByteArray campaigncfg;
   112     HWProto::addStringToBuffer(campaigncfg, "TL");
   133     HWProto::addStringToBuffer(campaigncfg, "TL");
   113     HWProto::addStringToBuffer(campaigncfg, "eseed " + QUuid::createUuid().toString());
   134     HWProto::addStringToBuffer(campaigncfg, "eseed " + QUuid::createUuid().toString());
   114 
   135 
   115     HWProto::addStringToBuffer(campaigncfg, "escript " + campaignScript);
   136     HWProto::addStringToBuffer(campaigncfg, "escript " + campaignScript);
   116 
   137 
   117    // RawSendIPC(campaigncfg);
   138     addKeyBindings(&campaigncfg);
       
   139 
       
   140     //RawSendIPC(campaigncfg);
   118 }
   141 }
   119 
   142 
   120 void HWGame::SendNetConfig()
   143 void HWGame::SendNetConfig()
   121 {
   144 {
   122     commonConfig();
   145     commonConfig();
   215                 sendCampaignVar(msg.right(msg.size() - 3));
   238                 sendCampaignVar(msg.right(msg.size() - 3));
   216             else if (msg.at(2) == '!')
   239             else if (msg.at(2) == '!')
   217                 writeCampaignVar(msg.right(msg.size() - 3));
   240                 writeCampaignVar(msg.right(msg.size() - 3));
   218             break;
   241             break;
   219         }
   242         }
       
   243         case 'W':
       
   244         {
       
   245             // fetch new window resolution via IPC and save it in the settings
       
   246             int size = msg.size();
       
   247             QString newResolution = QString().append(msg.mid(2)).left(size - 4);
       
   248             QStringList wh = newResolution.split('x');
       
   249             config->Form->ui.pageOptions->windowWidthEdit->setText(wh[0]);
       
   250             config->Form->ui.pageOptions->windowHeightEdit->setText(wh[1]);
       
   251             break;
       
   252         }
   220         default:
   253         default:
   221         {
   254         {
   222             if (gameType == gtNet && !netSuspend)
   255             if (gameType == gtNet && !netSuspend)
   223             {
   256             {
   224                 emit SendNet(msg);
   257                 emit SendNet(msg);
   254 }
   287 }
   255 
   288 
   256 QStringList HWGame::getArguments()
   289 QStringList HWGame::getArguments()
   257 {
   290 {
   258     QStringList arguments;
   291     QStringList arguments;
   259     QRect resolution = config->vid_Resolution();
   292     std::pair<QRect, QRect> resolutions = config->vid_ResolutionPair();
       
   293     QString nick = config->netNick().toUtf8().toBase64();
       
   294 
       
   295     arguments << "--internal"; //Must be passed as first argument
       
   296     arguments << "--port";
       
   297     arguments << QString::number(flib_gameconn_getport(m_conn));
       
   298     arguments << "--prefix";
       
   299     arguments << datadir->absolutePath();
       
   300     arguments << "--user-prefix";
   260     arguments << cfgdir->absolutePath();
   301     arguments << cfgdir->absolutePath();
   261     arguments << QString::number(resolution.width());
   302     arguments << "--locale";
   262     arguments << QString::number(resolution.height());
   303     arguments << tr("en.txt");
   263     arguments << QString::number(config->bitDepth()); // bpp
   304     arguments << "--frame-interval";
   264     arguments << QString::number(flib_gameconn_getport(m_conn));
       
   265     arguments << (config->vid_Fullscreen() ? "1" : "0");
       
   266     arguments << (config->isSoundEnabled() ? "1" : "0");
       
   267     arguments << (config->isMusicEnabled() ? "1" : "0");
       
   268     arguments << QString::number(config->volume()); // sound volume
       
   269     arguments << QString::number(config->timerInterval());
   305     arguments << QString::number(config->timerInterval());
   270     arguments << datadir->absolutePath();
   306     arguments << "--volume";
   271     arguments << (config->isShowFPSEnabled() ? "1" : "0");
   307     arguments << QString::number(config->volume());
   272     arguments << (config->isAltDamageEnabled() ? "1" : "0");
   308     arguments << "--fullscreen-width";
   273     arguments << config->netNick().toUtf8().toBase64();
   309     arguments << QString::number(resolutions.first.width());
       
   310     arguments << "--fullscreen-height";
       
   311     arguments << QString::number(resolutions.first.height());
       
   312     arguments << "--width";
       
   313     arguments << QString::number(resolutions.second.width());
       
   314     arguments << "--height";
       
   315     arguments << QString::number(resolutions.second.height());
       
   316     arguments << "--raw-quality";
   274     arguments << QString::number(config->translateQuality());
   317     arguments << QString::number(config->translateQuality());
       
   318     arguments << "--stereo";
   275     arguments << QString::number(config->stereoMode());
   319     arguments << QString::number(config->stereoMode());
   276     arguments << tr("en.txt");
   320     if (config->vid_Fullscreen())
       
   321         arguments << "--fullscreen";
       
   322     if (config->isShowFPSEnabled())
       
   323         arguments << "--showfps";
       
   324     if (config->isAltDamageEnabled())
       
   325         arguments << "--altdmg";
       
   326     if (!config->isSoundEnabled())
       
   327         arguments << "--nosound";
       
   328     if (!config->isMusicEnabled())
       
   329         arguments << "--nomusic";
       
   330     if (!nick.isEmpty()) {
       
   331         arguments << "--nick";
       
   332         arguments << nick;
       
   333     }
   277 
   334 
   278     return arguments;
   335     return arguments;
   279 }
   336 }
   280 
   337 
   281 void HWGame::PlayDemo(const QString & demofilename, bool isSave)
   338 void HWGame::PlayDemo(const QString & demofilename, bool isSave)