working mygui tag replacement system for GMST strings

actorid
scrawl 13 years ago
parent 9ca579ba63
commit 24ce88de2a

@ -1,13 +1,19 @@
#include "stats_window.hpp"
#include "../mwmechanics/mechanicsmanager.hpp"
#include "window_manager.hpp"
#include <cmath>
#include <algorithm>
#include <iterator>
#include <boost/lexical_cast.hpp>
#include "../mwmechanics/mechanicsmanager.hpp"
#include "../mwworld/world.hpp"
#include "../mwworld/player.hpp"
#include "../mwbase/environment.hpp"
#include "window_manager.hpp"
using namespace MWGui;
const int StatsWindow::lineHeight = 18;
@ -24,11 +30,12 @@ StatsWindow::StatsWindow (WindowManager& parWindowManager)
, skillValues()
, skillWidgetMap()
, factionWidgetMap()
, factions()
, mFactions()
, birthSignId()
, reputation(0)
, bounty(0)
, skillWidgets()
, mChanged(true)
{
setCoord(0,0,498, 342);
@ -128,7 +135,8 @@ void StatsWindow::setBar(const std::string& name, const std::string& tname, int
void StatsWindow::setPlayerName(const std::string& playerName)
{
setTitle(playerName);
static_cast<MyGUI::Window*>(mMainWidget)->setCaption(playerName);
adjustWindowCaption();
}
void StatsWindow::setValue (const std::string& id, const MWMechanics::Stat<int>& value)
@ -235,9 +243,24 @@ void StatsWindow::configureSkills (const std::vector<int>& major, const std::vec
}
}
void StatsWindow::setFactions (const std::vector<Faction>& factions)
void StatsWindow::onFrame ()
{
this->factions = factions;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
MWMechanics::NpcStats PCstats = MWWorld::Class::get(player).getNpcStats(player);
setFactions(PCstats.mFactionRank);
if (mChanged)
updateSkillArea();
}
void StatsWindow::setFactions (const FactionList& factions)
{
if (mFactions != factions)
{
mFactions = factions;
mChanged = true;
}
}
void StatsWindow::setBirthSign (const std::string& signId)
@ -345,6 +368,8 @@ void StatsWindow::addSkills(const SkillList &skills, const std::string &titleId,
void StatsWindow::updateSkillArea()
{
mChanged = false;
for (std::vector<MyGUI::WidgetPtr>::iterator it = skillWidgets.begin(); it != skillWidgets.end(); ++it)
{
MyGUI::Gui::getInstance().destroyWidget(*it);
@ -366,15 +391,15 @@ void StatsWindow::updateSkillArea()
const ESMS::ESMStore &store = mWindowManager.getStore();
if (!factions.empty())
if (!mFactions.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)
FactionList::const_iterator end = mFactions.end();
for (FactionList::const_iterator it = mFactions.begin(); it != end; ++it)
{
const ESM::Faction *faction = store.factions.find(it->first);
addItem(faction->name, coord1, coord2);

@ -18,13 +18,15 @@ namespace MWGui
class StatsWindow : public WindowPinnableBase
{
public:
typedef std::pair<std::string, int> Faction;
typedef std::vector<Faction> FactionList;
typedef std::map<std::string, int> FactionList;
typedef std::vector<int> SkillList;
StatsWindow(WindowManager& parWindowManager);
/// automatically updates all the data in the stats window, but only if it has changed.
void onFrame();
void setBar(const std::string& name, const std::string& tname, int val, int max);
void setPlayerName(const std::string& playerName);
@ -36,7 +38,7 @@ namespace MWGui
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 setFactions (const FactionList& factions);
void setBirthSign (const std::string &signId);
void setReputation (int reputation) { this->reputation = reputation; }
void setBounty (int bounty) { this->bounty = bounty; }
@ -69,11 +71,13 @@ namespace MWGui
std::map<int, MWMechanics::Stat<float> > skillValues;
std::map<int, MyGUI::TextBox*> skillWidgetMap;
std::map<std::string, MyGUI::WidgetPtr> factionWidgetMap;
FactionList factions; ///< Stores a list of factions and the current rank
FactionList mFactions; ///< Stores a list of factions and the current rank
std::string birthSignId;
int reputation, bounty;
std::vector<MyGUI::WidgetPtr> skillWidgets; //< Skills and other information
bool mChanged;
protected:
virtual void onPinToggled();
};

@ -47,12 +47,6 @@ namespace MWGui
mCancelButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sCancel")->str);
mOfferButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sBarterDialog8")->str);
mFilterAll->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sAllTab")->str);
mFilterWeapon->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sWeaponTab")->str);
mFilterApparel->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sApparelTab")->str);
mFilterMagic->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sMagicTab")->str);
mFilterMisc->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sMiscTab")->str);
// adjust size of buttons to fit text
int curX = 0;
mFilterAll->setSize( mFilterAll->getTextSize().width + 24, mFilterAll->getSize().height );

@ -40,7 +40,7 @@ WindowManager::WindowManager(
, hud(NULL)
, map(NULL)
, menu(NULL)
, stats(NULL)
, mStatsWindow(NULL)
, mToolTips(NULL)
, mMessageBoxManager(NULL)
, console(NULL)
@ -89,6 +89,8 @@ WindowManager::WindowManager(
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWDynamicStat>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWList>("Widget");
MyGUI::LanguageManager::getInstance().eventRequestTag = MyGUI::newDelegate(this, &WindowManager::onRetrieveTag);
// Get size info from the Gui object
assert(gui);
int w = MyGUI::RenderManager::getInstance().getViewSize().width;
@ -104,7 +106,7 @@ WindowManager::WindowManager(
menu = new MainMenu(w,h);
map = new MapWindow(*this);
stats = new StatsWindow(*this);
mStatsWindow = new StatsWindow(*this);
console = new Console(w,h, extensions);
mJournal = new JournalWindow(*this);
mMessageBoxManager = new MessageBoxManager(this);
@ -146,7 +148,7 @@ WindowManager::~WindowManager()
delete hud;
delete map;
delete menu;
delete stats;
delete mStatsWindow;
delete mJournal;
delete mDialogueWindow;
delete mContainerWindow;
@ -207,7 +209,7 @@ void WindowManager::updateVisible()
// Start out by hiding everything except the HUD
map->setVisible(false);
menu->setVisible(false);
stats->setVisible(false);
mStatsWindow->setVisible(false);
console->disable();
mJournal->setVisible(false);
mDialogueWindow->setVisible(false);
@ -261,7 +263,7 @@ void WindowManager::updateVisible()
// Show the windows we want
map -> setVisible( (eff & GW_Map) != 0 );
stats -> setVisible( (eff & GW_Stats) != 0 );
mStatsWindow -> setVisible( (eff & GW_Stats) != 0 );
mInventoryWindow->setVisible(true);
mInventoryWindow->openInventory();
break;
@ -299,7 +301,7 @@ void WindowManager::updateVisible()
void WindowManager::setValue (const std::string& id, const MWMechanics::Stat<int>& value)
{
stats->setValue (id, value);
mStatsWindow->setValue (id, value);
static const char *ids[] =
{
@ -329,13 +331,13 @@ void WindowManager::setValue (const std::string& id, const MWMechanics::Stat<int
void WindowManager::setValue(const ESM::Skill::SkillEnum parSkill, const MWMechanics::Stat<float>& value)
{
stats->setValue(parSkill, value);
mStatsWindow->setValue(parSkill, value);
playerSkillValues[parSkill] = value;
}
void WindowManager::setValue (const std::string& id, const MWMechanics::DynamicStat<int>& value)
{
stats->setValue (id, value);
mStatsWindow->setValue (id, value);
hud->setValue (id, value);
if (id == "HBar")
{
@ -368,7 +370,7 @@ MWMechanics::DynamicStat<int> WindowManager::getValue(const std::string& id)
void WindowManager::setValue (const std::string& id, const std::string& value)
{
stats->setValue (id, value);
mStatsWindow->setValue (id, value);
if (id=="name")
playerName = value;
else if (id=="race")
@ -377,46 +379,41 @@ void WindowManager::setValue (const std::string& id, const std::string& value)
void WindowManager::setValue (const std::string& id, int value)
{
stats->setValue (id, value);
mStatsWindow->setValue (id, value);
}
void WindowManager::setPlayerClass (const ESM::Class &class_)
{
playerClass = class_;
stats->setValue("class", playerClass.name);
mStatsWindow->setValue("class", playerClass.name);
}
void WindowManager::configureSkills (const SkillList& major, const SkillList& minor)
{
stats->configureSkills (major, minor);
mStatsWindow->configureSkills (major, minor);
playerMajorSkills = major;
playerMinorSkills = minor;
}
void WindowManager::setFactions (const FactionList& factions)
{
stats->setFactions (factions);
}
void WindowManager::setBirthSign (const std::string &signId)
{
stats->setBirthSign (signId);
mStatsWindow->setBirthSign (signId);
playerBirthSignId = signId;
}
void WindowManager::setReputation (int reputation)
{
stats->setReputation (reputation);
mStatsWindow->setReputation (reputation);
}
void WindowManager::setBounty (int bounty)
{
stats->setBounty (bounty);
mStatsWindow->setBounty (bounty);
}
void WindowManager::updateSkillArea()
{
stats->updateSkillArea();
mStatsWindow->updateSkillArea();
}
void WindowManager::removeDialog(OEngine::GUI::Layout*dialog)
@ -477,6 +474,8 @@ void WindowManager::onFrame (float frameDuration)
}
mInventoryWindow->update();
mStatsWindow->onFrame();
}
const ESMS::ESMStore& WindowManager::getStore() const
@ -598,3 +597,10 @@ void WindowManager::setDragDrop(bool dragDrop)
mToolTips->setEnabled(!dragDrop);
MWBase::Environment::get().getInputManager()->setDragDrop(dragDrop);
}
void WindowManager::onRetrieveTag(const MyGUI::UString& _tag, MyGUI::UString& _result)
{
const ESM::GameSetting *setting = MWBase::Environment::get().getWorld()->getStore().gameSettings.search(_tag);
if (setting && setting->type == ESM::VT_String)
_result = setting->str;
}

@ -14,11 +14,15 @@
#include <vector>
#include <set>
#include "MyGUI_UString.h"
#include <components/esm_store/store.hpp>
#include <openengine/ogre/renderer.hpp>
#include <openengine/gui/manager.hpp>
#include "../mwmechanics/stat.hpp"
#include "../mwworld/ptr.hpp"
#include "mode.hpp"
namespace MyGUI
@ -157,7 +161,6 @@ namespace MWGui
void setPlayerClass (const ESM::Class &class_); ///< set current class of player
void configureSkills (const SkillList& major, const SkillList& minor); ///< configure skill groups, each set contains the skill ID for that group.
void setFactions (const FactionList& factions); ///< set faction and rank to display on stat window, use an empty vector to disable
void setBirthSign (const std::string &signId); ///< set birth sign to display on stat window, use an empty string to disable.
void setReputation (int reputation); ///< set the current reputation value
void setBounty (int bounty); ///< set the current bounty value
@ -216,7 +219,7 @@ namespace MWGui
MapWindow *map;
MainMenu *menu;
ToolTips *mToolTips;
StatsWindow *stats;
StatsWindow *mStatsWindow;
MessageBoxManager *mMessageBoxManager;
Console *console;
JournalWindow* mJournal;
@ -270,6 +273,12 @@ namespace MWGui
size_t mBatchCount;
void onDialogueWindowBye();
/**
* Called when MyGUI tries to retrieve a tag. This usually corresponds to a GMST string,
* so this method will retrieve the GMST with the name \a _tag and place the result in \a _result
*/
void onRetrieveTag(const MyGUI::UString& _tag, MyGUI::UString& _result);
};
template<typename T>

@ -6,11 +6,21 @@
<!-- Categories -->
<Widget type="Widget" position="8 8 566 24" align="Left Top HStretch" name="Categories">
<Widget type="Button" skin="MW_Button" position="0 0 60 24" name="AllButton"/>
<Widget type="Button" skin="MW_Button" position="0 0 60 24" name="WeaponButton"/>
<Widget type="Button" skin="MW_Button" position="0 0 60 24" name="ApparelButton"/>
<Widget type="Button" skin="MW_Button" position="0 0 60 24" name="MagicButton"/>
<Widget type="Button" skin="MW_Button" position="0 0 60 24" name="MiscButton"/>
<Widget type="Button" skin="MW_Button" position="0 0 60 24" name="AllButton">
<Property key="Caption" value="#{sAllTab}"/>
</Widget>
<Widget type="Button" skin="MW_Button" position="0 0 60 24" name="WeaponButton">
<Property key="Caption" value="#{sWeaponTab}"/>
</Widget>
<Widget type="Button" skin="MW_Button" position="0 0 60 24" name="ApparelButton">
<Property key="Caption" value="#{sApparelTab}"/>
</Widget>
<Widget type="Button" skin="MW_Button" position="0 0 60 24" name="MagicButton">
<Property key="Caption" value="#{sMagicTab}"/>
</Widget>
<Widget type="Button" skin="MW_Button" position="0 0 60 24" name="MiscButton">
<Property key="Caption" value="#{sMiscTab}"/>
</Widget>
</Widget>
<!-- Items -->
@ -36,8 +46,8 @@
<Property key="Caption" value="-"/>
</Widget>
<Widget type="TextBox" skin="SandText" position="48 0 110 24" name="TotalBalanceLabel" align="Left Top "/>
<Widget type="TextBox" skin="SandText" position="48 28 110 24" name="TotalBalance" align="Left Top">
<Widget type="TextBox" skin="SandText" position="48 0 140 24" name="TotalBalanceLabel" align="Left Top "/>
<Widget type="TextBox" skin="SandText" position="48 28 140 24" name="TotalBalance" align="Left Top">
<Property key="TextAlign" value="Center"/>
</Widget>

Loading…
Cancel
Save