add keyData struct + general cleanup

pull/456/head
Finbar Crago 7 years ago
parent cac6d59140
commit 335e2c5897

@ -43,27 +43,21 @@ namespace MWGui
getWidget(mInstructionLabel, "InstructionLabel");
mMainWidget->setSize(mMainWidget->getWidth(),
mMainWidget->getHeight() + (mInstructionLabel->getTextSize().height - mInstructionLabel->getHeight()));
mMainWidget->getHeight() +
(mInstructionLabel->getTextSize().height - mInstructionLabel->getHeight()));
mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &QuickKeysMenu::onOkButtonClicked);
center();
mKey = std::vector<struct keyData>(10);
for (int i = 0; i < 10; ++i)
{
ItemWidget* button;
getWidget(button, "QuickKey" + MyGUI::utility::toString(i+1));
mKey[i].index = i;
getWidget(mKey[i].button, "QuickKey" + MyGUI::utility::toString(i+1));
mKey[i].button->eventMouseButtonClick += MyGUI::newDelegate(this, &QuickKeysMenu::onQuickKeyButtonClicked);
button->eventMouseButtonClick += MyGUI::newDelegate(this, &QuickKeysMenu::onQuickKeyButtonClicked);
mQuickKeyButtons.push_back(button);
mAssigned.push_back(Type_Unassigned);
mAssignedId.push_back(std::string(""));
mAssignedName.push_back(std::string(""));
unassign(button, i);
unassign(&mKey[i]);
}
}
@ -73,7 +67,7 @@ namespace MWGui
for (int i=0; i<10; ++i)
{
unassign(mQuickKeyButtons[i], i);
unassign(&mKey[i]);
}
}
@ -94,10 +88,7 @@ namespace MWGui
// Check if quick keys are still valid
for (int i=0; i<10; ++i)
{
ItemWidget* button = mQuickKeyButtons[i];
int type = mAssigned[i];
switch (type)
switch (mKey[i].type)
{
case Type_Unassigned:
case Type_HandToHand:
@ -106,7 +97,7 @@ namespace MWGui
case Type_Item:
case Type_MagicItem:
{
MWWorld::Ptr item = *button->getUserData<MWWorld::Ptr>();
MWWorld::Ptr item = *mKey[i].button->getUserData<MWWorld::Ptr>();
// Make sure the item is available and is not broken
if (item.getRefData().getCount() < 1 ||
(item.getClass().hasItemHealth(item) &&
@ -116,41 +107,43 @@ namespace MWGui
std::string id = item.getCellRef().getRefId();
item = store.findReplacement(id);
button->setUserData(MWWorld::Ptr(item));
mKey[i].button->setUserData(MWWorld::Ptr(item));
break;
}
}
}
}
}
void QuickKeysMenu::unassign(ItemWidget* key, int index)
void QuickKeysMenu::unassign(struct keyData* key)
{
mAssignedName[index] = "";
mAssignedId[index] = "";
key->button->clearUserStrings();
key->button->setItem(MWWorld::Ptr());
key->clearUserStrings();
key->setItem(MWWorld::Ptr());
while (key->getChildCount()) // Destroy number label
MyGUI::Gui::getInstance().destroyWidget(key->getChildAt(0));
while(key->button->getChildCount()) // Destroy number label
MyGUI::Gui::getInstance().destroyWidget(key->button->getChildAt(0));
if (index == 9)
if (key->index == 9)
{
mAssigned[index] = Type_HandToHand;
key->type = Type_HandToHand;
MyGUI::ImageBox* image = key->createWidget<MyGUI::ImageBox>("ImageBox",
MyGUI::ImageBox* image = key->button->createWidget<MyGUI::ImageBox>("ImageBox",
MyGUI::IntCoord(14, 13, 32, 32), MyGUI::Align::Default);
image->setImageTexture("icons\\k\\stealth_handtohand.dds");
image->setNeedMouseFocus(false);
}
else
{
mAssigned[index] = Type_Unassigned;
key->type = Type_Unassigned;
key->id = "";
key->name = "";
MyGUI::TextBox* textBox = key->button->createWidgetReal<MyGUI::TextBox>("SandText",
MyGUI::FloatCoord(0,0,1,1), MyGUI::Align::Default);
MyGUI::TextBox* textBox = key->createWidgetReal<MyGUI::TextBox>("SandText", MyGUI::FloatCoord(0,0,1,1), MyGUI::Align::Default);
textBox->setTextAlign(MyGUI::Align::Center);
textBox->setCaption (MyGUI::utility::toString(index+1));
textBox->setCaption(MyGUI::utility::toString(key->index + 1));
textBox->setNeedMouseFocus(false);
}
}
@ -160,7 +153,7 @@ namespace MWGui
int index = -1;
for(int i = 0; i < 10; ++i)
{
if (sender == mQuickKeyButtons[i] || sender->getParent () == mQuickKeyButtons[i])
if(sender == mKey[i].button || sender->getParent() == mKey[i].button)
{
index = i;
break;
@ -172,6 +165,7 @@ namespace MWGui
// open assign dialog
if(!mAssignDialog)
mAssignDialog = new QuickKeysMenuAssign(this);
mAssignDialog->setVisible(true);
}
@ -180,7 +174,6 @@ namespace MWGui
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_QuickKeysMenu);
}
void QuickKeysMenu::onItemButtonClicked(MyGUI::Widget* sender)
{
if (!mItemSelectionDialog )
@ -209,7 +202,7 @@ namespace MWGui
void QuickKeysMenu::onUnassignButtonClicked(MyGUI::Widget* sender)
{
unassign(mQuickKeyButtons[mSelectedIndex], mSelectedIndex);
unassign(&mKey[mSelectedIndex]);
mAssignDialog->setVisible(false);
}
@ -221,17 +214,17 @@ namespace MWGui
void QuickKeysMenu::onAssignItem(MWWorld::Ptr item)
{
assert(mSelectedIndex >= 0);
ItemWidget* button = mQuickKeyButtons[mSelectedIndex];
while (button->getChildCount()) // Destroy number label
MyGUI::Gui::getInstance().destroyWidget(button->getChildAt(0));
mAssigned[mSelectedIndex] = Type_Item;
mAssignedId[mSelectedIndex] = item.getCellRef().getRefId();
mAssignedName[mSelectedIndex] = item.getClass().getName(item);
while(mKey[mSelectedIndex].button->getChildCount()) // Destroy number label
MyGUI::Gui::getInstance().destroyWidget(mKey[mSelectedIndex].button->getChildAt(0));
button->setItem(item, ItemWidget::Barter);
button->setUserString ("ToolTipType", "ItemPtr");
button->setUserData(item);
mKey[mSelectedIndex].type = Type_Item;
mKey[mSelectedIndex].id = item.getCellRef().getRefId();
mKey[mSelectedIndex].name = item.getClass().getName(item);
mKey[mSelectedIndex].button->setItem(item, ItemWidget::Barter);
mKey[mSelectedIndex].button->setUserString("ToolTipType", "ItemPtr");
mKey[mSelectedIndex].button->setUserData(item);
if(mItemSelectionDialog)
mItemSelectionDialog->setVisible(false);
@ -245,17 +238,17 @@ namespace MWGui
void QuickKeysMenu::onAssignMagicItem(MWWorld::Ptr item)
{
assert(mSelectedIndex >= 0);
ItemWidget* button = mQuickKeyButtons[mSelectedIndex];
while (button->getChildCount()) // Destroy number label
MyGUI::Gui::getInstance().destroyWidget(button->getChildAt(0));
mAssigned[mSelectedIndex] = Type_MagicItem;
while(mKey[mSelectedIndex].button->getChildCount()) // Destroy number label
MyGUI::Gui::getInstance().destroyWidget(mKey[mSelectedIndex].button->getChildAt(0));
button->setFrame("textures\\menu_icon_select_magic_magic.dds", MyGUI::IntCoord(2, 2, 40, 40));
button->setIcon(item);
mKey[mSelectedIndex].type = Type_MagicItem;
button->setUserString ("ToolTipType", "ItemPtr");
button->setUserData(MWWorld::Ptr(item));
mKey[mSelectedIndex].button->setFrame("textures\\menu_icon_select_magic_magic.dds", MyGUI::IntCoord(2, 2, 40, 40));
mKey[mSelectedIndex].button->setIcon(item);
mKey[mSelectedIndex].button->setUserString ("ToolTipType", "ItemPtr");
mKey[mSelectedIndex].button->setUserData(MWWorld::Ptr(item));
if(mMagicSelectionDialog)
mMagicSelectionDialog->setVisible(false);
@ -264,15 +257,15 @@ namespace MWGui
void QuickKeysMenu::onAssignMagic(const std::string& spellId)
{
assert(mSelectedIndex >= 0);
ItemWidget* button = mQuickKeyButtons[mSelectedIndex];
while (button->getChildCount()) // Destroy number label
ItemWidget* button = mKey[mSelectedIndex].button;
while(mKey[mSelectedIndex].button->getChildCount()) // Destroy number label
MyGUI::Gui::getInstance().destroyWidget(button->getChildAt(0));
mAssigned[mSelectedIndex] = Type_Magic;
mKey[mSelectedIndex].type = Type_Magic;
button->setItem(MWWorld::Ptr());
button->setUserString ("ToolTipType", "Spell");
button->setUserString ("Spell", spellId);
mKey[mSelectedIndex].button->setItem(MWWorld::Ptr());
mKey[mSelectedIndex].button->setUserString("ToolTipType", "Spell");
mKey[mSelectedIndex].button->setUserString("Spell", spellId);
const MWWorld::ESMStore &esmStore =
MWBase::Environment::get().getWorld()->getStore();
@ -312,9 +305,8 @@ namespace MWGui
void QuickKeysMenu::activateQuickKey(int index)
{
assert(index-1 >= 0);
ItemWidget* button = mQuickKeyButtons[index-1];
QuickKeyType type = mAssigned[index-1];
ItemWidget* button = mKey[index-1].button;
QuickKeyType type = mKey[index-1].type;
MWWorld::Ptr player = MWMechanics::getPlayer();
MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player);
@ -351,17 +343,17 @@ namespace MWGui
break;
}
if (it == store.end())
item = NULL;
item = nullptr;
// check the item is available and not broken
if (!item || item.getRefData().getCount() < 1 ||
(item.getClass().hasItemHealth(item) && item.getClass().getItemHealth(item) <= 0))
{
item = store.findReplacement(mAssignedId[index-1]);
item = store.findReplacement(mKey[index-1].id);
if (!item || item.getRefData().getCount() < 1)
{
MWBase::Environment::get().getWindowManager()->messageBox(
"#{sQuickMenu5} " + mAssignedName[index-1]);
"#{sQuickMenu5} " + mKey[index-1].name);
return;
}
@ -490,9 +482,9 @@ namespace MWGui
for (int i=0; i<10; ++i)
{
ItemWidget* button = mQuickKeyButtons[i];
ItemWidget* button = mKey[i].button;
int type = mAssigned[i];
int type = mKey[i].type;
ESM::QuickKeys::QuickKey key;
key.mType = type;
@ -543,7 +535,6 @@ namespace MWGui
mSelectedIndex = i;
int keyType = it->mType;
std::string id = it->mId;
ItemWidget* button = mQuickKeyButtons[i];
switch (keyType)
{
@ -558,7 +549,7 @@ namespace MWGui
MWWorld::Ptr item = store.findReplacement(id);
if(item.isEmpty())
unassign(button, i);
unassign(&mKey[i]);
else
{
if(keyType == Type_Item)
@ -571,7 +562,7 @@ namespace MWGui
}
case Type_Unassigned:
case Type_HandToHand:
unassign(button, i);
unassign(&mKey[i]);
break;
}

@ -2,7 +2,6 @@
#define MWGUI_QUICKKEYS_H
#include "../mwworld/ptr.hpp"
#include "../mwworld/containerstore.hpp"
#include "windowbase.hpp"
@ -56,14 +55,21 @@ namespace MWGui
private:
struct keyData {
int index;
ItemWidget* button;
QuickKeysMenu::QuickKeyType type;
std::string id;
std::string name;
keyData(): index(-1), button(nullptr), type(Type_Unassigned), id(""), name("") {}
};
std::vector<struct keyData> mKey;
MyGUI::EditBox* mInstructionLabel;
MyGUI::Button* mOkButton;
std::vector<ItemWidget*> mQuickKeyButtons;
std::vector<QuickKeyType> mAssigned;
std::vector<std::string> mAssignedId;
std::vector<std::string> mAssignedName;
QuickKeysMenuAssign* mAssignDialog;
ItemSelectionDialog* mItemSelectionDialog;
MagicSelectionDialog* mMagicSelectionDialog;
@ -74,7 +80,7 @@ namespace MWGui
void onQuickKeyButtonClicked(MyGUI::Widget* sender);
void onOkButtonClicked(MyGUI::Widget* sender);
void unassign(ItemWidget* key, int index);
void unassign(struct keyData* key);
};
class QuickKeysMenuAssign : public WindowModal

Loading…
Cancel
Save