26
|
1 |
/*
|
|
2 |
* Hedgewars, a worms-like game
|
|
3 |
* Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
|
|
4 |
*
|
|
5 |
* Distributed under the terms of the BSD-modified licence:
|
|
6 |
*
|
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8 |
* of this software and associated documentation files (the "Software"), to deal
|
|
9 |
* with the Software without restriction, including without limitation the
|
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is
|
|
12 |
* furnished to do so, subject to the following conditions:
|
|
13 |
*
|
|
14 |
* 1. Redistributions of source code must retain the above copyright notice,
|
|
15 |
* this list of conditions and the following disclaimer.
|
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
17 |
* this list of conditions and the following disclaimer in the documentation
|
|
18 |
* and/or other materials provided with the distribution.
|
|
19 |
* 3. The name of the author may not be used to endorse or promote products
|
|
20 |
* derived from this software without specific prior written permission.
|
|
21 |
*
|
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
32 |
*/
|
|
33 |
|
|
34 |
#include <QFile>
|
|
35 |
#include <QTextStream>
|
|
36 |
#include "team.h"
|
|
37 |
#include "hwform.h"
|
|
38 |
|
|
39 |
HWTeam::HWTeam(const QString & teamname)
|
|
40 |
{
|
|
41 |
TeamName = teamname;
|
|
42 |
for (int i = 0; i < 8; i++) HHName[i].sprintf("hedgehog %d", i);
|
|
43 |
Grave = "Simple";
|
|
44 |
Fort = "Barrelhouse";
|
|
45 |
for(int i = 0; i < BINDS_NUMBER; i++)
|
|
46 |
{
|
|
47 |
binds[i].action = cbinds[i].action;
|
|
48 |
binds[i].strbind = cbinds[i].strbind;
|
|
49 |
}
|
|
50 |
dir = "";
|
|
51 |
}
|
|
52 |
|
|
53 |
bool HWTeam::LoadFromFile()
|
|
54 |
{
|
|
55 |
QFile cfgfile(dir + "/" + TeamName + ".cfg");
|
|
56 |
if (!cfgfile.open(QIODevice::ReadOnly)) return false;
|
|
57 |
QTextStream stream(&cfgfile);
|
|
58 |
stream.setCodec("UTF-8");
|
|
59 |
QString str;
|
|
60 |
QString action;
|
|
61 |
|
|
62 |
while (!stream.atEnd())
|
|
63 |
{
|
|
64 |
str = stream.readLine();
|
|
65 |
if (str.startsWith(";")) continue;
|
|
66 |
if (str.startsWith("name team "))
|
|
67 |
{
|
|
68 |
str.remove(0, 10);
|
|
69 |
TeamName = str;
|
|
70 |
} else
|
|
71 |
if (str.startsWith("name hh"))
|
|
72 |
{
|
|
73 |
str.remove(0, 7);
|
|
74 |
long i = str.left(1).toLong();
|
|
75 |
if ((i < 0) || (i > 7)) continue;
|
|
76 |
str.remove(0, 2);
|
|
77 |
HHName[i] = str;
|
|
78 |
} else
|
|
79 |
if (str.startsWith("grave "))
|
|
80 |
{
|
|
81 |
str.remove(0, 6);
|
|
82 |
Grave = str;
|
|
83 |
} else
|
|
84 |
if (str.startsWith("fort "))
|
|
85 |
{
|
|
86 |
str.remove(0, 5);
|
|
87 |
Fort = str;
|
|
88 |
} else
|
|
89 |
if (str.startsWith("bind "))
|
|
90 |
{
|
|
91 |
str.remove(0, 5);
|
|
92 |
action = str.section(' ', 1);
|
|
93 |
str = str.section(' ', 0, 0);
|
|
94 |
str.truncate(15);
|
|
95 |
for (int i = 0; i < BINDS_NUMBER; i++)
|
|
96 |
if (action == binds[i].action)
|
|
97 |
{
|
|
98 |
binds[i].strbind = str;
|
|
99 |
break;
|
|
100 |
}
|
|
101 |
}
|
|
102 |
}
|
|
103 |
cfgfile.close();
|
|
104 |
return true;
|
|
105 |
}
|
|
106 |
|
|
107 |
bool HWTeam::SaveToFile()
|
|
108 |
{
|
|
109 |
QFile cfgfile(dir + "/" + TeamName + ".cfg");
|
|
110 |
if (!cfgfile.open(QIODevice::WriteOnly)) return false;
|
|
111 |
QTextStream stream(&cfgfile);
|
|
112 |
stream.setCodec("UTF-8");
|
|
113 |
stream << "; Generated by Hedgewars, do not modify" << endl;
|
|
114 |
stream << "name team " << TeamName << endl;
|
|
115 |
for (int i = 0; i < 8; i++)
|
|
116 |
stream << "name hh" << i << " " << HHName[i] << endl;
|
|
117 |
stream << "grave " << Grave << endl;
|
|
118 |
stream << "fort " << Fort << endl;
|
|
119 |
for(int i = 0; i < BINDS_NUMBER; i++)
|
|
120 |
{
|
|
121 |
stream << "bind " << binds[i].strbind << " " << binds[i].action << endl;
|
|
122 |
}
|
|
123 |
cfgfile.close();
|
|
124 |
return true;
|
|
125 |
}
|
|
126 |
|
|
127 |
void HWTeam::SetToPage(HWForm * hwform)
|
|
128 |
{
|
|
129 |
hwform->TeamNameEdit->setText(TeamName);
|
|
130 |
for(int i = 0; i < 8; i++)
|
|
131 |
{
|
|
132 |
hwform->HHNameEdit[i]->setText(HHName[i]);
|
|
133 |
}
|
|
134 |
hwform->ui.CBGrave->setCurrentIndex(hwform->ui.CBGrave->findText(Grave));
|
|
135 |
hwform->CBGrave_activated(Grave);
|
|
136 |
|
|
137 |
hwform->ui.CBFort->setCurrentIndex(hwform->ui.CBFort->findText(Fort));
|
|
138 |
hwform->CBFort_activated(Fort);
|
|
139 |
|
|
140 |
for(int i = 0; i < BINDS_NUMBER; i++)
|
|
141 |
{
|
|
142 |
hwform->CBBind[i]->setCurrentIndex(hwform->CBBind[i]->findText(binds[i].strbind));
|
|
143 |
}
|
|
144 |
}
|
|
145 |
|
|
146 |
void HWTeam::GetFromPage(HWForm * hwform)
|
|
147 |
{
|
|
148 |
TeamName = hwform->TeamNameEdit->text();
|
|
149 |
for(int i = 0; i < 8; i++)
|
|
150 |
{
|
|
151 |
HHName[i] = hwform->HHNameEdit[i]->text();
|
|
152 |
}
|
|
153 |
|
|
154 |
Grave = hwform->ui.CBGrave->currentText();
|
|
155 |
Fort = hwform->ui.CBFort->currentText();
|
|
156 |
for(int i = 0; i < 8; i++)
|
|
157 |
{
|
|
158 |
binds[i].strbind = hwform->CBBind[i]->currentText();
|
|
159 |
}
|
|
160 |
}
|
|
161 |
|
|
162 |
void HWTeam::SetCfgDir(const QString & dir)
|
|
163 |
{
|
|
164 |
this->dir = dir;
|
|
165 |
}
|