Remove the need to cast door marker widgets

This commit is contained in:
Evil Eye 2025-09-08 19:35:37 +02:00
parent cdd2ea02b4
commit 75a04776b0
2 changed files with 16 additions and 16 deletions

View File

@ -38,7 +38,7 @@
namespace namespace
{ {
const int cellSize = Constants::CellSizeInUnits; constexpr int cellSize = Constants::CellSizeInUnits;
constexpr float speed = 1.08f; // the zoom speed, it should be greater than 1 constexpr float speed = 1.08f; // the zoom speed, it should be greater than 1
enum LocalMapWidgetDepth enum LocalMapWidgetDepth
@ -57,7 +57,10 @@ namespace
Global_ExploreOverlayLayer = 2, Global_ExploreOverlayLayer = 2,
Global_MapLayer = 3 Global_MapLayer = 3
}; };
}
namespace MWGui
{
/// @brief A widget that changes its color when hovered. /// @brief A widget that changes its color when hovered.
class MarkerWidget final : public MyGUI::Widget class MarkerWidget final : public MyGUI::Widget
{ {
@ -108,10 +111,6 @@ namespace
{ {
scrollView->setCanvasSize(widgetSize * (grid.width() + 1), widgetSize * (grid.height() + 1)); scrollView->setCanvasSize(widgetSize * (grid.width() + 1), widgetSize * (grid.height() + 1));
} }
}
namespace MWGui
{
void CustomMarkerCollection::addMarker(const ESM::CustomMarker& marker, bool triggerEvent) void CustomMarkerCollection::addMarker(const ESM::CustomMarker& marker, bool triggerEvent)
{ {
@ -293,7 +292,7 @@ namespace MWGui
return MyGUI::IntCoord(position.left - halfMarkerSize, position.top - halfMarkerSize, markerSize, markerSize); return MyGUI::IntCoord(position.left - halfMarkerSize, position.top - halfMarkerSize, markerSize, markerSize);
} }
MyGUI::Widget* LocalMapBase::createDoorMarker(const std::string& name, float x, float y) const MarkerWidget* LocalMapBase::createDoorMarker(const std::string& name, float x, float y) const
{ {
MarkerUserData data(mLocalMapRender); MarkerUserData data(mLocalMapRender);
data.caption = name; data.caption = name;
@ -327,7 +326,7 @@ namespace MWGui
return MyGUI::IntCoord(position.left - markerSize / 2, position.top - markerSize / 2, markerSize, markerSize); return MyGUI::IntCoord(position.left - markerSize / 2, position.top - markerSize / 2, markerSize, markerSize);
} }
std::vector<MyGUI::Widget*>& LocalMapBase::currentDoorMarkersWidgets() std::vector<MarkerWidget*>& LocalMapBase::currentDoorMarkersWidgets()
{ {
return mActiveCell->isExterior() ? mExteriorDoorMarkerWidgets : mInteriorDoorMarkerWidgets; return mActiveCell->isExterior() ? mExteriorDoorMarkerWidgets : mInteriorDoorMarkerWidgets;
} }
@ -628,7 +627,7 @@ namespace MWGui
if (!mActiveCell->isExterior()) if (!mActiveCell->isExterior())
{ {
for (MyGUI::Widget* widget : mExteriorDoorMarkerWidgets) for (MarkerWidget* widget : mExteriorDoorMarkerWidgets)
widget->setVisible(false); widget->setVisible(false);
MWWorld::CellStore& cell = worldModel->getInterior(mActiveCell->getNameId()); MWWorld::CellStore& cell = worldModel->getInterior(mActiveCell->getNameId());
@ -656,7 +655,7 @@ namespace MWGui
++iter) ++iter)
destNotes.push_back(iter->second.mNote); destNotes.push_back(iter->second.mNote);
MyGUI::Widget* markerWidget = nullptr; MarkerWidget* markerWidget = nullptr;
MarkerUserData* data; MarkerUserData* data;
if (mDoorMarkersToRecycle.empty()) if (mDoorMarkersToRecycle.empty())
{ {
@ -667,7 +666,7 @@ namespace MWGui
} }
else else
{ {
markerWidget = (MarkerWidget*)mDoorMarkersToRecycle.back(); markerWidget = mDoorMarkersToRecycle.back();
mDoorMarkersToRecycle.pop_back(); mDoorMarkersToRecycle.pop_back();
data = markerWidget->getUserData<MarkerUserData>(); data = markerWidget->getUserData<MarkerUserData>();

View File

@ -43,6 +43,7 @@ namespace SceneUtil
namespace MWGui namespace MWGui
{ {
class MarkerWidget;
class CustomMarkerCollection class CustomMarkerCollection
{ {
@ -146,14 +147,14 @@ namespace MWGui
std::vector<MapEntry> mMaps; std::vector<MapEntry> mMaps;
// Keep track of created marker widgets, just to easily remove them later. // Keep track of created marker widgets, just to easily remove them later.
std::vector<MyGUI::Widget*> mExteriorDoorMarkerWidgets; std::vector<MarkerWidget*> mExteriorDoorMarkerWidgets;
std::map<std::pair<int, int>, std::vector<MyGUI::Widget*>> mExteriorDoorsByCell; std::map<std::pair<int, int>, std::vector<MarkerWidget*>> mExteriorDoorsByCell;
std::vector<MyGUI::Widget*> mInteriorDoorMarkerWidgets; std::vector<MarkerWidget*> mInteriorDoorMarkerWidgets;
std::vector<MyGUI::Widget*> mMagicMarkerWidgets; std::vector<MyGUI::Widget*> mMagicMarkerWidgets;
std::vector<MyGUI::Widget*> mCustomMarkerWidgets; std::vector<MyGUI::Widget*> mCustomMarkerWidgets;
std::vector<MyGUI::Widget*> mDoorMarkersToRecycle; std::vector<MarkerWidget*> mDoorMarkersToRecycle;
std::vector<MyGUI::Widget*>& currentDoorMarkersWidgets(); std::vector<MarkerWidget*>& currentDoorMarkersWidgets();
virtual void updateCustomMarkers(); virtual void updateCustomMarkers();
@ -163,7 +164,7 @@ namespace MWGui
MyGUI::IntPoint getMarkerPosition(float worldX, float worldY, MarkerUserData& markerPos) const; MyGUI::IntPoint getMarkerPosition(float worldX, float worldY, MarkerUserData& markerPos) const;
MyGUI::IntCoord getMarkerCoordinates( MyGUI::IntCoord getMarkerCoordinates(
float worldX, float worldY, MarkerUserData& markerPos, size_t markerSize) const; float worldX, float worldY, MarkerUserData& markerPos, size_t markerSize) const;
MyGUI::Widget* createDoorMarker(const std::string& name, float x, float y) const; MarkerWidget* createDoorMarker(const std::string& name, float x, float y) const;
MyGUI::IntCoord getMarkerCoordinates(MyGUI::Widget* widget, size_t markerSize) const; MyGUI::IntCoord getMarkerCoordinates(MyGUI::Widget* widget, size_t markerSize) const;
virtual void notifyPlayerUpdate() {} virtual void notifyPlayerUpdate() {}