place the selection panel beside what it describes
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "BuildingType.h"
|
||||
#include "DeconstructModeChangedEvent.h"
|
||||
#include "EventHandler.h"
|
||||
#include "FloatingPanel.h"
|
||||
#include "GameConfig.h"
|
||||
#include "UnlockedBuildingsChangedEvent.h"
|
||||
|
||||
@@ -24,10 +25,12 @@ class BuildingIconCache;
|
||||
class ItemIconCache;
|
||||
|
||||
// The build menu: one horizontal row of build buttons floating over the game world
|
||||
// view (REQ-UI-BUILD-BAR). The bar is sized to its buttons; its owner hands it the
|
||||
// world view's rect through anchorTo() and it centers itself along that rect's
|
||||
// bottom edge.
|
||||
// view (REQ-UI-BUILD-BAR). The bar is sized to its buttons and centers itself along the
|
||||
// bottom edge of the rect its owner places it in. It is placed first of the floating
|
||||
// widgets and so takes the space it wants outright: nothing ever moves it aside, and the
|
||||
// widgets placed after it keep out of its way instead.
|
||||
class BuildButtonBar : public QWidget,
|
||||
public FloatingPanel,
|
||||
public CombinedEventHandler<BuilderModeExitedEvent,
|
||||
DeconstructModeChangedEvent,
|
||||
BuildHotkeyPressedEvent,
|
||||
@@ -45,15 +48,11 @@ public:
|
||||
QWidget* parent = nullptr);
|
||||
~BuildButtonBar() override;
|
||||
|
||||
// Centers the bar along the bottom edge of the game world view's rect, given in
|
||||
// the bar's parent coordinates (REQ-UI-BUILD-BAR). The rect is remembered, so a
|
||||
// re-center later driven by an unlock needs no second call from the owner.
|
||||
void anchorTo(const QRect& worldViewRect);
|
||||
|
||||
// Height of the strip the bar occupies along the bottom of the world view: its own
|
||||
// height plus the margin below it. The selection panel keeps out of this strip, and
|
||||
// the bar never moves for the panel in return (REQ-UI-BUILD-BAR).
|
||||
int getStripHeightPx() const;
|
||||
// Centers the bar along the bottom edge of the game world view's rect, given in the
|
||||
// bar's parent coordinates (REQ-UI-BUILD-BAR). Nothing is occupied yet when the bar
|
||||
// is placed, so it ignores what it is handed there.
|
||||
void placeIn(const QRect& viewRect,
|
||||
const std::vector<QRect>& occupiedRects) override;
|
||||
|
||||
void clearActiveButton();
|
||||
|
||||
@@ -67,11 +66,6 @@ private:
|
||||
// unlock state (REQ-LOCK-BUILDING); a locked building type's button is hidden.
|
||||
void updateVisibility();
|
||||
|
||||
// Shrinks the bar to its currently shown buttons and re-centers it in the
|
||||
// anchored rect (REQ-UI-BUILD-BAR). Does nothing until anchorTo() supplied that
|
||||
// rect, so the construction-time call is harmless.
|
||||
void recenter();
|
||||
|
||||
void handleEvent(std::shared_ptr<const BuilderModeExitedEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const DeconstructModeChangedEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const BuildHotkeyPressedEvent> event) override;
|
||||
@@ -91,5 +85,4 @@ private:
|
||||
std::map<BuildingType, int> m_costs;
|
||||
std::optional<std::size_t> m_activeIndex;
|
||||
QPushButton* m_deconstructButton;
|
||||
QRect m_viewRect;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user