| 1 |
cycrow |
1 |
#include "../StdAfx.h"
|
|
|
2 |
#include "CustomiseWeapons.h"
|
|
|
3 |
|
|
|
4 |
namespace Creator {
|
|
|
5 |
void CustomiseWeapons::SetupControls()
|
|
|
6 |
{
|
|
|
7 |
this->Dock = System::Windows::Forms::DockStyle::Fill;
|
|
|
8 |
|
|
|
9 |
this->ComboGameLaser->Items->Clear();
|
|
|
10 |
this->ComboGameLaser->Items->Add("- Default -");
|
|
|
11 |
}
|
|
|
12 |
|
| 94 |
cycrow |
13 |
void _addToList(CyStringList *list, std::pair<Utils::String, Utils::String> &pair, int idPos)
|
|
|
14 |
{
|
|
|
15 |
Utils::String group = pair.first.token(";", idPos);
|
|
|
16 |
SStringList *found = list->FindString(group);
|
|
|
17 |
if ( found ) {
|
|
|
18 |
found->data += ", ";
|
|
|
19 |
found->data += pair.second;
|
|
|
20 |
}
|
|
|
21 |
else
|
|
|
22 |
list->PushBack(CyString(group), CyString(pair.second));
|
|
|
23 |
}
|
|
|
24 |
|
| 1 |
cycrow |
25 |
void CustomiseWeapons::UpdateWeaponsList()
|
|
|
26 |
{
|
|
|
27 |
m_bUpdating = true;
|
|
|
28 |
|
|
|
29 |
this->ListWeapons->Items->Clear();
|
|
|
30 |
bool added = false;
|
|
|
31 |
|
|
|
32 |
CyStringList List;
|
|
|
33 |
int idPos = 23;
|
|
|
34 |
|
|
|
35 |
int mask = 0;
|
| 103 |
cycrow |
36 |
int defaultMask = 0;
|
| 1 |
cycrow |
37 |
|
| 94 |
cycrow |
38 |
CGameDirectories *gameDir = ((CustomiseShip ^)m_pParent)->gameDirectories();
|
|
|
39 |
|
| 1 |
cycrow |
40 |
if ( this->ComboGameLaser->SelectedIndex > 0 )
|
|
|
41 |
{
|
|
|
42 |
this->CheckWeaponDefault->Visible = true;
|
|
|
43 |
this->ButCopyDefault->Visible = true;
|
|
|
44 |
|
|
|
45 |
for ( SWeaponMasks *m = m_pWeapons->First(); m; m = m_pWeapons->Next() )
|
|
|
46 |
{
|
|
|
47 |
if ( m->iGame == this->ComboGameLaser->SelectedIndex )
|
|
|
48 |
{
|
|
|
49 |
if ( this->RadioMissiles->Checked )
|
|
|
50 |
mask = m->iMissileMask;
|
|
|
51 |
else
|
|
|
52 |
mask = m->iLaserMask;
|
|
|
53 |
break;
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
this->CheckWeaponDefault->Checked = (mask == -1) ? true : false;
|
|
|
57 |
}
|
|
|
58 |
else
|
|
|
59 |
{
|
|
|
60 |
this->ButCopyDefault->Visible = false;
|
|
|
61 |
this->CheckWeaponDefault->Visible = false;
|
|
|
62 |
this->CheckWeaponDefault->Checked = false;
|
|
|
63 |
if ( this->RadioMissiles->Checked )
|
|
|
64 |
mask = m_pShipData->iMissileMask;
|
|
|
65 |
else
|
|
|
66 |
mask = m_pShipData->iLaserMask;
|
|
|
67 |
}
|
|
|
68 |
|
| 103 |
cycrow |
69 |
if ( this->RadioMissiles->Checked )
|
|
|
70 |
defaultMask = m_pShipData->iMissileMask;
|
|
|
71 |
else
|
|
|
72 |
defaultMask = m_pShipData->iLaserMask;
|
|
|
73 |
|
|
|
74 |
if ( defaultMask == -1 ) defaultMask = 0;
|
| 1 |
cycrow |
75 |
if ( mask == -1 ) mask = 0;
|
|
|
76 |
|
| 103 |
cycrow |
77 |
if ( this->ComboGameLaser->SelectedIndex > 0 ) {
|
| 94 |
cycrow |
78 |
gameDir->setSelectedGameDirectory(this->ComboGameLaser->SelectedIndex, true);
|
| 103 |
cycrow |
79 |
if ( gameDir->selectedVFS() )
|
|
|
80 |
((CustomiseShip ^)m_pParent)->LoadText(gameDir->selectedVFS());
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
if ( !this->RadioMissiles->Checked ) {
|
|
|
84 |
for ( std::pair<Utils::String, Utils::String> laser = gameDir->firstLaser(); !laser.first.empty(); laser = gameDir->nextLaser() ) {
|
|
|
85 |
_addToList(&List, laser, 6);
|
| 1 |
cycrow |
86 |
}
|
| 103 |
cycrow |
87 |
}
|
|
|
88 |
else {
|
|
|
89 |
for ( std::pair<Utils::String, Utils::String> missile = gameDir->firstMissile(); !missile.first.empty(); missile = gameDir->nextMissile() ) {
|
|
|
90 |
_addToList(&List, missile, 6);
|
| 94 |
cycrow |
91 |
}
|
| 103 |
cycrow |
92 |
}
|
|
|
93 |
if ( this->ComboGameLaser->SelectedIndex > 0 )
|
| 94 |
cycrow |
94 |
gameDir->reselectTemporaryDirectory();
|
| 1 |
cycrow |
95 |
|
| 103 |
cycrow |
96 |
if ( this->ComboGameLaser->SelectedIndex > 0 && this->CheckWeaponDefault->Checked )
|
|
|
97 |
mask = defaultMask;
|
|
|
98 |
|
| 1 |
cycrow |
99 |
for ( int i = 0; i < 32; i++ )
|
|
|
100 |
{
|
|
|
101 |
if ( List.Count() > i )
|
|
|
102 |
{
|
|
|
103 |
ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(List.GetAt(i)->str));
|
|
|
104 |
item->SubItems->Add(SystemStringFromCyString(List.GetAt(i)->data));
|
|
|
105 |
this->ListWeapons->Items->Add(item);
|
|
|
106 |
if ( this->RadioMissiles->Checked )
|
|
|
107 |
{
|
|
|
108 |
if ( List.GetAt(i)->str.IsNumber() )
|
|
|
109 |
item->Tag = List.GetAt(i)->str.ToInt();
|
|
|
110 |
else
|
|
|
111 |
item->Tag = CShipData::ConvertMissileGroupToID(List.GetAt(i)->str);
|
|
|
112 |
}
|
|
|
113 |
else
|
|
|
114 |
item->Tag = i;
|
|
|
115 |
|
|
|
116 |
int flag = (1 << Convert::ToInt32(item->Tag));
|
| 103 |
cycrow |
117 |
|
| 1 |
cycrow |
118 |
if ( mask & flag )
|
|
|
119 |
item->Checked = true;
|
|
|
120 |
added = true;
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
if ( !added )
|
|
|
124 |
{
|
|
|
125 |
ListViewItem ^added;
|
|
|
126 |
if ( this->RadioMissiles->Checked )
|
|
|
127 |
added = this->ListWeapons->Items->Add("MISSILEGROUP_" + Convert::ToString(i + 1));
|
|
|
128 |
else
|
|
|
129 |
added = this->ListWeapons->Items->Add("LASERGROUP_" + Convert::ToString(i + 1));
|
|
|
130 |
added->Tag = i;
|
|
|
131 |
if ( mask & (1 << i) )
|
|
|
132 |
added->Checked = true;
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
this->ListWeapons->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
|
|
|
137 |
|
|
|
138 |
m_bUpdating = false;
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
void CustomiseWeapons::SaveWeaponsList()
|
|
|
142 |
{
|
|
|
143 |
if ( m_bUpdating )
|
|
|
144 |
return;
|
|
|
145 |
|
|
|
146 |
// compute the mask
|
|
|
147 |
int mask = 0;
|
|
|
148 |
for ( int i = 0; i < this->ListWeapons->Items->Count; i++ )
|
|
|
149 |
{
|
|
|
150 |
ListViewItem ^item = this->ListWeapons->Items[i];
|
|
|
151 |
if ( !item->Checked )
|
|
|
152 |
continue;
|
|
|
153 |
mask += (1 << Convert::ToInt32(item->Tag));
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
// edit the default lasers
|
|
|
157 |
if ( !this->ComboGameLaser->SelectedIndex )
|
|
|
158 |
{
|
|
|
159 |
if ( this->RadioMissiles->Checked )
|
|
|
160 |
m_pShipData->iMissileMask = mask;
|
|
|
161 |
else
|
|
|
162 |
m_pShipData->iLaserMask = mask;
|
|
|
163 |
}
|
|
|
164 |
// otherwise adjust for the game
|
|
|
165 |
else
|
|
|
166 |
{
|
|
|
167 |
for ( SWeaponMasks *m = m_pWeapons->First(); m; m = m_pWeapons->Next() )
|
|
|
168 |
{
|
|
|
169 |
if ( m->iGame == this->ComboGameLaser->SelectedIndex )
|
|
|
170 |
{
|
|
|
171 |
if ( this->RadioMissiles->Checked )
|
|
|
172 |
m->iMissileMask = mask;
|
|
|
173 |
else
|
|
|
174 |
m->iLaserMask = mask;
|
|
|
175 |
break;
|
|
|
176 |
}
|
|
|
177 |
}
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
};
|