void SaveState::saveGame() { updateStatus("STR_SAVING_GAME"); _game->getSavedGame()->setName(_edtSave->getText()); std::string oldFilename, newFilename; newFilename = CrossPlatform::sanitizeFilename(Language::wstrToFs(_edtSave->getText())); if (_selectedRow > 0) { oldFilename = _saves[_selectedRow-1].fileName; } else { while (CrossPlatform::fileExists(Options::getUserFolder() + newFilename + ".sav")) { newFilename += "_"; } oldFilename = newFilename; } quickSave(oldFilename); if (oldFilename != newFilename) { while (CrossPlatform::fileExists(Options::getUserFolder() + newFilename + ".sav")) { newFilename += "_"; } std::string oldPath = Options::getUserFolder() + oldFilename + ".sav"; std::string newPath = Options::getUserFolder() + newFilename + ".sav"; rename(oldPath.c_str(), newPath.c_str()); } _game->popState(); _game->popState(); }
/** * Saves the selected save. * @param action Pointer to an action. */ void SaveState::edtSaveKeyPress(Action *action) { if (action->getDetails()->key.keysym.sym == SDLK_RETURN || action->getDetails()->key.keysym.sym == SDLK_KP_ENTER) { updateStatus("STR_SAVING_GAME"); _game->getSavedGame()->setName(_edtSave->getText()); std::string oldFilename, newFilename; #ifdef _WIN32 newFilename = CrossPlatform::sanitizeFilename(Language::wstrToCp(_edtSave->getText())); #else newFilename = CrossPlatform::sanitizeFilename(Language::wstrToUtf8(_edtSave->getText())); #endif if (_selectedRow > 0) { oldFilename = CrossPlatform::noExt(_saves[_selectedRow-1]); } else { while (CrossPlatform::fileExists(Options::getUserFolder() + newFilename + ".sav")) { newFilename += "_"; } oldFilename = newFilename; } quickSave(oldFilename); if (oldFilename != newFilename) { while (CrossPlatform::fileExists(Options::getUserFolder() + newFilename + ".sav")) { newFilename += "_"; } std::string oldPath = Options::getUserFolder() + oldFilename + ".sav"; std::string newPath = Options::getUserFolder() + newFilename + ".sav"; rename(oldPath.c_str(), newPath.c_str()); } _game->popState(); _game->popState(); } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , m_ui(new Ui::MainWindow) , m_model(0) , m_controller(0) { // instantiate settings once here new Settings(this); // acces them later on via instance() /*Settings* s = Settings::instance(); qDebug() << "***** Current settings *****"; qDebug() << "Player name" << s->playerName(); qDebug() << "Player color" << s->playerColor(); qDebug(); qDebug() << "AI name" << s->aiName(); qDebug() << "AI color" << s->aiColor(); qDebug() << "AI level" << s->aiLevel(); qDebug();*/ m_ui->setupUi(this); m_ui->statusbar->setVisible(false); //connect actions to functions connect(m_ui->actionExit, SIGNAL(triggered()), QApplication::instance(), SLOT(quit())); connect(m_ui->action640x480, SIGNAL(triggered()), this, SLOT(resolutionChange())); connect(m_ui->action800x600, SIGNAL(triggered()), this, SLOT(resolutionChange())); connect(m_ui->action1920x1080, SIGNAL(triggered()), this, SLOT(resolutionChange())); connect(m_ui->actionPlayer, SIGNAL(triggered()), this, SLOT(openSettingsDialog())); connect(m_ui->actionNew_Game, SIGNAL(triggered()), this, SLOT(newGame())); connect(m_ui->actionQuicksave, SIGNAL(triggered()), this, SLOT(quickSave())); connect(m_ui->actionQuickload, SIGNAL(triggered()), this, SLOT(quickLoad())); connect(m_ui->actionImpressum_2, SIGNAL(triggered()), this, SLOT(showImpressum())); connect(m_ui->actionHow_to_play, SIGNAL(triggered()), this, SLOT(showRules())); setupGame(); }
/** * Creates the Quick Save Game state. * @param game Pointer to the core game. * @param origin Game section that originated this state. * @param showMsg True if need to show messages like "Loading game" or "Saving game". */ SaveState::SaveState(Game *game, OptionsOrigin origin, bool showMsg) : SavedGameState(game, origin, showMsg) { game->getSavedGame()->setName(L"autosave"); quickSave("autosave"); }
/** * Creates the Quick Save Game state. * @param game Pointer to the core game. * @param origin Game section that originated this state. * @param showMsg True if need to show messages like "Loading game" or "Saving game". */ SaveState::SaveState(Game *game, OptionsOrigin origin, bool showMsg) : SavedGameState(game, origin, showMsg) { quickSave(L"autosave"); }
MainState Game::run() { SDL_Event event; running = true; Uint32 fpsTicks = SDL_GetTicks(); Uint32 lastticks = fpsTicks; Desktop* desktop = dynamic_cast<Desktop*> (gui.get()); if(!desktop) { throw std::runtime_error("Toplevel component is not a Desktop");} gui->resize(getConfig()->videoX, getConfig()->videoY); int frame = 0; while(running) { getGameView()->scroll(); while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_VIDEORESIZE: initVideo(event.resize.w, event.resize.h); gui->resize(event.resize.w, event.resize.h); getConfig()->videoX = event.resize.w; getConfig()->videoY = event.resize.h; break; case SDL_KEYUP: { Event gui_event(event); if( gui_event.keysym.sym == SDLK_ESCAPE ){ getButtonPanel()->selectQueryTool(); break; } if( gui_event.keysym.sym == SDLK_b ){ getButtonPanel()->toggleBulldozeTool(); break; } /* //FIXME hack for monitoring constructionCount if( gui_event.keysym.sym == SDLK_c ){ std::cout << "ConstructionCount.size() = " << constructionCount.size() << std::endl; int i, j; for (i = 0, j = 0; i < constructionCount.size(); i++) {constructionCount[i]?j++:j;} std::cout << "for a total of " << j << " active constructions" << std::endl; break; } */ if( gui_event.keysym.sym == SDLK_p ){ static int i = 0; while(i < constructionCount.size() && !constructionCount[i]) {i++;} if (i < constructionCount.size()) { main_screen_originx = constructionCount[i]->x; main_screen_originy = constructionCount[i]->y; getGameView()->readOrigin(true); mps_set( main_screen_originx, main_screen_originy, MPS_MAP); mps_update(); mps_refresh(); i++; } else { i = 0; } break; } if( gui_event.keysym.sym == SDLK_F1 ){ helpWindow->showTopic("help"); break; } if( gui_event.keysym.sym == SDLK_F12 ){ quickSave(); break; } if( gui_event.keysym.sym == SDLK_F9 ){ quickLoad(); break; } #ifdef DEBUG if( gui_event.keysym.sym == SDLK_F5 ){ testAllHelpFiles(); break; } #endif int need_break=true; switch(gui_event.keysym.sym) { case SDLK_BACKQUOTE: getMiniMap()->mapViewChangeDisplayMode(MiniMap::NORMAL); break; case SDLK_1: getMiniMap()->mapViewChangeDisplayMode(MiniMap::STARVE); break; case SDLK_2: getMiniMap()->mapViewChangeDisplayMode(MiniMap::UB40); break; case SDLK_3: getMiniMap()->mapViewChangeDisplayMode(MiniMap::POWER); break; case SDLK_4: getMiniMap()->mapViewChangeDisplayMode(MiniMap::FIRE); break; case SDLK_5: getMiniMap()->mapViewChangeDisplayMode(MiniMap::CRICKET); break; case SDLK_6: getMiniMap()->mapViewChangeDisplayMode(MiniMap::HEALTH); break; case SDLK_7: getMiniMap()->mapViewChangeDisplayMode(MiniMap::TRAFFIC); break; case SDLK_8: getMiniMap()->mapViewChangeDisplayMode(MiniMap::POLLUTION); break; case SDLK_9: getMiniMap()->mapViewChangeDisplayMode(MiniMap::COAL); break; case SDLK_0: getMiniMap()->mapViewChangeDisplayMode(MiniMap::COMMODITIES); break; default: need_break=false; } if (need_break) break; gui->event(gui_event); break; } case SDL_MOUSEMOTION: case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: case SDL_KEYDOWN: { Event gui_event(event); gui->event(gui_event); break; } case SDL_ACTIVEEVENT: if( event.active.gain == 1 ){ gui->resize( gui->getWidth(), gui->getHeight() ); } break; case SDL_VIDEOEXPOSE: gui->resize( gui->getWidth(), gui->getHeight() ); break; case SDL_QUIT: saveCityNG( "9_currentGameNG.scn" ); running = false; quitState = QUIT; break; default: break; } } // create update Event Uint32 ticks = SDL_GetTicks(); float elapsedTime = ((float) (ticks - lastticks)) / 1000.0; gui->event(Event(elapsedTime)); lastticks = ticks; helpWindow->update(); if(desktop->needsRedraw()) { desktop->draw(*painter); flipScreenBuffer(); } frame++; // Slow down cpu consumption in pause mode if(ticks - fpsTicks > 1000 && lincitySpeed) { #ifdef DEBUG_FPS printf("FPS: %d.\n", (frame*1000) / (ticks - fpsTicks)); #endif getEconomyGraph()->newFPS( frame ); frame = 0; fpsTicks = ticks; } else if(!lincitySpeed) { frame = 0;} /* SDL_Delay is done in execute_timestep */ execute_timestep (); } return quitState; }