[Client] Use new code to set the console's Ptrs from server scripts

Previously, reusing the console's object selection code made it so using the same Ptr twice in a row was akin to clicking on the same object twice in the console window, i.e. the object was deselected the second time around. Additionally, that same code was setting key focus to the hidden console window, preventing players from moving until they activated another window (such as their inventory or chat window).
0.6.2
David Cernat 7 years ago
parent 5fd9079b26
commit db0e0d376e

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

@ -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());

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

@ -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());

@ -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);

@ -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,17 +456,29 @@ 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)
windowManager->setConsoleSelectedObject(PlayerList::getPlayer(worldObject.guid)->getPtr());
else
windowManager->setConsoleSelectedObject(Main::get().getLocalPlayer()->getPlayerPtr());
if (worldObject.guid == Main::get().getLocalPlayer()->guid)
{
player = Main::get().getLocalPlayer();
LOG_APPEND(Log::LOG_VERBOSE, "-- running on local player");
windowManager->setConsolePtr(static_cast<LocalPlayer*>(player)->getPlayerPtr());
windowManager->executeCommandInConsole(consoleCommand);
}
else if (player != 0)
{
player = PlayerList::getPlayer(guid);
LOG_APPEND(Log::LOG_VERBOSE, "-- running on player %s", player->npc.mName.c_str());
windowManager->setConsolePtr(static_cast<DedicatedPlayer*>(player)->getPtr());
windowManager->executeCommandInConsole(consoleCommand);
}
}
else
{
LOG_APPEND(Log::LOG_VERBOSE, "-- running on cellRef: %s, %i, %i", worldObject.refId.c_str(), worldObject.refNumIndex, worldObject.mpNum);
@ -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();
}
}

Loading…
Cancel
Save