mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-02 00:10:22 +02:00
converted to window
This commit is contained in:
parent
1f6e0fae7d
commit
814241e836
@ -417,11 +417,13 @@ BattleHero::BattleHero(const BattleInterface & owner, const CGHeroInstance * her
|
||||
addUsedEvents(TIME);
|
||||
}
|
||||
|
||||
QuickSpellPanel::QuickSpellPanel()
|
||||
: CIntObject(LCLICK | SHOW_POPUP)
|
||||
QuickSpellPanel::QuickSpellPanel(std::shared_ptr<CButton> initWidget)
|
||||
: CWindowObject(NEEDS_ANIMATED_BACKGROUND), initWidget(initWidget)
|
||||
{
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||
|
||||
addUsedEvents(LCLICK | SHOW_POPUP | MOVE);
|
||||
|
||||
setEnabled(false);
|
||||
|
||||
pos = Rect(0, 0, 52, 372);
|
||||
@ -452,13 +454,33 @@ void QuickSpellPanel::show(Canvas & to)
|
||||
void QuickSpellPanel::clickReleased(const Point & cursorPosition)
|
||||
{
|
||||
if(!pos.isInside(cursorPosition))
|
||||
setEnabled(false);
|
||||
close();
|
||||
|
||||
if(initWidget->pos.isInside(cursorPosition))
|
||||
{
|
||||
initWidget->clickPressed(cursorPosition);
|
||||
initWidget->clickReleased(cursorPosition);
|
||||
}
|
||||
}
|
||||
|
||||
void QuickSpellPanel::showPopupWindow(const Point & cursorPosition)
|
||||
{
|
||||
if(!pos.isInside(cursorPosition))
|
||||
setEnabled(false);
|
||||
close();
|
||||
|
||||
if(initWidget->pos.isInside(cursorPosition))
|
||||
{
|
||||
initWidget->showPopupWindow(cursorPosition);
|
||||
}
|
||||
}
|
||||
|
||||
void QuickSpellPanel::mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance)
|
||||
{
|
||||
if( cursorPosition.x <= initWidget->pos.x - 20 ||
|
||||
cursorPosition.x >= initWidget->pos.x + initWidget->pos.w + 20 ||
|
||||
cursorPosition.y <= initWidget->pos.y - pos.h - 20 ||
|
||||
(cursorPosition.y >= initWidget->pos.y && !initWidget->pos.isInside(cursorPosition)))
|
||||
close();
|
||||
}
|
||||
|
||||
bool QuickSpellPanel::receiveEvent(const Point & position, int eventType) const
|
||||
|
@ -147,7 +147,7 @@ public:
|
||||
BattleHero(const BattleInterface & owner, const CGHeroInstance * hero, bool defender);
|
||||
};
|
||||
|
||||
class QuickSpellPanel : public CIntObject
|
||||
class QuickSpellPanel : public CWindowObject
|
||||
{
|
||||
private:
|
||||
std::shared_ptr<CFilledTexture> background;
|
||||
@ -158,8 +158,11 @@ private:
|
||||
bool receiveEvent(const Point & position, int eventType) const override;
|
||||
void clickReleased(const Point & cursorPosition) override;
|
||||
void showPopupWindow(const Point & cursorPosition) override;
|
||||
void mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance) override;
|
||||
|
||||
std::shared_ptr<CButton> initWidget;
|
||||
public:
|
||||
QuickSpellPanel();
|
||||
QuickSpellPanel(std::shared_ptr<CButton> initWidget);
|
||||
|
||||
void show(Canvas & to) override;
|
||||
};
|
||||
|
@ -104,20 +104,17 @@ BattleWindow::BattleWindow(BattleInterface & owner):
|
||||
auto hero = owner.getBattle()->battleGetMyHero();
|
||||
if(GH.screenDimensions().x >= 1000 && hero && owner.getBattle()->battleCanCastSpell(hero, spells::Mode::HERO) != ESpellCastProblem::NO_SPELLBOOK && settings["general"]["enableUiEnhancements"].Bool())
|
||||
{
|
||||
quickSpellPanelWindow = std::make_shared<QuickSpellPanel>();
|
||||
quickSpellPanelWindow = std::make_shared<QuickSpellPanel>(w);
|
||||
quickSpellPanelWindow->moveTo(Point(w->pos.x - 2, w->pos.y - 378));
|
||||
w->addHoverCallback([this, w](bool on)
|
||||
{
|
||||
if(on)
|
||||
quickSpellPanelWindow->setEnabled(true);
|
||||
else
|
||||
if(GH.getCursorPosition().x <= w->pos.x || GH.getCursorPosition().x >= w->pos.x + w->pos.w || GH.getCursorPosition().y >= w->pos.y + w->pos.h)
|
||||
quickSpellPanelWindow->setEnabled(false);
|
||||
GH.windows().pushWindow(quickSpellPanelWindow);
|
||||
});
|
||||
w->addPanningCallback([this](const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
|
||||
{
|
||||
if((currentPosition - initialPosition).y < -20)
|
||||
quickSpellPanelWindow->setEnabled(true);
|
||||
GH.windows().pushWindow(quickSpellPanelWindow);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user