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