Browse Source

Merge pull request #4780 from Laserlicht/text_pos_fix

fix: campaign video scrolling for short texts
Ivan Savenko 1 year ago
parent
commit
52e0899d6f

+ 4 - 1
client/mainmenu/CPrologEpilogVideo.cpp

@@ -60,7 +60,10 @@ CPrologEpilogVideo::CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::f
 	CCS->soundh->setCallback(voiceSoundHandle, onVoiceStop);
 
 	text = std::make_shared<CMultiLineLabel>(Rect(100, 500, 600, 100), EFonts::FONT_BIG, ETextAlignment::CENTER, Colors::METALLIC_GOLD, spe.prologText.toString());
-	text->scrollTextTo(-50); // beginning of text in the vertical middle of black area
+	if(text->getLines().size() == 3)
+		text->scrollTextTo(-25); // beginning of text in the vertical middle of black area
+	else if(text->getLines().size() > 3)
+		text->scrollTextTo(-50); // beginning of text in the vertical middle of black area
 }
 
 void CPrologEpilogVideo::tick(uint32_t msPassed)

+ 5 - 0
client/widgets/TextControls.cpp

@@ -176,6 +176,11 @@ void CMultiLineLabel::setText(const std::string & Txt)
 	CLabel::setText(Txt);
 }
 
+std::vector<std::string> CMultiLineLabel::getLines()
+{
+	return lines;
+}
+
 void CTextContainer::blitLine(Canvas & to, Rect destRect, std::string what)
 {
 	const auto f = GH.renderHandler().loadFont(font);

+ 1 - 0
client/widgets/TextControls.h

@@ -96,6 +96,7 @@ public:
 	CMultiLineLabel(Rect position, EFonts Font = FONT_SMALL, ETextAlignment Align = ETextAlignment::TOPLEFT, const ColorRGBA & Color = Colors::WHITE, const std::string & Text = "");
 
 	void setText(const std::string & Txt) override;
+	std::vector<std::string> getLines();
 	void showAll(Canvas & to) override;
 
 	void setVisibleSize(Rect visibleSize, bool redrawElement = true);