mirror of
https://github.com/TES3MP/TES3MP.git
synced 2025-09-28 23:51:09 -04:00
set the implicit object for script excution by clicking on it
This commit is contained in:
parent
36d26e0681
commit
0ba0b2122e
@ -240,7 +240,7 @@ namespace MWGui
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ConsoleInterpreterContext interpreterContext (*this, MWWorld::Ptr());
|
ConsoleInterpreterContext interpreterContext (*this, mPtr);
|
||||||
Interpreter::Interpreter interpreter;
|
Interpreter::Interpreter interpreter;
|
||||||
MWScript::installOpcodes (interpreter);
|
MWScript::installOpcodes (interpreter);
|
||||||
std::vector<Interpreter::Type_Code> code;
|
std::vector<Interpreter::Type_Code> code;
|
||||||
@ -375,4 +375,14 @@ namespace MWGui
|
|||||||
{
|
{
|
||||||
setCoord(10,10, width-10, height/2);
|
setCoord(10,10, width-10, height/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Console::setSelectedObject(const MWWorld::Ptr& object)
|
||||||
|
{
|
||||||
|
mPtr = object;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Console::onReferenceUnavailable()
|
||||||
|
{
|
||||||
|
mPtr = MWWorld::Ptr();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,11 @@
|
|||||||
#include "../mwscript/compilercontext.hpp"
|
#include "../mwscript/compilercontext.hpp"
|
||||||
#include "../mwscript/interpretercontext.hpp"
|
#include "../mwscript/interpretercontext.hpp"
|
||||||
|
|
||||||
|
#include "referenceinterface.hpp"
|
||||||
|
|
||||||
namespace MWGui
|
namespace MWGui
|
||||||
{
|
{
|
||||||
class Console : private OEngine::GUI::Layout, private Compiler::ErrorHandler
|
class Console : private OEngine::GUI::Layout, private Compiler::ErrorHandler, public ReferenceInterface
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -39,6 +41,16 @@ namespace MWGui
|
|||||||
/// \note The list may contain duplicates (if a name is a keyword and an identifier at the same
|
/// \note The list may contain duplicates (if a name is a keyword and an identifier at the same
|
||||||
/// time).
|
/// time).
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
void setSelectedObject(const MWWorld::Ptr& object);
|
||||||
|
///< Set the implicit object for script execution
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual void onReferenceUnavailable();
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MyGUI::EditPtr command;
|
MyGUI::EditPtr command;
|
||||||
MyGUI::EditPtr history;
|
MyGUI::EditPtr history;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include "window_manager.hpp"
|
#include "window_manager.hpp"
|
||||||
#include "container.hpp"
|
#include "container.hpp"
|
||||||
|
#include "console.hpp"
|
||||||
|
|
||||||
using namespace MWGui;
|
using namespace MWGui;
|
||||||
|
|
||||||
@ -46,6 +47,7 @@ HUD::HUD(int width, int height, int fpsLevel, DragAndDrop* dragAndDrop)
|
|||||||
, mMapVisible(true)
|
, mMapVisible(true)
|
||||||
, mWeaponVisible(true)
|
, mWeaponVisible(true)
|
||||||
, mSpellVisible(true)
|
, mSpellVisible(true)
|
||||||
|
, mWorldMouseOver(false)
|
||||||
{
|
{
|
||||||
setCoord(0,0, width, height);
|
setCoord(0,0, width, height);
|
||||||
|
|
||||||
@ -265,12 +267,39 @@ void HUD::onWorldClicked(MyGUI::Widget* _sender)
|
|||||||
|
|
||||||
MWBase::Environment::get().getWindowManager()->setDragDrop(false);
|
MWBase::Environment::get().getWindowManager()->setDragDrop(false);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GuiMode mode = MWBase::Environment::get().getWindowManager()->getMode();
|
||||||
|
|
||||||
|
if ( (mode != GM_Console) && (mode != GM_Container) && (mode != GM_Inventory) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::string handle = MWBase::Environment::get().getWorld()->getFacedHandle();
|
||||||
|
MWWorld::Ptr object;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
object = MWBase::Environment::get().getWorld()->getPtrViaHandle(handle);
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode == GM_Console)
|
||||||
|
MWBase::Environment::get().getWindowManager()->getConsole()->setSelectedObject(object);
|
||||||
|
else if (mode == GM_Console || GM_Inventory)
|
||||||
|
{
|
||||||
|
// pick up object
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HUD::onWorldMouseOver(MyGUI::Widget* _sender, int x, int y)
|
void HUD::onWorldMouseOver(MyGUI::Widget* _sender, int x, int y)
|
||||||
{
|
{
|
||||||
if (mDragAndDrop->mIsOnDragAndDrop)
|
if (mDragAndDrop->mIsOnDragAndDrop)
|
||||||
{
|
{
|
||||||
|
mWorldMouseOver = false;
|
||||||
|
|
||||||
MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
|
MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
|
||||||
MyGUI::IntPoint cursorPosition = MyGUI::InputManager::getInstance().getMousePosition();
|
MyGUI::IntPoint cursorPosition = MyGUI::InputManager::getInstance().getMousePosition();
|
||||||
float mouseX = cursorPosition.left / float(viewSize.width);
|
float mouseX = cursorPosition.left / float(viewSize.width);
|
||||||
@ -290,13 +319,14 @@ void HUD::onWorldMouseOver(MyGUI::Widget* _sender, int x, int y)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
MyGUI::PointerManager::getInstance().setPointer("arrow");
|
MyGUI::PointerManager::getInstance().setPointer("arrow");
|
||||||
/// \todo make it possible to pick up objects with the mouse, if inventory or container window is open
|
mWorldMouseOver = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HUD::onWorldMouseLostFocus(MyGUI::Widget* _sender, MyGUI::Widget* _new)
|
void HUD::onWorldMouseLostFocus(MyGUI::Widget* _sender, MyGUI::Widget* _new)
|
||||||
{
|
{
|
||||||
MyGUI::PointerManager::getInstance().setPointer("arrow");
|
MyGUI::PointerManager::getInstance().setPointer("arrow");
|
||||||
|
mWorldMouseOver = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HUD::onHMSClicked(MyGUI::Widget* _sender)
|
void HUD::onHMSClicked(MyGUI::Widget* _sender)
|
||||||
|
@ -33,6 +33,8 @@ namespace MWGui
|
|||||||
|
|
||||||
void setCellName(const std::string& cellName);
|
void setCellName(const std::string& cellName);
|
||||||
|
|
||||||
|
bool getWorldMouseOver() { return mWorldMouseOver; }
|
||||||
|
|
||||||
MyGUI::ProgressPtr health, magicka, stamina;
|
MyGUI::ProgressPtr health, magicka, stamina;
|
||||||
MyGUI::Widget* mHealthFrame;
|
MyGUI::Widget* mHealthFrame;
|
||||||
MyGUI::Widget *weapBox, *spellBox;
|
MyGUI::Widget *weapBox, *spellBox;
|
||||||
@ -70,6 +72,8 @@ namespace MWGui
|
|||||||
bool mWeaponVisible;
|
bool mWeaponVisible;
|
||||||
bool mSpellVisible;
|
bool mSpellVisible;
|
||||||
|
|
||||||
|
bool mWorldMouseOver;
|
||||||
|
|
||||||
void onWorldClicked(MyGUI::Widget* _sender);
|
void onWorldClicked(MyGUI::Widget* _sender);
|
||||||
void onWorldMouseOver(MyGUI::Widget* _sender, int x, int y);
|
void onWorldMouseOver(MyGUI::Widget* _sender, int x, int y);
|
||||||
void onWorldMouseLostFocus(MyGUI::Widget* _sender, MyGUI::Widget* _new);
|
void onWorldMouseLostFocus(MyGUI::Widget* _sender, MyGUI::Widget* _new);
|
||||||
|
@ -67,6 +67,40 @@ void ToolTips::onFrame(float frameDuration)
|
|||||||
if (!mGameMode)
|
if (!mGameMode)
|
||||||
{
|
{
|
||||||
const MyGUI::IntPoint& mousePos = InputManager::getInstance().getMousePosition();
|
const MyGUI::IntPoint& mousePos = InputManager::getInstance().getMousePosition();
|
||||||
|
|
||||||
|
if (mWindowManager->getWorldMouseOver() && ((mWindowManager->getMode() == GM_Console)
|
||||||
|
|| (mWindowManager->getMode() == GM_Container)
|
||||||
|
|| (mWindowManager->getMode() == GM_Inventory)))
|
||||||
|
{
|
||||||
|
std::string handle = MWBase::Environment::get().getWorld()->getFacedHandle();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mFocusObject = MWBase::Environment::get().getWorld()->getPtrViaHandle(handle);
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MyGUI::IntSize tooltipSize = getToolTipViaPtr(true);
|
||||||
|
|
||||||
|
IntPoint tooltipPosition = InputManager::getInstance().getMousePosition() + IntPoint(0, 24);
|
||||||
|
|
||||||
|
// make the tooltip stay completely in the viewport
|
||||||
|
if ((tooltipPosition.left + tooltipSize.width) > viewSize.width)
|
||||||
|
{
|
||||||
|
tooltipPosition.left = viewSize.width - tooltipSize.width;
|
||||||
|
}
|
||||||
|
if ((tooltipPosition.top + tooltipSize.height) > viewSize.height)
|
||||||
|
{
|
||||||
|
tooltipPosition.top = viewSize.height - tooltipSize.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
setCoord(tooltipPosition.left, tooltipPosition.top, tooltipSize.width, tooltipSize.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
const MyGUI::IntPoint& lastPressed = InputManager::getInstance().getLastPressedPosition(MyGUI::MouseButton::Left);
|
const MyGUI::IntPoint& lastPressed = InputManager::getInstance().getLastPressedPosition(MyGUI::MouseButton::Left);
|
||||||
|
|
||||||
if (mousePos == lastPressed) // mouseclick makes tooltip disappear
|
if (mousePos == lastPressed) // mouseclick makes tooltip disappear
|
||||||
@ -220,6 +254,7 @@ void ToolTips::onFrame(float frameDuration)
|
|||||||
|
|
||||||
setCoord(tooltipPosition.left, tooltipPosition.top, tooltipSize.width, tooltipSize.height);
|
setCoord(tooltipPosition.left, tooltipPosition.top, tooltipSize.width, tooltipSize.height);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!mFocusObject.isEmpty())
|
if (!mFocusObject.isEmpty())
|
||||||
|
@ -487,6 +487,7 @@ void WindowManager::onFrame (float frameDuration)
|
|||||||
mDialogueWindow->checkReferenceAvailable();
|
mDialogueWindow->checkReferenceAvailable();
|
||||||
mTradeWindow->checkReferenceAvailable();
|
mTradeWindow->checkReferenceAvailable();
|
||||||
mContainerWindow->checkReferenceAvailable();
|
mContainerWindow->checkReferenceAvailable();
|
||||||
|
console->checkReferenceAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
const ESMS::ESMStore& WindowManager::getStore() const
|
const ESMS::ESMStore& WindowManager::getStore() const
|
||||||
@ -708,3 +709,25 @@ void WindowManager::unsetSelectedWeapon()
|
|||||||
hud->unsetSelectedWeapon();
|
hud->unsetSelectedWeapon();
|
||||||
mInventoryWindow->setTitle("#{sSkillHandtohand}");
|
mInventoryWindow->setTitle("#{sSkillHandtohand}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WindowManager::getMousePosition(int &x, int &y)
|
||||||
|
{
|
||||||
|
const MyGUI::IntPoint& pos = MyGUI::InputManager::getInstance().getMousePosition();
|
||||||
|
x = pos.left;
|
||||||
|
y = pos.top;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowManager::getMousePosition(float &x, float &y)
|
||||||
|
{
|
||||||
|
const MyGUI::IntPoint& pos = MyGUI::InputManager::getInstance().getMousePosition();
|
||||||
|
x = pos.left;
|
||||||
|
y = pos.top;
|
||||||
|
const MyGUI::IntSize& viewSize = MyGUI::RenderManager::getInstance().getViewSize();
|
||||||
|
x /= viewSize.width;
|
||||||
|
y /= viewSize.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WindowManager::getWorldMouseOver()
|
||||||
|
{
|
||||||
|
return hud->getWorldMouseOver();
|
||||||
|
}
|
||||||
|
@ -155,6 +155,7 @@ namespace MWGui
|
|||||||
MWGui::ConfirmationDialog* getConfirmationDialog() {return mConfirmationDialog;}
|
MWGui::ConfirmationDialog* getConfirmationDialog() {return mConfirmationDialog;}
|
||||||
MWGui::TradeWindow* getTradeWindow() {return mTradeWindow;}
|
MWGui::TradeWindow* getTradeWindow() {return mTradeWindow;}
|
||||||
MWGui::SpellWindow* getSpellWindow() {return mSpellWindow;}
|
MWGui::SpellWindow* getSpellWindow() {return mSpellWindow;}
|
||||||
|
MWGui::Console* getConsole() {return console;}
|
||||||
|
|
||||||
MyGUI::Gui* getGui() const { return gui; }
|
MyGUI::Gui* getGui() const { return gui; }
|
||||||
|
|
||||||
@ -188,7 +189,10 @@ namespace MWGui
|
|||||||
void setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y);
|
void setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y);
|
||||||
|
|
||||||
void setMouseVisible(bool visible);
|
void setMouseVisible(bool visible);
|
||||||
|
void getMousePosition(int &x, int &y);
|
||||||
|
void getMousePosition(float &x, float &y);
|
||||||
void setDragDrop(bool dragDrop);
|
void setDragDrop(bool dragDrop);
|
||||||
|
bool getWorldMouseOver();
|
||||||
|
|
||||||
void toggleFogOfWar();
|
void toggleFogOfWar();
|
||||||
void toggleFullHelp(); ///< show extra info in item tooltips (owner, script)
|
void toggleFullHelp(); ///< show extra info in item tooltips (owner, script)
|
||||||
|
@ -66,7 +66,23 @@ namespace MWWorld
|
|||||||
|
|
||||||
return mEngine->rayTest2(from,to);
|
return mEngine->rayTest2(from,to);
|
||||||
}
|
}
|
||||||
void PhysicsSystem::setCurrentWater(bool hasWater, int waterHeight){
|
|
||||||
|
std::vector < std::pair <float, std::string> > PhysicsSystem::getFacedObjects (float mouseX, float mouseY)
|
||||||
|
{
|
||||||
|
Ray ray = mRender.getCamera()->getCameraToViewportRay(mouseX, mouseY);
|
||||||
|
Ogre::Vector3 from = ray.getOrigin();
|
||||||
|
Ogre::Vector3 to = ray.getPoint(500); /// \todo make this distance (ray length) configurable
|
||||||
|
|
||||||
|
btVector3 _from, _to;
|
||||||
|
// OGRE to MW coordinates
|
||||||
|
_from = btVector3(from.x, -from.z, from.y);
|
||||||
|
_to = btVector3(to.x, -to.z, to.y);
|
||||||
|
|
||||||
|
return mEngine->rayTest2(_from,_to);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhysicsSystem::setCurrentWater(bool hasWater, int waterHeight)
|
||||||
|
{
|
||||||
playerphysics->hasWater = hasWater;
|
playerphysics->hasWater = hasWater;
|
||||||
if(hasWater){
|
if(hasWater){
|
||||||
playerphysics->waterHeight = waterHeight;
|
playerphysics->waterHeight = waterHeight;
|
||||||
@ -84,6 +100,14 @@ namespace MWWorld
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btVector3 PhysicsSystem::getRayPoint(float extent, float mouseX, float mouseY)
|
||||||
|
{
|
||||||
|
//get a ray pointing to the center of the viewport
|
||||||
|
Ray centerRay = mRender.getCamera()->getCameraToViewportRay(mouseX, mouseY);
|
||||||
|
btVector3 result(centerRay.getPoint(500*extent).x,-centerRay.getPoint(500*extent).z,centerRay.getPoint(500*extent).y); /// \todo make this distance (ray length) configurable
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
bool PhysicsSystem::castRay(const Vector3& from, const Vector3& to)
|
bool PhysicsSystem::castRay(const Vector3& from, const Vector3& to)
|
||||||
{
|
{
|
||||||
btVector3 _from, _to;
|
btVector3 _from, _to;
|
||||||
|
@ -47,9 +47,12 @@ namespace MWWorld
|
|||||||
std::pair<std::string, float> getFacedHandle (MWWorld::World& world);
|
std::pair<std::string, float> getFacedHandle (MWWorld::World& world);
|
||||||
|
|
||||||
btVector3 getRayPoint(float extent);
|
btVector3 getRayPoint(float extent);
|
||||||
|
btVector3 getRayPoint(float extent, float mouseX, float mouseY);
|
||||||
|
|
||||||
std::vector < std::pair <float, std::string> > getFacedObjects ();
|
std::vector < std::pair <float, std::string> > getFacedObjects ();
|
||||||
|
|
||||||
|
std::vector < std::pair <float, std::string> > getFacedObjects (float mouseX, float mouseY);
|
||||||
|
|
||||||
// cast ray, return true if it hit something
|
// cast ray, return true if it hit something
|
||||||
bool castRay(const Ogre::Vector3& from, const Ogre::Vector3& to);
|
bool castRay(const Ogre::Vector3& from, const Ogre::Vector3& to);
|
||||||
|
|
||||||
|
@ -818,7 +818,15 @@ namespace MWWorld
|
|||||||
|
|
||||||
// send new query
|
// send new query
|
||||||
// figure out which object we want to test against
|
// figure out which object we want to test against
|
||||||
std::vector < std::pair < float, std::string > > results = mPhysics->getFacedObjects();
|
std::vector < std::pair < float, std::string > > results;
|
||||||
|
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
|
||||||
|
{
|
||||||
|
float x, y;
|
||||||
|
MWBase::Environment::get().getWindowManager()->getMousePosition(x, y);
|
||||||
|
results = mPhysics->getFacedObjects(x, y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
results = mPhysics->getFacedObjects();
|
||||||
|
|
||||||
// ignore the player and other things we're not interested in
|
// ignore the player and other things we're not interested in
|
||||||
std::vector < std::pair < float, std::string > >::iterator it = results.begin();
|
std::vector < std::pair < float, std::string > >::iterator it = results.begin();
|
||||||
@ -843,7 +851,15 @@ namespace MWWorld
|
|||||||
mFaced1Name = results.front().second;
|
mFaced1Name = results.front().second;
|
||||||
mNumFacing = 1;
|
mNumFacing = 1;
|
||||||
|
|
||||||
btVector3 p = mPhysics->getRayPoint(results.front().first);
|
btVector3 p;
|
||||||
|
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
|
||||||
|
{
|
||||||
|
float x, y;
|
||||||
|
MWBase::Environment::get().getWindowManager()->getMousePosition(x, y);
|
||||||
|
p = mPhysics->getRayPoint(results.front().first, x, y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
p = mPhysics->getRayPoint(results.front().first);
|
||||||
Ogre::Vector3 pos(p.x(), p.z(), -p.y());
|
Ogre::Vector3 pos(p.x(), p.z(), -p.y());
|
||||||
Ogre::SceneNode* node = mFaced1.getRefData().getBaseNode();
|
Ogre::SceneNode* node = mFaced1.getRefData().getBaseNode();
|
||||||
|
|
||||||
@ -860,7 +876,15 @@ namespace MWWorld
|
|||||||
mFaced2 = getPtrViaHandle(results[1].second);
|
mFaced2 = getPtrViaHandle(results[1].second);
|
||||||
mNumFacing = 2;
|
mNumFacing = 2;
|
||||||
|
|
||||||
btVector3 p = mPhysics->getRayPoint(results[1].first);
|
btVector3 p;
|
||||||
|
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
|
||||||
|
{
|
||||||
|
float x, y;
|
||||||
|
MWBase::Environment::get().getWindowManager()->getMousePosition(x, y);
|
||||||
|
p = mPhysics->getRayPoint(results[1].first, x, y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
p = mPhysics->getRayPoint(results[1].first);
|
||||||
Ogre::Vector3 pos(p.x(), p.z(), -p.y());
|
Ogre::Vector3 pos(p.x(), p.z(), -p.y());
|
||||||
Ogre::SceneNode* node1 = mFaced1.getRefData().getBaseNode();
|
Ogre::SceneNode* node1 = mFaced1.getRefData().getBaseNode();
|
||||||
Ogre::SceneNode* node2 = mFaced2.getRefData().getBaseNode();
|
Ogre::SceneNode* node2 = mFaced2.getRefData().getBaseNode();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user