void CAddVariableDlg::validate_variable_name(int set_focus) { CString temp_name; CEdit *edit = (CEdit *) GetDlgItem(IDC_ADD_VARIABLE_NAME); edit->GetWindowText(temp_name); // Check if any change and not already in list if (stricmp(temp_name, "<Variable Name>")) { size_t len = strlen(temp_name); if ((len > 0) && (get_index_sexp_variable_name(LPCTSTR(temp_name)) == -1)) { //not already in list and length > 0 { //-V805 // Goober5000 - replace spaces with hyphens if (strchr(temp_name, ' ') != NULL) { // display msg MessageBox("Variable names cannot contain spaces. Replacing with hyphens."); // replace chars //Modified to make the code build. - Thunderbird temp_name.Replace((TCHAR) ' ', (TCHAR) '-'); //temp_name.Replace((TCHAR) ' ', (TCHAR) '-')); // fix what's displayed edit->SetFocus(); edit->SetWindowText(temp_name); edit->SetSel(0, -1); } m_name_validated = true; } else { // conflicting variable name if (len == 0) { edit->SetWindowText("<Variable Name>"); } m_name_validated = false; if (set_focus == RESET_FOCUS) { if (len == 0) { MessageBox("Variables must have a unique name."); } else { MessageBox("Another variable has this name already. Please choose another."); } edit->SetFocus(); edit->SetSel(0, -1); } } } else { // name unchanged from default m_name_validated = false; if (set_focus == RESET_FOCUS) { MessageBox("Invalid variable name"); edit->SetFocus(); edit->SetSel(0, -1); } } }
// Updates the Sexp_variable in a variable combobox to the value supplied void player_start_editor::UpdateQuantityVariable(CComboBox *variable_list, int pool_value) { char variable_name[TOKEN_LENGTH]; variable_list->GetLBText(variable_list->GetCurSel(), variable_name); int variable_index = get_index_sexp_variable_name(variable_name); if (variable_index > -1) { char variable_value[TOKEN_LENGTH]; sprintf(variable_value, "%d", pool_value); Assert (Sexp_variables[variable_index].type & SEXP_VARIABLE_NUMBER); sexp_fred_modify_variable(variable_value, variable_name, variable_index, SEXP_VARIABLE_NUMBER); } }
void player_start_editor::OnSelchangeWeaponVariablesCombo() { // Get the new selection char variable_name[TOKEN_LENGTH]; bool update_static_pool = false; bool update_dynamic_pool = false; m_weapon_quantity_variable.GetLBText(m_weapon_quantity_variable.GetCurSel(), variable_name); int sexp_index = get_index_sexp_variable_name(variable_name); Assert ((sexp_index > -1) || (!strcmp("Don't Use Variables", variable_name))); // See if the weapon_list was selected int weapon_index = GetSelectedWeaponListIndex(); if (weapon_index >= 0) { static_weapon_variable_pool[selected_team][weapon_index] = sexp_index; update_static_pool = true; } // Maybe it's the weapon_variables_list that is actually selected int weapon_variable_index = GetSelectedWeaponVariableListIndex(); if (weapon_variable_index >= 0 ) { dynamic_weapon_variable_pool[selected_team][weapon_variable_index] = sexp_index; update_dynamic_pool = true; } // Somethings gone wrong if they're both marked as true Assert (! (update_static_pool && update_dynamic_pool)); // Update the weapon_pool if (update_static_pool || update_dynamic_pool) { int new_quantity = 100; if (sexp_index > -1) { Assert (Sexp_variables[sexp_index].type & SEXP_VARIABLE_NUMBER); new_quantity = atoi(Sexp_variables[sexp_index].text); } if (update_static_pool) { static_weapon_pool[selected_team][weapon_index] = new_quantity; } else { dynamic_weapon_pool[selected_team][weapon_variable_index] = new_quantity; } m_weapon_pool = new_quantity; } // update stuff UpdateData(FALSE); }