mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-21 05:39:42 +00:00
Improve GUI mode validation
This commit is contained in:
parent
f1bcf64afb
commit
36d22cff1c
17 changed files with 61 additions and 10 deletions
|
@ -580,7 +580,7 @@ namespace MWDialogue
|
|||
|
||||
void DialogueManager::applyBarterDispositionChange(int delta)
|
||||
{
|
||||
if (mActor.getClass().isNpc())
|
||||
if (!mActor.isEmpty() && mActor.getClass().isNpc())
|
||||
{
|
||||
updateOriginalDisposition();
|
||||
mCurrentDisposition += delta;
|
||||
|
|
|
@ -83,6 +83,8 @@ namespace MWGui
|
|||
|
||||
void BookWindow::setPtr(const MWWorld::Ptr& book)
|
||||
{
|
||||
if (book.isEmpty() || book.getType() != ESM::REC_BOOK)
|
||||
throw std::runtime_error("Invalid argument in BookWindow::setPtr");
|
||||
mBook = book;
|
||||
|
||||
MWWorld::Ptr player = MWMechanics::getPlayer();
|
||||
|
|
|
@ -121,6 +121,8 @@ namespace MWGui
|
|||
|
||||
void CompanionWindow::setPtr(const MWWorld::Ptr& npc)
|
||||
{
|
||||
if (npc.isEmpty() || npc.getType() != ESM::REC_NPC_)
|
||||
throw std::runtime_error("Invalid argument in CompanionWindow::setPtr");
|
||||
mPtr = npc;
|
||||
updateEncumbranceBar();
|
||||
auto model = std::make_unique<CompanionItemModel>(npc);
|
||||
|
|
|
@ -124,6 +124,8 @@ namespace MWGui
|
|||
|
||||
void ContainerWindow::setPtr(const MWWorld::Ptr& container)
|
||||
{
|
||||
if (container.isEmpty() || (container.getType() != ESM::REC_CONT && !container.getClass().isActor()))
|
||||
throw std::runtime_error("Invalid argument in ContainerWindow::setPtr");
|
||||
bool lootAnyway = mTreatNextOpenAsLoot;
|
||||
mTreatNextOpenAsLoot = false;
|
||||
mPtr = container;
|
||||
|
@ -191,6 +193,8 @@ namespace MWGui
|
|||
|
||||
void ContainerWindow::onTakeAllButtonClicked(MyGUI::Widget* _sender)
|
||||
{
|
||||
if (!mModel)
|
||||
return;
|
||||
if (mDragAndDrop != nullptr && mDragAndDrop->mIsOnDragAndDrop)
|
||||
return;
|
||||
|
||||
|
|
|
@ -446,7 +446,7 @@ namespace MWGui
|
|||
|
||||
void DialogueWindow::setPtr(const MWWorld::Ptr& actor)
|
||||
{
|
||||
if (!actor.getClass().isActor())
|
||||
if (actor.isEmpty() || !actor.getClass().isActor())
|
||||
{
|
||||
Log(Debug::Warning) << "Warning: can not talk with non-actor object.";
|
||||
return;
|
||||
|
|
|
@ -139,6 +139,9 @@ namespace MWGui
|
|||
|
||||
void EnchantingDialog::setPtr(const MWWorld::Ptr& ptr)
|
||||
{
|
||||
if (ptr.isEmpty() || (ptr.getType() != ESM::REC_MISC && !ptr.getClass().isActor()))
|
||||
throw std::runtime_error("Invalid argument in EnchantingDialog::setPtr");
|
||||
|
||||
mName->setCaption({});
|
||||
|
||||
if (ptr.getClass().isActor())
|
||||
|
|
|
@ -32,6 +32,8 @@ namespace MWGui
|
|||
|
||||
void MerchantRepair::setPtr(const MWWorld::Ptr& actor)
|
||||
{
|
||||
if (actor.isEmpty() || !actor.getClass().isActor())
|
||||
throw std::runtime_error("Invalid argument in MerchantRepair::setPtr");
|
||||
mActor = actor;
|
||||
|
||||
while (mList->getChildCount())
|
||||
|
|
|
@ -56,6 +56,9 @@ namespace MWGui
|
|||
|
||||
void Recharge::setPtr(const MWWorld::Ptr& item)
|
||||
{
|
||||
if (item.isEmpty() || !item.getClass().isItem(item))
|
||||
throw std::runtime_error("Invalid argument in Recharge::setPtr");
|
||||
|
||||
mGemIcon->setItem(item);
|
||||
mGemIcon->setUserString("ToolTipType", "ItemPtr");
|
||||
mGemIcon->setUserData(MWWorld::Ptr(item));
|
||||
|
|
|
@ -56,6 +56,9 @@ namespace MWGui
|
|||
|
||||
void Repair::setPtr(const MWWorld::Ptr& item)
|
||||
{
|
||||
if (item.isEmpty() || !item.getClass().isItem(item))
|
||||
throw std::runtime_error("Invalid argument in Repair::setPtr");
|
||||
|
||||
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Item Repair Up"));
|
||||
|
||||
mRepair.setTool(item);
|
||||
|
|
|
@ -42,6 +42,8 @@ namespace MWGui
|
|||
|
||||
void ScrollWindow::setPtr(const MWWorld::Ptr& scroll)
|
||||
{
|
||||
if (scroll.isEmpty() || scroll.getType() != ESM::REC_BOOK)
|
||||
throw std::runtime_error("Invalid argument in ScrollWindow::setPtr");
|
||||
mScroll = scroll;
|
||||
|
||||
MWWorld::Ptr player = MWMechanics::getPlayer();
|
||||
|
|
|
@ -88,6 +88,9 @@ namespace MWGui
|
|||
|
||||
void SpellBuyingWindow::setPtr(const MWWorld::Ptr& actor, int startOffset)
|
||||
{
|
||||
if (actor.isEmpty() || !actor.getClass().isActor())
|
||||
throw std::runtime_error("Invalid argument in SpellBuyingWindow::setPtr");
|
||||
|
||||
center();
|
||||
mPtr = actor;
|
||||
clearSpells();
|
||||
|
|
|
@ -364,6 +364,9 @@ namespace MWGui
|
|||
|
||||
void SpellCreationDialog::setPtr(const MWWorld::Ptr& actor)
|
||||
{
|
||||
if (actor.isEmpty() || !actor.getClass().isActor())
|
||||
throw std::runtime_error("Invalid argument in SpellCreationDialog::setPtr");
|
||||
|
||||
mPtr = actor;
|
||||
mNameEdit->setCaption({});
|
||||
|
||||
|
|
|
@ -102,6 +102,8 @@ namespace MWGui
|
|||
|
||||
void TradeWindow::setPtr(const MWWorld::Ptr& actor)
|
||||
{
|
||||
if (actor.isEmpty() || !actor.getClass().isActor())
|
||||
throw std::runtime_error("Invalid argument in TradeWindow::setPtr");
|
||||
mPtr = actor;
|
||||
|
||||
mCurrentBalance = 0;
|
||||
|
|
|
@ -53,6 +53,8 @@ namespace MWGui
|
|||
|
||||
void TrainingWindow::setPtr(const MWWorld::Ptr& actor)
|
||||
{
|
||||
if (actor.isEmpty() || !actor.getClass().isActor())
|
||||
throw std::runtime_error("Invalid argument in TrainingWindow::setPtr");
|
||||
mPtr = actor;
|
||||
|
||||
MWWorld::Ptr player = MWMechanics::getPlayer();
|
||||
|
|
|
@ -112,6 +112,9 @@ namespace MWGui
|
|||
|
||||
void TravelWindow::setPtr(const MWWorld::Ptr& actor)
|
||||
{
|
||||
if (actor.isEmpty() || !actor.getClass().isActor())
|
||||
throw std::runtime_error("Invalid argument in TravelWindow::setPtr");
|
||||
|
||||
center();
|
||||
mPtr = actor;
|
||||
clearDestinations();
|
||||
|
|
|
@ -1278,8 +1278,17 @@ namespace MWGui
|
|||
}
|
||||
if (force)
|
||||
mContainerWindow->treatNextOpenAsLoot();
|
||||
for (WindowBase* window : mGuiModeStates[mode].mWindows)
|
||||
window->setPtr(arg);
|
||||
|
||||
try
|
||||
{
|
||||
for (WindowBase* window : mGuiModeStates[mode].mWindows)
|
||||
window->setPtr(arg);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
popGuiMode();
|
||||
throw;
|
||||
}
|
||||
|
||||
mKeyboardNavigation->restoreFocus(mode);
|
||||
|
||||
|
|
|
@ -51,18 +51,29 @@ local function updateHidden(mode, options)
|
|||
end
|
||||
|
||||
local function setMode(mode, options)
|
||||
if mode then
|
||||
local function impl()
|
||||
updateHidden(mode, options)
|
||||
ui._setUiModeStack({mode}, options and options.target)
|
||||
end
|
||||
if mode then
|
||||
if not pcall(impl) then
|
||||
error('Invalid mode: ' .. tostring(mode))
|
||||
end
|
||||
else
|
||||
ui._setUiModeStack({})
|
||||
end
|
||||
end
|
||||
|
||||
local function addMode(mode, options)
|
||||
updateHidden(mode, options)
|
||||
local function impl()
|
||||
updateHidden(mode, options)
|
||||
ui._setUiModeStack(modeStack, options and options.target)
|
||||
end
|
||||
modeStack[#modeStack + 1] = mode
|
||||
ui._setUiModeStack(modeStack, options and options.target)
|
||||
if not pcall(impl) then
|
||||
modeStack[#modeStack] = nil
|
||||
error('Invalid mode: ' .. tostring(mode))
|
||||
end
|
||||
end
|
||||
|
||||
local function removeMode(mode)
|
||||
|
@ -181,7 +192,4 @@ return {
|
|||
engineHandlers = {
|
||||
_onUiModeChanged = onUiModeChanged,
|
||||
},
|
||||
eventHandlers = {
|
||||
UiModeChanged = function() end,
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue