Skip to content

Commit

Permalink
Initial dialog for choosing pointfiles
Browse files Browse the repository at this point in the history
Dialog is shown by File->Pointfile if (and only if) there is more than one
pointfile available. The dialog shows the correct list of files but is rather
useless at the moment since the selection does not have any influence over the
pointfile which is actually loaded.
  • Loading branch information
Matthew Mott committed May 25, 2021
1 parent dfc0ae4 commit 01cd735
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 13 deletions.
2 changes: 1 addition & 1 deletion install/menu.xml
Expand Up @@ -29,7 +29,7 @@
<menuSeparator />
<menuItem name="gameSelector" caption="&amp;Game/Project Setup..." command="ProjectSettings" />
<menuSeparator />
<menuItem name="pointfile" caption="&amp;Pointfile" command="TogglePointfile" icon="pointfile16.png"/>
<menuItem name="pointfile" caption="&amp;Pointfile" command="ChooseAndTogglePointfile" icon="pointfile16.png"/>
<menuSeparator />
<!-- MRU is inserted automatically at this position -->
<menuItem name="exit" caption="E&amp;xit" command="Exit" />
Expand Down
1 change: 1 addition & 0 deletions radiant/CMakeLists.txt
Expand Up @@ -148,6 +148,7 @@ add_executable(darkradiant
ui/patch/PatchCreateDialog.cpp
ui/patch/PatchInspector.cpp
ui/patch/PatchThickenDialog.cpp
ui/PointFileChooser.cpp
ui/prefabselector/PrefabSelector.cpp
ui/prefdialog/GameSetupDialog.cpp
ui/prefdialog/GameSetupPage.cpp
Expand Down
60 changes: 60 additions & 0 deletions radiant/ui/PointFileChooser.cpp
@@ -0,0 +1,60 @@
#include "PointFileChooser.h"

#include "imainframe.h"
#include "imap.h"
#include "icommandsystem.h"
#include "os/fs.h"
#include "command/ExecutionFailure.h"

#include <wx/frame.h>
#include <wx/sizer.h>
#include <wx/choice.h>
#include <list>

namespace ui
{

PointFileChooser::PointFileChooser(const wxArrayString& files)
: wxDialog(GlobalMainFrame().getWxTopLevelWindow(), wxID_ANY,
"Choose pointfile")
{
SetSizer(new wxBoxSizer(wxVERTICAL));

// Construct and populate the dropdown list
auto list = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
files);
list->SetSelection(0);
GetSizer()->Add(list, 0, wxEXPAND | wxALL, 12);

// Add dialog buttons
auto btnSizer = CreateStdDialogButtonSizer(wxOK | wxCANCEL);
GetSizer()->Add(btnSizer, 0, wxALIGN_RIGHT | wxALIGN_BOTTOM, 0);
}

void PointFileChooser::chooseAndToggle()
{
// Determine the list of pointfiles
std::list<fs::path> pointfiles;
GlobalMapModule().forEachPointfile([&](const fs::path& p)
{ pointfiles.push_back(p); });
if (pointfiles.empty())
throw cmd::ExecutionFailure("No pointfiles found for current map.");

// If there is a choice to make, show the dialog
if (pointfiles.size() > 1)
{
// Construct list of wxString filenames
wxArrayString filenames;
for (const fs::path& p: pointfiles)
filenames.Add(static_cast<std::string>(p.filename()));

// Show dialog with list of pointfiles
PointFileChooser chooser(filenames);
chooser.ShowModal();
}

// Hand over to the actual pointfile renderer to toggle visibility
GlobalCommandSystem().executeCommand("TogglePointfile");
}

}
27 changes: 27 additions & 0 deletions radiant/ui/PointFileChooser.h
@@ -0,0 +1,27 @@
#pragma once

#include <wx/dialog.h>

namespace ui
{

/// Selector dialog for pointfiles associated with the current map
class PointFileChooser: public wxDialog
{
// Dialog constructor
PointFileChooser(const wxArrayString& files);

public:

/**
* \brief Toggle pointfile visibility, showing the chooser if necessary.
*
* If there is only a single pointfile available, this method acts as a
* simple visibility toggle. If there is more than one pointfile, the
* chooser dialog will be shown before toggling visibility on. If there are
* no pointfiles available, an error dialog will be shown.
*/
static void chooseAndToggle();
};

}
28 changes: 16 additions & 12 deletions radiant/ui/UserInterfaceModule.cpp
Expand Up @@ -61,6 +61,7 @@
#include "ui/brush/FindBrush.h"
#include "ui/mousetool/RegistrationHelper.h"
#include "ui/mapselector/MapSelector.h"
#include "ui/PointFileChooser.h"

#include <wx/version.h>

Expand Down Expand Up @@ -130,19 +131,19 @@ void UserInterfaceModule::initialiseModule(const IApplicationContext& ctx)

// Add the orthocontext menu's layer actions
GlobalOrthoContextMenu().addItem(
std::make_shared<LayerOrthoContextMenuItem>(_(ADD_TO_LAYER_TEXT),
std::make_shared<LayerOrthoContextMenuItem>(_(ADD_TO_LAYER_TEXT),
LayerOrthoContextMenuItem::AddToLayer),
IOrthoContextMenu::SECTION_LAYER
);

GlobalOrthoContextMenu().addItem(
std::make_shared<LayerOrthoContextMenuItem>(_(MOVE_TO_LAYER_TEXT),
std::make_shared<LayerOrthoContextMenuItem>(_(MOVE_TO_LAYER_TEXT),
LayerOrthoContextMenuItem::MoveToLayer),
IOrthoContextMenu::SECTION_LAYER
);

GlobalOrthoContextMenu().addItem(
std::make_shared<LayerOrthoContextMenuItem>(_(REMOVE_FROM_LAYER_TEXT),
std::make_shared<LayerOrthoContextMenuItem>(_(REMOVE_FROM_LAYER_TEXT),
LayerOrthoContextMenuItem::RemoveFromLayer),
IOrthoContextMenu::SECTION_LAYER
);
Expand Down Expand Up @@ -239,7 +240,7 @@ void UserInterfaceModule::shutdownModule()
_editStopwatchStatus.reset();
_manipulatorToggle.reset();
_selectionModeToggle.reset();

_mruMenu.reset();
}

Expand All @@ -265,17 +266,17 @@ void UserInterfaceModule::HandleNotificationMessage(radiant::NotificationMessage
switch (msg.getType())
{
case radiant::NotificationMessage::Information:
wxutil::Messagebox::Show(msg.hasTitle() ? msg.getTitle() : _("Notification"),
wxutil::Messagebox::Show(msg.hasTitle() ? msg.getTitle() : _("Notification"),
msg.getMessage(), IDialog::MessageType::MESSAGE_CONFIRM, parentWindow);
break;

case radiant::NotificationMessage::Warning:
wxutil::Messagebox::Show(msg.hasTitle() ? msg.getTitle() : _("Warning"),
wxutil::Messagebox::Show(msg.hasTitle() ? msg.getTitle() : _("Warning"),
msg.getMessage(), IDialog::MessageType::MESSAGE_WARNING, parentWindow);
break;

case radiant::NotificationMessage::Error:
wxutil::Messagebox::Show(msg.hasTitle() ? msg.getTitle() : _("Error"),
wxutil::Messagebox::Show(msg.hasTitle() ? msg.getTitle() : _("Error"),
msg.getMessage(), IDialog::MessageType::MESSAGE_ERROR, parentWindow);
break;
};
Expand All @@ -300,9 +301,9 @@ void UserInterfaceModule::initialiseEntitySettings()
applyPatchVertexColours();

_coloursUpdatedConn = ColourSchemeEditor::signal_ColoursChanged().connect(
[this]() {
applyEntityVertexColours();
applyBrushVertexColours();
[this]() {
applyEntityVertexColours();
applyBrushVertexColours();
applyPatchVertexColours();
}
);
Expand Down Expand Up @@ -343,7 +344,7 @@ void UserInterfaceModule::refreshShadersCmd(const cmd::ArgumentList& args)
// Disable screen updates for the scope of this function
auto blocker = GlobalMainFrame().getScopedScreenUpdateBlocker(_("Processing..."), _("Loading Shaders"));

// Reload the Shadersystem, this will also trigger an
// Reload the Shadersystem, this will also trigger an
// OpenGLRenderSystem unrealise/realise sequence as the rendersystem
// is attached to this class as Observer
// We can't do this refresh() operation in a thread it seems due to context binding
Expand All @@ -365,8 +366,11 @@ void UserInterfaceModule::registerUICommands()
GlobalCommandSystem().addCommand("PatchInspector", PatchInspector::toggle);
GlobalCommandSystem().addCommand("OverlayDialog", OverlayDialog::toggle);
GlobalCommandSystem().addCommand("TransformDialog", TransformDialog::toggle);
GlobalCommandSystem().addCommand("ChooseAndTogglePointfile",
[](const cmd::ArgumentList&)
{ PointFileChooser::chooseAndToggle(); });

GlobalCommandSystem().addCommand("FindBrush", FindBrushDialog::Show);
GlobalCommandSystem().addCommand("FindBrush", FindBrushDialog::Show);
GlobalCommandSystem().addCommand("AnimationPreview", MD5AnimationViewer::Show);
GlobalCommandSystem().addCommand("EditColourScheme", ColourSchemeEditor::DisplayDialog);

Expand Down

0 comments on commit 01cd735

Please sign in to comment.