Skip to content

Commit

Permalink
Merge pull request scp-fs2open#5963 from MjnMixael/fix_custom_string_dlg
Browse files Browse the repository at this point in the history
Fix assert when adding custom strings
  • Loading branch information
JohnAFernandez committed Feb 3, 2024
2 parents 7c29504 + de3e382 commit a7e1a27
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
37 changes: 21 additions & 16 deletions fred2/customstringsdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void CustomStringsDlg::OnStringRemove()

void CustomStringsDlg::OnStringUpdate()
{
if (!edit_boxes_have_valid_data()) {
if (!edit_boxes_have_valid_data(true)) {
return;
}

Expand Down Expand Up @@ -256,7 +256,7 @@ void CustomStringsDlg::OnStringUpdate()
update_text_edit_boxes("", "", "");
}

bool CustomStringsDlg::edit_boxes_have_valid_data()
bool CustomStringsDlg::edit_boxes_have_valid_data(bool update)
{
if (!data_edit_box_has_valid_data()) {
return false;
Expand All @@ -266,14 +266,14 @@ bool CustomStringsDlg::edit_boxes_have_valid_data()
return false;
}

if (!key_edit_box_has_valid_data()) {
if (!key_edit_box_has_valid_data(update)) {
return false;
}

return true;
}

bool CustomStringsDlg::key_edit_box_has_valid_data()
bool CustomStringsDlg::key_edit_box_has_valid_data(bool update)
{

CEdit* key_edit = (CEdit*)GetDlgItem(IDC_CUSTOM_KEY);
Expand All @@ -290,19 +290,24 @@ bool CustomStringsDlg::key_edit_box_has_valid_data()
return false;
}

// Only check for duplicate keys if there are other keys to check!
if (m_lister_keys.size() > 0) {
const int index = m_data_lister.GetCurSel();
const auto& this_key = m_lister_keys[index];

if (strcmp(this_key.c_str(), key_str)) {
for (const auto& cs : m_custom_strings) {
const CString key = cs.name.c_str();
if (key == key_str) {
MessageBox("Names must be unique!");
return false;
}
for (const auto& cs : m_custom_strings) {
const CString key = cs.name.c_str();
if (update) {
const int index = m_data_lister.GetCurSel();

if (!SCP_vector_inbounds(m_lister_keys, index)) {
MessageBox("Must select an item to update!");
return false;
}

const auto& this_key = m_lister_keys[index];
if (!strcmp(this_key.c_str(), key)) {
continue;
}
}
if (key == key_str) {
MessageBox("Names must be unique!");
return false;
}
}

Expand Down
4 changes: 2 additions & 2 deletions fred2/customstringsdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class CustomStringsDlg : public CDialog {
void update_text_edit_boxes(const SCP_string& key, const SCP_string& value, const SCP_string& text);
void update_help_text(const SCP_string& desc);

bool edit_boxes_have_valid_data();
bool edit_boxes_have_valid_data(bool update = false);
bool data_edit_box_has_valid_data();
bool key_edit_box_has_valid_data();
bool key_edit_box_has_valid_data(bool update = false);
bool text_edit_box_has_valid_data();

void add_pair_entry();
Expand Down

0 comments on commit a7e1a27

Please sign in to comment.