2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
10 * $Logfile: /Freespace2/code/FRED2/IgnoreOrdersDlg.cpp $
15 * C code for dialog to set which orders from the player that a particular ship should ignore
21 #include "ignoreordersdlg.h"
22 #include "hudsquadmsg.h" // need this for the menu stuff
28 static char THIS_FILE[] = __FILE__;
31 // super cool macro to make IDC_* names
33 // note: If you change this table at all, keep it in sync with version in HUDsquadmsg.cpp
34 fred_comm_order Fred_comm_orders[] = {
35 ATTACK_TARGET_ITEM, "Attack my target",
36 DISABLE_TARGET_ITEM, "Disable my target",
37 DISARM_TARGET_ITEM, "Disarm my target",
38 DISABLE_SUBSYSTEM_ITEM, "Destroy my subsystem",
39 PROTECT_TARGET_ITEM, "Protect my target",
40 IGNORE_TARGET_ITEM, "Ignore my target",
41 FORMATION_ITEM, "Form on my wing",
42 COVER_ME_ITEM, "Cover me",
43 ENGAGE_ENEMY_ITEM, "Engage enemy",
44 CAPTURE_TARGET_ITEM, "Capture my target",
45 REARM_REPAIR_ME_ITEM, "Rearm/repair me",
46 ABORT_REARM_REPAIR_ITEM, "Abort rearm repair",
47 DEPART_ITEM, "Depart",
50 int Fred_comm_orders_max = sizeof(Fred_comm_orders)/sizeof(fred_comm_order);
52 /////////////////////////////////////////////////////////////////////////////
53 // ignore_orders_dlg dialog
55 ignore_orders_dlg::ignore_orders_dlg(CWnd* pParent /*=NULL*/)
56 : CDialog(ignore_orders_dlg::IDD, pParent)
58 //{{AFX_DATA_INIT(ignore_orders_dlg)
59 // NOTE: the ClassWizard will add member initialization here
63 void ignore_orders_dlg::DoDataExchange(CDataExchange* pDX)
65 CDialog::DoDataExchange(pDX);
66 //{{AFX_DATA_MAP(ignore_orders_dlg)
67 // NOTE: the ClassWizard will add DDX and DDV calls here
72 BEGIN_MESSAGE_MAP(ignore_orders_dlg, CDialog)
73 //{{AFX_MSG_MAP(ignore_orders_dlg)
74 ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
75 ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
76 ON_BN_CLICKED(IDC_CHECK3, OnCheck3)
77 ON_BN_CLICKED(IDC_CHECK4, OnCheck4)
78 ON_BN_CLICKED(IDC_CHECK5, OnCheck5)
79 ON_BN_CLICKED(IDC_CHECK6, OnCheck6)
80 ON_BN_CLICKED(IDC_CHECK7, OnCheck7)
81 ON_BN_CLICKED(IDC_CHECK8, OnCheck8)
82 ON_BN_CLICKED(IDC_CHECK9, OnCheck9)
83 ON_BN_CLICKED(IDC_CHECK10, OnCheck10)
87 /////////////////////////////////////////////////////////////////////////////
88 // ignore_orders_dlg message handlers
90 BOOL ignore_orders_dlg::OnInitDialog()
92 int i, default_orders, last_bottom, orders_accepted;
97 CDialog::OnInitDialog();
99 check_boxes[0].button = (CButton *)GetDlgItem( IDC_CHECK1 );
100 check_boxes[1].button = (CButton *)GetDlgItem( IDC_CHECK2 );
101 check_boxes[2].button = (CButton *)GetDlgItem( IDC_CHECK3 );
102 check_boxes[3].button = (CButton *)GetDlgItem( IDC_CHECK4 );
103 check_boxes[4].button = (CButton *)GetDlgItem( IDC_CHECK5 );
104 check_boxes[5].button = (CButton *)GetDlgItem( IDC_CHECK6 );
105 check_boxes[6].button = (CButton *)GetDlgItem( IDC_CHECK7 );
106 check_boxes[7].button = (CButton *)GetDlgItem( IDC_CHECK8 );
107 check_boxes[8].button = (CButton *)GetDlgItem( IDC_CHECK9 );
108 check_boxes[9].button = (CButton *)GetDlgItem( IDC_CHECK10 );
110 // change the labels on the check boxes to reflect the set of default
111 // orders for this ship
113 default_orders = ship_get_default_orders_accepted( &Ship_info[Ships[m_ship].ship_info_index] );
115 // we are doing multiple edit on ships. We just need to get default orders for
116 // the first marked ship since they'd better all be the same anyway!!!
118 for ( objp = GET_FIRST(&obj_used_list); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
119 if (((objp->type == OBJ_SHIP) || (objp->type == OBJ_START)) && (objp->flags & OF_MARKED)) {
122 these_orders = ship_get_default_orders_accepted( &Ship_info[Ships[objp->instance].ship_info_index] );
123 if ( default_orders == 0 )
124 default_orders = these_orders;
125 else if ( default_orders != these_orders )
132 // set the checkboxes for the orders accepted
133 m_num_checks_active = 0;
134 for (i = 0; i < MAX_SHIP_ORDERS; i++ ) {
135 if ( default_orders & Fred_comm_orders[i].value ) {
136 SDL_assert( m_num_checks_active < MAX_CHECKBOXES );
137 check_boxes[m_num_checks_active].button->SetWindowText( Fred_comm_orders[i].menu_text );
138 check_boxes[m_num_checks_active].id = Fred_comm_orders[i].value;
139 m_num_checks_active++;
143 // resize the dialog by shrinking the height by the number of checkboxes that
145 GetWindowRect( &window_size );
147 // hide the rest of the dialog items
149 for ( i = MAX_CHECKBOXES - 1; i >= m_num_checks_active; i-- ) {
152 // get the size of the checkbox, then hide it.
153 check_boxes[i].button->GetWindowRect( &check_size );
154 check_boxes[i].button->ShowWindow(SW_HIDE);
156 // shrink the size of the parent window by the size of the checkbox
157 if ( last_bottom != 0 )
158 window_size.bottom -= (last_bottom - check_size.bottom );
160 last_bottom = check_size.bottom;
164 // call MoveWindow to resize the window
165 MoveWindow( &window_size, TRUE );
167 // set the check marks in the box based on orders_accepted valud in the ship structure(s)
169 orders_accepted = Ships[m_ship].orders_accepted;
170 for ( i = 0; i < m_num_checks_active; i++ ) {
171 if ( check_boxes[i].id & orders_accepted )
172 check_boxes[i].button->SetCheck(1);
178 for ( objp = GET_FIRST(&obj_used_list); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
179 if (((objp->type == OBJ_START) || (objp->type == OBJ_SHIP)) && (objp->flags & OF_MARKED)) {
181 // get the orders for this ship. If a state is not set
182 orders_accepted = Ships[objp->instance].orders_accepted;
184 for ( i = 0; i < m_num_checks_active; i++ ) {
185 if ( check_boxes[i].id & orders_accepted )
186 check_boxes[i].button->SetCheck(1);
190 for ( i = 0; i < m_num_checks_active; i++ ) {
191 // see if the order matches the check box order
192 if ( check_boxes[i].id & orders_accepted ) {
193 // if it matches, if it is not already set, then it is indeterminate.
194 if ( !check_boxes[i].button->GetCheck() )
195 check_boxes[i].button->SetCheck(2);
197 // if the order isn't active, and already set, mark as indeterminite.
198 if ( check_boxes[i].button->GetCheck() )
199 check_boxes[i].button->SetCheck(2);
207 // finally, set the title of the window to be something else. We really aren't checking orders
208 // which will be ignore, but rather orders which will be accepted
209 sprintf(buf, "Player orders accepted" );
212 return TRUE; // return TRUE unless you set the focus to a control
213 // EXCEPTION: OCX Property Pages should return FALSE
216 // for the OnOK function, we scan through the list of checkboxes, and reset the ship's orders accepted
217 // variable based on the state of the checkboxes
218 void ignore_orders_dlg::OnOK()
220 int orders_accepted, i;
223 // clear out the orders, then set the bits according to which check boxes are set
226 for ( i = 0; i < m_num_checks_active; i++ ) {
227 if ( check_boxes[i].button->GetCheck() )
228 orders_accepted |= check_boxes[i].id;
230 Ships[m_ship].orders_accepted = orders_accepted;
232 for ( objp = GET_FIRST(&obj_used_list); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
233 if (((objp->type == OBJ_SHIP) || (objp->type == OBJ_START)) && (objp->flags & OF_MARKED)) {
234 Ships[objp->instance].orders_accepted = 0;
235 for ( i = 0; i < m_num_checks_active; i++ ) {
238 box_value = check_boxes[i].button->GetCheck();
239 // get the status of the checkbox -- if in the indeterminite state, then
241 if ( box_value == 2 )
244 // if the button is set, then set the bit, otherwise, clear the bit
245 if ( box_value == 1 )
246 Ships[objp->instance].orders_accepted |= check_boxes[i].id;
248 Ships[objp->instance].orders_accepted &= ~(check_boxes[i].id);
257 // stupid routines to deal with the tri-state values of the checkboxes
258 void ignore_orders_dlg::OnCheck1()
262 button = (CButton *)GetDlgItem(IDC_CHECK1);
263 if (button->GetCheck() == 1)
269 void ignore_orders_dlg::OnCheck2()
273 button = (CButton *)GetDlgItem(IDC_CHECK2);
274 if (button->GetCheck() == 1)
280 void ignore_orders_dlg::OnCheck3()
284 button = (CButton *)GetDlgItem(IDC_CHECK3);
285 if (button->GetCheck() == 1)
291 void ignore_orders_dlg::OnCheck4()
295 button = (CButton *)GetDlgItem(IDC_CHECK4);
296 if (button->GetCheck() == 1)
302 void ignore_orders_dlg::OnCheck5()
306 button = (CButton *)GetDlgItem(IDC_CHECK5);
307 if (button->GetCheck() == 1)
313 void ignore_orders_dlg::OnCheck6()
317 button = (CButton *)GetDlgItem(IDC_CHECK6);
318 if (button->GetCheck() == 1)
324 void ignore_orders_dlg::OnCheck7()
328 button = (CButton *)GetDlgItem(IDC_CHECK7);
329 if (button->GetCheck() == 1)
335 void ignore_orders_dlg::OnCheck8()
339 button = (CButton *)GetDlgItem(IDC_CHECK8);
340 if (button->GetCheck() == 1)
346 void ignore_orders_dlg::OnCheck9()
350 button = (CButton *)GetDlgItem(IDC_CHECK9);
351 if (button->GetCheck() == 1)
357 void ignore_orders_dlg::OnCheck10()
361 button = (CButton *)GetDlgItem(IDC_CHECK10);
362 if (button->GetCheck() == 1)