Skip to content

Commit d839f9f

Browse files
authored
Merge pull request #5444 from Goober5000/5401_followup
refinements of jump node features
2 parents 9d10066 + 3ae178e commit d839f9f

File tree

12 files changed

+113
-44
lines changed

12 files changed

+113
-44
lines changed

code/hud/hudbrackets.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,10 +675,7 @@ void HudGaugeBrackets::renderBoundingBrackets(int x1, int y1, int x2, int y2, in
675675
if(jnp->GetSCPObject() == t_objp)
676676
break;
677677
}
678-
679-
strcpy_s(temp_name, jnp->GetDisplayName());
680-
end_string_at_first_hash_symbol(temp_name);
681-
tinfo_name = temp_name;
678+
tinfo_name = jnp->GetDisplayName();
682679
break;
683680
}
684681

code/hud/hudtargetbox.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,9 +1320,7 @@ void HudGaugeTargetBox::renderTargetJumpNode(object *target_objp)
13201320
renderTargetIntegrity(1);
13211321
setGaugeColor();
13221322

1323-
strcpy_s(outstr, jnp->GetDisplayName());
1324-
end_string_at_first_hash_symbol(outstr);
1325-
renderString(position[0] + Name_offsets[0], position[1] + Name_offsets[1], EG_TBOX_NAME, outstr);
1323+
renderString(position[0] + Name_offsets[0], position[1] + Name_offsets[1], EG_TBOX_NAME, jnp->GetDisplayName());
13261324

13271325
dist = Player_ai->current_target_distance;
13281326
if ( Hud_unit_multiplier > 0.0f ) { // use a different displayed distance scale

code/jumpnode/jumpnode.cpp

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ CJumpNode::CJumpNode(const vec3d* position)
3939

4040
gr_init_alphacolor(&m_display_color, 0, 255, 0, 255);
4141

42-
// Set m_name
42+
// Set m_name and m_display
4343
sprintf(m_name, XSTR( "Jump Node %d", 632), Jump_nodes.size());
44-
45-
// Set m_display
46-
sprintf(m_display, XSTR("Jump Node %d", 632), Jump_nodes.size());
44+
m_display[0] = '\0';
4745

4846
// Set m_modelnum and m_radius
4947
m_modelnum = model_load(NOX(JN_DEFAULT_MODEL), 0, NULL, 0);
@@ -145,7 +143,10 @@ const char *CJumpNode::GetName()
145143
*/
146144
const char* CJumpNode::GetDisplayName()
147145
{
148-
return m_display;
146+
if (HasDisplayName())
147+
return m_display;
148+
else
149+
return m_name;
149150
}
150151

151152
/**
@@ -214,7 +215,15 @@ void CJumpNode::SetAlphaColor(int r, int g, int b, int alpha)
214215
CLAMP(b, 0, 255);
215216
CLAMP(alpha, 0, 255);
216217

217-
m_flags |= JN_USE_DISPLAY_COLOR;
218+
// see whether this is actually the default color
219+
// (which actually means to use the HUD color rather than this exact color;
220+
// it might be useful to change this design in the future, but beware of
221+
// FRED calling this function in the background)
222+
if (r == 0 && g == 255 && b == 0 && alpha == 255)
223+
m_flags &= ~JN_USE_DISPLAY_COLOR;
224+
else
225+
m_flags |= JN_USE_DISPLAY_COLOR;
226+
218227
gr_init_alphacolor(&m_display_color, r, g, b, alpha);
219228
}
220229

@@ -266,20 +275,38 @@ void CJumpNode::SetName(const char *new_name)
266275
CJumpNode* check = jumpnode_get_by_name(new_name);
267276
Assertion((check == this || !check), "Jumpnode %s is being renamed to %s, but a jump node with that name already exists in the mission!\n", m_name, new_name);
268277
#endif
269-
278+
270279
strcpy_s(m_name, new_name);
280+
281+
// if this name has a hash, create a default display name
282+
if (get_pointer_to_first_hash_symbol(new_name))
283+
{
284+
strcpy_s(m_display, new_name);
285+
end_string_at_first_hash_symbol(m_display);
286+
m_flags |= JN_HAS_DISPLAY_NAME;
287+
}
271288
}
272289

273290
/**
274-
* Set jump node name
291+
* Set jump node display name
275292
*
276-
* @param new_name New name to set
293+
* @param new_display_name New name to set
277294
*/
278-
void CJumpNode::SetDisplayName(const char* new_name)
295+
void CJumpNode::SetDisplayName(const char *new_display_name)
279296
{
280-
Assert(new_name != NULL);
297+
Assert(new_display_name != NULL);
281298

282-
strcpy_s(m_display, new_name);
299+
// if display name is blank or matches the actual name, clear it
300+
if (*new_display_name == '\0' || !stricmp(new_display_name, m_name))
301+
{
302+
*m_display = '\0';
303+
m_flags &= ~JN_HAS_DISPLAY_NAME;
304+
}
305+
else
306+
{
307+
strcpy_s(m_display, new_display_name);
308+
m_flags |= JN_HAS_DISPLAY_NAME;
309+
}
283310
}
284311

285312
/**
@@ -307,7 +334,7 @@ void CJumpNode::SetVisibility(bool enabled)
307334
/**
308335
* @return Is the jump node hidden when rendering?
309336
*/
310-
bool CJumpNode::IsHidden()
337+
bool CJumpNode::IsHidden() const
311338
{
312339
if(m_flags & JN_HIDE)
313340
return true;
@@ -318,19 +345,27 @@ bool CJumpNode::IsHidden()
318345
/**
319346
* @return Is the jump node colored any other color than default white?
320347
*/
321-
bool CJumpNode::IsColored()
348+
bool CJumpNode::IsColored() const
322349
{
323350
return ((m_flags & JN_USE_DISPLAY_COLOR) != 0);
324351
}
325352

326353
/**
327354
* @return Is the jump node model set differently from the default one?
328355
*/
329-
bool CJumpNode::IsSpecialModel()
356+
bool CJumpNode::IsSpecialModel() const
330357
{
331358
return ((m_flags & JN_SPECIAL_MODEL) != 0);
332359
}
333360

361+
/**
362+
* @return Does the jump node have a display name?
363+
*/
364+
bool CJumpNode::HasDisplayName() const
365+
{
366+
return ((m_flags & JN_HAS_DISPLAY_NAME) != 0);
367+
}
368+
334369
/**
335370
* Render jump node. Creates its own draw list to render
336371
*

code/jumpnode/jumpnode.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class model_draw_list;
2727
#define JN_SHOW_POLYS (1<<1) //Display model normally, rather than as wireframe
2828
#define JN_HIDE (1<<2) //Hides a jump node
2929
#define JN_SPECIAL_MODEL (1<<3) //If non-default model
30+
#define JN_HAS_DISPLAY_NAME (1<<4) //If it has a display name
3031

3132
#define JN_DEFAULT_MODEL "subspacenode.pof"
3233

@@ -76,9 +77,10 @@ class CJumpNode
7677
void SetVisibility(bool enabled);
7778

7879
//Query
79-
bool IsHidden();
80-
bool IsColored();
81-
bool IsSpecialModel();
80+
bool IsHidden() const;
81+
bool IsColored() const;
82+
bool IsSpecialModel() const;
83+
bool HasDisplayName() const;
8284

8385
//Rendering
8486
void Render(vec3d *pos, vec3d *view_pos = NULL);

code/mission/missionparse.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5280,8 +5280,6 @@ void parse_waypoints_and_jumpnodes(mission *pm)
52805280
if (optional_string("+Display Name:")) {
52815281
stuff_string(jump_display_name, F_NAME, NAME_LENGTH);
52825282
jnp.SetDisplayName(jump_display_name);
5283-
} else {
5284-
jnp.SetDisplayName(jump_name);
52855283
}
52865284

52875285
if(optional_string("+Model File:")){

code/parse/sexp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35251,7 +35251,7 @@ int get_subcategory(int op_id)
3525135251
case OP_SET_MOTION_DEBRIS:
3525235252
return CHANGE_SUBCATEGORY_BACKGROUND_AND_NEBULA;
3525335253

35254-
case OP_JUMP_NODE_SET_JUMPNODE_NAME: //
35254+
case OP_JUMP_NODE_SET_JUMPNODE_NAME:
3525535255
case OP_JUMP_NODE_SET_JUMPNODE_DISPLAY_NAME:
3525635256
case OP_JUMP_NODE_SET_JUMPNODE_COLOR:
3525735257
case OP_JUMP_NODE_SET_JUMPNODE_MODEL:
@@ -39577,7 +39577,7 @@ SCP_vector<sexp_help_struct> Sexp_help = {
3957739577
"\t4: Everywhere (optional). Whether the effect is applied to all camera views.\r\n"
3957839578
},
3957939579

39580-
{ OP_JUMP_NODE_SET_JUMPNODE_NAME, "set-jumpnode-name\r\n"
39580+
{ OP_JUMP_NODE_SET_JUMPNODE_NAME, "set-jumpnode-name (deprecated in favor of set-jumpnode-display-name)\r\n"
3958139581
"\tSets the name of a jump node. Takes 2 arguments...\r\n"
3958239582
"\t1: Name of jump node to change name for\r\n"
3958339583
"\t2: New name for jump node\r\n\r\n"

fred2/jumpnodedlg.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ BEGIN_MESSAGE_MAP(jumpnode_dlg, CDialog)
6868
ON_BN_CLICKED(IDC_NODE_HIDDEN, OnHidden)
6969
ON_WM_CLOSE()
7070
ON_WM_INITMENU()
71+
ON_EN_KILLFOCUS(IDC_NAME, OnKillfocusName)
7172
//}}AFX_MSG_MAP
7273
END_MESSAGE_MAP()
7374

@@ -181,7 +182,7 @@ int jumpnode_dlg::update_data()
181182
if (!GetSafeHwnd())
182183
return 0;
183184

184-
if (Objects[cur_object_index].type == OBJ_JUMP_NODE) {
185+
if (query_valid_object() && Objects[cur_object_index].type == OBJ_JUMP_NODE) {
185186
for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
186187
if(jnp->GetSCPObject() == &Objects[cur_object_index])
187188
break;
@@ -376,3 +377,20 @@ void jumpnode_dlg::OnHidden()
376377

377378
((CButton*)GetDlgItem(IDC_NODE_HIDDEN))->SetCheck(m_hidden);
378379
}
380+
381+
void jumpnode_dlg::OnKillfocusName()
382+
{
383+
char buffer[NAME_LENGTH];
384+
385+
// Note, in this dialog, UpdateData(TRUE) is not used to move data from controls to variables until the dialog is closed, so we edit the control text directly
386+
387+
// grab the name
388+
GetDlgItemText(IDC_NAME, buffer, NAME_LENGTH);
389+
390+
// if this name has a hash, truncate it for the display name
391+
if (get_pointer_to_first_hash_symbol(buffer))
392+
end_string_at_first_hash_symbol(buffer);
393+
394+
// set the display name derived from this name
395+
SetDlgItemText(IDC_ALT_NAME, buffer);
396+
}

fred2/jumpnodedlg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class jumpnode_dlg : public CDialog
5555
afx_msg void OnInitMenu(CMenu* pMenu);
5656
afx_msg void OnClose();
5757
afx_msg void OnHidden();
58+
afx_msg void OnKillfocusName();
5859
//}}AFX_MSG
5960
DECLARE_MESSAGE_MAP()
6061
};

fred2/missionsave.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4610,14 +4610,22 @@ int CFred_mission_save::save_waypoints()
46104610

46114611
if (Mission_save_format != FSO_FORMAT_RETAIL) {
46124612

4613-
if (jnp->GetDisplayName()[0] != '\0') {
4614-
if (optional_string_fred("+Display Name:", "$Jump Node:")) {
4615-
parse_comments();
4616-
} else {
4617-
fout("\n+Display Name:");
4613+
// The display name is only written if there was one at the start to avoid introducing inconsistencies
4614+
if (jnp->HasDisplayName()) {
4615+
char truncated_name[NAME_LENGTH];
4616+
strcpy_s(truncated_name, jnp->GetName());
4617+
end_string_at_first_hash_symbol(truncated_name);
4618+
4619+
// Also, the display name is not written if it's just the truncation of the name at the hash
4620+
if (strcmp(jnp->GetDisplayName(), truncated_name) != 0) {
4621+
if (optional_string_fred("+Display Name:", "$Jump Node:")) {
4622+
parse_comments();
4623+
} else {
4624+
fout("\n+Display Name:");
4625+
}
4626+
4627+
fout_ext("", "%s", jnp->GetDisplayName());
46184628
}
4619-
4620-
fout_ext("", "%s", jnp->GetDisplayName());
46214629
}
46224630

46234631
if (jnp->IsSpecialModel()) {

fred2/sexp_tree.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,7 @@ void sexp_tree::right_clicked(int mode)
10111011
case OP_TRIGGER_SUBMODEL_ANIMATION:
10121012
case OP_ADD_BACKGROUND_BITMAP:
10131013
case OP_ADD_SUN_BITMAP:
1014+
case OP_JUMP_NODE_SET_JUMPNODE_NAME:
10141015
j = (int)op_menu.size(); // don't allow these operators to be visible
10151016
break;
10161017
}
@@ -1065,6 +1066,7 @@ void sexp_tree::right_clicked(int mode)
10651066
case OP_TRIGGER_SUBMODEL_ANIMATION:
10661067
case OP_ADD_BACKGROUND_BITMAP:
10671068
case OP_ADD_SUN_BITMAP:
1069+
case OP_JUMP_NODE_SET_JUMPNODE_NAME:
10681070
j = (int)op_submenu.size(); // don't allow these operators to be visible
10691071
break;
10701072
}

0 commit comments

Comments
 (0)