QTfrontend/hwform.cpp
changeset 7006 6af78154dc62
parent 6960 822f8269e13f
child 7004 45d43f372107
equal deleted inserted replaced
6852:9e724f4863a3 7006:6af78154dc62
     1 /*
     1 /*
     2  * Hedgewars, a free turn based strategy game
     2  * Hedgewars, a free turn based strategy game
     3  * Copyright (c) 2005-2012 Andrey Korotaev <unC0Rr@gmail.com>
     3  * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
     4  *
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     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
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation; version 2 of the License
     7  * the Free Software Foundation; version 2 of the License
     8  *
     8  *
    81 #include "gamecfgwidget.h"
    81 #include "gamecfgwidget.h"
    82 #include "netserverslist.h"
    82 #include "netserverslist.h"
    83 #include "netudpserver.h"
    83 #include "netudpserver.h"
    84 #include "chatwidget.h"
    84 #include "chatwidget.h"
    85 #include "input_ip.h"
    85 #include "input_ip.h"
       
    86 #include "input_password.h"
    86 #include "ammoSchemeModel.h"
    87 #include "ammoSchemeModel.h"
    87 #include "bgwidget.h"
    88 #include "bgwidget.h"
    88 #include "xfire.h"
    89 #include "xfire.h"
    89 #include "drawmapwidget.h"
    90 #include "drawmapwidget.h"
    90 #include "mouseoverfilter.h"
    91 #include "mouseoverfilter.h"
    91 #include "roomslistmodel.h"
    92 #include "roomslistmodel.h"
    92 
    93 
    93 #include "HWDataManager.h"
    94 #include "DataManager.h"
    94 
    95 
    95 #ifdef __APPLE__
    96 #ifdef __APPLE__
    96 #include "M3Panel.h"
    97 #include "M3Panel.h"
    97 #ifdef SPARKLE_ENABLED
    98 #ifdef SPARKLE_ENABLED
    98 #define SPARKLE_APPCAST_URL "http://www.hedgewars.org/download/appcast.xml"
    99 #define SPARKLE_APPCAST_URL "http://www.hedgewars.org/download/appcast.xml"
   117     , editedTeam(0)
   118     , editedTeam(0)
   118     , hwnet(0)
   119     , hwnet(0)
   119 {
   120 {
   120     // set music track
   121     // set music track
   121     SDLInteraction::instance().setMusicTrack(
   122     SDLInteraction::instance().setMusicTrack(
   122         HWDataManager::instance().findFileForRead("Music/main_theme.ogg")
   123         DataManager::instance().findFileForRead("Music/main_theme.ogg")
   123     );
   124     );
   124 
   125 
   125 #ifdef USE_XFIRE
   126 #ifdef USE_XFIRE
   126     xfire_init();
   127     xfire_init();
   127 #endif
   128 #endif
   152 
   153 
   153     QShortcut *hideFrontend = new QShortcut(QKeySequence("Ctrl+M"), this);
   154     QShortcut *hideFrontend = new QShortcut(QKeySequence("Ctrl+M"), this);
   154     connect (hideFrontend, SIGNAL(activated()), this, SLOT(showMinimized()));
   155     connect (hideFrontend, SIGNAL(activated()), this, SLOT(showMinimized()));
   155 #else
   156 #else
   156     // ctrl+q closes frontend for consistency
   157     // ctrl+q closes frontend for consistency
   157     QShortcut *closeFrontend = new QShortcut(QKeySequence("Ctrl+Q"), this);
   158     QShortcut * closeFrontend = new QShortcut(QKeySequence("Ctrl+Q"), this);
   158     connect (closeFrontend, SIGNAL(activated()), this, SLOT(close()));
   159     connect (closeFrontend, SIGNAL(activated()), this, SLOT(close()));
       
   160     QShortcut * updateData = new QShortcut(QKeySequence("F5"), this);
       
   161     connect (updateData, SIGNAL(activated()), &DataManager::instance(), SLOT(reload()));
   159 #endif
   162 #endif
   160 
   163 
   161     UpdateTeamsLists();
   164     UpdateTeamsLists();
   162     UpdateCampaignPage(0);
   165     UpdateCampaignPage(0);
   163     UpdateWeapons();
   166     UpdateWeapons();
   590     if (id == ID_PAGE_MAIN)
   593     if (id == ID_PAGE_MAIN)
   591     {
   594     {
   592         ui.pageOptions->setTeamOptionsEnabled(true);
   595         ui.pageOptions->setTeamOptionsEnabled(true);
   593     }
   596     }
   594 
   597 
       
   598     if (id == ID_PAGE_SETUP)
       
   599     {
       
   600         config->reloadValues();
       
   601     }
       
   602 
   595     // load and save ignore/friends lists
   603     // load and save ignore/friends lists
   596     if (lastid == ID_PAGE_NETGAME) // leaving a room
   604     if (lastid == ID_PAGE_NETGAME) // leaving a room
   597         ui.pageNetGame->pChatWidget->saveLists(ui.pageOptions->editNetNick->text());
   605         ui.pageNetGame->pChatWidget->saveLists(ui.pageOptions->editNetNick->text());
   598     else if(lastid == ID_PAGE_ROOMSLIST) // leaving the lobby
   606     else if(lastid == ID_PAGE_ROOMSLIST) // leaving the lobby
   599         ui.pageRoomsList->chatWidget->saveLists(ui.pageOptions->editNetNick->text());
   607         ui.pageRoomsList->chatWidget->saveLists(ui.pageOptions->editNetNick->text());
   636         int duration = config->isFrontendEffects() ? 500 : 0;
   644         int duration = config->isFrontendEffects() ? 500 : 0;
   637 
   645 
   638         //New page animation
   646         //New page animation
   639         animationNewSlide = new QPropertyAnimation(ui.Pages->widget(id), "pos");
   647         animationNewSlide = new QPropertyAnimation(ui.Pages->widget(id), "pos");
   640         animationNewSlide->setDuration(duration);
   648         animationNewSlide->setDuration(duration);
   641         animationNewSlide->setStartValue(QPoint(20000/coeff, 0));
   649         animationNewSlide->setStartValue(QPoint(this->width()*1.5/coeff, 0));
   642         animationNewSlide->setEndValue(QPoint(0, 0));
   650         animationNewSlide->setEndValue(QPoint(0, 0));
   643         animationNewSlide->setEasingCurve(QEasingCurve::OutExpo);
   651         animationNewSlide->setEasingCurve(QEasingCurve::OutExpo);
   644 
   652 
   645 #ifdef false
   653 #ifdef false
   646         animationNewOpacity = new QPropertyAnimation(effectNew, "opacity");
   654         animationNewOpacity = new QPropertyAnimation(effectNew, "opacity");
   654         ui.Pages->widget(lastid)->setHidden(false);
   662         ui.Pages->widget(lastid)->setHidden(false);
   655 
   663 
   656         animationOldSlide = new QPropertyAnimation(ui.Pages->widget(lastid), "pos");
   664         animationOldSlide = new QPropertyAnimation(ui.Pages->widget(lastid), "pos");
   657         animationOldSlide->setDuration(duration);
   665         animationOldSlide->setDuration(duration);
   658         animationOldSlide->setStartValue(QPoint(0, 0));
   666         animationOldSlide->setStartValue(QPoint(0, 0));
   659         animationOldSlide->setEndValue(QPoint(-20000/coeff, 0));
   667         animationOldSlide->setEndValue(QPoint(this->width()*1.5/coeff, 0));
   660         animationOldSlide->setEasingCurve(QEasingCurve::OutExpo);
   668         animationOldSlide->setEasingCurve(QEasingCurve::OutExpo);
   661 
   669 
   662 #ifdef false
   670 #ifdef false
   663         animationOldOpacity = new QPropertyAnimation(effectLast, "opacity");
   671         animationOldOpacity = new QPropertyAnimation(effectLast, "opacity");
   664         animationOldOpacity->setDuration(duration);
   672         animationOldOpacity->setDuration(duration);
   933     NetConnectServer("netserver.hedgewars.org", 46631);
   941     NetConnectServer("netserver.hedgewars.org", 46631);
   934 }
   942 }
   935 
   943 
   936 void HWForm::NetPassword(const QString & nick)
   944 void HWForm::NetPassword(const QString & nick)
   937 {
   945 {
   938     bool ok = false;
       
   939     int passLength = config->value("net/passwordlength", 0).toInt();
   946     int passLength = config->value("net/passwordlength", 0).toInt();
   940     QString hash = config->value("net/passwordhash", "").toString();
   947     QString hash = config->value("net/passwordhash", "").toString();
   941 
   948 
   942     // If the password is blank, ask the user to enter one in
   949     // If the password is blank, ask the user to enter one in
   943     if (passLength == 0)
   950     if (passLength == 0)
   944     {
   951     {
   945         QString password = QInputDialog::getText(this, tr("Password"), tr("Your nickname %1 is\nregistered on Hedgewars.org\nPlease provide your password below\nor pick another nickname in game config:").arg(nick), QLineEdit::Password, passLength==0?NULL:QString(passLength,'\0'), &ok);
   952         HWPasswordDialog * hpd = new HWPasswordDialog(this, tr("Your nickname %1 is\nregistered on Hedgewars.org\nPlease provide your password below\nor pick another nickname in game config:").arg(nick));
   946 
   953         hpd->cbSave->setChecked(config->value("net/savepassword", true).toBool());
   947         if (!ok)
   954         if (hpd->exec() != QDialog::Accepted)
   948         {
   955         {
   949             ForcedDisconnect(tr("No password supplied."));
   956             ForcedDisconnect(tr("No password supplied."));
       
   957             delete hpd;
   950             return;
   958             return;
   951         }
   959         }
   952 
   960 
       
   961         QString password = hpd->lePassword->text();
   953         hash = QCryptographicHash::hash(password.toLatin1(), QCryptographicHash::Md5).toHex();
   962         hash = QCryptographicHash::hash(password.toLatin1(), QCryptographicHash::Md5).toHex();
   954         config->setValue("net/passwordhash", hash);
   963 
   955         config->setValue("net/passwordlength", password.size());
   964         bool save = hpd->cbSave->isChecked();
   956         config->setNetPasswordLength(password.size());
   965         config->setValue("net/savepassword", save);
       
   966         if (save) // user wants to save password
       
   967         {
       
   968             config->setValue("net/passwordhash", hash);
       
   969             config->setValue("net/passwordlength", password.size());
       
   970             config->setNetPasswordLength(password.size());
       
   971         }
       
   972 
       
   973         delete hpd;
   957     }
   974     }
   958 
   975 
   959     hwnet->SendPasswordHash(hash);
   976     hwnet->SendPasswordHash(hash);
   960 }
   977 }
   961 
   978 
  1178         delete netHost;
  1195         delete netHost;
  1179         netHost = new QString(hpd->leHost->text());
  1196         netHost = new QString(hpd->leHost->text());
  1180         netPort = hpd->sbPort->value();
  1197         netPort = hpd->sbPort->value();
  1181         NetConnectServer(*netHost, netPort);
  1198         NetConnectServer(*netHost, netPort);
  1182     }
  1199     }
       
  1200     delete hpd;
  1183 }
  1201 }
  1184 
  1202 
  1185 void HWForm::NetStartServer()
  1203 void HWForm::NetStartServer()
  1186 {
  1204 {
  1187     config->SaveOptions();
  1205     config->SaveOptions();
  1522     Q_UNUSED(index);
  1540     Q_UNUSED(index);
  1523 
  1541 
  1524     HWTeam team(ui.pageCampaign->CBTeam->currentText());
  1542     HWTeam team(ui.pageCampaign->CBTeam->currentText());
  1525     ui.pageCampaign->CBSelect->clear();
  1543     ui.pageCampaign->CBSelect->clear();
  1526 
  1544 
  1527     QStringList entries = HWDataManager::instance().entryList(
  1545     QStringList entries = DataManager::instance().entryList(
  1528                               "Missions/Campaign",
  1546                               "Missions/Campaign",
  1529                               QDir::Files,
  1547                               QDir::Files,
  1530                               QStringList("*#*.lua")
  1548                               QStringList("*#*.lua")
  1531                           );
  1549                           );
  1532 
  1550