Skip to content

Commit 78b2b93

Browse files
Goober5000claude
andcommitted
add a Reorder Ships and Wings editor to FRED
Accessible from the Tools menu, this dialog lists all ships or all wings (selectable via a drop-down) and provides Move to top/up/down/ bottom buttons. Moves are applied immediately via the slot reassignment utilities in missioneditor/common.h, using adjacent swaps so the relative order of other entries is preserved. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 4951673 commit 78b2b93

7 files changed

Lines changed: 270 additions & 11 deletions

File tree

fred2/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ set(FRED2_SOURCES
105105
propdlg.h
106106
reinforcementeditordlg.cpp
107107
reinforcementeditordlg.h
108+
reorderdlg.cpp
109+
reorderdlg.h
108110
resource.h
109111
restrictpaths.cpp
110112
restrictpaths.h

fred2/fred.rc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ BEGIN
404404
BEGIN
405405
MENUITEM "&Voice Acting Manager", ID_EDITORS_VOICE
406406
MENUITEM "Set Global Ship Flags", 33073
407+
MENUITEM "Reorder Ships and Wings", ID_REORDER
407408
MENUITEM "Calculate Relative Coordinates", 33030
408409
MENUITEM "Music Player", ID_MUSIC_PLAYER
409410
MENUITEM "Mission Statistics\tCtrl+Shift+D", 33067
@@ -2030,6 +2031,19 @@ BEGIN
20302031
EDITTEXT IDC_ORIENTATION_H,255,81,49,14,ES_READONLY
20312032
END
20322033

2034+
IDD_REORDER DIALOG 0, 0, 185, 191
2035+
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
2036+
CAPTION "Reorder Ships and Wings"
2037+
FONT 8, "MS Sans Serif"
2038+
BEGIN
2039+
COMBOBOX IDC_REORDER_TYPE,7,7,98,114,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
2040+
LISTBOX IDC_REORDER_LIST,7,25,98,159,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
2041+
PUSHBUTTON "Move to top",IDC_REORDER_MOVE_TO_TOP,112,25,66,14
2042+
PUSHBUTTON "Move up",IDC_REORDER_MOVE_UP,112,43,66,14
2043+
PUSHBUTTON "Move down",IDC_REORDER_MOVE_DOWN,112,61,66,14
2044+
PUSHBUTTON "Move to bottom",IDC_REORDER_MOVE_TO_BOTTOM,112,79,66,14
2045+
END
2046+
20332047
IDD_SHIELD_SYS DIALOG 0, 0, 192, 106
20342048
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
20352049
CAPTION "Shield System Editor"
@@ -2929,6 +2943,14 @@ BEGIN
29292943
BOTTOMMARGIN, 87
29302944
END
29312945

2946+
IDD_REORDER, DIALOG
2947+
BEGIN
2948+
LEFTMARGIN, 7
2949+
RIGHTMARGIN, 178
2950+
TOPMARGIN, 7
2951+
BOTTOMMARGIN, 184
2952+
END
2953+
29322954
IDD_SHIELD_SYS, DIALOG
29332955
BEGIN
29342956
LEFTMARGIN, 7
@@ -3791,6 +3813,7 @@ END
37913813
STRINGTABLE
37923814
BEGIN
37933815
ID_CALC_RELATIVE_COORDS "Calculate orientation and distance relative to an origin object"
3816+
ID_REORDER "Change the order in which ships and wings are stored in the mission"
37943817
ID_EDITORS_ADJUST_GRID "Adjust the orientation and level of the grid"
37953818
ID_EDITORS_SHIELD_SYS "Editor for availability of shield system for ships"
37963819
ID_ALIGN_OBJ "Align object (or camera if no objects are marked) X/Y/Z axes with the global axes that are closest"

fred2/fredview.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include "sound/audiostr.h"
6262
#include "mission/missiongrid.h"
6363
#include "calcrelativecoordsdlg.h"
64+
#include "reorderdlg.h"
6465
#include "musicplayerdlg.h"
6566
#include "volumetricsdlg.h"
6667
#include "customdatadlg.h"
@@ -341,6 +342,7 @@ BEGIN_MESSAGE_MAP(CFREDView, CView)
341342
ON_UPDATE_COMMAND_UI(ID_LOOKAT_OBJ, OnUpdateLookatObj)
342343
ON_COMMAND(ID_EDITORS_ADJUST_GRID, OnEditorsAdjustGrid)
343344
ON_COMMAND(ID_CALC_RELATIVE_COORDS, OnCalcRelativeCoords)
345+
ON_COMMAND(ID_REORDER, OnReorder)
344346
ON_COMMAND(ID_MUSIC_PLAYER, OnMusicPlayer)
345347
ON_COMMAND(ID_EDITORS_SHIELD_SYS, OnEditorsShieldSys)
346348
ON_COMMAND(ID_LEVEL_OBJ, OnLevelObj)
@@ -4474,6 +4476,13 @@ void CFREDView::OnCalcRelativeCoords()
44744476
dlg.DoModal();
44754477
}
44764478

4479+
void CFREDView::OnReorder()
4480+
{
4481+
reorder_dlg dlg;
4482+
4483+
dlg.DoModal();
4484+
}
4485+
44774486
void CFREDView::OnMusicPlayer()
44784487
{
44794488
Assertion(Music_player_dialog.GetSafeHwnd(), "Unable to create music player window!");

fred2/fredview.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ class CFREDView : public CView
301301
afx_msg void OnUpdateLookatObj(CCmdUI* pCmdUI);
302302
afx_msg void OnEditorsAdjustGrid();
303303
afx_msg void OnCalcRelativeCoords();
304+
afx_msg void OnReorder();
304305
afx_msg void OnMusicPlayer();
305306
afx_msg void OnEditorsShieldSys();
306307
afx_msg void OnLevelObj();

fred2/reorderdlg.cpp

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
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+
}

fred2/reorderdlg.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// reorderdlg.h : header file
2+
3+
#ifndef _REORDERDLG_H
4+
#define _REORDERDLG_H
5+
6+
class reorder_dlg : public CDialog
7+
{
8+
public:
9+
reorder_dlg(CWnd *pParent = nullptr);
10+
11+
// Dialog Data
12+
//{{AFX_DATA(reorder_dlg)
13+
enum { IDD = IDD_REORDER };
14+
CComboBox m_type_combo;
15+
CListBox m_list;
16+
//}}AFX_DATA
17+
18+
protected:
19+
virtual void DoDataExchange(CDataExchange *pDX); // DDX/DDV support
20+
21+
//{{AFX_MSG(reorder_dlg)
22+
virtual BOOL OnInitDialog();
23+
afx_msg void OnSelchangeReorderType();
24+
afx_msg void OnSelchangeReorderList();
25+
afx_msg void OnMoveToTop();
26+
afx_msg void OnMoveUp();
27+
afx_msg void OnMoveDown();
28+
afx_msg void OnMoveToBottom();
29+
//}}AFX_MSG
30+
DECLARE_MESSAGE_MAP()
31+
32+
bool ships_selected() const;
33+
void populate_list();
34+
void update_buttons();
35+
void move_selected(bool up, bool all_the_way);
36+
37+
// occupied Ships[] or Wings[] slot indexes, in list order
38+
SCP_vector<int> m_slots;
39+
};
40+
#endif // _REORDERDLG_H

fred2/resource.h

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
#define IDD_VOLUMETRICS 332
139139
#define IDD_EDIT_CUSTOM_STRINGS 333
140140
#define IDD_SUPPORT_REARM_OPTIONS 334
141+
#define IDD_REORDER 335
141142
#define IDC_SHIP_CLASS 1003
142143
#define IDC_SHIP_WING 1004
143144
#define IDC_SOUND_CLIP_NAME 1007
@@ -1290,6 +1291,12 @@
12901291
#define IDC_SUPPORT_REARM_SET_ALL_UNLIMITED 1729
12911292
#define IDC_SUPPORT_REARM_SET_ALL_ZERO 1730
12921293
#define IDC_SUPPORT_REARM_POOL_TEAM 1731
1294+
#define IDC_REORDER_TYPE 1732
1295+
#define IDC_REORDER_LIST 1733
1296+
#define IDC_REORDER_MOVE_TO_TOP 1734
1297+
#define IDC_REORDER_MOVE_UP 1735
1298+
#define IDC_REORDER_MOVE_DOWN 1736
1299+
#define IDC_REORDER_MOVE_TO_BOTTOM 1737
12931300
#define IDC_SEXP_POPUP_LIST 32770
12941301
#define ID_FILE_MISSIONNOTES 32771
12951302
#define ID_DUPLICATE 32774
@@ -1471,14 +1478,6 @@
14711478
#define ID_EDITORS_WAYPOINT 32979
14721479
#define ID_VIEW_OUTLINES 32980
14731480
#define ID_NEW_SHIP_TYPE 32981
1474-
#define ID_NEW_PROP_TYPE 33104
1475-
#define ID_STATIC_SHIP_LABEL 33105
1476-
#define ID_STATIC_PROP_LABEL 33106
1477-
#define ID_OUTLINE_LOD_0 33107
1478-
#define ID_OUTLINE_LOD_1 33108
1479-
#define ID_OUTLINE_LOD_2 33109
1480-
#define ID_OUTLINE_LOD_3 33110
1481-
#define ID_OUTLINE_LOD_4 33111
14821481
#define ID_VIEW_OUTLINES_ON_SELECTED 32982
14831482
#define ID_SHOW_STARFIELD 32983
14841483
#define ID_ASTEROID_EDITOR 32984
@@ -1593,6 +1592,15 @@
15931592
#define ID_MISC_POINTUSINGUVEC 33101
15941593
#define ID_MUSIC_PLAYER 33102
15951594
#define ID_EDITORS_VOLUMETRICS 33103
1595+
#define ID_NEW_PROP_TYPE 33104
1596+
#define ID_STATIC_SHIP_LABEL 33105
1597+
#define ID_STATIC_PROP_LABEL 33106
1598+
#define ID_OUTLINE_LOD_0 33107
1599+
#define ID_OUTLINE_LOD_1 33108
1600+
#define ID_OUTLINE_LOD_2 33109
1601+
#define ID_OUTLINE_LOD_3 33110
1602+
#define ID_OUTLINE_LOD_4 33111
1603+
#define ID_REORDER 33112
15961604
#define ID_INDICATOR_MODE 59142
15971605
#define ID_INDICATOR_LEFT 59143
15981606
#define ID_INDICATOR_RIGHT 59144
@@ -1604,9 +1612,9 @@
16041612
#ifdef APSTUDIO_INVOKED
16051613
#ifndef APSTUDIO_READONLY_SYMBOLS
16061614
#define _APS_3D_CONTROLS 1
1607-
#define _APS_NEXT_RESOURCE_VALUE 335
1608-
#define _APS_NEXT_COMMAND_VALUE 33112
1609-
#define _APS_NEXT_CONTROL_VALUE 1732
1615+
#define _APS_NEXT_RESOURCE_VALUE 336
1616+
#define _APS_NEXT_COMMAND_VALUE 33113
1617+
#define _APS_NEXT_CONTROL_VALUE 1738
16101618
#define _APS_NEXT_SYMED_VALUE 105
16111619
#endif
16121620
#endif

0 commit comments

Comments
 (0)