Skip to content

Commit

Permalink
Game connection UI initialisation happens in the plugin itself
Browse files Browse the repository at this point in the history
The addition of game connection functionality to the menu, command manager and
event manager now happens in GameConnection::initialiseModule() rather than
elsewhere in DarkRadiant. This ensures that there is no Connection menu when
the plugin is not compiled or installed.
  • Loading branch information
Matthew Mott committed Sep 23, 2020
1 parent 954dd44 commit bf7ff89
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 71 deletions.
18 changes: 0 additions & 18 deletions install/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -319,22 +319,4 @@
<menuItem name="about" caption="&amp;About" command="About" />
<menuItem name="userGuide" caption="&amp;User Guide" command="ShowUserGuide" />
</subMenu>

<subMenu name="gamecon" caption="Connection">
<menuItem name="cameraSyncEnable" caption="Enable camera synchronization" command="GameConnectionCameraSyncEnable" />
<menuItem name="cameraSyncDisable" caption="Disable camera synchronization" command="GameConnectionCameraSyncDisable" />
<menuItem name="backSyncCamera" caption="Sync camera back now" command="GameConnectionBackSyncCamera" />
<menuSeparator />
<menuItem name="reloadMap" caption="Reload map from .map file" command="GameConnectionReloadMap" />
<menuItem name="reloadMapAutoEnable" caption="Enable automation .map reload on save" command="GameConnectionReloadMapAutoEnable" />
<menuItem name="reloadMapAutoDisable" caption="Disable automation .map reload on save" command="GameConnectionReloadMapAutoDisable" />
<menuSeparator />
<menuItem name="updateMapOff" caption="Disable map update mode" command="GameConnectionUpdateMapOff" />
<menuItem name="updateMapOn" caption="Enable map update mode" command="GameConnectionUpdateMapOn" />
<menuItem name="updateMapAlways" caption="Always update map immediately after change" command="GameConnectionUpdateMapAlways" />
<menuItem name="updateMap" caption="Update map right now" command="GameConnectionUpdateMap" />
<menuSeparator />
<menuItem name="pauseGame" caption="Pause game" command="GameConnectionPauseGame" />
<menuItem name="respawnSelected" caption="Respawn selected entities" command="GameConnectionRespawnSelected" />
</subMenu>
</menu>
98 changes: 85 additions & 13 deletions plugins/dm.gameconnection/GameConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "inode.h"
#include "ientity.h"
#include "iselection.h"
#include "iuimanager.h"
#include "ieventmanager.h"

#include "scene/MapExporter.h"
#include "scene/Traverse.h"
Expand Down Expand Up @@ -188,24 +190,94 @@ GameConnection::~GameConnection() {

//-------------------------------------------------------------

const std::string& GameConnection::getName() const {
const std::string& GameConnection::getName() const
{
static std::string _name = MODULE_GAMECONNECTION;
return _name;
}
const StringSet& GameConnection::getDependencies() const {
static StringSet _dependencies;
if (_dependencies.empty()) {
_dependencies.insert(MODULE_CAMERA);
_dependencies.insert(MODULE_COMMANDSYSTEM);
_dependencies.insert(MODULE_MAP);
_dependencies.insert(MODULE_SCENEGRAPH);
_dependencies.insert(MODULE_SELECTIONSYSTEM);
}

const StringSet& GameConnection::getDependencies() const
{
static StringSet _dependencies {
MODULE_CAMERA, MODULE_COMMANDSYSTEM, MODULE_MAP, MODULE_SCENEGRAPH,
MODULE_SELECTIONSYSTEM, MODULE_EVENTMANAGER, MODULE_UIMANAGER
};
return _dependencies;
}
void GameConnection::initialiseModule(const ApplicationContext& ctx) {
}
void GameConnection::shutdownModule() {

void GameConnection::initialiseModule(const ApplicationContext& ctx)
{
// Add commands
GlobalCommandSystem().addCommand("GameConnectionCameraSyncEnable",
[this](const cmd::ArgumentList&) { setCameraSyncEnabled(true); });
GlobalCommandSystem().addCommand("GameConnectionCameraSyncDisable",
[this](const cmd::ArgumentList&) { setCameraSyncEnabled(false); });
GlobalCommandSystem().addCommand("GameConnectionBackSyncCamera",
[this](const cmd::ArgumentList&) { backSyncCamera(); });
GlobalCommandSystem().addCommand("GameConnectionReloadMap",
[this](const cmd::ArgumentList&) { reloadMap(); });
GlobalCommandSystem().addCommand("GameConnectionReloadMapAutoEnable",
[this](const cmd::ArgumentList&) { setAutoReloadMapEnabled(true); });
GlobalCommandSystem().addCommand("GameConnectionReloadMapAutoDisable",
[this](const cmd::ArgumentList&) { setAutoReloadMapEnabled(false); });
GlobalCommandSystem().addCommand("GameConnectionUpdateMapOff",
[this](const cmd::ArgumentList&) { setUpdateMapLevel(false, false); });
GlobalCommandSystem().addCommand("GameConnectionUpdateMapOn",
[this](const cmd::ArgumentList&) { setUpdateMapLevel(true, false); });
GlobalCommandSystem().addCommand("GameConnectionUpdateMapAlways",
[this](const cmd::ArgumentList&) { setUpdateMapLevel(true, true); });
GlobalCommandSystem().addCommand("GameConnectionUpdateMap",
[this](const cmd::ArgumentList&) { doUpdateMap(); });
GlobalCommandSystem().addCommand("GameConnectionPauseGame",
[this](const cmd::ArgumentList&) { togglePauseGame(); });
GlobalCommandSystem().addCommand("GameConnectionRespawnSelected",
[this](const cmd::ArgumentList&) { respawnSelectedEntities(); });

// Add events
GlobalEventManager().addCommand("GameConnectionCameraSyncEnable", "GameConnectionCameraSyncEnable");
GlobalEventManager().addCommand("GameConnectionCameraSyncDisable", "GameConnectionCameraSyncDisable");
GlobalEventManager().addCommand("GameConnectionBackSyncCamera", "GameConnectionBackSyncCamera");
GlobalEventManager().addCommand("GameConnectionReloadMap", "GameConnectionReloadMap");
GlobalEventManager().addCommand("GameConnectionReloadMapAutoEnable", "GameConnectionReloadMapAutoEnable");
GlobalEventManager().addCommand("GameConnectionReloadMapAutoDisable", "GameConnectionReloadMapAutoDisable");
GlobalEventManager().addCommand("GameConnectionUpdateMapOff", "GameConnectionUpdateMapOff");
GlobalEventManager().addCommand("GameConnectionUpdateMapOn", "GameConnectionUpdateMapOn");
GlobalEventManager().addCommand("GameConnectionUpdateMapAlways", "GameConnectionUpdateMapAlways");
GlobalEventManager().addCommand("GameConnectionUpdateMap", "GameConnectionUpdateMap");
GlobalEventManager().addCommand("GameConnectionPauseGame", "GameConnectionPauseGame");
GlobalEventManager().addCommand("GameConnectionRespawnSelected", "GameConnectionRespawnSelected");

// Add menu items
IMenuManager& mm = GlobalUIManager().getMenuManager();
mm.add("main", "connection", ui::menuFolder, "Connection", "", "");
mm.add("main/connection", "cameraSyncEnable", ui::menuItem,
"Enable camera synchronization", "", "GameConnectionCameraSyncEnable");
mm.add("main/connection", "cameraSyncDisable", ui::menuItem,
"Disable camera synchronization", "", "GameConnectionCameraSyncDisable");
mm.add("main/connection", "backSyncCamera", ui::menuItem,
"Sync camera back now", "", "GameConnectionBackSyncCamera");
mm.add("main/connection", "reloadMap", ui::menuItem,
"Reload map from .map file", "", "GameConnectionReloadMap");
mm.add("main/connection", "reloadMapAutoEnable", ui::menuItem,
"Enable automation .map reload on save", "", "GameConnectionReloadMapAutoEnable");
mm.add("main/connection", "reloadMapAutoDisable", ui::menuItem,
"Disable automation .map reload on save", "", "GameConnectionReloadMapAutoDisable");
mm.add("main/connection", "updateMapOff", ui::menuItem,
"Disable map update mode", "", "GameConnectionUpdateMapOff");
mm.add("main/connection", "updateMapOn", ui::menuItem,
"Enable map update mode", "", "GameConnectionUpdateMapOn");
mm.add("main/connection", "updateMapAlways", ui::menuItem,
"Always update map immediately after change", "", "GameConnectionUpdateMapAlways");
mm.add("main/connection", "updateMap", ui::menuItem,
"Update map right now", "", "GameConnectionUpdateMap");
mm.add("main/connection", "pauseGame", ui::menuItem,
"Pause game", "", "GameConnectionPauseGame");
mm.add("main/connection", "respawnSelected", ui::menuItem,
"Respawn selected entities", "", "GameConnectionRespawnSelected");
}

void GameConnection::shutdownModule()
{
disconnect(true);
}

Expand Down
40 changes: 0 additions & 40 deletions radiant/ui/UserInterfaceModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,33 +160,6 @@ void UserInterfaceModule::registerUICommands()
GlobalCommandSystem().addCommand("EntityClassTree", EClassTree::ShowDialog);
GlobalCommandSystem().addCommand("EntityList", EntityList::toggle);

if (IGameConnection *gameconn = GlobalGameConnection()) {
GlobalCommandSystem().addCommand("GameConnectionCameraSyncEnable",
[gameconn](const cmd::ArgumentList&) { gameconn->setCameraSyncEnabled(true); });
GlobalCommandSystem().addCommand("GameConnectionCameraSyncDisable",
[gameconn](const cmd::ArgumentList&) { gameconn->setCameraSyncEnabled(false); });
GlobalCommandSystem().addCommand("GameConnectionBackSyncCamera",
[gameconn](const cmd::ArgumentList&) { gameconn->backSyncCamera(); });
GlobalCommandSystem().addCommand("GameConnectionReloadMap",
[gameconn](const cmd::ArgumentList&) { gameconn->reloadMap(); });
GlobalCommandSystem().addCommand("GameConnectionReloadMapAutoEnable",
[gameconn](const cmd::ArgumentList&) { gameconn->setAutoReloadMapEnabled(true); });
GlobalCommandSystem().addCommand("GameConnectionReloadMapAutoDisable",
[gameconn](const cmd::ArgumentList&) { gameconn->setAutoReloadMapEnabled(false); });
GlobalCommandSystem().addCommand("GameConnectionUpdateMapOff",
[gameconn](const cmd::ArgumentList&) { gameconn->setUpdateMapLevel(false, false); });
GlobalCommandSystem().addCommand("GameConnectionUpdateMapOn",
[gameconn](const cmd::ArgumentList&) { gameconn->setUpdateMapLevel(true, false); });
GlobalCommandSystem().addCommand("GameConnectionUpdateMapAlways",
[gameconn](const cmd::ArgumentList&) { gameconn->setUpdateMapLevel(true, true); });
GlobalCommandSystem().addCommand("GameConnectionUpdateMap",
[gameconn](const cmd::ArgumentList&) { gameconn->doUpdateMap(); });
GlobalCommandSystem().addCommand("GameConnectionPauseGame",
[gameconn](const cmd::ArgumentList&) { gameconn->togglePauseGame(); });
GlobalCommandSystem().addCommand("GameConnectionRespawnSelected",
[gameconn](const cmd::ArgumentList&) { gameconn->respawnSelectedEntities(); });
}

// ----------------------- Bind Events ---------------------------------------

GlobalEventManager().addCommand("ProjectSettings", "ProjectSettings");
Expand Down Expand Up @@ -214,19 +187,6 @@ void UserInterfaceModule::registerUICommands()
GlobalEventManager().addCommand("ExportSelectedAsModelDialog", "ExportSelectedAsModelDialog");
GlobalEventManager().addCommand("EntityClassTree", "EntityClassTree");
GlobalEventManager().addCommand("EntityList", "EntityList");

GlobalEventManager().addCommand("GameConnectionCameraSyncEnable", "GameConnectionCameraSyncEnable");
GlobalEventManager().addCommand("GameConnectionCameraSyncDisable", "GameConnectionCameraSyncDisable");
GlobalEventManager().addCommand("GameConnectionBackSyncCamera", "GameConnectionBackSyncCamera");
GlobalEventManager().addCommand("GameConnectionReloadMap", "GameConnectionReloadMap");
GlobalEventManager().addCommand("GameConnectionReloadMapAutoEnable", "GameConnectionReloadMapAutoEnable");
GlobalEventManager().addCommand("GameConnectionReloadMapAutoDisable", "GameConnectionReloadMapAutoDisable");
GlobalEventManager().addCommand("GameConnectionUpdateMapOff", "GameConnectionUpdateMapOff");
GlobalEventManager().addCommand("GameConnectionUpdateMapOn", "GameConnectionUpdateMapOn");
GlobalEventManager().addCommand("GameConnectionUpdateMapAlways", "GameConnectionUpdateMapAlways");
GlobalEventManager().addCommand("GameConnectionUpdateMap", "GameConnectionUpdateMap");
GlobalEventManager().addCommand("GameConnectionPauseGame", "GameConnectionPauseGame");
GlobalEventManager().addCommand("GameConnectionRespawnSelected", "GameConnectionRespawnSelected");
}

// Static module registration
Expand Down

0 comments on commit bf7ff89

Please sign in to comment.