- bugfixes for map editor and file extension function

This commit is contained in:
Mark Vejvoda 2011-05-24 01:44:48 +00:00
parent 821e159b05
commit e10df0affe
3 changed files with 47 additions and 12 deletions

View File

@ -251,6 +251,9 @@ int App::MainLoop(){
} }
int App::OnExit(){ int App::OnExit(){
SystemFlags::Close();
SystemFlags::SHUTDOWN_PROGRAM_MODE=true;
return 0; return 0;
} }

View File

@ -391,7 +391,12 @@ void MainWindow::init(string fname) {
//program = new Program(glCanvas->GetClientSize().x, glCanvas->GetClientSize().y); //program = new Program(glCanvas->GetClientSize().x, glCanvas->GetClientSize().y);
fileName = "New (unsaved) Map"; fileName = "New (unsaved) Map";
if (!fname.empty() && fileExists(fname)) {
//printf("Does file exist, fname [%s]\n",fname.c_str());
if (fname.empty() == false && fileExists(fname)) {
//printf("YES file exist, fname [%s]\n",fname.c_str());
//program->loadMap(fname); //program->loadMap(fname);
currentFile = fname; currentFile = fname;
fileName = cutLastExt(extractFileFromDirectoryPath(fname.c_str())); fileName = cutLastExt(extractFileFromDirectoryPath(fname.c_str()));
@ -400,6 +405,11 @@ void MainWindow::init(string fname) {
SetTitle(ToUnicode(currentFile + " - " + winHeader)); SetTitle(ToUnicode(currentFile + " - " + winHeader));
//setDirty(false); //setDirty(false);
//setExtension(); //setExtension();
if(startupSettingsInited == false) {
startupSettingsInited = true;
setupStartupSettings();
}
} }
void MainWindow::onClose(wxCloseEvent &event) { void MainWindow::onClose(wxCloseEvent &event) {
@ -415,7 +425,12 @@ void MainWindow::setupStartupSettings() {
program = new Program(glCanvas->GetClientSize().x, glCanvas->GetClientSize().y); program = new Program(glCanvas->GetClientSize().x, glCanvas->GetClientSize().y);
fileName = "New (unsaved) Map"; fileName = "New (unsaved) Map";
//printf("#0 file load [%s]\n",currentFile.c_str());
if (!currentFile.empty() && fileExists(currentFile)) { if (!currentFile.empty() && fileExists(currentFile)) {
//printf("#0 exists file load [%s]\n",currentFile.c_str());
program->loadMap(currentFile); program->loadMap(currentFile);
//currentFile = fname; //currentFile = fname;
fileName = cutLastExt(extractFileFromDirectoryPath(currentFile.c_str())); fileName = cutLastExt(extractFileFromDirectoryPath(currentFile.c_str()));
@ -452,14 +467,19 @@ void MainWindow::setExtension() {
if (currentFile.empty() || program == NULL) { if (currentFile.empty() || program == NULL) {
return; return;
} }
string extnsn = ext(currentFile); string extnsn = ext(currentFile);
//printf("#A currentFile [%s] extnsn [%s]\n",currentFile.c_str(),extnsn.c_str());
if (extnsn == "gbm" || extnsn == "mgm") { if (extnsn == "gbm" || extnsn == "mgm") {
currentFile = cutLastExt(currentFile); currentFile = cutLastExt(currentFile);
} }
if (Program::getMap()->getMaxFactions() <= 4) { if (Program::getMap()->getMaxFactions() <= 4) {
SetStatusText(wxT(".gbm"), siFILE_TYPE); SetStatusText(wxT(".gbm"), siFILE_TYPE);
currentFile += ".gbm"; currentFile += ".gbm";
} else { }
else {
SetStatusText(wxT(".mgm"), siFILE_TYPE); SetStatusText(wxT(".mgm"), siFILE_TYPE);
currentFile += ".mgm"; currentFile += ".mgm";
} }
@ -549,11 +569,6 @@ void MainWindow::onPaint(wxPaintEvent &event) {
glCanvas->setCurrentGLContext(); glCanvas->setCurrentGLContext();
#endif #endif
if(startupSettingsInited == false) {
startupSettingsInited = true;
setupStartupSettings();
}
if(lastPaintEvent.getMillis() < 30) { if(lastPaintEvent.getMillis() < 30) {
sleep(1); sleep(1);
return; return;
@ -591,9 +606,14 @@ void MainWindow::onMenuFileLoad(wxCommandEvent &event) {
std::auto_ptr<wchar_t> wstr(Ansi2WideString(currentFile.c_str())); std::auto_ptr<wchar_t> wstr(Ansi2WideString(currentFile.c_str()));
currentFile = utf8_encode(wstr.get()); currentFile = utf8_encode(wstr.get());
#else #else
currentFile = fileDialog->GetPath().ToAscii(); //currentFile = fileDialog->GetPath().ToAscii();
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath());
currentFile = tmp_buf;
#endif #endif
//printf("#1 file load [%s]\n",currentFile.c_str());
program->loadMap(currentFile); program->loadMap(currentFile);
fileName = cutLastExt(extractFileFromDirectoryPath(currentFile.c_str())); fileName = cutLastExt(extractFileFromDirectoryPath(currentFile.c_str()));
setDirty(false); setDirty(false);
@ -618,9 +638,12 @@ void MainWindow::onMenuFileSave(wxCommandEvent &event) {
if (currentFile.empty()) { if (currentFile.empty()) {
wxCommandEvent ev; wxCommandEvent ev;
onMenuFileSaveAs(ev); onMenuFileSaveAs(ev);
} else { }
else {
setExtension(); setExtension();
//printf("#1 save load [%s]\n",currentFile.c_str());
program->saveMap(currentFile); program->saveMap(currentFile);
setDirty(false); setDirty(false);
} }
@ -659,11 +682,16 @@ void MainWindow::onMenuFileSaveAs(wxCommandEvent &event) {
std::auto_ptr<wchar_t> wstr(Ansi2WideString(currentFile.c_str())); std::auto_ptr<wchar_t> wstr(Ansi2WideString(currentFile.c_str()));
currentFile = utf8_encode(wstr.get()); currentFile = utf8_encode(wstr.get());
#else #else
currentFile = fd.GetPath().ToAscii(); //currentFile = fd.GetPath().ToAscii();
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fd.GetPath());
currentFile = tmp_buf;
#endif #endif
fileDialog->SetPath(fd.GetPath()); fileDialog->SetPath(fd.GetPath());
setExtension(); setExtension();
//printf("#2 file save [%s]\n",currentFile.c_str());
program->saveMap(currentFile); program->saveMap(currentFile);
fileName = cutLastExt(extractFileFromDirectoryPath(currentFile.c_str())); fileName = cutLastExt(extractFileFromDirectoryPath(currentFile.c_str()));
setDirty(false); setDirty(false);
@ -1440,6 +1468,7 @@ bool SimpleDialog::show(const string &title, bool wide) {
bool App::OnInit() { bool App::OnInit() {
SystemFlags::VERBOSE_MODE_ENABLED = true; SystemFlags::VERBOSE_MODE_ENABLED = true;
SystemFlags::ENABLE_THREADED_LOGGING = false;
string fileparam; string fileparam;
if(argc==2){ if(argc==2){
@ -1520,6 +1549,9 @@ int App::MainLoop() {
} }
int App::OnExit() { int App::OnExit() {
SystemFlags::Close();
SystemFlags::SHUTDOWN_PROGRAM_MODE=true;
return 0; return 0;
} }

View File

@ -654,8 +654,8 @@ string ext(const string &s) {
i=s.find_last_of('.')+1; i=s.find_last_of('.')+1;
if (i == string::npos) { if (i != string::npos) {
throw runtime_error(string(__FILE__) + " line: " + intToStr(__LINE__) + " i==string::npos for [" + s + "]"); //throw runtime_error(string(__FILE__) + " line: " + intToStr(__LINE__) + " i==string::npos for [" + s + "]");
//} //}
return (s.substr(i, s.size()-i)); return (s.substr(i, s.size()-i));
} }