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