Skip to content

Commit

Permalink
#5346: 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 authored and codereader committed Sep 28, 2020
1 parent 423f424 commit 27ffd54
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 75 deletions.
18 changes: 0 additions & 18 deletions install/menu.xml
Expand Up @@ -323,22 +323,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>
100 changes: 86 additions & 14 deletions plugins/dm.gameconnection/GameConnection.cpp
Expand Up @@ -5,7 +5,9 @@
#include "ientity.h"
#include "imap.h"
#include "iselection.h"
#include "module/StaticModule.h"
#include "iuimanager.h"
#include "ieventmanager.h"

#include <sigc++/signal.h>
#include "clsocket/ActiveSocket.h"

Expand Down Expand Up @@ -179,24 +181,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_MANAGER);
_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 IApplicationContext& 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);
}
module::StaticModule<GameConnection> gameConnectionModule;
Expand Down
43 changes: 0 additions & 43 deletions radiant/ui/UserInterfaceModule.cpp
Expand Up @@ -380,36 +380,6 @@ void UserInterfaceModule::registerUICommands()
GlobalCommandSystem().addCommand("EntityClassTree", EClassTree::ShowDialog);
GlobalCommandSystem().addCommand("EntityList", EntityList::toggle);

GlobalCommandSystem().addCommand("RefreshShaders",
std::bind(&UserInterfaceModule::refreshShadersCmd, this, std::placeholders::_1));

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 ---------------------------------------

// Add the callback event
Expand Down Expand Up @@ -438,19 +408,6 @@ void UserInterfaceModule::registerUICommands()
GlobalEventManager().addRegistryToggle("TogTexLock", RKEY_ENABLE_TEXTURE_LOCK);

GlobalCommandSystem().addCommand("LoadPrefab", ui::loadPrefabDialog);

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");
}

void UserInterfaceModule::HandleTextureChanged(radiant::TextureChangedMessage& msg)
Expand Down

0 comments on commit 27ffd54

Please sign in to comment.