Browse Source

CSplitWindow: added input check

This one fixes issue 1952
ArseniyShestakov 11 years ago
parent
commit
94d0e5486a
1 changed files with 17 additions and 6 deletions
  1. 17 6
      client/windows/GUIClasses.cpp

+ 17 - 6
client/windows/GUIClasses.cpp

@@ -400,14 +400,25 @@ CSplitWindow::CSplitWindow(const CCreature * creature, std::function<void(int, i
 
 void CSplitWindow::setAmountText(std::string text, bool left)
 {
-	try
-	{
-		setAmount(boost::lexical_cast<int>(text), left);
-		slider->moveTo(rightAmount - rightMin);
-	}
-	catch(boost::bad_lexical_cast &)
+	int amount = 0;
+	if (text.length())
 	{
+		try
+		{
+			amount = boost::lexical_cast<int>(text);
+		}
+		catch(boost::bad_lexical_cast &)
+		{
+			amount = left ? leftAmount : rightAmount;
+		}
+
+		int total = leftAmount + rightAmount;
+		if (amount > total)
+			amount = total;
 	}
+
+	setAmount(amount, left);
+	slider->moveTo(rightAmount - rightMin);
 }
 
 void CSplitWindow::setAmount(int value, bool left)