Skip to content

Commit f991bf1

Browse files
authored
Qtfred cleanup pass (scp-fs2open#7345)
* set line edit fields to max length in code * fix some dialog window titles * remove unused context help button on Windows * address some easy todo items * static access
1 parent de07dc6 commit f991bf1

39 files changed

Lines changed: 178 additions & 122 deletions

code/missioneditor/common.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@ SCP_string Voice_script_instructions_string = "$name - name of the message\r\n"
2525
"$note - message notes\r\n\r\n"
2626
"Note that $persona and $sender will only appear for the Message section.";
2727

28+
// TODO: The implementation here is a direct copy of what was in the original FRED code. It is not clear whether the
29+
// original implementation was intentionally designed to produce the same output as the incorrect implementations in the
30+
// two editors, or whether it was intended to be a correct normalization but was implemented incorrectly. If the former,
31+
// then this implementation should be changed to produce the same output as the original implementations in the two
32+
// editors, even if that output is mathematically incorrect. If the latter, then this implementation should be changed
33+
// to produce correct normalization into [-180, 180] using a step of 360 instead of 180. This should be evaluated and
34+
// decided upon before making any changes to this implementation.
35+
36+
// NOTE: FRED and QtFRED Relative coordinates used this version exactly while QtFRED Object orient editor used the
37+
// correct 360 step version. This version was preserved here to avoid silent behavior changes to FRED during a routine
38+
// cleanup pass. This should be fixed intentionally in a dedicated pass once the impact on both editors has been evaluated.
39+
float normalize_degrees(float deg)
40+
{
41+
while (deg < -180.0f)
42+
deg += 180.0f; // was 360.0f in the qtfred object orient version, but this is the original FRED implementation
43+
while (deg > 180.0f)
44+
deg -= 180.0f; // was 360.0f in the qtfred object orient version, but this is the original FRED implementation
45+
// check for negative zero
46+
if (deg == -0.0f)
47+
deg = 0.0f;
48+
return deg;
49+
}
50+
2851
void time_to_mission_info_string(const std::tm* src, char* dest, size_t dest_max_len)
2952
{
3053
std::strftime(dest, dest_max_len, "%x at %X", src);

code/missioneditor/common.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
#include "mission/missionmessage.h"
44
#include "ship/anchor_t.h"
55

6+
// Default AWACS range applied when the nebula intensity is unset or invalid
7+
constexpr float DEFAULT_NEBULA_RANGE = 3000.0f;
8+
9+
// Smallest meaningful change in an orientation input field (degrees)
10+
constexpr float ORIENT_INPUT_THRESHOLD = 0.01f;
11+
12+
// Normalize a degree value into the range [-180, 180]
13+
float normalize_degrees(float deg);
14+
615
// Voice acting manager
716
#define INVALID_MESSAGE ((MMessage*)SIZE_MAX) // was originally SIZE_T_MAX but that wasn't available outside fred. May need more research.
817

fred2/bgbitmapdlg.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "parse/parselo.h"
2828
#include "starfield/starfield.h"
2929
#include "starfield/nebula.h"
30+
#include "missioneditor/common.h"
3031
#include <vcruntime.h>
3132

3233
#ifdef _DEBUG
@@ -428,7 +429,7 @@ void bg_bitmap_dlg::OnClose()
428429

429430
// override dumb values with reasonable ones
430431
if(Neb2_awacs <= 0.00000001f){
431-
Neb2_awacs = 3000.0f;
432+
Neb2_awacs = DEFAULT_NEBULA_RANGE;
432433
}
433434

434435
// store poof flags

fred2/orienteditor.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
static char THIS_FILE[] = __FILE__;
2222
#endif
2323

24-
constexpr auto INPUT_THRESHOLD = 0.01f; // smallest increment of input box
2524
constexpr auto INPUT_FORMAT = "%.01f";
2625

2726
static bool Select_set_relative = false;
@@ -205,7 +204,7 @@ bool orient_editor::is_close(float val, const CString &input_str) const
205204
float input_val = convert(input_str);
206205

207206
float diff = val - input_val;
208-
return abs(diff) < INPUT_THRESHOLD;
207+
return abs(diff) < ORIENT_INPUT_THRESHOLD;
209208
}
210209

211210
/**
@@ -217,7 +216,7 @@ bool orient_editor::is_angle_close(float rad, const CString &input_str) const
217216
float input_deg = normalize_degrees(convert(input_str));
218217

219218
float diff = deg - input_deg;
220-
return abs(diff) < INPUT_THRESHOLD;
219+
return abs(diff) < ORIENT_INPUT_THRESHOLD;
221220
}
222221

223222
bool orient_editor::query_modified()
@@ -418,18 +417,6 @@ float orient_editor::to_degrees(float rad)
418417
return normalize_degrees(deg);
419418
}
420419

421-
float orient_editor::normalize_degrees(float deg)
422-
{
423-
while (deg < -180.0f)
424-
deg += 180.0f;
425-
while (deg > 180.0f)
426-
deg -= 180.0f;
427-
// check for negative zero...
428-
if (deg == -0.0f)
429-
return 0.0f;
430-
return deg;
431-
}
432-
433420
/**
434421
* Extract a float from the CString, being mindful of any comma separators.
435422
*/

fred2/orienteditor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
#include "object/object.h"
13+
#include "missioneditor/common.h"
1314

1415
/////////////////////////////////////////////////////////////////////////////
1516
// orient_editor dialog
@@ -24,7 +25,6 @@ class orient_editor : public CDialog
2425
orient_editor(CWnd* pParent = NULL); // standard constructor
2526

2627
static float to_degrees(float radians);
27-
static float normalize_degrees(float degrees);
2828

2929
// Dialog Data
3030
//{{AFX_DATA(orient_editor)

qtfred/src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ int main(int argc, char* argv[]) {
9898
QCoreApplication::setApplicationName("qtFRED");
9999

100100
QApplication app(argc, argv);
101+
QApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);
101102

102103
// Expect that the platform library is in the same directory
103104
QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath());

qtfred/src/mission/Editor.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ int Editor::common_object_delete(int obj) {
11221122

11231123
} else if (type == OBJ_POINT) {
11241124
/*
1125-
TODO: Implement vriefing dialog
1125+
TODO: Implement briefing dialog
11261126
11271127
Assert(Briefing_dialog);
11281128
Briefing_dialog->delete_icon(Objects[obj].instance);
@@ -2151,12 +2151,6 @@ int Editor::global_error_check_impl() {
21512151
strcpy(names[obj_count], buf);
21522152
err_flags[obj_count] = 1;
21532153
} else if (ptr->type == OBJ_POINT) {
2154-
// TODO: Fix this once the briefing dialog exists
2155-
/*
2156-
if (!Briefing_dialog) {
2157-
return internal_error("Briefing icon detected when not in briefing edit mode");
2158-
}
2159-
*/
21602154
//Shouldn't be needed anymore.
21612155
//If we really do need it, call me and I'll write a is_valid function for jumpnodes -WMC
21622156
} else if (ptr->type == OBJ_JUMP_NODE) {

qtfred/src/mission/EditorViewport.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,9 +1085,7 @@ int EditorViewport::drag_objects(int x, int y)
10851085
if (!query_valid_object(editor->currentObject) || Lookat_mode)
10861086
return -1;
10871087

1088-
if (Dup_drag == 1
1089-
//&& (Briefing_dialog) TODO
1090-
) {
1088+
if (Dup_drag == 1) {
10911089
Dup_drag = 0;
10921090
}
10931091

@@ -1182,12 +1180,6 @@ int EditorViewport::drag_objects(int x, int y)
11821180
}
11831181
}
11841182

1185-
/*
1186-
TODO: Implement brieding dialog
1187-
if (Briefing_dialog)
1188-
Briefing_dialog->update_positions();
1189-
*/
1190-
11911183
editor->missionChanged();
11921184
return rval;
11931185
}

qtfred/src/mission/dialogs/BackgroundEditorDialogModel.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
#include "nebula/neb.h"
88
#include "nebula/neblightning.h"
99
#include "starfield/nebula.h"
10-
#include "lighting/lighting_profiles.h"
11-
12-
// TODO move this to common for both FREDs.
13-
const static float default_nebula_range = 3000.0f;
10+
#include "lighting/lighting_profiles.h"
11+
#include "missioneditor/common.h"
1412

1513
extern void parse_one_background(background_t* background);
1614

@@ -37,7 +35,7 @@ bool BackgroundEditorDialogModel::apply()
3735
// ours is a limited spinbox so this probably isn't necessary anymore??
3836
// Does this mean range can never be 0?????????
3937
if (Neb2_awacs <= 0.00000001f) {
40-
Neb2_awacs = 3000.0f;
38+
Neb2_awacs = DEFAULT_NEBULA_RANGE;
4139
}
4240
return true;
4341
}
@@ -59,7 +57,7 @@ void BackgroundEditorDialogModel::refreshBackgroundPreview()
5957
background_t& BackgroundEditorDialogModel::getActiveBackground()
6058
{
6159
if (!SCP_vector_inbounds(Backgrounds, Cur_background)) {
62-
// Fall back to first background if Cur_background isnt set
60+
// Fall back to first background if Cur_background isn't set
6361
Cur_background = 0;
6462
}
6563
return Backgrounds[Cur_background];
@@ -761,7 +759,7 @@ void BackgroundEditorDialogModel::setFullNebulaEnabled(bool enabled)
761759

762760
// Set defaults if needed
763761
if (Neb2_awacs <= 0.0f) {
764-
modify(Neb2_awacs, default_nebula_range);
762+
modify(Neb2_awacs, DEFAULT_NEBULA_RANGE);
765763
}
766764
} else {
767765
// Disable full nebula

qtfred/src/mission/dialogs/BriefingEditorDialogModel.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#include "BriefingEditorDialogModel.h"
22

33
#include "gamesnd/eventmusic.h"
4-
#include "mission/missionparse.h" //TODO remove?
5-
#include "missionui/missioncmdbrief.h" //TODO remove?
4+
#include "mission/missionparse.h"
65
#include "sound/audiostr.h"
76
#include "iff_defs/iff_defs.h"
87

@@ -164,8 +163,8 @@ void BriefingEditorDialogModel::addStage()
164163
if (_currentStage > 0) {
165164
const brief_stage& prev = _wipBriefings[_currentTeam].stages[_currentStage - 1];
166165

167-
dst = prev; // start by copying everything
168-
// then clear fields that should not carry over by default
166+
dst = prev; // start by copying everything
167+
// then clear fields that should not carry over by default
169168
dst.text = "<Text here>";
170169
dst.voice[0] = '\0';
171170
} else {
@@ -665,7 +664,7 @@ int BriefingEditorDialogModel::getIconShipTypeIndex() const
665664
const auto& s = b.stages[_currentStage];
666665
if (_currentIcon < 0 || _currentIcon >= s.num_icons)
667666
return -1;
668-
return s.icons[_currentIcon].ship_class; // may be -1 for unset depending on icon type
667+
return s.icons[_currentIcon].ship_class; // may be -1 for "unset" depending on icon type
669668
}
670669

671670
void BriefingEditorDialogModel::setIconShipTypeIndex(int idx)
@@ -1042,7 +1041,7 @@ void BriefingEditorDialogModel::makeIcon(const SCP_string& label, int typeIndex,
10421041
for (int i = 0; i < bs.num_icons; ++i)
10431042
maxId = std::max(maxId, bs.icons[i].id);
10441043
}
1045-
return maxId + 1; // unique within this teams briefing
1044+
return maxId + 1; // unique within this team's briefing
10461045
};
10471046

10481047
// Clamp incoming indices to safe ranges

0 commit comments

Comments
 (0)