Ignore invalid input in numeric EditBox (Fixes #1885)

This commit is contained in:
scrawl 2014-09-08 15:22:33 +02:00
parent f3f869e99a
commit 07d827c907

View file

@ -436,6 +436,10 @@ namespace MWGui
} }
catch (std::bad_cast&) catch (std::bad_cast&)
{ {
if (_sender->getCaption().empty())
mTotalBalance->setCaption("0");
else
mTotalBalance->setCaption(boost::lexical_cast<std::string>(std::abs(mCurrentBalance)));
} }
} }
@ -460,16 +464,19 @@ namespace MWGui
mPlayerGold->setCaptionWithReplacing("#{sYourGold} " + boost::lexical_cast<std::string>(playerGold)); mPlayerGold->setCaptionWithReplacing("#{sYourGold} " + boost::lexical_cast<std::string>(playerGold));
std::string balanceCaption;
if (mCurrentBalance > 0) if (mCurrentBalance > 0)
{ {
mTotalBalanceLabel->setCaptionWithReplacing("#{sTotalSold}"); mTotalBalanceLabel->setCaptionWithReplacing("#{sTotalSold}");
mTotalBalance->setCaption(boost::lexical_cast<std::string>(mCurrentBalance)); balanceCaption = boost::lexical_cast<std::string>(mCurrentBalance);
} }
else else
{ {
mTotalBalanceLabel->setCaptionWithReplacing("#{sTotalCost}"); mTotalBalanceLabel->setCaptionWithReplacing("#{sTotalCost}");
mTotalBalance->setCaption(boost::lexical_cast<std::string>(-mCurrentBalance)); balanceCaption = boost::lexical_cast<std::string>(-mCurrentBalance);
} }
if (balanceCaption != mTotalBalance->getCaption().asUTF8()) // Don't reset text cursor if text doesn't need to be changed
mTotalBalance->setCaption(balanceCaption);
mMerchantGold->setCaptionWithReplacing("#{sSellerGold} " + boost::lexical_cast<std::string>(getMerchantGold())); mMerchantGold->setCaptionWithReplacing("#{sSellerGold} " + boost::lexical_cast<std::string>(getMerchantGold()));
} }