2010-08-03 13:24:44 +00:00
|
|
|
|
|
|
|
#include "light.hpp"
|
|
|
|
|
|
|
|
#include <components/esm/loadligh.hpp>
|
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-07-03 10:30:50 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
2012-04-23 13:27:03 +00:00
|
|
|
|
2010-08-03 15:11:41 +00:00
|
|
|
#include "../mwworld/ptr.hpp"
|
2010-08-07 18:25:17 +00:00
|
|
|
#include "../mwworld/actiontake.hpp"
|
2012-06-04 19:48:20 +00:00
|
|
|
#include "../mwworld/actionequip.hpp"
|
2010-08-07 18:25:17 +00:00
|
|
|
#include "../mwworld/nullaction.hpp"
|
2012-03-13 14:35:06 +00:00
|
|
|
#include "../mwworld/inventorystore.hpp"
|
2012-06-29 14:48:50 +00:00
|
|
|
#include "../mwworld/cellstore.hpp"
|
2012-07-03 11:15:20 +00:00
|
|
|
#include "../mwworld/physicssystem.hpp"
|
2012-04-16 20:58:16 +00:00
|
|
|
|
|
|
|
#include "../mwgui/window_manager.hpp"
|
|
|
|
#include "../mwgui/tooltips.hpp"
|
2010-08-03 15:11:41 +00:00
|
|
|
|
2010-08-14 09:39:32 +00:00
|
|
|
#include "../mwsound/soundmanager.hpp"
|
|
|
|
|
2012-01-27 14:11:02 +00:00
|
|
|
#include "../mwrender/objects.hpp"
|
2012-07-03 11:15:20 +00:00
|
|
|
#include "../mwrender/renderinginterface.hpp"
|
2012-01-27 14:11:02 +00:00
|
|
|
|
2010-08-03 13:24:44 +00:00
|
|
|
namespace MWClass
|
|
|
|
{
|
2011-11-12 04:01:12 +00:00
|
|
|
void Light::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
|
2010-08-14 08:02:54 +00:00
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Light> *ref =
|
2010-08-14 08:02:54 +00:00
|
|
|
ptr.get<ESM::Light>();
|
|
|
|
|
|
|
|
assert (ref->base != NULL);
|
|
|
|
const std::string &model = ref->base->model;
|
2012-01-27 14:11:02 +00:00
|
|
|
|
2012-02-04 09:48:15 +00:00
|
|
|
MWRender::Objects& objects = renderingInterface.getObjects();
|
|
|
|
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
|
|
|
|
|
2010-08-14 08:02:54 +00:00
|
|
|
if (!model.empty())
|
2011-11-12 04:01:12 +00:00
|
|
|
objects.insertMesh(ptr, "meshes\\" + model);
|
2012-02-04 09:48:15 +00:00
|
|
|
|
|
|
|
const int color = ref->base->data.color;
|
|
|
|
const float r = ((color >> 0) & 0xFF) / 255.0f;
|
|
|
|
const float g = ((color >> 8) & 0xFF) / 255.0f;
|
|
|
|
const float b = ((color >> 16) & 0xFF) / 255.0f;
|
|
|
|
const float radius = float (ref->base->data.radius);
|
|
|
|
objects.insertLight (ptr, r, g, b, radius);
|
2011-11-12 04:01:12 +00:00
|
|
|
}
|
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
void Light::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
|
2011-11-12 04:01:12 +00:00
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Light> *ref =
|
2011-11-12 04:01:12 +00:00
|
|
|
ptr.get<ESM::Light>();
|
|
|
|
|
|
|
|
assert (ref->base != NULL);
|
2012-02-04 09:48:15 +00:00
|
|
|
const std::string &model = ref->base->model;
|
|
|
|
|
2011-11-12 04:01:12 +00:00
|
|
|
if(!model.empty()){
|
2011-11-18 00:38:52 +00:00
|
|
|
physics.insertObjectPhysics(ptr, "meshes\\" + model);
|
2010-08-14 08:02:54 +00:00
|
|
|
}
|
2010-08-14 09:39:32 +00:00
|
|
|
|
|
|
|
if (!ref->base->sound.empty())
|
|
|
|
{
|
2012-04-23 13:27:03 +00:00
|
|
|
MWBase::Environment::get().getSoundManager()->playSound3D (ptr, ref->base->sound, 1.0, 1.0, MWSound::Play_Loop);
|
2010-08-14 09:39:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-03 15:11:41 +00:00
|
|
|
std::string Light::getName (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Light> *ref =
|
2010-08-03 15:11:41 +00:00
|
|
|
ptr.get<ESM::Light>();
|
|
|
|
|
|
|
|
if (ref->base->model.empty())
|
|
|
|
return "";
|
|
|
|
|
|
|
|
return ref->base->name;
|
|
|
|
}
|
|
|
|
|
2010-08-07 18:25:17 +00:00
|
|
|
boost::shared_ptr<MWWorld::Action> Light::activate (const MWWorld::Ptr& ptr,
|
2012-04-23 13:27:03 +00:00
|
|
|
const MWWorld::Ptr& actor) const
|
2010-08-07 18:25:17 +00:00
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Light> *ref =
|
2010-08-07 18:25:17 +00:00
|
|
|
ptr.get<ESM::Light>();
|
|
|
|
|
|
|
|
if (!(ref->base->data.flags & ESM::Light::Carry))
|
|
|
|
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
|
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
MWBase::Environment::get().getSoundManager()->playSound3D (ptr, getUpSoundId(ptr), 1.0, 1.0, MWSound::Play_NoTrack);
|
2012-03-13 18:01:55 +00:00
|
|
|
|
2010-08-07 18:25:17 +00:00
|
|
|
return boost::shared_ptr<MWWorld::Action> (
|
|
|
|
new MWWorld::ActionTake (ptr));
|
|
|
|
}
|
|
|
|
|
2010-08-05 13:40:03 +00:00
|
|
|
std::string Light::getScript (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Light> *ref =
|
2010-08-05 13:40:03 +00:00
|
|
|
ptr.get<ESM::Light>();
|
|
|
|
|
|
|
|
return ref->base->script;
|
|
|
|
}
|
|
|
|
|
2012-03-13 14:35:06 +00:00
|
|
|
std::pair<std::vector<int>, bool> Light::getEquipmentSlots (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Light> *ref =
|
2012-03-13 14:35:06 +00:00
|
|
|
ptr.get<ESM::Light>();
|
|
|
|
|
|
|
|
std::vector<int> slots;
|
|
|
|
|
|
|
|
if (ref->base->data.flags & ESM::Light::Carry)
|
|
|
|
slots.push_back (int (MWWorld::InventoryStore::Slot_CarriedLeft));
|
|
|
|
|
|
|
|
return std::make_pair (slots, false);
|
|
|
|
}
|
|
|
|
|
2012-04-07 17:53:49 +00:00
|
|
|
int Light::getValue (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Light> *ref =
|
2012-04-07 17:53:49 +00:00
|
|
|
ptr.get<ESM::Light>();
|
|
|
|
|
|
|
|
return ref->base->data.value;
|
|
|
|
}
|
|
|
|
|
2010-08-03 13:24:44 +00:00
|
|
|
void Light::registerSelf()
|
|
|
|
{
|
|
|
|
boost::shared_ptr<Class> instance (new Light);
|
|
|
|
|
|
|
|
registerClass (typeid (ESM::Light).name(), instance);
|
|
|
|
}
|
2012-03-13 18:01:55 +00:00
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
std::string Light::getUpSoundId (const MWWorld::Ptr& ptr) const
|
2012-03-13 18:01:55 +00:00
|
|
|
{
|
|
|
|
return std::string("Item Misc Up");
|
|
|
|
}
|
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
std::string Light::getDownSoundId (const MWWorld::Ptr& ptr) const
|
2012-03-13 18:01:55 +00:00
|
|
|
{
|
|
|
|
return std::string("Item Misc Down");
|
|
|
|
}
|
2012-04-15 15:52:39 +00:00
|
|
|
|
2012-05-11 08:40:40 +00:00
|
|
|
|
2012-04-15 15:52:39 +00:00
|
|
|
std::string Light::getInventoryIcon (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Light> *ref =
|
2012-04-15 15:52:39 +00:00
|
|
|
ptr.get<ESM::Light>();
|
|
|
|
|
|
|
|
return ref->base->icon;
|
|
|
|
}
|
2012-05-11 08:40:40 +00:00
|
|
|
|
2012-04-16 20:58:16 +00:00
|
|
|
bool Light::hasToolTip (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Light> *ref =
|
2012-04-16 20:58:16 +00:00
|
|
|
ptr.get<ESM::Light>();
|
|
|
|
|
|
|
|
return (ref->base->name != "");
|
|
|
|
}
|
|
|
|
|
2012-04-24 00:02:03 +00:00
|
|
|
MWGui::ToolTipInfo Light::getToolTipInfo (const MWWorld::Ptr& ptr) const
|
2012-04-16 20:58:16 +00:00
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Light> *ref =
|
2012-04-16 20:58:16 +00:00
|
|
|
ptr.get<ESM::Light>();
|
|
|
|
|
|
|
|
MWGui::ToolTipInfo info;
|
2012-05-12 11:46:03 +00:00
|
|
|
info.caption = ref->base->name + MWGui::ToolTips::getCountString(ptr.getRefData().getCount());
|
2012-04-16 20:58:16 +00:00
|
|
|
info.icon = ref->base->icon;
|
|
|
|
|
2012-04-24 00:02:03 +00:00
|
|
|
const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
|
|
|
|
|
2012-04-16 20:58:16 +00:00
|
|
|
std::string text;
|
|
|
|
|
2012-04-24 00:02:03 +00:00
|
|
|
text += "\n" + store.gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight);
|
|
|
|
text += MWGui::ToolTips::getValueString(ref->base->data.value, store.gameSettings.search("sValue")->str);
|
2012-04-16 20:58:16 +00:00
|
|
|
|
2012-04-24 00:02:03 +00:00
|
|
|
if (MWBase::Environment::get().getWindowManager()->getFullHelp()) {
|
2012-04-16 20:58:16 +00:00
|
|
|
text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner");
|
|
|
|
text += MWGui::ToolTips::getMiscString(ref->base->script, "Script");
|
|
|
|
}
|
|
|
|
|
|
|
|
info.text = text;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
2012-06-04 19:48:20 +00:00
|
|
|
|
|
|
|
boost::shared_ptr<MWWorld::Action> Light::use (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getSoundManager()->playSound (getUpSoundId(ptr), 1.0, 1.0);
|
|
|
|
|
|
|
|
return boost::shared_ptr<MWWorld::Action>(new MWWorld::ActionEquip(ptr));
|
|
|
|
}
|
2010-08-03 13:24:44 +00:00
|
|
|
}
|