소스 검색

vcmi: all notifications now shows inside the infobar properly

No more dangling images or text.
Konstantin 2 년 전
부모
커밋
de211e9f13
4개의 변경된 파일34개의 추가작업 그리고 25개의 파일을 삭제
  1. 19 14
      client/adventureMap/CInfoBar.cpp
  2. 1 1
      client/adventureMap/CInfoBar.h
  3. 10 8
      client/widgets/CComponent.cpp
  4. 4 2
      client/widgets/CComponent.h

+ 19 - 14
client/adventureMap/CInfoBar.cpp

@@ -173,6 +173,7 @@ CInfoBar::VisibleComponentInfo::VisibleComponentInfo(const std::vector<Component
 	auto textRect = fullRect;
 	auto imageRect = fullRect;
 	auto font = FONT_SMALL;
+	auto maxComponents = 2; 
 
 	if(!compsToDisplay.empty())
 	{
@@ -189,21 +190,24 @@ CInfoBar::VisibleComponentInfo::VisibleComponentInfo(const std::vector<Component
 							data_width - 2 * CInfoBar::offset,
 							textH);
 			imageRect = Rect(CInfoBar::offset,
-							 textH + CInfoBar::offset,
+							 textH,
 							 data_width - 2 * CInfoBar::offset,
 							 CInfoBar::data_height - 2* CInfoBar::offset - textH);
-			if(compsToDisplay.size() > 4)
-				size = CComponent::tiny;
 		}
-		if(compsToDisplay.size() > 6)
+		
+		if(compsToDisplay.size() > 4) {
+			maxComponents = 3; 
 			size = CComponent::small;
+		}
+		if(compsToDisplay.size() > 6)
+			maxComponents = 4;
 
 		std::vector<std::shared_ptr<CComponent>> vect;
 
 		for(const auto & c : compsToDisplay)
 			vect.emplace_back(std::make_shared<CComponent>(c, size, font));
 
-		comps = std::make_shared<CComponentBox>(vect, imageRect, 4, 4, 1);
+		comps = std::make_shared<CComponentBox>(vect, imageRect, 4, 4, 1, maxComponents);
 	}
 	else
 		font = tiny ? FONT_TINY : font;
@@ -216,12 +220,10 @@ int CInfoBar::getEstimatedComponentHeight(int numComps) const
 {
 	if (numComps > 8) //Bigger than 8 components - return invalid value
 		return std::numeric_limits<int>::max();
-	else if (numComps > 4)
-		return 48 + 20; // 24px * 2 rows + 20 to offset
 	else if (numComps > 2)
-		return 96 + 20; // 32px * 1 row + 20 to offset
+		return 160; // 32px * 1 row + 20 to offset
 	else if (numComps)
-		return 128; // 128 px to offset
+		return 118; // 118 px to offset
 	return 0;
 }
 
@@ -344,23 +346,23 @@ void CInfoBar::pushComponents(const std::vector<Component> & components, std::st
 				case Component::EComponentType::PRIM_SKILL:
 				case Component::EComponentType::EXPERIENCE: 
 					reward_map.at(0).first.push_back(c);
-					reward_map.at(0).second = 6; //At most 6, cannot be more
+					reward_map.at(0).second = 8; //At most 8, cannot be more
 					break;
 				case Component::EComponentType::SEC_SKILL:
 					reward_map.at(1).first.push_back(c);
-					reward_map.at(1).second = 8; //At most 8
+					reward_map.at(1).second = 4; //At most 4
 					break;
 				case Component::EComponentType::SPELL: 
 					reward_map.at(2).first.push_back(c);
-					reward_map.at(2).second = 6; //At most 6
+					reward_map.at(2).second = 4; //At most 4
 					break;
 				case Component::EComponentType::ARTIFACT:
 					reward_map.at(3).first.push_back(c);
-					reward_map.at(3).second = 6; //At most 6
+					reward_map.at(3).second = 4; //At most 4, too long names
 					break;
 				case Component::EComponentType::CREATURE:
 					reward_map.at(4).first.push_back(c);
-					reward_map.at(4).second = 8; //At most 8
+					reward_map.at(4).second = 4; //At most 4, too long names
 					break;
 				case Component::EComponentType::RESOURCE:
 					reward_map.at(5).first.push_back(c);
@@ -402,6 +404,7 @@ void CInfoBar::prepareComponents(const std::vector<Component> & components, std:
 	auto tinyH = CMessage::guessHeight(message,CInfoBar::data_width - 2 * CInfoBar::offset, FONT_TINY);
 	auto header = CMessage::guessHeader(message);
 	auto headerH = CMessage::guessHeight(header, CInfoBar::data_width - 2 * CInfoBar::offset, FONT_SMALL);
+	auto headerTinyH = CMessage::guessHeight(header, CInfoBar::data_width - 2 * CInfoBar::offset, FONT_TINY);
 
 	// Order matters - priority form should be chosen first
 	if(imageH + textH < CInfoBar::data_height)
@@ -410,6 +413,8 @@ void CInfoBar::prepareComponents(const std::vector<Component> & components, std:
 		pushComponents(components, message, tinyH, true, timer);
 	else if(imageH + headerH < CInfoBar::data_height)
 		pushComponents(components, header, headerH, false, timer);
+	else if(imageH + headerTinyH < CInfoBar::data_height - 2 * CInfoBar::offset)
+		pushComponents(components, header, headerTinyH, true, timer);
 	else
 		pushComponents(components, "", 0, false, timer);
 

+ 1 - 1
client/adventureMap/CInfoBar.h

@@ -56,7 +56,7 @@ private:
 	};
 
 	static constexpr int data_width = width - 2 * CVisibleInfo::offset_x;
-	static constexpr int data_height = height - 2 * CVisibleInfo::offset_y + 4; //yes, +4 is required
+	static constexpr int data_height = height - 2 * CVisibleInfo::offset_y;
 
 	class EmptyVisibleInfo : public CVisibleInfo
 	{

+ 10 - 8
client/widgets/CComponent.cpp

@@ -75,7 +75,7 @@ void CComponent::init(Etype Type, int Subtype, int Val, ESize imageSize, EFonts
 
 	auto max = 80;
 	if (size < large)
-		max = 60;
+		max = 72;
 	if (size < medium)
 		max = 40;
 	if (size < small)
@@ -387,7 +387,7 @@ void CComponentBox::placeComponents(bool selectable)
 
 		//start next row
 		if ((pos.w != 0 && rows.back().width + comp->pos.w + distance > pos.w) // row is full
-			|| rows.back().comps >= 4) // no more than 4 comps per row
+			|| rows.back().comps >= componentsInRow)
 		{
 			prevComp = nullptr;
 			rows.push_back (RowData (0,0,0));
@@ -453,15 +453,16 @@ void CComponentBox::placeComponents(bool selectable)
 }
 
 CComponentBox::CComponentBox(std::vector<std::shared_ptr<CComponent>> _components, Rect position):
-	CComponentBox(_components, position, defaultBetweenImagesMin, defaultBetweenSubtitlesMin, defaultBetweenRows)
+	CComponentBox(_components, position, defaultBetweenImagesMin, defaultBetweenSubtitlesMin, defaultBetweenRows, defaultComponentsInRow)
 {
 }
 
-CComponentBox::CComponentBox(std::vector<std::shared_ptr<CComponent>> _components, Rect position, int betweenImagesMin, int betweenSubtitlesMin, int betweenRows):
+CComponentBox::CComponentBox(std::vector<std::shared_ptr<CComponent>> _components, Rect position, int betweenImagesMin, int betweenSubtitlesMin, int betweenRows, int componentsInRow):
 	components(_components),
 	betweenImagesMin(betweenImagesMin),
 	betweenSubtitlesMin(betweenSubtitlesMin),
-	betweenRows(betweenRows)
+	betweenRows(betweenRows),
+	componentsInRow(componentsInRow)
 {
 	type |= REDRAW_PARENT;
 	pos = position + pos.topLeft();
@@ -469,16 +470,17 @@ CComponentBox::CComponentBox(std::vector<std::shared_ptr<CComponent>> _component
 }
 
 CComponentBox::CComponentBox(std::vector<std::shared_ptr<CSelectableComponent>> _components, Rect position, std::function<void(int newID)> _onSelect):
-	CComponentBox(_components, position, _onSelect, defaultBetweenImagesMin, defaultBetweenSubtitlesMin, defaultBetweenRows)
+	CComponentBox(_components, position, _onSelect, defaultBetweenImagesMin, defaultBetweenSubtitlesMin, defaultBetweenRows, defaultComponentsInRow)
 {
 }
 
-CComponentBox::CComponentBox(std::vector<std::shared_ptr<CSelectableComponent>> _components, Rect position, std::function<void(int newID)> _onSelect, int betweenImagesMin, int betweenSubtitlesMin, int betweenRows):
+CComponentBox::CComponentBox(std::vector<std::shared_ptr<CSelectableComponent>> _components, Rect position, std::function<void(int newID)> _onSelect, int betweenImagesMin, int betweenSubtitlesMin, int betweenRows, int componentsInRow):
 	components(_components.begin(), _components.end()),
 	onSelect(_onSelect),
 	betweenImagesMin(betweenImagesMin),
 	betweenSubtitlesMin(betweenSubtitlesMin),
-	betweenRows(betweenRows)
+	betweenRows(betweenRows),
+	componentsInRow(componentsInRow)
 {
 	type |= REDRAW_PARENT;
 	pos = position + pos.topLeft();

+ 4 - 2
client/widgets/CComponent.h

@@ -98,10 +98,12 @@ class CComponentBox : public CIntObject
 	static constexpr int defaultBetweenImagesMin = 20;
 	static constexpr int defaultBetweenSubtitlesMin = 10;
 	static constexpr int defaultBetweenRows = 22;
+	static constexpr int defaultComponentsInRow = 4;
 
 	int betweenImagesMin;
 	int betweenSubtitlesMin;
 	int betweenRows;
+	int componentsInRow;
 
 	void selectionChanged(std::shared_ptr<CSelectableComponent> newSelection);
 
@@ -119,11 +121,11 @@ public:
 
 	/// constructors for non-selectable components
 	CComponentBox(std::vector<std::shared_ptr<CComponent>> components, Rect position);
-	CComponentBox(std::vector<std::shared_ptr<CComponent>> components, Rect position, int betweenImagesMin, int betweenSubtitlesMin, int betweenRows);
+	CComponentBox(std::vector<std::shared_ptr<CComponent>> components, Rect position, int betweenImagesMin, int betweenSubtitlesMin, int betweenRows, int componentsInRow);
 
 	/// constructor for selectable components
 	/// will also create "or" labels between components
 	/// onSelect - optional function that will be called every time on selection change
 	CComponentBox(std::vector<std::shared_ptr<CSelectableComponent>> components, Rect position, std::function<void(int newID)> onSelect = nullptr);
-	CComponentBox(std::vector<std::shared_ptr<CSelectableComponent>> components, Rect position, std::function<void(int newID)> onSelect, int betweenImagesMin, int betweenSubtitlesMin, int betweenRows);
+	CComponentBox(std::vector<std::shared_ptr<CSelectableComponent>> components, Rect position, std::function<void(int newID)> onSelect, int betweenImagesMin, int betweenSubtitlesMin, int betweenRows, int componentsInRow);
 };