1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-29 21:56:54 +02:00

Merge pull request from IvanSavenko/keymaster_popup

Added popup for keymasters/border guards similar to teleporters
This commit is contained in:
Ivan Savenko 2025-01-06 21:52:23 +02:00 committed by GitHub
commit 094a037096
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 170 additions and 32 deletions

Binary file not shown.

After

(image error) Size: 147 B

Binary file not shown.

After

(image error) Size: 141 B

Binary file not shown.

After

(image error) Size: 252 B

Binary file not shown.

After

(image error) Size: 119 B

Binary file not shown.

After

(image error) Size: 119 B

Binary file not shown.

After

(image error) Size: 206 B

Binary file not shown.

After

(image error) Size: 208 B

Binary file not shown.

After

(image error) Size: 391 B

Binary file not shown.

After

(image error) Size: 154 B

Binary file not shown.

After

(image error) Size: 150 B

@ -31,12 +31,13 @@
#include "../../CCallback.h"
#include "../../lib/CConfigHandler.h"
#include "../ConditionalWait.h"
#include "../../lib/gameState/InfoAboutArmy.h"
#include "../../lib/mapObjects/CGCreature.h"
#include "../../lib/mapObjects/CGHeroInstance.h"
#include "../../lib/mapObjects/CGTownInstance.h"
#include "../../lib/mapObjects/CQuest.h"
#include "../../lib/mapObjects/MiscObjects.h"
#include "../ConditionalWait.h"
CSelWindow::CSelWindow( const std::string & Text, PlayerColor player, int charperline, const std::vector<std::shared_ptr<CSelectableComponent>> & comps, const std::vector<std::pair<AnimationPath, CFunctionList<void()>>> & Buttons, QueryID askID)
{
@ -333,12 +334,10 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGCreature * creature)
fitToScreen(10);
}
TeleporterPopup::TeleporterPopup(const Point & position, const CGTeleport * teleporter)
: CWindowObject(BORDERED | RCLICK_POPUP)
MinimapWithIcons::MinimapWithIcons(const Point & position)
{
OBJECT_CONSTRUCTION;
pos.w = 322;
pos.h = 200;
pos += position;
Rect areaSurface(11, 41, 144, 144);
Rect areaUnderground(167, 41, 144, 144);
@ -346,16 +345,14 @@ TeleporterPopup::TeleporterPopup(const Point & position, const CGTeleport * tele
Rect borderSurface(10, 40, 147, 147);
Rect borderUnderground(166, 40, 147, 147);
bool singleLevelMap = LOCPLINT->cb->getMapSize().y == 0;
bool singleLevelMap = LOCPLINT->cb->getMapSize().z == 1;
if (singleLevelMap)
{
areaSurface.x += 144;
borderSurface.x += 144;
areaSurface.x += 78;
borderSurface.x += 78;
}
filledBackground = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, pos.w, pos.h));
backgroundSurface = std::make_shared<TransparentFilledRectangle>(borderSurface, Colors::TRANSPARENCY, Colors::YELLOW);
surface = std::make_shared<CMinimapInstance>(areaSurface.topLeft(), areaSurface.dimensions(), 0);
@ -364,8 +361,43 @@ TeleporterPopup::TeleporterPopup(const Point & position, const CGTeleport * tele
backgroundUnderground = std::make_shared<TransparentFilledRectangle>(borderUnderground, Colors::TRANSPARENCY, Colors::YELLOW);
undergroud = std::make_shared<CMinimapInstance>(areaUnderground.topLeft(), areaUnderground.dimensions(), 1);
}
}
void MinimapWithIcons::addIcon(const int3 & coordinates, const ImagePath & image )
{
OBJECT_CONSTRUCTION;
Rect areaSurface(11, 41, 144, 144);
Rect areaUnderground(167, 41, 144, 144);
bool singleLevelMap = LOCPLINT->cb->getMapSize().z == 1;
if (singleLevelMap)
areaSurface.x += 78;
int positionX = 144 * coordinates.x / LOCPLINT->cb->getMapSize().x;
int positionY = 144 * coordinates.y / LOCPLINT->cb->getMapSize().y;
Point iconPosition(positionX, positionY);
iconPosition -= Point(8,8); // compensate for 16x16 icon half-size
if (coordinates.z == 0)
iconPosition += areaSurface.topLeft();
else
iconPosition += areaUnderground.topLeft();
iconsOverlay.push_back(std::make_shared<CPicture>(image, iconPosition));
}
TeleporterPopup::TeleporterPopup(const Point & position, const CGTeleport * teleporter)
: CWindowObject(BORDERED | RCLICK_POPUP)
{
OBJECT_CONSTRUCTION;
pos.w = 322;
pos.h = 200;
filledBackground = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, pos.w, pos.h));
labelTitle = std::make_shared<CLabel>(pos.w / 2, 20, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, teleporter->getPopupText(LOCPLINT->playerID));
minimap = std::make_shared<MinimapWithIcons>(Point(0,0));
const auto & entrances = teleporter->getAllEntrances();
const auto & exits = teleporter->getAllExits();
@ -382,31 +414,87 @@ TeleporterPopup::TeleporterPopup(const Point & position, const CGTeleport * tele
continue;
int3 position = exitObject->visitablePos();
int positionX = 144 * position.x / LOCPLINT->cb->getMapSize().x;
int positionY = 144 * position.y / LOCPLINT->cb->getMapSize().y;
Point iconPosition(positionX, positionY);
iconPosition -= Point(8,8); // compensate for 16x16 icon half-size
if (position.z == 0)
iconPosition += areaSurface.topLeft();
else
iconPosition += areaUnderground.topLeft();
ImagePath image;
if (!vstd::contains(entrances, exit))
image = ImagePath::builtin("portalExit");
image = ImagePath::builtin("minimapIcons/portalExit");
else if (!vstd::contains(exits, exit))
image = ImagePath::builtin("portalEntrance");
image = ImagePath::builtin("minimapIcons/portalEntrance");
else
image = ImagePath::builtin("portalBidirectional");
image = ImagePath::builtin("minimapIcons/portalBidirectional");
iconsOverlay.push_back(std::make_shared<CPicture>(image, iconPosition));
minimap->addIcon(position, image);
}
center(position);
fitToScreen(10);
}
KeymasterPopup::KeymasterPopup(const Point & position, const CGKeys * keymasterOrGuard)
: CWindowObject(BORDERED | RCLICK_POPUP)
{
OBJECT_CONSTRUCTION;
pos.w = 322;
pos.h = 220;
filledBackground = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, pos.w, pos.h));
labelTitle = std::make_shared<CLabel>(pos.w / 2, 20, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, keymasterOrGuard->getObjectName());
labelDescription = std::make_shared<CLabel>(pos.w / 2, 40, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, keymasterOrGuard->getObjectDescription(LOCPLINT->playerID));
minimap = std::make_shared<MinimapWithIcons>(Point(0,20));
const auto allObjects = LOCPLINT->cb->getAllVisitableObjs();
for (const auto mapObject : allObjects)
{
if (!mapObject)
continue;
switch (mapObject->ID)
{
case Obj::KEYMASTER:
if (mapObject->subID == keymasterOrGuard->subID)
minimap->addIcon(mapObject->visitablePos(), ImagePath::builtin("minimapIcons/keymaster"));
break;
case Obj::BORDERGUARD:
if (mapObject->subID == keymasterOrGuard->subID)
minimap->addIcon(mapObject->visitablePos(), ImagePath::builtin("minimapIcons/borderguard"));
break;
case Obj::BORDER_GATE:
if (mapObject->subID == keymasterOrGuard->subID)
minimap->addIcon(mapObject->visitablePos(), ImagePath::builtin("minimapIcons/bordergate"));
break;
}
}
center(position);
fitToScreen(10);
}
ObeliskPopup::ObeliskPopup(const Point & position, const CGObelisk * obelisk)
: CWindowObject(BORDERED | RCLICK_POPUP)
{
OBJECT_CONSTRUCTION;
pos.w = 322;
pos.h = 220;
filledBackground = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, pos.w, pos.h));
labelTitle = std::make_shared<CLabel>(pos.w / 2, 20, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, obelisk->getObjectName());
labelDescription = std::make_shared<CLabel>(pos.w / 2, 40, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, obelisk->getObjectDescription(LOCPLINT->playerID));
minimap = std::make_shared<MinimapWithIcons>(Point(0,20));
const auto allObjects = LOCPLINT->cb->getAllVisitableObjs();
for (const auto mapObject : allObjects)
{
if (!mapObject)
continue;
if (mapObject->ID != Obj::OBELISK)
continue;
if (mapObject->wasVisited(LOCPLINT->playerID))
minimap->addIcon(mapObject->visitablePos(), ImagePath::builtin("minimapIcons/obeliskVisited"));
else
minimap->addIcon(mapObject->visitablePos(), ImagePath::builtin("minimapIcons/obelisk"));
}
center(position);
fitToScreen(10);
}
@ -440,6 +528,12 @@ CRClickPopup::createCustomInfoWindow(Point position, const CGObjectInstance * sp
case Obj::SUBTERRANEAN_GATE:
case Obj::WHIRLPOOL:
return std::make_shared<TeleporterPopup>(position, dynamic_cast<const CGTeleport *>(specific));
case Obj::KEYMASTER:
case Obj::BORDERGUARD:
case Obj::BORDER_GATE:
return std::make_shared<KeymasterPopup>(position, dynamic_cast<const CGKeys *>(specific));
case Obj::OBELISK:
return std::make_shared<ObeliskPopup>(position, dynamic_cast<const CGObelisk *>(specific));
default:
return std::shared_ptr<WindowBase>();
}

@ -21,6 +21,8 @@ class CGHeroInstance;
class CGGarrison;
class CGCreature;
class CGTeleport;
class CGKeys;
class CGObelisk;
VCMI_LIB_NAMESPACE_END
@ -116,20 +118,50 @@ public:
CSelWindow(const std::string & text, PlayerColor player, int charperline, const std::vector<std::shared_ptr<CSelectableComponent>> & comps, const std::vector<std::pair<AnimationPath,CFunctionList<void()> > > &Buttons, QueryID askID);
};
class TeleporterPopup : public CWindowObject
class MinimapWithIcons : public CIntObject
{
std::shared_ptr<FilledTexturePlayerColored> filledBackground;
std::shared_ptr<TransparentFilledRectangle> backgroundSurface;
std::shared_ptr<TransparentFilledRectangle> backgroundUnderground;
std::shared_ptr<CMinimapInstance> surface;
std::shared_ptr<CMinimapInstance> undergroud;
std::vector<std::shared_ptr<CPicture>> iconsOverlay;
public:
MinimapWithIcons(const Point & position);
void addIcon(const int3 & coordinates, const ImagePath & image);
};
class TeleporterPopup : public CWindowObject
{
std::shared_ptr<FilledTexturePlayerColored> filledBackground;
std::shared_ptr<MinimapWithIcons> minimap;
std::shared_ptr<CLabel> labelTitle;
std::vector<std::shared_ptr<CPicture>> iconsOverlay;
public:
TeleporterPopup(const Point & position, const CGTeleport * teleporter);
};
class KeymasterPopup : public CWindowObject
{
std::shared_ptr<FilledTexturePlayerColored> filledBackground;
std::shared_ptr<MinimapWithIcons> minimap;
std::shared_ptr<CLabel> labelTitle;
std::shared_ptr<CLabel> labelDescription;
public:
KeymasterPopup(const Point & position, const CGKeys * keymasterOrGuard);
};
class ObeliskPopup : public CWindowObject
{
std::shared_ptr<FilledTexturePlayerColored> filledBackground;
std::shared_ptr<MinimapWithIcons> minimap;
std::shared_ptr<CLabel> labelTitle;
std::shared_ptr<CLabel> labelDescription;
public:
ObeliskPopup(const Point & position, const CGObelisk * obelisk);
};

@ -803,6 +803,11 @@ std::string CGKeys::getObjectName() const
return VLC->generaltexth->tentColors[subID.getNum()] + " " + CGObjectInstance::getObjectName();
}
std::string CGKeys::getObjectDescription(PlayerColor player) const
{
return visitedTxt(wasMyColorVisited(player));
}
bool CGKeymasterTent::wasVisited (PlayerColor player) const
{
return wasMyColorVisited (player);

@ -199,7 +199,8 @@ public:
bool wasMyColorVisited(const PlayerColor & player) const;
std::string getObjectName() const override; //depending on color
std::string getObjectName() const override;
std::string getObjectDescription(PlayerColor player) const;
std::string getHoverText(PlayerColor player) const override;
template <typename Handler> void serialize(Handler &h)

@ -1289,6 +1289,11 @@ std::string CGObelisk::getHoverText(PlayerColor player) const
return getObjectName() + " " + visitedTxt(wasVisited(player));
}
std::string CGObelisk::getObjectDescription(PlayerColor player) const
{
return visitedTxt(wasVisited(player));
}
void CGObelisk::setPropertyDer(ObjProperty what, ObjPropertyID identifier)
{
switch(what)

@ -406,6 +406,7 @@ public:
void onHeroVisit(const CGHeroInstance * h) const override;
void initObj(vstd::RNG & rand) override;
std::string getHoverText(PlayerColor player) const override;
std::string getObjectDescription(PlayerColor player) const;
template <typename Handler> void serialize(Handler &h)
{