void MapPropertiesDialog::populateModChoice(const String& mod) {
            m_modChoice->Clear();

            IO::FileManager fileManager;
            Preferences::PreferenceManager& prefs = Preferences::PreferenceManager::preferences();
            const String& quakePath = prefs.getString(Preferences::QuakePath);
            if (fileManager.exists(quakePath) && fileManager.isDirectory(quakePath)) {
                const StringList modDirs = fileManager.directoryContents(quakePath, "", true, false);

                int id1Index = -1;
                int selectionIndex = -1;
                for (size_t i = 0; i < modDirs.size(); i++) {
                    const String& item = modDirs[i];
                    m_modChoice->Append(item);
                    if (Utility::equalsString(item, "id1", false))
                        id1Index = static_cast<int>(i);
                    if (Utility::equalsString(item, mod, false))
                        selectionIndex = static_cast<int>(i);
                }

                if (selectionIndex == -1)
                    selectionIndex = id1Index;
                m_modChoice->SetSelection(selectionIndex);
            }
        }
Ejemplo n.º 2
0
 void EntityDefinitionManager::load(const String& path) {
     Preferences::PreferenceManager& prefs = Preferences::PreferenceManager::preferences();
     const Color& defaultColor = prefs.getColor(Preferences::EntityBoundsColor);
     EntityDefinitionMap newDefinitions;
     
     IO::FileManager fileManager;
     IO::MappedFile::Ptr file = fileManager.mapFile(path);
     if (file.get() != NULL) {
         try {
             const String extension = fileManager.pathExtension(path);
             if (Utility::equalsString(extension, "def", false)) {
                 IO::DefParser parser(file->begin(), file->end(), defaultColor);
                 
                 EntityDefinition* definition = NULL;
                 while ((definition = parser.nextDefinition()) != NULL)
                     Utility::insertOrReplace(newDefinitions, definition->name(), definition);
             } else if (Utility::equalsString(extension, "fgd", false)) {
                 IO::FgdParser parser(file->begin(), file->end(), defaultColor);
                 
                 EntityDefinition* definition = NULL;
                 while ((definition = parser.nextDefinition()) != NULL)
                     Utility::insertOrReplace(newDefinitions, definition->name(), definition);
             }
             
             clear();
             m_entityDefinitions = newDefinitions;
             m_path = path;
         } catch (IO::ParserException e) {
             Utility::deleteAll(newDefinitions);
             m_console.error(e.what());
         }
     } else {
         m_console.error("Unable to open entity definition file %s", path.c_str());
     }
 }
        AboutDialog::AboutDialog(wxWindow* parent) :
        wxDialog(parent, wxID_ANY, wxT("About")) {
            IO::FileManager fileManager;
            
            wxBitmap icon(fileManager.appendPath(fileManager.resourceDirectory(), "Icon.png"), wxBITMAP_TYPE_PNG);
            
            wxStaticBitmap* appIcon = new wxStaticBitmap(this, wxID_ANY, icon);
            wxStaticLine* appLine = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL);
            wxStaticText* appName = new wxStaticText(this, wxID_ANY, wxT("TrenchBroom"));
            appName->SetFont(appName->GetFont().Larger().Larger().Larger().Larger().Bold());
            
            wxStaticText* appClaim = new wxStaticText(this, wxID_ANY, wxT("A Modern Level Editor for Quake"));
            
            wxString versionStr(wxT("Version "));
            versionStr << VERSIONSTR;
            
            wxStaticText* version = new wxStaticText(this, wxID_ANY, versionStr);
            
            wxStaticText* devHeader = new wxStaticText(this, wxID_ANY, wxT("Development"));
            devHeader->SetFont(devHeader->GetFont().Bold());
            wxStaticText* devText = new wxStaticText(this, wxID_ANY, wxT("Kristian Duske"));
            
            wxStaticText* contrHeader = new wxStaticText(this, wxID_ANY, wxT("Contributions"));
            contrHeader->SetFont(contrHeader->GetFont().Bold());
            wxSizer* contrText = CreateTextSizer(wxT("Corey Jones (feedback, testing, documentation)\nAndré König (feedback, testing)\nWouter van Oortmerssen (feedback)\nHannes Kröger (testing)\nMorgan Allen (testing)\nForest Hale (fov code)\nChristian Grawert (Quake.fdg)"));
            
            wxSizer* copyright = CreateTextSizer(wxT("Copyright 2010-2013 Kristian Duske\nQuake is a registered trademark of id Software"));

            wxGridBagSizer* sizer = new wxGridBagSizer();

            int row = 0;
            sizer->Add(0, 10, wxGBPosition(row++, 1));
            sizer->AddGrowableRow(static_cast<size_t>(row - 1));
            sizer->Add(appName, wxGBPosition(row++, 1));
            sizer->Add(appLine, wxGBPosition(row++, 1), wxDefaultSpan, wxEXPAND);
            sizer->Add(appClaim, wxGBPosition(row++, 1));
            sizer->Add(0, 20, wxGBPosition(row++, 1));
            sizer->Add(version, wxGBPosition(row++, 1));
            sizer->Add(0, 20, wxGBPosition(row++, 1));
            sizer->Add(devHeader, wxGBPosition(row++, 1));
            sizer->Add(devText, wxGBPosition(row++, 1));
            sizer->Add(0, 20, wxGBPosition(row++, 1));
            sizer->Add(contrHeader, wxGBPosition(row++, 1));
            sizer->Add(contrText, wxGBPosition(row++, 1));
            sizer->Add(0, 20, wxGBPosition(row++, 1));
            sizer->Add(copyright, wxGBPosition(row++, 1));
            sizer->Add(0, 10, wxGBPosition(row++, 1));
            sizer->AddGrowableRow(static_cast<size_t>(row - 1));
            sizer->Add(appIcon, wxGBPosition(0, 0), wxGBSpan(row, 1), wxALIGN_CENTER);
            
            SetSizer(sizer);
            SetSize(650, 420);
            CenterOnParent();
            
            SetBackgroundColour(*wxWHITE);
        }
Ejemplo n.º 4
0
 StringList EntityDefinitionManager::builtinDefinitionFiles() {
     StringList result;
     
     IO::FileManager fileManager;
     const String resourcePath = fileManager.resourceDirectory();
     const String defPath = fileManager.appendPathComponent(resourcePath, "Defs");
     
     const StringList defFiles = fileManager.directoryContents(defPath, "def");
     const StringList fgdFiles = fileManager.directoryContents(defPath, "fgd");
     
     result.insert(result.end(), defFiles.begin(), defFiles.end());
     result.insert(result.end(), fgdFiles.begin(), fgdFiles.end());
     
     std::sort(result.begin(), result.end());
     return result;
 }
        EntityModelRenderer* EntityModelRendererManager::modelRenderer(const Model::ModelDefinition& modelDefinition, const StringList& searchPaths) {
            assert(m_palette != NULL);
            IO::FileManager fileManager;
            
            if (!m_valid) {
                clear();
                m_valid = true;
            }
            
            const String key = modelRendererKey(modelDefinition, searchPaths);
            MismatchCache::iterator mismatchIt = m_mismatches.find(key);
            if (mismatchIt != m_mismatches.end())
                return NULL;
            
            EntityModelRendererCache::iterator rendererIt = m_modelRenderers.find(key);
            if (rendererIt != m_modelRenderers.end())
                return rendererIt->second;

            String modelName = Utility::toLower(modelDefinition.name().substr(1));
            String ext = Utility::toLower(fileManager.pathExtension(modelName));
            if (ext == "mdl") {
                unsigned int skinIndex = modelDefinition.skinIndex();
                unsigned int frameIndex = modelDefinition.frameIndex();

                Model::AliasManager& aliasManager = *Model::AliasManager::sharedManager;
                const Model::Alias* alias = aliasManager.alias(modelName, searchPaths, m_console);

                if (alias != NULL && skinIndex < alias->skins().size() && frameIndex < alias->frames().size()) {
                    Renderer::EntityModelRenderer* renderer = new AliasModelRenderer(*alias, frameIndex, skinIndex, *m_vbo, *m_palette);
                    m_modelRenderers[key] = renderer;
                    return renderer;
                }
            } else if (ext == "bsp") {
                Model::BspManager& bspManager = *Model::BspManager::sharedManager;
                const Model::Bsp* bsp = bspManager.bsp(modelName, searchPaths, m_console);
                if (bsp != NULL) {
                    Renderer::EntityModelRenderer* renderer = new BspModelRenderer(*bsp, *m_vbo, *m_palette);
                    m_modelRenderers[key] = renderer;
                    return renderer;
                }
            } else {
                m_console.warn("Unknown model type '%s'", ext.c_str());
            }

            m_mismatches.insert(key);
            return NULL;
        }
Ejemplo n.º 6
0
void Console::logToFile(const LogMessage& message) {
#if defined __APPLE__
    NSLogWrapper(message.string());
#else
    IO::FileManager fileManager;
    const String logDirectory = fileManager.logDirectory();
    if (logDirectory.empty())
        return;
    if (!fileManager.exists(logDirectory))
        fileManager.makeDirectory(logDirectory);
    const String logFilePath = fileManager.appendPath(logDirectory, "TrenchBroom.log");
    std::fstream logStream(logFilePath.c_str(), std::ios::out | std::ios::app);
    if (logStream.is_open()) {
        wxDateTime now = wxDateTime::Now();
        logStream << wxGetProcessId() << " " << now.FormatISOCombined(' ') << ": " << message.string() << std::endl;
    }
#endif
}
        void MapPropertiesDialog::Create(wxWindow* parent, Model::MapDocument& document) {
            wxDialog::Create(parent, wxID_ANY, wxT("Map Properties"));
            m_document = &document;

            const int width = 330;

            wxStaticBox* modBox = new wxStaticBox(this, wxID_ANY, wxT("Entity Definitions"));
            wxStaticText* defText = new wxStaticText(modBox, wxID_ANY, wxT("Select an entity definition file for this map."));
#if defined __APPLE__
            defText->SetFont(*wxSMALL_FONT);
#endif
            defText->Wrap(width);
            m_defChoice = new wxChoice(modBox, CommandIds::MapPropertiesDialog::DefChoiceId);

            wxStaticText* modText = new wxStaticText(modBox, wxID_ANY, wxT("Select a subdirectory within your Quake directory to search for entity models. ID1 is always searched in addition to the selected subdirectory."));
#if defined __APPLE__
            modText->SetFont(*wxSMALL_FONT);
#endif
            modText->Wrap(width);
            m_modChoice = new wxChoice(modBox, CommandIds::MapPropertiesDialog::ModChoiceId);

            wxSizer* modBoxSizer = new wxBoxSizer(wxVERTICAL);
            modBoxSizer->AddSpacer(LayoutConstants::StaticBoxTopMargin);
            modBoxSizer->Add(defText, 0, wxEXPAND | wxLEFT | wxRIGHT, LayoutConstants::StaticBoxSideMargin);
            modBoxSizer->AddSpacer(LayoutConstants::ControlVerticalMargin);
            modBoxSizer->Add(m_defChoice, 0, wxEXPAND | wxLEFT | wxRIGHT, LayoutConstants::StaticBoxSideMargin);
            modBoxSizer->AddSpacer(2 * LayoutConstants::ControlVerticalMargin);
            modBoxSizer->Add(modText, 0, wxEXPAND | wxLEFT | wxRIGHT, LayoutConstants::StaticBoxSideMargin);
            modBoxSizer->AddSpacer(LayoutConstants::ControlVerticalMargin);
            modBoxSizer->Add(m_modChoice, 0, wxEXPAND | wxLEFT | wxRIGHT, LayoutConstants::StaticBoxSideMargin);
            modBoxSizer->AddSpacer(LayoutConstants::StaticBoxBottomMargin);
            modBox->SetSizerAndFit(modBoxSizer);

            IO::FileManager fileManager;
            String resourcePath = fileManager.resourceDirectory();

            wxBitmap add(fileManager.appendPath(resourcePath, "Add.png"), wxBITMAP_TYPE_PNG);
            wxBitmap remove(fileManager.appendPath(resourcePath, "Remove.png"), wxBITMAP_TYPE_PNG);
            wxBitmap up(fileManager.appendPath(resourcePath, "Up.png"), wxBITMAP_TYPE_PNG);
            wxBitmap down(fileManager.appendPath(resourcePath, "Down.png"), wxBITMAP_TYPE_PNG);

            wxStaticBox* wadBox = new wxStaticBox(this, wxID_ANY, wxT("Texture Wads"));
            wxStaticText* wadText = new wxStaticText(wadBox, wxID_ANY, wxT("Manage the wad files for this map. Wad files are searched from bottom to top, so textures in the lower entries override textures in the upper entries if the names of the textures are the same."));
#if defined __APPLE__
            wadText->SetFont(*wxSMALL_FONT);
#endif
            wadText->Wrap(width);

            m_wadList = new WadListBox(wadBox, CommandIds::MapPropertiesDialog::WadListId);
            m_wadList->SetMinSize(wxSize(wxDefaultSize.x, 120));
            m_addWadButton = new wxBitmapButton(wadBox, CommandIds::MapPropertiesDialog::AddWadButtonId, add, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN);
            m_addWadButton->SetMinSize(wxSize(20, 20));
            m_removeWadsButton = new wxBitmapButton(wadBox, CommandIds::MapPropertiesDialog::RemoveWadsButtonId, remove, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN);
            m_removeWadsButton->SetMinSize(wxSize(20, 20));
            m_moveWadUpButton = new wxBitmapButton(wadBox, CommandIds::MapPropertiesDialog::MoveWadUpButtonId, up, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN);
            m_moveWadUpButton->SetMinSize(wxSize(20, 20));
            m_moveWadDownButton = new wxBitmapButton(wadBox, CommandIds::MapPropertiesDialog::MoveWadDownButtonId, down, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN);
            m_moveWadDownButton->SetMinSize(wxSize(20, 20));

            wxSizer* wadButtonsSizer = new wxBoxSizer(wxHORIZONTAL);
            wadButtonsSizer->Add(m_addWadButton);
            wadButtonsSizer->AddSpacer(LayoutConstants::ControlHorizontalMargin);
            wadButtonsSizer->Add(m_removeWadsButton);
            wadButtonsSizer->AddSpacer(LayoutConstants::ControlHorizontalMargin);
            wadButtonsSizer->Add(m_moveWadUpButton);
            wadButtonsSizer->AddSpacer(LayoutConstants::ControlHorizontalMargin);
            wadButtonsSizer->Add(m_moveWadDownButton);

            wxSizer* wadBoxSizer = new wxBoxSizer(wxVERTICAL);
            wadBoxSizer->AddSpacer(LayoutConstants::StaticBoxTopMargin);
            wadBoxSizer->Add(wadText, 0, wxEXPAND | wxLEFT | wxRIGHT, LayoutConstants::StaticBoxSideMargin);
            wadBoxSizer->AddSpacer(LayoutConstants::ControlVerticalMargin);
            wadBoxSizer->Add(m_wadList, 0, wxEXPAND | wxLEFT | wxRIGHT, LayoutConstants::StaticBoxSideMargin);
            wadBoxSizer->AddSpacer(LayoutConstants::ControlVerticalMargin);
            wadBoxSizer->Add(wadButtonsSizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxALIGN_LEFT, LayoutConstants::StaticBoxSideMargin);
            wadBoxSizer->AddSpacer(LayoutConstants::StaticBoxBottomMargin);
            wadBox->SetSizerAndFit(wadBoxSizer);

            wxStaticBox* coordBox = new wxStaticBox(this, wxID_ANY, wxT("Plane Point Coordinates"));
            wxStaticText* coordText = new wxStaticText(coordBox, wxID_ANY, wxT("By default, TrenchBroom stores plane point coordinates as floating point values internally and in the map file. Checking this option will force it to use integer coordinates. This improves compatibility with older compilers, but it will lead to less precision when editing vertices."));
#if defined __APPLE__
            coordText->SetFont(*wxSMALL_FONT);
#endif
            coordText->Wrap(width);
            m_intFacePointsCheckBox = new wxCheckBox(coordBox, CommandIds::MapPropertiesDialog::ForceIntCoordsId, wxT("Force integer plane points"));

            wxSizer* coordBoxSizer = new wxBoxSizer(wxVERTICAL);
            coordBoxSizer->AddSpacer(LayoutConstants::StaticBoxTopMargin);
            coordBoxSizer->Add(coordText, 0, wxEXPAND | wxLEFT | wxRIGHT, LayoutConstants::StaticBoxSideMargin);
            coordBoxSizer->AddSpacer(LayoutConstants::ControlVerticalMargin);
            coordBoxSizer->Add(m_intFacePointsCheckBox, 0, wxEXPAND | wxLEFT | wxRIGHT, LayoutConstants::StaticBoxSideMargin);
            coordBoxSizer->AddSpacer(LayoutConstants::StaticBoxBottomMargin);
            coordBox->SetSizerAndFit(coordBoxSizer);

            wxSizer* buttonSizer = CreateButtonSizer(wxCLOSE);
            SetAffirmativeId(wxCLOSE);
            SetEscapeId(wxCLOSE);

            wxSizer* outerSizer = new wxBoxSizer(wxVERTICAL);
            outerSizer->Add(modBox, 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, LayoutConstants::DialogOuterMargin);
            outerSizer->AddSpacer(LayoutConstants::ControlVerticalMargin);
            outerSizer->Add(wadBox, 1, wxEXPAND | wxLEFT | wxRIGHT, LayoutConstants::DialogOuterMargin);
            outerSizer->AddSpacer(LayoutConstants::ControlVerticalMargin);
            outerSizer->Add(coordBox, 0, wxEXPAND | wxLEFT | wxRIGHT, LayoutConstants::DialogOuterMargin);
            outerSizer->Add(buttonSizer, 0, wxEXPAND | wxALL, LayoutConstants::DialogButtonMargin);

            SetSizerAndFit(outerSizer);

#ifdef __APPLE__
            // allow the dialog to be closed using CMD+W
            wxAcceleratorEntry acceleratorEntries[1];
            acceleratorEntries[0].Set(wxACCEL_CMD, static_cast<int>('W'), wxID_CLOSE);
            wxAcceleratorTable accceleratorTable(1, acceleratorEntries);
            SetAcceleratorTable(accceleratorTable);
#endif

            init();

            CommandProcessor::BeginGroup(m_document->GetCommandProcessor(), "Edit map properties");
        }