Browse Source

Fix credits scrolling

Ivan Savenko 1 year ago
parent
commit
2796931259
2 changed files with 11 additions and 9 deletions
  1. 9 7
      client/mainmenu/CreditsScreen.cpp
  2. 2 2
      client/mainmenu/CreditsScreen.h

+ 9 - 7
client/mainmenu/CreditsScreen.cpp

@@ -22,13 +22,15 @@
 #include "../../AUTHORS.h"
 
 CreditsScreen::CreditsScreen(Rect rect)
-	: CIntObject(LCLICK), positionCounter(0)
+	: CIntObject(LCLICK), timePassed(0)
 {
 	pos.w = rect.w;
 	pos.h = rect.h;
 	setRedrawParent(true);
 	OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
 
+	addUsedEvents(TIME);
+
 	std::string contributorsText = "";
 	std::string contributorsTask = "";
 	for (auto & element : contributors) 
@@ -48,15 +50,15 @@ CreditsScreen::CreditsScreen(Rect rect)
 	credits->scrollTextTo(-600); // move all text below the screen
 }
 
-void CreditsScreen::show(Canvas & to)
+void CreditsScreen::tick(uint32_t msPassed)
 {
-	CIntObject::show(to);
-	positionCounter++;
-	if(positionCounter % 2 == 0)
-		credits->scrollTextBy(1);
+	static const int timeToScrollByOnePx = 20;
+	timePassed += msPassed;
+	int scrollPosition = timePassed / timeToScrollByOnePx - 600;
+	credits->scrollTextTo(scrollPosition);
 
 	//end of credits, close this screen
-	if(credits->textSize.y + 600 < positionCounter / 2)
+	if(credits->textSize.y < scrollPosition)
 		clickPressed(GH.getCursorPosition());
 }
 

+ 2 - 2
client/mainmenu/CreditsScreen.h

@@ -15,11 +15,11 @@ class CMultiLineLabel;
 
 class CreditsScreen : public CIntObject
 {
-	int positionCounter;
+	int timePassed;
 	std::shared_ptr<CMultiLineLabel> credits;
 
 public:
 	CreditsScreen(Rect rect);
-	void show(Canvas & to) override;
+	void tick(uint32_t msPassed) override;
 	void clickPressed(const Point & cursorPosition) override;
 };