forked from teamnwah/openmw-tes3coop
Inventory item picking
This commit is contained in:
parent
8d033f0558
commit
c4452afd89
6 changed files with 41 additions and 8 deletions
|
@ -487,10 +487,8 @@ namespace MWGui
|
||||||
{
|
{
|
||||||
MyGUI::IntPoint mousePos = MyGUI::InputManager::getInstance ().getLastPressedPosition (MyGUI::MouseButton::Left);
|
MyGUI::IntPoint mousePos = MyGUI::InputManager::getInstance ().getLastPressedPosition (MyGUI::MouseButton::Left);
|
||||||
MyGUI::IntPoint relPos = mousePos - mAvatarImage->getAbsolutePosition ();
|
MyGUI::IntPoint relPos = mousePos - mAvatarImage->getAbsolutePosition ();
|
||||||
int realX = int(float(relPos.left) / float(mAvatarImage->getSize().width) * 512.f );
|
|
||||||
int realY = int(float(relPos.top) / float(mAvatarImage->getSize().height) * 1024.f );
|
|
||||||
|
|
||||||
MWWorld::Ptr itemSelected = getAvatarSelectedItem (realX, realY);
|
MWWorld::Ptr itemSelected = getAvatarSelectedItem (relPos.left, relPos.top);
|
||||||
if (itemSelected.isEmpty ())
|
if (itemSelected.isEmpty ())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -508,6 +506,8 @@ namespace MWGui
|
||||||
|
|
||||||
MWWorld::Ptr InventoryWindow::getAvatarSelectedItem(int x, int y)
|
MWWorld::Ptr InventoryWindow::getAvatarSelectedItem(int x, int y)
|
||||||
{
|
{
|
||||||
|
// convert to OpenGL lower-left origin
|
||||||
|
y = (mAvatarImage->getHeight()-1) - y;
|
||||||
int slot = mPreview->getSlotSelected (x, y);
|
int slot = mPreview->getSlotSelected (x, y);
|
||||||
|
|
||||||
if (slot == -1)
|
if (slot == -1)
|
||||||
|
|
|
@ -200,9 +200,7 @@ namespace MWGui
|
||||||
{
|
{
|
||||||
MyGUI::IntCoord avatarPos = focus->getAbsoluteCoord();
|
MyGUI::IntCoord avatarPos = focus->getAbsoluteCoord();
|
||||||
MyGUI::IntPoint relMousePos = MyGUI::InputManager::getInstance ().getMousePosition () - MyGUI::IntPoint(avatarPos.left, avatarPos.top);
|
MyGUI::IntPoint relMousePos = MyGUI::InputManager::getInstance ().getMousePosition () - MyGUI::IntPoint(avatarPos.left, avatarPos.top);
|
||||||
int realX = int(float(relMousePos.left) / float(avatarPos.width) * 512.f );
|
MWWorld::Ptr item = MWBase::Environment::get().getWindowManager()->getInventoryWindow ()->getAvatarSelectedItem (relMousePos.left, relMousePos.top);
|
||||||
int realY = int(float(relMousePos.top) / float(avatarPos.height) * 1024.f );
|
|
||||||
MWWorld::Ptr item = MWBase::Environment::get().getWindowManager()->getInventoryWindow ()->getAvatarSelectedItem (realX, realY);
|
|
||||||
|
|
||||||
mFocusObject = item;
|
mFocusObject = item;
|
||||||
if (!mFocusObject.isEmpty ())
|
if (!mFocusObject.isEmpty ())
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include <osg/PositionAttitudeTransform>
|
#include <osg/PositionAttitudeTransform>
|
||||||
#include <osgViewer/Viewer>
|
#include <osgViewer/Viewer>
|
||||||
#include <osg/LightModel>
|
#include <osg/LightModel>
|
||||||
|
#include <osgUtil/IntersectionVisitor>
|
||||||
|
#include <osgUtil/LineSegmentIntersector>
|
||||||
|
|
||||||
#include <components/sceneutil/lightmanager.hpp>
|
#include <components/sceneutil/lightmanager.hpp>
|
||||||
|
|
||||||
|
@ -253,8 +255,21 @@ namespace MWRender
|
||||||
|
|
||||||
int InventoryPreview::getSlotSelected (int posX, int posY)
|
int InventoryPreview::getSlotSelected (int posX, int posY)
|
||||||
{
|
{
|
||||||
// TODO: implement
|
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector (new osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, posX, posY));
|
||||||
return 0;
|
intersector->setIntersectionLimit(osgUtil::LineSegmentIntersector::LIMIT_ONE);
|
||||||
|
osgUtil::IntersectionVisitor visitor(intersector);
|
||||||
|
|
||||||
|
osg::Node::NodeMask nodeMask = mCamera->getNodeMask();
|
||||||
|
mCamera->setNodeMask(~0);
|
||||||
|
mCamera->accept(visitor);
|
||||||
|
mCamera->setNodeMask(nodeMask);
|
||||||
|
|
||||||
|
if (intersector->containsIntersections())
|
||||||
|
{
|
||||||
|
osgUtil::LineSegmentIntersector::Intersection intersection = intersector->getFirstIntersection();
|
||||||
|
return mAnimation->getSlot(intersection.nodePath);
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InventoryPreview::updatePtr(const MWWorld::Ptr &ptr)
|
void InventoryPreview::updatePtr(const MWWorld::Ptr &ptr)
|
||||||
|
|
|
@ -235,6 +235,21 @@ void NpcAnimation::rebuild()
|
||||||
MWBase::Environment::get().getMechanicsManager()->forceStateUpdate(mPtr);
|
MWBase::Environment::get().getMechanicsManager()->forceStateUpdate(mPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int NpcAnimation::getSlot(const osg::NodePath &path) const
|
||||||
|
{
|
||||||
|
for (int i=0; i<ESM::PRT_Count; ++i)
|
||||||
|
{
|
||||||
|
PartHolderPtr part = mObjectParts[i];
|
||||||
|
if (!part.get())
|
||||||
|
continue;
|
||||||
|
if (std::find(path.begin(), path.end(), part->getNode().get()) != path.end())
|
||||||
|
{
|
||||||
|
return mPartslots[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void NpcAnimation::updateNpcBase()
|
void NpcAnimation::updateNpcBase()
|
||||||
{
|
{
|
||||||
clearAnimSources();
|
clearAnimSources();
|
||||||
|
|
|
@ -174,6 +174,9 @@ public:
|
||||||
/// Rebuilds the NPC, updating their root model, animation sources, and equipment.
|
/// Rebuilds the NPC, updating their root model, animation sources, and equipment.
|
||||||
void rebuild();
|
void rebuild();
|
||||||
|
|
||||||
|
/// Get the inventory slot that the given node path leads into, or -1 if not found.
|
||||||
|
int getSlot(const osg::NodePath& path) const;
|
||||||
|
|
||||||
/// Make the NPC only partially visible
|
/// Make the NPC only partially visible
|
||||||
virtual void setAlpha(float alpha);
|
virtual void setAlpha(float alpha);
|
||||||
|
|
||||||
|
|
|
@ -139,6 +139,8 @@ namespace MWRender
|
||||||
mViewer->getCamera()->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
|
mViewer->getCamera()->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
|
||||||
mViewer->getCamera()->setCullingMode(cullingMode);
|
mViewer->getCamera()->setCullingMode(cullingMode);
|
||||||
|
|
||||||
|
mViewer->getCamera()->setCullMask(~(Mask_UpdateVisitor));
|
||||||
|
|
||||||
mViewDistance = Settings::Manager::getFloat("viewing distance", "Viewing distance");
|
mViewDistance = Settings::Manager::getFloat("viewing distance", "Viewing distance");
|
||||||
mFieldOfView = Settings::Manager::getFloat("field of view", "General");
|
mFieldOfView = Settings::Manager::getFloat("field of view", "General");
|
||||||
updateProjectionMatrix();
|
updateProjectionMatrix();
|
||||||
|
|
Loading…
Reference in a new issue