mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 06:53:53 +00:00
refactor and maintenance alchemywindow and alchemy
This commit is contained in:
parent
033be4e6e6
commit
f3ad16620a
4 changed files with 22 additions and 43 deletions
|
@ -147,12 +147,12 @@ namespace MWGui
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove ingredient slots that have been fully used up
|
// remove ingredient slots that have been fully used up
|
||||||
for (int i = 0; i < 4; ++i)
|
for (size_t i = 0; i < mIngredients.size(); ++i)
|
||||||
if (mIngredients[i]->isUserString("ToolTipType"))
|
if (mIngredients[i]->isUserString("ToolTipType"))
|
||||||
{
|
{
|
||||||
MWWorld::Ptr ingred = *mIngredients[i]->getUserData<MWWorld::Ptr>();
|
MWWorld::Ptr ingred = *mIngredients[i]->getUserData<MWWorld::Ptr>();
|
||||||
if (ingred.getRefData().getCount() == 0)
|
if (ingred.getRefData().getCount() == 0)
|
||||||
removeIngredient(mIngredients[i]);
|
mAlchemy->removeIngredient(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFilters();
|
updateFilters();
|
||||||
|
@ -295,7 +295,8 @@ namespace MWGui
|
||||||
|
|
||||||
void AlchemyWindow::onIngredientSelected(MyGUI::Widget* _sender)
|
void AlchemyWindow::onIngredientSelected(MyGUI::Widget* _sender)
|
||||||
{
|
{
|
||||||
removeIngredient(_sender);
|
size_t i = std::distance(mIngredients.begin(), std::find(mIngredients.begin(), mIngredients.end(), _sender));
|
||||||
|
mAlchemy->removeIngredient(i);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,10 +331,10 @@ namespace MWGui
|
||||||
|
|
||||||
void AlchemyWindow::onApparatusSelected(MyGUI::Widget* _sender)
|
void AlchemyWindow::onApparatusSelected(MyGUI::Widget* _sender)
|
||||||
{
|
{
|
||||||
|
size_t i = std::distance(mApparatus.begin(), std::find(mApparatus.begin(), mApparatus.end(), _sender));
|
||||||
if (_sender->getUserData<MWWorld::Ptr>()->isEmpty()) // if this apparatus slot is empty
|
if (_sender->getUserData<MWWorld::Ptr>()->isEmpty()) // if this apparatus slot is empty
|
||||||
{
|
{
|
||||||
std::string title;
|
std::string title;
|
||||||
size_t i = std::distance(mApparatus.begin(), std::find(mApparatus.begin(), mApparatus.end(), _sender));
|
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
case ESM::Apparatus::AppaType::MortarPestle:
|
case ESM::Apparatus::AppaType::MortarPestle:
|
||||||
|
@ -361,7 +362,17 @@ namespace MWGui
|
||||||
mItemSelectionDialog->setFilter(SortFilterItemModel::Filter_OnlyAlchemyTools);
|
mItemSelectionDialog->setFilter(SortFilterItemModel::Filter_OnlyAlchemyTools);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
removeApparatus(_sender);
|
{
|
||||||
|
const auto& widget = mApparatus[i];
|
||||||
|
mAlchemy->removeApparatus(i);
|
||||||
|
|
||||||
|
if (widget->getChildCount())
|
||||||
|
MyGUI::Gui::getInstance().destroyWidget(widget->getChildAt(0));
|
||||||
|
|
||||||
|
widget->clearUserStrings();
|
||||||
|
widget->setItem(MWWorld::Ptr());
|
||||||
|
widget->setUserData(MWWorld::Ptr());
|
||||||
|
}
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -459,35 +470,6 @@ namespace MWGui
|
||||||
effectsWidget->setCoord(coord);
|
effectsWidget->setCoord(coord);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlchemyWindow::removeIngredient(MyGUI::Widget* ingredient)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < mIngredients.size(); ++i)
|
|
||||||
if (mIngredients[i] == ingredient)
|
|
||||||
mAlchemy->removeIngredient(i);
|
|
||||||
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AlchemyWindow::removeApparatus(MyGUI::Widget* apparatus)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < mApparatus.size(); ++i)
|
|
||||||
{
|
|
||||||
if (mApparatus[i] == apparatus)
|
|
||||||
{
|
|
||||||
const auto& widget = mApparatus[i];
|
|
||||||
mAlchemy->removeApparatus(i);
|
|
||||||
|
|
||||||
if (widget->getChildCount())
|
|
||||||
MyGUI::Gui::getInstance().destroyWidget(widget->getChildAt(0));
|
|
||||||
|
|
||||||
widget->clearUserStrings();
|
|
||||||
widget->setItem(MWWorld::Ptr());
|
|
||||||
widget->setUserData(MWWorld::Ptr());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AlchemyWindow::addRepeatController(MyGUI::Widget* widget)
|
void AlchemyWindow::addRepeatController(MyGUI::Widget* widget)
|
||||||
{
|
{
|
||||||
MyGUI::ControllerItem* item
|
MyGUI::ControllerItem* item
|
||||||
|
|
|
@ -88,9 +88,6 @@ namespace MWGui
|
||||||
|
|
||||||
void onSelectedItem(int index);
|
void onSelectedItem(int index);
|
||||||
|
|
||||||
void removeIngredient(MyGUI::Widget* ingredient);
|
|
||||||
void removeApparatus(MyGUI::Widget* ingredient);
|
|
||||||
|
|
||||||
void onItemSelected(MWWorld::Ptr item);
|
void onItemSelected(MWWorld::Ptr item);
|
||||||
void onItemCancel();
|
void onItemCancel();
|
||||||
|
|
||||||
|
|
|
@ -452,9 +452,9 @@ int MWMechanics::Alchemy::addIngredient(const MWWorld::Ptr& ingredient)
|
||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MWMechanics::Alchemy::removeIngredient(int index)
|
void MWMechanics::Alchemy::removeIngredient(size_t index)
|
||||||
{
|
{
|
||||||
if (index >= 0 && index < static_cast<int>(mIngredients.size()))
|
if (index >= 0 && index < mIngredients.size())
|
||||||
{
|
{
|
||||||
mIngredients[index] = MWWorld::Ptr();
|
mIngredients[index] = MWWorld::Ptr();
|
||||||
updateEffects();
|
updateEffects();
|
||||||
|
@ -470,9 +470,9 @@ void MWMechanics::Alchemy::addApparatus(const MWWorld::Ptr& apparatus)
|
||||||
updateEffects();
|
updateEffects();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MWMechanics::Alchemy::removeApparatus(int index)
|
void MWMechanics::Alchemy::removeApparatus(size_t index)
|
||||||
{
|
{
|
||||||
if (index >= 0 && index < static_cast<int>(mTools.size()))
|
if (index >= 0 && index < mTools.size())
|
||||||
{
|
{
|
||||||
mTools[index] = MWWorld::Ptr();
|
mTools[index] = MWWorld::Ptr();
|
||||||
updateEffects();
|
updateEffects();
|
||||||
|
|
|
@ -122,10 +122,10 @@ namespace MWMechanics
|
||||||
void addApparatus(const MWWorld::Ptr& apparatus);
|
void addApparatus(const MWWorld::Ptr& apparatus);
|
||||||
///< Add apparatus into the appropriate slot.
|
///< Add apparatus into the appropriate slot.
|
||||||
|
|
||||||
void removeIngredient(int index);
|
void removeIngredient(size_t index);
|
||||||
///< Remove ingredient from slot (calling this function on an empty slot is a no-op).
|
///< Remove ingredient from slot (calling this function on an empty slot is a no-op).
|
||||||
|
|
||||||
void removeApparatus(int index);
|
void removeApparatus(size_t index);
|
||||||
///< Remove apparatus from slot.
|
///< Remove apparatus from slot.
|
||||||
|
|
||||||
std::string suggestPotionName();
|
std::string suggestPotionName();
|
||||||
|
|
Loading…
Reference in a new issue