| 635 | } |
| 636 | |
| 637 | void CWorldObjectsGenericDialog::OnGenericAddNew() { |
| 638 | char filename[256], dir[256], fname[256], ext[32]; |
| 639 | char cur_name[100], *t; |
| 640 | int img_handle; |
| 641 | int object_handle; |
| 642 | int c = 1, finding_name = 1; |
| 643 | |
| 644 | ASSERT(Network_up); |
| 645 | |
| 646 | // Get the filename of the representing image |
| 647 | |
| 648 | CString filter = "Descent III files (*.pof,*.oof)|*.pof;*.oof||"; |
| 649 | |
| 650 | if (!OpenFileDialog(this, (LPCTSTR)filter, filename, Current_model_dir, sizeof(Current_model_dir))) |
| 651 | return; |
| 652 | |
| 653 | ddio_SplitPath(filename, dir, fname, ext); |
| 654 | |
| 655 | std::filesystem::path tmp = ChangePolyModelName(filename); |
| 656 | strcpy(cur_name, tmp.u8string().c_str()); |
| 657 | |
| 658 | if ((FindPolyModelName(fname)) != -1) { |
| 659 | OutrageMessageBox("You must rename your model to something else because there is already a model with that name!"); |
| 660 | return; |
| 661 | } |
| 662 | |
| 663 | // Okay, we selected a file. Lets do what needs to be done here. |
| 664 | img_handle = LoadPolyModel(filename, 0); |
| 665 | |
| 666 | if (img_handle < 0) { |
| 667 | OutrageMessageBox("Couldn't open that model file."); |
| 668 | return; |
| 669 | } |
| 670 | |
| 671 | // Get a default name |
| 672 | strcpy(cur_name, fname); // Start with the filename |
| 673 | t = strchr(cur_name, '.'); // Strip the extention |
| 674 | if (!t) |
| 675 | t = cur_name + strlen(cur_name); |
| 676 | *t = 0; |
| 677 | do { // Make sure the name not already in use |
| 678 | int c = 0; |
| 679 | |
| 680 | if (FindObjectIDName(cur_name) == -1) |
| 681 | break; |
| 682 | |
| 683 | *t = 0; |
| 684 | sprintf(cur_name, "%s%d", cur_name, ++c); |
| 685 | } while (1); |
| 686 | cur_name[0] = toupper(cur_name[0]); // make first char uppercase |
| 687 | |
| 688 | // Get the object name from the user |
| 689 | retry_name: |
| 690 | |
| 691 | if (!InputObjectName(cur_name, sizeof(cur_name), "Object name", "Enter a name for your object:", this)) |
| 692 | return; |
| 693 | |
| 694 | if (FindObjectIDName(cur_name) != -1) { |
nothing calls this directly
no test coverage detected