]> icculus.org git repositories - taylor/freespace2.git/blob - src/fred2/shieldsysdlg.cpp
Initial revision
[taylor/freespace2.git] / src / fred2 / shieldsysdlg.cpp
1 /*
2  * $Logfile: /Freespace2/code/FRED2/ShieldSysDlg.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Shield generator system editor.  This dialog allows one to indicate whether all ships
8  * (on a certain team or of a certain type) have a shield system or not.
9  *
10  * $Log$
11  * Revision 1.1  2002/05/03 03:28:08  root
12  * Initial revision
13  *
14  * 
15  * 2     10/07/98 6:28p Dave
16  * Initial checkin. Renamed all relevant stuff to be Fred2 instead of
17  * Fred. Globalized mission and campaign file extensions. Removed Silent
18  * Threat specific code.
19  * 
20  * 1     10/07/98 3:01p Dave
21  * 
22  * 1     10/07/98 3:00p Dave
23  * 
24  * 2     8/18/97 9:31p Hoffoss
25  * Added grid adjustment dialog and shield system editor dialog.
26  *
27  * $NoKeywords: $
28  */
29
30 #include "stdafx.h"
31 #include "fred.h"
32 #include "shieldsysdlg.h"
33 #include "ship.h"
34 #include "missionparse.h"
35
36 #ifdef _DEBUG
37 #define new DEBUG_NEW
38 #undef THIS_FILE
39 static char THIS_FILE[] = __FILE__;
40 #endif
41
42 int Shield_sys_teams[MAX_TEAM_NAMES] = {0};
43 int Shield_sys_types[MAX_SHIP_TYPES] = {0};
44
45 /////////////////////////////////////////////////////////////////////////////
46 // shield_sys_dlg dialog
47
48 shield_sys_dlg::shield_sys_dlg(CWnd* pParent /*=NULL*/)
49         : CDialog(shield_sys_dlg::IDD, pParent)
50 {
51         //{{AFX_DATA_INIT(shield_sys_dlg)
52         m_team = 0;
53         m_type = 0;
54         //}}AFX_DATA_INIT
55 }
56
57 void shield_sys_dlg::DoDataExchange(CDataExchange* pDX)
58 {
59         CDialog::DoDataExchange(pDX);
60         //{{AFX_DATA_MAP(shield_sys_dlg)
61         DDX_CBIndex(pDX, IDC_TEAM, m_team);
62         DDX_CBIndex(pDX, IDC_TYPE, m_type);
63         //}}AFX_DATA_MAP
64 }
65
66 BEGIN_MESSAGE_MAP(shield_sys_dlg, CDialog)
67         //{{AFX_MSG_MAP(shield_sys_dlg)
68         ON_CBN_SELCHANGE(IDC_TEAM, OnSelchangeTeam)
69         ON_CBN_SELCHANGE(IDC_TYPE, OnSelchangeType)
70         //}}AFX_MSG_MAP
71 END_MESSAGE_MAP()
72
73 /////////////////////////////////////////////////////////////////////////////
74 // shield_sys_dlg message handlers
75
76 BOOL shield_sys_dlg::OnInitDialog() 
77 {
78         int i, z;
79         int teams[MAX_TEAM_NAMES];
80         int types[MAX_SHIP_TYPES];
81         CComboBox *box;
82
83         for (i=0; i<MAX_TEAM_NAMES; i++)
84                 teams[i] = 0;
85
86         for (i=0; i<MAX_SHIP_TYPES; i++)
87                 types[i] = 0;
88
89         for (i=0; i<MAX_SHIPS; i++)
90                 if (Ships[i].objnum >= 0) {
91                         z = (Objects[Ships[i].objnum].flags & OF_NO_SHIELDS) ? 1 : 0;
92                         if (!teams[Ships[i].team])
93                                 Shield_sys_teams[Ships[i].team] = z;
94                         else if (Shield_sys_teams[Ships[i].team] != z)
95                                 Shield_sys_teams[Ships[i].team] = 2;
96
97                         if (!types[Ships[i].ship_info_index])
98                                 Shield_sys_types[Ships[i].ship_info_index] = z;
99                         else if (Shield_sys_types[Ships[i].ship_info_index] != z)
100                                 Shield_sys_types[Ships[i].ship_info_index] = 2;
101
102                         teams[Ships[i].team]++;
103                         types[Ships[i].ship_info_index]++;
104                 }
105
106         box = (CComboBox *) GetDlgItem(IDC_TYPE);
107         box->ResetContent();
108         for (i=0; i<Num_ship_types; i++)
109                 box->AddString(Ship_info[i].name);
110
111         box = (CComboBox *) GetDlgItem(IDC_TEAM);
112         box->ResetContent();
113         for (i=0; i<Num_team_names; i++)
114                 box->AddString(Team_names[i]);
115
116         CDialog::OnInitDialog();
117         set_team();
118         set_type();
119         return TRUE;
120 }
121
122 void shield_sys_dlg::OnOK() 
123 {
124         int i, z;
125
126         OnSelchangeTeam();
127         OnSelchangeType();
128         for (i=0; i<MAX_SHIPS; i++)
129                 if (Ships[i].objnum >= 0) {
130                         z = Shield_sys_teams[Ships[i].team];
131                         if (!Shield_sys_types[Ships[i].ship_info_index])
132                                 z = 0;
133                         else if (Shield_sys_types[Ships[i].ship_info_index] == 1)
134                                 z = 1;
135
136                         if (!z)
137                                 Objects[Ships[i].objnum].flags &= ~OF_NO_SHIELDS;
138                         else if (z == 1)
139                                 Objects[Ships[i].objnum].flags |= OF_NO_SHIELDS;
140                 }
141
142         CDialog::OnOK();
143 }
144
145 void shield_sys_dlg::OnSelchangeTeam()
146 {
147         Assert(m_team >= 0);
148         if (((CButton *) GetDlgItem(IDC_TEAM_YES))->GetCheck())
149                 Shield_sys_teams[m_team] = 0;
150         else if (((CButton *) GetDlgItem(IDC_TEAM_NO))->GetCheck())
151                 Shield_sys_teams[m_team] = 1;
152
153         UpdateData(TRUE);
154         set_team();
155 }
156
157 void shield_sys_dlg::set_team()
158 {
159         if (!Shield_sys_teams[m_team])
160                 ((CButton *) GetDlgItem(IDC_TEAM_YES))->SetCheck(TRUE);
161         else
162                 ((CButton *) GetDlgItem(IDC_TEAM_YES))->SetCheck(FALSE);
163
164         if (Shield_sys_teams[m_team] == 1)
165                 ((CButton *) GetDlgItem(IDC_TEAM_NO))->SetCheck(TRUE);
166         else
167                 ((CButton *) GetDlgItem(IDC_TEAM_NO))->SetCheck(FALSE);
168 }
169
170 void shield_sys_dlg::OnSelchangeType()
171 {
172         Assert(m_type >= 0);
173         if (((CButton *) GetDlgItem(IDC_TYPE_YES))->GetCheck())
174                 Shield_sys_types[m_type] = 0;
175         else if (((CButton *) GetDlgItem(IDC_TYPE_NO))->GetCheck())
176                 Shield_sys_types[m_type] = 1;
177
178         UpdateData(TRUE);
179         set_type();
180 }
181
182 void shield_sys_dlg::set_type()
183 {
184         if (!Shield_sys_types[m_type])
185                 ((CButton *) GetDlgItem(IDC_TYPE_YES))->SetCheck(TRUE);
186         else
187                 ((CButton *) GetDlgItem(IDC_TYPE_YES))->SetCheck(FALSE);
188
189         if (Shield_sys_types[m_type] == 1)
190                 ((CButton *) GetDlgItem(IDC_TYPE_NO))->SetCheck(TRUE);
191         else
192                 ((CButton *) GetDlgItem(IDC_TYPE_NO))->SetCheck(FALSE);
193 }