// Static command targets void Map::newMap(const cmd::ArgumentList& args) { if (GlobalMap().askForSave(_("New Map"))) { // Turn regioning off when starting a new map GlobalRegion().disable(); GlobalMap().freeMap(); GlobalMap().createNew(); } }
void Map::saveMap(const cmd::ArgumentList& args) { if (GlobalMap().isUnnamed()) { GlobalMap().saveAs(); } // greebo: Always let the map be saved, regardless of the modified status. else /*if(GlobalMap().isModified())*/ { GlobalMap().save(); } }
void Map::openMap(const cmd::ArgumentList& args) { if (!GlobalMap().askForSave(_("Open Map"))) return; // Get the map file name to load std::string filename = MapFileManager::getMapFilename(true, _("Open map")); if (!filename.empty()) { GlobalMRU().insert(filename); GlobalMap().freeMap(); GlobalMap().load(filename); } }
gint PrefabSelector::callbackButtonPress (GtkWidget *widget, GdkEventButton *event, PrefabSelector *self) { if (event->type == GDK_2BUTTON_PRESS && event->button == 1) { GtkTreeModel* model; GtkTreeIter iter; if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(self->_view), &model, &iter) == FALSE) { return FALSE; } else { UndoableCommand undo("mapImport"); const std::string text = gtkutil::TreeModel::getString(model, &iter, PREFAB_NAME); switch (self->_selectedSelectionStrategy) { case PREFAB_SELECT_REPLACE: selection::algorithm::deleteSelection(); break; case PREFAB_SELECT_UNSELECT: Selection_Deselect(); break; case PREFAB_SELECT_EXTEND: //do nothing break; } const std::string fileName = PrefabSelector::GetFullPath(text); GlobalMap().importFile(fileName); GlobalMaterialSystem()->importMaterialFile(os::stripExtension(fileName) + ".mat"); return TRUE; } } return FALSE; }
void surroundWithMonsterclip(const cmd::ArgumentList& args) { UndoableCommand command("addMonsterclip"); // create a ModelFinder and retrieve the modelList selection::algorithm::ModelFinder visitor; GlobalSelectionSystem().foreachSelected(visitor); // Retrieve the list with all the found models from the visitor selection::algorithm::ModelFinder::ModelList list = visitor.getList(); selection::algorithm::ModelFinder::ModelList::iterator iter; for (iter = list.begin(); iter != list.end(); ++iter) { // one of the models in the SelectionStack const scene::INodePtr& node = *iter; // retrieve the AABB AABB brushAABB(node->worldAABB()); // create the brush scene::INodePtr brushNode(GlobalBrushCreator().createBrush()); if (brushNode != NULL) { scene::addNodeToContainer(brushNode, GlobalMap().findOrInsertWorldspawn()); Brush* theBrush = Node_getBrush(brushNode); std::string clipShader = GlobalRegistry().get(RKEY_MONSTERCLIP_SHADER); Scene_BrushResize(*theBrush, brushAABB, clipShader); } } }
static gint mainframe_delete (GtkWidget *widget, GdkEvent *event, gpointer data) { if (GlobalMap().askForSave("Exit Radiant")) { gtk_main_quit(); } return TRUE; }
void Map::exportMap(const cmd::ArgumentList& args) { std::string filename = MapFileManager::getMapFilename(false, _("Export selection")); if (!filename.empty()) { GlobalMap().saveSelected(filename); } }
void ToolsCompile () { if (!GlobalMap().askForSave(_("Compile Map"))) return; /* empty map? */ if (!GlobalRadiant().getCounter(counterBrushes).get()) { gtkutil::errorDialog(_("Nothing that could get compiled\n")); return; } try { const std::string mapName = GlobalMap().getName(); NullMapCompilerObserver observer; GlobalMapCompiler().compileMap(mapName, observer); } catch (MapCompileException& e) { gtkutil::errorDialog(e.what()); } }
void MapCompiler::fixErrors (const std::string& mapName, ICompilerObserver& observer) { int exitCode = run(mapName, _errorFixParameters, observer); if (exitCode == 0) { // reload after fix GlobalMap().reload(); } }
void Map::saveSelectedAsPrefab(const cmd::ArgumentList& args) { std::string filename = MapFileManager::getMapFilename(false, _("Save selected as Prefab"), "prefab"); if (!filename.empty()) { GlobalMap().saveSelected(filename); } }
void ToolsGenerateMaterials () { if (!GlobalMap().askForSave(_("Generate Materials"))) return; /* empty map? */ if (!GlobalRadiant().getCounter(counterBrushes).get()) { gtkutil::errorDialog(_("Nothing to generate materials for\n")); return; } try { const std::string mapName = GlobalMap().getName(); NullMapCompilerObserver observer; GlobalMapCompiler().generateMaterial(mapName, observer); GlobalMaterialSystem()->showMaterialDefinition(); } catch (MapCompileException& e) { gtkutil::errorDialog(e.what()); } }
void MaterialSystem::loadMaterials () { if (GlobalMap().isUnnamed()) return; AutoPtr<ArchiveTextFile> file(GlobalFileSystem().openTextFile(getMaterialFilename())); if (file) { _material = file->getString(); _materialLoaded = true; } }
void Map::importMap(const cmd::ArgumentList& args) { std::string filename = MapFileManager::getMapFilename(true, _("Import map")); if (!filename.empty()) { UndoableCommand undo("mapImport"); GlobalMap().import(filename); } }
void CamWnd::draw() { m_drawing = true; gtkutil::GLWidgetSentry sentry(m_gl_widget); if (GlobalMap().isValid() && ScreenUpdates_Enabled()) { Cam_Draw(); m_XORRectangle.set(rectangle_t()); } m_drawing = false; }
const std::string MaterialSystem::getMaterialFilename () const { const std::string& mapname = GlobalMap().getName(); const std::string umpname = GlobalUMPSystem().getUMPFilename(mapname); std::string materialFilename; if (umpname.empty()) materialFilename = os::getFilenameFromPath(mapname); else materialFilename = os::getFilenameFromPath(umpname); std::string relativePath = "materials/" + os::stripExtension(materialFilename) + ".mat"; return relativePath; }
void CamWnd::jumpToObject(SelectionTest& selectionTest) { // Find a suitable target Instance scene::Instance* instance; GlobalSceneGraph().traverse(ObjectFinder(selectionTest, instance)); if (instance != NULL) { // An instance has been found, get the bounding box AABB found = instance->worldAABB(); // Focuse the view at the center of the found AABB GlobalMap().FocusViews(found.origin, getCameraAngles()[CAMERA_YAW]); } }
void ErrorCheckDialog::callbackFix (GtkWidget* widget, ErrorCheckDialog* self) { // close this dialog self->hide(); try { const std::string mapName = GlobalMap().getName(); CheckDialogCompilerIgnoreObserver observer; GlobalMapCompiler().fixErrors(mapName, observer); } catch (MapCompileException& e) { gtkutil::errorDialog(e.what()); } }
void MRU::loadMap(const std::string& fileName) { if (GlobalMap().askForSave(_("Open Map"))) { if (os::fileIsReadable(fileName)) { // Shut down the current map GlobalMap().freeMap(); // Load the file GlobalMap().load(fileName); // Update the MRU list with this file insert(fileName); } else { wxutil::Messagebox::ShowError( fmt::format(_("Could not read map file: {0}"), fileName)); } } }
void ToolsCheckErrors () { if (!GlobalMap().askForSave(_("Check Map"))) return; /* empty map? */ if (!GlobalRadiant().getCounter(counterBrushes).get()) { gtkutil::errorDialog(_("Nothing to fix in this map\n")); return; } ui::ErrorCheckDialog::showDialog(); }
bool MaterialSystem::isDefined(const std::string& texture, const std::string& content) { const std::string textureDir = GlobalTexturePrefix_get(); if (texture == textureDir || GlobalMap().isUnnamed()) return false; std::string skippedTextureDirectory = texture.substr(textureDir.length()); std::string materialDefinition = "material " + skippedTextureDirectory; /* check whether there is already an entry for the selected texture */ if (content.find(materialDefinition) != std::string::npos) return true; return false; }
void MapPosition::store(const cmd::ArgumentList& args) { rMessage() << "Storing map position #" << _index << std::endl; CamWndPtr camwnd = GlobalCamera().getActiveCamWnd(); if (camwnd != NULL) { _position = camwnd->getCameraOrigin(); _angle = camwnd->getCameraAngles(); // Tag the map as modified GlobalMap().setModified(true); } else { rError() << "MapPosition: Warning: Couldn't find Camera." << std::endl; } }
void constructPrefab(const AABB& aabb, const std::string& shader, EPatchPrefab eType, EViewType viewType, std::size_t width, std::size_t height) { GlobalSelectionSystem().setSelectedAll(false); scene::INodePtr node(GlobalPatchCreator(DEF2).createPatch()); GlobalMap().findOrInsertWorldspawn()->addChildNode(node); Patch* patch = Node_getPatch(node); patch->setShader(shader); patch->ConstructPrefab(aabb, eType, viewType, width, height); patch->controlPointsChanged(); Node_setSelected(node, true); }
CamWnd::CamWnd() : m_view(true), m_Camera(&m_view, CamWndQueueDraw(*this)), m_cameraview(m_Camera, &m_view, CamWndUpdate(*this)), m_drawing(false), _glWidget(true), m_gl_widget(static_cast<GtkWidget*>(_glWidget)), m_window_observer(NewWindowObserver()), m_XORRectangle(m_gl_widget), m_deferredDraw(WidgetQueueDrawCaller(*m_gl_widget)), m_deferred_motion(selection_motion, m_window_observer), m_selection_button_press_handler(0), m_selection_button_release_handler(0), m_selection_motion_handler(0), m_freelook_button_press_handler(0) { m_bFreeMove = false; GlobalWindowObservers_add(m_window_observer); GlobalWindowObservers_connectWidget(m_gl_widget); m_window_observer->setRectangleDrawCallback(ReferenceCaller1<CamWnd, Rectangle, camwnd_update_xor_rectangle>(*this)); m_window_observer->setView(m_view); gtk_widget_ref(m_gl_widget); gtk_widget_set_events(m_gl_widget, GDK_DESTROY | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_SCROLL_MASK); GTK_WIDGET_SET_FLAGS (m_gl_widget, GTK_CAN_FOCUS); gtk_widget_set_size_request(m_gl_widget, CAMWND_MINSIZE_X, CAMWND_MINSIZE_Y); g_object_set(m_gl_widget, "can-focus", TRUE, NULL); m_sizeHandler = g_signal_connect(G_OBJECT(m_gl_widget), "size_allocate", G_CALLBACK(camera_size_allocate), this); m_exposeHandler = g_signal_connect(G_OBJECT(m_gl_widget), "expose_event", G_CALLBACK(camera_expose), this); GlobalMap().addValidCallback(DeferredDrawOnMapValidChangedCaller(m_deferredDraw)); // Deactivate all commands, just to make sure disableDiscreteMoveEvents(); disableFreeMoveEvents(); // Now add the handlers for the non-freelook mode, the events are activated by this addHandlersMove(); g_signal_connect(G_OBJECT(m_gl_widget), "scroll_event", G_CALLBACK(wheelmove_scroll), this); GlobalSceneGraph().addSceneObserver(this); GlobalEventManager().connect(GTK_OBJECT(m_gl_widget)); }
void MaterialSystem::generateMaterialFromTexture () { if (GlobalMap().isUnnamed()) { // save the map first gtkutil::errorDialog(_("You have to save your map before material generation can work")); return; } loadMaterials(); if (!_materialLoaded) return; const std::string textureDir = GlobalTexturePrefix_get(); std::string append = ""; if (GlobalSelectionSystem().areFacesSelected()) { for (FaceInstancesList::iterator i = g_SelectedFaceInstances.m_faceInstances.begin(); i != g_SelectedFaceInstances.m_faceInstances.end(); ++i) { const FaceInstance& faceInstance = *(*i); const Face &face = faceInstance.getFace(); const std::string& texture = face.GetShader(); // don't generate materials for common textures if (texture.find("tex_common") != std::string::npos) continue; std::string skippedTextureDirectory = texture.substr(textureDir.length()); std::string materialDefinition = "material " + skippedTextureDirectory; /* check whether there is already an entry for the selected texture */ if (_material.find(materialDefinition) == std::string::npos) { std::stringstream os; ContentsFlagsValue flags; ContentsFlagsValue faceFlags(face.GetFlags()); os << "{" << std::endl; os << "\t" << materialDefinition << std::endl; os << "\t{" << std::endl; generateMaterialForFace(flags.getContentFlags(), flags.getSurfaceFlags(), skippedTextureDirectory, os); os << "\t}" << std::endl; os << "}" << std::endl; append += os.str(); } } } showMaterialDefinitionAndAppend(append); }
void ErrorCheckDialog::callbackSelect (GtkTreeSelection* sel, ErrorCheckDialog* self) { // Get the selection GtkTreeIter selected; bool hasSelection = gtk_tree_selection_get_selected(sel, NULL, &selected) ? true : false; if (hasSelection) { // get the values from the tree view model list const int entnum = gtkutil::TreeModel::getInt(GTK_TREE_MODEL(self->_listStore), &selected, CHECK_ENTITY); const int brushnum = gtkutil::TreeModel::getInt(GTK_TREE_MODEL(self->_listStore), &selected, CHECK_BRUSH); // correct brush and ent values if (brushnum < 0 || entnum < 0) return; // and now do the real selection GlobalMap().SelectBrush(entnum, brushnum, true); } }
/** * Method recreates rma tile menu adding entries for all tiles in current rma if available */ void UMPMenu::addItems() { IMenuManager* menuManager = GlobalUIManager().getMenuManager(); menuManager->remove(MENU_PATH); std::string umpFilename = GlobalUMPSystem().getUMPFilename(GlobalMap().getName()); if (umpFilename.empty()) return; map::ump::UMPFile file = map::ump::UMPFile(umpFilename); if (!file.load()) return; // Create the sub menu item in the map menu menuManager->add(MENU_MAP_PATH, MENU_UMP_NAME, ui::menuFolder, _("RMA tiles"), MENU_ICON, ""); UMPTileToMenuItemVisitor visitor(file); file.forEachTile(visitor); }
ErrorCheckDialog::ErrorCheckDialog () : gtkutil::BlockingTransientWindow(_("Error checking"), GlobalRadiant().getMainWindow()) { gtk_window_set_default_size(GTK_WINDOW(getWindow()), CHECKDLG_DEFAULT_SIZE_X, CHECKDLG_DEFAULT_SIZE_Y); gtk_container_set_border_width(GTK_CONTAINER(getWindow()), 12); gtk_window_set_type_hint(GTK_WINDOW(getWindow()), GDK_WINDOW_TYPE_HINT_DIALOG); // Create all the widgets populateWindow(); // Propagate shortcuts to the main window GlobalEventManager().connectDialogWindow(GTK_WINDOW(getWindow())); try { const std::string mapName = GlobalMap().getName(); CompilerObserver observer(_listStore); GlobalMapCompiler().performCheck(mapName, observer); // Show the window and its children show(); } catch (MapCompileException& e) { hide(); gtkutil::errorDialog(e.what()); } }
void Map::saveMapAs(const cmd::ArgumentList& args) { GlobalMap().saveAs(); }
/** * Callback function for menu items to load the specific file * @param menuItem activated menu item * @param name map name to load as pointer to g_quark */ void UMPMenu::_activate (GtkMenuItem* menuItem, gpointer name) { GlobalMap().changeMap(_("Open Map"), g_quark_to_string(gpointer_to_int(name))); }
void Map::loadPrefab(const cmd::ArgumentList& args) { GlobalMap().loadPrefabAt(Vector3(0,0,0)); }