Skip to content

Commit

Permalink
#5568: Preprocess the path to DDS files to be assignable to a map exp…
Browse files Browse the repository at this point in the history
…ression.
  • Loading branch information
codereader committed Mar 23, 2021
1 parent 0c663f5 commit ffe0f0a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
16 changes: 16 additions & 0 deletions libs/os/path.h
Expand Up @@ -171,6 +171,22 @@ namespace os
}
}

/**
* Strip off the extension of the given path and return the new string.
* If there is no extension, the original string is returned.
*/
inline std::string removeExtension(const std::string& path)
{
std::size_t dotPos = path.rfind('.');

if (dotPos == std::string::npos)
{
return path;
}

return path.substr(0, dotPos);
}

/**
* Get the containing folder of the specified object. This is calculated
* as the directory before the rightmost slash (which will be the object
Expand Down
14 changes: 13 additions & 1 deletion radiant/ui/common/ImageFilePopulator.h
Expand Up @@ -3,6 +3,8 @@
#include "ifilesystem.h"
#include "gamelib.h"
#include "string/case_conv.h"
#include "string/predicate.h"
#include "string/trim.h"
#include "os/path.h"
#include "wxutil/dataview/ThreadedResourceTreePopulator.h"
#include "wxutil/dataview/ResourceTreeView.h"
Expand Down Expand Up @@ -40,15 +42,25 @@ class ImageFileFunctor :

void addFile(const vfs::FileInfo& fileInfo)
{
const std::string ddsPrefix = "dds/";
std::string fullPath = fileInfo.fullPath();

// Sort the shader into the tree and set the values
addPath(fullPath, [&](wxutil::TreeModel::Row& row, const std::string& path,
const std::string& leafName, bool isFolder)
{
// The map expressions don't need any file extensions
auto imageFilePath = os::removeExtension(path);

// Cut off the dds prefix, it won't be valid when set in a material
if (string::istarts_with(path, ddsPrefix))
{
imageFilePath = imageFilePath.substr(ddsPrefix.length());
}

row[_columns.iconAndName] = wxVariant(wxDataViewIconText(leafName, isFolder ? _folderIcon : _fileIcon));
row[_columns.leafName] = leafName;
row[_columns.fullName] = path;
row[_columns.fullName] = imageFilePath;
row[_columns.isFolder] = isFolder;
row[_columns.isFavourite] = false;

Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/common/ImageFileSelector.cpp
Expand Up @@ -53,7 +53,7 @@ int ImageFileSelector::ShowModal()
return result;
}

std::string ImageFileSelector::GetSelection()
std::string ImageFileSelector::GetSelectedImageFilePath()
{
auto item = _treeView->GetSelection();
if (!item.IsOk()) return std::string();
Expand Down
3 changes: 2 additions & 1 deletion radiant/ui/common/ImageFileSelector.h
Expand Up @@ -27,7 +27,8 @@ class ImageFileSelector :

int ShowModal() override;

std::string GetSelection();
// Returns the path of the selected image file
std::string GetSelectedImageFilePath();

private:
void onTreeSelectionChanged(wxDataViewEvent& ev);
Expand Down
4 changes: 3 additions & 1 deletion radiant/ui/materials/MapExpressionEntry.h
@@ -1,5 +1,6 @@
#pragma once

#include "i18n.h"
#include <wx/panel.h>
#include <wx/textctrl.h>
#include <wx/button.h>
Expand All @@ -18,7 +19,7 @@ class MapExpressionEntry :
wxButton* _browseButton;

public:
MapExpressionEntry(wxWindow* parent = nullptr) :
MapExpressionEntry(wxWindow* parent) :
wxPanel(parent, wxID_ANY)
{
SetSizer(new wxBoxSizer(wxHORIZONTAL));
Expand All @@ -28,6 +29,7 @@ class MapExpressionEntry :
_browseButton = new wxButton(this, wxID_ANY, "...");
_browseButton->SetMaxSize(wxSize(40, -1));
_browseButton->Bind(wxEVT_BUTTON, &MapExpressionEntry::onBrowseButtonClick, this);
_browseButton->SetToolTip(_("Select an Image File"));

GetSizer()->Add(_textEntry, 1, wxRIGHT|wxALIGN_CENTER_VERTICAL, 6);
GetSizer()->Add(_browseButton, 0, wxALIGN_CENTER_VERTICAL, 0);
Expand Down

0 comments on commit ffe0f0a

Please sign in to comment.