|
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 <qstring.h> |
|
35 #include <qfile.h> |
|
36 #include <qtextstream.h> |
|
37 #include "hw.h" |
|
38 |
|
39 class QString; |
|
40 class QTextStream; |
|
41 class QFile; |
|
42 class HWForm; |
|
43 |
|
44 class HWTeam |
|
45 { |
|
46 public: |
|
47 HWTeam() |
|
48 { |
|
49 TeamName = "unnamed"; |
|
50 for (int i = 0; i < 8; i++) HHName[i].sprintf("hedgehog %d", i); |
|
51 Grave = "Simple"; |
|
52 } |
|
53 QString TeamName; |
|
54 QString HHName[8]; |
|
55 QString Grave; |
|
56 QString Fort; |
|
57 |
|
58 bool LoadFromFile(const QString & filename) |
|
59 { |
|
60 QFile cfgfile(filename); |
|
61 if (!cfgfile.open(IO_ReadOnly)) return false; |
|
62 QTextStream stream(&cfgfile); |
|
63 stream.setEncoding(QTextStream::Unicode); |
|
64 QString str; |
|
65 |
|
66 while (!stream.atEnd()) |
|
67 { |
|
68 str = stream.readLine(); |
|
69 if (str.startsWith(";")) continue; |
|
70 if (str.startsWith("teamname ")) |
|
71 { |
|
72 str.remove(0, 9); |
|
73 TeamName = str; |
|
74 } else |
|
75 if (str.startsWith("name")) |
|
76 { |
|
77 str.remove(0, 4); |
|
78 long i = str.left(1).toLong(); |
|
79 if ((i < 0) || (i > 7)) continue; |
|
80 str.remove(0, 2); |
|
81 HHName[i] = str; |
|
82 } else |
|
83 if (str.startsWith("grave ")) |
|
84 { |
|
85 str.remove(0, 6); |
|
86 Grave = str; |
|
87 } else |
|
88 if (str.startsWith("fort ")) |
|
89 { |
|
90 str.remove(0, 5); |
|
91 Fort = str; |
|
92 } |
|
93 } |
|
94 cfgfile.close(); |
|
95 return true; |
|
96 } |
|
97 |
|
98 bool SaveToFile(const QString & filename) |
|
99 { |
|
100 QFile cfgfile(filename); |
|
101 if (!cfgfile.open(IO_WriteOnly)) return false; |
|
102 QTextStream stream(&cfgfile); |
|
103 stream.setEncoding(QTextStream::Unicode); |
|
104 stream << "; Generated by Hedgewars, do not modify" << endl; |
|
105 stream << "teamname " << TeamName << endl; |
|
106 for (int i = 0; i < 8; i++) |
|
107 stream << "name" << i << " " << HHName[i] << endl; |
|
108 stream << "grave " << Grave << endl; |
|
109 stream << "fort " << Fort << endl; |
|
110 cfgfile.close(); |
|
111 return true; |
|
112 } |
|
113 |
|
114 void ToPage(HWForm * form) |
|
115 { |
|
116 form->EditTeamName->setText(TeamName); |
|
117 form->HHName0->setText(HHName[0]); |
|
118 form->HHName1->setText(HHName[1]); |
|
119 form->HHName2->setText(HHName[2]); |
|
120 form->HHName3->setText(HHName[3]); |
|
121 form->HHName4->setText(HHName[4]); |
|
122 form->HHName5->setText(HHName[5]); |
|
123 form->HHName6->setText(HHName[6]); |
|
124 form->HHName7->setText(HHName[7]); |
|
125 |
|
126 const QListBox * lb = form->CBGraves->listBox(); |
|
127 form->CBGraves->setCurrentItem(lb->index(lb->findItem(Grave))); |
|
128 |
|
129 lb = form->CBForts->listBox(); |
|
130 form->CBForts->setCurrentItem(lb->index(lb->findItem(Fort))); |
|
131 } |
|
132 |
|
133 void FromPage(HWForm * form) |
|
134 { |
|
135 TeamName = form->EditTeamName->text(); |
|
136 HHName[0] = form->HHName0->text(); |
|
137 HHName[1] = form->HHName1->text(); |
|
138 HHName[2] = form->HHName2->text(); |
|
139 HHName[3] = form->HHName3->text(); |
|
140 HHName[4] = form->HHName4->text(); |
|
141 HHName[5] = form->HHName5->text(); |
|
142 HHName[6] = form->HHName6->text(); |
|
143 HHName[7] = form->HHName7->text(); |
|
144 |
|
145 Grave = form->CBGraves->currentText(); |
|
146 Fort = form->CBForts->currentText(); |
|
147 } |
|
148 private: |
|
149 }; |