Browse Source

move to left side

Laserlicht 1 year ago
parent
commit
37b5de689a

+ 28 - 61
client/battle/BattleInterfaceClasses.cpp

@@ -419,19 +419,17 @@ BattleHero::BattleHero(const BattleInterface & owner, const CGHeroInstance * her
 	addUsedEvents(TIME);
 }
 
-QuickSpellPanel::QuickSpellPanel(std::shared_ptr<CButton> initWidget, BattleInterface & owner)
-	: CWindowObject(NEEDS_ANIMATED_BACKGROUND), initWidget(initWidget), owner(owner)
+QuickSpellPanel::QuickSpellPanel(BattleInterface & owner)
+	: CWindowObject(NEEDS_ANIMATED_BACKGROUND), owner(owner)
 {
 	OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
 
 	addUsedEvents(LCLICK | SHOW_POPUP | MOVE);
 
-	pos = Rect(0, 0, 52, 372);
+	pos = Rect(0, 0, 52, 713);
 	background = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), pos);
 	rect = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, pos.w + 1, pos.h + 1), ColorRGBA(0, 0, 0, 0), ColorRGBA(241, 216, 120, 255));
 
-	panelSelect = std::make_shared<QuickSpellPanelSelect>(this);
-
 	create();
 }
 
@@ -447,7 +445,7 @@ void QuickSpellPanel::create()
 	if(!hero)
 		return;
 
-	for(int i = 0; i < 10; i++) {
+	for(int i = 0; i < 19; i++) {
 		std::string spellIdentifier = persistentStorage["quickSpell"][std::to_string(i)].String();
 
 		SpellID id;
@@ -460,24 +458,25 @@ void QuickSpellPanel::create()
 			id = SpellID::NONE;
 		}
 
-		auto button = std::make_shared<CButton>(Point(2, 1 + 37 * i), AnimationPath::builtin("spellint"), CButton::tooltip(), [this, id, hero](){
+		auto button = std::make_shared<CButton>(Point(2, 6 + 37 * i), AnimationPath::builtin("spellint"), CButton::tooltip(), [this, id, hero](){
 			if(id.hasValue() && id.toSpell()->canBeCast(owner.getBattle().get(), spells::Mode::HERO, hero))
 			{
-				close();
 				owner.castThisSpell(id);
 			}
 		});
 		button->setOverlay(std::make_shared<CAnimImage>(AnimationPath::builtin("spellint"), !spellIdentifier.empty() ? id.num + 1 : 0));
 		button->addPopupCallback([this, i](){
+			auto panelSelect = std::make_shared<QuickSpellPanelSelect>(this);
 			panelSelect->spellSlot = i;
-			panelSelect->setEnabled(true);
+			panelSelect->moveTo(Point(pos.x + 54, pos.y + 5));
+			GH.windows().pushWindow(panelSelect);
 		});
 
 		if(!id.hasValue() || !id.toSpell()->canBeCast(owner.getBattle().get(), spells::Mode::HERO, hero))
 		{
-			buttonsDisabled.push_back(std::make_shared<TransparentFilledRectangle>(Rect(2, 1 + 37 * i, 48, 36), ColorRGBA(0, 0, 0, 128)));
+			buttonsDisabled.push_back(std::make_shared<TransparentFilledRectangle>(Rect(2, 6 + 37 * i, 48, 36), ColorRGBA(0, 0, 0, 172)));
 		}
-		labels.push_back(std::make_shared<CLabel>(7, 4 + 37 * i, EFonts::FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, std::to_string(i)));
+		labels.push_back(std::make_shared<CLabel>(7, 9 + 37 * i, EFonts::FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, std::to_string(i)));
 
 		buttons.push_back(button);
 	}
@@ -489,54 +488,12 @@ void QuickSpellPanel::show(Canvas & to)
 	CIntObject::show(to);
 }
 
-void QuickSpellPanel::clickReleased(const Point & cursorPosition)
-{
-	if(!pos.isInside(cursorPosition) && (!(panelSelect->isActive() || panelSelect->wasEnabled) || !panelSelect->pos.isInside(cursorPosition)))
-		close();
-	
-	if(initWidget->pos.isInside(cursorPosition))
-	{
-		initWidget->clickPressed(cursorPosition);
-		initWidget->clickReleased(cursorPosition);
-	}
-}
-
-void QuickSpellPanel::showPopupWindow(const Point & cursorPosition)
-{
-	if(!pos.isInside(cursorPosition) && (!(panelSelect->isActive() || panelSelect->wasEnabled) || !panelSelect->pos.isInside(cursorPosition)))
-		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 + 5 && !initWidget->pos.isInside(cursorPosition))) &&
-		(!(panelSelect->isActive() || panelSelect->wasEnabled) || !panelSelect->pos.resize(20).isInside(cursorPosition))
-	)
-		close();
-	
-	if(initWidget->pos.isInside(cursorPosition))
-		panelSelect->wasEnabled = false;
-}
-
-bool QuickSpellPanel::receiveEvent(const Point & position, int eventType) const
-{
-	return true;  // capture click also outside of window
-}
-
 QuickSpellPanelSelect::QuickSpellPanelSelect(QuickSpellPanel * Parent)
-	: parent(Parent), wasEnabled(false)
+	: parent(Parent)
 {
 	OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
 
-	setEnabled(false);
+	addUsedEvents(LCLICK);
 
 	std::vector<std::shared_ptr<CSpell>> spellList;
 	for (auto const & s : VLC->spellh->objects)
@@ -544,21 +501,20 @@ QuickSpellPanelSelect::QuickSpellPanelSelect(QuickSpellPanel * Parent)
 			spellList.push_back(s);
 
 	auto ceil = [](int x, int y){ return(x + y - 1) / y; };
-	int columnsNeeded = ceil(spellList.size(), 10);
+	int columnsNeeded = ceil(spellList.size(), NUM_PER_COLUMN);
 
-	pos = Rect(-20 - columnsNeeded * 50, 0, columnsNeeded * 50 + 2, 372);
+	pos = Rect(pos.x, pos.y, columnsNeeded * 50 + 2, 2 + 37 * NUM_PER_COLUMN);
 	background = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, pos.w, pos.h));
 	rect = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, pos.w + 1, pos.h + 1), ColorRGBA(0, 0, 0, 0), ColorRGBA(241, 216, 120, 255));
 
 	for(int i = 0; i < spellList.size(); i++)
 	{
-		int y = i % 10;
-		int x = i / 10;
+		int y = i % NUM_PER_COLUMN;
+		int x = i / NUM_PER_COLUMN;
 		std::shared_ptr<CSpell> spell = spellList[i];
 		auto button = std::make_shared<CButton>(Point(2 + 50 * x, 1 + 37 * y), AnimationPath::builtin("spellint"), CButton::tooltip(), [this, spell](){ 
-			setEnabled(false);
+			close();
 			GH.windows().totalRedraw();
-			wasEnabled = true;
 			Settings configID = persistentStorage.write["quickSpell"][std::to_string(spellSlot)];
 			configID->String() = spell->identifier;
 			parent->create();
@@ -571,6 +527,17 @@ QuickSpellPanelSelect::QuickSpellPanelSelect(QuickSpellPanel * Parent)
 	}
 }
 
+void QuickSpellPanelSelect::clickReleased(const Point & cursorPosition)
+{
+	if(!pos.isInside(cursorPosition))
+		close();
+}
+
+bool QuickSpellPanelSelect::receiveEvent(const Point & position, int eventType) const
+{
+	return true;  // capture click also outside of window
+}
+
 HeroInfoBasicPanel::HeroInfoBasicPanel(const InfoAboutHero & hero, Point * position, bool initializeBackground)
 	: CIntObject(0)
 {

+ 8 - 11
client/battle/BattleInterfaceClasses.h

@@ -149,16 +149,21 @@ public:
 	BattleHero(const BattleInterface & owner, const CGHeroInstance * hero, bool defender);
 };
 
-class QuickSpellPanelSelect : public CIntObject
+class QuickSpellPanelSelect : public CWindowObject
 {
 private:
+	const int NUM_PER_COLUMN = 19;
+
 	std::shared_ptr<CFilledTexture> background;
 	std::shared_ptr<TransparentFilledRectangle> rect;
 	std::vector<std::shared_ptr<CButton>> buttons;
 	QuickSpellPanel * parent;
 public:
 	QuickSpellPanelSelect(QuickSpellPanel * Parent);
-	bool wasEnabled; // was the panel opened? -> don't close window because mouse is not in area
+
+	bool receiveEvent(const Point & position, int eventType) const override;
+	void clickReleased(const Point & cursorPosition) override;
+
 	int spellSlot;
 };
 
@@ -171,17 +176,9 @@ private:
 	std::vector<std::shared_ptr<TransparentFilledRectangle>> buttonsDisabled;
 	std::vector<std::shared_ptr<CLabel>> labels;
 
-	std::shared_ptr<QuickSpellPanelSelect> panelSelect;
-
-	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;
 	BattleInterface & owner;
 public:
-	QuickSpellPanel(std::shared_ptr<CButton> initWidget, BattleInterface & owner);
+	QuickSpellPanel(BattleInterface & owner);
 
 	void create();
 

+ 19 - 25
client/battle/BattleWindow.cpp

@@ -90,6 +90,15 @@ BattleWindow::BattleWindow(BattleInterface & Owner):
 	addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_7, [useSpellIfPossible](){ useSpellIfPossible(7); });
 	addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_8, [useSpellIfPossible](){ useSpellIfPossible(8); });
 	addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_9, [useSpellIfPossible](){ useSpellIfPossible(9); });
+	addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_10, [useSpellIfPossible](){ useSpellIfPossible(10); });
+	addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_11, [useSpellIfPossible](){ useSpellIfPossible(11); });
+	addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_12, [useSpellIfPossible](){ useSpellIfPossible(12); });
+	addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_13, [useSpellIfPossible](){ useSpellIfPossible(13); });
+	addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_14, [useSpellIfPossible](){ useSpellIfPossible(14); });
+	addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_15, [useSpellIfPossible](){ useSpellIfPossible(15); });
+	addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_16, [useSpellIfPossible](){ useSpellIfPossible(16); });
+	addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_17, [useSpellIfPossible](){ useSpellIfPossible(17); });
+	addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_18, [useSpellIfPossible](){ useSpellIfPossible(18); });
 
 	addShortcut(EShortcut::GLOBAL_OPTIONS, std::bind(&BattleWindow::bOptionsf, this));
 	addShortcut(EShortcut::BATTLE_SURRENDER, std::bind(&BattleWindow::bSurrenderf, this));
@@ -123,33 +132,9 @@ BattleWindow::BattleWindow(BattleInterface & Owner):
 
 	createQueue();
 	createStickyHeroInfoWindows();
+	createQuickSpellWindow();
 	createTimerInfoWindows();
 
-	auto w = widget<CButton>("cast");
-	if(w)
-	{
-		auto hero = owner.getBattle()->battleGetMyHero();
-		if(hero && settings["general"]["enableUiEnhancements"].Bool())
-		{
-			auto createQuickSpellPanelWindow = [](std::shared_ptr<CButton> widget, BattleInterface & owner){
-				std::shared_ptr<QuickSpellPanel> window = std::make_shared<QuickSpellPanel>(widget, owner);
-				window->moveTo(Point(widget->pos.x - 2, widget->pos.y - 378));
-				GH.windows().pushWindow(window);
-			};
-			
-			w->addHoverCallback([this, createQuickSpellPanelWindow, w](bool on)
-			{
-				if(on)
-					createQuickSpellPanelWindow(w, owner);
-			});
-			w->addPanningCallback([this, createQuickSpellPanelWindow, w](const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
-			{
-				if((currentPosition - initialPosition).y < -20)
-					createQuickSpellPanelWindow(w, owner);
-			});
-		}
-	}
-
 	if ( owner.tacticsMode )
 		tacticPhaseStarted();
 	else
@@ -216,6 +201,15 @@ void BattleWindow::createStickyHeroInfoWindows()
 	setPositionInfoWindow();
 }
 
+void BattleWindow::createQuickSpellWindow()
+{
+	OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
+
+	std::shared_ptr<QuickSpellPanel> window = std::make_shared<QuickSpellPanel>(owner);
+	window->moveTo(Point(pos.x - 68, pos.y - 14));
+	GH.windows().pushWindow(window);
+}
+
 void BattleWindow::createTimerInfoWindows()
 {
 	OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;

+ 3 - 0
client/battle/BattleWindow.h

@@ -41,6 +41,8 @@ class BattleWindow : public InterfaceObjectConfigurable
 	std::shared_ptr<StackInfoBasicPanel> attackerStackWindow;
 	std::shared_ptr<StackInfoBasicPanel> defenderStackWindow;
 
+	std::shared_ptr<QuickSpellPanel> quickSpellWindow;
+
 	std::shared_ptr<TurnTimerWidget> attackerTimerWidget;
 	std::shared_ptr<TurnTimerWidget> defenderTimerWidget;
 
@@ -75,6 +77,7 @@ class BattleWindow : public InterfaceObjectConfigurable
 
 	void toggleStickyHeroWindowsVisibility();
 	void createStickyHeroInfoWindows();
+	void createQuickSpellWindow();
 	void createTimerInfoWindows();
 
 	std::shared_ptr<BattleConsole> buildBattleConsole(const JsonNode &) const;

+ 9 - 0
client/gui/Shortcut.h

@@ -196,6 +196,15 @@ enum class EShortcut
 	BATTLE_SPELL_SHORTCUT_7,
 	BATTLE_SPELL_SHORTCUT_8,
 	BATTLE_SPELL_SHORTCUT_9,
+	BATTLE_SPELL_SHORTCUT_10,
+	BATTLE_SPELL_SHORTCUT_11,
+	BATTLE_SPELL_SHORTCUT_12,
+	BATTLE_SPELL_SHORTCUT_13,
+	BATTLE_SPELL_SHORTCUT_14,
+	BATTLE_SPELL_SHORTCUT_15,
+	BATTLE_SPELL_SHORTCUT_16,
+	BATTLE_SPELL_SHORTCUT_17,
+	BATTLE_SPELL_SHORTCUT_18,
 
 	MARKET_DEAL,
 	MARKET_MAX_AMOUNT,

+ 9 - 0
client/gui/ShortcutHandler.cpp

@@ -232,6 +232,15 @@ EShortcut ShortcutHandler::findShortcut(const std::string & identifier ) const
 		{"battleSpellShortcut7",     EShortcut::BATTLE_SPELL_SHORTCUT_7   },
 		{"battleSpellShortcut8",     EShortcut::BATTLE_SPELL_SHORTCUT_8   },
 		{"battleSpellShortcut9",     EShortcut::BATTLE_SPELL_SHORTCUT_9   },
+		{"battleSpellShortcut10",    EShortcut::BATTLE_SPELL_SHORTCUT_10  },
+		{"battleSpellShortcut11",    EShortcut::BATTLE_SPELL_SHORTCUT_11  },
+		{"battleSpellShortcut12",    EShortcut::BATTLE_SPELL_SHORTCUT_12  },
+		{"battleSpellShortcut13",    EShortcut::BATTLE_SPELL_SHORTCUT_13  },
+		{"battleSpellShortcut14",    EShortcut::BATTLE_SPELL_SHORTCUT_14  },
+		{"battleSpellShortcut15",    EShortcut::BATTLE_SPELL_SHORTCUT_15  },
+		{"battleSpellShortcut16",    EShortcut::BATTLE_SPELL_SHORTCUT_16  },
+		{"battleSpellShortcut17",    EShortcut::BATTLE_SPELL_SHORTCUT_17  },
+		{"battleSpellShortcut18",    EShortcut::BATTLE_SPELL_SHORTCUT_18  },
 		{"spectateTrackHero",        EShortcut::SPECTATE_TRACK_HERO       },
 		{"spectateSkipBattle",       EShortcut::SPECTATE_SKIP_BATTLE      },
 		{"spectateSkipBattleResult", EShortcut::SPECTATE_SKIP_BATTLE_RESULT },

+ 9 - 0
config/shortcutsConfig.json

@@ -74,6 +74,15 @@
 		"battleSpellShortcut7":     "7",
 		"battleSpellShortcut8":     "8",
 		"battleSpellShortcut9":     "9",
+		"battleSpellShortcut10":    "Shift+0",
+		"battleSpellShortcut11":    "Shift+1",
+		"battleSpellShortcut12":    "Shift+2",
+		"battleSpellShortcut13":    "Shift+3",
+		"battleSpellShortcut14":    "Shift+4",
+		"battleSpellShortcut15":    "Shift+5",
+		"battleSpellShortcut16":    "Shift+6",
+		"battleSpellShortcut17":    "Shift+7",
+		"battleSpellShortcut18":    "Shift+8",
 		"battleSurrender":          "S",
 		"battleTacticsEnd":         [ "Return", "Keypad Enter"],
 		"battleTacticsNext":        "Space",