Skip to content

Commit 54f0b41

Browse files
authored
Qtfred waypoint features (#7328)
* waypoint drawing features * use ints * parse and save as ints
1 parent 170a4a8 commit 54f0b41

10 files changed

Lines changed: 316 additions & 12 deletions

File tree

code/mission/missionparse.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5803,11 +5803,34 @@ void parse_waypoint_list(mission *pm)
58035803
required_string("$Name:");
58045804
stuff_string(name_buf, F_NAME, NAME_LENGTH);
58055805

5806+
bool no_draw_lines = false;
5807+
if (optional_string("+No Draw Lines:"))
5808+
stuff_boolean(&no_draw_lines);
5809+
5810+
bool has_custom_color = false;
5811+
int cr = 255, cg = 255, cb = 255;
5812+
if (optional_string("+Color:")) {
5813+
has_custom_color = true;
5814+
stuff_int(&cr);
5815+
stuff_int(&cg);
5816+
stuff_int(&cb);
5817+
}
5818+
58065819
SCP_vector<vec3d> vec_list;
58075820
required_string("$List:");
58085821
stuff_vec3d_list(vec_list);
58095822

58105823
waypoint_add_list(name_buf, vec_list);
5824+
5825+
// Apply display properties to the list just added
5826+
if (no_draw_lines || has_custom_color) {
5827+
waypoint_list* wl = find_matching_waypoint_list(name_buf);
5828+
if (wl) {
5829+
wl->set_no_draw_lines(no_draw_lines);
5830+
if (has_custom_color)
5831+
wl->set_color(cr, cg, cb);
5832+
}
5833+
}
58115834
}
58125835

58135836
void parse_waypoints_and_jumpnodes(mission *pm)

code/missioneditor/missionsave.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4856,6 +4856,27 @@ int Fred_mission_save::save_waypoints()
48564856
parse_comments(first_wpt_list ? 1 : 2);
48574857
fout(" %s", ii.get_name());
48584858

4859+
if (save_config.save_format != MissionFormat::RETAIL) {
4860+
4861+
int nol_in_file = optional_string_fred("+No Draw Lines:", "$List:");
4862+
if (nol_in_file)
4863+
parse_comments();
4864+
if (nol_in_file || ii.get_no_draw_lines()) {
4865+
if (!nol_in_file)
4866+
fout("\n+No Draw Lines:");
4867+
fout(" %s", ii.get_no_draw_lines() ? "true" : "false");
4868+
}
4869+
4870+
if (ii.get_has_custom_color()) {
4871+
if (optional_string_fred("+Color:", "$List:")) {
4872+
parse_comments();
4873+
} else {
4874+
fout("\n+Color:");
4875+
}
4876+
fout(" %d %d %d", ii.get_color_r(), ii.get_color_g(), ii.get_color_b());
4877+
}
4878+
}
4879+
48594880
required_string_fred("$List:");
48604881
parse_comments();
48614882
fout(" (\t\t;! %d points in list\n", ii.get_waypoints().size());

code/object/waypoint.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,19 @@ void waypoint::set_pos(const vec3d *pos)
9696
waypoint_list::waypoint_list()
9797
{
9898
this->m_name[0] = '\0';
99+
this->m_no_draw_lines = false;
100+
this->m_has_custom_color = false;
101+
this->m_color_r = this->m_color_g = this->m_color_b = 255;
99102
}
100103

101104
waypoint_list::waypoint_list(const char *name)
102105
{
103106
Assert(name != NULL);
104107
Assert(find_matching_waypoint_list(name) == NULL);
105108
strcpy_s(this->m_name, name);
109+
this->m_no_draw_lines = false;
110+
this->m_has_custom_color = false;
111+
this->m_color_r = this->m_color_g = this->m_color_b = 255;
106112
}
107113

108114
waypoint_list::~waypoint_list()
@@ -137,6 +143,49 @@ void waypoint_list::set_name(const char *name)
137143
this->m_name[len] = '\0';
138144
}
139145

146+
void waypoint_list::set_no_draw_lines(bool val)
147+
{
148+
m_no_draw_lines = val;
149+
}
150+
151+
void waypoint_list::set_color(int r, int g, int b)
152+
{
153+
m_color_r = r;
154+
m_color_g = g;
155+
m_color_b = b;
156+
m_has_custom_color = true;
157+
}
158+
159+
void waypoint_list::clear_color()
160+
{
161+
m_has_custom_color = false;
162+
}
163+
164+
bool waypoint_list::get_no_draw_lines() const
165+
{
166+
return m_no_draw_lines;
167+
}
168+
169+
bool waypoint_list::get_has_custom_color() const
170+
{
171+
return m_has_custom_color;
172+
}
173+
174+
int waypoint_list::get_color_r() const
175+
{
176+
return m_color_r;
177+
}
178+
179+
int waypoint_list::get_color_g() const
180+
{
181+
return m_color_g;
182+
}
183+
184+
int waypoint_list::get_color_b() const
185+
{
186+
return m_color_b;
187+
}
188+
140189
//********************FUNCTIONS********************
141190
void waypoint_level_close()
142191
{

code/object/waypoint.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,23 @@ class waypoint_list
4646

4747
// mutators
4848
void set_name(const char *name);
49+
void set_no_draw_lines(bool val);
50+
void set_color(int r, int g, int b);
51+
void clear_color();
52+
53+
// display property accessors
54+
bool get_no_draw_lines() const;
55+
bool get_has_custom_color() const;
56+
int get_color_r() const;
57+
int get_color_g() const;
58+
int get_color_b() const;
4959

5060
private:
5161
char m_name[NAME_LENGTH];
5262
SCP_vector<waypoint> m_waypoints;
63+
bool m_no_draw_lines;
64+
bool m_has_custom_color;
65+
int m_color_r, m_color_g, m_color_b;
5366
};
5467

5568
//********************GLOBALS********************

qtfred/src/mission/FredRenderer.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -968,9 +968,16 @@ void FredRenderer::render_one_model_htl(object* objp,
968968
g = 127;
969969
b = 0;
970970
} else if (objp->type == OBJ_WAYPOINT) {
971-
r = 96;
972-
g = 0;
973-
b = 112;
971+
waypoint_list* wpt_list = find_waypoint_list_with_instance(objp->instance);
972+
if (wpt_list && wpt_list->get_has_custom_color()) {
973+
r = wpt_list->get_color_r();
974+
g = wpt_list->get_color_g();
975+
b = wpt_list->get_color_b();
976+
} else {
977+
r = 96;
978+
g = 0;
979+
b = 112;
980+
}
974981
} else if (objp->type == OBJ_POINT) {
975982
if (objp->instance != BRIEFING_LOOKAT_POINT_ID) {
976983
///! \fixme Briefing stuff!
@@ -1004,11 +1011,14 @@ void FredRenderer::render_one_model_htl(object* objp,
10041011
}
10051012

10061013
if (objp->type == OBJ_WAYPOINT) {
1007-
for (auto objIdx : rendering_order) {
1008-
o2 = &Objects[objIdx];
1009-
if (o2->type == OBJ_WAYPOINT) {
1010-
if ((o2->instance == objp->instance - 1) || (o2->instance == objp->instance + 1)) {
1011-
g3_draw_htl_line(&o2->pos, &objp->pos);
1014+
waypoint_list* wpt_list = find_waypoint_list_with_instance(objp->instance);
1015+
if (!wpt_list || !wpt_list->get_no_draw_lines()) {
1016+
for (auto objIdx : rendering_order) {
1017+
o2 = &Objects[objIdx];
1018+
if (o2->type == OBJ_WAYPOINT) {
1019+
if ((o2->instance == objp->instance - 1) || (o2->instance == objp->instance + 1)) {
1020+
g3_draw_htl_line(&o2->pos, &objp->pos);
1021+
}
10121022
}
10131023
}
10141024
}

qtfred/src/mission/dialogs/WaypointEditorDialogModel.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ bool WaypointEditorDialogModel::apply()
4141
}
4242
}
4343

44+
// apply display properties
45+
_editor->cur_waypoint_list->set_no_draw_lines(_noDrawLines);
46+
if (_hasCustomColor)
47+
_editor->cur_waypoint_list->set_color((ubyte)_colorR, (ubyte)_colorG, (ubyte)_colorB);
48+
else
49+
_editor->cur_waypoint_list->clear_color();
50+
51+
_editor->missionChanged();
52+
4453
return true;
4554
}
4655

@@ -61,8 +70,16 @@ void WaypointEditorDialogModel::initializeData()
6170

6271
if (_editor->cur_waypoint_list != nullptr) {
6372
_currentName = _editor->cur_waypoint_list->get_name();
73+
_noDrawLines = _editor->cur_waypoint_list->get_no_draw_lines();
74+
_hasCustomColor = _editor->cur_waypoint_list->get_has_custom_color();
75+
_colorR = _editor->cur_waypoint_list->get_color_r();
76+
_colorG = _editor->cur_waypoint_list->get_color_g();
77+
_colorB = _editor->cur_waypoint_list->get_color_b();
6478
} else {
6579
_currentName = "";
80+
_noDrawLines = false;
81+
_hasCustomColor = false;
82+
_colorR = _colorG = _colorB = 255;
6683
_enabled = false;
6784
}
6885

@@ -223,4 +240,17 @@ const SCP_vector<std::pair<SCP_string, int>>& WaypointEditorDialogModel::getWayp
223240
return _waypointPathList;
224241
}
225242

243+
bool WaypointEditorDialogModel::getNoDrawLines() const { return _noDrawLines; }
244+
void WaypointEditorDialogModel::setNoDrawLines(bool val) { modify(_noDrawLines, val); }
245+
246+
bool WaypointEditorDialogModel::getHasCustomColor() const { return _hasCustomColor; }
247+
void WaypointEditorDialogModel::setHasCustomColor(bool val) { modify(_hasCustomColor, val); }
248+
249+
int WaypointEditorDialogModel::getColorR() const { return _colorR; }
250+
int WaypointEditorDialogModel::getColorG() const { return _colorG; }
251+
int WaypointEditorDialogModel::getColorB() const { return _colorB; }
252+
void WaypointEditorDialogModel::setColorR(int r) { modify(_colorR, r); }
253+
void WaypointEditorDialogModel::setColorG(int g) { modify(_colorG, g); }
254+
void WaypointEditorDialogModel::setColorB(int b) { modify(_colorB, b); }
255+
226256
} // namespace fso::fred::dialogs

qtfred/src/mission/dialogs/WaypointEditorDialogModel.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@ class WaypointEditorDialogModel: public AbstractDialogModel {
1616
void setCurrentName(const SCP_string& name);
1717
int getCurrentlySelectedPath() const;
1818
void setCurrentlySelectedPath(int elementId);
19-
19+
20+
bool getNoDrawLines() const;
21+
void setNoDrawLines(bool val);
22+
bool getHasCustomColor() const;
23+
void setHasCustomColor(bool val);
24+
int getColorR() const;
25+
int getColorG() const;
26+
int getColorB() const;
27+
void setColorR(int r);
28+
void setColorG(int g);
29+
void setColorB(int b);
30+
2031
bool isEnabled() const;
2132
const SCP_vector<std::pair<SCP_string, int>>& getWaypointPathList() const;
2233

@@ -40,6 +51,9 @@ private slots:
4051
bool _enabled = false;
4152
SCP_vector<std::pair<SCP_string, int>> _waypointPathList;
4253
bool _bypass_errors = false;
54+
bool _noDrawLines = false;
55+
bool _hasCustomColor = false;
56+
int _colorR = 255, _colorG = 255, _colorB = 255;
4357
};
4458

4559
} // namespace fso::fred::dialogs

qtfred/src/ui/dialogs/WaypointEditorDialog.cpp

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ void WaypointEditorDialog::initializeUi()
3636
util::SignalBlockers blockers(this);
3737

3838
updateWaypointListComboBox();
39-
ui->nameEdit->setEnabled(_model->isEnabled());
39+
bool enabled = _model->isEnabled();
40+
ui->nameEdit->setEnabled(enabled);
41+
ui->noDrawLinesCheck->setEnabled(enabled);
42+
ui->customColorCheck->setEnabled(enabled);
4043
}
4144

4245
void WaypointEditorDialog::updateWaypointListComboBox()
@@ -55,6 +58,28 @@ void WaypointEditorDialog::updateUi()
5558
util::SignalBlockers blockers(this);
5659
ui->nameEdit->setText(QString::fromStdString(_model->getCurrentName()));
5760
ui->pathSelection->setCurrentIndex(ui->pathSelection->findData(_model->getCurrentlySelectedPath()));
61+
62+
ui->noDrawLinesCheck->setChecked(_model->getNoDrawLines());
63+
ui->customColorCheck->setChecked(_model->getHasCustomColor());
64+
ui->colorRSpinBox->setValue(_model->getColorR());
65+
ui->colorGSpinBox->setValue(_model->getColorG());
66+
ui->colorBSpinBox->setValue(_model->getColorB());
67+
68+
bool colorEnabled = _model->isEnabled() && _model->getHasCustomColor();
69+
ui->colorRSpinBox->setEnabled(colorEnabled);
70+
ui->colorGSpinBox->setEnabled(colorEnabled);
71+
ui->colorBSpinBox->setEnabled(colorEnabled);
72+
73+
updateColorSwatch();
74+
}
75+
76+
void WaypointEditorDialog::updateColorSwatch()
77+
{
78+
ui->colorSwatch->setStyleSheet(QString("background: rgb(%1,%2,%3);"
79+
"border: 1px solid #444; border-radius: 3px;")
80+
.arg(_model->getColorR())
81+
.arg(_model->getColorG())
82+
.arg(_model->getColorB()));
5883
}
5984

6085
void WaypointEditorDialog::on_pathSelection_currentIndexChanged(int index)
@@ -86,4 +111,41 @@ void WaypointEditorDialog::on_nameEdit_editingFinished()
86111
}
87112
}
88113

114+
void WaypointEditorDialog::on_noDrawLinesCheck_toggled(bool checked)
115+
{
116+
_model->setNoDrawLines(checked);
117+
_model->apply();
118+
}
119+
120+
void WaypointEditorDialog::on_customColorCheck_toggled(bool checked)
121+
{
122+
_model->setHasCustomColor(checked);
123+
ui->colorRSpinBox->setEnabled(checked);
124+
ui->colorGSpinBox->setEnabled(checked);
125+
ui->colorBSpinBox->setEnabled(checked);
126+
updateColorSwatch();
127+
_model->apply();
128+
}
129+
130+
void WaypointEditorDialog::on_colorRSpinBox_valueChanged(int value)
131+
{
132+
_model->setColorR(value);
133+
updateColorSwatch();
134+
_model->apply();
135+
}
136+
137+
void WaypointEditorDialog::on_colorGSpinBox_valueChanged(int value)
138+
{
139+
_model->setColorG(value);
140+
updateColorSwatch();
141+
_model->apply();
142+
}
143+
144+
void WaypointEditorDialog::on_colorBSpinBox_valueChanged(int value)
145+
{
146+
_model->setColorB(value);
147+
updateColorSwatch();
148+
_model->apply();
149+
}
150+
89151
} // namespace fso::fred::dialogs

qtfred/src/ui/dialogs/WaypointEditorDialog.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ class WaypointEditorDialog : public QDialog {
1818
private slots:
1919
void on_pathSelection_currentIndexChanged(int index);
2020
void on_nameEdit_editingFinished();
21+
void on_noDrawLinesCheck_toggled(bool checked);
22+
void on_customColorCheck_toggled(bool checked);
23+
void on_colorRSpinBox_valueChanged(int value);
24+
void on_colorGSpinBox_valueChanged(int value);
25+
void on_colorBSpinBox_valueChanged(int value);
2126

2227
private: // NOLINT(readability-redundant-access-specifiers)
2328
EditorViewport* _viewport;
@@ -26,7 +31,8 @@ private slots:
2631

2732
void initializeUi();
2833
void updateWaypointListComboBox();
29-
void updateUi();
34+
void updateUi();
35+
void updateColorSwatch();
3036
};
3137

3238
} // namespace fso::fred::dialogs

0 commit comments

Comments
 (0)