mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 18:19:55 +00:00
Move to esm component
This commit is contained in:
parent
f8cc328b5e
commit
8560b43464
4 changed files with 93 additions and 16 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include <components/esm/quickkeys.hpp>
|
||||
|
||||
#include "../mwworld/inventorystore.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
|
||||
|
@ -385,39 +387,41 @@ namespace MWGui
|
|||
|
||||
void QuickKeysMenu::write(ESM::ESMWriter &writer)
|
||||
{
|
||||
const std::string recKey = "KEY_";
|
||||
writer.startRecord(ESM::REC_KEYS);
|
||||
|
||||
ESM::QuickKeys keys;
|
||||
|
||||
for (int i=0; i<10; ++i)
|
||||
{
|
||||
writer.startSubRecord(recKey);
|
||||
|
||||
MyGUI::Button* button = mQuickKeyButtons[i];
|
||||
|
||||
int type = *button->getUserData<QuickKeyType>();
|
||||
writer.writeHNT("TYPE", type);
|
||||
|
||||
ESM::QuickKeys::QuickKey key;
|
||||
key.mType = type;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case Type_Unassigned:
|
||||
writer.writeHNString("ID__", "");
|
||||
break;
|
||||
case Type_Item:
|
||||
case Type_MagicItem:
|
||||
{
|
||||
MWWorld::Ptr item = *button->getChildAt(0)->getUserData<MWWorld::Ptr>();
|
||||
writer.writeHNString("ID__", item.getCellRef().mRefID);
|
||||
key.mId = item.getCellRef().mRefID;
|
||||
break;
|
||||
}
|
||||
case Type_Magic:
|
||||
std::string spellId = button->getChildAt(0)->getUserString("Spell");
|
||||
writer.writeHNString("ID__", spellId);
|
||||
key.mId = spellId;
|
||||
break;
|
||||
}
|
||||
|
||||
writer.endRecord(recKey);
|
||||
keys.mKeys.push_back(key);
|
||||
}
|
||||
|
||||
keys.save(writer);
|
||||
|
||||
writer.endRecord(ESM::REC_KEYS);
|
||||
}
|
||||
|
||||
|
@ -426,17 +430,18 @@ namespace MWGui
|
|||
if (type != ESM::REC_KEYS)
|
||||
return;
|
||||
|
||||
ESM::QuickKeys keys;
|
||||
keys.load(reader);
|
||||
|
||||
int i=0;
|
||||
while (reader.isNextSub("KEY_"))
|
||||
for (std::vector<ESM::QuickKeys::QuickKey>::const_iterator it = keys.mKeys.begin(); it != keys.mKeys.end(); ++it)
|
||||
{
|
||||
reader.getSubHeader();
|
||||
int keyType;
|
||||
reader.getHNT(keyType, "TYPE");
|
||||
std::string id;
|
||||
id = reader.getHNString("ID__");
|
||||
if (i >= 10)
|
||||
return;
|
||||
|
||||
mSelectedIndex = i;
|
||||
|
||||
int keyType = it->mType;
|
||||
std::string id = it->mId;
|
||||
MyGUI::Button* button = mQuickKeyButtons[i];
|
||||
|
||||
switch (keyType)
|
||||
|
@ -480,6 +485,7 @@ namespace MWGui
|
|||
unassign(button, i);
|
||||
break;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ add_component_dir (esm
|
|||
loadnpc loadpgrd loadrace loadregn loadscpt loadskil loadsndg loadsoun loadspel loadsscr loadstat
|
||||
loadweap records aipackage effectlist spelllist variant variantimp loadtes3 cellref filter
|
||||
savedgame journalentry queststate locals globalscript player objectstate cellid cellstate globalmap lightstate inventorystate containerstate npcstate creaturestate dialoguestate statstate
|
||||
npcstats creaturestats weatherstate
|
||||
npcstats creaturestats weatherstate quickkeys
|
||||
)
|
||||
|
||||
add_component_dir (misc
|
||||
|
|
43
components/esm/quickkeys.cpp
Normal file
43
components/esm/quickkeys.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "quickkeys.hpp"
|
||||
|
||||
#include "esmwriter.hpp"
|
||||
#include "esmreader.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
|
||||
void QuickKeys::load(ESMReader &esm)
|
||||
{
|
||||
while (esm.isNextSub("KEY_"))
|
||||
{
|
||||
esm.getSubHeader();
|
||||
int keyType;
|
||||
esm.getHNT(keyType, "TYPE");
|
||||
std::string id;
|
||||
id = esm.getHNString("ID__");
|
||||
|
||||
QuickKey key;
|
||||
key.mType = keyType;
|
||||
key.mId = id;
|
||||
|
||||
mKeys.push_back(key);
|
||||
}
|
||||
}
|
||||
|
||||
void QuickKeys::save(ESMWriter &esm) const
|
||||
{
|
||||
const std::string recKey = "KEY_";
|
||||
|
||||
for (std::vector<QuickKey>::const_iterator it = mKeys.begin(); it != mKeys.end(); ++it)
|
||||
{
|
||||
esm.startSubRecord(recKey);
|
||||
|
||||
esm.writeHNT("TYPE", it->mType);
|
||||
esm.writeHNString("ID__", it->mId);
|
||||
|
||||
esm.endRecord(recKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
28
components/esm/quickkeys.hpp
Normal file
28
components/esm/quickkeys.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
#ifndef OPENMW_COMPONENTS_ESM_QUICKKEYS_H
|
||||
#define OPENMW_COMPONENTS_ESM_QUICKKEYS_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
class ESMReader;
|
||||
class ESMWriter;
|
||||
|
||||
struct QuickKeys
|
||||
{
|
||||
struct QuickKey
|
||||
{
|
||||
int mType;
|
||||
std::string mId; // Spell or Item ID
|
||||
};
|
||||
|
||||
std::vector<QuickKey> mKeys;
|
||||
|
||||
void load (ESMReader &esm);
|
||||
void save (ESMWriter &esm) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue