Esempio n. 1
0
// //////////////////////////////////////////////////////////////
void MainWindow::on_actionAnimation_triggered(bool checked)
{
    GlobalSettings::LvlOpts.animationEnabled = checked;
    if (activeChildWindow()==1)
    {
        activeLvlEditWin()->scene->opts.animationEnabled = GlobalSettings::LvlOpts.animationEnabled;
        if(GlobalSettings::LvlOpts.animationEnabled)
        {
            activeLvlEditWin()->scene->startAnimation();
        }
        else
            activeLvlEditWin()->scene->stopAnimation();
    }
    else
    if (activeChildWindow()==3)
    {
        activeWldEditWin()->scene->opts.animationEnabled = GlobalSettings::LvlOpts.animationEnabled;
        if(GlobalSettings::LvlOpts.animationEnabled)
        {
            activeWldEditWin()->scene->startAnimation();
        }
        else
            activeWldEditWin()->scene->stopAnimation();
    }
}
Esempio n. 2
0
// //////////////////////////////////////////////////////////////
void MainWindow::on_actionAnimation_triggered(bool checked)
{
    GlobalSettings::LvlOpts.animationEnabled = checked;
    if(activeChildWindow() == WND_Level)
    {
        LevelEdit *e=activeLvlEditWin(); if(!e) return;
        LvlScene  *s=e->scene; if(!s) return;
        if(GlobalSettings::LvlOpts.animationEnabled)
            s->startAnimation();
        else
            s->stopAnimation();
        s->m_opts.animationEnabled = GlobalSettings::LvlOpts.animationEnabled;
    }
    else
    if(activeChildWindow() == WND_World)
    {
        activeWldEditWin()->scene->m_opts.animationEnabled = GlobalSettings::LvlOpts.animationEnabled;
        if(GlobalSettings::LvlOpts.animationEnabled)
        {
            activeWldEditWin()->scene->startAnimation();
        }
        else
            activeWldEditWin()->scene->stopAnimation();
    }
}
Esempio n. 3
0
void MainWindow::on_actionSemi_transparent_paths_triggered(bool checked)
{
    GlobalSettings::LvlOpts.semiTransparentPaths = checked;
    if(activeChildWindow()==3)
    {
        activeWldEditWin()->scene->opts.semiTransparentPaths = GlobalSettings::LvlOpts.semiTransparentPaths;
        activeWldEditWin()->scene->setSemiTransparentPaths(GlobalSettings::LvlOpts.semiTransparentPaths);
    }

}
Esempio n. 4
0
//Paste
void MainWindow::on_actionPaste_triggered()
{
    if (activeChildWindow()==1)
    {
        LevelData tmp;
        QString raw=QApplication::clipboard()->text();
        if( FileFormats::ReadExtendedLvlFileRaw(raw, "<clipboard>", tmp) )
        {
            LvlBuffer = tmp;
        }

        if
        (   //if buffer is empty
                (LvlBuffer.blocks.size()==0)&&
                (LvlBuffer.bgo.size()==0)&&
                (LvlBuffer.npc.size()==0)&&
                (LvlBuffer.physez.size()==0)
        ) return;
    }
    else
    if (activeChildWindow()==3)
    {
        WorldData tmp;
        QString raw = QApplication::clipboard()->text();
        if( FileFormats::ReadExtendedWldFileRaw(raw, "<clipboard>", tmp) )
        {
            WldBuffer = tmp;
        }

        if
        (   //if buffer is empty
                (WldBuffer.tiles.size()==0)&&
                (WldBuffer.scenery.size()==0)&&
                (WldBuffer.paths.size()==0)&&
                (WldBuffer.levels.size()==0)&&
                (WldBuffer.music.size()==0)
        ) return;
    }

    resetEditmodeButtons();
    ui->actionSelect->setChecked(1);

    if (activeChildWindow()==1)
    {
       activeLvlEditWin()->scene->SwitchEditingMode(LvlScene::MODE_PasteFromClip);
       activeLvlEditWin()->scene->m_dataBuffer = LvlBuffer;
    }
    else
    if (activeChildWindow()==3)
    {
       activeWldEditWin()->scene->SwitchEditingMode(LvlScene::MODE_PasteFromClip);
       activeWldEditWin()->scene->WldBuffer = WldBuffer;
    }

}
Esempio n. 5
0
void MainWindow::on_actionRotateRight_triggered()
{
    if(activeChildWindow()==1)
    {
        activeLvlEditWin()->scene->rotateGroup(
                    activeLvlEditWin()->scene->selectedItems(), true  );
    }
    else
    if(activeChildWindow()==3)
    {
        activeWldEditWin()->scene->rotateGroup(
                    activeWldEditWin()->scene->selectedItems(), true   );
    }
}
Esempio n. 6
0
void MainWindow::on_actionFlipVertical_triggered()
{
    if(activeChildWindow()==1)
    {
        activeLvlEditWin()->scene->flipGroup(
                    activeLvlEditWin()->scene->selectedItems(), true  );
    }
    else
    if(activeChildWindow()==3)
    {
        activeWldEditWin()->scene->flipGroup(
                    activeWldEditWin()->scene->selectedItems(), true  );
    }
}
void MainWindow::on_action_doTestWld_triggered()
{
    /*
        FIXME!!! Implement the right world map testing via interprocess
        with ability to start player at absolutely any position on it
    */
    if(activeChildWindow() == WND_World)
    {
        WorldEdit *we = activeWldEditWin();
        if(!we->isUntitled() && we->isModified())
        {
            QMessageBox::StandardButton reply =
                QMessageBox::question(this,
                                      tr("World map testing of saved file"),
                                      tr("File is not saved!\n"
                                         "Do you want to save file or you want to run test "
                                         "of copy which is currently saved on the disk?"),
                                      QMessageBox::Yes | QMessageBox::No | QMessageBox::Abort);
            if(reply == QMessageBox::Yes)
            {
                if(!we->save())
                    return;
            }
            else if(reply != QMessageBox::No)
                return;
        }
        on_action_doSafeTest_triggered();
    }
}
Esempio n. 8
0
//Cut
void MainWindow::on_actionCut_triggered()
{
    int q1=0, q2=0, q3=0, q4=0, q5=0;
    if (activeChildWindow()==1) //if active window is a levelEditor
    {
       LvlBuffer=activeLvlEditWin()->scene->copy(true);
       q1 += LvlBuffer.blocks.size();
       q2 += LvlBuffer.bgo.size();
       q3 += LvlBuffer.npc.size();
       q4 += LvlBuffer.physez.size();
       statusBar()->showMessage(tr("%1 blocks, %2 BGO, %3 NPC, %4 Water items have been moved to clipboard").arg(q1).arg(q2).arg(q3).arg(q4), 2000);
       QString raw;
       FileFormats::WriteExtendedLvlFileRaw(LvlBuffer, raw);
       QApplication::clipboard()->setText(raw);
    }
    else
    if (activeChildWindow()==3) //if active window is a worldEditor
    {
       WldBuffer=activeWldEditWin()->scene->copy(true);
       q1 += WldBuffer.tiles.size();
       q2 += WldBuffer.scenery.size();
       q3 += WldBuffer.paths.size();
       q4 += WldBuffer.levels.size();
       q5 += WldBuffer.music.size();
       statusBar()->showMessage(tr("%1 tiles, %2 sceneries, %3 paths, %4 levels, %5 music boxes items have been moved to clipboard").arg(q1).arg(q2).arg(q3).arg(q4).arg(q5), 2000);
       QString raw;
       FileFormats::WriteExtendedWldFileRaw(WldBuffer, raw);
       QApplication::clipboard()->setText(raw);
    }
}
Esempio n. 9
0
void MainWindow::on_actionLockMusicBoxes_triggered(bool checked)
{
    if (activeChildWindow()==3)
    {
        activeWldEditWin()->scene->setLocked(5, checked);
    }
}
Esempio n. 10
0
void MainWindow::on_actionAlign_selected_triggered()
{

    if(activeChildWindow()==1)
    {
        activeLvlEditWin()->scene->applyGridToEach(
                    activeLvlEditWin()->scene->selectedItems()   );
    }
    else
    if(activeChildWindow()==3)
    {
        activeWldEditWin()->scene->applyGridToEach(
                    activeWldEditWin()->scene->selectedItems()   );
    }

}
Esempio n. 11
0
void MainWindow::on_actionNewWorld_map_triggered()
{
    //Check if data configs are valid
    if( configs.check() )
    {
        WriteToLog(QtCriticalMsg, QString("Error! *.INI configs not loaded"));
        QMessageBox::warning(this, tr("Configuration is loaded with errors"),
                             tr("Cannot create world map file:\nConfiguration package loaded with errors.").arg(ConfStatus::configPath));
        //Show configuration status window
        on_actionCurConfig_triggered();
        return;
    }

    WorldEdit *child = createWldChild();
    if(child->newFile(configs, GlobalSettings::LvlOpts))
    {
        child->show();
        child->updateGeometry();
        child->ResetPosition();
        updateMenus(true);
        on_actionSelect_triggered();
    } else {
        child->show();
        if(activeChildWindow()==3) activeWldEditWin()->WldData.modified = false;
        ui->centralWidget->activeSubWindow()->close();
    }
}
Esempio n. 12
0
void MainWindow::on_actionZoomReset_triggered()
{
    if(activeChildWindow()==1)
        activeLvlEditWin()->ResetZoom();
    else
    if(activeChildWindow()==3)
        activeWldEditWin()->ResetZoom();
}
Esempio n. 13
0
void MainWindow::on_actionLockLevels_triggered(bool checked)
{
    if (activeChildWindow()==3)
    {
        WorldEdit *e=activeWldEditWin();
        if(e) e->scene->setLocked(4, checked);
    }
}
Esempio n. 14
0
// //////////////////////////////////////////////////////////////
void MainWindow::on_actionGridEn_triggered(bool checked)
{
    if (activeChildWindow()==1)
    {
       activeLvlEditWin()->scene->grid = checked;
    }
    else
    if (activeChildWindow()==3)
    {
       activeWldEditWin()->scene->grid = checked;
    }
}
Esempio n. 15
0
void MainWindow::on_actionResizeCancel_triggered()
{
    if (activeChildWindow()==1)
    {
        activeLvlEditWin()->scene->resetResizers();;
    }
    else
    if (activeChildWindow()==3)
    {
        activeWldEditWin()->scene->resetResizers();
    }
    ui->ResizingToolbar->setVisible(false);
}
Esempio n. 16
0
void MainWindow::on_actionCollisions_triggered(bool checked)
{
    GlobalSettings::LvlOpts.collisionsEnabled = checked;
    if(activeChildWindow() == WND_Level)
    {
        activeLvlEditWin()->scene->m_opts.collisionsEnabled = GlobalSettings::LvlOpts.collisionsEnabled;
    }
    else
    if(activeChildWindow() == WND_World)
    {
        activeWldEditWin()->scene->m_opts.collisionsEnabled = GlobalSettings::LvlOpts.collisionsEnabled;
    }
}
Esempio n. 17
0
void MainWindow::applyTextZoom()
{
    bool ok = false;
    int zoomPercent = 100;
    zoomPercent = zoom->text().toInt(&ok);
    if(!ok)
        return;

    if(activeChildWindow()==1){
        activeLvlEditWin()->setZoom(zoomPercent);
    }else if(activeChildWindow()==3){
        activeWldEditWin()->setZoom(zoomPercent);
    }
}
Esempio n. 18
0
// //////////////////////////////////////////////////////////////
void MainWindow::on_actionGridEn_triggered(bool checked)
{
    if(activeChildWindow() == WND_Level)
    {
        LevelEdit *e = activeLvlEditWin();
        assert(e);
        e->scene->m_opts.grid_snap = checked;
    }
    else
    if(activeChildWindow() == WND_World)
    {
        WorldEdit *e = activeWldEditWin();
        assert(e);
        e->scene->m_opts.grid_snap = checked;
    }
}
Esempio n. 19
0
void MainWindow::on_actionSelectOnly_triggered()
{
    resetEditmodeButtons();
    ui->actionSelectOnly->setChecked(1);

    ui->ItemProperties->hide();

    if ((activeChildWindow()==1) && (ui->actionSelectOnly->isChecked()))
    {
       activeLvlEditWin()->scene->SwitchEditingMode(LvlScene::MODE_SelectingOnly);
    }
    else
    if ((activeChildWindow()==3) && (ui->actionSelectOnly->isChecked()))
    {
       activeWldEditWin()->scene->SwitchEditingMode(WldScene::MODE_SelectingOnly);
    }
}
Esempio n. 20
0
void MainWindow::on_actionTileset_groups_editor_triggered()
{
    TilesetGroupEditor * groupDialog;
    if(activeChildWindow()==1)
        groupDialog = new TilesetGroupEditor(activeLvlEditWin()->scene, this);
    else if(activeChildWindow()==3)
        groupDialog = new TilesetGroupEditor(activeWldEditWin()->scene, this);
    else
        groupDialog = new TilesetGroupEditor(NULL, this);

    util::DialogToCenter(groupDialog);
    groupDialog->exec();
    delete groupDialog;

    configs.loadTilesets();
    setTileSetBox();
}
Esempio n. 21
0
void MainWindow::on_actionGotoLeftBottom_triggered()
{
    if (activeChildWindow()==1)
    {
        LevelEdit* edit = activeLvlEditWin();
        if(!edit) return;
        int SectionId = edit->LvlData.CurSection;
        int xb = edit->LvlData.sections[SectionId].size_left;
        int yb = edit->LvlData.sections[SectionId].size_bottom -
                 edit->scene->_viewPort->viewport()->height() + 10;
        edit->goTo(xb, yb, false, QPoint(-10, 10));
    }
    else
    if (activeChildWindow()==3)
    {
        WorldEdit *e=activeWldEditWin();
        if(e) e->ResetPosition();
    }
}
Esempio n. 22
0
void MainWindow::on_actionShowGrid_triggered(bool checked)
{
    GlobalSettings::LvlOpts.grid_show = checked;
    if(activeChildWindow() == WND_Level)
    {
        LevelEdit *e = activeLvlEditWin();
        assert(e);
        e->scene->m_opts.grid_show = checked;
        e->scene->update();
    }
    else
    if(activeChildWindow() == WND_World)
    {
        WorldEdit *e = activeWldEditWin();
        assert(e);
        e->scene->m_opts.grid_show = checked;
        e->scene->update();
    }
}
Esempio n. 23
0
void MainWindow::resetEditmodeButtons()
{
    ui->actionSelect->setChecked(0);
    ui->actionSelectOnly->setChecked(0);
    ui->actionEriser->setChecked(0);
    ui->actionHandScroll->setChecked(0);

    ui->actionSetFirstPlayer->setChecked(0);
    ui->actionSetSecondPlayer->setChecked(0);
    ui->actionDrawWater->setChecked(0);
    ui->actionDrawSand->setChecked(0);

    ui->PlacingToolbar->setVisible(false);
    ui->ResizingToolbar->setVisible(false);

    if(activeChildWindow()==1)
       activeLvlEditWin()->scene->setMessageBoxItem(false);
    else if(activeChildWindow()==3)
       activeWldEditWin()->scene->setMessageBoxItem(false);

}
Esempio n. 24
0
void MainWindow::on_action_openEpisodeFolder_triggered()
{
    QString path;
    bool isUntitled=false;
    if(activeChildWindow()==1)
    {
        LevelEdit *e = activeLvlEditWin();
        if(e)
        {
            path=e->LvlData.meta.path;
            isUntitled=e->isUntitled;
        }
    } else if(activeChildWindow()==2) {
        NpcEdit *e = activeNpcEditWin();
        if(e)
        {
            path=QFileInfo(e->curFile).absoluteDir().absolutePath();
            isUntitled=e->isUntitled;
        }
    } else if(activeChildWindow()==3) {
        WorldEdit *e = activeWldEditWin();
        if(e)
        {
            path=e->WldData.meta.path;
            isUntitled=e->isUntitled;
        }
    }

    if(isUntitled)
    {
        QMessageBox::warning(this, tr("Untitled file"), tr("Please save file to the disk first."));
        return;
    }

    if(!path.isEmpty())
    {
        QDesktopServices::openUrl(QUrl("file:///"+path));
    }
}
Esempio n. 25
0
bool MainWindow::getCurrentSceneCoordinates(qreal &x, qreal &y)
{
    if(activeChildWindow() == 1)
    {
        LevelEdit* edit = activeLvlEditWin();
        if(!edit) return false;
        QPointF coor = edit->getGraphicsView()->mapToScene(0,0);
        x = coor.x();
        y = coor.y();
        return true;
    }
    else if(activeChildWindow() == 3)
    {
        WorldEdit* edit = activeWldEditWin();
        if(!edit) return false;
        QPointF coor = edit->getGraphicsView()->mapToScene(0,0);
        x = coor.x();
        y = coor.y();
        return true;
    }
    return false;
}
Esempio n. 26
0
void MainWindow::on_DEBUG_GotoPoint_clicked()
{
    if(ui->DEBUG_GotoX->text().isEmpty()) return;
    if(ui->DEBUG_GotoY->text().isEmpty()) return;

    if(activeChildWindow()==1)
    {
        activeLvlEditWin()->goTo(
                    ui->DEBUG_GotoX->text().toInt(),
                    ui->DEBUG_GotoY->text().toInt(), true, QPoint(0,0), true);
    }
    else if(activeChildWindow()==3)
    {
        activeWldEditWin()->goTo(
                    ui->DEBUG_GotoX->text().toInt(),
                    ui->DEBUG_GotoY->text().toInt(), true, QPoint(0,0), true);

    }

    ui->DEBUG_GotoX->setText("");
    ui->DEBUG_GotoY->setText("");
}
Esempio n. 27
0
void MainWindow::on_action_openCustomFolder_triggered()
{
    QString path;
    bool isUntitled=false;
    if(activeChildWindow()==1)
    {
        LevelEdit *e = activeLvlEditWin();
        if(e)
        {
            path=e->LvlData.meta.path+"/"+e->LvlData.meta.filename;
            isUntitled=e->isUntitled;
        }
    } else if(activeChildWindow()==2) {
        return;
    } else if(activeChildWindow()==3) {
        WorldEdit *e = activeWldEditWin();
        if(e)
        {
            path=e->WldData.meta.path+"/"+e->WldData.meta.filename;
            isUntitled=e->isUntitled;
        }
    }

    if(isUntitled)
    {
        QMessageBox::warning(this, tr("Untitled file"), tr("Please save file to the disk first."));
        return;
    }

    if(!path.isEmpty())
    {
        if(!QFileInfo(path).dir().exists())
        {
            QDir(path).mkpath(path);
        }
        QDesktopServices::openUrl(QUrl("file:///"+path));
    }
}
Esempio n. 28
0
void MainWindow::customGrid(bool)
{
    QAction* action = (QAction*)sender();
    int gridSize = action->data().toInt();

    GlobalSettings::LvlOpts.grid_override = (gridSize != 0);
    if(gridSize != 0)
    {
        if(gridSize == -1)
        {
            bool ok=0;
            gridSize = QInputDialog::getInt(this,
                                            tr("Custom align grid size"),
                                            tr("Please enter grid alignment size:"),
                                            32, 0, 2147483647, 1, &ok);
            if(!ok) return;
        }
        GlobalSettings::LvlOpts.customGrid.setWidth(gridSize);
        GlobalSettings::LvlOpts.customGrid.setHeight(gridSize);
    }

    if(activeChildWindow() == WND_Level)
    {
        LevelEdit *e = activeLvlEditWin();
        assert(e);
        e->scene->m_opts.grid_override = GlobalSettings::LvlOpts.grid_override;
        e->scene->m_opts.customGrid = GlobalSettings::LvlOpts.customGrid;
    }
    else
    if(activeChildWindow() == WND_World)
    {
        WorldEdit *e = activeWldEditWin();
        assert(e);
        e->scene->m_opts.grid_override = GlobalSettings::LvlOpts.grid_override;
        e->scene->m_opts.customGrid = GlobalSettings::LvlOpts.customGrid;
    }
}
Esempio n. 29
0
//Reload opened file data
void MainWindow::on_actionReload_triggered()
{
    if(_is_reloading) return;
    _is_reloading=true;
    BoolReseter rst(&_is_reloading);
    Q_UNUSED(rst);

    QString filePath;
    QRect wnGeom;

    if (activeChildWindow()==1)
    {
        LevelData FileData;
        filePath = activeLvlEditWin()->curFile;

        if(activeLvlEditWin()->isUntitled)
        {
                    QMessageBox::warning(this, tr("File not saved"),
                    tr("File doesn't saved on disk."), QMessageBox::Ok);
                        return;
        }

        if (!QFileInfo(filePath).exists() ) {
            QMessageBox::critical(this, tr("File open error"),
            tr("Can't open the file.\nFile not exist."), QMessageBox::Ok);
                return;
        }

        if(activeLvlEditWin()->LvlData.modified)
        {
            QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Reload file and custom stuff"),
            tr("Do you want to save before reload stuff?"), QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel);
            if((ret==QMessageBox::Cancel)||(ret==0))
                return;
            else
              if(ret==QMessageBox::Yes)
                save();
        }

        //Open level file
        FileData = FileFormats::OpenLevelFile(filePath);

        if( !FileData.ReadFileValid ){
            statusBar()->showMessage(tr("Reloading error"), 2000);
            return;}

        FileData.playmusic = GlobalSettings::autoPlayMusic;
        activeLvlEditWin()->LvlData.modified = false;

        QFile file(filePath+".meta");
        if(QFileInfo(filePath+".meta").exists())
        {
            if (file.open(QIODevice::ReadOnly))
            {
                QString metaRaw;
                QTextStream meta(&file);
                meta.setCodec("UTF-8");
                metaRaw = meta.readAll();
                if(FileData.metaData.script)
                {
                    delete FileData.metaData.script;
                    FileData.metaData.script = NULL;
                }
                FileData.metaData = FileFormats::ReadNonSMBX64MetaData(metaRaw, filePath+".meta");
            }
            else
            {
                QMessageBox::critical(this, tr("File open error"),
                tr("Can't open the file."), QMessageBox::Ok);
            }
        }

        //Remember last section ID and positions!
        int lastSection=0;
        QMap<int, QPair<long, long> > sectionPoss;
        lastSection = activeLvlEditWin()->LvlData.CurSection;
        SetCurrentLevelSection(lastSection);//Need to remember position of current section
        for(int i=0; i<activeLvlEditWin()->LvlData.sections.size(); i++)
        {
            LevelSection sct = activeLvlEditWin()->LvlData.sections[i];
            sectionPoss[sct.id]=QPair<long, long >(sct.PositionX, sct.PositionY);
        }

        activeLvlEditWin()->close();//Close old widget without closing of sub-window

        //Get pointer to current sub-window
        QMdiSubWindow *window = ui->centralWidget->activeSubWindow();

        //Get geometry of current subwindow
        wnGeom = ui->centralWidget->activeSubWindow()->geometry();
        //delete window->widget();
        LevelEdit *chLvlWin = new LevelEdit(window);
        connect(chLvlWin, SIGNAL(forceReload()), this, SLOT(on_actionReload_triggered()));
        window->setWidget(chLvlWin);
        GraphicsWorkspace* gr = static_cast<GraphicsWorkspace *>(chLvlWin->getGraphicsView());
        connect(gr, SIGNAL(zoomValueChanged(QString)), zoom, SLOT(setText(QString)));

        //ui->centralWidget->activeSubWindow()->close();
        LevelEdit *child = chLvlWin;//createLvlChild();
        LvlMusPlay::setNoMusic();
        setMusic(false);
        if ((bool) (child->loadFile(filePath, FileData, configs, GlobalSettings::LvlOpts)))
        {
            child->show();
            ui->centralWidget->activeSubWindow()->setGeometry(wnGeom);
            child->updateGeometry();
            child->ResetPosition();
            statusBar()->showMessage(tr("Level file reloaded"), 2000);
            LvlMusPlay::musicForceReset=true; //reset musics
            updateMenus(true);

            child->setFocus();
            //Restore saved section positions
            for(int i=0; i<child->LvlData.sections.size(); i++)
            {
                if(sectionPoss.contains(child->LvlData.sections[i].id))
                {
                    child->LvlData.sections[i].PositionX=sectionPoss[child->LvlData.sections[i].id].first;
                    child->LvlData.sections[i].PositionY=sectionPoss[child->LvlData.sections[i].id].second;
                }
            }

            SetCurrentLevelSection(lastSection);

            if(GlobalSettings::autoPlayMusic) ui->actionPlayMusic->setChecked(true);
        } else {
                WriteToLog(QtDebugMsg, ">>File loading aborted");
            child->show();
                WriteToLog(QtDebugMsg, ">>Window showed");
            if(activeChildWindow()==1) activeLvlEditWin()->LvlData.modified = false;
                WriteToLog(QtDebugMsg, ">>Option set");
            ui->centralWidget->activeSubWindow()->close();
                WriteToLog(QtDebugMsg, ">>Windows closed");
        }
    }
    else
    if (activeChildWindow()==2)
    {
        filePath = activeNpcEditWin()->curFile;
        QFile fileIn(filePath);

        if(activeNpcEditWin()->isUntitled)
        {
                    QMessageBox::warning(this, tr("File not saved"),
                    tr("File doesn't saved on disk."), QMessageBox::Ok);
                        return;
        }

        if(activeNpcEditWin()->isModyfied)
        {
            QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Reload file and custom stuff"),
            tr("Do you want to save before reload stuff?"), QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel);
            if((ret==QMessageBox::Cancel)||(ret==0))
                return;
            else
              if(ret==QMessageBox::Yes)
                save();
        }

        if (!fileIn.open(QIODevice::ReadOnly)) {
        QMessageBox::critical(this, tr("File open error"),
        tr("Can't open the file."), QMessageBox::Ok);
            return;
        }

        NPCConfigFile FileData = FileFormats::ReadNpcTXTFile(fileIn);
        if( !FileData.ReadFileValid ) return;
        wnGeom = ui->centralWidget->activeSubWindow()->geometry();
        activeNpcEditWin()->isModyfied = false;
        activeNpcEditWin()->close();
        //NpcEdit *child = createNPCChild();

        QMdiSubWindow *npcWindow = ui->centralWidget->activeSubWindow();
        NpcEdit *child = new NpcEdit(&configs, npcWindow);
        npcWindow->setWidget(child);

        if (child->loadFile(filePath, FileData)) {
            statusBar()->showMessage(tr("NPC Config reloaded"), 2000);
            child->show();
            ui->centralWidget->activeSubWindow()->setGeometry(wnGeom);
            updateMenus(true);
        } else {
            child->close();
            npcWindow->close();
        }
    }
    else
    if (activeChildWindow()==3)
    {
        WorldData FileData;
        filePath = activeWldEditWin()->curFile;

        if(activeWldEditWin()->isUntitled)
        {
                    QMessageBox::warning(this, tr("File not saved"),
                    tr("File doesn't saved on disk."), QMessageBox::Ok);
                        return;
        }

        if (!QFileInfo(filePath).exists() ) {
            QMessageBox::critical(this, tr("File open error"),
            tr("Can't open the file.\nFile not exist."), QMessageBox::Ok);
                return;
        }

        if(activeWldEditWin()->WldData.modified){
            QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Reload file and custom stuff"),
            tr("Do you want to save before reload stuff?"), QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel);
            if((ret==QMessageBox::Cancel)||(ret==0))
                return;
            else
              if(ret==QMessageBox::Yes)
                save();
        }

        FileData = FileFormats::OpenWorldFile(filePath);

        if( !FileData.ReadFileValid ){
            statusBar()->showMessage(tr("Reloading error"), 2000);
            return;}

        FileData.filename = QFileInfo(filePath).baseName();
        FileData.path = QFileInfo(filePath).absoluteDir().absolutePath();
        FileData.playmusic = GlobalSettings::autoPlayMusic;
        activeWldEditWin()->WldData.modified = false;

        QFile file(filePath+".meta");
        if(QFileInfo(filePath+".meta").exists())
        {
            if (file.open(QIODevice::ReadOnly))
            {
                QString metaRaw;
                QTextStream meta(&file);
                meta.setCodec("UTF-8");
                metaRaw = meta.readAll();
                FileData.metaData = FileFormats::ReadNonSMBX64MetaData(metaRaw, filePath+".meta");
            }
            else
            {
                QMessageBox::critical(this, tr("File open error"),
                tr("Can't open the file."), QMessageBox::Ok);
            }
        }

        wnGeom = ui->centralWidget->activeSubWindow()->geometry();
        QMdiSubWindow *worldWindow = ui->centralWidget->activeSubWindow();
        long posX = activeWldEditWin()->scene->_viewPort->horizontalScrollBar()->value();
        long posY = activeWldEditWin()->scene->_viewPort->verticalScrollBar()->value();

        activeWldEditWin()->close();

        WorldEdit *child = new WorldEdit(worldWindow);
        connect(child, SIGNAL(forceReload()), this, SLOT(on_actionReload_triggered()));
        worldWindow->setWidget(child);
        GraphicsWorkspace* gr = static_cast<GraphicsWorkspace *>(child->getGraphicsView());

        connect(gr, SIGNAL(zoomValueChanged(QString)), zoom, SLOT(setText(QString)));
        if ( (bool)(child->loadFile(filePath, FileData, configs, GlobalSettings::LvlOpts)) ) {
            child->show();
            ui->centralWidget->activeSubWindow()->setGeometry(wnGeom);
            child->updateGeometry();
            child->ResetPosition();
            updateMenus(true);
            dock_WldSettingsBox->setCurrentWorldSettings();
            if(FileData.HubStyledWorld)
            {
                dock_WldSettingsBox->setVisible(true);
                dock_WldSettingsBox->raise();
            }

            child->scene->_viewPort->horizontalScrollBar()->setValue(posX);
            child->scene->_viewPort->verticalScrollBar()->setValue(posY);

            statusBar()->showMessage(tr("World map file loaded"), 2000);
        } else {
            WriteToLog(QtDebugMsg, ">>File loading aborted");
            child->show();
            WriteToLog(QtDebugMsg, ">>Window showed");
            if(activeChildWindow()==3) activeWldEditWin()->WldData.modified = false;
            WriteToLog(QtDebugMsg, ">>Option set");
            ui->centralWidget->activeSubWindow()->close();
            WriteToLog(QtDebugMsg, ">>Windows closed");
        }

    }

    dock_LvlItemBox->clearFilter();
}
void MainWindow::SwitchPlacingItem(int itemType, unsigned long itemID)
{
    if(activeChildWindow()==1) // Level editing window
    {
       bool valid=false;
       switch(itemType)
       {
           case ItemTypes::LVL_Block:
           case ItemTypes::LVL_BGO:
           case ItemTypes::LVL_NPC:
                valid=true;

                resetEditmodeButtons();

                activeLvlEditWin()->scene->clearSelection();
                activeLvlEditWin()->changeCursor(leveledit::MODE_PlaceItem);
                activeLvlEditWin()->scene->SwitchEditingMode(LvlScene::MODE_PlacingNew);


                LvlPlacingItems::placingMode = LvlPlacingItems::PMODE_Brush;


                //LvlPlacingItems::squareFillingMode = false;
                ui->actionSquareFill->setChecked(false);
                ui->actionSquareFill->setEnabled(true);

                //LvlPlacingItems::lineMode = false;
                ui->actionLine->setChecked(false);
                ui->actionLine->setEnabled(true);

                //LvlPlacingItems::floodFillingMode = false;
                ui->actionFill->setChecked(false);
                ui->actionFill->setEnabled(true);

                ui->PlacingToolbar->setVisible(true);
                qApp->setActiveWindow(this);
                activeLvlEditWin()->setFocus();
           default:;
       }

       Placing_ShowProperties_lastType = itemType;

       //Switch placing mode
       if(valid)
           switch(itemType)
           {
           case ItemTypes::LVL_Block:
               {
                   ui->action_Placing_ShowProperties->setChecked(true);
                   ui->action_Placing_ShowProperties->setEnabled(true);
                   //Switch scene to placing mode:
                   activeLvlEditWin()->scene->setItemPlacer(0, itemID);

                   //Open block properties toolbox for define placing properties
                   LvlItemProps(0,LvlPlacingItems::blockSet,
                                             FileFormats::dummyLvlBgo(),
                                             FileFormats::dummyLvlNpc(), true);

                   if(GlobalSettings::Placing_dontShowPropertiesBox)
                        ui->ItemProperties->hide();

                   break;
               }
           case ItemTypes::LVL_BGO:
               {
                   ui->action_Placing_ShowProperties->setChecked(true);
                   ui->action_Placing_ShowProperties->setEnabled(true);

                   activeLvlEditWin()->scene->setItemPlacer(1, itemID );

                   LvlItemProps(1,FileFormats::dummyLvlBlock(),
                                             LvlPlacingItems::bgoSet,
                                             FileFormats::dummyLvlNpc(), true);

                   if(GlobalSettings::Placing_dontShowPropertiesBox)
                        ui->ItemProperties->hide();

                   break;
               }
           case ItemTypes::LVL_NPC:
               {
                   ui->action_Placing_ShowProperties->setChecked(true);
                   ui->action_Placing_ShowProperties->setEnabled(true);

                   ui->actionSquareFill->setEnabled(false);
                   ui->actionFill->setEnabled(false);

                   activeLvlEditWin()->scene->setItemPlacer(2, itemID );

                   LvlItemProps(2,FileFormats::dummyLvlBlock(),
                                             FileFormats::dummyLvlBgo(),
                                             LvlPlacingItems::npcSet, true);

                   if(GlobalSettings::Placing_dontShowPropertiesBox)
                        ui->ItemProperties->hide();

                   break;
               }
           }
    }
    else if(activeChildWindow()==3) // World editing window
    {
        bool valid=false;
        ui->action_Placing_ShowProperties->setChecked(false);
        ui->action_Placing_ShowProperties->setEnabled(false);
        switch(itemType)
        {
            case ItemTypes::WLD_Tile:
            case ItemTypes::WLD_Scenery:
            case ItemTypes::WLD_Path:
            case ItemTypes::WLD_Level:
            case ItemTypes::WLD_MusicBox:
                 valid=true;

                 resetEditmodeButtons();

                 ui->PlacingToolbar->setVisible(true);
                 activeWldEditWin()->scene->clearSelection();
                 activeWldEditWin()->changeCursor(WorldEdit::MODE_PlaceItem);
                 activeWldEditWin()->scene->SwitchEditingMode(WldScene::MODE_PlacingNew);

                 WldPlacingItems::placingMode = WldPlacingItems::PMODE_Brush;

                 //WldPlacingItems::squarefillingMode = false;
                 ui->actionSquareFill->setChecked(false);
                 ui->actionSquareFill->setEnabled(true);

                 //WldPlacingItems::lineMode = false;
                 ui->actionLine->setChecked(false);
                 ui->actionLine->setEnabled(true);

                 //WldPlacingItems::floodFillingMode = false;
                 ui->actionFill->setChecked(false);
                 ui->actionFill->setEnabled(true);

                 qApp->setActiveWindow(this);
                 activeWldEditWin()->setFocus();
            default:;
        }

        Placing_ShowProperties_lastType = itemType;

        //Switch placing mode
        if(valid)
            switch(itemType)
            {
                case ItemTypes::WLD_Tile:
                    {
                        activeWldEditWin()->scene->setItemPlacer(0, itemID);
                        WldItemProps(-1, FileFormats::dummyWldLevel(), true);
                        break;
                    }
                case ItemTypes::WLD_Scenery:
                    {
                        activeWldEditWin()->scene->setItemPlacer(1, itemID);
                        WldItemProps(-1, FileFormats::dummyWldLevel(), true);
                        break;
                    }
                case ItemTypes::WLD_Path:\
                    {
                        activeWldEditWin()->scene->setItemPlacer(2, itemID);
                        WldItemProps(-1, FileFormats::dummyWldLevel(), true);
                        break;
                    }
                case ItemTypes::WLD_Level:
                    {
                        ui->action_Placing_ShowProperties->setChecked(true);
                        ui->action_Placing_ShowProperties->setEnabled(true);

                        activeWldEditWin()->scene->setItemPlacer(3, itemID);
                        WldItemProps(0, WldPlacingItems::LevelSet, true);

                        if(GlobalSettings::Placing_dontShowPropertiesBox)
                             ui->WLD_ItemProps->hide();

                        break;
                    }
                case ItemTypes::WLD_MusicBox:
                    {
                        ui->actionSquareFill->setEnabled(false);
                        ui->actionLine->setEnabled(false);
                        ui->actionFill->setEnabled(false);
                        activeWldEditWin()->scene->setItemPlacer(4, itemID);
                        WldItemProps(-1, FileFormats::dummyWldLevel(), true);
                        break;
                    }
            }

    }
}