Skip to content

Commit

Permalink
Add new UserInterfaceModule and migrate Layer context menu init code
Browse files Browse the repository at this point in the history
UI module should take care of initialising the UI classes, in an effort
to disentangle the UI code from the underlying model code.
  • Loading branch information
codereader committed Jan 2, 2017
1 parent b62e6d0 commit 3b53afc
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 35 deletions.
1 change: 1 addition & 0 deletions radiant/Makefile.am
Expand Up @@ -65,6 +65,7 @@ darkradiant_SOURCES = main.cpp \
render/RenderSystemFactory.cpp \
render/View.cpp \
render/debug/SpacePartitionRenderer.cpp \
ui/UserInterfaceModule.cpp \
ui/entitychooser/EntityClassChooser.cpp \
ui/entitychooser/EntityClassTreePopulator.cpp \
ui/prefabselector/PrefabPopulator.cpp \
Expand Down
37 changes: 2 additions & 35 deletions radiant/layers/LayerSystem.cpp
Expand Up @@ -21,10 +21,8 @@
#include "wxutil/dialog/Dialog.h"
#include "wxutil/dialog/MessageBox.h"
#include "wxutil/EntryAbortedException.h"
#include "wxutil/menu/CommandMenuItem.h"

#include "ui/layers/LayerControlDialog.h"
#include "ui/layers/LayerOrthoContextMenuItem.h"

#include <functional>

Expand All @@ -34,14 +32,6 @@ namespace scene
namespace
{
const char* const DEFAULT_LAYER_NAME = N_("Default");

const char* const LAYER_ICON = "layers.png";
const char* const CREATE_LAYER_TEXT = N_("Create Layer...");

const char* const ADD_TO_LAYER_TEXT = N_("Add to Layer...");
const char* const MOVE_TO_LAYER_TEXT = N_("Move to Layer...");
const char* const REMOVE_FROM_LAYER_TEXT = N_("Remove from Layer...");

const int DEFAULT_LAYER = 0;
}

Expand Down Expand Up @@ -453,7 +443,8 @@ int LayerSystem::getLowestUnusedLayerID() {
}

// RegisterableModule implementation
const std::string& LayerSystem::getName() const {
const std::string& LayerSystem::getName() const
{
static std::string _name(MODULE_LAYERSYSTEM);
return _name;
}
Expand All @@ -466,8 +457,6 @@ const StringSet& LayerSystem::getDependencies() const
{
_dependencies.insert(MODULE_EVENTMANAGER);
_dependencies.insert(MODULE_COMMANDSYSTEM);
_dependencies.insert(MODULE_UIMANAGER);
_dependencies.insert(MODULE_ORTHOCONTEXTMENU);
_dependencies.insert(MODULE_MAPINFOFILEMANAGER);
}

Expand Down Expand Up @@ -501,28 +490,6 @@ void LayerSystem::initialiseModule(const ApplicationContext& ctx)
sigc::mem_fun(*this, &LayerSystem::onMapEvent)
);

// Create a new menu item connected to the CreateNewLayer command
wxutil::CommandMenuItemPtr menuItem(new wxutil::CommandMenuItem(
new wxutil::IconTextMenuItem(_(CREATE_LAYER_TEXT), LAYER_ICON),
"CreateNewLayer")
);

GlobalOrthoContextMenu().addItem(menuItem, ui::IOrthoContextMenu::SECTION_LAYER);

// Add the ortho context menu items
ui::LayerOrthoContextMenuItemPtr addMenu(new ui::LayerOrthoContextMenuItem(
_(ADD_TO_LAYER_TEXT), ui::LayerOrthoContextMenuItem::AddToLayer));

ui::LayerOrthoContextMenuItemPtr moveMenu(new ui::LayerOrthoContextMenuItem(
_(MOVE_TO_LAYER_TEXT), ui::LayerOrthoContextMenuItem::MoveToLayer));

ui::LayerOrthoContextMenuItemPtr removeMenu(new ui::LayerOrthoContextMenuItem(
_(REMOVE_FROM_LAYER_TEXT), ui::LayerOrthoContextMenuItem::RemoveFromLayer));

GlobalOrthoContextMenu().addItem(addMenu, ui::IOrthoContextMenu::SECTION_LAYER);
GlobalOrthoContextMenu().addItem(moveMenu, ui::IOrthoContextMenu::SECTION_LAYER);
GlobalOrthoContextMenu().addItem(removeMenu, ui::IOrthoContextMenu::SECTION_LAYER);

GlobalMapInfoFileManager().registerInfoFileModule(
std::make_shared<LayerInfoFileModule>()
);
Expand Down
83 changes: 83 additions & 0 deletions radiant/ui/UserInterfaceModule.cpp
@@ -0,0 +1,83 @@
#include "UserInterfaceModule.h"

#include "i18n.h"
#include "ilayer.h"
#include "iorthocontextmenu.h"

#include "wxutil/menu/CommandMenuItem.h"

#include "modulesystem/StaticModule.h"

#include "ui/layers/LayerOrthoContextMenuItem.h"

namespace ui
{

namespace
{
const char* const LAYER_ICON = "layers.png";
const char* const CREATE_LAYER_TEXT = N_("Create Layer...");

const char* const ADD_TO_LAYER_TEXT = N_("Add to Layer...");
const char* const MOVE_TO_LAYER_TEXT = N_("Move to Layer...");
const char* const REMOVE_FROM_LAYER_TEXT = N_("Remove from Layer...");
}

const std::string& UserInterfaceModule::getName() const
{
static std::string _name("UserInterfaceModule");
return _name;
}

const StringSet& UserInterfaceModule::getDependencies() const
{
static StringSet _dependencies;

if (_dependencies.empty())
{
_dependencies.insert(MODULE_LAYERSYSTEM);
_dependencies.insert(MODULE_ORTHOCONTEXTMENU);
_dependencies.insert(MODULE_UIMANAGER);
}

return _dependencies;
}

void UserInterfaceModule::initialiseModule(const ApplicationContext& ctx)
{
rMessage() << getName() << "::initialiseModule called." << std::endl;

// Create a new menu item connected to the CreateNewLayer command
_layerMenuItems.push_back(
std::make_shared<wxutil::CommandMenuItem>(
new wxutil::IconTextMenuItem(_(CREATE_LAYER_TEXT), LAYER_ICON), "CreateNewLayer"));

// Add the orthocontext menu's layer actions
_layerMenuItems.push_back(
std::make_shared<LayerOrthoContextMenuItem>(_(ADD_TO_LAYER_TEXT), LayerOrthoContextMenuItem::AddToLayer));

_layerMenuItems.push_back(
std::make_shared<LayerOrthoContextMenuItem>(_(MOVE_TO_LAYER_TEXT), LayerOrthoContextMenuItem::MoveToLayer));

_layerMenuItems.push_back(
std::make_shared<LayerOrthoContextMenuItem>(_(REMOVE_FROM_LAYER_TEXT), LayerOrthoContextMenuItem::RemoveFromLayer));

for (const IMenuItemPtr& item : _layerMenuItems)
{
GlobalOrthoContextMenu().addItem(item, IOrthoContextMenu::SECTION_LAYER);
}
}

void UserInterfaceModule::shutdownModule()
{
// Remove layer items again
for (const IMenuItemPtr& item : _layerMenuItems)
{
GlobalOrthoContextMenu().removeItem(item);
}
}

// Static module registration
module::StaticModule<UserInterfaceModule> userInterfaceModule;

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

#include "imodule.h"
#include "iorthocontextmenu.h"

namespace ui
{

/**
* Module responsible of registering and intialising the various
* UI classes in DarkRadiant, e.g. the LayerSystem.
*
* Currently many UI classes are spread and initialised all across
* the main binary, so there's still work left to do.
*/
class UserInterfaceModule :
public RegisterableModule
{
private:
std::vector<IMenuItemPtr> _layerMenuItems;

public:
// RegisterableModule
const std::string & getName() const override;
const StringSet & getDependencies() const override;
void initialiseModule(const ApplicationContext & ctx) override;
void shutdownModule() override;
};

}
2 changes: 2 additions & 0 deletions tools/msvc2015/DarkRadiant.vcxproj
Expand Up @@ -553,6 +553,7 @@
<ClCompile Include="..\..\radiant\ui\mainframe\ScreenUpdateBlocker.cpp" />
<ClCompile Include="..\..\radiant\ui\mainframe\SplitPaneLayout.cpp" />
<ClCompile Include="..\..\radiant\ui\brush\QuerySidesDialog.cpp" />
<ClCompile Include="..\..\radiant\ui\UserInterfaceModule.cpp" />
<ClCompile Include="..\..\radiant\xyview\FloatingOrthoView.cpp" />
<ClCompile Include="..\..\radiant\xyview\GlobalXYWnd.cpp" />
<ClCompile Include="..\..\radiant\xyview\tools\BrushCreatorTool.cpp" />
Expand Down Expand Up @@ -847,6 +848,7 @@
<ClInclude Include="..\..\radiant\ui\mainframe\ScreenUpdateBlocker.h" />
<ClInclude Include="..\..\radiant\ui\mainframe\SplitPaneLayout.h" />
<ClInclude Include="..\..\radiant\ui\brush\QuerySidesDialog.h" />
<ClInclude Include="..\..\radiant\ui\UserInterfaceModule.h" />
<ClInclude Include="..\..\radiant\xyview\FloatingOrthoView.h" />
<ClInclude Include="..\..\radiant\xyview\GlobalXYWnd.h" />
<ClInclude Include="..\..\radiant\xyview\tools\BrushCreatorTool.h" />
Expand Down
6 changes: 6 additions & 0 deletions tools/msvc2015/DarkRadiant.vcxproj.filters
Expand Up @@ -892,6 +892,9 @@
<ClCompile Include="..\..\radiant\ui\mapinfo\LayerInfoTab.cpp">
<Filter>src\ui\mapinfo</Filter>
</ClCompile>
<ClCompile Include="..\..\radiant\ui\UserInterfaceModule.cpp">
<Filter>src\ui</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\radiant\RadiantModule.h">
Expand Down Expand Up @@ -1815,6 +1818,9 @@
<ClInclude Include="..\..\radiant\ui\mapinfo\LayerInfoTab.h">
<Filter>src\ui\mapinfo</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\ui\UserInterfaceModule.h">
<Filter>src\ui</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\radiant\darkradiant.rc" />
Expand Down

0 comments on commit 3b53afc

Please sign in to comment.