1 |
cycrow |
1 |
#include "../StdAfx.h"
|
|
|
2 |
#include "CustomiseTurret.h"
|
|
|
3 |
|
|
|
4 |
#include "CustomiseShip.h"
|
|
|
5 |
|
|
|
6 |
namespace Creator {
|
|
|
7 |
String ^CustomiseTurret::GetPosition(int dir)
|
|
|
8 |
{
|
|
|
9 |
return ((CustomiseShip ^)m_pParent)->GetPosition(dir);
|
|
|
10 |
}
|
|
|
11 |
|
|
|
12 |
void CustomiseTurret::SetupControlsEnd()
|
|
|
13 |
{
|
|
|
14 |
this->ComboGameCockpit->SelectedIndex = 0;
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
void CustomiseTurret::SetupControls()
|
|
|
18 |
{
|
|
|
19 |
// fill to tab
|
|
|
20 |
this->PanelCockpit->Enabled = false;
|
|
|
21 |
this->Dock = System::Windows::Forms::DockStyle::Fill;
|
|
|
22 |
|
|
|
23 |
// adjust the game list
|
|
|
24 |
this->ComboGameCockpit->Items->Clear();
|
|
|
25 |
this->ComboGameCockpit->Items->Add("- Default -");
|
|
|
26 |
|
|
|
27 |
// cockpit combo selection
|
|
|
28 |
this->ComboCockpit->Items->Clear();
|
170 |
cycrow |
29 |
if (!_pModels || _pModels->empty())
|
1 |
cycrow |
30 |
{
|
|
|
31 |
// if no scene file
|
|
|
32 |
if ( m_pShipData->lTurrets.size() )
|
|
|
33 |
{
|
|
|
34 |
STurretEntry *t = m_pShipData->lTurrets[0];
|
191 |
cycrow |
35 |
this->ComboCockpit->Items->Add("No Scene File Loaded!! (" + _US(t->sModel) + ":" + Convert::ToString(t->iTurret) + ")");
|
1 |
cycrow |
36 |
}
|
|
|
37 |
else
|
|
|
38 |
this->ComboCockpit->Items->Add("No Scene File Loaded!!");
|
|
|
39 |
this->ComboCockpit->Enabled = false;
|
|
|
40 |
this->ComboCockpit->SelectedIndex = 0;
|
|
|
41 |
}
|
|
|
42 |
// otherwise, fill in the data
|
|
|
43 |
else
|
|
|
44 |
{
|
|
|
45 |
this->ComboCockpit->Enabled = true;
|
|
|
46 |
int i = 0;
|
170 |
cycrow |
47 |
for(auto itr = _pModels->begin(); itr != _pModels->end(); itr++)
|
1 |
cycrow |
48 |
{
|
170 |
cycrow |
49 |
String ^entry = _US((*itr)->str) + ":" + Convert::ToString(i);
|
1 |
cycrow |
50 |
this->ComboCockpit->Items->Add(entry);
|
|
|
51 |
++i;
|
|
|
52 |
}
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
this->UpdateTurrets();
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
void CustomiseTurret::UpdateDisplay()
|
|
|
59 |
{
|
170 |
cycrow |
60 |
if (_pModels && !_pModels->empty())
|
1 |
cycrow |
61 |
this->ComboCockpit->SelectedIndex = m_pShipData->lTurrets.Get(0)->iSceneNode;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
void CustomiseTurret::UpdateCockpits()
|
|
|
65 |
{
|
|
|
66 |
this->ComboCockpitStd->Items->Clear();
|
|
|
67 |
|
94 |
cycrow |
68 |
CGameDirectories *gameDir = ((CustomiseShip ^)m_pParent)->gameDirectories();
|
197 |
cycrow |
69 |
for(Utils::WString cockpit = gameDir->firstCockpit(); !cockpit.empty(); cockpit = gameDir->nextCockpit()) {
|
94 |
cycrow |
70 |
this->ComboCockpitStd->Items->Add(_US(cockpit));
|
1 |
cycrow |
71 |
}
|
|
|
72 |
|
|
|
73 |
this->ComboCockpitCustom->Items->Clear();
|
|
|
74 |
for ( SCockpit *c = m_pShipFile->GetCockpits()->First(); c; c = m_pShipFile->GetCockpits()->Next() )
|
39 |
cycrow |
75 |
this->ComboCockpitCustom->Items->Add(_US(c->sCockpit.token(";", 19)));
|
1 |
cycrow |
76 |
}
|
|
|
77 |
|
|
|
78 |
void CustomiseTurret::UpdateTurrets()
|
|
|
79 |
{
|
|
|
80 |
this->ListTurret->Items->Clear();
|
|
|
81 |
int i = 0;
|
|
|
82 |
for ( STurretEntry *t = m_pShipData->lTurrets.First(); t; t = m_pShipData->lTurrets.Next() )
|
|
|
83 |
{
|
|
|
84 |
if ( t == m_pShipData->lTurrets.Front()->Data() ) continue; // skip the first entry (its the cockpit not a turret
|
|
|
85 |
ListViewItem ^item = this->ListTurret->Items->Add(gcnew ListViewItem(Convert::ToString(t->iIndex - 1)));
|
170 |
cycrow |
86 |
if (m_pShipData->cockpits[t->iTurret - 1].sCockpit.empty())
|
1 |
cycrow |
87 |
item->SubItems->Add(Convert::ToString(m_pShipData->cockpits[t->iTurret - 1].iCockpit));
|
|
|
88 |
else
|
170 |
cycrow |
89 |
item->SubItems->Add(_US(m_pShipData->cockpits[t->iTurret - 1].sCockpit));
|
1 |
cycrow |
90 |
item->SubItems->Add(this->GetPosition(m_pShipData->cockpits[t->iTurret - 1].iPos));
|
170 |
cycrow |
91 |
item->SubItems->Add(_US(t->sModel) + ":" + Convert::ToString(t->iSceneNode));
|
1 |
cycrow |
92 |
item->ImageKey = "turret";
|
|
|
93 |
++i;
|
|
|
94 |
item->Tag = i;
|
|
|
95 |
}
|
|
|
96 |
this->ListTurret->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
|
|
|
97 |
|
|
|
98 |
this->UpdateCockpitDisplay();
|
|
|
99 |
((CustomiseShip ^)m_pParent)->UpdateGunTurrets();
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
void CustomiseTurret::UpdateCockpitDisplay()
|
|
|
103 |
{
|
|
|
104 |
this->RadioCockpitCustom->Enabled = (this->ComboCockpitCustom->Items->Count) ? true : false;
|
|
|
105 |
this->GroupCockpit->Enabled = (this->ListTurret->SelectedItems->Count) ? true : false;
|
|
|
106 |
if ( this->ListTurret->SelectedItems->Count )
|
|
|
107 |
{
|
|
|
108 |
ListViewItem ^item = this->ListTurret->SelectedItems[0];
|
193 |
cycrow |
109 |
if ( _WS(item->SubItems[1]->Text).isNumber() && Convert::ToInt32(item->SubItems[1]->Text) < this->ComboCockpitStd->Items->Count )
|
1 |
cycrow |
110 |
{
|
|
|
111 |
this->RadioCockpitStd->Checked = true;
|
|
|
112 |
this->ComboCockpitStd->SelectedIndex = Convert::ToInt32(item->SubItems[1]->Text);
|
|
|
113 |
|
|
|
114 |
}
|
|
|
115 |
else
|
|
|
116 |
{
|
|
|
117 |
this->RadioCockpitCustom->Checked = true;
|
|
|
118 |
this->ComboCockpitCustom->Text = item->SubItems[1]->Text;
|
|
|
119 |
this->UpdateCockpitDisplay2();
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
else
|
|
|
123 |
{
|
|
|
124 |
this->ComboCockpitStd->SelectedIndex = -1;
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
void CustomiseTurret::UpdateCockpitDisplay2()
|
|
|
129 |
{
|
39 |
cycrow |
130 |
m_pCurrentCockpit = m_pShipFile->FindCockpit(_S(ComboCockpitCustom->Text));
|
1 |
cycrow |
131 |
if ( m_pCurrentCockpit )
|
|
|
132 |
{
|
191 |
cycrow |
133 |
this->TextCockpitScene->Text = _US(m_pCurrentCockpit->sCockpit.token(";", 8));
|
1 |
cycrow |
134 |
this->UpdateCockpitWeaponsList();
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
void CustomiseTurret::UpdateCockpitWeaponsList()
|
|
|
138 |
{
|
|
|
139 |
this->ListWeaponCockpit->Items->Clear();
|
|
|
140 |
|
|
|
141 |
if ( !m_pCurrentCockpit )
|
|
|
142 |
return;
|
|
|
143 |
|
|
|
144 |
bool oldUpdate = m_bUpdateing;
|
|
|
145 |
m_bUpdateing = true;
|
|
|
146 |
|
|
|
147 |
bool added = false;
|
|
|
148 |
|
|
|
149 |
CyStringList List;
|
|
|
150 |
int mask = -1;
|
|
|
151 |
if ( this->ComboGameCockpit->SelectedIndex > 0 )
|
|
|
152 |
{
|
|
|
153 |
this->CheckWeaponDefaultCockpit->Visible = true;
|
|
|
154 |
for ( SWeaponMask *m = m_pCurrentCockpit->lWeaponMask.First(); m; m = m_pCurrentCockpit->lWeaponMask.Next() )
|
|
|
155 |
{
|
|
|
156 |
if ( m->iGame == this->ComboGameCockpit->SelectedIndex )
|
|
|
157 |
{
|
|
|
158 |
mask = m->iMask;
|
|
|
159 |
break;
|
|
|
160 |
}
|
|
|
161 |
}
|
|
|
162 |
this->CheckWeaponDefaultCockpit->Checked = (mask == -1) ? true : false;
|
|
|
163 |
}
|
|
|
164 |
else
|
|
|
165 |
{
|
39 |
cycrow |
166 |
mask = m_pCurrentCockpit->sCockpit.token(";", 9);
|
1 |
cycrow |
167 |
this->CheckWeaponDefaultCockpit->Visible = false;
|
|
|
168 |
this->CheckWeaponDefaultCockpit->Checked = false;
|
|
|
169 |
}
|
|
|
170 |
if ( mask == -1 ) mask = 0;
|
94 |
cycrow |
171 |
|
|
|
172 |
if ( this->ComboGameCockpit->SelectedIndex > 0 )
|
1 |
cycrow |
173 |
{
|
94 |
cycrow |
174 |
CGameDirectories *gameDir = ((CustomiseShip ^)m_pParent)->gameDirectories();
|
|
|
175 |
gameDir->setSelectedGameDirectory(this->ComboGameCockpit->SelectedIndex, true);
|
197 |
cycrow |
176 |
for ( std::pair<Utils::WString, Utils::WString> laser = gameDir->firstLaser(); !laser.first.empty(); laser = gameDir->nextLaser() ) {
|
|
|
177 |
Utils::WString group = laser.first.token(L";", 6);
|
|
|
178 |
SStringList *found = List.FindString(group.toString());
|
94 |
cycrow |
179 |
if ( found ) {
|
1 |
cycrow |
180 |
found->data += ", ";
|
197 |
cycrow |
181 |
found->data += laser.second.toString();
|
1 |
cycrow |
182 |
}
|
|
|
183 |
else
|
197 |
cycrow |
184 |
List.PushBack(CyString(group.toString()), CyString(laser.second.toString()));
|
1 |
cycrow |
185 |
}
|
94 |
cycrow |
186 |
gameDir->reselectTemporaryDirectory();
|
1 |
cycrow |
187 |
}
|
|
|
188 |
|
|
|
189 |
for ( int i = 0; i < 32; i++ )
|
|
|
190 |
{
|
|
|
191 |
if ( List.Count() > i )
|
|
|
192 |
{
|
191 |
cycrow |
193 |
ListViewItem ^item = gcnew ListViewItem(_US(List.GetAt(i)->str.ToString()));
|
|
|
194 |
item->SubItems->Add(_US(List.GetAt(i)->data.ToString()));
|
1 |
cycrow |
195 |
this->ListWeaponCockpit->Items->Add(item);
|
|
|
196 |
item->Tag = i;
|
|
|
197 |
if ( mask & (1 << i) )
|
|
|
198 |
item->Checked = true;
|
|
|
199 |
added = true;
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
if ( !added )
|
|
|
203 |
{
|
|
|
204 |
ListViewItem ^added;
|
|
|
205 |
added = this->ListWeaponCockpit->Items->Add("LASERGROUP_" + Convert::ToString(i + 1));
|
|
|
206 |
added->Tag = i;
|
|
|
207 |
if ( mask & (1 << i) )
|
|
|
208 |
added->Checked = true;
|
|
|
209 |
}
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
this->ListWeaponCockpit->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
|
|
|
213 |
|
|
|
214 |
m_bUpdateing = oldUpdate;
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
void CustomiseTurret::EditTurret(ListViewItem ^item)
|
|
|
218 |
{
|
|
|
219 |
String ^str = this->EditTurret(Convert::ToInt32(item->Tag));
|
|
|
220 |
if ( str )
|
|
|
221 |
item->SubItems[3]->Text = str;
|
|
|
222 |
}
|
|
|
223 |
|
|
|
224 |
String ^CustomiseTurret::EditTurret(int id)
|
|
|
225 |
{
|
170 |
cycrow |
226 |
if (!_pModels) return nullptr;
|
1 |
cycrow |
227 |
InputBox ^input = gcnew InputBox("Select the model entry to use for the cockpit (Turret: " + Convert::ToString(id) + ")");
|
|
|
228 |
int i = 0;
|
170 |
cycrow |
229 |
for(auto itr = _pModels->begin(); itr != _pModels->end(); itr++)
|
1 |
cycrow |
230 |
{
|
170 |
cycrow |
231 |
input->AddItem(_US((*itr)->str) + ":" + Convert::ToString(i));
|
1 |
cycrow |
232 |
++i;
|
|
|
233 |
}
|
|
|
234 |
input->SetSelectedOption(m_pShipData->lTurrets.Get(id)->iSceneNode);
|
|
|
235 |
|
|
|
236 |
if ( input->ShowDialog(this) == Windows::Forms::DialogResult::OK )
|
|
|
237 |
{
|
|
|
238 |
String ^str = input->GetInput();
|
|
|
239 |
i = input->GetInputSelected();
|
|
|
240 |
m_pShipData->lTurrets.Get(id)->iSceneNode = i;
|
211 |
cycrow |
241 |
m_pShipData->lTurrets.Get(id)->sModel = _WS(str).token(L":", 1);
|
1 |
cycrow |
242 |
|
|
|
243 |
return str;
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
return nullptr;
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
void CustomiseTurret::SaveCockpitWeaponsList()
|
|
|
250 |
{
|
|
|
251 |
if ( m_bUpdateing )
|
|
|
252 |
return;
|
|
|
253 |
|
|
|
254 |
if ( !m_pCurrentCockpit )
|
|
|
255 |
return;
|
|
|
256 |
|
|
|
257 |
// compute the mask
|
|
|
258 |
int mask = 0;
|
|
|
259 |
for ( int i = 0; i < this->ListWeaponCockpit->Items->Count; i++ )
|
|
|
260 |
{
|
|
|
261 |
ListViewItem ^item = this->ListWeaponCockpit->Items[i];
|
|
|
262 |
if ( !item->Checked )
|
|
|
263 |
continue;
|
|
|
264 |
mask += (1 << Convert::ToInt32(item->Tag));
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
// edit the default lasers
|
|
|
268 |
if ( !this->ComboGameCockpit->SelectedIndex )
|
39 |
cycrow |
269 |
m_pCurrentCockpit->sCockpit = m_pCurrentCockpit->sCockpit.replaceToken(";", 9, (long)mask);
|
1 |
cycrow |
270 |
// otherwise adjust for the game
|
|
|
271 |
else
|
|
|
272 |
{
|
|
|
273 |
bool found = false;
|
|
|
274 |
for ( SWeaponMask *m = m_pCurrentCockpit->lWeaponMask.First(); m; m = m_pCurrentCockpit->lWeaponMask.Next() )
|
|
|
275 |
{
|
|
|
276 |
if ( m->iGame == this->ComboGameCockpit->SelectedIndex )
|
|
|
277 |
{
|
|
|
278 |
m->iMask = mask;
|
|
|
279 |
found = true;
|
|
|
280 |
break;
|
|
|
281 |
}
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
if ( !found )
|
|
|
285 |
{
|
|
|
286 |
SWeaponMask *m = new SWeaponMask;
|
|
|
287 |
m->iGame = this->ComboGameCockpit->SelectedIndex;
|
|
|
288 |
m->iMask = mask;
|
|
|
289 |
m_pCurrentCockpit->lWeaponMask.push_back(m);
|
|
|
290 |
}
|
|
|
291 |
}
|
|
|
292 |
}
|
|
|
293 |
|
|
|
294 |
};
|