Merge remote-tracking branch 'upstream/master' into static
commit
05c3936797
@ -0,0 +1,197 @@
|
||||
#include "levelupdialog.hpp"
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
|
||||
#include "../mwworld/player.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
|
||||
#include "../mwmechanics/creaturestats.hpp"
|
||||
#include "../mwmechanics/npcstats.hpp"
|
||||
#include "../mwmechanics/stat.hpp"
|
||||
|
||||
#include <components/esm_store/reclists.hpp>
|
||||
#include <components/esm_store/store.hpp>
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
LevelupDialog::LevelupDialog(MWBase::WindowManager &parWindowManager)
|
||||
: WindowBase("openmw_levelup_dialog.layout", parWindowManager)
|
||||
{
|
||||
getWidget(mOkButton, "OkButton");
|
||||
getWidget(mClassImage, "ClassImage");
|
||||
getWidget(mLevelText, "LevelText");
|
||||
|
||||
mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &LevelupDialog::onOkButtonClicked);
|
||||
|
||||
for (int i=1; i<9; ++i)
|
||||
{
|
||||
MyGUI::TextBox* t;
|
||||
getWidget(t, "AttribVal" + boost::lexical_cast<std::string>(i));
|
||||
|
||||
MyGUI::Button* b;
|
||||
getWidget(b, "Attrib" + boost::lexical_cast<std::string>(i));
|
||||
b->setUserData (i-1);
|
||||
b->eventMouseButtonClick += MyGUI::newDelegate(this, &LevelupDialog::onAttributeClicked);
|
||||
mAttributes.push_back(b);
|
||||
|
||||
mAttributeValues.push_back(t);
|
||||
|
||||
getWidget(t, "AttribMultiplier" + boost::lexical_cast<std::string>(i));
|
||||
|
||||
mAttributeMultipliers.push_back(t);
|
||||
}
|
||||
|
||||
int curX = mMainWidget->getWidth()/2 - (16 + 2) * 1.5;
|
||||
for (int i=0; i<3; ++i)
|
||||
{
|
||||
MyGUI::ImageBox* image = mMainWidget->createWidget<MyGUI::ImageBox>("ImageBox", MyGUI::IntCoord(curX,250,16,16), MyGUI::Align::Default);
|
||||
image->setImageTexture ("icons\\tx_goldicon.dds");
|
||||
curX += 24+2;
|
||||
mCoins.push_back(image);
|
||||
}
|
||||
|
||||
center();
|
||||
}
|
||||
|
||||
void LevelupDialog::setAttributeValues()
|
||||
{
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayer().getPlayer();
|
||||
MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get(player).getCreatureStats (player);
|
||||
MWMechanics::NpcStats& pcStats = MWWorld::Class::get(player).getNpcStats (player);
|
||||
|
||||
for (int i=0; i<8; ++i)
|
||||
{
|
||||
int val = creatureStats.getAttribute (i).getBase ();
|
||||
if (std::find(mSpentAttributes.begin(), mSpentAttributes.end(), i) != mSpentAttributes.end())
|
||||
{
|
||||
val += pcStats.getLevelupAttributeMultiplier (i);
|
||||
}
|
||||
|
||||
if (val >= 100)
|
||||
val = 100;
|
||||
|
||||
mAttributeValues[i]->setCaption(boost::lexical_cast<std::string>(val));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LevelupDialog::resetCoins ()
|
||||
{
|
||||
int curX = mMainWidget->getWidth()/2 - (16 + 2) * 1.5;
|
||||
for (int i=0; i<3; ++i)
|
||||
{
|
||||
MyGUI::ImageBox* image = mCoins[i];
|
||||
image->setCoord(MyGUI::IntCoord(curX,250,16,16));
|
||||
curX += 24+2;
|
||||
}
|
||||
}
|
||||
|
||||
void LevelupDialog::assignCoins ()
|
||||
{
|
||||
resetCoins();
|
||||
for (unsigned int i=0; i<mSpentAttributes.size(); ++i)
|
||||
{
|
||||
MyGUI::ImageBox* image = mCoins[i];
|
||||
int attribute = mSpentAttributes[i];
|
||||
|
||||
int xdiff = mAttributeMultipliers[attribute]->getCaption() == "" ? 0 : 30;
|
||||
|
||||
MyGUI::IntPoint pos = mAttributes[attribute]->getAbsolutePosition() - mMainWidget->getAbsolutePosition() - MyGUI::IntPoint(24+xdiff,-4);
|
||||
image->setPosition(pos);
|
||||
}
|
||||
|
||||
setAttributeValues();
|
||||
}
|
||||
|
||||
void LevelupDialog::open()
|
||||
{
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayer().getPlayer();
|
||||
MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get(player).getCreatureStats (player);
|
||||
MWMechanics::NpcStats& pcStats = MWWorld::Class::get(player).getNpcStats (player);
|
||||
|
||||
center();
|
||||
|
||||
mSpentAttributes.clear();
|
||||
resetCoins();
|
||||
|
||||
setAttributeValues();
|
||||
|
||||
// set class image
|
||||
const ESM::Class& playerClass = MWBase::Environment::get().getWorld ()->getPlayer ().getClass ();
|
||||
// retrieve the ID to this class
|
||||
std::string classId;
|
||||
std::map<std::string, ESM::Class> list = MWBase::Environment::get().getWorld()->getStore ().classes.list;
|
||||
for (std::map<std::string, ESM::Class>::iterator it = list.begin(); it != list.end(); ++it)
|
||||
{
|
||||
if (playerClass.name == it->second.name)
|
||||
classId = it->first;
|
||||
}
|
||||
mClassImage->setImageTexture ("textures\\levelup\\" + classId + ".dds");
|
||||
|
||||
/// \todo replace this with INI-imported texts
|
||||
int level = creatureStats.getLevel ()+1;
|
||||
mLevelText->setCaptionWithReplacing("#{sLevelUpMenu1} " + boost::lexical_cast<std::string>(level));
|
||||
|
||||
for (int i=0; i<8; ++i)
|
||||
{
|
||||
MyGUI::TextBox* text = mAttributeMultipliers[i];
|
||||
int mult = pcStats.getLevelupAttributeMultiplier (i);
|
||||
text->setCaption(mult <= 1 ? "" : "x" + boost::lexical_cast<std::string>(mult));
|
||||
}
|
||||
}
|
||||
|
||||
void LevelupDialog::onOkButtonClicked (MyGUI::Widget* sender)
|
||||
{
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayer().getPlayer();
|
||||
MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get(player).getCreatureStats (player);
|
||||
MWMechanics::NpcStats& pcStats = MWWorld::Class::get(player).getNpcStats (player);
|
||||
|
||||
if (mSpentAttributes.size() < 3)
|
||||
MWBase::Environment::get().getWindowManager ()->messageBox("#{sNotifyMessage36}", std::vector<std::string>());
|
||||
else
|
||||
{
|
||||
// increase attributes
|
||||
for (int i=0; i<3; ++i)
|
||||
{
|
||||
MWMechanics::Stat<int>& attribute = creatureStats.getAttribute(mSpentAttributes[i]);
|
||||
attribute.setBase (attribute.getBase () + pcStats.getLevelupAttributeMultiplier (mSpentAttributes[i]));
|
||||
|
||||
if (attribute.getBase() >= 100)
|
||||
attribute.setBase(100);
|
||||
}
|
||||
|
||||
// "When you gain a level, in addition to increasing three primary attributes, your Health
|
||||
// will automatically increase by 10% of your Endurance attribute. If you increased Endurance this level,
|
||||
// the Health increase is calculated from the increased Endurance"
|
||||
creatureStats.increaseLevelHealthBonus (creatureStats.getAttribute(ESM::Attribute::Endurance).getBase() * 0.1f);
|
||||
|
||||
creatureStats.setLevel (creatureStats.getLevel()+1);
|
||||
pcStats.levelUp ();
|
||||
|
||||
mWindowManager.removeGuiMode (GM_Rest);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LevelupDialog::onAttributeClicked (MyGUI::Widget *sender)
|
||||
{
|
||||
int attribute = *sender->getUserData<int>();
|
||||
|
||||
std::vector<int>::iterator found = std::find(mSpentAttributes.begin(), mSpentAttributes.end(), attribute);
|
||||
if (found != mSpentAttributes.end())
|
||||
mSpentAttributes.erase (found);
|
||||
else
|
||||
{
|
||||
if (mSpentAttributes.size() == 3)
|
||||
mSpentAttributes[2] = attribute;
|
||||
else
|
||||
mSpentAttributes.push_back(attribute);
|
||||
}
|
||||
assignCoins();
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
#ifndef MWGUI_LEVELUPDIALOG_H
|
||||
#define MWGUI_LEVELUPDIALOG_H
|
||||
|
||||
#include "window_base.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
class LevelupDialog : public WindowBase
|
||||
{
|
||||
public:
|
||||
LevelupDialog(MWBase::WindowManager& parWindowManager);
|
||||
|
||||
virtual void open();
|
||||
|
||||
private:
|
||||
MyGUI::Button* mOkButton;
|
||||
MyGUI::ImageBox* mClassImage;
|
||||
MyGUI::TextBox* mLevelText;
|
||||
|
||||
std::vector<MyGUI::Button*> mAttributes;
|
||||
std::vector<MyGUI::TextBox*> mAttributeValues;
|
||||
std::vector<MyGUI::TextBox*> mAttributeMultipliers;
|
||||
std::vector<MyGUI::ImageBox*> mCoins;
|
||||
|
||||
std::vector<int> mSpentAttributes;
|
||||
|
||||
void onOkButtonClicked (MyGUI::Widget* sender);
|
||||
void onAttributeClicked (MyGUI::Widget* sender);
|
||||
|
||||
void assignCoins();
|
||||
void resetCoins();
|
||||
|
||||
void setAttributeValues();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,135 @@
|
||||
#include "characterpreview.hpp"
|
||||
|
||||
|
||||
#include <OgreSceneManager.h>
|
||||
#include <OgreHardwarePixelBuffer.h>
|
||||
|
||||
#include <libs/openengine/ogre/selectionbuffer.hpp>
|
||||
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
#include "../mwworld/player.hpp"
|
||||
|
||||
#include "renderconst.hpp"
|
||||
#include "npcanimation.hpp"
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
|
||||
CharacterPreview::CharacterPreview(MWWorld::Ptr character, int sizeX, int sizeY, const std::string& name,
|
||||
Ogre::Vector3 position, Ogre::Vector3 lookAt)
|
||||
: mSizeX(sizeX)
|
||||
, mSizeY(sizeY)
|
||||
, mName(name)
|
||||
, mPosition(position)
|
||||
, mLookAt(lookAt)
|
||||
, mCharacter(character)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CharacterPreview::onSetup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CharacterPreview::setup (Ogre::SceneManager *sceneManager)
|
||||
{
|
||||
mSceneMgr = sceneManager;
|
||||
mCamera = mSceneMgr->createCamera (mName);
|
||||
mCamera->setAspectRatio (float(mSizeX) / float(mSizeY));
|
||||
|
||||
mNode = static_cast<Ogre::SceneNode*>(mSceneMgr->getRootSceneNode()->getChild("mwRoot"))->createChildSceneNode ();
|
||||
|
||||
mAnimation = new NpcAnimation(mCharacter, mNode,
|
||||
MWWorld::Class::get(mCharacter).getInventoryStore (mCharacter), RV_PlayerPreview);
|
||||
|
||||
mNode->setVisible (false);
|
||||
|
||||
mCamera->setPosition(mPosition);
|
||||
mCamera->lookAt(mLookAt);
|
||||
|
||||
mCamera->setNearClipDistance (0.01);
|
||||
mCamera->setFarClipDistance (1000);
|
||||
|
||||
mTexture = Ogre::TextureManager::getSingleton().createManual(mName,
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, mSizeX, mSizeY, 0, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET);
|
||||
|
||||
mRenderTarget = mTexture->getBuffer()->getRenderTarget();
|
||||
mViewport = mRenderTarget->addViewport(mCamera);
|
||||
mViewport->setOverlaysEnabled(false);
|
||||
mViewport->setBackgroundColour(Ogre::ColourValue(0, 0, 0, 0));
|
||||
mViewport->setShadowsEnabled(false);
|
||||
mViewport->setMaterialScheme("local_map");
|
||||
mViewport->setVisibilityMask (RV_PlayerPreview);
|
||||
mRenderTarget->setActive(true);
|
||||
mRenderTarget->setAutoUpdated (false);
|
||||
|
||||
onSetup ();
|
||||
}
|
||||
|
||||
CharacterPreview::~CharacterPreview ()
|
||||
{
|
||||
Ogre::TextureManager::getSingleton().remove(mName);
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
InventoryPreview::InventoryPreview(MWWorld::Ptr character)
|
||||
: CharacterPreview(character, 512, 1024, "CharacterPreview", Ogre::Vector3(0, 65, -180), Ogre::Vector3(0,65,0))
|
||||
{
|
||||
}
|
||||
|
||||
InventoryPreview::~InventoryPreview()
|
||||
{
|
||||
delete mSelectionBuffer;
|
||||
}
|
||||
|
||||
void InventoryPreview::update(int sizeX, int sizeY)
|
||||
{
|
||||
mAnimation->forceUpdate ();
|
||||
|
||||
mViewport->setDimensions (0, 0, std::min(1.f, float(sizeX) / float(512)), std::min(1.f, float(sizeY) / float(1024)));
|
||||
|
||||
mNode->setOrientation (Ogre::Quaternion::IDENTITY);
|
||||
|
||||
mNode->setVisible (true);
|
||||
|
||||
mRenderTarget->update();
|
||||
mSelectionBuffer->update();
|
||||
|
||||
mNode->setVisible (false);
|
||||
}
|
||||
|
||||
int InventoryPreview::getSlotSelected (int posX, int posY)
|
||||
{
|
||||
return mSelectionBuffer->getSelected (posX, posY);
|
||||
}
|
||||
|
||||
void InventoryPreview::onSetup ()
|
||||
{
|
||||
mSelectionBuffer = new OEngine::Render::SelectionBuffer(mCamera, 512, 1024, RV_PlayerPreview);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------
|
||||
|
||||
RaceSelectionPreview::RaceSelectionPreview()
|
||||
: CharacterPreview(MWBase::Environment::get().getWorld()->getPlayer().getPlayer(),
|
||||
512, 512, "CharacterHeadPreview", Ogre::Vector3(0, 120, -35), Ogre::Vector3(0,125,0))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RaceSelectionPreview::update(float angle)
|
||||
{
|
||||
mNode->roll(Ogre::Radian(angle), Ogre::SceneNode::TS_LOCAL);
|
||||
|
||||
mNode->setVisible (true);
|
||||
mRenderTarget->update();
|
||||
mNode->setVisible (false);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
#ifndef MWRENDER_CHARACTERPREVIEW_H
|
||||
#define MWRENDER_CHARACTERPREVIEW_H
|
||||
|
||||
#include <OgreRenderTarget.h>
|
||||
#include <OgreMaterialManager.h>
|
||||
|
||||
|
||||
#include "externalrendering.hpp"
|
||||
|
||||
#include "../mwworld/ptr.hpp"
|
||||
|
||||
namespace OEngine
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
class SelectionBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
|
||||
class NpcAnimation;
|
||||
|
||||
class CharacterPreview : public ExternalRendering
|
||||
{
|
||||
public:
|
||||
CharacterPreview(MWWorld::Ptr character, int sizeX, int sizeY, const std::string& name,
|
||||
Ogre::Vector3 position, Ogre::Vector3 lookAt);
|
||||
virtual ~CharacterPreview();
|
||||
|
||||
virtual void setup (Ogre::SceneManager *sceneManager);
|
||||
virtual void onSetup();
|
||||
|
||||
|
||||
protected:
|
||||
Ogre::TexturePtr mTexture;
|
||||
Ogre::RenderTarget* mRenderTarget;
|
||||
Ogre::Viewport* mViewport;
|
||||
|
||||
Ogre::Camera* mCamera;
|
||||
|
||||
Ogre::SceneManager* mSceneMgr;
|
||||
Ogre::SceneNode* mNode;
|
||||
|
||||
Ogre::Vector3 mPosition;
|
||||
Ogre::Vector3 mLookAt;
|
||||
|
||||
MWWorld::Ptr mCharacter;
|
||||
|
||||
MWRender::NpcAnimation* mAnimation;
|
||||
|
||||
std::string mName;
|
||||
|
||||
int mSizeX;
|
||||
int mSizeY;
|
||||
};
|
||||
|
||||
class InventoryPreview : public CharacterPreview
|
||||
{
|
||||
public:
|
||||
|
||||
InventoryPreview(MWWorld::Ptr character);
|
||||
virtual ~InventoryPreview();
|
||||
virtual void onSetup();
|
||||
|
||||
void update(int sizeX, int sizeY);
|
||||
|
||||
int getSlotSelected(int posX, int posY);
|
||||
|
||||
void setNpcAnimation (NpcAnimation* anim);
|
||||
|
||||
private:
|
||||
|
||||
OEngine::Render::SelectionBuffer* mSelectionBuffer;
|
||||
};
|
||||
|
||||
class RaceSelectionPreview : public CharacterPreview
|
||||
{
|
||||
public:
|
||||
RaceSelectionPreview();
|
||||
|
||||
void update(float angle);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,23 @@
|
||||
#ifndef GAME_RENDERING_EXTERNALRENDERING_H
|
||||
#define GAME_RENDERING_EXTERNALRENDERING_H
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class SceneManager;
|
||||
}
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
/// \brief Base class for out of world rendering
|
||||
class ExternalRendering
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void setup (Ogre::SceneManager *sceneManager) = 0;
|
||||
|
||||
virtual ~ExternalRendering() {}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 7168415233905de2864eec71ed4312cb8f83059b
|
||||
Subproject commit 4750676ac46a7aaa86bca53dc68c5a1ba11f3bc1
|
@ -0,0 +1,8 @@
|
||||
material SelectionColour
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_program selection_vertex
|
||||
fragment_program selection_fragment
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
#include "core.h"
|
||||
|
||||
#ifdef SH_VERTEX_SHADER
|
||||
|
||||
SH_BEGIN_PROGRAM
|
||||
shUniform(float4x4, wvp) @shAutoConstant(wvp, worldviewproj_matrix)
|
||||
|
||||
SH_START_PROGRAM
|
||||
{
|
||||
shOutputPosition = shMatrixMult(wvp, shInputPosition);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
SH_BEGIN_PROGRAM
|
||||
shUniform(float4, colour) @shAutoConstant(colour, custom, 1)
|
||||
|
||||
SH_START_PROGRAM
|
||||
{
|
||||
shOutputColour(0) = colour;
|
||||
//shOutputColour(0) = float4(1,0,0,1);
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,15 @@
|
||||
shader_set selection_vertex
|
||||
{
|
||||
source selection.shader
|
||||
type vertex
|
||||
profiles_cg vs_2_0 arbvp1
|
||||
profiles_hlsl vs_2_0
|
||||
}
|
||||
|
||||
shader_set selection_fragment
|
||||
{
|
||||
source selection.shader
|
||||
type fragment
|
||||
profiles_cg ps_2_x ps_2_0 ps arbfp1
|
||||
profiles_hlsl ps_2_0
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<MyGUI type="Layout">
|
||||
<Widget type="Window" skin="MW_Dialog" layer="Windows" position="0 0 440 438" name="_Main">
|
||||
|
||||
<Widget type="Widget" skin="MW_Box" position="28 14 391 198">
|
||||
<Widget type="ImageBox" skin="ImageBox" name="ClassImage" position="4 4 383 190">
|
||||
</Widget>
|
||||
</Widget>
|
||||
|
||||
<Widget type="TextBox" skin="SandText" position="28 218 391 24" name="LevelText">
|
||||
</Widget>
|
||||
|
||||
<Widget type="Widget" skin="" position="36 280 400 400">
|
||||
<Widget type="TextBox" skin="SandText" position="0 0 100 24" name="AttribMultiplier1"/>
|
||||
<Widget type="TextBox" skin="SandText" position="0 24 100 24" name="AttribMultiplier2"/>
|
||||
<Widget type="TextBox" skin="SandText" position="0 48 100 24" name="AttribMultiplier3"/>
|
||||
<Widget type="TextBox" skin="SandText" position="0 72 100 24" name="AttribMultiplier4"/>
|
||||
<Widget type="TextBox" skin="SandText" position="200 0 100 24" name="AttribMultiplier5"/>
|
||||
<Widget type="TextBox" skin="SandText" position="200 24 100 24" name="AttribMultiplier6"/>
|
||||
<Widget type="TextBox" skin="SandText" position="200 48 100 24" name="AttribMultiplier7"/>
|
||||
<Widget type="TextBox" skin="SandText" position="200 72 100 24" name="AttribMultiplier8"/>
|
||||
|
||||
<Widget type="HBox" position="22 0 200 24">
|
||||
<Widget type="AutoSizedButton" skin="SandTextButton" name="Attrib1">
|
||||
<UserString key="ToolTipType" value="Layout"/>
|
||||
<UserString key="ToolTipLayout" value="AttributeToolTip"/>
|
||||
<UserString key="Caption_AttributeName" value="#{sAttributeStrength}"/>
|
||||
<UserString key="Caption_AttributeDescription" value="#{sStrDesc}"/>
|
||||
<UserString key="ImageTexture_AttributeImage" value="icons\k\attribute_strength.dds"/>
|
||||
<Property key="Caption" value="#{sAttributeStrength}"/>
|
||||
</Widget>
|
||||
<Widget type="AutoSizedTextBox" skin="SandText" name="AttribVal1">
|
||||
</Widget>
|
||||
</Widget>
|
||||
|
||||
<Widget type="HBox" position="22 24 200 24">
|
||||
<Widget type="AutoSizedButton" skin="SandTextButton" name="Attrib2">
|
||||
<UserString key="ToolTipType" value="Layout"/>
|
||||
<UserString key="ToolTipLayout" value="AttributeToolTip"/>
|
||||
<UserString key="Caption_AttributeName" value="#{sAttributeIntelligence}"/>
|
||||
<UserString key="Caption_AttributeDescription" value="#{sIntDesc}"/>
|
||||
<UserString key="ImageTexture_AttributeImage" value="icons\k\attribute_int.dds"/>
|
||||
<Property key="Caption" value="#{sAttributeIntelligence}"/>
|
||||
</Widget>
|
||||
<Widget type="AutoSizedTextBox" skin="SandText" name="AttribVal2">
|
||||
</Widget>
|
||||
</Widget>
|
||||
|
||||
<Widget type="HBox" position="22 48 200 24">
|
||||
<Widget type="AutoSizedButton" skin="SandTextButton" name="Attrib3">
|
||||
<UserString key="ToolTipType" value="Layout"/>
|
||||
<UserString key="ToolTipLayout" value="AttributeToolTip"/>
|
||||
<UserString key="Caption_AttributeName" value="#{sAttributeWillpower}"/>
|
||||
<UserString key="Caption_AttributeDescription" value="#{sWilDesc}"/>
|
||||
<UserString key="ImageTexture_AttributeImage" value="icons\k\attribute_wilpower.dds"/>
|
||||
<Property key="Caption" value="#{sAttributeWillpower}"/>
|
||||
</Widget>
|
||||
<Widget type="AutoSizedTextBox" skin="SandText" name="AttribVal3">
|
||||
</Widget>
|
||||
</Widget>
|
||||
|
||||
<Widget type="HBox" position="22 72 200 24">
|
||||
<Widget type="AutoSizedButton" skin="SandTextButton" name="Attrib4">
|
||||
<UserString key="ToolTipType" value="Layout"/>
|
||||
<UserString key="ToolTipLayout" value="AttributeToolTip"/>
|
||||
<UserString key="Caption_AttributeName" value="#{sAttributeAgility}"/>
|
||||
<UserString key="Caption_AttributeDescription" value="#{sAgiDesc}"/>
|
||||
<UserString key="ImageTexture_AttributeImage" value="icons\k\attribute_agility.dds"/>
|
||||
<Property key="Caption" value="#{sAttributeAgility}"/>
|
||||
</Widget>
|
||||
<Widget type="AutoSizedTextBox" skin="SandText" name="AttribVal4">
|
||||
</Widget>
|
||||
</Widget>
|
||||
|
||||
|
||||
<Widget type="HBox" position="222 0 200 24">
|
||||
<Widget type="AutoSizedButton" skin="SandTextButton" name="Attrib5">
|
||||
<UserString key="ToolTipType" value="Layout"/>
|
||||
<UserString key="ToolTipLayout" value="AttributeToolTip"/>
|
||||
<UserString key="Caption_AttributeName" value="#{sAttributeSpeed}"/>
|
||||
<UserString key="Caption_AttributeDescription" value="#{sSpdDesc}"/>
|
||||
<UserString key="ImageTexture_AttributeImage" value="icons\k\attribute_speed.dds"/>
|
||||
<Property key="Caption" value="#{sAttributeSpeed}"/>
|
||||
</Widget>
|
||||
<Widget type="AutoSizedTextBox" skin="SandText" name="AttribVal5">
|
||||
</Widget>
|
||||
</Widget>
|
||||
|
||||
<Widget type="HBox" position="222 24 200 24">
|
||||
<Widget type="AutoSizedButton" skin="SandTextButton" name="Attrib6">
|
||||
<UserString key="ToolTipType" value="Layout"/>
|
||||
<UserString key="ToolTipLayout" value="AttributeToolTip"/>
|
||||
<UserString key="Caption_AttributeName" value="#{sAttributeEndurance}"/>
|
||||
<UserString key="Caption_AttributeDescription" value="#{sEndDesc}"/>
|
||||
<UserString key="ImageTexture_AttributeImage" value="icons\k\attribute_endurance.dds"/>
|
||||
<Property key="Caption" value="#{sAttributeEndurance}"/>
|
||||
</Widget>
|
||||
<Widget type="AutoSizedTextBox" skin="SandText" name="AttribVal6">
|
||||
</Widget>
|
||||
</Widget>
|
||||
|
||||
<Widget type="HBox" position="222 48 200 24">
|
||||
<Widget type="AutoSizedButton" skin="SandTextButton" name="Attrib7">
|
||||
<UserString key="ToolTipType" value="Layout"/>
|
||||
<UserString key="ToolTipLayout" value="AttributeToolTip"/>
|
||||
<UserString key="Caption_AttributeName" value="#{sAttributePersonality}"/>
|
||||
<UserString key="Caption_AttributeDescription" value="#{sPerDesc}"/>
|
||||
<UserString key="ImageTexture_AttributeImage" value="icons\k\attribute_personality.dds"/>
|
||||
<Property key="Caption" value="#{sAttributePersonality}"/>
|
||||
</Widget>
|
||||
<Widget type="AutoSizedTextBox" skin="SandText" name="AttribVal7">
|
||||
</Widget>
|
||||
</Widget>
|
||||
|
||||
<Widget type="HBox" position="222 72 200 24">
|
||||
<Widget type="AutoSizedButton" skin="SandTextButton" name="Attrib8">
|
||||
<UserString key="ToolTipType" value="Layout"/>
|
||||
<UserString key="ToolTipLayout" value="AttributeToolTip"/>
|
||||
<UserString key="Caption_AttributeName" value="#{sAttributeLuck}"/>
|
||||
<UserString key="Caption_AttributeDescription" value="#{sLucDesc}"/>
|
||||
<UserString key="ImageTexture_AttributeImage" value="icons\k\attribute_luck.dds"/>
|
||||
<Property key="Caption" value="#{sAttributeLuck}"/>
|
||||
</Widget>
|
||||
<Widget type="AutoSizedTextBox" skin="SandText" name="AttribVal8">
|
||||
</Widget>
|
||||
</Widget>
|
||||
</Widget>
|
||||
|
||||
|
||||
<Widget type="AutoSizedButton" skin="MW_Button" position="422 398 0 24" name="OkButton">
|
||||
<Property key="ExpandDirection" value="Left"/>
|
||||
<Property key="Caption" value="#{sOk}"/>
|
||||
</Widget>
|
||||
|
||||
</Widget>
|
||||
|
||||
</MyGUI>
|
@ -0,0 +1,123 @@
|
||||
#include "selectionbuffer.hpp"
|
||||
|
||||
#include <OgreHardwarePixelBuffer.h>
|
||||
#include <OgreRenderTexture.h>
|
||||
#include <OgreSubEntity.h>
|
||||
#include <OgreEntity.h>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <extern/shiny/Main/Factory.hpp>
|
||||
|
||||
namespace OEngine
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
|
||||
SelectionBuffer::SelectionBuffer(Ogre::Camera *camera, int sizeX, int sizeY, int visibilityFlags)
|
||||
{
|
||||
mTexture = Ogre::TextureManager::getSingleton().createManual("SelectionBuffer",
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, sizeX, sizeY, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);
|
||||
|
||||
mRenderTarget = mTexture->getBuffer()->getRenderTarget();
|
||||
Ogre::Viewport* vp = mRenderTarget->addViewport(camera);
|
||||
vp->setOverlaysEnabled(false);
|
||||
vp->setBackgroundColour(Ogre::ColourValue(0, 0, 0, 0));
|
||||
vp->setShadowsEnabled(false);
|
||||
vp->setMaterialScheme("selectionbuffer");
|
||||
vp->setVisibilityMask (visibilityFlags);
|
||||
mRenderTarget->setActive(true);
|
||||
mRenderTarget->setAutoUpdated (false);
|
||||
|
||||
mCurrentColour = Ogre::ColourValue(0.3, 0.3, 0.3);
|
||||
}
|
||||
|
||||
SelectionBuffer::~SelectionBuffer()
|
||||
{
|
||||
Ogre::TextureManager::getSingleton ().remove("SelectionBuffer");
|
||||
}
|
||||
|
||||
void SelectionBuffer::update ()
|
||||
{
|
||||
Ogre::MaterialManager::getSingleton ().addListener (this);
|
||||
|
||||
mRenderTarget->update();
|
||||
|
||||
Ogre::MaterialManager::getSingleton ().removeListener (this);
|
||||
|
||||
mTexture->convertToImage(mBuffer);
|
||||
}
|
||||
|
||||
int SelectionBuffer::getSelected(int xPos, int yPos)
|
||||
{
|
||||
Ogre::ColourValue clr = mBuffer.getColourAt (xPos, yPos, 0);
|
||||
clr.a = 1;
|
||||
if (mColourMap.find(clr) != mColourMap.end())
|
||||
return mColourMap[clr];
|
||||
else
|
||||
return -1; // nothing selected
|
||||
}
|
||||
|
||||
Ogre::Technique* SelectionBuffer::handleSchemeNotFound (
|
||||
unsigned short schemeIndex, const Ogre::String &schemeName, Ogre::Material *originalMaterial,
|
||||
unsigned short lodIndex, const Ogre::Renderable *rend)
|
||||
{
|
||||
if (schemeName == "selectionbuffer")
|
||||
{
|
||||
sh::Factory::getInstance ()._ensureMaterial ("SelectionColour", "Default");
|
||||
|
||||
Ogre::MaterialPtr m = Ogre::MaterialManager::getSingleton ().getByName("SelectionColour");
|
||||
|
||||
|
||||
if(typeid(*rend) == typeid(Ogre::SubEntity))
|
||||
{
|
||||
const Ogre::SubEntity *subEntity = static_cast<const Ogre::SubEntity *>(rend);
|
||||
int id = Ogre::any_cast<int>(subEntity->getParent ()->getUserObjectBindings().getUserAny());
|
||||
bool found = false;
|
||||
Ogre::ColourValue colour;
|
||||
for (std::map<Ogre::ColourValue, int, cmp_ColourValue>::iterator it = mColourMap.begin(); it != mColourMap.end(); ++it)
|
||||
{
|
||||
if (it->second == id)
|
||||
{
|
||||
found = true;
|
||||
colour = it->first;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!found)
|
||||
{
|
||||
getNextColour();
|
||||
const_cast<Ogre::SubEntity *>(subEntity)->setCustomParameter(1, Ogre::Vector4(mCurrentColour.r, mCurrentColour.g, mCurrentColour.b, 1.0));
|
||||
mColourMap[mCurrentColour] = id;
|
||||
}
|
||||
else
|
||||
{
|
||||
const_cast<Ogre::SubEntity *>(subEntity)->setCustomParameter(1, Ogre::Vector4(colour.r, colour.g, colour.b, 1.0));
|
||||
}
|
||||
|
||||
assert(m->getTechnique(1));
|
||||
return m->getTechnique(1);
|
||||
}
|
||||
else
|
||||
throw std::runtime_error("selectionbuffer only works with entities");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SelectionBuffer::getNextColour ()
|
||||
{
|
||||
Ogre::ARGB color = (float(rand()) / float(RAND_MAX)) * std::numeric_limits<Ogre::uint32>::max();
|
||||
|
||||
if (mCurrentColour.getAsARGB () == color)
|
||||
{
|
||||
getNextColour();
|
||||
return;
|
||||
}
|
||||
|
||||
mCurrentColour.setAsARGB(color);
|
||||
mCurrentColour.a = 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
#ifndef OENGINE_SELECTIONBUFFER_H
|
||||
#define OENGINE_SELECTIONBUFFER_H
|
||||
|
||||
|
||||
#include <OgreTexture.h>
|
||||
#include <OgreRenderTarget.h>
|
||||
#include <OgreMaterialManager.h>
|
||||
|
||||
namespace OEngine
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
|
||||
struct cmp_ColourValue
|
||||
{
|
||||
bool operator()(const Ogre::ColourValue &a, const Ogre::ColourValue &b) const
|
||||
{
|
||||
return a.getAsBGRA() < b.getAsBGRA();
|
||||
}
|
||||
};
|
||||
|
||||
class SelectionBuffer : public Ogre::MaterialManager::Listener
|
||||
{
|
||||
public:
|
||||
SelectionBuffer(Ogre::Camera* camera, int sizeX, int sizeY, int visibilityFlags);
|
||||
virtual ~SelectionBuffer();
|
||||
|
||||
int getSelected(int xPos, int yPos);
|
||||
///< @return ID of the selected object
|
||||
|
||||
void update();
|
||||
|
||||
virtual Ogre::Technique* handleSchemeNotFound (
|
||||
unsigned short schemeIndex, const Ogre::String &schemeName, Ogre::Material *originalMaterial,
|
||||
unsigned short lodIndex, const Ogre::Renderable *rend);
|
||||
|
||||
|
||||
private:
|
||||
Ogre::TexturePtr mTexture;
|
||||
Ogre::RenderTexture* mRenderTarget;
|
||||
|
||||
Ogre::Image mBuffer;
|
||||
|
||||
std::map<Ogre::ColourValue, int, cmp_ColourValue> mColourMap;
|
||||
|
||||
Ogre::ColourValue mCurrentColour;
|
||||
|
||||
void getNextColour();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue