瀏覽代碼

converted to window

Laserlicht 1 年之前
父節點
當前提交
814241e836
共有 3 個文件被更改,包括 34 次插入12 次删除
  1. 26 4
      client/battle/BattleInterfaceClasses.cpp
  2. 5 2
      client/battle/BattleInterfaceClasses.h
  3. 3 6
      client/battle/BattleWindow.cpp

+ 26 - 4
client/battle/BattleInterfaceClasses.cpp

@@ -417,11 +417,13 @@ BattleHero::BattleHero(const BattleInterface & owner, const CGHeroInstance * her
 	addUsedEvents(TIME);
 	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);
 	OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
 
 
+	addUsedEvents(LCLICK | SHOW_POPUP | MOVE);
+
 	setEnabled(false);
 	setEnabled(false);
 
 
 	pos = Rect(0, 0, 52, 372);
 	pos = Rect(0, 0, 52, 372);
@@ -452,13 +454,33 @@ void QuickSpellPanel::show(Canvas & to)
 void QuickSpellPanel::clickReleased(const Point & cursorPosition)
 void QuickSpellPanel::clickReleased(const Point & cursorPosition)
 {
 {
 	if(!pos.isInside(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)
 void QuickSpellPanel::showPopupWindow(const Point & cursorPosition)
 {
 {
 	if(!pos.isInside(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
 bool QuickSpellPanel::receiveEvent(const Point & position, int eventType) const

+ 5 - 2
client/battle/BattleInterfaceClasses.h

@@ -147,7 +147,7 @@ public:
 	BattleHero(const BattleInterface & owner, const CGHeroInstance * hero, bool defender);
 	BattleHero(const BattleInterface & owner, const CGHeroInstance * hero, bool defender);
 };
 };
 
 
-class QuickSpellPanel : public CIntObject
+class QuickSpellPanel : public CWindowObject
 {
 {
 private:
 private:
 	std::shared_ptr<CFilledTexture> background;
 	std::shared_ptr<CFilledTexture> background;
@@ -158,8 +158,11 @@ private:
 	bool receiveEvent(const Point & position, int eventType) const override;
 	bool receiveEvent(const Point & position, int eventType) const override;
 	void clickReleased(const Point & cursorPosition) override;
 	void clickReleased(const Point & cursorPosition) override;
 	void showPopupWindow(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:
 public:
-	QuickSpellPanel();
+	QuickSpellPanel(std::shared_ptr<CButton> initWidget);
 
 
 	void show(Canvas & to) override;
 	void show(Canvas & to) override;
 };
 };

+ 3 - 6
client/battle/BattleWindow.cpp

@@ -104,20 +104,17 @@ BattleWindow::BattleWindow(BattleInterface & owner):
 		auto hero = owner.getBattle()->battleGetMyHero();
 		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())
 		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));
 			quickSpellPanelWindow->moveTo(Point(w->pos.x - 2, w->pos.y - 378));
 			w->addHoverCallback([this, w](bool on)
 			w->addHoverCallback([this, w](bool on)
 			{
 			{
 				if(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)
 			w->addPanningCallback([this](const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
 			{
 			{
 				if((currentPosition - initialPosition).y < -20)
 				if((currentPosition - initialPosition).y < -20)
-					quickSpellPanelWindow->setEnabled(true);
+					GH.windows().pushWindow(quickSpellPanelWindow);
 			});
 			});
 		}
 		}
 	}
 	}