Skip to content

Commit

Permalink
item selection working on the preview
Browse files Browse the repository at this point in the history
  • Loading branch information
scrawl committed Sep 14, 2012
1 parent eef750e commit 6ac2a12
Show file tree
Hide file tree
Showing 22 changed files with 367 additions and 34 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ set(OENGINE_OGRE
${LIBDIR}/openengine/ogre/fader.cpp
${LIBDIR}/openengine/ogre/imagerotate.cpp
${LIBDIR}/openengine/ogre/atlas.cpp
${LIBDIR}/openengine/ogre/selectionbuffer.cpp
)
set(OENGINE_GUI
${LIBDIR}/openengine/gui/manager.cpp
Expand Down
1 change: 1 addition & 0 deletions apps/openmw/mwbase/world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ namespace MWBase

virtual void updateCharacterPreview(int sizeX, int sizeY) = 0;
virtual void updateRaceSelectionPreview(float angle) = 0;
virtual MWWorld::Ptr getCharacterPreviewItemSelected(int posX, int posY) = 0;
};
}

Expand Down
30 changes: 30 additions & 0 deletions apps/openmw/mwgui/inventorywindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace MWGui
: ContainerBase(dragAndDrop)
, WindowPinnableBase("openmw_inventory_window.layout", parWindowManager)
, mTrading(false)
, mAvatarClickedPosX(0)
, mAvatarClickedPosY(0)
{
static_cast<MyGUI::Window*>(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &InventoryWindow::onWindowResize);

Expand Down Expand Up @@ -107,6 +109,7 @@ namespace MWGui
MWBase::Environment::get().getWorld()->updateCharacterPreview (size.width, size.height);
mAvatarImage->setSize(MyGUI::IntSize(std::max(mAvatar->getSize().width, 512), std::max(mAvatar->getSize().height, 1024)));
mAvatarImage->setImageTexture("CharacterPreview");
mAvatarImage->setImageTexture("SelectionBuffer");
}

void InventoryWindow::onFilterChanged(MyGUI::Widget* _sender)
Expand Down Expand Up @@ -180,6 +183,28 @@ namespace MWGui

notifyContentChanged();
}
else
{
MyGUI::IntPoint mousePos = MyGUI::InputManager::getInstance ().getLastPressedPosition (MyGUI::MouseButton::Left);
MyGUI::IntPoint relPos = mousePos - mAvatar->getAbsolutePosition ();
int realX = int(float(relPos.left) / float(mAvatar->getSize().width) * 512.f );
int realY = int(float(relPos.top) / float(mAvatar->getSize().height) * 1024.f );
MWWorld::Ptr itemSelected = MWBase::Environment::get().getWorld ()->getCharacterPreviewItemSelected (realX, realY);
if (itemSelected.isEmpty ())
return;


for (unsigned int i=0; i < mContainerWidget->getChildCount (); ++i)
{
MyGUI::Widget* w = mContainerWidget->getChildAt (i);

if (*w->getUserData<MWWorld::Ptr>() == itemSelected)
{
onSelectedItem(w);
return;
}
}
}
}

std::vector<MWWorld::Ptr> InventoryWindow::getEquippedItems()
Expand Down Expand Up @@ -336,4 +361,9 @@ namespace MWGui
text->setCaption(getCountString(count));
mDragAndDrop->mDraggedFrom = this;
}

MyGUI::IntCoord InventoryWindow::getAvatarScreenCoord ()
{
return mAvatar->getAbsoluteCoord ();
}
}
6 changes: 6 additions & 0 deletions apps/openmw/mwgui/inventorywindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace MWGui

int getPlayerGold();

MyGUI::IntCoord getAvatarScreenCoord();

protected:
MyGUI::Widget* mAvatar;
MyGUI::ImageBox* mAvatarImage;
Expand All @@ -38,6 +40,10 @@ namespace MWGui
MyGUI::Button* mFilterMagic;
MyGUI::Button* mFilterMisc;

int mAvatarClickedPosX;
int mAvatarClickedPosY;


bool mTrading;

void onWindowResize(MyGUI::Window* _sender);
Expand Down
13 changes: 12 additions & 1 deletion apps/openmw/mwgui/tooltips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "map_window.hpp"
#include "widgets.hpp"
#include "inventorywindow.hpp"

using namespace MWGui;
using namespace MyGUI;
Expand Down Expand Up @@ -162,12 +163,22 @@ void ToolTips::onFrame(float frameDuration)
return;
}


if (type == "ItemPtr")
{
mFocusObject = *focus->getUserData<MWWorld::Ptr>();
tooltipSize = getToolTipViaPtr(false);
}
else if (type == "AvatarItemSelection")
{
MyGUI::IntCoord avatarPos = mWindowManager->getInventoryWindow ()->getAvatarScreenCoord ();
MyGUI::IntPoint relMousePos = MyGUI::InputManager::getInstance ().getMousePosition () - MyGUI::IntPoint(avatarPos.left, avatarPos.top);
int realX = int(float(relMousePos.left) / float(avatarPos.width) * 512.f );
int realY = int(float(relMousePos.top) / float(avatarPos.height) * 1024.f );
MWWorld::Ptr item = MWBase::Environment::get().getWorld ()->getCharacterPreviewItemSelected (realX, realY);

mFocusObject = item;
tooltipSize = getToolTipViaPtr(false);
}
else if (type == "Spell")
{
ToolTipInfo info;
Expand Down
16 changes: 16 additions & 0 deletions apps/openmw/mwrender/characterpreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <OgreSceneManager.h>
#include <OgreHardwarePixelBuffer.h>

#include <libs/openengine/ogre/selectionbuffer.hpp>


#include "renderconst.hpp"
#include "npcanimation.hpp"
Expand Down Expand Up @@ -50,7 +52,12 @@ namespace MWRender
: CharacterPreview(sceneMgr, node, 512, 1024, "CharacterPreview", Ogre::Vector3(0, 65, -180), Ogre::Vector3(0,65,0))
, mAnimation(NULL)
{
mSelectionBuffer = new OEngine::Render::SelectionBuffer(mCamera, 512, 1024, RV_PlayerPreview);
}

InventoryPreview::~InventoryPreview()
{
delete mSelectionBuffer;
}

void InventoryPreview::update(int sizeX, int sizeY)
Expand All @@ -63,7 +70,10 @@ namespace MWRender
mNode->setOrientation (Ogre::Quaternion::IDENTITY);

mNode->setVisible (true);

mRenderTarget->update();
mSelectionBuffer->update();

mNode->setVisible (false);
}

Expand All @@ -72,6 +82,12 @@ namespace MWRender
mAnimation = anim;
}

int InventoryPreview::getSlotSelected (int posX, int posY)
{
std::cout << posX << " " << posY << std::endl;
return mSelectionBuffer->getSelected (posX, posY);
}

// --------------------------------------------------------------------------------------------------

RaceSelectionPreview::RaceSelectionPreview(Ogre::SceneManager *sceneMgr, Ogre::SceneNode *node)
Expand Down
15 changes: 15 additions & 0 deletions apps/openmw/mwrender/characterpreview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
#define MWRENDER_CHARACTERPREVIEW_H

#include <OgreRenderTarget.h>
#include <OgreMaterialManager.h>


namespace OEngine
{
namespace Render
{
class SelectionBuffer;
}
}

namespace MWRender
{
Expand Down Expand Up @@ -32,13 +42,18 @@ namespace MWRender
{
public:
InventoryPreview(Ogre::SceneManager* sceneMgr, Ogre::SceneNode* node);
virtual ~InventoryPreview();

void update(int sizeX, int sizeY);

int getSlotSelected(int posX, int posY);

void setNpcAnimation (NpcAnimation* anim);

private:
NpcAnimation* mAnimation;

OEngine::Render::SelectionBuffer* mSelectionBuffer;
};

class RaceSelectionPreview : public CharacterPreview
Expand Down
59 changes: 32 additions & 27 deletions apps/openmw/mwrender/npcanimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, OEngi
{
Ogre::Entity *base = mEntityList.mEntities[i];

base->getUserObjectBindings ().setUserAny (Ogre::Any(-1));

base->setVisibilityFlags(mVisibilityFlags);
bool transparent = false;
for(unsigned int j=0;j < base->getNumSubEntities();++j)
Expand Down Expand Up @@ -351,13 +353,16 @@ void NpcAnimation::updateParts()
}
}

NifOgre::EntityList NpcAnimation::insertBoundedPart(const std::string &mesh, const std::string &bonename)
NifOgre::EntityList NpcAnimation::insertBoundedPart(const std::string &mesh, int group, const std::string &bonename)
{
NifOgre::EntityList entities = NIFLoader::createEntities(mEntityList.mSkelBase, bonename,
mInsert, mesh);
std::vector<Ogre::Entity*> &parts = entities.mEntities;
for(size_t i = 0;i < parts.size();i++)
{
parts[i]->setVisibilityFlags(mVisibilityFlags);
parts[i]->getUserObjectBindings ().setUserAny (Ogre::Any(group));
}
return entities;
}

Expand Down Expand Up @@ -480,83 +485,83 @@ bool NpcAnimation::addOrReplaceIndividualPart(int type, int group, int priority,
switch(type)
{
case ESM::PRT_Head: //0
head = insertBoundedPart(mesh, "Head");
head = insertBoundedPart(mesh, group, "Head");
break;
case ESM::PRT_Hair: //1
hair = insertBoundedPart(mesh, "Head");
hair = insertBoundedPart(mesh, group, "Head");
break;
case ESM::PRT_Neck: //2
neck = insertBoundedPart(mesh, "Neck");
neck = insertBoundedPart(mesh, group, "Neck");
break;
case ESM::PRT_Cuirass: //3
chest = insertBoundedPart(mesh, "Chest");
chest = insertBoundedPart(mesh, group, "Chest");
break;
case ESM::PRT_Groin: //4
groin = insertBoundedPart(mesh, "Groin");
groin = insertBoundedPart(mesh, group, "Groin");
break;
case ESM::PRT_Skirt: //5
skirt = insertBoundedPart(mesh, "Groin");
skirt = insertBoundedPart(mesh, group, "Groin");
break;
case ESM::PRT_RHand: //6
rHand = insertBoundedPart(mesh, "Right Hand");
rHand = insertBoundedPart(mesh, group, "Right Hand");
break;
case ESM::PRT_LHand: //7
lHand = insertBoundedPart(mesh, "Left Hand");
lHand = insertBoundedPart(mesh, group, "Left Hand");
break;
case ESM::PRT_RWrist: //8
rWrist = insertBoundedPart(mesh, "Right Wrist");
rWrist = insertBoundedPart(mesh, group, "Right Wrist");
break;
case ESM::PRT_LWrist: //9
lWrist = insertBoundedPart(mesh, "Left Wrist");
lWrist = insertBoundedPart(mesh, group, "Left Wrist");
break;
case ESM::PRT_Shield: //10
break;
case ESM::PRT_RForearm: //11
rForearm = insertBoundedPart(mesh, "Right Forearm");
rForearm = insertBoundedPart(mesh, group, "Right Forearm");
break;
case ESM::PRT_LForearm: //12
lForearm = insertBoundedPart(mesh, "Left Forearm");
lForearm = insertBoundedPart(mesh, group, "Left Forearm");
break;
case ESM::PRT_RUpperarm: //13
rupperArm = insertBoundedPart(mesh, "Right Upper Arm");
rupperArm = insertBoundedPart(mesh, group, "Right Upper Arm");
break;
case ESM::PRT_LUpperarm: //14
lupperArm = insertBoundedPart(mesh, "Left Upper Arm");
lupperArm = insertBoundedPart(mesh, group, "Left Upper Arm");
break;
case ESM::PRT_RFoot: //15
rfoot = insertBoundedPart(mesh, "Right Foot");
rfoot = insertBoundedPart(mesh, group, "Right Foot");
break;
case ESM::PRT_LFoot: //16
lfoot = insertBoundedPart(mesh, "Left Foot");
lfoot = insertBoundedPart(mesh, group, "Left Foot");
break;
case ESM::PRT_RAnkle: //17
rAnkle = insertBoundedPart(mesh, "Right Ankle");
rAnkle = insertBoundedPart(mesh, group, "Right Ankle");
break;
case ESM::PRT_LAnkle: //18
lAnkle = insertBoundedPart(mesh, "Left Ankle");
lAnkle = insertBoundedPart(mesh, group, "Left Ankle");
break;
case ESM::PRT_RKnee: //19
rKnee = insertBoundedPart(mesh, "Right Knee");
rKnee = insertBoundedPart(mesh, group, "Right Knee");
break;
case ESM::PRT_LKnee: //20
lKnee = insertBoundedPart(mesh, "Left Knee");
lKnee = insertBoundedPart(mesh, group, "Left Knee");
break;
case ESM::PRT_RLeg: //21
rUpperLeg = insertBoundedPart(mesh, "Right Upper Leg");
rUpperLeg = insertBoundedPart(mesh, group, "Right Upper Leg");
break;
case ESM::PRT_LLeg: //22
lUpperLeg = insertBoundedPart(mesh, "Left Upper Leg");
lUpperLeg = insertBoundedPart(mesh, group, "Left Upper Leg");
break;
case ESM::PRT_RPauldron: //23
rclavicle = insertBoundedPart(mesh , "Right Clavicle");
rclavicle = insertBoundedPart(mesh , group, "Right Clavicle");
break;
case ESM::PRT_LPauldron: //24
lclavicle = insertBoundedPart(mesh, "Left Clavicle");
lclavicle = insertBoundedPart(mesh, group, "Left Clavicle");
break;
case ESM::PRT_Weapon: //25
break;
case ESM::PRT_Tail: //26
tail = insertBoundedPart(mesh, "Tail");
tail = insertBoundedPart(mesh, group, "Tail");
break;
}
return true;
Expand All @@ -575,7 +580,7 @@ void NpcAnimation::addPartGroup(int group, int priority, std::vector<ESM::PartRe
bodypart = MWBase::Environment::get().getWorld()->getStore().bodyParts.search(part.male);

if(bodypart)
addOrReplaceIndividualPart(part.part, group,priority,"meshes\\" + bodypart->model);
addOrReplaceIndividualPart(part.part, group, priority,"meshes\\" + bodypart->model);
else
reserveIndividualPart(part.part, group, priority);
}
Expand Down
4 changes: 1 addition & 3 deletions apps/openmw/mwrender/npcanimation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class NpcAnimation: public Animation{
int mPartslots[27]; //Each part slot is taken by clothing, armor, or is empty
int mPartPriorities[27];

bool mIsPlayer;

//Bounded Parts
NifOgre::EntityList lclavicle;
NifOgre::EntityList rclavicle;
Expand Down Expand Up @@ -73,7 +71,7 @@ class NpcAnimation: public Animation{
NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, OEngine::Render::OgreRenderer& _rend,
MWWorld::InventoryStore& _inv, int visibilityFlags);
virtual ~NpcAnimation();
NifOgre::EntityList insertBoundedPart(const std::string &mesh, const std::string &bonename);
NifOgre::EntityList insertBoundedPart(const std::string &mesh, int group, const std::string &bonename);
virtual void runAnimation(float timepassed);
void updateParts();
void removeEntities(NifOgre::EntityList &entities);
Expand Down
6 changes: 6 additions & 0 deletions apps/openmw/mwrender/renderingmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,4 +905,10 @@ void RenderingManager::updateRaceSelectionPreview (float angle)
mRaceSelectionPreview->update(angle);
}

int RenderingManager::getCharacterPreviewSlotSelected(int posX, int posY)
{
std::cout << "SLOT IS " << mInventoryPreview->getSlotSelected(posX, posY) << std::endl;
return mInventoryPreview->getSlotSelected(posX, posY);
}

} // namespace
1 change: 1 addition & 0 deletions apps/openmw/mwrender/renderingmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class RenderingManager: private RenderingInterface, public Ogre::WindowEventList

void updateCharacterPreview(int sizeX, int sizeY);
void updateRaceSelectionPreview(float angle);
int getCharacterPreviewSlotSelected(int posX, int posY);

protected:
virtual void windowResized(Ogre::RenderWindow* rw);
Expand Down
Loading

0 comments on commit 6ac2a12

Please sign in to comment.