Subversion Repositories spk

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 cycrow 1
#include "../StdAfx.h"
2
#include "CustomiseGuns.h"
3
 
4
namespace Creator {
5
	String ^CustomiseGuns::GetPosition(int dir)
6
	{
7
		return ((CustomiseShip ^)m_pParent)->GetPosition(dir);
8
	}
9
 
10
	void CustomiseGuns::SetupControls()
11
	{
12
		this->Dock = System::Windows::Forms::DockStyle::Fill;
13
 
14
		// update scene file entries
15
		if ( !m_pModels || m_pModels->Empty() )
16
		{
17
			// if no scene file
18
			if ( this->PageAuto )
19
				delete this->PageAuto;
20
			this->PageAuto = nullptr;
21
		}
22
		// otherwise, fill in the data
23
		else
24
		{
25
			int i = 0;
26
			this->ComboAutoPrimary->Items->Add("None");
27
			this->ComboAutoSecondary->Items->Add("None");
28
			for ( SStringList *str = m_pModels->Head(); str; str = str->next )
29
			{
30
				String ^entry = SystemStringFromCyString(str->str) + ":" + Convert::ToString(i);
31
				this->ComboAutoPrimary->Items->Add(entry);
32
				this->ComboAutoSecondary->Items->Add(entry);
33
				++i;
34
			}
35
		}
36
	}
37
 
38
	void CustomiseGuns::UpdateDisplay()
39
	{
40
	}
41
 
42
	void CustomiseGuns::ChangeGunValues()
43
	{
44
		if ( m_bUpdatingGunLists )
45
			return;
46
		this->UpdateGunTurrets();
47
	}
48
 
49
	void CustomiseGuns::UpdateGunEntrys()
50
	{
51
		if ( !this->ListTurrets->SelectedItems->Count || !this->ListGuns->SelectedItems->Count )
52
			return;
53
 
54
		m_bUpdatingGunLists = true;
55
 
56
		SGunGroup *g = m_pShipData->lGuns.Get(Convert::ToInt32(this->ListTurrets->SelectedItems[0]->Tag));
57
		SWeaponGroup *w = g->lWeapons.Get(Convert::ToInt32(this->ListGuns->SelectedItems[0]->Tag));
58
 
59
		if ( this->PageAuto )
60
		{
61
			if ( w->iNode1 == -1 || (w->iNode1 == 0 && w->sModel1 == "0") || w->sModel1.Empty() )
62
				this->ComboAutoPrimary->SelectedIndex = 0;
63
			else
64
				this->ComboAutoPrimary->SelectedIndex = w->iNode1 + 1;
65
 
66
			if ( w->iNode2 == -1 || (w->iNode2 == 0 && w->sModel2 == "0") || w->sModel2.Empty() )
67
				this->ComboAutoSecondary->SelectedIndex = 0;
68
			else
69
				this->ComboAutoSecondary->SelectedIndex = w->iNode2 + 1;
70
		}
71
 
72
		if ( w->iNode1 == -1 || w->sModel1.Empty() || w->sModel1 == "0" )
73
			this->CheckManualPrimary->Checked = false;
74
		else
75
			this->CheckManualPrimary->Checked = true;
76
		this->NumManualPrimary->Value = w->iNode1;
77
		this->TextManualPrimary->Text = SystemStringFromCyString(w->sModel1);
78
 
79
		if ( w->iNode2 == -1 || w->sModel2.Empty() || w->sModel2 == "0" )
80
			this->CheckManualSecondary->Checked = false;
81
		else
82
			this->CheckManualSecondary->Checked = true;
83
		this->NumManualSecondary->Value = w->iNode2;
84
		this->TextManualSecondary->Text = SystemStringFromCyString(w->sModel2);
85
 
86
		m_bUpdatingGunLists = false;
87
	}
88
 
89
	void CustomiseGuns::UpdateGunsList()
90
	{
91
		m_bUpdatingGunLists = true;
92
 
93
		int selected = -1;
94
		if ( this->ListTurrets->SelectedItems->Count )
95
			selected = Convert::ToInt32(this->ListTurrets->SelectedItems[0]->Tag);
96
 
97
		this->ListGuns->Items->Clear();
98
 
99
		if ( this->ListTurrets->SelectedItems->Count )
100
		{
101
			int pos = Convert::ToInt32(this->ListTurrets->SelectedItems[0]->Tag);
102
			SGunGroup *g = m_pShipData->lGuns.Get(pos);
103
			STurretEntry *t = m_pShipData->lTurrets.Get(pos);
104
 
105
			int i = 0;
106
			for ( SWeaponGroup *w = g->lWeapons.First(); w; w = g->lWeapons.Next(), i++ )
107
			{
108
				ListViewItem ^item = this->ListGuns->Items->Add(gcnew ListViewItem(Convert::ToString(i)));
109
				item->SubItems->Add(Convert::ToString(w->iGunIndex));
110
				item->SubItems->Add(Convert::ToString(w->iLaser));
111
				if ( w->iNode1 == -1 || (w->iNode1 == 0 && w->sModel1 == "0") || w->sModel1.Empty() )
112
					item->SubItems->Add("None");
113
				else
114
					item->SubItems->Add(SystemStringFromCyString(w->sModel1) + ":" + Convert::ToString(w->iNode1));
115
				if ( w->iNode2 == -1 || (w->iNode2 == 0 && w->sModel2 == "0") || w->sModel2.Empty() )
116
					item->SubItems->Add("None");
117
				else
118
					item->SubItems->Add(SystemStringFromCyString(w->sModel2) + ":" + Convert::ToString(w->iNode2));
119
				item->Tag = i;
120
				item->ImageKey = "gun";
121
				if ( i == selected )
122
					item->Selected = true;
123
			}
124
		}
125
 
126
		this->ListGuns->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
127
 
128
		m_bUpdatingGunLists = false;
129
	}
130
 
131
	void CustomiseGuns::UpdateGunTurrets()
132
	{
133
		int selected = -1;
134
		if ( this->ListTurrets->SelectedItems->Count )
135
			selected = Convert::ToInt32(this->ListTurrets->SelectedItems[0]->Tag);
136
 
137
		this->ListTurrets->Items->Clear();
138
		int i = 0;
139
		for ( SGunGroup *g = m_pShipData->lGuns.First(); g; g = m_pShipData->lGuns.Next(), i++ )
140
		{
141
			STurretEntry *t = m_pShipData->lTurrets.Get(i);
142
			ListViewItem ^item = this->ListTurrets->Items->Add(gcnew ListViewItem(Convert::ToString(g->iIndex)));
143
 
144
			item->SubItems->Add(Convert::ToString(g->iGunIndex));
145
			item->SubItems->Add(Convert::ToString(g->iLaserCount));
146
			item->SubItems->Add(Convert::ToString(g->iWeaponCount));
147
			// turret position
148
			if ( i == 0 ) item->SubItems->Add(this->GetPosition(0));
149
			else item->SubItems->Add(this->GetPosition(m_pShipData->cockpits[t->iTurret - 1].iPos));
150
			item->ImageKey = "turret";
151
			item->Tag = i;
152
 
153
			if ( i == selected )
154
			{
155
				item->Selected = true;
156
				this->UpdateGunsList();
157
			}
158
		}
159
		this->ListTurrets->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
160
	}
161
};