diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index 52d637c64..11d96f16c 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -152,6 +152,29 @@ namespace MWBase virtual void setConsoleSelectedObject(const MWWorld::Ptr& object) = 0; + /* + Start of tes3mp addition + + Allow the direct setting of a console's Ptr, without the assumption that an object + was clicked and that key focus should be restored to the console window, for console + commands executed via server scripts + */ + virtual void setConsolePtr(const MWWorld::Ptr& object) = 0; + /* + End of tes3mp addition + */ + + /* + Start of tes3mp addition + + Allow the clearing of the console's Ptr from elsewhere in the code, so that + Ptrs used in console commands run from server scripts do not stay selected + */ + virtual void clearConsolePtr() = 0; + /* + End of tes3mp addition + */ + /// Set value for the given ID. virtual void setValue (const std::string& id, const MWMechanics::AttributeValue& value) = 0; virtual void setValue (int parSkill, const MWMechanics::SkillValue& value) = 0; diff --git a/apps/openmw/mwgui/console.cpp b/apps/openmw/mwgui/console.cpp index e8ac33f6d..b5937ce80 100644 --- a/apps/openmw/mwgui/console.cpp +++ b/apps/openmw/mwgui/console.cpp @@ -439,6 +439,21 @@ namespace MWGui } } + /* + Start of tes3mp addition + + Allow the direct setting of a console's Ptr, without the assumption that an object + was clicked and that key focus should be restored to the console window, for console + commands executed via server scripts + */ + void Console::setPtr(const MWWorld::Ptr& object) + { + mPtr = object; + } + /* + End of tes3mp addition + */ + void Console::onReferenceUnavailable() { setSelectedObject(MWWorld::Ptr()); diff --git a/apps/openmw/mwgui/console.hpp b/apps/openmw/mwgui/console.hpp index bbff34c8d..1848705fc 100644 --- a/apps/openmw/mwgui/console.hpp +++ b/apps/openmw/mwgui/console.hpp @@ -27,6 +27,18 @@ namespace MWGui /// Set the implicit object for script execution void setSelectedObject(const MWWorld::Ptr& object); + /* + Start of tes3mp addition + + Allow the direct setting of a console's Ptr, without the assumption that an object + was clicked and that key focus should be restored to the console window, for console + commands executed via server scripts + */ + void setPtr(const MWWorld::Ptr& object); + /* + End of tes3mp addition + */ + MyGUI::EditBox* mCommandLine; MyGUI::EditBox* mHistory; diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 30cbd6758..a5c3a3b2a 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -2021,6 +2021,35 @@ namespace MWGui mConsole->setSelectedObject(object); } + /* + Start of tes3mp addition + + Allow the direct setting of a console's Ptr, without the assumption that an object + was clicked and that key focus should be restored to the console window, for console + commands executed via server scripts + */ + void WindowManager::setConsolePtr(const MWWorld::Ptr &object) + { + mConsole->setPtr(object); + } + /* + End of tes3mp addition + */ + + /* + Start of tes3mp addition + + Allow the clearing of the console's Ptr from elsewhere in the code, so that + Ptrs used in console commands run from server scripts do not stay selected + */ + void WindowManager::clearConsolePtr() + { + mConsole->resetReference(); + } + /* + End of tes3mp addition + */ + std::string WindowManager::correctIconPath(const std::string& path) { return Misc::ResourceHelpers::correctIconPath(path, mResourceSystem->getVFS()); diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index 04af36ed1..f1fa3e7c5 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -191,6 +191,29 @@ namespace MWGui virtual void setConsoleSelectedObject(const MWWorld::Ptr& object); + /* + Start of tes3mp addition + + Allow the direct setting of a console's Ptr, without the assumption that an object + was clicked and that key focus should be restored to the console window, for console + commands executed via server scripts + */ + virtual void setConsolePtr(const MWWorld::Ptr& object); + /* + End of tes3mp addition + */ + + /* + Start of tes3mp addition + + Allow the clearing of the console's Ptr from elsewhere in the code, so that + Ptrs used in console commands run from server scripts do not stay selected + */ + virtual void clearConsolePtr(); + /* + End of tes3mp addition + */ + ///< Set value for the given ID. virtual void setValue (const std::string& id, const MWMechanics::AttributeValue& value); virtual void setValue (int parSkill, const MWMechanics::SkillValue& value); diff --git a/apps/openmw/mwmp/WorldEvent.cpp b/apps/openmw/mwmp/WorldEvent.cpp index be39c458a..6e4e0b2eb 100644 --- a/apps/openmw/mwmp/WorldEvent.cpp +++ b/apps/openmw/mwmp/WorldEvent.cpp @@ -447,6 +447,8 @@ void WorldEvent::runConsoleCommands(MWWorld::CellStore* cellStore) if (worldObjects.empty()) { + windowManager->clearConsolePtr(); + LOG_APPEND(Log::LOG_VERBOSE, "-- running with no object reference"); windowManager->executeCommandInConsole(consoleCommand); } @@ -454,16 +456,28 @@ void WorldEvent::runConsoleCommands(MWWorld::CellStore* cellStore) { for (const auto &worldObject : worldObjects) { + windowManager->clearConsolePtr(); + if (worldObject.isPlayer) { - LOG_APPEND(Log::LOG_VERBOSE, "-- running on player %s"); + BasePlayer *player = 0; + + if (worldObject.guid == Main::get().getLocalPlayer()->guid) + { + player = Main::get().getLocalPlayer(); - if (worldObject.guid != Main::get().getLocalPlayer()->guid) - windowManager->setConsoleSelectedObject(PlayerList::getPlayer(worldObject.guid)->getPtr()); - else - windowManager->setConsoleSelectedObject(Main::get().getLocalPlayer()->getPlayerPtr()); + LOG_APPEND(Log::LOG_VERBOSE, "-- running on local player"); + windowManager->setConsolePtr(static_cast(player)->getPlayerPtr()); + windowManager->executeCommandInConsole(consoleCommand); + } + else if (player != 0) + { + player = PlayerList::getPlayer(guid); - windowManager->executeCommandInConsole(consoleCommand); + LOG_APPEND(Log::LOG_VERBOSE, "-- running on player %s", player->npc.mName.c_str()); + windowManager->setConsolePtr(static_cast(player)->getPtr()); + windowManager->executeCommandInConsole(consoleCommand); + } } else { @@ -476,11 +490,13 @@ void WorldEvent::runConsoleCommands(MWWorld::CellStore* cellStore) LOG_APPEND(Log::LOG_VERBOSE, "-- Found %s, %i, %i", ptrFound.getCellRef().getRefId().c_str(), ptrFound.getCellRef().getRefNum(), ptrFound.getCellRef().getMpNum()); - windowManager->setConsoleSelectedObject(ptrFound); + windowManager->setConsolePtr(ptrFound); windowManager->executeCommandInConsole(consoleCommand); } } } + + windowManager->clearConsolePtr(); } }