Browse Source

Fix infinitely updating simultaneous turns slider

Ivan Savenko 1 year ago
parent
commit
2c42737b28
3 changed files with 12 additions and 11 deletions
  1. 3 3
      client/lobby/OptionsTabBase.cpp
  2. 6 5
      client/widgets/Slider.cpp
  3. 3 3
      client/widgets/Slider.h

+ 3 - 3
client/lobby/OptionsTabBase.cpp

@@ -340,10 +340,10 @@ void OptionsTabBase::recreate(bool campaign)
 
 	//Simultaneous turns
 	if(auto turnSlider = widget<CSlider>("simturnsDurationMin"))
-		turnSlider->setValue(SEL->getStartInfo()->simturnsInfo.requiredTurns);
+		turnSlider->setValue(SEL->getStartInfo()->simturnsInfo.requiredTurns, false);
 
 	if(auto turnSlider = widget<CSlider>("simturnsDurationMax"))
-		turnSlider->setValue(SEL->getStartInfo()->simturnsInfo.optionalTurns);
+		turnSlider->setValue(SEL->getStartInfo()->simturnsInfo.optionalTurns, false);
 
 	if(auto w = widget<CLabel>("labelSimturnsDurationValueMin"))
 		w->setText(generateSimturnsDurationText(SEL->getStartInfo()->simturnsInfo.requiredTurns));
@@ -388,7 +388,7 @@ void OptionsTabBase::recreate(bool campaign)
 				auto & tpreset = variables["timerPresets"].Vector()[idx];
 				if(tpreset.Vector().at(1).Integer() == turnTimerRemote.turnTimer / 1000)
 				{
-					turnSlider->scrollTo(idx);
+					turnSlider->scrollTo(idx, false);
 					if(auto w = widget<CLabel>("labelTurnDurationValue"))
 						w->setText(CGI->generaltexth->turnDurations[idx]);
 				}

+ 6 - 5
client/widgets/Slider.cpp

@@ -70,7 +70,7 @@ int CSlider::getValue() const
 	return value;
 }
 
-void CSlider::setValue(int to)
+void CSlider::setValue(int to, bool callCallbacks)
 {
 	scrollTo(value);
 }
@@ -113,7 +113,7 @@ void CSlider::updateSliderPos()
 	}
 }
 
-void CSlider::scrollTo(int to)
+void CSlider::scrollTo(int to, bool callCallbacks)
 {
 	vstd::amax(to, 0);
 	vstd::amin(to, positions);
@@ -125,7 +125,8 @@ void CSlider::scrollTo(int to)
 
 	updateSliderPos();
 
-	moved(getValue());
+	if (callCallbacks)
+		moved(getValue());
 }
 
 void CSlider::clickPressed(const Point & cursorPosition)
@@ -321,7 +322,7 @@ int SliderNonlinear::getValue() const
 	return scaledValues.at(CSlider::getValue());
 }
 
-void SliderNonlinear::setValue(int to)
+void SliderNonlinear::setValue(int to, bool callCallbacks)
 {
 	size_t nearest = 0;
 
@@ -334,5 +335,5 @@ void SliderNonlinear::setValue(int to)
 			nearest = i;
 	}
 
-	scrollTo(nearest);
+	scrollTo(nearest, callCallbacks);
 }

+ 3 - 3
client/widgets/Slider.h

@@ -52,14 +52,14 @@ public:
 	void clearScrollBounds();
 
 	/// Value modifiers
-	void scrollTo(int value);
+	void scrollTo(int value, bool callCallbacks = true);
 	void scrollBy(int amount) override;
 	void scrollToMin();
 	void scrollToMax();
 
 	/// Amount modifier
 	void setAmount(int to);
-	virtual void setValue(int to);
+	virtual void setValue(int to, bool callCallbacks = true);
 
 	/// Accessors
 	int getAmount() const;
@@ -95,7 +95,7 @@ class SliderNonlinear : public CSlider
 
 	using CSlider::setAmount; // make private
 public:
-	void setValue(int to) override;
+	void setValue(int to, bool callCallbacks) override;
 	int getValue() const override;
 
 	SliderNonlinear(Point position, int length, const std::function<void(int)> & Moved, const std::vector<int> & values, int Value, Orientation orientation, EStyle style);