void MainWindow::on_filePath_textChanged(const QString &fileName) { QFile file(fileName); bool fileExists = file.exists(); if (!fileExists) { ui->filePath->setStyleSheet("color: red"); QColor tc = ui->infopanel->textColor(); // save ui->infopanel->setTextColor(QColor("red")); ui->feedback->setText("File input does not exists !"); ui->infopanel->setTextColor(tc); } else { ui->filePath->setStyleSheet("color: inherited"); ui->feedback->setText(""); ffprobeInfo(); loadPreview(); } ui->timeStart->setDisabled(!fileExists); ui->timeStop->setDisabled(!fileExists); ui->execute->setDisabled(!fileExists); ui->play->setDisabled(!fileExists); ui->pause->setDisabled(!fileExists); }
bool NpcEdit::loadFile(const QString &fileName, NPCConfigFile FileData) { QFile file(fileName); NpcData = FileData; if (!file.open(QFile::ReadOnly | QFile::Text)) { QMessageBox::warning(this, tr("Load file error"), tr("Cannot read file %1:\n%2.") .arg(fileName) .arg(file.errorString())); return false; } QFileInfo fileI(fileName); //Get NPC-ID from FileName npc_id = FileName_to_npcID(fileI.baseName()); setDefaultData(npc_id); ui->CurrentNPCID->setText( QString::number(npc_id) ); StartNPCData = NpcData; //Save current history for made reset setDataBoxes(); setCurrentFile(fileName); documentNotModified(); loadPreview(); on_DirectLeft_clicked(); return true; }
void KNMusicStandardBackend::playPreviewSection(const QString &fileName, const qint64 &start, const qint64 &duration) { //Load the music file first. loadPreview(fileName); //Turn on the smart volume. smartVolumeOn(); //Play the section m_preview->playSection(start, duration); }
void GameStateLoad::readGameSlot(int slot) { stringstream filename; FileParser infile; // abort if not a valid slot number if (slot < 0 || slot >= GAME_SLOT_MAX) return; // save slots are named save#.txt filename << "saves/save" << (slot+1) << ".txt"; if (!infile.open(filename.str())) return; while (infile.next()) { // load (key=value) pairs if (infile.key == "name") stats[slot].name = infile.val; else if (infile.key == "xp") stats[slot].xp = atoi(infile.val.c_str()); else if (infile.key == "build") { stats[slot].physical_character = atoi(infile.nextValue().c_str()); stats[slot].mental_character = atoi(infile.nextValue().c_str()); stats[slot].offense_character = atoi(infile.nextValue().c_str()); stats[slot].defense_character = atoi(infile.nextValue().c_str()); } else if (infile.key == "equipped") { equipped[slot][0] = atoi(infile.nextValue().c_str()); equipped[slot][1] = atoi(infile.nextValue().c_str()); equipped[slot][2] = atoi(infile.nextValue().c_str()); } else if (infile.key == "option") { stats[slot].base = infile.nextValue(); stats[slot].head = infile.nextValue(); stats[slot].portrait = infile.nextValue(); } else if (infile.key == "spawn") { current_map[slot] = getMapName(infile.nextValue()); } } infile.close(); stats[slot].recalc(); loadPreview(slot); }
bool NpcEdit::saveFile(const QString &fileName, const bool addToRecent) { QApplication::setOverrideCursor(Qt::WaitCursor); if(!FileFormats::WriteNPCTxtFileF(fileName, NpcData)) { QApplication::restoreOverrideCursor(); QMessageBox::warning(this, tr("File save error"), tr("Cannot save file %1:\n%2.") .arg(fileName) .arg(FileFormats::errorString)); return false; } GlobalSettings::savePath_npctxt = QFileInfo(fileName).path(); QFileInfo fileI(fileName); unsigned int old_npc_id = npc_id; npc_id = FileName_to_npcID(fileI.baseName()); setDefaultData(npc_id); ui->CurrentNPCID->setText( QString::number(npc_id) ); QApplication::restoreOverrideCursor(); setCurrentFile(fileName); documentNotModified(); if(old_npc_id == npc_id) { refreshImageFile(); updatePreview(); } else { loadPreview(); } if(addToRecent) { MainWinConnect::pMainWin->AddToRecentFiles(fileName); MainWinConnect::pMainWin->SyncRecentFiles(); } return true; }
void KNMusicDetailTooltip::enterEvent(QEvent *event) { //Do enter event first. QWidget::enterEvent(event); //Stop the disappear counter. m_fadeOutCounter->stop(); //Magic Interval: /* * Reduce the disappear timer interval. This is called magic interval, when * user move there mouse in and then move mouse out. */ m_fadeOutCounter->setInterval(ShortFadeOutTime); //Start mouse in animation. startAnime(m_mouseIn); //When mouse move in, it means user may want to preview the song, load the //music here. loadPreview(); //Set focus. setFocus(); }
void BlobGame::beginEditor(){ m_Camera->moveTo(0,0); SafePtrRelease(m_Editor); if(!m_GameObjects){ m_GameObjects = new std::vector<GameObject*>(); } m_Editing = false; DIR* dir; struct stat fileStat; struct dirent* dirp; std::string levelName; std::string filePath; unsigned int width; unsigned int height; UiButton* selectLevel = new UiButton(510,380,64,128,"Finished.png","FinishedS.png", FIRE_ON_RELEASED,m_Camera,loadEditor,NULL); m_GameObjects->push_back(selectLevel); m_LevelSelect = new UiListMenu(200,50,m_Camera,NULL,NULL,"tfa_squaresans.ttf",10,6); m_LevelSelect->setHeight(300); m_LevelSelect->setWidth(700); m_LevelSelect->addEntry("New Level"); selectLevel->setCallBackParam(m_LevelSelect); dir = opendir("levels"); if(dir == NULL){ std::cout << "Levels not found!" << std::endl; changeState(MainMenu); return; } while((dirp = readdir(dir))){ filePath = "levels/" + std::string(dirp->d_name); if(stat(filePath.c_str(),&fileStat)){continue;} if(S_ISDIR(fileStat.st_mode)){continue;} if(loadPreview(&levelName,&width,&height,filePath)){ m_LevelSelect->addEntry("Name :" + levelName + " Size : " + intToString(width) + " X " + intToString(height)); } } SafePtrRelease(dir); }
bool npcedit::loadFile(const QString &fileName, NPCConfigFile FileData) { QFile file(fileName); NpcData = FileData; if (!file.open(QFile::ReadOnly | QFile::Text)) { QMessageBox::warning(this, tr("Load file error"), tr("Cannot read file %1:\n%2.") .arg(fileName) .arg(file.errorString())); return false; } QFileInfo fileI(fileName); //Get NPC-ID from FileName QStringList tmp = fileI.baseName().split(QChar('-')); if(tmp.size()==2) if(!SMBX64::Int(tmp[1])) { npc_id = tmp[1].toInt(); setDefaultData( tmp[1].toInt() ); ui->CurrentNPCID->setText( tmp[1] ); } else setDefaultData(0); else setDefaultData(0); StartNPCData = NpcData; //Save current history for made reset setDataBoxes(); setCurrentFile(fileName); documentNotModified(); loadPreview(); on_DirectLeft_clicked(); return true; }
void npcedit::newFile(unsigned long npcID) { npc_id = npcID; static int sequenceNumber = 1; ui->CurrentNPCID->setText( QString::number(npcID) ); isUntitled = true; curFile = tr("npc-%1.txt").arg(npcID); setWindowTitle(curFile + QString(" [*] (%1)").arg(sequenceNumber++)); setDefaultData(npcID); NpcData = DefaultNPCData; // create data template StartNPCData = DefaultNPCData; setDataBoxes(); documentWasModified(); loadPreview(); /*connect(document(), SIGNAL(contentsChanged()), this, SLOT(documentWasModified()));*/ }
void GameStateLoad::readGameSlots() { FileParser infile; std::stringstream filename; std::vector<std::string> save_dirs; getDirList(PATH_USER + "saves/" + SAVE_PREFIX, save_dirs); std::sort(save_dirs.begin(), save_dirs.end(), compareSaveDirs); game_slots.resize(save_dirs.size(), NULL); visible_slots = (game_slot_max > static_cast<int>(game_slots.size()) ? static_cast<int>(game_slots.size()) : game_slot_max); for (size_t i=0; i<save_dirs.size(); ++i){ // save data is stored in slot#/avatar.txt filename.str(""); filename << PATH_USER << "saves/" << SAVE_PREFIX << "/" << save_dirs[i] << "/avatar.txt"; if (!infile.open(filename.str(),false)) continue; game_slots[i] = new GameSlot(); game_slots[i]->id = toInt(save_dirs[i]); while (infile.next()) { // load (key=value) pairs if (infile.key == "name") game_slots[i]->stats.name = infile.val; else if (infile.key == "class") { game_slots[i]->stats.character_class = popFirstString(infile.val); game_slots[i]->stats.character_subclass = popFirstString(infile.val); } else if (infile.key == "xp") game_slots[i]->stats.xp = toInt(infile.val); else if (infile.key == "build") { for (size_t j = 0; j < PRIMARY_STATS.size(); ++j) { game_slots[i]->stats.primary[j] = popFirstInt(infile.val); } } else if (infile.key == "equipped") { std::string repeat_val = popFirstString(infile.val); while (repeat_val != "") { game_slots[i]->equipped.push_back(toInt(repeat_val)); repeat_val = popFirstString(infile.val); } } else if (infile.key == "option") { game_slots[i]->stats.gfx_base = popFirstString(infile.val); game_slots[i]->stats.gfx_head = popFirstString(infile.val); game_slots[i]->stats.gfx_portrait = popFirstString(infile.val); } else if (infile.key == "spawn") { game_slots[i]->current_map = getMapName(popFirstString(infile.val)); } else if (infile.key == "permadeath") { game_slots[i]->stats.permadeath = toBool(infile.val); } } infile.close(); game_slots[i]->stats.recalc(); game_slots[i]->stats.direction = 6; game_slots[i]->preview.setStatBlock(&(game_slots[i]->stats)); loadPreview(game_slots[i]); } }
void BlobGame::handleMessage(const Message& msg){ switch(msg.type){ case 2:{ Unit* unit = (Unit*)msg.extraInfo; for(int i = 0;i < m_GameObjects->size();i++){ if((*m_GameObjects)[i] == unit){ m_GameObjects->erase(m_GameObjects->begin()+i); SafePtrRelease(unit); return; } } break; } case PISTOL_ATTACK:{ Unit* unit; Tile* tile = (Tile*)msg.extraInfo; if((unit = unitOnTile(tile))){ unit->hit(PISTOL_DAMAGE); MessageHandler::Instance()->deleteMessage(msg.name); } break; } case REMOVE_TILE_EFFECT:{ Tile* tile = (Tile*)msg.extraInfo; unsigned int tileStatuses = tile->getTileTypes(); if(msg.name == "Fire"){ if(ContainsFlags(tile->getTileTypes(),Fire)){ RemoveFlag(&tileStatuses,Fire); tile->setTileTypes(tileStatuses); } } else if(msg.name == "Posion"){ if(ContainsFlags(tile->getTileTypes(),Posion)){ RemoveFlag(&tileStatuses,Posion); tile->setTileTypes(tileStatuses); } } else if(msg.name == "Slime"){ if(ContainsFlags(tile->getTileTypes(),Slime)){ RemoveFlag(&tileStatuses,Slime); tile->setTileTypes(tileStatuses); } } for(int i = 0;i < m_Effects->size();i++){ if((*m_Effects)[i]->getName() == (msg.name + "_" + tile->getName())){ Sprite2d* sprite = (*m_Effects)[i]; m_Effects->erase(m_Effects->begin()+i); SpriteManager::instance()->deleteSprite(sprite); } } } case 5:{ for(int i = 0;i < m_GameObjects->size();i++){ if((*m_GameObjects)[i]->getName() == msg.name){ Enemy* enemy = (Enemy*)(*m_GameObjects)[i]; enemy->hold(); return; } } break; } case 6:{ for(int i = 0;i < m_GameObjects->size();i++){ if((*m_GameObjects)[i]->getName() == msg.name){ Unit* unit = (Unit*)(*m_GameObjects)[i]; unit->hit(unit->getHealth()); return; } } break; } case REMOVE_UNIT_STATUS:{ Unit* unit = (Unit*)msg.extraInfo; unsigned int unitStatuses = unit->getStatus(); if(msg.name == "Fire"){ if(ContainsFlags(unit->getStatus(),OnFire)){ RemoveFlag(&unitStatuses,OnFire); unit->setStatus(unitStatuses); } } else if(msg.name == "Posioned"){ if(ContainsFlags(unit->getStatus(),Posioned)){ RemoveFlag(&unitStatuses,Posioned); unit->setStatus(unitStatuses); } } else if(msg.name == "Slowed"){ if(ContainsFlags(unit->getStatus(),Slowed)){ RemoveFlag(&unitStatuses,Slowed); unit->setStatus(unitStatuses); } } break; } case CHANGE_STATE:{ int s = (int)msg.extraInfo; changeState((BlobGameStates)s); break; } case LOAD_LEVEL_EDITOR:{ if(m_CurrentState == Editor){ int level = (int)msg.extraInfo - 1; if(level < 0){ int tileTypes[MAX_HORIZONTAL_TILES*MAX_VERTICAL_TILES]; for(int i = 0;i < (MAX_HORIZONTAL_TILES*MAX_VERTICAL_TILES);i++){ tileTypes[i] = Empty; } Level* newLevel = new Level(MAX_HORIZONTAL_TILES,MAX_VERTICAL_TILES, TILE_SIZE,tileTypes,NULL,NULL); m_Editor = new LevelEditor(newLevel,m_Camera); m_Editing = true; SafePtrRelease(m_LevelSelect); if(m_GameObjects != NULL){ SafeVectorDelete((*m_GameObjects)); SafePtrRelease(m_GameObjects); } return; } else{ DIR* dir; struct stat fileStat; struct dirent* dirp; std::string levelName; std::string filePath; unsigned int width; unsigned int height; int i = 0; dir = opendir("levels"); if(dir == NULL){ std::cout << "Levels not found!" << std::endl; return; } while(i <= level && (dirp = readdir(dir))){ filePath = "levels/" + std::string(dirp->d_name); if(stat(filePath.c_str(),&fileStat)){continue;} if(S_ISDIR(fileStat.st_mode)){continue;} if(loadPreview(&levelName,&width,&height,filePath)){ if(i == level){ m_Editing = true; m_Editor = new LevelEditor(NULL,m_Camera); m_Editor->loadLevelToEditor(filePath); SafePtrRelease(dir); SafePtrRelease(m_LevelSelect); if(m_GameObjects != NULL){ SafeVectorDelete((*m_GameObjects)); SafePtrRelease(m_GameObjects); } return; } else{ i++; } } } } break; } } case LOAD_LEVEL:{ if(m_CurrentState == LevelSelect){ int level = (int)msg.extraInfo; if(level >= 0){ DIR* dir; struct stat fileStat; struct dirent* dirp; std::string levelName; std::string filePath; unsigned int width; unsigned int height; int i = 0; dir = opendir("levels"); if(dir == NULL){ std::cout << "Levels not found!" << std::endl; return; } while(i <= level && (dirp = readdir(dir))){ filePath = "levels/" + std::string(dirp->d_name); if(stat(filePath.c_str(),&fileStat)){continue;} if(S_ISDIR(fileStat.st_mode)){continue;} if(loadPreview(&levelName,&width,&height,filePath)){ if(i == level){ SafePtrRelease(dir); changeGameState((void*)GamePlay); m_LevelToLoad = filePath; return; } else{ i++; } } } } break; } } default: break; } }
void GameStateLoad::logic() { frame_ticker++; if (frame_ticker == 64) frame_ticker = 0; if (frame_ticker < 32) current_frame = frame_ticker / 8; else current_frame = (63 - frame_ticker) / 8; if (button_exit->checkClick()) { requestedGameState = new GameStateTitle(screen, inp, font, msg); } if(loading_requested) { loading = true; loading_requested = false; logicLoading(); } if (button_action->checkClick()) { if (stats[selected_slot].name == "") { // create a new game GameStateNew* newgame = new GameStateNew(screen, inp, font, msg); newgame->game_slot = selected_slot + 1; requestedGameState = newgame; } else { loading_requested = true; } } if (button_alternate->checkClick()) { // Display pop-up to make sure save should be deleted confirm->visible = true; confirm->render(); } if (confirm->visible) { confirm->logic(); if(confirm->confirmClicked) { stringstream filename; filename << PATH_USER << "save" << (selected_slot+1) << ".txt"; if(remove(filename.str().c_str()) != 0) perror("Error deleting save from path"); stats[selected_slot] = StatBlock(); readGameSlot(selected_slot); loadPreview(selected_slot); loadPortrait(selected_slot); button_alternate->enabled = false; button_action->label = msg->get("new_game_button"); confirm->visible = false; confirm->confirmClicked = false; } } // check clicking game slot if (inp->pressing[MAIN1] && !inp->lock[MAIN1]) { for (int i=0; i<GAME_SLOT_MAX; i++) { if (isWithin(slot_pos[i], inp->mouse)) { selected_slot = i; inp->lock[MAIN1] = true; loadPortrait(selected_slot); button_action->enabled = true; if (stats[selected_slot].name == "") { button_action->label = msg->get("new_game_button"); button_alternate->enabled = false; } else { button_action->label = msg->get("load_game_button"); button_alternate->enabled = true; } } } } }