work toward a unicode-compatible max converter

This commit is contained in:
rdb 2013-10-07 22:36:05 +00:00
parent 146f56e01e
commit e1ff689adc
4 changed files with 141 additions and 110 deletions

View File

@ -468,29 +468,29 @@ void MaxEggPlugin::SaveCheckState() {
void MaxEggPlugin::UpdateUI() { void MaxEggPlugin::UpdateUI() {
HWND lv = GetDlgItem(hMaxEggParams, IDC_LIST_EGGS); HWND lv = GetDlgItem(hMaxEggParams, IDC_LIST_EGGS);
LV_COLUMN pCol; LV_COLUMN pCol;
if (ListView_GetColumnWidth(lv, 1) <= 0 || ListView_GetColumnWidth(lv, 1) > 10000) { if (ListView_GetColumnWidth(lv, 1) <= 0 || ListView_GetColumnWidth(lv, 1) > 10000) {
//Columns have not been setup, so initialize the control // Columns have not been setup, so initialize the control
ListView_SetExtendedListViewStyleEx(lv, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT, ListView_SetExtendedListViewStyleEx(lv, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT,
LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT); LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT);
pCol.fmt = LVCFMT_LEFT; pCol.fmt = LVCFMT_LEFT;
pCol.cx = 96; pCol.cx = 96;
pCol.pszText = "Filename"; pCol.pszText = _T("Filename");
pCol.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; pCol.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
pCol.iSubItem = 0; pCol.iSubItem = 0;
ListView_InsertColumn(lv, 0, &pCol); ListView_InsertColumn(lv, 0, &pCol);
pCol.cx = 44; pCol.cx = 44;
pCol.pszText = "Type"; pCol.pszText = _T("Type");
ListView_InsertColumn(lv, 1, &pCol); ListView_InsertColumn(lv, 1, &pCol);
} }
//Add the eggs to the list // Add the eggs to the list
ListView_DeleteAllItems(lv); ListView_DeleteAllItems(lv);
LV_ITEM Item; LV_ITEM Item;
Item.mask = LVIF_TEXT; Item.mask = LVIF_TEXT;
for (int i = 0; i < numEggs; i++) { for (int i = 0; i < numEggs; i++) {
Item.iItem = i; Item.iItem = i;
Item.iSubItem = 0; Item.iSubItem = 0;
@ -498,16 +498,16 @@ void MaxEggPlugin::UpdateUI() {
ListView_InsertItem(lv, &Item); ListView_InsertItem(lv, &Item);
Item.iSubItem = 1; Item.iSubItem = 1;
switch(eggList[i]->_anim_type) { switch(eggList[i]->_anim_type) {
case MaxEggOptions::AT_chan: Item.pszText = "Animation"; break; case MaxEggOptions::AT_chan: Item.pszText = _T("Animation"); break;
case MaxEggOptions::AT_both: Item.pszText = "Both"; break; case MaxEggOptions::AT_both: Item.pszText = _T("Both"); break;
case MaxEggOptions::AT_pose: Item.pszText = "Static"; break; case MaxEggOptions::AT_pose: Item.pszText = _T("Static"); break;
case MaxEggOptions::AT_model: Item.pszText = "Model"; break; case MaxEggOptions::AT_model: Item.pszText = _T("Model"); break;
default: Item.pszText = "Model"; break; default: Item.pszText = _T("Model"); break;
} }
ListView_SetItem(lv, &Item); ListView_SetItem(lv, &Item);
ListView_SetCheckState(lv, i, eggList[i]->_checked); ListView_SetCheckState(lv, i, eggList[i]->_checked);
} }
// Set the "Overwrite Existing Files" and "Pview" checkboxes // Set the "Overwrite Existing Files" and "Pview" checkboxes
CheckDlgButton(hMaxEggParams, IDC_OVERWRITE_CHECK, CheckDlgButton(hMaxEggParams, IDC_OVERWRITE_CHECK,
autoOverwrite ? BST_CHECKED : BST_UNCHECKED); autoOverwrite ? BST_CHECKED : BST_UNCHECKED);
@ -519,48 +519,48 @@ void MaxEggPlugin::UpdateUI() {
void MaxEggPlugin::DoExport() { void MaxEggPlugin::DoExport() {
int good = 0, bad = 0; int good = 0, bad = 0;
std::stringstream status; std::basic_stringstream<TCHAR> status;
SaveCheckState(); SaveCheckState();
for (int i = 0; i < numEggs; i++) { for (int i = 0; i < numEggs; i++) {
if (eggList[i]->_checked) { if (eggList[i]->_checked) {
// If "auto overwrite" was not checked and the file exists, // If "auto overwrite" was not checked and the file exists,
// ask if the user wishes to overwrite the file // ask if the user wishes to overwrite the file
bool do_write = true; bool do_write = true;
if (!autoOverwrite && Filename::from_os_specific(eggList[i]->_file_name).exists()) { if (!autoOverwrite && Filename::from_os_specific(eggList[i]->_file_name).exists()) {
char msg[1024]; TCHAR msg[1024];
sprintf(msg, "Overwrite file \"%s.egg\"?", eggList[i]->_short_name); _stprintf(msg, "Overwrite file \"%s.egg\"?", eggList[i]->_short_name);
do_write = (MessageBox(hMaxEggParams, msg, "Panda3D Exporter", MB_YESNO | MB_ICONQUESTION) == IDYES); do_write = (MessageBox(hMaxEggParams, msg, _T("Panda3D Exporter"), MB_YESNO | MB_ICONQUESTION) == IDYES);
} }
if (do_write) { if (do_write) {
MaxToEggConverter converter; MaxToEggConverter converter;
if (converter.convert((MaxEggOptions*)eggList[i])) { if (converter.convert((MaxEggOptions*)eggList[i])) {
good += 1; good += 1;
status << "Successfully created " << eggList[i]->_short_name << ".egg\n"; status << _T("Successfully created ") << eggList[i]->_short_name << _T(".egg\n");
} else { } else {
bad += 1; bad += 1;
status << "Could not export " << eggList[i]->_short_name << ".egg\n"; status << _T("Could not export ") << eggList[i]->_short_name << _T(".egg\n");
} }
} else { } else {
bad += 1; bad += 1;
status << "Skipped file " << eggList[i]->_short_name << ".egg\n"; status << _T("Skipped file ") << eggList[i]->_short_name << _T(".egg\n");
} }
} }
} }
UINT mask = MB_OK; UINT mask = MB_OK;
if (good == 0 && bad == 0) { if (good == 0 && bad == 0) {
mask |= MB_ICONEXCLAMATION; mask |= MB_ICONEXCLAMATION;
MessageBox(hMaxEggParams, "Nothing to export!", "Panda3D Export results", mask); MessageBox(hMaxEggParams, _T("Nothing to export!"), _T("Panda3D Export results"), mask);
} else { } else {
if (bad > 0) mask |= MB_ICONEXCLAMATION; if (bad > 0) mask |= MB_ICONEXCLAMATION;
else mask |= MB_ICONINFORMATION; else mask |= MB_ICONINFORMATION;
MessageBox(hMaxEggParams, status.str().c_str(), "Panda3D Export results", mask); MessageBox(hMaxEggParams, status.str().c_str(), _T("Panda3D Export results"), mask);
} }
int pviewed = 0; int pviewed = 0;
if (pview && good > 0) { if (pview && good > 0) {
for (i = 0; i < numEggs; i++) { for (i = 0; i < numEggs; i++) {
@ -568,18 +568,18 @@ void MaxEggPlugin::DoExport() {
if (eggList[i]->_anim_type != MaxEggOptions::AT_chan) { if (eggList[i]->_anim_type != MaxEggOptions::AT_chan) {
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
STARTUPINFO si; STARTUPINFO si;
memset(&si,0,sizeof(si)); memset(&si, 0, sizeof(si));
si.cb= sizeof(si); si.cb = sizeof(si);
char cmdLine[2048]; TCHAR cmdLine[2048];
// If we have just one model and animation file, pview them both // If we have just one model and animation file, pview them both
if (numEggs == 2 && eggList[i]->_anim_type == MaxEggOptions::AT_model && if (numEggs == 2 && eggList[i]->_anim_type == MaxEggOptions::AT_model &&
eggList[1-i]->_checked && eggList[1-i]->_successful && eggList[1-i]->_checked && eggList[1-i]->_successful &&
eggList[1-i]->_anim_type == MaxEggOptions::AT_chan) { eggList[1-i]->_anim_type == MaxEggOptions::AT_chan) {
sprintf(cmdLine, "pview \"%s\" \"%s\"", eggList[i]->_file_name, eggList[1-i]->_file_name); _stprintf(cmdLine, _T("pview \"%s\" \"%s\""), eggList[i]->_file_name, eggList[1-i]->_file_name);
} else { } else {
sprintf(cmdLine, "pview \"%s\"", eggList[i]->_file_name); _stprintf(cmdLine, _T("pview \"%s\""), eggList[i]->_file_name);
} }
CreateProcess(NULL, cmdLine, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, CreateProcess(NULL, cmdLine, NULL, NULL, FALSE, CREATE_NEW_CONSOLE,
NULL, NULL, &si, &pi); NULL, NULL, &si, &pi);
@ -595,7 +595,7 @@ void MaxEggPlugin::BuildMesh()
{ {
int i; int i;
if(meshBuilt) return; if(meshBuilt) return;
mesh.setNumVerts(252); mesh.setNumVerts(252);
mesh.setNumFaces(84); mesh.setNumFaces(84);
mesh.setSmoothFlags(0); mesh.setSmoothFlags(0);

View File

@ -15,8 +15,8 @@
//Disable the forcing int to true or false performance warning //Disable the forcing int to true or false performance warning
#pragma warning(disable: 4800) #pragma warning(disable: 4800)
void SetICustEdit(HWND wnd, int nIDDlgItem, char *text) void SetICustEdit(HWND wnd, int nIDDlgItem, const TCHAR *text)
{ {
ICustEdit *edit = GetICustEdit(GetDlgItem(wnd, nIDDlgItem)); ICustEdit *edit = GetICustEdit(GetDlgItem(wnd, nIDDlgItem));
edit->SetText(text); edit->SetText(text);
ReleaseICustEdit(edit); ReleaseICustEdit(edit);
@ -24,18 +24,18 @@ void SetICustEdit(HWND wnd, int nIDDlgItem, char *text)
void SetICustEdit(HWND wnd, int nIDDlgItem, int n) void SetICustEdit(HWND wnd, int nIDDlgItem, int n)
{ {
char text[80]; TCHAR text[80];
sprintf(text, "%d", n); _stprintf(text, _T("%d"), n);
ICustEdit *edit = GetICustEdit(GetDlgItem(wnd, nIDDlgItem)); ICustEdit *edit = GetICustEdit(GetDlgItem(wnd, nIDDlgItem));
edit->SetText(text); edit->SetText(text);
ReleaseICustEdit(edit); ReleaseICustEdit(edit);
} }
char *GetICustEditT(HWND wnd) TCHAR *GetICustEditT(HWND wnd)
{ {
static char buffer[2084]; static TCHAR buffer[2084];
ICustEdit *edit = GetICustEdit(wnd); ICustEdit *edit = GetICustEdit(wnd);
edit->GetText(buffer,2084); edit->GetText(buffer, 2084);
ReleaseICustEdit(edit); ReleaseICustEdit(edit);
return buffer; return buffer;
} }
@ -72,24 +72,24 @@ void ChunkSave(ISave *isave, int chunkid, bool value)
isave->EndChunk(); isave->EndChunk();
} }
void ChunkSave(ISave *isave, int chunkid, char *value) void ChunkSave(ISave *isave, int chunkid, TCHAR *value)
{ {
ULONG nb; ULONG nb;
isave->BeginChunk(chunkid); isave->BeginChunk(chunkid);
int bytes = strlen(value) + 1; int length = _tcslen(value) + 1;
isave->Write(&bytes, sizeof(int), &nb); isave->Write(&length, sizeof(int), &nb);
isave->Write(value, bytes, &nb); isave->Write(value, length * sizeof(TCHAR), &nb);
isave->EndChunk(); isave->EndChunk();
} }
char *ChunkLoadString(ILoad *iload, char *buffer, int maxBytes) TCHAR *ChunkLoadString(ILoad *iload, TCHAR *buffer, int maxLength)
{ {
ULONG nb; ULONG nb;
int bytes; int length;
IOResult res; IOResult res;
res = iload->Read(&bytes, sizeof(int), &nb); res = iload->Read(&length, sizeof(int), &nb);
assert(res == IO_OK && bytes <= maxBytes); assert(res == IO_OK && length <= maxLength);
res = iload->Read(buffer, bytes, &nb); res = iload->Read(buffer, length * sizeof(TCHAR), &nb);
assert(res == IO_OK); assert(res == IO_OK);
return buffer; return buffer;
} }
@ -128,7 +128,7 @@ void showAnimControls(HWND hWnd, BOOL val) {
ShowWindow(GetDlgItem(hWnd, IDC_EF), val); ShowWindow(GetDlgItem(hWnd, IDC_EF), val);
ShowWindow(GetDlgItem(hWnd, IDC_SF_LABEL), val); ShowWindow(GetDlgItem(hWnd, IDC_SF_LABEL), val);
SetWindowText(GetDlgItem(hWnd, IDC_EXP_SEL_FRAMES), SetWindowText(GetDlgItem(hWnd, IDC_EXP_SEL_FRAMES),
val ? "Use Range:" : "Use Frame:"); val ? _T("Use Range:") : _T("Use Frame:"));
} }
void enableAnimControls(HWND hWnd, BOOL val) { void enableAnimControls(HWND hWnd, BOOL val) {
@ -262,7 +262,7 @@ MaxEggOptions::MaxEggOptions() {
INT_PTR CALLBACK MaxOptionsDialogProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) INT_PTR CALLBACK MaxOptionsDialogProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{ {
char tempFilename[2048]; TCHAR tempFilename[2048];
//We pass in our plugin through the lParam variable. Let's convert it back. //We pass in our plugin through the lParam variable. Let's convert it back.
MaxOptionsDialog *imp = (MaxOptionsDialog*)GetWindowLongPtr(hWnd,GWLP_USERDATA); MaxOptionsDialog *imp = (MaxOptionsDialog*)GetWindowLongPtr(hWnd,GWLP_USERDATA);
if ( !imp && message != WM_INITDIALOG ) return FALSE; if ( !imp && message != WM_INITDIALOG ) return FALSE;
@ -286,7 +286,7 @@ INT_PTR CALLBACK MaxOptionsDialogProc( HWND hWnd, UINT message, WPARAM wParam, L
case IDC_MODEL: case IDC_MODEL:
if (HIWORD(wParam) == BN_CLICKED) { if (HIWORD(wParam) == BN_CLICKED) {
SetWindowText(GetDlgItem(hWnd, IDC_EXPORT_SELECTED), SetWindowText(GetDlgItem(hWnd, IDC_EXPORT_SELECTED),
"Export Meshes:"); _T("Export Meshes:"));
enableAnimRadios(hWnd, ANIM_RAD_NONE); enableAnimRadios(hWnd, ANIM_RAD_NONE);
showAnimControls(hWnd, TRUE); showAnimControls(hWnd, TRUE);
enableAnimControls(hWnd, FALSE); enableAnimControls(hWnd, FALSE);
@ -300,7 +300,7 @@ INT_PTR CALLBACK MaxOptionsDialogProc( HWND hWnd, UINT message, WPARAM wParam, L
case IDC_ANIMATION: case IDC_ANIMATION:
if (HIWORD(wParam) == BN_CLICKED) { if (HIWORD(wParam) == BN_CLICKED) {
SetWindowText(GetDlgItem(hWnd, IDC_EXPORT_SELECTED), SetWindowText(GetDlgItem(hWnd, IDC_EXPORT_SELECTED),
"Export Bones:"); _T("Export Bones:"));
enableAnimRadios(hWnd, ANIM_RAD_ALL); enableAnimRadios(hWnd, ANIM_RAD_ALL);
showAnimControls(hWnd, TRUE); showAnimControls(hWnd, TRUE);
enableAnimControls(hWnd, IsDlgButtonChecked(hWnd, IDC_EXP_SEL_FRAMES)); enableAnimControls(hWnd, IsDlgButtonChecked(hWnd, IDC_EXP_SEL_FRAMES));
@ -314,7 +314,7 @@ INT_PTR CALLBACK MaxOptionsDialogProc( HWND hWnd, UINT message, WPARAM wParam, L
case IDC_BOTH: case IDC_BOTH:
if (HIWORD(wParam) == BN_CLICKED) { if (HIWORD(wParam) == BN_CLICKED) {
SetWindowText(GetDlgItem(hWnd, IDC_EXPORT_SELECTED), SetWindowText(GetDlgItem(hWnd, IDC_EXPORT_SELECTED),
"Export Models:"); _T("Export Models:"));
enableAnimRadios(hWnd, ANIM_RAD_ALL); enableAnimRadios(hWnd, ANIM_RAD_ALL);
showAnimControls(hWnd, TRUE); showAnimControls(hWnd, TRUE);
enableAnimControls(hWnd, IsDlgButtonChecked(hWnd, IDC_EXP_SEL_FRAMES)); enableAnimControls(hWnd, IsDlgButtonChecked(hWnd, IDC_EXP_SEL_FRAMES));
@ -328,7 +328,7 @@ INT_PTR CALLBACK MaxOptionsDialogProc( HWND hWnd, UINT message, WPARAM wParam, L
case IDC_POSE: case IDC_POSE:
if (HIWORD(wParam) == BN_CLICKED) { if (HIWORD(wParam) == BN_CLICKED) {
SetWindowText(GetDlgItem(hWnd, IDC_EXPORT_SELECTED), SetWindowText(GetDlgItem(hWnd, IDC_EXPORT_SELECTED),
"Export Meshes:"); _T("Export Meshes:"));
enableAnimRadios(hWnd, ANIM_RAD_EXPSEL); enableAnimRadios(hWnd, ANIM_RAD_EXPSEL);
showAnimControls(hWnd, FALSE); showAnimControls(hWnd, FALSE);
enableAnimControls(hWnd, TRUE); enableAnimControls(hWnd, TRUE);
@ -415,17 +415,17 @@ INT_PTR CALLBACK MaxOptionsDialogProc( HWND hWnd, UINT message, WPARAM wParam, L
return TRUE; break; return TRUE; break;
case IDC_BROWSE: case IDC_BROWSE:
OPENFILENAME ofn; OPENFILENAME ofn;
strcpy(tempFilename, GetICustEditT(GetDlgItem(hWnd, IDC_FILENAME))); _tcscpy(tempFilename, GetICustEditT(GetDlgItem(hWnd, IDC_FILENAME)));
memset(&ofn, 0, sizeof(ofn)); memset(&ofn, 0, sizeof(ofn));
ofn.nMaxFile = 2047; ofn.nMaxFile = 2047;
ofn.lpstrFile = tempFilename; ofn.lpstrFile = tempFilename;
ofn.lStructSize = sizeof(ofn); ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hWnd; ofn.hwndOwner = hWnd;
ofn.Flags = OFN_HIDEREADONLY | OFN_NOREADONLYRETURN | OFN_PATHMUSTEXIST; ofn.Flags = OFN_HIDEREADONLY | OFN_NOREADONLYRETURN | OFN_PATHMUSTEXIST;
ofn.lpstrDefExt = "egg"; ofn.lpstrDefExt = _T("egg");
ofn.lpstrFilter = "Panda3D Egg Files (*.egg)\0*.egg\0All Files (*.*)\0*.*\0"; ofn.lpstrFilter = _T("Panda3D Egg Files (*.egg)\0*.egg\0All Files (*.*)\0*.*\0");
SetFocus(GetDlgItem(hWnd, IDC_FILENAME)); SetFocus(GetDlgItem(hWnd, IDC_FILENAME));
if (GetSaveFileName(&ofn)) if (GetSaveFileName(&ofn))
SetICustEdit(hWnd, IDC_FILENAME, ofn.lpstrFile); SetICustEdit(hWnd, IDC_FILENAME, ofn.lpstrFile);
@ -437,9 +437,9 @@ INT_PTR CALLBACK MaxOptionsDialogProc( HWND hWnd, UINT message, WPARAM wParam, L
return TRUE; break; return TRUE; break;
case IDC_CHECK1: case IDC_CHECK1:
if (IsDlgButtonChecked(hWnd, IDC_CHECK1)) if (IsDlgButtonChecked(hWnd, IDC_CHECK1))
if (MessageBox(hWnd, "Warning: Exporting double-sided polygons can severely hurt " if (MessageBox(hWnd, _T("Warning: Exporting double-sided polygons can severely hurt ")
"performance in Panda3D.\n\nAre you sure you want to export them?", _T("performance in Panda3D.\n\nAre you sure you want to export them?"),
"Panda3D Exporter", MB_YESNO | MB_ICONQUESTION) != IDYES) _T("Panda3D Exporter"), MB_YESNO | MB_ICONQUESTION) != IDYES)
CheckDlgButton(hWnd, IDC_CHECK1, BST_UNCHECKED); CheckDlgButton(hWnd, IDC_CHECK1, BST_UNCHECKED);
return TRUE; break; return TRUE; break;
@ -533,7 +533,7 @@ bool MaxOptionsDialog::UpdateFromUI(HWND hWnd) {
BOOL valid; BOOL valid;
Anim_Type newAnimType; Anim_Type newAnimType;
int newSF = INT_MIN, newEF = INT_MIN; int newSF = INT_MIN, newEF = INT_MIN;
char msg[1024]; TCHAR msg[1024];
if (IsDlgButtonChecked(hWnd, IDC_MODEL)) newAnimType = MaxEggOptions::AT_model; if (IsDlgButtonChecked(hWnd, IDC_MODEL)) newAnimType = MaxEggOptions::AT_model;
else if (IsDlgButtonChecked(hWnd, IDC_ANIMATION)) newAnimType = MaxEggOptions::AT_chan; else if (IsDlgButtonChecked(hWnd, IDC_ANIMATION)) newAnimType = MaxEggOptions::AT_chan;
@ -543,56 +543,58 @@ bool MaxOptionsDialog::UpdateFromUI(HWND hWnd) {
if (newAnimType != MaxEggOptions::AT_model && IsDlgButtonChecked(hWnd, IDC_EXP_SEL_FRAMES)) { if (newAnimType != MaxEggOptions::AT_model && IsDlgButtonChecked(hWnd, IDC_EXP_SEL_FRAMES)) {
newSF = GetICustEditI(GetDlgItem(hWnd, IDC_SF), &valid); newSF = GetICustEditI(GetDlgItem(hWnd, IDC_SF), &valid);
if (!valid) { if (!valid) {
MessageBox(hWnd, "Start Frame must be an integer", "Invalid Value", MB_OK | MB_ICONEXCLAMATION); MessageBox(hWnd, _T("Start Frame must be an integer"), _T("Invalid Value"), MB_OK | MB_ICONEXCLAMATION);
return false; return false;
} }
if (newSF < _min_frame) { if (newSF < _min_frame) {
sprintf(msg, "Start Frame must be at least %d", _min_frame); _stprintf(msg, _T("Start Frame must be at least %d"), _min_frame);
MessageBox(hWnd, msg, "Invalid Value", MB_OK | MB_ICONEXCLAMATION); MessageBox(hWnd, msg, _T("Invalid Value"), MB_OK | MB_ICONEXCLAMATION);
return false; return false;
} }
if (newSF > _max_frame) { if (newSF > _max_frame) {
sprintf(msg, "Start Frame must be at most %d", _max_frame); _stprintf(msg, _T("Start Frame must be at most %d"), _max_frame);
MessageBox(hWnd, msg, "Invalid Value", MB_OK | MB_ICONEXCLAMATION); MessageBox(hWnd, msg, _T("Invalid Value"), MB_OK | MB_ICONEXCLAMATION);
return false; return false;
} }
if (newAnimType != MaxEggOptions::AT_pose) { if (newAnimType != MaxEggOptions::AT_pose) {
newEF = GetICustEditI(GetDlgItem(hWnd, IDC_EF), &valid); newEF = GetICustEditI(GetDlgItem(hWnd, IDC_EF), &valid);
if (!valid) { if (!valid) {
MessageBox(hWnd, "End Frame must be an integer", "Invalid Value", MB_OK | MB_ICONEXCLAMATION); MessageBox(hWnd, _T("End Frame must be an integer"), _T("Invalid Value"), MB_OK | MB_ICONEXCLAMATION);
return false; return false;
} }
if (newEF > _max_frame) { if (newEF > _max_frame) {
sprintf(msg, "End Frame must be at most %d", _max_frame); _stprintf(msg, _T("End Frame must be at most %d"), _max_frame);
MessageBox(hWnd, msg, "Invalid Value", MB_OK | MB_ICONEXCLAMATION); MessageBox(hWnd, msg, _T("Invalid Value"), MB_OK | MB_ICONEXCLAMATION);
return false; return false;
} }
if (newEF < newSF) { if (newEF < newSF) {
MessageBox(hWnd, "End Frame must be greater than the start frame", "Invalid Value", MB_OK | MB_ICONEXCLAMATION); MessageBox(hWnd, _T("End Frame must be greater than the start frame"), _T("Invalid Value"), MB_OK | MB_ICONEXCLAMATION);
return false; return false;
} }
} }
} }
char *temp = GetICustEditT(GetDlgItem(hWnd, IDC_FILENAME)); TCHAR *temp = GetICustEditT(GetDlgItem(hWnd, IDC_FILENAME));
if (!strlen(temp)) { if (!_tcslen(temp)) {
MessageBox(hWnd, "The filename cannot be empty", "Invalid Value", MB_OK | MB_ICONEXCLAMATION); MessageBox(hWnd, _T("The filename cannot be empty"), _T("Invalid Value"), MB_OK | MB_ICONEXCLAMATION);
return false; return false;
} }
if (strlen(temp) < 4 || strncmp(".egg", temp+(strlen(temp) - 4), 4)) if (_tcslen(temp) < 4 || _tcsncmp(_T(".egg"), temp+(_tcslen(temp) - 4), 4)) {
sprintf(_file_name, "%s.egg", temp); _stprintf(_file_name, _T("%s.egg"), temp);
else strcpy(_file_name, temp); } else {
_tcscpy(_file_name, temp);
}
temp = strrchr(_file_name, '\\'); temp = _tcsrchr(_file_name, '\\');
if (!temp) temp = _file_name; if (!temp) temp = _file_name;
else temp++; else temp++;
if (strlen(temp) > sizeof(_short_name)) if (_tcslen(temp) > sizeof(_short_name))
sprintf(_short_name, "%.*s...", sizeof(_short_name)-4, temp); _stprintf(_short_name, _T("%.*s..."), sizeof(_short_name)-4, temp);
else { else {
strcpy(_short_name, temp); _tcscpy(_short_name, temp);
_short_name[strlen(_short_name) - 4] = NULL; //Cut off the .egg _short_name[_tcslen(_short_name) - 4] = NULL; //Cut off the .egg
} }
_start_frame = newSF; _start_frame = newSF;

View File

@ -42,12 +42,12 @@ extern HINSTANCE hInstance;
void ChunkSave(ISave *isave, int chunkid, int value); void ChunkSave(ISave *isave, int chunkid, int value);
void ChunkSave(ISave *isave, int chunkid, bool value); void ChunkSave(ISave *isave, int chunkid, bool value);
void ChunkSave(ISave *isave, int chunkid, char *value); void ChunkSave(ISave *isave, int chunkid, char *value);
char *ChunkLoadString(ILoad *iload, char *buffer, int maxBytes); TCHAR *ChunkLoadString(ILoad *iload, TCHAR *buffer, int maxLength);
int ChunkLoadInt(ILoad *iload); int ChunkLoadInt(ILoad *iload);
bool ChunkLoadBool(ILoad *iload); bool ChunkLoadBool(ILoad *iload);
void SetICustEdit(HWND wnd, int nIDDlgItem, char *text); void SetICustEdit(HWND wnd, int nIDDlgItem, TCHAR *text);
INT_PTR CALLBACK MaxOptionsDialogProc( HWND hWnd, UINT message, INT_PTR CALLBACK MaxOptionsDialogProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam ); WPARAM wParam, LPARAM lParam );
struct MaxEggOptions struct MaxEggOptions
{ {
@ -71,16 +71,16 @@ struct MaxEggOptions
bool _successful; bool _successful;
bool _export_whole_scene; bool _export_whole_scene;
bool _export_all_frames; bool _export_all_frames;
char _file_name[2048]; TCHAR _file_name[2048];
char _short_name[256]; TCHAR _short_name[256];
PT(PathReplace) _path_replace; PT(PathReplace) _path_replace;
std::vector<ULONG> _node_list; std::vector<ULONG> _node_list;
}; };
class MaxOptionsDialog : public MaxEggOptions class MaxOptionsDialog : public MaxEggOptions
{ {
friend class MaxEggPlugin; friend class MaxEggPlugin;
public: public:
int _min_frame, _max_frame; int _min_frame, _max_frame;
bool _checked; bool _checked;
@ -89,24 +89,24 @@ class MaxOptionsDialog : public MaxEggOptions
MaxOptionsDialog(); MaxOptionsDialog();
~MaxOptionsDialog(); ~MaxOptionsDialog();
//All these List functions should probably take what list they need to operate on // All these List functions should probably take what list they need to operate on
//rather than just operating on a global list // rather than just operating on a global list
void SetMaxInterface(IObjParam *iface) { _max_interface = iface; } void SetMaxInterface(IObjParam *iface) { _max_interface = iface; }
void UpdateUI(HWND hWnd); void UpdateUI(HWND hWnd);
bool UpdateFromUI(HWND hWnd); bool UpdateFromUI(HWND hWnd);
void RefreshNodeList(HWND hWnd); void RefreshNodeList(HWND hWnd);
void SetAnimRange(); void SetAnimRange();
bool FindNode(ULONG INodeHandle); //returns true if the node is already in the list bool FindNode(ULONG INodeHandle); //returns true if the node is already in the list
void AddNode(ULONG INodeHandle); void AddNode(ULONG INodeHandle);
void RemoveNode(int i); void RemoveNode(int i);
void RemoveNodeByHandle(ULONG INodeHandle); void RemoveNodeByHandle(ULONG INodeHandle);
void ClearNodeList(HWND hWnd); void ClearNodeList(HWND hWnd);
void CullBadNodes(); void CullBadNodes();
ULONG GetNode(int i) { return (i >= 0 && i < _node_list.size()) ? _node_list[i] : ULONG_MAX; } ULONG GetNode(int i) { return (i >= 0 && i < _node_list.size()) ? _node_list[i] : ULONG_MAX; }
IOResult Load(ILoad *iload); IOResult Load(ILoad *iload);
IOResult Save(ISave *isave); IOResult Save(ISave *isave);
}; };

View File

@ -71,7 +71,13 @@ bool MaxToEggConverter::convert(MaxEggOptions *options) {
_options = options; _options = options;
Filename fn = Filename::from_os_specific(_options->_file_name); Filename fn;
#ifdef _UNICODE
fn = Filename::from_os_specific_w(_options->_file_name);
#else
fn = Filename::from_os_specific(_options->_file_name);
#endif
_options->_path_replace->_path_directory = fn.get_dirname(); _options->_path_replace->_path_directory = fn.get_dirname();
_egg_data = new EggData; _egg_data = new EggData;
@ -163,7 +169,11 @@ bool MaxToEggConverter::convert(MaxEggOptions *options) {
_options->_successful = all_ok; _options->_successful = all_ok;
if (all_ok) { if (all_ok) {
#ifdef _UNICODE
Filename fn = Filename::from_os_specific_w(_options->_file_name);
#else
Filename fn = Filename::from_os_specific(_options->_file_name); Filename fn = Filename::from_os_specific(_options->_file_name);
#endif
return _egg_data->write_egg(fn); return _egg_data->write_egg(fn);
} else { } else {
return false; return false;
@ -1016,7 +1026,6 @@ get_panda_material(Mtl *mtl, MtlID matID) {
pandaMat._color[2] = diffuseColor.z; pandaMat._color[2] = diffuseColor.z;
} }
if (!pandaMat._any_opacity) { if (!pandaMat._any_opacity) {
pandaMat._color[3] = (maxMaterial->GetOpacity(_current_frame * GetTicksPerFrame())); pandaMat._color[3] = (maxMaterial->GetOpacity(_current_frame * GetTicksPerFrame()));
} }
if (pandaMat._texture_list.size() < 1) { if (pandaMat._texture_list.size() < 1) {
@ -1027,7 +1036,7 @@ get_panda_material(Mtl *mtl, MtlID matID) {
} }
return pandaMat; return pandaMat;
} }
// Otherwise, it's unrecognizable. Leave result blank. // Otherwise, it's unrecognizable. Leave result blank.
return pandaMat; return pandaMat;
} }
@ -1038,7 +1047,7 @@ get_panda_material(Mtl *mtl, MtlID matID) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void MaxToEggConverter::analyze_diffuse_maps(PandaMaterial &pandaMat, Texmap *mat) { void MaxToEggConverter::analyze_diffuse_maps(PandaMaterial &pandaMat, Texmap *mat) {
if (mat == 0) return; if (mat == 0) return;
if (mat->ClassID() == Class_ID(RGBMULT_CLASS_ID, 0)) { if (mat->ClassID() == Class_ID(RGBMULT_CLASS_ID, 0)) {
for (int i=0; i<mat->NumSubTexmaps(); i++) { for (int i=0; i<mat->NumSubTexmaps(); i++) {
analyze_diffuse_maps(pandaMat, mat->GetSubTexmap(i)); analyze_diffuse_maps(pandaMat, mat->GetSubTexmap(i));
@ -1053,7 +1062,11 @@ void MaxToEggConverter::analyze_diffuse_maps(PandaMaterial &pandaMat, Texmap *ma
BitmapTex *diffuseTex = (BitmapTex *)mat; BitmapTex *diffuseTex = (BitmapTex *)mat;
Filename fullpath, outpath; Filename fullpath, outpath;
#ifdef _UNICDOE
Filename filename = Filename::from_os_specific_w(diffuseTex->GetMapName());
#else
Filename filename = Filename::from_os_specific(diffuseTex->GetMapName()); Filename filename = Filename::from_os_specific(diffuseTex->GetMapName());
#endif
_options->_path_replace->full_convert_path(filename, get_model_path(), _options->_path_replace->full_convert_path(filename, get_model_path(),
fullpath, outpath); fullpath, outpath);
tex->set_filename(outpath); tex->set_filename(outpath);
@ -1061,7 +1074,7 @@ void MaxToEggConverter::analyze_diffuse_maps(PandaMaterial &pandaMat, Texmap *ma
apply_texture_properties(*tex, diffuseTex->GetMapChannel()); apply_texture_properties(*tex, diffuseTex->GetMapChannel());
add_map_channel(pandaMat, diffuseTex->GetMapChannel()); add_map_channel(pandaMat, diffuseTex->GetMapChannel());
Bitmap *diffuseBitmap = diffuseTex->GetBitmap(0); Bitmap *diffuseBitmap = diffuseTex->GetBitmap(0);
if ( diffuseBitmap && diffuseBitmap->HasAlpha()) { if ( diffuseBitmap && diffuseBitmap->HasAlpha()) {
tex->set_format(EggTexture::F_rgba); tex->set_format(EggTexture::F_rgba);
@ -1069,7 +1082,7 @@ void MaxToEggConverter::analyze_diffuse_maps(PandaMaterial &pandaMat, Texmap *ma
tex->set_format(EggTexture::F_rgb); tex->set_format(EggTexture::F_rgb);
} }
tex->set_env_type(EggTexture::ET_modulate); tex->set_env_type(EggTexture::ET_modulate);
pandaMat._texture_list.push_back(tex); pandaMat._texture_list.push_back(tex);
} }
} }
@ -1094,7 +1107,11 @@ void MaxToEggConverter::analyze_opacity_maps(PandaMaterial &pandaMat, Texmap *ma
BitmapTex *transTex = (BitmapTex *)mat; BitmapTex *transTex = (BitmapTex *)mat;
Filename fullpath, outpath; Filename fullpath, outpath;
#ifdef _UNICODE
Filename filename = Filename::from_os_specific_w(transTex->GetMapName());
#else
Filename filename = Filename::from_os_specific(transTex->GetMapName()); Filename filename = Filename::from_os_specific(transTex->GetMapName());
#endif
_options->_path_replace->full_convert_path(filename, get_model_path(), _options->_path_replace->full_convert_path(filename, get_model_path(),
fullpath, outpath); fullpath, outpath);
@ -1146,7 +1163,11 @@ void MaxToEggConverter::analyze_glow_maps(PandaMaterial &pandaMat, Texmap *mat)
BitmapTex *gtex = (BitmapTex *)mat; BitmapTex *gtex = (BitmapTex *)mat;
Filename fullpath, outpath; Filename fullpath, outpath;
#ifdef _UNICODE
Filename filename = Filename::from_os_specific_w(gtex->GetMapName());
#else
Filename filename = Filename::from_os_specific(gtex->GetMapName()); Filename filename = Filename::from_os_specific(gtex->GetMapName());
#endif
_options->_path_replace->full_convert_path(filename, get_model_path(), _options->_path_replace->full_convert_path(filename, get_model_path(),
fullpath, outpath); fullpath, outpath);
@ -1191,7 +1212,11 @@ void MaxToEggConverter::analyze_gloss_maps(PandaMaterial &pandaMat, Texmap *mat)
BitmapTex *gtex = (BitmapTex *)mat; BitmapTex *gtex = (BitmapTex *)mat;
Filename fullpath, outpath; Filename fullpath, outpath;
#ifdef _UNICODE
Filename filename = Filename::from_os_specific_w(gtex->GetMapName());
#else
Filename filename = Filename::from_os_specific(gtex->GetMapName()); Filename filename = Filename::from_os_specific(gtex->GetMapName());
#endif
_options->_path_replace->full_convert_path(filename, get_model_path(), _options->_path_replace->full_convert_path(filename, get_model_path(),
fullpath, outpath); fullpath, outpath);
@ -1236,7 +1261,11 @@ void MaxToEggConverter::analyze_normal_maps(PandaMaterial &pandaMat, Texmap *mat
BitmapTex *ntex = (BitmapTex *)mat; BitmapTex *ntex = (BitmapTex *)mat;
Filename fullpath, outpath; Filename fullpath, outpath;
#ifdef _UNICODE
Filename filename = Filename::from_os_specific_w(ntex->GetMapName());
#else
Filename filename = Filename::from_os_specific(ntex->GetMapName()); Filename filename = Filename::from_os_specific(ntex->GetMapName());
#endif
_options->_path_replace->full_convert_path(filename, get_model_path(), _options->_path_replace->full_convert_path(filename, get_model_path(),
fullpath, outpath); fullpath, outpath);