mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-10 22:31:40 +02:00
show building names with ALT
This commit is contained in:
@@ -81,6 +81,8 @@ public:
|
|||||||
//test transparency of specific pixel
|
//test transparency of specific pixel
|
||||||
virtual bool isTransparent(const Point & coords) const = 0;
|
virtual bool isTransparent(const Point & coords) const = 0;
|
||||||
|
|
||||||
|
virtual Rect contentRect() const = 0;
|
||||||
|
|
||||||
virtual Point dimensions() const = 0;
|
virtual Point dimensions() const = 0;
|
||||||
int width() const;
|
int width() const;
|
||||||
int height() const;
|
int height() const;
|
||||||
@@ -109,6 +111,7 @@ public:
|
|||||||
virtual Point dimensions() const = 0;
|
virtual Point dimensions() const = 0;
|
||||||
virtual void exportBitmap(const boost::filesystem::path & path, SDL_Palette * palette) const = 0;
|
virtual void exportBitmap(const boost::filesystem::path & path, SDL_Palette * palette) const = 0;
|
||||||
virtual bool isTransparent(const Point & coords) 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;
|
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;
|
[[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);
|
return source->isTransparent(coords);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rect ImageScaled::contentRect() const
|
||||||
|
{
|
||||||
|
return source->contentRect();
|
||||||
|
}
|
||||||
|
|
||||||
Point ImageScaled::dimensions() const
|
Point ImageScaled::dimensions() const
|
||||||
{
|
{
|
||||||
return source->dimensions();
|
return source->dimensions();
|
||||||
|
@@ -52,6 +52,7 @@ public:
|
|||||||
void scaleTo(const Point & size) override;
|
void scaleTo(const Point & size) override;
|
||||||
void exportBitmap(const boost::filesystem::path & path) const override;
|
void exportBitmap(const boost::filesystem::path & path) const override;
|
||||||
bool isTransparent(const Point & coords) const override;
|
bool isTransparent(const Point & coords) const override;
|
||||||
|
Rect contentRect() const override;
|
||||||
Point dimensions() const override;
|
Point dimensions() const override;
|
||||||
void setAlpha(uint8_t value) override;
|
void setAlpha(uint8_t value) override;
|
||||||
void setBlitMode(EImageBlitMode mode) override;
|
void setBlitMode(EImageBlitMode mode) override;
|
||||||
|
@@ -388,6 +388,13 @@ bool SDLImageShared::isTransparent(const Point & coords) const
|
|||||||
return true;
|
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
|
Point SDLImageShared::dimensions() const
|
||||||
{
|
{
|
||||||
return fullSize / preScaleFactor;
|
return fullSize / preScaleFactor;
|
||||||
@@ -621,6 +628,11 @@ bool SDLImageBase::isTransparent(const Point & coords) const
|
|||||||
return image->isTransparent(coords);
|
return image->isTransparent(coords);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rect SDLImageBase::contentRect() const
|
||||||
|
{
|
||||||
|
return image->contentRect();
|
||||||
|
}
|
||||||
|
|
||||||
Point SDLImageBase::dimensions() const
|
Point SDLImageBase::dimensions() const
|
||||||
{
|
{
|
||||||
return image->dimensions();
|
return image->dimensions();
|
||||||
|
@@ -57,6 +57,7 @@ public:
|
|||||||
void exportBitmap(const boost::filesystem::path & path, SDL_Palette * palette) const override;
|
void exportBitmap(const boost::filesystem::path & path, SDL_Palette * palette) const override;
|
||||||
Point dimensions() const override;
|
Point dimensions() const override;
|
||||||
bool isTransparent(const Point & coords) 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<IImage> createImageReference(EImageBlitMode mode) const override;
|
||||||
[[nodiscard]] std::shared_ptr<const ISharedImage> horizontalFlip() const override;
|
[[nodiscard]] std::shared_ptr<const ISharedImage> horizontalFlip() const override;
|
||||||
[[nodiscard]] std::shared_ptr<const ISharedImage> verticalFlip() 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);
|
SDLImageBase(const std::shared_ptr<const ISharedImage> & image, EImageBlitMode mode);
|
||||||
|
|
||||||
bool isTransparent(const Point & coords) const override;
|
bool isTransparent(const Point & coords) const override;
|
||||||
|
Rect contentRect() const override;
|
||||||
Point dimensions() const override;
|
Point dimensions() const override;
|
||||||
void setAlpha(uint8_t value) override;
|
void setAlpha(uint8_t value) override;
|
||||||
void setBlitMode(EImageBlitMode mode) override;
|
void setBlitMode(EImageBlitMode mode) override;
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
#include "../render/IRenderHandler.h"
|
#include "../render/IRenderHandler.h"
|
||||||
#include "../render/CAnimation.h"
|
#include "../render/CAnimation.h"
|
||||||
#include "../render/ColorFilter.h"
|
#include "../render/ColorFilter.h"
|
||||||
|
#include "../render/IFont.h"
|
||||||
#include "../adventureMap/AdventureMapInterface.h"
|
#include "../adventureMap/AdventureMapInterface.h"
|
||||||
#include "../adventureMap/CList.h"
|
#include "../adventureMap/CList.h"
|
||||||
#include "../adventureMap/CResDataBar.h"
|
#include "../adventureMap/CResDataBar.h"
|
||||||
@@ -173,6 +174,8 @@ void CBuildingRect::show(Canvas & to)
|
|||||||
{
|
{
|
||||||
uint32_t stageDelay = BUILDING_APPEAR_TIMEPOINT;
|
uint32_t stageDelay = BUILDING_APPEAR_TIMEPOINT;
|
||||||
|
|
||||||
|
bool showTextOverlay = GH.isKeyboardAltDown();
|
||||||
|
|
||||||
if(stateTimeCounter < BUILDING_APPEAR_TIMEPOINT)
|
if(stateTimeCounter < BUILDING_APPEAR_TIMEPOINT)
|
||||||
{
|
{
|
||||||
setAlpha(255 * stateTimeCounter / stageDelay);
|
setAlpha(255 * stateTimeCounter / stageDelay);
|
||||||
@@ -188,7 +191,7 @@ void CBuildingRect::show(Canvas & to)
|
|||||||
{
|
{
|
||||||
if(stateTimeCounter >= BUILD_ANIMATION_FINISHED_TIMEPOINT)
|
if(stateTimeCounter >= BUILD_ANIMATION_FINISHED_TIMEPOINT)
|
||||||
{
|
{
|
||||||
if(parent->selectedBuilding == this)
|
if(parent->selectedBuilding == this || showTextOverlay)
|
||||||
to.draw(border, pos.topLeft());
|
to.draw(border, pos.topLeft());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -646,6 +649,54 @@ void CCastleBuildings::recreate()
|
|||||||
boost::sort(children, buildSorter); //TODO: create building in blit order
|
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;
|
||||||
|
int 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 >= 30)
|
||||||
|
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)
|
void CCastleBuildings::addBuilding(BuildingID building)
|
||||||
{
|
{
|
||||||
//FIXME: implement faster method without complete recreation of town
|
//FIXME: implement faster method without complete recreation of town
|
||||||
|
@@ -159,6 +159,9 @@ class CCastleBuildings : public CIntObject
|
|||||||
void openTownHall();
|
void openTownHall();
|
||||||
|
|
||||||
void recreate();
|
void recreate();
|
||||||
|
|
||||||
|
void drawOverlays(Canvas & to, std::vector<std::shared_ptr<CBuildingRect>> buildingRects);
|
||||||
|
void show(Canvas & to) override;
|
||||||
public:
|
public:
|
||||||
CBuildingRect * selectedBuilding;
|
CBuildingRect * selectedBuilding;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user