Exemplo n.º 1
0
bool MapEditor::saveMap()
{
    return saveMapAs(m_mapName);
}
Exemplo n.º 2
0
/* MapEditorWindow::saveMap
 * Saves the current map to its archive, or opens the 'save as'
 * dialog if it doesn't currently belong to one
 *******************************************************************/
bool MapEditorWindow::saveMap()
{
	// Check for newly created map
	if (!mdesc_current.head)
		return saveMapAs();

	// Write map to temp wad
	WadArchive* wad = writeMap();
	if (!wad)
		return false;

	// Check for map archive
	Archive* tempwad = NULL;
	Archive::mapdesc_t map = mdesc_current;
	if (mdesc_current.archive && mdesc_current.head)
	{
		tempwad = new WadArchive();
		tempwad->open(mdesc_current.head);
		vector<Archive::mapdesc_t> amaps = tempwad->detectMaps();
		if (amaps.size() > 0)
			map = amaps[0];
		else
			return false;
	}

	// Unlock current map entries
	lockMapEntries(false);

	// Delete current map entries
	ArchiveEntry* entry = map.end;
	Archive* archive = map.head->getParent();
	while (entry && entry != map.head)
	{
		ArchiveEntry* prev = entry->prevEntry();
		archive->removeEntry(entry);
		entry = prev;
	}

	// Create backup
	if (!backup_manager->writeBackup(map_data, map.head->getTopParent()->getFilename(false), map.head->getName(true)))
		LOG_MESSAGE(1, "Warning: Failed to backup map data");

	// Add new map entries
	for (unsigned a = 1; a < wad->numEntries(); a++)
		entry = archive->addEntry(wad->getEntry(a), archive->entryIndex(map.head) + a, NULL, true);

	// Clean up
	delete wad;
	if (tempwad)
	{
		tempwad->save();
		delete tempwad;
	}
	else
	{
		// Update map description
		mdesc_current.end = entry;
	}

	// Finish
	lockMapEntries();
	editor.getMap().setOpenedTime();

	return true;
}
Exemplo n.º 3
0
MapEditor::MapEditor(QWidget* par, const QString& map, const QString& ressourceList):QMainWindow(par)
{
    m_mapWidget = NULL; m_currentItemIndex=0;

    pgrdia=new QProgressDialog(tr("Chargement en cours..."), tr("Veuillez patienter.."), 0, 100, this);
    pgrdia->setWindowModality(Qt::WindowModal);
    pgrdia->setMinimumDuration(100);
    pgrdia->hide();

    setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North);
    setDockNestingEnabled(true);

    m_rsRegExp.setPatternSyntax(QRegExp::Wildcard);

    setWindowTitle(tr("Éditeur de carte"));

    { ///MAP PROPERTIES DOCK
    QDockWidget* dw_mapProperties = new QDockWidget(tr("Propriétés de la carte"), this);
    dw_mapProperties->setWhatsThis(tr("Un dock regroupant quelques propriétés de la carte"));
    dw_mapProperties->setFeatures(QDockWidget::NoDockWidgetFeatures);
    dw_mapProperties->setFeatures(QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable);
    QWidget *w_mapProperties = new QWidget(dw_mapProperties);
    dw_mapProperties->setWidget(w_mapProperties);

    addDockWidget(Qt::TopDockWidgetArea, dw_mapProperties);

    QVBoxLayout *l_mapProperties = new QVBoxLayout(w_mapProperties);
    w_mapProperties->setLayout(l_mapProperties);

    {
        QHBoxLayout *lay=new QHBoxLayout();
        l_mapProperties->addLayout(lay);
        m_mapSizeX = new QSpinBox(this);
        m_mapSizeX->setRange(0,MAP_MAX_SIZE);
        m_mapSizeX->setEnabled(false);
        lay->addWidget(m_mapSizeX);


        m_mapSizeY = new QSpinBox(this);
        m_mapSizeY->setRange(0,MAP_MAX_SIZE);
        m_mapSizeY->setEnabled(false);
        lay->addWidget(m_mapSizeY);
    }
    {
        m_mapNameLabel=new QLabel(this);
        l_mapProperties->addWidget(m_mapNameLabel);
        m_sendingBtn=new QPushButton(tr("(MJ) Envoyer la carte au serveur"), this);
        l_mapProperties->addWidget(m_sendingBtn);
        setSendingButtonEnabled(false);
        connect(m_sendingBtn, SIGNAL(pressed()), this, SLOT(btnMapSend()));
    }
    }

    { ///CASE PROPERTIES DOCK
    QDockWidget* dw_caseProperties = new QDockWidget(tr("Propriétés de la case"), this);
    dw_caseProperties->setWhatsThis(tr("Un dock regroupant quelques propriétés de la case sélectionnée"));
    dw_caseProperties->setFeatures(QDockWidget::NoDockWidgetFeatures);
    dw_caseProperties->setFeatures(QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable);
    QWidget *w_caseProperties = new QWidget(dw_caseProperties);
    dw_caseProperties->setWidget(w_caseProperties);

    addDockWidget(Qt::RightDockWidgetArea, dw_caseProperties);

    QVBoxLayout *l_caseProperties = new QVBoxLayout(w_caseProperties);
    w_caseProperties->setLayout(l_caseProperties);

    {

        m_selectedCaseLabel = new QLabel(this);
        l_caseProperties->addWidget(m_selectedCaseLabel);

        m_selectedCaseRSID = new QSpinBox(this);
        m_selectedCaseRSID->setRange(0,MAX_LOADED_RESSOURCES);
        m_selectedCaseRSID->setEnabled(false);
        l_caseProperties->addWidget(m_selectedCaseRSID);
        connect(m_selectedCaseRSID, SIGNAL(valueChanged(int)), this, SLOT(changeCurrentCaseRSID(int)));

        {
            QGroupBox* gb = new QGroupBox(tr("Objets sur la case :"), this);
            m_mapCaseItemList = new QListWidget(this);
            connect(m_mapCaseItemList, SIGNAL(clicked(const QModelIndex&)), this, SLOT(selectMapItem(const QModelIndex&)));
            m_addItem = new QPushButton(tr("Ajouter un objet"), this);
            m_addItem->setEnabled(false);
            connect(m_addItem, SIGNAL(pressed()), this, SLOT(addMapObject()));
            QVBoxLayout* lyt = new QVBoxLayout();
            gb->setLayout(lyt); lyt->addWidget(m_mapCaseItemList); lyt->addWidget(m_addItem);
            l_caseProperties->addWidget(gb);
        }
    }
    }

    { ///MAPITEMS DOCK
    QDockWidget* dw_mapItems = new QDockWidget(tr("Objets de la carte"), this);
    dw_mapItems->setWhatsThis(tr("Un dock permettant la gestion des objets de la carte"));
    dw_mapItems->setFeatures(QDockWidget::NoDockWidgetFeatures);
    dw_mapItems->setFeatures(QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable);
    QWidget *w_mapItems = new QWidget(dw_mapItems);
    dw_mapItems->setWidget(w_mapItems);

    addDockWidget(Qt::RightDockWidgetArea, dw_mapItems);

    QVBoxLayout *l_mapItems = new QVBoxLayout(w_mapItems);
    w_mapItems->setLayout(l_mapItems);
    {
        m_mapItemList = new QListWidget(this);
        connect(m_mapItemList, SIGNAL(clicked(const QModelIndex&)), this, SLOT(selectMapItem(const QModelIndex&)));
        l_mapItems->addWidget(m_mapItemList);
        m_mapItemName = new QLabel(this);
        l_mapItems->addWidget(m_mapItemName);
        m_mapItemRSID = new QSpinBox(this); m_mapItemRSID->setRange(0,MAX_LOADED_RESSOURCES); m_mapItemRSID->setPrefix(tr("RSID : ")); m_mapItemRSID->setEnabled(false);
        l_mapItems->addWidget(m_mapItemRSID);
        m_mapItemPos = new QLabel(this);
        l_mapItems->addWidget(m_mapItemPos);
        l_mapItems->addWidget(new QLabel(tr("Teinte :"), this));
        m_mapItemColorViewer = new QColorViewer(this);
        l_mapItems->addWidget(m_mapItemColorViewer);
        m_removeItem = new QPushButton(tr("Supprimer l'objet"), this);
        l_mapItems->addWidget(m_removeItem);
        connect(m_removeItem, SIGNAL(pressed()), this, SLOT(removeMapObject()));
    }

    }

    { ///RSSMNGR PROPERTIES DOCK
    QDockWidget* dw_rssMngrProperties = new QDockWidget(tr("Gestionnaire de ressources"), this);
    dw_rssMngrProperties->setWhatsThis(tr("Un dock regroupant les différentes ressources chargées dans l'éditeur"));
    dw_rssMngrProperties->setFeatures(QDockWidget::NoDockWidgetFeatures);
    dw_rssMngrProperties->setFeatures(QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable);
    QWidget *w_rssMngrProperties = new QWidget(dw_rssMngrProperties);
    dw_rssMngrProperties->setWidget(w_rssMngrProperties);

    addDockWidget(Qt::RightDockWidgetArea, dw_rssMngrProperties);
    QVBoxLayout *l_rssMngrProperties = new QVBoxLayout(w_rssMngrProperties);
    w_rssMngrProperties->setLayout(l_rssMngrProperties);
    {
        m_rsMngrFilter = new QLineEdit(this); m_rsMngrFilter->setPlaceholderText(tr("Filtre..."));
        connect(m_rsMngrFilter, SIGNAL(textEdited(const QString&)),this, SLOT(changeRsMngrFilter(const QString&)));
        l_rssMngrProperties->addWidget(m_rsMngrFilter);

        m_rsMngrWidget = new QTableWidget(0,2, this);
        m_rsMngrWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
        m_rsMngrWidget->setSelectionMode(QAbstractItemView::SingleSelection);
        m_rsMngrWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
        m_rsMngrWidget->setSortingEnabled(true);
        m_rsMngrWidget->verticalHeader()->hide();
        l_rssMngrProperties->addWidget(m_rsMngrWidget);

        m_rsMngrEdit = new QPushButton(tr("Modifier..."), this);
        m_rsMngrEdit->setEnabled(false);
        l_rssMngrProperties->addWidget(m_rsMngrEdit);

        connect(m_rsMngrEdit, SIGNAL(pressed()), this, SLOT(modifyRssMngr()));

        m_rsMngrAdd = new QPushButton(tr("Ajouter..."), this);
        m_rsMngrAdd->setEnabled(false);
        l_rssMngrProperties->addWidget(m_rsMngrAdd);

        connect(m_rsMngrAdd, SIGNAL(pressed()), this, SLOT(addRssMngr()));
    }
    }

    QMenu *fileMenu = menuBar()->addMenu(tr("&Fichier"));

    QAction *ac_new= fileMenu->addAction(tr("&Nouvelle carte..."));
    connect(ac_new, SIGNAL(triggered()), this, SLOT(newMap()));

    QAction *ac_open= fileMenu->addAction(tr("&Charger une carte..."));
    connect(ac_open, SIGNAL(triggered()), this, SLOT(loadMap()));

    QAction *ac_save = fileMenu->addAction(tr("Sauvegarder &la carte..."));
    connect(ac_save, SIGNAL(triggered()), this, SLOT(saveMap()));

    QAction *ac_saveAs = fileMenu->addAction(tr("Sa&uvegarder la carte sous..."));
    connect(ac_saveAs, SIGNAL(triggered()), this, SLOT(saveMapAs()));

    QAction *ac_quit = fileMenu->addAction(tr("&Quitter..."));
    connect(ac_quit, SIGNAL(triggered()), this, SLOT(close()));


    QMenu *toolMenu = menuBar()->addMenu(tr("&Outils"));
    QAction *ac_replace= toolMenu->addAction(tr("&Remplacer..."));
    connect(ac_replace, SIGNAL(triggered()), this, SLOT(replaceRSID()));
    QAction *ac_copy= toolMenu->addAction(tr("Copier...")); ac_copy->setShortcut(QKeySequence::Copy);
    connect(ac_copy, SIGNAL(triggered()), this, SLOT(copy()));
    QAction *ac_paste= toolMenu->addAction(tr("Coller...")); ac_paste->setShortcut(QKeySequence::Paste);
    connect(ac_paste, SIGNAL(triggered()), this, SLOT(paste()));

    QMenu *exportMenu = menuBar()->addMenu(tr("&Export"));
    QAction *ac_ex_rss= exportMenu->addAction(tr("... la liste de ressources"));
    connect(ac_ex_rss,SIGNAL(triggered()),this,SLOT(exportRss()));
    QAction *ac_ex_map= exportMenu->addAction(tr("... la matrice de la carte"));
    connect(ac_ex_map,SIGNAL(triggered()),this,SLOT(exportMap()));


    m_hoveredCaseLabel = new QLabel(this);
    statusBar()->addWidget(m_hoveredCaseLabel);

    m_mapName=map;
    m_ressourcePackName=ressourceList;
    if(!map.isEmpty())
    {
        loadMap(map,m_ressourcePackName);
    }

    enableMapSystem(false);
}
Exemplo n.º 4
0
/* MapEditorWindow::handleAction
 * Handles the action [id]. Returns true if the action was handled,
 * false otherwise
 *******************************************************************/
bool MapEditorWindow::handleAction(string id)
{
	// Don't handle actions if hidden
	if (!IsShown())
		return false;

	// Map->Save
	if (id == "mapw_save")
	{
		// Save map
		if (saveMap())
		{
			// Save archive
			Archive* a = currentMapDesc().head->getParent();
			if (a && save_archive_with_map) a->save();
		}

		return true;
	}

	// Map->Save As
	if (id == "mapw_saveas")
	{
		saveMapAs();
		return true;
	}

	// Map->Restore Backup
	if (id == "mapw_backup")
	{
		if (mdesc_current.head)
		{
			Archive* data = backup_manager->openBackup(mdesc_current.head->getTopParent()->getFilename(false), mdesc_current.name);
			if (data)
			{
				vector<Archive::mapdesc_t> maps = data->detectMaps();
				if (!maps.empty())
				{
					editor.getMap().clearMap();
					editor.openMap(maps[0]);
					loadMapScripts(maps[0]);
				}
			}
		}

		return true;
	}

	// Edit->Undo
	if (id == "mapw_undo")
	{
		editor.doUndo();
		return true;
	}

	// Edit->Redo
	if (id == "mapw_redo")
	{
		editor.doRedo();
		return true;
	}

	// Editor->Set Base Resource Archive
	if (id == "mapw_setbra")
	{
		wxDialog dialog_ebr(this, -1, "Edit Base Resource Archives", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER);
		BaseResourceArchivesPanel brap(&dialog_ebr);

		wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
		sizer->Add(&brap, 1, wxEXPAND|wxALL, 4);

		sizer->Add(dialog_ebr.CreateButtonSizer(wxOK|wxCANCEL), 0, wxEXPAND|wxLEFT|wxRIGHT|wxDOWN, 4);

		dialog_ebr.SetSizer(sizer);
		dialog_ebr.Layout();
		dialog_ebr.SetInitialSize(wxSize(500, 300));
		dialog_ebr.CenterOnParent();
		if (dialog_ebr.ShowModal() == wxID_OK)
			theArchiveManager->openBaseResource(brap.getSelectedPath());

		return true;
	}

	// Editor->Preferences
	if (id == "mapw_preferences")
	{
		PreferencesDialog::openPreferences(this);

		return true;
	}

	// View->Item Properties
	if (id == "mapw_showproperties")
	{
		wxAuiManager* m_mgr = wxAuiManager::GetManager(this);
		wxAuiPaneInfo& p_inf = m_mgr->GetPane("item_props");

		// Toggle window and focus
		p_inf.Show(!p_inf.IsShown());
		map_canvas->SetFocus();

		m_mgr->Update();
		return true;
	}

	// View->Console
	else if (id == "mapw_showconsole")
	{
		wxAuiManager* m_mgr = wxAuiManager::GetManager(this);
		wxAuiPaneInfo& p_inf = m_mgr->GetPane("console");

		// Toggle window and focus
		if (p_inf.IsShown())
		{
			p_inf.Show(false);
			map_canvas->SetFocus();
		}
		else
		{
			p_inf.Show(true);
			p_inf.window->SetFocus();
		}

		p_inf.MinSize(200, 128);
		m_mgr->Update();
		return true;
	}

	// View->Script Editor
	else if (id == "mapw_showscripteditor")
	{
		wxAuiManager* m_mgr = wxAuiManager::GetManager(this);
		wxAuiPaneInfo& p_inf = m_mgr->GetPane("script_editor");

		// Toggle window and focus
		if (p_inf.IsShown())
		{
			p_inf.Show(false);
			map_canvas->SetFocus();
		}
		else if (!theGameConfiguration->scriptLanguage().IsEmpty())
		{
			p_inf.Show(true);
			p_inf.window->SetFocus();
		}

		p_inf.MinSize(200, 128);
		m_mgr->Update();
		return true;
	}

	// View->Map Checks
	else if (id == "mapw_showchecks")
	{
		wxAuiManager* m_mgr = wxAuiManager::GetManager(this);
		wxAuiPaneInfo& p_inf = m_mgr->GetPane("map_checks");

		// Toggle window and focus
		if (p_inf.IsShown())
		{
			p_inf.Show(false);
			map_canvas->SetFocus();
		}
		else
		{
			p_inf.Show(true);
			p_inf.window->SetFocus();
		}

		//p_inf.MinSize(200, 128);
		m_mgr->Update();
		return true;
	}

	// View->Undo History
	else if (id == "mapw_showundohistory")
	{
		wxAuiManager* m_mgr = wxAuiManager::GetManager(this);
		wxAuiPaneInfo& p_inf = m_mgr->GetPane("undo_history");

		// Toggle window
		p_inf.Show(!p_inf.IsShown());

		m_mgr->Update();
		return true;
	}

	// Run Map
	else if (id == "mapw_run_map")
	{
		Archive* archive = NULL;
		if (mdesc_current.head)
			archive = mdesc_current.head->getParent();
		RunDialog dlg(this, archive);
		if (dlg.ShowModal() == wxID_OK)
		{
			WadArchive* wad = writeMap(mdesc_current.name);
			if (wad)
				wad->save(appPath("sladetemp_run.wad", DIR_TEMP));

			string command = dlg.getSelectedCommandLine(archive, mdesc_current.name, wad->getFilename());
			if (!command.IsEmpty())
			{
				// Set working directory
				string wd = wxGetCwd();
				wxSetWorkingDirectory(dlg.getSelectedExeDir());

				// Run
				wxExecute(command, wxEXEC_ASYNC);

				// Restore working directory
				wxSetWorkingDirectory(wd);
			}
		}

		return true;
	}
	
	return false;
}