|
| 1 | +// reorderdlg.cpp : implementation file |
| 2 | +// |
| 3 | + |
| 4 | +#include "stdafx.h" |
| 5 | +#include "FRED.h" |
| 6 | +#include "freddoc.h" |
| 7 | +#include "management.h" |
| 8 | +#include "reorderdlg.h" |
| 9 | + |
| 10 | +#include "missioneditor/common.h" |
| 11 | +#include "ship/ship.h" |
| 12 | + |
| 13 | +#ifdef _DEBUG |
| 14 | +#undef THIS_FILE |
| 15 | +static char THIS_FILE[] = __FILE__; |
| 16 | +#endif |
| 17 | + |
| 18 | +reorder_dlg::reorder_dlg(CWnd *pParent /*=nullptr*/) |
| 19 | + : CDialog(reorder_dlg::IDD, pParent) |
| 20 | +{ |
| 21 | + //{{AFX_DATA_INIT(reorder_dlg) |
| 22 | + //}}AFX_DATA_INIT |
| 23 | +} |
| 24 | + |
| 25 | +void reorder_dlg::DoDataExchange(CDataExchange *pDX) |
| 26 | +{ |
| 27 | + CDialog::DoDataExchange(pDX); |
| 28 | + //{{AFX_DATA_MAP(reorder_dlg) |
| 29 | + DDX_Control(pDX, IDC_REORDER_TYPE, m_type_combo); |
| 30 | + DDX_Control(pDX, IDC_REORDER_LIST, m_list); |
| 31 | + //}}AFX_DATA_MAP |
| 32 | +} |
| 33 | + |
| 34 | +BEGIN_MESSAGE_MAP(reorder_dlg, CDialog) |
| 35 | + //{{AFX_MSG_MAP(reorder_dlg) |
| 36 | + ON_CBN_SELCHANGE(IDC_REORDER_TYPE, OnSelchangeReorderType) |
| 37 | + ON_LBN_SELCHANGE(IDC_REORDER_LIST, OnSelchangeReorderList) |
| 38 | + ON_BN_CLICKED(IDC_REORDER_MOVE_TO_TOP, OnMoveToTop) |
| 39 | + ON_BN_CLICKED(IDC_REORDER_MOVE_UP, OnMoveUp) |
| 40 | + ON_BN_CLICKED(IDC_REORDER_MOVE_DOWN, OnMoveDown) |
| 41 | + ON_BN_CLICKED(IDC_REORDER_MOVE_TO_BOTTOM, OnMoveToBottom) |
| 42 | + //}}AFX_MSG_MAP |
| 43 | +END_MESSAGE_MAP() |
| 44 | + |
| 45 | +BOOL reorder_dlg::OnInitDialog() |
| 46 | +{ |
| 47 | + CDialog::OnInitDialog(); |
| 48 | + |
| 49 | + m_type_combo.AddString("Ships"); |
| 50 | + m_type_combo.AddString("Wings"); |
| 51 | + m_type_combo.SetCurSel(0); |
| 52 | + |
| 53 | + populate_list(); |
| 54 | + update_buttons(); |
| 55 | + |
| 56 | + return TRUE; |
| 57 | +} |
| 58 | + |
| 59 | +bool reorder_dlg::ships_selected() const |
| 60 | +{ |
| 61 | + return m_type_combo.GetCurSel() == 0; |
| 62 | +} |
| 63 | + |
| 64 | +void reorder_dlg::populate_list() |
| 65 | +{ |
| 66 | + m_list.ResetContent(); |
| 67 | + m_slots.clear(); |
| 68 | + |
| 69 | + if (ships_selected()) |
| 70 | + { |
| 71 | + for (int i = 0; i < MAX_SHIPS; ++i) |
| 72 | + { |
| 73 | + if (Ships[i].objnum >= 0) |
| 74 | + { |
| 75 | + m_list.AddString(Ships[i].ship_name); |
| 76 | + m_slots.push_back(i); |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + else |
| 81 | + { |
| 82 | + for (int i = 0; i < MAX_WINGS; ++i) |
| 83 | + { |
| 84 | + if (Wings[i].wave_count > 0) |
| 85 | + { |
| 86 | + m_list.AddString(Wings[i].name); |
| 87 | + m_slots.push_back(i); |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +void reorder_dlg::update_buttons() |
| 94 | +{ |
| 95 | + int pos = m_list.GetCurSel(); |
| 96 | + int count = (int)m_slots.size(); |
| 97 | + bool can_move_up = (pos > 0); |
| 98 | + bool can_move_down = (pos >= 0 && pos < count - 1); |
| 99 | + |
| 100 | + GetDlgItem(IDC_REORDER_MOVE_TO_TOP)->EnableWindow(can_move_up); |
| 101 | + GetDlgItem(IDC_REORDER_MOVE_UP)->EnableWindow(can_move_up); |
| 102 | + GetDlgItem(IDC_REORDER_MOVE_DOWN)->EnableWindow(can_move_down); |
| 103 | + GetDlgItem(IDC_REORDER_MOVE_TO_BOTTOM)->EnableWindow(can_move_down); |
| 104 | +} |
| 105 | + |
| 106 | +void reorder_dlg::move_selected(bool up, bool all_the_way) |
| 107 | +{ |
| 108 | + int pos = m_list.GetCurSel(); |
| 109 | + int count = (int)m_slots.size(); |
| 110 | + if (pos < 0 || pos >= count) |
| 111 | + return; |
| 112 | + |
| 113 | + int target; |
| 114 | + if (up) |
| 115 | + target = all_the_way ? 0 : pos - 1; |
| 116 | + else |
| 117 | + target = all_the_way ? count - 1 : pos + 1; |
| 118 | + |
| 119 | + if (target < 0 || target >= count || target == pos) |
| 120 | + return; |
| 121 | + |
| 122 | + // Rotate the item to the target position, which preserves the relative |
| 123 | + // order of everything else in the list. |
| 124 | + if (ships_selected()) |
| 125 | + { |
| 126 | + FredShipSlotConfig cfg; |
| 127 | + cfg.fred_alt_names = Fred_alt_names; |
| 128 | + cfg.fred_callsigns = Fred_callsigns; |
| 129 | + cfg.cur_ship = &cur_ship; |
| 130 | + rotate_ship_slots(m_slots, pos, target, cfg); |
| 131 | + } |
| 132 | + else |
| 133 | + { |
| 134 | + FredWingSlotConfig cfg; |
| 135 | + cfg.wing_objects = wing_objects; |
| 136 | + cfg.cur_wing = &cur_wing; |
| 137 | + rotate_wing_slots(m_slots, pos, target, cfg); |
| 138 | + } |
| 139 | + |
| 140 | + set_modified(); |
| 141 | + |
| 142 | + populate_list(); |
| 143 | + m_list.SetCurSel(target); |
| 144 | + update_buttons(); |
| 145 | +} |
| 146 | + |
| 147 | +void reorder_dlg::OnSelchangeReorderType() |
| 148 | +{ |
| 149 | + populate_list(); |
| 150 | + update_buttons(); |
| 151 | +} |
| 152 | + |
| 153 | +void reorder_dlg::OnSelchangeReorderList() |
| 154 | +{ |
| 155 | + update_buttons(); |
| 156 | +} |
| 157 | + |
| 158 | +void reorder_dlg::OnMoveToTop() |
| 159 | +{ |
| 160 | + move_selected(true, true); |
| 161 | +} |
| 162 | + |
| 163 | +void reorder_dlg::OnMoveUp() |
| 164 | +{ |
| 165 | + move_selected(true, false); |
| 166 | +} |
| 167 | + |
| 168 | +void reorder_dlg::OnMoveDown() |
| 169 | +{ |
| 170 | + move_selected(false, false); |
| 171 | +} |
| 172 | + |
| 173 | +void reorder_dlg::OnMoveToBottom() |
| 174 | +{ |
| 175 | + move_selected(false, true); |
| 176 | +} |
0 commit comments