forked from teamnwah/openmw-tes3coop
actorid
commit
2236f69645
@ -1,6 +1,6 @@
|
||||
[submodule "libs/mangle"]
|
||||
path = libs/mangle
|
||||
url = git://github.com/korslund/mangle.git
|
||||
url = git://github.com/zinnschlag/mangle.git
|
||||
[submodule "libs/openengine"]
|
||||
path = libs/openengine
|
||||
url = git://github.com/korslund/OpenEngine
|
||||
url = git://github.com/zinnschlag/OpenEngine
|
||||
|
@ -1,412 +1,126 @@
|
||||
#include "layouts.hpp"
|
||||
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwmechanics/mechanicsmanager.hpp"
|
||||
#include "../mwgui/window_manager.hpp"
|
||||
#include "window_manager.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#undef min
|
||||
#undef max
|
||||
|
||||
using namespace MWGui;
|
||||
|
||||
const int StatsWindow::lineHeight = 18;
|
||||
|
||||
StatsWindow::StatsWindow (MWWorld::Environment& environment)
|
||||
: WindowBase("openmw_stats_window_layout.xml", environment)
|
||||
, lastPos(0)
|
||||
, reputation(0)
|
||||
, bounty(0)
|
||||
HUD::HUD(int width, int height, bool fpsSwitch)
|
||||
: Layout("openmw_hud_layout.xml")
|
||||
{
|
||||
setCoord(0,0,498, 342);
|
||||
setCoord(0,0, width, height);
|
||||
|
||||
const char *names[][2] =
|
||||
{
|
||||
{ "Attrib1", "sAttributeStrength" },
|
||||
{ "Attrib2", "sAttributeIntelligence" },
|
||||
{ "Attrib3", "sAttributeWillpower" },
|
||||
{ "Attrib4", "sAttributeAgility" },
|
||||
{ "Attrib5", "sAttributeSpeed" },
|
||||
{ "Attrib6", "sAttributeEndurance" },
|
||||
{ "Attrib7", "sAttributePersonality" },
|
||||
{ "Attrib8", "sAttributeLuck" },
|
||||
{ "Health_str", "sHealth" },
|
||||
{ "Magicka_str", "sMagic" },
|
||||
{ "Fatigue_str", "sFatigue" },
|
||||
{ "Level_str", "sLevel" },
|
||||
{ "Race_str", "sRace" },
|
||||
{ "Class_str", "sClass" },
|
||||
{ 0, 0 }
|
||||
};
|
||||
// Energy bars
|
||||
getWidget(health, "Health");
|
||||
getWidget(magicka, "Magicka");
|
||||
getWidget(stamina, "Stamina");
|
||||
|
||||
const ESMS::ESMStore &store = environment.mWorld->getStore();
|
||||
for (int i=0; names[i][0]; ++i)
|
||||
{
|
||||
setText (names[i][0], store.gameSettings.find (names[i][1])->str);
|
||||
}
|
||||
// Item and spell images and status bars
|
||||
getWidget(weapImage, "WeapImage");
|
||||
getWidget(weapStatus, "WeapStatus");
|
||||
getWidget(spellImage, "SpellImage");
|
||||
getWidget(spellStatus, "SpellStatus");
|
||||
|
||||
getWidget(skillAreaWidget, "Skills");
|
||||
getWidget(skillClientWidget, "SkillClient");
|
||||
getWidget(skillScrollerWidget, "SkillScroller");
|
||||
getWidget(effectBox, "EffectBox");
|
||||
getWidget(effect1, "Effect1");
|
||||
|
||||
skillScrollerWidget->eventScrollChangePosition = MyGUI::newDelegate(this, &StatsWindow::onScrollChangePosition);
|
||||
updateScroller();
|
||||
getWidget(minimap, "MiniMap");
|
||||
getWidget(compass, "Compass");
|
||||
|
||||
for (int i = 0; i < ESM::Skill::Length; ++i)
|
||||
{
|
||||
skillValues.insert(std::pair<int, MWMechanics::Stat<float> >(i, MWMechanics::Stat<float>()));
|
||||
skillWidgetMap.insert(std::pair<int, MyGUI::StaticTextPtr>(i, (MyGUI::StaticTextPtr) nullptr));
|
||||
}
|
||||
getWidget(crosshair, "Crosshair");
|
||||
|
||||
MyGUI::WindowPtr t = static_cast<MyGUI::WindowPtr>(mMainWidget);
|
||||
t->eventWindowChangeCoord = MyGUI::newDelegate(this, &StatsWindow::onWindowResize);
|
||||
}
|
||||
getWidget(fpsbox, "FPSBox");
|
||||
getWidget(fpscounter, "FPSCounter");
|
||||
|
||||
void StatsWindow::onScrollChangePosition(MyGUI::VScrollPtr scroller, size_t pos)
|
||||
{
|
||||
int diff = lastPos - pos;
|
||||
// Adjust position of all widget according to difference
|
||||
if (diff == 0)
|
||||
return;
|
||||
lastPos = pos;
|
||||
fpsbox->setVisible(fpsSwitch);
|
||||
|
||||
std::vector<MyGUI::WidgetPtr>::const_iterator end = skillWidgets.end();
|
||||
for (std::vector<MyGUI::WidgetPtr>::const_iterator it = skillWidgets.begin(); it != end; ++it)
|
||||
{
|
||||
(*it)->setCoord((*it)->getCoord() + MyGUI::IntPoint(0, diff));
|
||||
}
|
||||
}
|
||||
compass->setImageTexture("textures\\compass.dds");
|
||||
crosshair->setImageTexture("textures\\target.dds");
|
||||
|
||||
void StatsWindow::onWindowResize(MyGUI::WidgetPtr window)
|
||||
{
|
||||
updateScroller();
|
||||
// These are just demo values, you should replace these with
|
||||
// real calls from outside the class later.
|
||||
setWeapIcon("icons\\w\\tx_knife_iron.dds");
|
||||
setWeapStatus(90, 100);
|
||||
setSpellIcon("icons\\s\\b_tx_s_rstor_health.dds");
|
||||
setSpellStatus(65, 100);
|
||||
setEffect("icons\\s\\tx_s_chameleon.dds");
|
||||
}
|
||||
|
||||
void StatsWindow::setBar(const std::string& name, const std::string& tname, int val, int max)
|
||||
void HUD::setFPS(float fps)
|
||||
{
|
||||
MyGUI::ProgressPtr pt;
|
||||
getWidget(pt, name);
|
||||
pt->setProgressRange(max);
|
||||
pt->setProgressPosition(val);
|
||||
|
||||
std::stringstream out;
|
||||
out << val << "/" << max;
|
||||
setText(tname, out.str().c_str());
|
||||
fpscounter->setCaption(boost::lexical_cast<std::string>((int)fps));
|
||||
}
|
||||
|
||||
void StatsWindow::setPlayerName(const std::string& playerName)
|
||||
|
||||
void HUD::setStats(int h, int hmax, int m, int mmax, int s, int smax)
|
||||
{
|
||||
mMainWidget->setCaption(playerName);
|
||||
health->setProgressRange(hmax);
|
||||
health->setProgressPosition(h);
|
||||
magicka->setProgressRange(mmax);
|
||||
magicka->setProgressPosition(m);
|
||||
stamina->setProgressRange(smax);
|
||||
stamina->setProgressPosition(s);
|
||||
}
|
||||
|
||||
void StatsWindow::setStyledText(MyGUI::StaticTextPtr widget, ColorStyle style, const std::string &value)
|
||||
void HUD::setWeapIcon(const char *str)
|
||||
{
|
||||
widget->setCaption(value);
|
||||
if (style == CS_Super)
|
||||
widget->setTextColour(MyGUI::Colour(0, 1, 0));
|
||||
else if (style == CS_Sub)
|
||||
widget->setTextColour(MyGUI::Colour(1, 0, 0));
|
||||
else
|
||||
widget->setTextColour(MyGUI::Colour(1, 1, 1));
|
||||
weapImage->setImageTexture(str);
|
||||
}
|
||||
|
||||
void StatsWindow::setValue (const std::string& id, const MWMechanics::Stat<int>& value)
|
||||
void HUD::setSpellIcon(const char *str)
|
||||
{
|
||||
static const char *ids[] =
|
||||
{
|
||||
"AttribVal1", "AttribVal2", "AttribVal3", "AttribVal4", "AttribVal5",
|
||||
"AttribVal6", "AttribVal7", "AttribVal8",
|
||||
0
|
||||
};
|
||||
|
||||
for (int i=0; ids[i]; ++i)
|
||||
if (ids[i]==id)
|
||||
{
|
||||
std::ostringstream valueString;
|
||||
valueString << value.getModified();
|
||||
setText (id, valueString.str());
|
||||
|
||||
if (value.getModified()>value.getBase())
|
||||
setTextColor (id, 0, 1, 0);
|
||||
else if (value.getModified()<value.getBase())
|
||||
setTextColor (id, 1, 0, 0);
|
||||
else
|
||||
setTextColor (id, 1, 1, 1);
|
||||
|
||||
break;
|
||||
}
|
||||
spellImage->setImageTexture(str);
|
||||
}
|
||||
|
||||
void StatsWindow::setValue (const std::string& id, const MWMechanics::DynamicStat<int>& value)
|
||||
void HUD::setWeapStatus(int s, int smax)
|
||||
{
|
||||
static const char *ids[] =
|
||||
{
|
||||
"HBar", "MBar", "FBar",
|
||||
0
|
||||
};
|
||||
|
||||
for (int i=0; ids[i]; ++i)
|
||||
if (ids[i]==id)
|
||||
{
|
||||
std::string id (ids[i]);
|
||||
setBar (id, id + "T", value.getCurrent(), value.getModified());
|
||||
}
|
||||
weapStatus->setProgressRange(smax);
|
||||
weapStatus->setProgressPosition(s);
|
||||
}
|
||||
|
||||
void StatsWindow::setValue (const std::string& id, const std::string& value)
|
||||
void HUD::setSpellStatus(int s, int smax)
|
||||
{
|
||||
if (id=="name")
|
||||
setPlayerName (value);
|
||||
else if (id=="race")
|
||||
setText ("RaceText", value);
|
||||
else if (id=="class")
|
||||
setText ("ClassText", value);
|
||||
spellStatus->setProgressRange(smax);
|
||||
spellStatus->setProgressPosition(s);
|
||||
}
|
||||
|
||||
void StatsWindow::setValue (const std::string& id, int value)
|
||||
void HUD::setEffect(const char *img)
|
||||
{
|
||||
if (id=="level")
|
||||
{
|
||||
std::ostringstream text;
|
||||
text << value;
|
||||
setText("LevelText", text.str());
|
||||
}
|
||||
effect1->setImageTexture(img);
|
||||
}
|
||||
|
||||
void StatsWindow::setValue (const std::string& id, const MWMechanics::Stat<float>& value)
|
||||
void HUD::setValue(const std::string& id, const MWMechanics::DynamicStat<int>& value)
|
||||
{
|
||||
static struct {const char *id; ESM::Skill::SkillEnum skillId; } skillMap[] =
|
||||
static const char *ids[] =
|
||||
{
|
||||
{"SkillBlock", ESM::Skill::Block},
|
||||
{"SkillArmorer", ESM::Skill::Armorer},
|
||||
{"SkillMediumArmor", ESM::Skill::MediumArmor},
|
||||
{"SkillHeavyArmor", ESM::Skill::HeavyArmor},
|
||||
{"SkillBluntWeapon", ESM::Skill::BluntWeapon},
|
||||
{"SkillLongBlade", ESM::Skill::LongBlade},
|
||||
{"SkillAxe", ESM::Skill::Axe},
|
||||
{"SkillSpear", ESM::Skill::Spear},
|
||||
{"SkillAthletics", ESM::Skill::Athletics},
|
||||
{"SkillEnchant", ESM::Skill::Armorer},
|
||||
{"SkillDestruction", ESM::Skill::Destruction},
|
||||
{"SkillAlteration", ESM::Skill::Alteration},
|
||||
{"SkillIllusion", ESM::Skill::Illusion},
|
||||
{"SkillConjuration", ESM::Skill::Conjuration},
|
||||
{"SkillMysticism", ESM::Skill::Mysticism},
|
||||
{"SkillRestoration", ESM::Skill::Restoration},
|
||||
{"SkillAlchemy", ESM::Skill::Alchemy},
|
||||
{"SkillUnarmored", ESM::Skill::Unarmored},
|
||||
{"SkillSecurity", ESM::Skill::Security},
|
||||
{"SkillSneak", ESM::Skill::Sneak},
|
||||
{"SkillAcrobatics", ESM::Skill::Acrobatics},
|
||||
{"SkillLightArmor", ESM::Skill::LightArmor},
|
||||
{"SkillShortBlade", ESM::Skill::ShortBlade},
|
||||
{"SkillMarksman", ESM::Skill::Marksman},
|
||||
{"SkillMercantile", ESM::Skill::Mercantile},
|
||||
{"SkillSpeechcraft", ESM::Skill::Speechcraft},
|
||||
{"SkillHandToHand", ESM::Skill::HandToHand},
|
||||
"HBar", "MBar", "FBar", 0
|
||||
};
|
||||
for (size_t i = 0; i < sizeof(skillMap)/sizeof(skillMap[0]); ++i)
|
||||
{
|
||||
if (skillMap[i].id == id)
|
||||
|
||||
for (int i=0; ids[i]; ++i)
|
||||
if (ids[i]==id)
|
||||
{
|
||||
int skillId = skillMap[i].skillId;
|
||||
skillValues[skillId] = value;
|
||||
MyGUI::StaticTextPtr widget = skillWidgetMap[skillId];
|
||||
if (widget)
|
||||
switch (i)
|
||||
{
|
||||
float modified = value.getModified(), base = value.getBase();
|
||||
std::string text = boost::lexical_cast<std::string>(std::floor(modified));
|
||||
ColorStyle style = CS_Normal;
|
||||
if (modified > base)
|
||||
style = CS_Super;
|
||||
else if (modified < base)
|
||||
style = CS_Sub;
|
||||
|
||||
setStyledText(widget, style, text);
|
||||
case 0:
|
||||
health->setProgressRange (value.getModified());
|
||||
health->setProgressPosition (value.getCurrent());
|
||||
break;
|
||||
case 1:
|
||||
magicka->setProgressRange (value.getModified());
|
||||
magicka->setProgressPosition (value.getCurrent());
|
||||
break;
|
||||
case 2:
|
||||
stamina->setProgressRange (value.getModified());
|
||||
stamina->setProgressPosition (value.getCurrent());
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StatsWindow::configureSkills (const std::vector<int>& major, const std::vector<int>& minor)
|
||||
{
|
||||
majorSkills = major;
|
||||
minorSkills = minor;
|
||||
|
||||
// Update misc skills with the remaining skills not in major or minor
|
||||
std::set<int> skillSet;
|
||||
std::copy(major.begin(), major.end(), std::inserter(skillSet, skillSet.begin()));
|
||||
std::copy(minor.begin(), minor.end(), std::inserter(skillSet, skillSet.begin()));
|
||||
boost::array<ESM::Skill::SkillEnum, ESM::Skill::Length>::const_iterator end = ESM::Skill::skillIds.end();
|
||||
miscSkills.clear();
|
||||
for (boost::array<ESM::Skill::SkillEnum, ESM::Skill::Length>::const_iterator it = ESM::Skill::skillIds.begin(); it != end; ++it)
|
||||
{
|
||||
int skill = *it;
|
||||
if (skillSet.find(skill) == skillSet.end())
|
||||
miscSkills.push_back(skill);
|
||||
}
|
||||
}
|
||||
|
||||
void StatsWindow::setFactions (const std::vector<Faction>& factions)
|
||||
{
|
||||
this->factions = factions;
|
||||
}
|
||||
|
||||
void StatsWindow::setBirthSign (const std::string& signId)
|
||||
{
|
||||
birthSignId = signId;
|
||||
}
|
||||
|
||||
void StatsWindow::addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2)
|
||||
{
|
||||
MyGUI::StaticImagePtr separator = skillClientWidget->createWidget<MyGUI::StaticImage>("MW_HLine", MyGUI::IntCoord(10, coord1.top, coord1.width + coord2.width - 4, 18), MyGUI::Align::Default);
|
||||
skillWidgets.push_back(separator);
|
||||
|
||||
coord1.top += separator->getHeight();
|
||||
coord2.top += separator->getHeight();
|
||||
}
|
||||
|
||||
void StatsWindow::addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2)
|
||||
{
|
||||
MyGUI::StaticTextPtr groupWidget = skillClientWidget->createWidget<MyGUI::StaticText>("SandBrightText", MyGUI::IntCoord(0, coord1.top, coord1.width + coord2.width, coord1.height), MyGUI::Align::Default);
|
||||
groupWidget->setCaption(label);
|
||||
skillWidgets.push_back(groupWidget);
|
||||
|
||||
coord1.top += lineHeight;
|
||||
coord2.top += lineHeight;
|
||||
}
|
||||
|
||||
MyGUI::StaticTextPtr StatsWindow::addValueItem(const std::string text, const std::string &value, ColorStyle style, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2)
|
||||
{
|
||||
MyGUI::StaticTextPtr skillNameWidget, skillValueWidget;
|
||||
|
||||
skillNameWidget = skillClientWidget->createWidget<MyGUI::StaticText>("SandText", coord1, MyGUI::Align::Default);
|
||||
skillNameWidget->setCaption(text);
|
||||
|
||||
skillValueWidget = skillClientWidget->createWidget<MyGUI::StaticText>("SandTextRight", coord2, MyGUI::Align::Default);
|
||||
setStyledText(skillValueWidget, style, value);
|
||||
|
||||
skillWidgets.push_back(skillNameWidget);
|
||||
skillWidgets.push_back(skillValueWidget);
|
||||
|
||||
coord1.top += lineHeight;
|
||||
coord2.top += lineHeight;
|
||||
|
||||
return skillValueWidget;
|
||||
}
|
||||
|
||||
void StatsWindow::addItem(const std::string text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2)
|
||||
{
|
||||
MyGUI::StaticTextPtr skillNameWidget;
|
||||
|
||||
skillNameWidget = skillClientWidget->createWidget<MyGUI::StaticText>("SandText", coord1 + MyGUI::IntSize(coord2.width, 0), MyGUI::Align::Default);
|
||||
skillNameWidget->setCaption(text);
|
||||
|
||||
skillWidgets.push_back(skillNameWidget);
|
||||
|
||||
coord1.top += lineHeight;
|
||||
coord2.top += lineHeight;
|
||||
}
|
||||
|
||||
void StatsWindow::addSkills(const SkillList &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2)
|
||||
{
|
||||
WindowManager *wm = environment.mWindowManager;
|
||||
|
||||
// Add a line separator if there are items above
|
||||
if (!skillWidgets.empty())
|
||||
{
|
||||
addSeparator(coord1, coord2);
|
||||
}
|
||||
|
||||
addGroup(wm->getGameSettingString(titleId, titleDefault), coord1, coord2);
|
||||
|
||||
SkillList::const_iterator end = skills.end();
|
||||
for (SkillList::const_iterator it = skills.begin(); it != end; ++it)
|
||||
{
|
||||
int skillId = *it;
|
||||
if (skillId < 0 || skillId > ESM::Skill::Length) // Skip unknown skill indexes
|
||||
continue;
|
||||
assert(skillId >= 0 && skillId < ESM::Skill::Length);
|
||||
const std::string &skillNameId = ESMS::Skill::sSkillNameIds[skillId];
|
||||
const MWMechanics::Stat<float> &stat = skillValues.find(skillId)->second;
|
||||
float base = stat.getBase();
|
||||
float modified = stat.getModified();
|
||||
|
||||
ColorStyle style = CS_Normal;
|
||||
if (modified > base)
|
||||
style = CS_Super;
|
||||
else if (modified < base)
|
||||
style = CS_Sub;
|
||||
MyGUI::StaticTextPtr widget = addValueItem(wm->getGameSettingString(skillNameId, skillNameId), boost::lexical_cast<std::string>(static_cast<int>(modified)), style, coord1, coord2);
|
||||
skillWidgetMap[skillId] = widget;
|
||||
}
|
||||
}
|
||||
|
||||
void StatsWindow::updateSkillArea()
|
||||
{
|
||||
for (std::vector<MyGUI::WidgetPtr>::iterator it = skillWidgets.begin(); it != skillWidgets.end(); ++it)
|
||||
{
|
||||
MyGUI::Gui::getInstance().destroyWidget(*it);
|
||||
}
|
||||
skillWidgets.clear();
|
||||
|
||||
const int valueSize = 40;
|
||||
MyGUI::IntCoord coord1(10, 0, skillClientWidget->getWidth() - (10 + valueSize), 18);
|
||||
MyGUI::IntCoord coord2(coord1.left + coord1.width, coord1.top, valueSize, coord1.height);
|
||||
|
||||
if (!majorSkills.empty())
|
||||
addSkills(majorSkills, "sSkillClassMajor", "Major Skills", coord1, coord2);
|
||||
|
||||
if (!minorSkills.empty())
|
||||
addSkills(minorSkills, "sSkillClassMinor", "Minor Skills", coord1, coord2);
|
||||
|
||||
if (!miscSkills.empty())
|
||||
addSkills(miscSkills, "sSkillClassMisc", "Misc Skills", coord1, coord2);
|
||||
|
||||
WindowManager *wm = environment.mWindowManager;
|
||||
ESMS::ESMStore &store = environment.mWorld->getStore();
|
||||
|
||||
if (!factions.empty())
|
||||
{
|
||||
// Add a line separator if there are items above
|
||||
if (!skillWidgets.empty())
|
||||
addSeparator(coord1, coord2);
|
||||
|
||||
addGroup(wm->getGameSettingString("sFaction", "Faction"), coord1, coord2);
|
||||
FactionList::const_iterator end = factions.end();
|
||||
for (FactionList::const_iterator it = factions.begin(); it != end; ++it)
|
||||
{
|
||||
const ESM::Faction *faction = store.factions.find(it->first);
|
||||
addItem(faction->name, coord1, coord2);
|
||||
// TODO: Faction rank should be placed in tooltip
|
||||
}
|
||||
}
|
||||
|
||||
if (!birthSignId.empty())
|
||||
{
|
||||
// Add a line separator if there are items above
|
||||
if (!skillWidgets.empty())
|
||||
addSeparator(coord1, coord2);
|
||||
|
||||
addGroup(wm->getGameSettingString("sSign", "Sign"), coord1, coord2);
|
||||
const ESM::BirthSign *sign = store.birthSigns.find(birthSignId);
|
||||
addItem(sign->name, coord1, coord2);
|
||||
}
|
||||
|
||||
// Add a line separator if there are items above
|
||||
if (!skillWidgets.empty())
|
||||
addSeparator(coord1, coord2);
|
||||
|
||||
addValueItem(wm->getGameSettingString("sReputation", "Reputation"), boost::lexical_cast<std::string>(static_cast<int>(reputation)), CS_Normal, coord1, coord2);
|
||||
addValueItem(wm->getGameSettingString("sBounty", "Bounty"), boost::lexical_cast<std::string>(static_cast<int>(bounty)), CS_Normal, coord1, coord2);
|
||||
|
||||
clientHeight = coord1.top;
|
||||
updateScroller();
|
||||
}
|
||||
|
||||
void StatsWindow::updateScroller()
|
||||
{
|
||||
skillScrollerWidget->setScrollRange(std::max(clientHeight - skillClientWidget->getHeight(), 0));
|
||||
skillScrollerWidget->setScrollPage(std::max(skillClientWidget->getHeight() - lineHeight, 0));
|
||||
}
|
||||
|
@ -0,0 +1,370 @@
|
||||
#include "stats_window.hpp"
|
||||
|
||||
#include "../mwmechanics/mechanicsmanager.hpp"
|
||||
#include "window_manager.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
using namespace MWGui;
|
||||
const int StatsWindow::lineHeight = 18;
|
||||
|
||||
StatsWindow::StatsWindow (WindowManager& parWindowManager)
|
||||
: WindowBase("openmw_stats_window_layout.xml", parWindowManager)
|
||||
, lastPos(0)
|
||||
, reputation(0)
|
||||
, bounty(0)
|
||||
{
|
||||
setCoord(0,0,498, 342);
|
||||
|
||||
const char *names[][2] =
|
||||
{
|
||||
{ "Attrib1", "sAttributeStrength" },
|
||||
{ "Attrib2", "sAttributeIntelligence" },
|
||||
{ "Attrib3", "sAttributeWillpower" },
|
||||
{ "Attrib4", "sAttributeAgility" },
|
||||
{ "Attrib5", "sAttributeSpeed" },
|
||||
{ "Attrib6", "sAttributeEndurance" },
|
||||
{ "Attrib7", "sAttributePersonality" },
|
||||
{ "Attrib8", "sAttributeLuck" },
|
||||
{ "Health_str", "sHealth" },
|
||||
{ "Magicka_str", "sMagic" },
|
||||
{ "Fatigue_str", "sFatigue" },
|
||||
{ "Level_str", "sLevel" },
|
||||
{ "Race_str", "sRace" },
|
||||
{ "Class_str", "sClass" },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
const ESMS::ESMStore &store = mWindowManager.getStore();
|
||||
for (int i=0; names[i][0]; ++i)
|
||||
{
|
||||
setText (names[i][0], store.gameSettings.find (names[i][1])->str);
|
||||
}
|
||||
|
||||
getWidget(skillAreaWidget, "Skills");
|
||||
getWidget(skillClientWidget, "SkillClient");
|
||||
getWidget(skillScrollerWidget, "SkillScroller");
|
||||
|
||||
skillScrollerWidget->eventScrollChangePosition = MyGUI::newDelegate(this, &StatsWindow::onScrollChangePosition);
|
||||
updateScroller();
|
||||
|
||||
for (int i = 0; i < ESM::Skill::Length; ++i)
|
||||
{
|
||||
skillValues.insert(std::pair<int, MWMechanics::Stat<float> >(i, MWMechanics::Stat<float>()));
|
||||
skillWidgetMap.insert(std::pair<int, MyGUI::StaticTextPtr>(i, nullptr));
|
||||
}
|
||||
|
||||
MyGUI::WindowPtr t = static_cast<MyGUI::WindowPtr>(mMainWidget);
|
||||
t->eventWindowChangeCoord = MyGUI::newDelegate(this, &StatsWindow::onWindowResize);
|
||||
}
|
||||
|
||||
void StatsWindow::onScrollChangePosition(MyGUI::VScrollPtr scroller, size_t pos)
|
||||
{
|
||||
int diff = lastPos - pos;
|
||||
// Adjust position of all widget according to difference
|
||||
if (diff == 0)
|
||||
return;
|
||||
lastPos = pos;
|
||||
|
||||
std::vector<MyGUI::WidgetPtr>::const_iterator end = skillWidgets.end();
|
||||
for (std::vector<MyGUI::WidgetPtr>::const_iterator it = skillWidgets.begin(); it != end; ++it)
|
||||
{
|
||||
(*it)->setCoord((*it)->getCoord() + MyGUI::IntPoint(0, diff));
|
||||
}
|
||||
}
|
||||
|
||||
void StatsWindow::onWindowResize(MyGUI::Window* window)
|
||||
{
|
||||
updateScroller();
|
||||
}
|
||||
|
||||
void StatsWindow::setBar(const std::string& name, const std::string& tname, int val, int max)
|
||||
{
|
||||
MyGUI::ProgressPtr pt;
|
||||
getWidget(pt, name);
|
||||
pt->setProgressRange(max);
|
||||
pt->setProgressPosition(val);
|
||||
|
||||
std::stringstream out;
|
||||
out << val << "/" << max;
|
||||
setText(tname, out.str().c_str());
|
||||
}
|
||||
|
||||
void StatsWindow::setPlayerName(const std::string& playerName)
|
||||
{
|
||||
mMainWidget->setCaption(playerName);
|
||||
}
|
||||
|
||||
void StatsWindow::setStyledText(MyGUI::StaticTextPtr widget, ColorStyle style, const std::string &value)
|
||||
{
|
||||
widget->setCaption(value);
|
||||
if (style == CS_Super)
|
||||
widget->setTextColour(MyGUI::Colour(0, 1, 0));
|
||||
else if (style == CS_Sub)
|
||||
widget->setTextColour(MyGUI::Colour(1, 0, 0));
|
||||
else
|
||||
widget->setTextColour(MyGUI::Colour(1, 1, 1));
|
||||
}
|
||||
|
||||
void StatsWindow::setValue (const std::string& id, const MWMechanics::Stat<int>& value)
|
||||
{
|
||||
static const char *ids[] =
|
||||
{
|
||||
"AttribVal1", "AttribVal2", "AttribVal3", "AttribVal4", "AttribVal5",
|
||||
"AttribVal6", "AttribVal7", "AttribVal8",
|
||||
0
|
||||
};
|
||||
|
||||
for (int i=0; ids[i]; ++i)
|
||||
if (ids[i]==id)
|
||||
{
|
||||
std::ostringstream valueString;
|
||||
valueString << value.getModified();
|
||||
setText (id, valueString.str());
|
||||
|
||||
if (value.getModified()>value.getBase())
|
||||
setTextColor (id, 0, 1, 0);
|
||||
else if (value.getModified()<value.getBase())
|
||||
setTextColor (id, 1, 0, 0);
|
||||
else
|
||||
setTextColor (id, 1, 1, 1);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void StatsWindow::setValue (const std::string& id, const MWMechanics::DynamicStat<int>& value)
|
||||
{
|
||||
static const char *ids[] =
|
||||
{
|
||||
"HBar", "MBar", "FBar",
|
||||
0
|
||||
};
|
||||
|
||||
for (int i=0; ids[i]; ++i)
|
||||
if (ids[i]==id)
|
||||
{
|
||||
std::string id (ids[i]);
|
||||
setBar (id, id + "T", value.getCurrent(), value.getModified());
|
||||
}
|
||||
}
|
||||
|
||||
void StatsWindow::setValue (const std::string& id, const std::string& value)
|
||||
{
|
||||
if (id=="name")
|
||||
setPlayerName (value);
|
||||
else if (id=="race")
|
||||
setText ("RaceText", value);
|
||||
else if (id=="class")
|
||||
setText ("ClassText", value);
|
||||
}
|
||||
|
||||
void StatsWindow::setValue (const std::string& id, int value)
|
||||
{
|
||||
if (id=="level")
|
||||
{
|
||||
std::ostringstream text;
|
||||
text << value;
|
||||
setText("LevelText", text.str());
|
||||
}
|
||||
}
|
||||
|
||||
void StatsWindow::setValue(const ESM::Skill::SkillEnum parSkill, const MWMechanics::Stat<float>& value)
|
||||
{
|
||||
skillValues[parSkill] = value;
|
||||
MyGUI::StaticTextPtr widget = skillWidgetMap[(int)parSkill];
|
||||
if (widget)
|
||||
{
|
||||
float modified = value.getModified(), base = value.getBase();
|
||||
std::string text = boost::lexical_cast<std::string>(std::floor(modified));
|
||||
ColorStyle style = CS_Normal;
|
||||
if (modified > base)
|
||||
style = CS_Super;
|
||||
else if (modified < base)
|
||||
style = CS_Sub;
|
||||
|
||||
setStyledText(widget, style, text);
|
||||
}
|
||||
}
|
||||
|
||||
void StatsWindow::configureSkills (const std::vector<int>& major, const std::vector<int>& minor)
|
||||
{
|
||||
majorSkills = major;
|
||||
minorSkills = minor;
|
||||
|
||||
// Update misc skills with the remaining skills not in major or minor
|
||||
std::set<int> skillSet;
|
||||
std::copy(major.begin(), major.end(), std::inserter(skillSet, skillSet.begin()));
|
||||
std::copy(minor.begin(), minor.end(), std::inserter(skillSet, skillSet.begin()));
|
||||
boost::array<ESM::Skill::SkillEnum, ESM::Skill::Length>::const_iterator end = ESM::Skill::skillIds.end();
|
||||
miscSkills.clear();
|
||||
for (boost::array<ESM::Skill::SkillEnum, ESM::Skill::Length>::const_iterator it = ESM::Skill::skillIds.begin(); it != end; ++it)
|
||||
{
|
||||
int skill = *it;
|
||||
if (skillSet.find(skill) == skillSet.end())
|
||||
miscSkills.push_back(skill);
|
||||
}
|
||||
}
|
||||
|
||||
void StatsWindow::setFactions (const std::vector<Faction>& factions)
|
||||
{
|
||||
this->factions = factions;
|
||||
}
|
||||
|
||||
void StatsWindow::setBirthSign (const std::string& signId)
|
||||
{
|
||||
birthSignId = signId;
|
||||
}
|
||||
|
||||
void StatsWindow::addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2)
|
||||
{
|
||||
MyGUI::StaticImagePtr separator = skillClientWidget->createWidget<MyGUI::StaticImage>("MW_HLine", MyGUI::IntCoord(10, coord1.top, coord1.width + coord2.width - 4, 18), MyGUI::Align::Default);
|
||||
skillWidgets.push_back(separator);
|
||||
|
||||
coord1.top += separator->getHeight();
|
||||
coord2.top += separator->getHeight();
|
||||
}
|
||||
|
||||
void StatsWindow::addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2)
|
||||
{
|
||||
MyGUI::StaticTextPtr groupWidget = skillClientWidget->createWidget<MyGUI::StaticText>("SandBrightText", MyGUI::IntCoord(0, coord1.top, coord1.width + coord2.width, coord1.height), MyGUI::Align::Default);
|
||||
groupWidget->setCaption(label);
|
||||
skillWidgets.push_back(groupWidget);
|
||||
|
||||
coord1.top += lineHeight;
|
||||
coord2.top += lineHeight;
|
||||
}
|
||||
|
||||
MyGUI::StaticTextPtr StatsWindow::addValueItem(const std::string text, const std::string &value, ColorStyle style, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2)
|
||||
{
|
||||
MyGUI::StaticTextPtr skillNameWidget, skillValueWidget;
|
||||
|
||||
skillNameWidget = skillClientWidget->createWidget<MyGUI::StaticText>("SandText", coord1, MyGUI::Align::Default);
|
||||
skillNameWidget->setCaption(text);
|
||||
|
||||
skillValueWidget = skillClientWidget->createWidget<MyGUI::StaticText>("SandTextRight", coord2, MyGUI::Align::Default);
|
||||
setStyledText(skillValueWidget, style, value);
|
||||
|
||||
skillWidgets.push_back(skillNameWidget);
|
||||
skillWidgets.push_back(skillValueWidget);
|
||||
|
||||
coord1.top += lineHeight;
|
||||
coord2.top += lineHeight;
|
||||
|
||||
return skillValueWidget;
|
||||
}
|
||||
|
||||
void StatsWindow::addItem(const std::string text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2)
|
||||
{
|
||||
MyGUI::StaticTextPtr skillNameWidget;
|
||||
|
||||
skillNameWidget = skillClientWidget->createWidget<MyGUI::StaticText>("SandText", coord1 + MyGUI::IntSize(coord2.width, 0), MyGUI::Align::Default);
|
||||
skillNameWidget->setCaption(text);
|
||||
|
||||
skillWidgets.push_back(skillNameWidget);
|
||||
|
||||
coord1.top += lineHeight;
|
||||
coord2.top += lineHeight;
|
||||
}
|
||||
|
||||
void StatsWindow::addSkills(const SkillList &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2)
|
||||
{
|
||||
// Add a line separator if there are items above
|
||||
if (!skillWidgets.empty())
|
||||
{
|
||||
addSeparator(coord1, coord2);
|
||||
}
|
||||
|
||||
addGroup(mWindowManager.getGameSettingString(titleId, titleDefault), coord1, coord2);
|
||||
|
||||
SkillList::const_iterator end = skills.end();
|
||||
for (SkillList::const_iterator it = skills.begin(); it != end; ++it)
|
||||
{
|
||||
int skillId = *it;
|
||||
if (skillId < 0 || skillId > ESM::Skill::Length) // Skip unknown skill indexes
|
||||
continue;
|
||||
assert(skillId >= 0 && skillId < ESM::Skill::Length);
|
||||
const std::string &skillNameId = ESMS::Skill::sSkillNameIds[skillId];
|
||||
const MWMechanics::Stat<float> &stat = skillValues.find(skillId)->second;
|
||||
float base = stat.getBase();
|
||||
float modified = stat.getModified();
|
||||
|
||||
ColorStyle style = CS_Normal;
|
||||
if (modified > base)
|
||||
style = CS_Super;
|
||||
else if (modified < base)
|
||||
style = CS_Sub;
|
||||
MyGUI::StaticTextPtr widget = addValueItem(mWindowManager.getGameSettingString(skillNameId, skillNameId), boost::lexical_cast<std::string>(static_cast<int>(modified)), style, coord1, coord2);
|
||||
skillWidgetMap[skillId] = widget;
|
||||
}
|
||||
}
|
||||
|
||||
void StatsWindow::updateSkillArea()
|
||||
{
|
||||
for (std::vector<MyGUI::WidgetPtr>::iterator it = skillWidgets.begin(); it != skillWidgets.end(); ++it)
|
||||
{
|
||||
MyGUI::Gui::getInstance().destroyWidget(*it);
|
||||
}
|
||||
skillWidgets.clear();
|
||||
|
||||
const int valueSize = 40;
|
||||
MyGUI::IntCoord coord1(10, 0, skillClientWidget->getWidth() - (10 + valueSize), 18);
|
||||
MyGUI::IntCoord coord2(coord1.left + coord1.width, coord1.top, valueSize, coord1.height);
|
||||
|
||||
if (!majorSkills.empty())
|
||||
addSkills(majorSkills, "sSkillClassMajor", "Major Skills", coord1, coord2);
|
||||
|
||||
if (!minorSkills.empty())
|
||||
addSkills(minorSkills, "sSkillClassMinor", "Minor Skills", coord1, coord2);
|
||||
|
||||
if (!miscSkills.empty())
|
||||
addSkills(miscSkills, "sSkillClassMisc", "Misc Skills", coord1, coord2);
|
||||
|
||||
ESMS::ESMStore &store = mWindowManager.getStore();
|
||||
|
||||
if (!factions.empty())
|
||||
{
|
||||
// Add a line separator if there are items above
|
||||
if (!skillWidgets.empty())
|
||||
addSeparator(coord1, coord2);
|
||||
|
||||
addGroup(mWindowManager.getGameSettingString("sFaction", "Faction"), coord1, coord2);
|
||||
FactionList::const_iterator end = factions.end();
|
||||
for (FactionList::const_iterator it = factions.begin(); it != end; ++it)
|
||||
{
|
||||
const ESM::Faction *faction = store.factions.find(it->first);
|
||||
addItem(faction->name, coord1, coord2);
|
||||
// TODO: Faction rank should be placed in tooltip
|
||||
}
|
||||
}
|
||||
|
||||
if (!birthSignId.empty())
|
||||
{
|
||||
// Add a line separator if there are items above
|
||||
if (!skillWidgets.empty())
|
||||
addSeparator(coord1, coord2);
|
||||
|
||||
addGroup(mWindowManager.getGameSettingString("sSign", "Sign"), coord1, coord2);
|
||||
const ESM::BirthSign *sign = store.birthSigns.find(birthSignId);
|
||||
addItem(sign->name, coord1, coord2);
|
||||
}
|
||||
|
||||
// Add a line separator if there are items above
|
||||
if (!skillWidgets.empty())
|
||||
addSeparator(coord1, coord2);
|
||||
|
||||
addValueItem(mWindowManager.getGameSettingString("sReputation", "Reputation"), boost::lexical_cast<std::string>(static_cast<int>(reputation)), CS_Normal, coord1, coord2);
|
||||
addValueItem(mWindowManager.getGameSettingString("sBounty", "Bounty"), boost::lexical_cast<std::string>(static_cast<int>(bounty)), CS_Normal, coord1, coord2);
|
||||
|
||||
clientHeight = coord1.top;
|
||||
updateScroller();
|
||||
}
|
||||
|
||||
void StatsWindow::updateScroller()
|
||||
{
|
||||
skillScrollerWidget->setScrollRange(std::max(clientHeight - skillClientWidget->getHeight(), 0));
|
||||
skillScrollerWidget->setScrollPage(std::max(skillClientWidget->getHeight() - lineHeight, 0));
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
#ifndef MWGUI_STATS_WINDOW_H
|
||||
#define MWGUI_STATS_WINDOW_H
|
||||
|
||||
#include <components/esm_store/store.hpp>
|
||||
|
||||
#include <sstream>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "../mwmechanics/stat.hpp"
|
||||
#include "window_base.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
class WindowManager;
|
||||
|
||||
class StatsWindow : public WindowBase
|
||||
{
|
||||
public:
|
||||
typedef std::pair<std::string, int> Faction;
|
||||
typedef std::vector<Faction> FactionList;
|
||||
|
||||
typedef std::vector<int> SkillList;
|
||||
|
||||
StatsWindow(WindowManager& parWindowManager);
|
||||
|
||||
void setBar(const std::string& name, const std::string& tname, int val, int max);
|
||||
void setPlayerName(const std::string& playerName);
|
||||
|
||||
/// Set value for the given ID.
|
||||
void setValue (const std::string& id, const MWMechanics::Stat<int>& value);
|
||||
void setValue (const std::string& id, const MWMechanics::DynamicStat<int>& value);
|
||||
void setValue (const std::string& id, const std::string& value);
|
||||
void setValue (const std::string& id, int value);
|
||||
void setValue(const ESM::Skill::SkillEnum parSkill, const MWMechanics::Stat<float>& value);
|
||||
|
||||
void configureSkills (const SkillList& major, const SkillList& minor);
|
||||
void setFactions (const std::vector<Faction>& factions);
|
||||
void setBirthSign (const std::string &signId);
|
||||
void setReputation (int reputation) { this->reputation = reputation; }
|
||||
void setBounty (int bounty) { this->bounty = bounty; }
|
||||
void updateSkillArea();
|
||||
|
||||
private:
|
||||
enum ColorStyle
|
||||
{
|
||||
CS_Sub,
|
||||
CS_Normal,
|
||||
CS_Super
|
||||
};
|
||||
void setStyledText(MyGUI::StaticTextPtr widget, ColorStyle style, const std::string &value);
|
||||
void addSkills(const SkillList &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
|
||||
void addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
|
||||
void addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
|
||||
MyGUI::StaticTextPtr addValueItem(const std::string text, const std::string &value, ColorStyle style, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
|
||||
void addItem(const std::string text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
|
||||
void updateScroller();
|
||||
|
||||
void onScrollChangePosition(MyGUI::VScrollPtr scroller, size_t pos);
|
||||
void onWindowResize(MyGUI::Window* window);
|
||||
|
||||
static const int lineHeight;
|
||||
|
||||
MyGUI::WidgetPtr skillAreaWidget, skillClientWidget;
|
||||
MyGUI::VScrollPtr skillScrollerWidget;
|
||||
int lastPos, clientHeight;
|
||||
|
||||
SkillList majorSkills, minorSkills, miscSkills;
|
||||
std::map<int, MWMechanics::Stat<float> > skillValues;
|
||||
std::map<int, MyGUI::StaticTextPtr> skillWidgetMap;
|
||||
std::map<std::string, MyGUI::WidgetPtr> factionWidgetMap;
|
||||
FactionList factions; ///< Stores a list of factions and the current rank
|
||||
std::string birthSignId;
|
||||
int reputation, bounty;
|
||||
std::vector<MyGUI::WidgetPtr> skillWidgets; //< Skills and other information
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
@ -0,0 +1,16 @@
|
||||
#ifndef GAME_MWMECHANICS_MOVEMENT_H
|
||||
#define GAME_MWMECHANICS_MOVEMENT_H
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
/// Desired movement for an actor
|
||||
struct Movement
|
||||
{
|
||||
signed char mLeftRight; // 1: wants to move left, -1: wants to move right
|
||||
signed char mForwardBackward; // 1:wants to move forward, -1: wants to move backward
|
||||
|
||||
Movement() : mLeftRight (0), mForwardBackward (0) {}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,9 @@
|
||||
|
||||
#include "player.hpp"
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
Player::Player (Ogre::Camera *camera, const std::string& handle)
|
||||
: mCamera (camera), mHandle (handle)
|
||||
{}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
#ifndef GAME_MWRENDER_PLAYER_H
|
||||
#define GAME_MWRENDER_PLAYER_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class Camera;
|
||||
}
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
/// \brief Player character rendering and camera control
|
||||
class Player
|
||||
{
|
||||
Ogre::Camera *mCamera;
|
||||
std::string mHandle;
|
||||
|
||||
public:
|
||||
|
||||
Player (Ogre::Camera *camera, const std::string& handle);
|
||||
|
||||
Ogre::Camera *getCamera() { return mCamera; }
|
||||
|
||||
std::string getHandle() const { return mHandle; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,41 +0,0 @@
|
||||
|
||||
#include "playerpos.hpp"
|
||||
|
||||
#include "../mwworld/world.hpp"
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
PlayerPos::PlayerPos (Ogre::Camera *cam, const ESM::NPC *player, MWWorld::World& world) :
|
||||
mCellStore (0), camera(cam), mWorld (world), mClass (0)
|
||||
{
|
||||
mPlayer.base = player;
|
||||
mName = player->name;
|
||||
mMale = !(player->flags & ESM::NPC::Female);
|
||||
mRace = player->race;
|
||||
mPlayer.ref.pos.pos[0] = mPlayer.ref.pos.pos[1] = mPlayer.ref.pos.pos[2] = 0;
|
||||
mClass = new ESM::Class (*world.getStore().classes.find (player->cls));
|
||||
}
|
||||
|
||||
PlayerPos::~PlayerPos()
|
||||
{
|
||||
delete mClass;
|
||||
}
|
||||
|
||||
void PlayerPos::setPos(float x, float y, float z, bool updateCamera)
|
||||
{
|
||||
mWorld.moveObject (getPlayer(), x, y, z);
|
||||
|
||||
if (updateCamera)
|
||||
camera->setPosition (Ogre::Vector3 (
|
||||
mPlayer.ref.pos.pos[0],
|
||||
mPlayer.ref.pos.pos[2],
|
||||
-mPlayer.ref.pos.pos[1]));
|
||||
}
|
||||
|
||||
void PlayerPos::setClass (const ESM::Class& class_)
|
||||
{
|
||||
ESM::Class *new_class = new ESM::Class (class_);
|
||||
delete mClass;
|
||||
mClass = new_class;
|
||||
}
|
||||
}
|
@ -1,128 +0,0 @@
|
||||
#ifndef _MWRENDER_PLAYERPOS_H
|
||||
#define _MWRENDER_PLAYERPOS_H
|
||||
|
||||
#include "OgreCamera.h"
|
||||
|
||||
#include <components/esm_store/cell_store.hpp>
|
||||
|
||||
#include "../mwworld/refdata.hpp"
|
||||
#include "../mwworld/ptr.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class World;
|
||||
}
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
// This class keeps track of the player position. It takes care of
|
||||
// camera movement, sound listener updates, and collision handling
|
||||
// (to be done).
|
||||
class PlayerPos
|
||||
{
|
||||
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> mPlayer;
|
||||
MWWorld::Ptr::CellStore *mCellStore;
|
||||
Ogre::Camera *camera;
|
||||
MWWorld::World& mWorld;
|
||||
std::string mName;
|
||||
bool mMale;
|
||||
std::string mRace;
|
||||
std::string mBirthsign;
|
||||
ESM::Class *mClass;
|
||||
|
||||
public:
|
||||
|
||||
PlayerPos(Ogre::Camera *cam, const ESM::NPC *player, MWWorld::World& world);
|
||||
|
||||
~PlayerPos();
|
||||
|
||||
// Set the player position. Uses Morrowind coordinates.
|
||||
void setPos(float _x, float _y, float _z, bool updateCamera = false);
|
||||
|
||||
void setCell (MWWorld::Ptr::CellStore *cellStore)
|
||||
{
|
||||
mCellStore = cellStore;
|
||||
}
|
||||
|
||||
Ogre::Camera *getCamera() { return camera; }
|
||||
|
||||
// Move the player relative to her own position and
|
||||
// orientation. After the call, the new position is returned.
|
||||
void moveRel(float &relX, float &relY, float &relZ)
|
||||
{
|
||||
using namespace Ogre;
|
||||
|
||||
// Move camera relative to its own direction
|
||||
camera->moveRelative(Vector3(relX,0,relZ));
|
||||
|
||||
// Up/down movement is always done relative the world axis.
|
||||
camera->move(Vector3(0,relY,0));
|
||||
|
||||
// Get new camera position, converting back to MW coords.
|
||||
Vector3 pos = camera->getPosition();
|
||||
relX = pos[0];
|
||||
relY = -pos[2];
|
||||
relZ = pos[1];
|
||||
|
||||
// TODO: Collision detection must be used to find the REAL new
|
||||
// position.
|
||||
|
||||
// Set the position
|
||||
setPos(relX, relY, relZ);
|
||||
}
|
||||
|
||||
MWWorld::Ptr getPlayer()
|
||||
{
|
||||
MWWorld::Ptr ptr (&mPlayer, mCellStore);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void setName (const std::string& name)
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
void setGender (bool male)
|
||||
{
|
||||
mMale = male;
|
||||
}
|
||||
|
||||
void setRace (const std::string& race)
|
||||
{
|
||||
mRace = race;
|
||||
}
|
||||
|
||||
void setBirthsign (const std::string& birthsign)
|
||||
{
|
||||
mBirthsign = birthsign;
|
||||
}
|
||||
|
||||
void setClass (const ESM::Class& class_);
|
||||
|
||||
std::string getName() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
bool isMale() const
|
||||
{
|
||||
return mMale;
|
||||
}
|
||||
|
||||
std::string getRace() const
|
||||
{
|
||||
return mRace;
|
||||
}
|
||||
|
||||
std::string getBirthsign() const
|
||||
{
|
||||
return mBirthsign;
|
||||
}
|
||||
|
||||
const ESM::Class& getClass() const
|
||||
{
|
||||
return *mClass;
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif
|
@ -0,0 +1,41 @@
|
||||
#ifndef GAME_MWSCRIPT_REF_H
|
||||
#define GAME_MWSCRIPT_REF_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <components/interpreter/runtime.hpp>
|
||||
|
||||
#include "../mwworld/ptr.hpp"
|
||||
#include "../mwworld/world.hpp"
|
||||
|
||||
#include "interpretercontext.hpp"
|
||||
|
||||
namespace MWScript
|
||||
{
|
||||
struct ExplicitRef
|
||||
{
|
||||
MWWorld::Ptr operator() (Interpreter::Runtime& runtime) const
|
||||
{
|
||||
MWScript::InterpreterContext& context
|
||||
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
|
||||
|
||||
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
|
||||
return context.getWorld().getPtr (id, false);
|
||||
}
|
||||
};
|
||||
|
||||
struct ImplicitRef
|
||||
{
|
||||
MWWorld::Ptr operator() (Interpreter::Runtime& runtime) const
|
||||
{
|
||||
MWScript::InterpreterContext& context
|
||||
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
|
||||
|
||||
return context.getReference();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,31 @@
|
||||
#ifndef GAME_MWWORLD_CELLFUNCTORS_H
|
||||
#define GAME_MWWORLD_CELLFUNCTORS_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "refdata.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
class CellRef;
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
/// List all (Ogre-)handles.
|
||||
struct ListHandles
|
||||
{
|
||||
std::vector<std::string> mHandles;
|
||||
|
||||
bool operator() (ESM::CellRef& ref, RefData& data)
|
||||
{
|
||||
std::string handle = data.getHandle();
|
||||
if (!handle.empty())
|
||||
mHandles.push_back (handle);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,33 @@
|
||||
|
||||
#include "doingphysics.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
int DoingPhysics::sCounter = 0;
|
||||
int DoingPhysics::sSuppress = 0;
|
||||
|
||||
DoingPhysics::DoingPhysics()
|
||||
{
|
||||
++sCounter;
|
||||
}
|
||||
|
||||
DoingPhysics::~DoingPhysics()
|
||||
{
|
||||
--sCounter;
|
||||
}
|
||||
|
||||
bool DoingPhysics::isDoingPhysics()
|
||||
{
|
||||
return sCounter>0 && sSuppress==0;
|
||||
}
|
||||
|
||||
SuppressDoingPhysics::SuppressDoingPhysics()
|
||||
{
|
||||
++DoingPhysics::sSuppress;
|
||||
}
|
||||
|
||||
SuppressDoingPhysics::~SuppressDoingPhysics()
|
||||
{
|
||||
--DoingPhysics::sSuppress;
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
#ifndef GAME_MWWORLD_DOINGPHYSICS_H
|
||||
#define GAME_MWWORLD_DOINGPHYSICS_H
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class SuppressDoingPhysics;
|
||||
|
||||
/// Scope guard for blocking physics updates during physics simulation.
|
||||
class DoingPhysics
|
||||
{
|
||||
static int sCounter;
|
||||
static int sSuppress;
|
||||
|
||||
private:
|
||||
|
||||
DoingPhysics (const DoingPhysics&);
|
||||
DoingPhysics& operator= (const DoingPhysics&);
|
||||
|
||||
public:
|
||||
|
||||
DoingPhysics();
|
||||
|
||||
~DoingPhysics();
|
||||
|
||||
static bool isDoingPhysics();
|
||||
|
||||
friend class SuppressDoingPhysics;
|
||||
};
|
||||
|
||||
/// Scope guard for temporarily lifting the block issues by DoingPhysics
|
||||
class SuppressDoingPhysics
|
||||
{
|
||||
private:
|
||||
|
||||
SuppressDoingPhysics (const SuppressDoingPhysics&);
|
||||
SuppressDoingPhysics& operator= (const SuppressDoingPhysics&);
|
||||
|
||||
public:
|
||||
|
||||
SuppressDoingPhysics();
|
||||
|
||||
~SuppressDoingPhysics();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,88 @@
|
||||
|
||||
#include "player.hpp"
|
||||
|
||||
#include "../mwrender/player.hpp"
|
||||
|
||||
#include "world.hpp"
|
||||
#include "class.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
Player::Player (MWRender::Player *renderer, const ESM::NPC *player, MWWorld::World& world) :
|
||||
mCellStore (0), mRenderer (renderer), mWorld (world), mClass (0),
|
||||
mAutoMove (false), mForwardBackward (0)
|
||||
{
|
||||
mPlayer.base = player;
|
||||
mName = player->name;
|
||||
mMale = !(player->flags & ESM::NPC::Female);
|
||||
mRace = player->race;
|
||||
mPlayer.ref.pos.pos[0] = mPlayer.ref.pos.pos[1] = mPlayer.ref.pos.pos[2] = 0;
|
||||
mPlayer.mData.setHandle (renderer->getHandle());
|
||||
mClass = new ESM::Class (*world.getStore().classes.find (player->cls));
|
||||
}
|
||||
|
||||
Player::~Player()
|
||||
{
|
||||
delete mClass;
|
||||
}
|
||||
|
||||
void Player::setPos(float x, float y, float z, bool updateCamera)
|
||||
{
|
||||
mWorld.moveObject (getPlayer(), x, y, z);
|
||||
|
||||
if (updateCamera)
|
||||
mRenderer->getCamera()->setPosition (Ogre::Vector3 (
|
||||
mPlayer.ref.pos.pos[0],
|
||||
mPlayer.ref.pos.pos[2],
|
||||
-mPlayer.ref.pos.pos[1]));
|
||||
}
|
||||
|
||||
void Player::setClass (const ESM::Class& class_)
|
||||
{
|
||||
ESM::Class *new_class = new ESM::Class (class_);
|
||||
delete mClass;
|
||||
mClass = new_class;
|
||||
}
|
||||
|
||||
void Player::setAutoMove (bool enable)
|
||||
{
|
||||
MWWorld::Ptr ptr = getPlayer();
|
||||
|
||||
mAutoMove = enable;
|
||||
|
||||
int value = mForwardBackward;
|
||||
|
||||
if (mAutoMove)
|
||||
value = 1;
|
||||
|
||||
MWWorld::Class::get (ptr).getMovementSettings (ptr).mForwardBackward = value;
|
||||
}
|
||||
|
||||
void Player::setLeftRight (int value)
|
||||
{
|
||||
MWWorld::Ptr ptr = getPlayer();
|
||||
|
||||
MWWorld::Class::get (ptr).getMovementSettings (ptr).mLeftRight = value;
|
||||
}
|
||||
|
||||
void Player::setForwardBackward (int value)
|
||||
{
|
||||
MWWorld::Ptr ptr = getPlayer();
|
||||
|
||||
mForwardBackward = value;
|
||||
|
||||
if (mAutoMove)
|
||||
value = 1;
|
||||
|
||||
MWWorld::Class::get (ptr).getMovementSettings (ptr).mForwardBackward = value;
|
||||
}
|
||||
|
||||
void Player::toggleRunning()
|
||||
{
|
||||
MWWorld::Ptr ptr = getPlayer();
|
||||
|
||||
bool running = MWWorld::Class::get (ptr).getStance (ptr, MWWorld::Class::Run, true);
|
||||
|
||||
MWWorld::Class::get (ptr).setStance (ptr, MWWorld::Class::Run, !running);
|
||||
}
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
#ifndef GAME_MWWORLD_PLAYER_H
|
||||
#define GAME_MWWORLD_PLAYER_H
|
||||
|
||||
#include "OgreCamera.h"
|
||||
|
||||
#include <components/esm_store/cell_store.hpp>
|
||||
|
||||
#include "../mwworld/refdata.hpp"
|
||||
#include "../mwworld/ptr.hpp"
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
class Player;
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class World;
|
||||
|
||||
/// \brief NPC object representing the player and additional player data
|
||||
class Player
|
||||
{
|
||||
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> mPlayer;
|
||||
MWWorld::Ptr::CellStore *mCellStore;
|
||||
MWRender::Player *mRenderer;
|
||||
MWWorld::World& mWorld;
|
||||
std::string mName;
|
||||
bool mMale;
|
||||
std::string mRace;
|
||||
std::string mBirthsign;
|
||||
ESM::Class *mClass;
|
||||
bool mAutoMove;
|
||||
int mForwardBackward;
|
||||
|
||||
public:
|
||||
|
||||
Player(MWRender::Player *renderer, const ESM::NPC *player, MWWorld::World& world);
|
||||
|
||||
~Player();
|
||||
|
||||
/// Set the player position. Uses Morrowind coordinates.
|
||||
void setPos(float _x, float _y, float _z, bool updateCamera = false);
|
||||
|
||||
void setCell (MWWorld::Ptr::CellStore *cellStore)
|
||||
{
|
||||
mCellStore = cellStore;
|
||||
}
|
||||
|
||||
MWWorld::Ptr getPlayer()
|
||||
{
|
||||
MWWorld::Ptr ptr (&mPlayer, mCellStore);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
MWRender::Player *getRenderer() { return mRenderer; }
|
||||
|
||||
void setName (const std::string& name)
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
void setGender (bool male)
|
||||
{
|
||||
mMale = male;
|
||||
}
|
||||
|
||||
void setRace (const std::string& race)
|
||||
{
|
||||
mRace = race;
|
||||
}
|
||||
|
||||
void setBirthsign (const std::string& birthsign)
|
||||
{
|
||||
mBirthsign = birthsign;
|
||||
}
|
||||
|
||||
void setClass (const ESM::Class& class_);
|
||||
|
||||
std::string getName() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
bool isMale() const
|
||||
{
|
||||
return mMale;
|
||||
}
|
||||
|
||||
std::string getRace() const
|
||||
{
|
||||
return mRace;
|
||||
}
|
||||
|
||||
std::string getBirthsign() const
|
||||
{
|
||||
return mBirthsign;
|
||||
}
|
||||
|
||||
const ESM::Class& getClass() const
|
||||
{
|
||||
return *mClass;
|
||||
}
|
||||
|
||||
bool getAutoMove()
|
||||
{
|
||||
return mAutoMove;
|
||||
}
|
||||
|
||||
void setAutoMove (bool enable);
|
||||
|
||||
void setLeftRight (int value);
|
||||
|
||||
void setForwardBackward (int value);
|
||||
|
||||
void toggleRunning();
|
||||
};
|
||||
}
|
||||
#endif
|
@ -0,0 +1,56 @@
|
||||
#include "path.hpp"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
|
||||
#include <stdlib.h> //getenv
|
||||
#endif
|
||||
|
||||
|
||||
std::string OMW::Path::getPath(PathTypeEnum parType, const std::string parApp, const std::string parFile)
|
||||
{
|
||||
std::string theBasePath;
|
||||
if(parType == GLOBAL_CFG_PATH)
|
||||
{
|
||||
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
|
||||
theBasePath = Ogre::macBundlePath() + "/Contents/MacOS/"; //FIXME do we have global/local with OSX?
|
||||
#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
|
||||
theBasePath = "/etc/"+parApp+"/";
|
||||
#else
|
||||
theBasePath = "";
|
||||
#endif
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
|
||||
theBasePath = Ogre::macBundlePath() + "/Contents/MacOS/"; //FIXME do we have global/local with OSX?
|
||||
#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
|
||||
const char* theDir;
|
||||
if ((theDir = getenv("OPENMW_HOME")) != NULL)
|
||||
{
|
||||
theBasePath = std::string(theDir)+"/";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((theDir = getenv("XDG_CONFIG_HOME")))
|
||||
{
|
||||
theBasePath = std::string(theDir)+"/"+parApp+"/";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((theDir = getenv("HOME")) == NULL)
|
||||
return parFile;
|
||||
theBasePath = std::string(theDir)+"/.config/"+parApp+"/";
|
||||
}
|
||||
}
|
||||
boost::filesystem::create_directories(boost::filesystem::path(theBasePath));
|
||||
#else
|
||||
theBasePath = "";
|
||||
#endif
|
||||
}
|
||||
|
||||
theBasePath.append(parFile);
|
||||
return theBasePath;
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
#ifndef PATH__HPP
|
||||
#define PATH__HPP
|
||||
|
||||
#include <OgrePlatform.h>
|
||||
#include <string>
|
||||
|
||||
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
|
||||
#include <OSX/macUtils.h>
|
||||
#endif
|
||||
|
||||
namespace OMW
|
||||
{
|
||||
class Path
|
||||
{
|
||||
public:
|
||||
enum PathTypeEnum
|
||||
{
|
||||
USER_CFG_PATH,
|
||||
GLOBAL_CFG_PATH
|
||||
};
|
||||
|
||||
static std::string getPath(PathTypeEnum parType, const std::string parApp, const std::string parFile);
|
||||
};
|
||||
}
|
||||
#endif
|
@ -0,0 +1,76 @@
|
||||
# - Try to find the Bullet physics engine
|
||||
#
|
||||
# This module defines the following variables
|
||||
#
|
||||
# BULLET_FOUND - Was bullet found
|
||||
# BULLET_INCLUDE_DIRS - the Bullet include directories
|
||||
# BULLET_LIBRARIES - Link to this, by default it includes
|
||||
# all bullet components (Dynamics,
|
||||
# Collision, LinearMath, & SoftBody)
|
||||
#
|
||||
# This module accepts the following variables
|
||||
#
|
||||
# BULLET_ROOT - Can be set to bullet install path or Windows build path
|
||||
#
|
||||
|
||||
# Copyright (c) 2009, Philip Lowman <philip at yhbt.com>
|
||||
#
|
||||
# Redistribution AND use is allowed according to the terms of the New
|
||||
# BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
macro(_FIND_BULLET_LIBRARY _var)
|
||||
find_library(${_var}
|
||||
NAMES
|
||||
${ARGN}
|
||||
PATHS
|
||||
${BULLET_ROOT}
|
||||
${BULLET_ROOT}/out/release8/libs
|
||||
${BULLET_ROOT}/out/debug8/libs
|
||||
PATH_SUFFIXES lib
|
||||
)
|
||||
mark_as_advanced(${_var})
|
||||
endmacro()
|
||||
|
||||
macro(_BULLET_APPEND_LIBRARIES _list _release)
|
||||
set(_debug ${_release}_DEBUG)
|
||||
if(${_debug})
|
||||
set(${_list} ${${_list}} optimized ${${_release}} debug ${${_debug}})
|
||||
else()
|
||||
set(${_list} ${${_list}} ${${_release}})
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
find_path(BULLET_INCLUDE_DIR NAMES btBulletCollisionCommon.h
|
||||
PATHS
|
||||
${BULLET_ROOT}/include
|
||||
${BULLET_ROOT}/src
|
||||
PATH_SUFFIXES bullet
|
||||
)
|
||||
|
||||
# Find the libraries
|
||||
|
||||
_FIND_BULLET_LIBRARY(BULLET_DYNAMICS_LIBRARY BulletDynamics)
|
||||
_FIND_BULLET_LIBRARY(BULLET_DYNAMICS_LIBRARY_DEBUG BulletDynamics_d)
|
||||
_FIND_BULLET_LIBRARY(BULLET_COLLISION_LIBRARY BulletCollision)
|
||||
_FIND_BULLET_LIBRARY(BULLET_COLLISION_LIBRARY_DEBUG BulletCollision_d)
|
||||
_FIND_BULLET_LIBRARY(BULLET_MATH_LIBRARY LinearMath BulletMath)
|
||||
_FIND_BULLET_LIBRARY(BULLET_MATH_LIBRARY_DEBUG LinearMath_d BulletMath_d)
|
||||
_FIND_BULLET_LIBRARY(BULLET_SOFTBODY_LIBRARY BulletSoftBody)
|
||||
_FIND_BULLET_LIBRARY(BULLET_SOFTBODY_LIBRARY_DEBUG BulletSoftBody_d)
|
||||
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set BULLET_FOUND to TRUE if
|
||||
# all listed variables are TRUE
|
||||
include(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Bullet DEFAULT_MSG
|
||||
BULLET_DYNAMICS_LIBRARY BULLET_COLLISION_LIBRARY BULLET_MATH_LIBRARY
|
||||
BULLET_SOFTBODY_LIBRARY BULLET_INCLUDE_DIR)
|
||||
|
||||
set(BULLET_INCLUDE_DIRS ${BULLET_INCLUDE_DIR})
|
||||
if(BULLET_FOUND)
|
||||
_BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_DYNAMICS_LIBRARY)
|
||||
_BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_COLLISION_LIBRARY)
|
||||
_BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_MATH_LIBRARY)
|
||||
_BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_SOFTBODY_LIBRARY)
|
||||
endif()
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue