mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 09:53:50 +00:00
Fixes #1252: Add item/magic keybindings to savegame
This commit is contained in:
parent
fc7e79027a
commit
17bb8d7f9a
7 changed files with 144 additions and 8 deletions
|
@ -305,6 +305,7 @@ namespace MWBase
|
||||||
|
|
||||||
virtual void write (ESM::ESMWriter& writer, Loading::Listener& progress) = 0;
|
virtual void write (ESM::ESMWriter& writer, Loading::Listener& progress) = 0;
|
||||||
virtual void readRecord (ESM::ESMReader& reader, int32_t type) = 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()
|
QuickKeysMenu::~QuickKeysMenu()
|
||||||
{
|
{
|
||||||
delete mAssignDialog;
|
delete mAssignDialog;
|
||||||
|
@ -154,8 +162,6 @@ namespace MWGui
|
||||||
frame->setUserString ("ToolTipType", "ItemPtr");
|
frame->setUserString ("ToolTipType", "ItemPtr");
|
||||||
frame->setUserData(item);
|
frame->setUserData(item);
|
||||||
frame->eventMouseButtonClick += MyGUI::newDelegate(this, &QuickKeysMenu::onQuickKeyButtonClicked);
|
frame->eventMouseButtonClick += MyGUI::newDelegate(this, &QuickKeysMenu::onQuickKeyButtonClicked);
|
||||||
|
|
||||||
|
|
||||||
MyGUI::ImageBox* image = frame->createWidget<MyGUI::ImageBox>("ImageBox", MyGUI::IntCoord(5, 5, 32, 32), MyGUI::Align::Default);
|
MyGUI::ImageBox* image = frame->createWidget<MyGUI::ImageBox>("ImageBox", MyGUI::IntCoord(5, 5, 32, 32), MyGUI::Align::Default);
|
||||||
std::string path = std::string("icons\\");
|
std::string path = std::string("icons\\");
|
||||||
path += MWWorld::Class::get(item).getInventoryIcon(item);
|
path += MWWorld::Class::get(item).getInventoryIcon(item);
|
||||||
|
@ -165,6 +171,7 @@ namespace MWGui
|
||||||
image->setImageTexture (path);
|
image->setImageTexture (path);
|
||||||
image->setNeedMouseFocus (false);
|
image->setNeedMouseFocus (false);
|
||||||
|
|
||||||
|
if (mItemSelectionDialog)
|
||||||
mItemSelectionDialog->setVisible(false);
|
mItemSelectionDialog->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,6 +205,7 @@ namespace MWGui
|
||||||
image->setImageTexture (path);
|
image->setImageTexture (path);
|
||||||
image->setNeedMouseFocus (false);
|
image->setNeedMouseFocus (false);
|
||||||
|
|
||||||
|
if (mMagicSelectionDialog)
|
||||||
mMagicSelectionDialog->setVisible(false);
|
mMagicSelectionDialog->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,6 +247,7 @@ namespace MWGui
|
||||||
image->setImageTexture (path);
|
image->setImageTexture (path);
|
||||||
image->setNeedMouseFocus (false);
|
image->setNeedMouseFocus (false);
|
||||||
|
|
||||||
|
if (mMagicSelectionDialog)
|
||||||
mMagicSelectionDialog->setVisible(false);
|
mMagicSelectionDialog->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,6 +383,106 @@ namespace MWGui
|
||||||
center();
|
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:
|
private:
|
||||||
MyGUI::EditBox* mInstructionLabel;
|
MyGUI::EditBox* mInstructionLabel;
|
||||||
MyGUI::Button* mOkButton;
|
MyGUI::Button* mOkButton;
|
||||||
|
|
|
@ -1405,16 +1405,29 @@ namespace MWGui
|
||||||
void WindowManager::clear()
|
void WindowManager::clear()
|
||||||
{
|
{
|
||||||
mMap->clear();
|
mMap->clear();
|
||||||
|
mQuickKeysMenu->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::write(ESM::ESMWriter &writer, Loading::Listener& progress)
|
void WindowManager::write(ESM::ESMWriter &writer, Loading::Listener& progress)
|
||||||
{
|
{
|
||||||
mMap->write(writer, progress);
|
mMap->write(writer, progress);
|
||||||
|
|
||||||
|
mQuickKeysMenu->write(writer);
|
||||||
|
progress.increaseProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::readRecord(ESM::ESMReader &reader, int32_t type)
|
void WindowManager::readRecord(ESM::ESMReader &reader, int32_t type)
|
||||||
{
|
{
|
||||||
|
if (type == ESM::REC_GMAP)
|
||||||
mMap->readRecord(reader, type);
|
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)
|
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 write (ESM::ESMWriter& writer, Loading::Listener& progress);
|
||||||
virtual void readRecord (ESM::ESMReader& reader, int32_t type);
|
virtual void readRecord (ESM::ESMReader& reader, int32_t type);
|
||||||
|
virtual int countSavedGameRecords() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool mConsoleOnlyScripts;
|
bool mConsoleOnlyScripts;
|
||||||
|
|
|
@ -201,7 +201,7 @@ void MWState::StateManager::saveGame (const std::string& description, const Slot
|
||||||
+MWBase::Environment::get().getWorld()->countSavedGameRecords()
|
+MWBase::Environment::get().getWorld()->countSavedGameRecords()
|
||||||
+MWBase::Environment::get().getScriptManager()->getGlobalScripts().countSavedGameRecords()
|
+MWBase::Environment::get().getScriptManager()->getGlobalScripts().countSavedGameRecords()
|
||||||
+MWBase::Environment::get().getDialogueManager()->countSavedGameRecords()
|
+MWBase::Environment::get().getDialogueManager()->countSavedGameRecords()
|
||||||
+1; // global map
|
+MWBase::Environment::get().getWindowManager()->countSavedGameRecords();
|
||||||
writer.setRecordCount (recordCount);
|
writer.setRecordCount (recordCount);
|
||||||
|
|
||||||
writer.save (stream);
|
writer.save (stream);
|
||||||
|
@ -323,7 +323,7 @@ void MWState::StateManager::loadGame (const Character *character, const Slot *sl
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ESM::REC_GMAP:
|
case ESM::REC_GMAP:
|
||||||
|
case ESM::REC_KEYS:
|
||||||
MWBase::Environment::get().getWindowManager()->readRecord(reader, n.val);
|
MWBase::Environment::get().getWindowManager()->readRecord(reader, n.val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,12 @@ struct Position
|
||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#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
|
enum RecNameInts
|
||||||
{
|
{
|
||||||
// format 0 / legacy
|
// format 0 / legacy
|
||||||
|
@ -93,6 +99,7 @@ enum RecNameInts
|
||||||
REC_GMAP = 0x50414d47,
|
REC_GMAP = 0x50414d47,
|
||||||
REC_DIAS = 0x53414944,
|
REC_DIAS = 0x53414944,
|
||||||
REC_WTHR = 0x52485457,
|
REC_WTHR = 0x52485457,
|
||||||
|
REC_KEYS = FourCC<'K','E','Y','S'>::value,
|
||||||
|
|
||||||
// format 1
|
// format 1
|
||||||
REC_FILT = 0x544C4946
|
REC_FILT = 0x544C4946
|
||||||
|
|
Loading…
Reference in a new issue