QTfrontend/team.cpp
branchflibqtfrontend
changeset 8100 0e6fadf81a2c
parent 7955 85b3970b402a
child 8103 c247346d296f
equal deleted inserted replaced
8097:59a8feebec2c 8100:0e6fadf81a2c
    21 #include <QStringList>
    21 #include <QStringList>
    22 #include <QLineEdit>
    22 #include <QLineEdit>
    23 #include <QCryptographicHash>
    23 #include <QCryptographicHash>
    24 #include <QSettings>
    24 #include <QSettings>
    25 #include <QStandardItemModel>
    25 #include <QStandardItemModel>
       
    26 #include <QDebug>
    26 
    27 
    27 #include "team.h"
    28 #include "team.h"
    28 #include "hwform.h"
    29 #include "hwform.h"
    29 #include "DataManager.h"
    30 #include "DataManager.h"
    30 
    31 
    31 HWTeam::HWTeam(const QString & teamname) :
    32 HWTeam::HWTeam(const QString & teamname) :
    32     QObject(0)
    33     QObject(0)
    33     , m_difficulty(0)
    34     , m_difficulty(0)
    34     , m_numHedgehogs(4)
    35     , m_numHedgehogs(4)
    35     , m_isNetTeam(false)
    36     , m_isNetTeam(false)
       
    37     , m_team(NULL)
    36 {
    38 {
    37     m_name = teamname;
    39     m_name = teamname;
    38     OldTeamName = m_name;
    40     OldTeamName = m_name;
    39     for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
    41     for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
    40     {
    42     {
    60 
    62 
    61 HWTeam::HWTeam(const QStringList& strLst) :
    63 HWTeam::HWTeam(const QStringList& strLst) :
    62     QObject(0)
    64     QObject(0)
    63     , m_numHedgehogs(4)
    65     , m_numHedgehogs(4)
    64     , m_isNetTeam(true)
    66     , m_isNetTeam(true)
       
    67     , m_team(NULL)
    65 {
    68 {
    66     // net teams are configured from QStringList
    69     // net teams are configured from QStringList
    67     if(strLst.size() != 23) throw HWTeamConstructException();
    70     if(strLst.size() != 23) throw HWTeamConstructException();
    68     m_name = strLst[0];
    71     m_name = strLst[0];
    69     m_grave = strLst[1];
    72     m_grave = strLst[1];
    90 HWTeam::HWTeam() :
    93 HWTeam::HWTeam() :
    91     QObject(0)
    94     QObject(0)
    92     , m_difficulty(0)
    95     , m_difficulty(0)
    93     , m_numHedgehogs(4)
    96     , m_numHedgehogs(4)
    94     , m_isNetTeam(false)
    97     , m_isNetTeam(false)
       
    98     , m_team(NULL)
    95 {
    99 {
    96     m_name = QString("Team");
   100     m_name = QString("Team");
    97     for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
   101     for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
    98     {
   102     {
    99         m_hedgehogs.append(HWHog());
   103         m_hedgehogs.append(HWHog());
   127     , m_flag(other.m_flag)
   131     , m_flag(other.m_flag)
   128     , m_voicepack(other.m_voicepack)
   132     , m_voicepack(other.m_voicepack)
   129     , m_hedgehogs(other.m_hedgehogs)
   133     , m_hedgehogs(other.m_hedgehogs)
   130     , m_difficulty(other.m_difficulty)
   134     , m_difficulty(other.m_difficulty)
   131     , m_binds(other.m_binds)
   135     , m_binds(other.m_binds)
       
   136     , m_team(flib_team_copy(other.m_team))
   132     , m_numHedgehogs(other.m_numHedgehogs)
   137     , m_numHedgehogs(other.m_numHedgehogs)
   133     , m_color(other.m_color)
   138     , m_color(other.m_color)
   134     , m_isNetTeam(other.m_isNetTeam)
   139     , m_isNetTeam(other.m_isNetTeam)
   135     , m_owner(other.m_owner)
   140     , m_owner(other.m_owner)
   136     , m_campaignProgress(other.m_campaignProgress)
   141     , m_campaignProgress(other.m_campaignProgress)
   165     }
   170     }
   166 
   171 
   167     return *this;
   172     return *this;
   168 }
   173 }
   169 
   174 
       
   175 HWTeam::~HWTeam()
       
   176 {
       
   177     if(m_team)
       
   178         flib_team_destroy(m_team);
       
   179 }
       
   180 
   170 bool HWTeam::loadFromFile()
   181 bool HWTeam::loadFromFile()
   171 {
   182 {
       
   183     if(m_team)
       
   184         flib_team_destroy(m_team);
       
   185 
       
   186     m_team = flib_team_from_ini(QString("/config/Teams/%1.hwt").arg(m_name).toUtf8().constData());
       
   187 
       
   188     /*
   172     QSettings teamfile(QString("physfs://config/Teams/%1.hwt").arg(m_name), QSettings::IniFormat, 0);
   189     QSettings teamfile(QString("physfs://config/Teams/%1.hwt").arg(m_name), QSettings::IniFormat, 0);
   173     teamfile.setIniCodec("UTF-8");
   190     teamfile.setIniCodec("UTF-8");
   174     m_name = teamfile.value("Team/Name", m_name).toString();
   191     m_name = teamfile.value("Team/Name", m_name).toString();
   175     m_grave = teamfile.value("Team/Grave", "Statue").toString();
   192     m_grave = teamfile.value("Team/Grave", "Statue").toString();
   176     m_fort = teamfile.value("Team/Fort", "Plane").toString();
   193     m_fort = teamfile.value("Team/Fort", "Plane").toString();
   194         m_binds[i].strbind = teamfile.value(QString("Binds/%1").arg(m_binds[i].action), cbinds[i].strbind).toString();
   211         m_binds[i].strbind = teamfile.value(QString("Binds/%1").arg(m_binds[i].action), cbinds[i].strbind).toString();
   195     for(int i = 0; i < MAX_ACHIEVEMENTS; i++)
   212     for(int i = 0; i < MAX_ACHIEVEMENTS; i++)
   196         if(achievements[i][0][0])
   213         if(achievements[i][0][0])
   197             AchievementProgress[i] = teamfile.value(QString("Achievements/%1").arg(achievements[i][0]), 0).toUInt();
   214             AchievementProgress[i] = teamfile.value(QString("Achievements/%1").arg(achievements[i][0]), 0).toUInt();
   198         else
   215         else
   199             break;
   216             break;*/
   200     return true;
   217     return m_team != NULL;
   201 }
   218 }
   202 
   219 
   203 bool HWTeam::fileExists()
   220 bool HWTeam::fileExists()
   204 {
   221 {
   205     QFile f(QString("physfs://config/Teams/%1.hwt").arg(m_name));
   222     QFile f(QString("physfs://config/Teams/%1.hwt").arg(m_name));