Fixes #1252: Add item/magic keybindings to savegame

openmw-30
scrawl 11 years ago
parent fc7e79027a
commit 17bb8d7f9a

@ -305,6 +305,7 @@ namespace MWBase
virtual void write (ESM::ESMWriter& writer, Loading::Listener& progress) = 0;
virtual void readRecord (ESM::ESMReader& reader, int32_t type) = 0;
virtual int countSavedGameRecords() const = 0;
};
}

@ -55,6 +55,14 @@ namespace MWGui
}
}
void QuickKeysMenu::clear()
{
for (int i=0; i<10; ++i)
{
unassign(mQuickKeyButtons[i], i);
}
}
QuickKeysMenu::~QuickKeysMenu()
{
delete mAssignDialog;
@ -154,8 +162,6 @@ namespace MWGui
frame->setUserString ("ToolTipType", "ItemPtr");
frame->setUserData(item);
frame->eventMouseButtonClick += MyGUI::newDelegate(this, &QuickKeysMenu::onQuickKeyButtonClicked);
MyGUI::ImageBox* image = frame->createWidget<MyGUI::ImageBox>("ImageBox", MyGUI::IntCoord(5, 5, 32, 32), MyGUI::Align::Default);
std::string path = std::string("icons\\");
path += MWWorld::Class::get(item).getInventoryIcon(item);
@ -165,7 +171,8 @@ namespace MWGui
image->setImageTexture (path);
image->setNeedMouseFocus (false);
mItemSelectionDialog->setVisible(false);
if (mItemSelectionDialog)
mItemSelectionDialog->setVisible(false);
}
void QuickKeysMenu::onAssignItemCancel()
@ -198,7 +205,8 @@ namespace MWGui
image->setImageTexture (path);
image->setNeedMouseFocus (false);
mMagicSelectionDialog->setVisible(false);
if (mMagicSelectionDialog)
mMagicSelectionDialog->setVisible(false);
}
void QuickKeysMenu::onAssignMagic (const std::string& spellId)
@ -239,7 +247,8 @@ namespace MWGui
image->setImageTexture (path);
image->setNeedMouseFocus (false);
mMagicSelectionDialog->setVisible(false);
if (mMagicSelectionDialog)
mMagicSelectionDialog->setVisible(false);
}
void QuickKeysMenu::onAssignMagicCancel ()
@ -374,6 +383,106 @@ namespace MWGui
center();
}
void QuickKeysMenu::write(ESM::ESMWriter &writer)
{
const std::string recKey = "KEY_";
writer.startRecord(ESM::REC_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);
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);
break;
}
case Type_Magic:
std::string spellId = button->getChildAt(0)->getUserString("Spell");
writer.writeHNString("ID__", spellId);
break;
}
writer.endRecord(recKey);
}
writer.endRecord(ESM::REC_KEYS);
}
void QuickKeysMenu::readRecord(ESM::ESMReader &reader, int32_t type)
{
if (type != ESM::REC_KEYS)
return;
int i=0;
while (reader.isNextSub("KEY_"))
{
reader.getSubHeader();
int keyType;
reader.getHNT(keyType, "TYPE");
std::string id;
id = reader.getHNString("ID__");
mSelectedIndex = i;
MyGUI::Button* button = mQuickKeyButtons[i];
switch (keyType)
{
case Type_Magic:
onAssignMagic(id);
break;
case Type_Item:
case Type_MagicItem:
{
// Find the item by id
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player);
MWWorld::Ptr item;
for (MWWorld::ContainerStoreIterator it = store.begin(); it != store.end(); ++it)
{
if (Misc::StringUtils::ciEqual(it->getCellRef().mRefID, id))
{
if (item.isEmpty() ||
// Prefer the stack with the lowest remaining uses
(it->getCellRef().mCharge != -1 && (item.getCellRef().mCharge == -1 || it->getCellRef().mCharge < item.getCellRef().mCharge) ))
{
item = *it;
}
}
}
if (item.isEmpty())
unassign(button, i);
else
{
if (keyType == Type_Item)
onAssignItem(item);
else if (keyType == Type_MagicItem)
onAssignMagicItem(item);
}
break;
}
case Type_Unassigned:
unassign(button, i);
break;
}
++i;
}
}
// ---------------------------------------------------------------------------------------------------------

@ -41,6 +41,11 @@ namespace MWGui
};
void write (ESM::ESMWriter& writer);
void readRecord (ESM::ESMReader& reader, int32_t type);
void clear();
private:
MyGUI::EditBox* mInstructionLabel;
MyGUI::Button* mOkButton;

@ -1405,16 +1405,29 @@ namespace MWGui
void WindowManager::clear()
{
mMap->clear();
mQuickKeysMenu->clear();
}
void WindowManager::write(ESM::ESMWriter &writer, Loading::Listener& progress)
{
mMap->write(writer, progress);
mQuickKeysMenu->write(writer);
progress.increaseProgress();
}
void WindowManager::readRecord(ESM::ESMReader &reader, int32_t type)
{
mMap->readRecord(reader, type);
if (type == ESM::REC_GMAP)
mMap->readRecord(reader, type);
else if (type == ESM::REC_KEYS)
mQuickKeysMenu->readRecord(reader, type);
}
int WindowManager::countSavedGameRecords() const
{
return 1 // Global map
+ 1; // QuickKeysMenu
}
void WindowManager::playVideo(const std::string &name, bool allowSkipping)

@ -293,6 +293,7 @@ namespace MWGui
virtual void write (ESM::ESMWriter& writer, Loading::Listener& progress);
virtual void readRecord (ESM::ESMReader& reader, int32_t type);
virtual int countSavedGameRecords() const;
private:
bool mConsoleOnlyScripts;

@ -201,7 +201,7 @@ void MWState::StateManager::saveGame (const std::string& description, const Slot
+MWBase::Environment::get().getWorld()->countSavedGameRecords()
+MWBase::Environment::get().getScriptManager()->getGlobalScripts().countSavedGameRecords()
+MWBase::Environment::get().getDialogueManager()->countSavedGameRecords()
+1; // global map
+MWBase::Environment::get().getWindowManager()->countSavedGameRecords();
writer.setRecordCount (recordCount);
writer.save (stream);
@ -323,7 +323,7 @@ void MWState::StateManager::loadGame (const Character *character, const Slot *sl
break;
case ESM::REC_GMAP:
case ESM::REC_KEYS:
MWBase::Environment::get().getWindowManager()->readRecord(reader, n.val);
break;

@ -34,6 +34,12 @@ struct Position
};
#pragma pack(pop)
template <int a, int b, int c, int d>
struct FourCC
{
static const unsigned int value = (((((d << 8) | c) << 8) | b) << 8) | a;
};
enum RecNameInts
{
// format 0 / legacy
@ -93,6 +99,7 @@ enum RecNameInts
REC_GMAP = 0x50414d47,
REC_DIAS = 0x53414944,
REC_WTHR = 0x52485457,
REC_KEYS = FourCC<'K','E','Y','S'>::value,
// format 1
REC_FILT = 0x544C4946

Loading…
Cancel
Save