mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Merge pull request #5160 from Laserlicht/alt_town
[1.6.2] show building names with ALT
This commit is contained in:
		| @@ -81,6 +81,8 @@ public: | ||||
| 	//test transparency of specific pixel | ||||
| 	virtual bool isTransparent(const Point & coords) const = 0; | ||||
|  | ||||
| 	virtual Rect contentRect() const = 0; | ||||
|  | ||||
| 	virtual Point dimensions() const = 0; | ||||
| 	int width() const; | ||||
| 	int height() const; | ||||
| @@ -109,6 +111,7 @@ public: | ||||
| 	virtual Point dimensions() const = 0; | ||||
| 	virtual void exportBitmap(const boost::filesystem::path & path, SDL_Palette * palette) const = 0; | ||||
| 	virtual bool isTransparent(const Point & coords) const = 0; | ||||
| 	virtual Rect contentRect() const = 0; | ||||
| 	virtual void draw(SDL_Surface * where, SDL_Palette * palette, const Point & dest, const Rect * src, const ColorRGBA & colorMultiplier, uint8_t alpha, EImageBlitMode mode) const = 0; | ||||
|  | ||||
| 	[[nodiscard]] virtual std::shared_ptr<IImage> createImageReference(EImageBlitMode mode) const = 0; | ||||
|   | ||||
| @@ -60,6 +60,11 @@ bool ImageScaled::isTransparent(const Point &coords) const | ||||
| 	return source->isTransparent(coords); | ||||
| } | ||||
|  | ||||
| Rect ImageScaled::contentRect() const | ||||
| { | ||||
| 	return source->contentRect(); | ||||
| } | ||||
|  | ||||
| Point ImageScaled::dimensions() const | ||||
| { | ||||
| 	return source->dimensions(); | ||||
|   | ||||
| @@ -52,6 +52,7 @@ public: | ||||
| 	void scaleTo(const Point & size) override; | ||||
| 	void exportBitmap(const boost::filesystem::path & path) const override; | ||||
| 	bool isTransparent(const Point & coords) const override; | ||||
| 	Rect contentRect() const override; | ||||
| 	Point dimensions() const override; | ||||
| 	void setAlpha(uint8_t value) override; | ||||
| 	void setBlitMode(EImageBlitMode mode) override; | ||||
|   | ||||
| @@ -382,6 +382,13 @@ bool SDLImageShared::isTransparent(const Point & coords) const | ||||
| 		return true; | ||||
| } | ||||
|  | ||||
| Rect SDLImageShared::contentRect() const | ||||
| { | ||||
| 	auto tmpMargins = margins / preScaleFactor; | ||||
| 	auto tmpSize = Point(surf->w, surf->h) / preScaleFactor; | ||||
| 	return Rect(tmpMargins, tmpSize); | ||||
| } | ||||
|  | ||||
| Point SDLImageShared::dimensions() const | ||||
| { | ||||
| 	return fullSize / preScaleFactor; | ||||
| @@ -615,6 +622,11 @@ bool SDLImageBase::isTransparent(const Point & coords) const | ||||
| 	return image->isTransparent(coords); | ||||
| } | ||||
|  | ||||
| Rect SDLImageBase::contentRect() const | ||||
| { | ||||
| 	return image->contentRect(); | ||||
| } | ||||
|  | ||||
| Point SDLImageBase::dimensions() const | ||||
| { | ||||
| 	return image->dimensions(); | ||||
|   | ||||
| @@ -57,6 +57,7 @@ public: | ||||
| 	void exportBitmap(const boost::filesystem::path & path, SDL_Palette * palette) const override; | ||||
| 	Point dimensions() const override; | ||||
| 	bool isTransparent(const Point & coords) const override; | ||||
| 	Rect contentRect() const override; | ||||
| 	[[nodiscard]] std::shared_ptr<IImage> createImageReference(EImageBlitMode mode) const override; | ||||
| 	[[nodiscard]] std::shared_ptr<const ISharedImage> horizontalFlip() const override; | ||||
| 	[[nodiscard]] std::shared_ptr<const ISharedImage> verticalFlip() const override; | ||||
| @@ -78,6 +79,7 @@ public: | ||||
| 	SDLImageBase(const std::shared_ptr<const ISharedImage> & image, EImageBlitMode mode); | ||||
|  | ||||
| 	bool isTransparent(const Point & coords) const override; | ||||
| 	Rect contentRect() const override; | ||||
| 	Point dimensions() const override; | ||||
| 	void setAlpha(uint8_t value) override; | ||||
| 	void setBlitMode(EImageBlitMode mode) override; | ||||
|   | ||||
| @@ -36,6 +36,7 @@ | ||||
| #include "../render/IRenderHandler.h" | ||||
| #include "../render/CAnimation.h" | ||||
| #include "../render/ColorFilter.h" | ||||
| #include "../render/IFont.h" | ||||
| #include "../adventureMap/AdventureMapInterface.h" | ||||
| #include "../adventureMap/CList.h" | ||||
| #include "../adventureMap/CResDataBar.h" | ||||
| @@ -173,6 +174,8 @@ void CBuildingRect::show(Canvas & to) | ||||
| { | ||||
| 	uint32_t stageDelay = BUILDING_APPEAR_TIMEPOINT; | ||||
|  | ||||
| 	bool showTextOverlay = GH.isKeyboardAltDown(); | ||||
|  | ||||
| 	if(stateTimeCounter < BUILDING_APPEAR_TIMEPOINT) | ||||
| 	{ | ||||
| 		setAlpha(255 * stateTimeCounter / stageDelay); | ||||
| @@ -188,7 +191,7 @@ void CBuildingRect::show(Canvas & to) | ||||
| 	{ | ||||
| 		if(stateTimeCounter >= BUILD_ANIMATION_FINISHED_TIMEPOINT) | ||||
| 		{ | ||||
| 			if(parent->selectedBuilding == this) | ||||
| 			if(parent->selectedBuilding == this || showTextOverlay) | ||||
| 				to.draw(border, pos.topLeft()); | ||||
| 			return; | ||||
| 		} | ||||
| @@ -232,9 +235,9 @@ std::string CBuildingRect::getSubtitle()//hover text for building | ||||
| 	if (!getBuilding()) | ||||
| 		return ""; | ||||
|  | ||||
| 	int bid = getBuilding()->bid; | ||||
| 	auto bid = getBuilding()->bid; | ||||
|  | ||||
| 	if (bid<30)//non-dwellings - only building name | ||||
| 	if (!bid.IsDwelling())//non-dwellings - only building name | ||||
| 		return town->getTown()->buildings.at(getBuilding()->bid)->getNameTranslated(); | ||||
| 	else//dwellings - recruit %creature% | ||||
| 	{ | ||||
| @@ -646,6 +649,54 @@ void CCastleBuildings::recreate() | ||||
| 	boost::sort(children, buildSorter); //TODO: create building in blit order | ||||
| } | ||||
|  | ||||
| void CCastleBuildings::drawOverlays(Canvas & to, std::vector<std::shared_ptr<CBuildingRect>> buildingRects) | ||||
| { | ||||
| 	std::vector<Rect> textRects; | ||||
| 	for(auto & buildingRect : buildingRects) | ||||
| 	{ | ||||
| 		if(!buildingRect->border) | ||||
| 			continue; | ||||
|  | ||||
| 		auto building = buildingRect->getBuilding(); | ||||
| 		if (!building) | ||||
| 			continue; | ||||
| 		auto bid = building->bid; | ||||
|  | ||||
| 		auto overlay = town->getTown()->buildings.at(bid)->getNameTranslated(); | ||||
| 		const auto & font = GH.renderHandler().loadFont(FONT_TINY); | ||||
|  | ||||
| 		auto backColor = Colors::GREEN; // Other | ||||
| 		if(bid.IsDwelling()) | ||||
| 			backColor = Colors::PURPLE; // dwelling | ||||
|  | ||||
| 		auto contentRect = buildingRect->border->contentRect(); | ||||
| 		auto center = Rect(buildingRect->pos.x + contentRect.x, buildingRect->pos.y + contentRect.y, contentRect.w, contentRect.h).center(); | ||||
| 		Point dimensions(font->getStringWidth(overlay), font->getLineHeight()); | ||||
| 		Rect textRect = Rect(center - dimensions / 2, dimensions).resize(2); | ||||
|  | ||||
| 		while(!pos.resize(-5).isInside(Point(textRect.topLeft().x, textRect.center().y))) | ||||
| 			textRect.x++; | ||||
| 		while(!pos.resize(-5).isInside(Point(textRect.topRight().x, textRect.center().y))) | ||||
| 			textRect.x--; | ||||
| 		while(std::any_of(textRects.begin(), textRects.end(), [textRect](Rect existingTextRect) { return existingTextRect.resize(3).intersectionTest(textRect); })) | ||||
| 			textRect.y++; | ||||
| 		textRects.push_back(textRect); | ||||
|  | ||||
| 		to.drawColor(textRect, backColor); | ||||
| 		to.drawBorder(textRect, Colors::BRIGHT_YELLOW); | ||||
| 		to.drawText(textRect.center(), EFonts::FONT_TINY, Colors::BLACK, ETextAlignment::CENTER, overlay); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CCastleBuildings::show(Canvas & to) | ||||
| { | ||||
| 	CIntObject::show(to); | ||||
|  | ||||
| 	bool showTextOverlay = GH.isKeyboardAltDown(); | ||||
| 	if(showTextOverlay) | ||||
| 		drawOverlays(to, buildings); | ||||
| } | ||||
|  | ||||
| void CCastleBuildings::addBuilding(BuildingID building) | ||||
| { | ||||
| 	//FIXME: implement faster method without complete recreation of town | ||||
|   | ||||
| @@ -159,6 +159,9 @@ class CCastleBuildings : public CIntObject | ||||
| 	void openTownHall(); | ||||
|  | ||||
| 	void recreate(); | ||||
|  | ||||
| 	void drawOverlays(Canvas & to, std::vector<std::shared_ptr<CBuildingRect>> buildingRects); | ||||
| 	void show(Canvas & to) override; | ||||
| public: | ||||
| 	CBuildingRect * selectedBuilding; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user