2 * $Logfile: /Freespace2/code/FRED2/IgnoreOrdersDlg.cpp $
7 * C code for dialog to set which orders from the player that a particular ship should ignore
13 #include "ignoreordersdlg.h"
14 #include "hudsquadmsg.h" // need this for the menu stuff
20 static char THIS_FILE[] = __FILE__;
23 // super cool macro to make IDC_* names
25 // note: If you change this table at all, keep it in sync with version in HUDsquadmsg.cpp
26 fred_comm_order Fred_comm_orders[] = {
27 ATTACK_TARGET_ITEM, "Attack my target",
28 DISABLE_TARGET_ITEM, "Disable my target",
29 DISARM_TARGET_ITEM, "Disarm my target",
30 DISABLE_SUBSYSTEM_ITEM, "Destroy my subsystem",
31 PROTECT_TARGET_ITEM, "Protect my target",
32 IGNORE_TARGET_ITEM, "Ignore my target",
33 FORMATION_ITEM, "Form on my wing",
34 COVER_ME_ITEM, "Cover me",
35 ENGAGE_ENEMY_ITEM, "Engage enemy",
36 CAPTURE_TARGET_ITEM, "Capture my target",
37 REARM_REPAIR_ME_ITEM, "Rearm/repair me",
38 ABORT_REARM_REPAIR_ITEM, "Abort rearm repair",
39 DEPART_ITEM, "Depart",
42 int Fred_comm_orders_max = sizeof(Fred_comm_orders)/sizeof(fred_comm_order);
44 /////////////////////////////////////////////////////////////////////////////
45 // ignore_orders_dlg dialog
47 ignore_orders_dlg::ignore_orders_dlg(CWnd* pParent /*=NULL*/)
48 : CDialog(ignore_orders_dlg::IDD, pParent)
50 //{{AFX_DATA_INIT(ignore_orders_dlg)
51 // NOTE: the ClassWizard will add member initialization here
55 void ignore_orders_dlg::DoDataExchange(CDataExchange* pDX)
57 CDialog::DoDataExchange(pDX);
58 //{{AFX_DATA_MAP(ignore_orders_dlg)
59 // NOTE: the ClassWizard will add DDX and DDV calls here
64 BEGIN_MESSAGE_MAP(ignore_orders_dlg, CDialog)
65 //{{AFX_MSG_MAP(ignore_orders_dlg)
66 ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
67 ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
68 ON_BN_CLICKED(IDC_CHECK3, OnCheck3)
69 ON_BN_CLICKED(IDC_CHECK4, OnCheck4)
70 ON_BN_CLICKED(IDC_CHECK5, OnCheck5)
71 ON_BN_CLICKED(IDC_CHECK6, OnCheck6)
72 ON_BN_CLICKED(IDC_CHECK7, OnCheck7)
73 ON_BN_CLICKED(IDC_CHECK8, OnCheck8)
74 ON_BN_CLICKED(IDC_CHECK9, OnCheck9)
75 ON_BN_CLICKED(IDC_CHECK10, OnCheck10)
79 /////////////////////////////////////////////////////////////////////////////
80 // ignore_orders_dlg message handlers
82 BOOL ignore_orders_dlg::OnInitDialog()
84 int i, default_orders, last_bottom, orders_accepted;
89 CDialog::OnInitDialog();
91 check_boxes[0].button = (CButton *)GetDlgItem( IDC_CHECK1 );
92 check_boxes[1].button = (CButton *)GetDlgItem( IDC_CHECK2 );
93 check_boxes[2].button = (CButton *)GetDlgItem( IDC_CHECK3 );
94 check_boxes[3].button = (CButton *)GetDlgItem( IDC_CHECK4 );
95 check_boxes[4].button = (CButton *)GetDlgItem( IDC_CHECK5 );
96 check_boxes[5].button = (CButton *)GetDlgItem( IDC_CHECK6 );
97 check_boxes[6].button = (CButton *)GetDlgItem( IDC_CHECK7 );
98 check_boxes[7].button = (CButton *)GetDlgItem( IDC_CHECK8 );
99 check_boxes[8].button = (CButton *)GetDlgItem( IDC_CHECK9 );
100 check_boxes[9].button = (CButton *)GetDlgItem( IDC_CHECK10 );
102 // change the labels on the check boxes to reflect the set of default
103 // orders for this ship
105 default_orders = ship_get_default_orders_accepted( &Ship_info[Ships[m_ship].ship_info_index] );
107 // we are doing multiple edit on ships. We just need to get default orders for
108 // the first marked ship since they'd better all be the same anyway!!!
110 for ( objp = GET_FIRST(&obj_used_list); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
111 if (((objp->type == OBJ_SHIP) || (objp->type == OBJ_START)) && (objp->flags & OF_MARKED)) {
114 these_orders = ship_get_default_orders_accepted( &Ship_info[Ships[objp->instance].ship_info_index] );
115 if ( default_orders == 0 )
116 default_orders = these_orders;
117 else if ( default_orders != these_orders )
124 // set the checkboxes for the orders accepted
125 m_num_checks_active = 0;
126 for (i = 0; i < MAX_SHIP_ORDERS; i++ ) {
127 if ( default_orders & Fred_comm_orders[i].value ) {
128 Assert( m_num_checks_active < MAX_CHECKBOXES );
129 check_boxes[m_num_checks_active].button->SetWindowText( Fred_comm_orders[i].menu_text );
130 check_boxes[m_num_checks_active].id = Fred_comm_orders[i].value;
131 m_num_checks_active++;
135 // resize the dialog by shrinking the height by the number of checkboxes that
137 GetWindowRect( &window_size );
139 // hide the rest of the dialog items
141 for ( i = MAX_CHECKBOXES - 1; i >= m_num_checks_active; i-- ) {
144 // get the size of the checkbox, then hide it.
145 check_boxes[i].button->GetWindowRect( &check_size );
146 check_boxes[i].button->ShowWindow(SW_HIDE);
148 // shrink the size of the parent window by the size of the checkbox
149 if ( last_bottom != 0 )
150 window_size.bottom -= (last_bottom - check_size.bottom );
152 last_bottom = check_size.bottom;
156 // call MoveWindow to resize the window
157 MoveWindow( &window_size, TRUE );
159 // set the check marks in the box based on orders_accepted valud in the ship structure(s)
161 orders_accepted = Ships[m_ship].orders_accepted;
162 for ( i = 0; i < m_num_checks_active; i++ ) {
163 if ( check_boxes[i].id & orders_accepted )
164 check_boxes[i].button->SetCheck(1);
170 for ( objp = GET_FIRST(&obj_used_list); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
171 if (((objp->type == OBJ_START) || (objp->type == OBJ_SHIP)) && (objp->flags & OF_MARKED)) {
173 // get the orders for this ship. If a state is not set
174 orders_accepted = Ships[objp->instance].orders_accepted;
176 for ( i = 0; i < m_num_checks_active; i++ ) {
177 if ( check_boxes[i].id & orders_accepted )
178 check_boxes[i].button->SetCheck(1);
182 for ( i = 0; i < m_num_checks_active; i++ ) {
183 // see if the order matches the check box order
184 if ( check_boxes[i].id & orders_accepted ) {
185 // if it matches, if it is not already set, then it is indeterminate.
186 if ( !check_boxes[i].button->GetCheck() )
187 check_boxes[i].button->SetCheck(2);
189 // if the order isn't active, and already set, mark as indeterminite.
190 if ( check_boxes[i].button->GetCheck() )
191 check_boxes[i].button->SetCheck(2);
199 // finally, set the title of the window to be something else. We really aren't checking orders
200 // which will be ignore, but rather orders which will be accepted
201 sprintf(buf, "Player orders accepted" );
204 return TRUE; // return TRUE unless you set the focus to a control
205 // EXCEPTION: OCX Property Pages should return FALSE
208 // for the OnOK function, we scan through the list of checkboxes, and reset the ship's orders accepted
209 // variable based on the state of the checkboxes
210 void ignore_orders_dlg::OnOK()
212 int orders_accepted, i;
215 // clear out the orders, then set the bits according to which check boxes are set
218 for ( i = 0; i < m_num_checks_active; i++ ) {
219 if ( check_boxes[i].button->GetCheck() )
220 orders_accepted |= check_boxes[i].id;
222 Ships[m_ship].orders_accepted = orders_accepted;
224 for ( objp = GET_FIRST(&obj_used_list); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
225 if (((objp->type == OBJ_SHIP) || (objp->type == OBJ_START)) && (objp->flags & OF_MARKED)) {
226 Ships[objp->instance].orders_accepted = 0;
227 for ( i = 0; i < m_num_checks_active; i++ ) {
230 box_value = check_boxes[i].button->GetCheck();
231 // get the status of the checkbox -- if in the indeterminite state, then
233 if ( box_value == 2 )
236 // if the button is set, then set the bit, otherwise, clear the bit
237 if ( box_value == 1 )
238 Ships[objp->instance].orders_accepted |= check_boxes[i].id;
240 Ships[objp->instance].orders_accepted &= ~(check_boxes[i].id);
249 // stupid routines to deal with the tri-state values of the checkboxes
250 void ignore_orders_dlg::OnCheck1()
254 button = (CButton *)GetDlgItem(IDC_CHECK1);
255 if (button->GetCheck() == 1)
261 void ignore_orders_dlg::OnCheck2()
265 button = (CButton *)GetDlgItem(IDC_CHECK2);
266 if (button->GetCheck() == 1)
272 void ignore_orders_dlg::OnCheck3()
276 button = (CButton *)GetDlgItem(IDC_CHECK3);
277 if (button->GetCheck() == 1)
283 void ignore_orders_dlg::OnCheck4()
287 button = (CButton *)GetDlgItem(IDC_CHECK4);
288 if (button->GetCheck() == 1)
294 void ignore_orders_dlg::OnCheck5()
298 button = (CButton *)GetDlgItem(IDC_CHECK5);
299 if (button->GetCheck() == 1)
305 void ignore_orders_dlg::OnCheck6()
309 button = (CButton *)GetDlgItem(IDC_CHECK6);
310 if (button->GetCheck() == 1)
316 void ignore_orders_dlg::OnCheck7()
320 button = (CButton *)GetDlgItem(IDC_CHECK7);
321 if (button->GetCheck() == 1)
327 void ignore_orders_dlg::OnCheck8()
331 button = (CButton *)GetDlgItem(IDC_CHECK8);
332 if (button->GetCheck() == 1)
338 void ignore_orders_dlg::OnCheck9()
342 button = (CButton *)GetDlgItem(IDC_CHECK9);
343 if (button->GetCheck() == 1)
349 void ignore_orders_dlg::OnCheck10()
353 button = (CButton *)GetDlgItem(IDC_CHECK10);
354 if (button->GetCheck() == 1)