1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

add spell cast

This commit is contained in:
Laserlicht
2024-05-19 23:12:48 +02:00
parent e4dfca9f3d
commit 53a1bf2051
6 changed files with 70 additions and 16 deletions

View File

@@ -417,8 +417,8 @@ BattleHero::BattleHero(const BattleInterface & owner, const CGHeroInstance * her
addUsedEvents(TIME);
}
QuickSpellPanel::QuickSpellPanel(std::shared_ptr<CButton> initWidget, std::shared_ptr<CPlayerBattleCallback> battle)
: CWindowObject(NEEDS_ANIMATED_BACKGROUND), initWidget(initWidget), battle(battle)
QuickSpellPanel::QuickSpellPanel(std::shared_ptr<CButton> initWidget, BattleInterface & owner)
: CWindowObject(NEEDS_ANIMATED_BACKGROUND), initWidget(initWidget), owner(owner)
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
@@ -441,7 +441,7 @@ void QuickSpellPanel::create()
buttons.clear();
buttonsDisabled.clear();
auto hero = battle->battleGetMyHero();
auto hero = owner.getBattle()->battleGetMyHero();
if(!hero)
return;
@@ -449,14 +449,20 @@ void QuickSpellPanel::create()
std::string spellIdentifier = persistentStorage["quickSpell"][std::to_string(i)].String();
SpellID id = SpellID::decode(spellIdentifier);
auto button = std::make_shared<CButton>(Point(2, 1 + 37 * i), AnimationPath::builtin("spellint"), CButton::tooltip(), [&](){ std::cout << "test"; });
auto button = std::make_shared<CButton>(Point(2, 1 + 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](){
panelSelect->spellSlot = i;
panelSelect->setEnabled(true);
});
if(!id.hasValue() || !id.toSpell()->canBeCast(battle.get(), spells::Mode::HERO, hero))
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)));
}

View File

@@ -179,9 +179,9 @@ private:
void mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance) override;
std::shared_ptr<CButton> initWidget;
std::shared_ptr<CPlayerBattleCallback> battle;
BattleInterface & owner;
public:
QuickSpellPanel(std::shared_ptr<CButton> initWidget, std::shared_ptr<CPlayerBattleCallback> battle);
QuickSpellPanel(std::shared_ptr<CButton> initWidget, BattleInterface & owner);
void create();

View File

@@ -45,8 +45,8 @@
#include "../../lib/CPlayerState.h"
#include "../windows/settings/SettingsMainWindow.h"
BattleWindow::BattleWindow(BattleInterface & owner):
owner(owner),
BattleWindow::BattleWindow(BattleInterface & Owner):
owner(Owner),
defaultAction(PossiblePlayerBattleAction::INVALID)
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
@@ -64,6 +64,25 @@ BattleWindow::BattleWindow(BattleInterface & owner):
const JsonNode config(JsonPath::builtin("config/widgets/BattleWindow2.json"));
auto useSpellIfPossible = [this](int slot){
std::string spellIdentifier = persistentStorage["quickSpell"][std::to_string(slot)].String();
SpellID id = SpellID::decode(spellIdentifier);
if(id.hasValue() && owner.getBattle()->battleGetMyHero() && id.toSpell()->canBeCast(owner.getBattle().get(), spells::Mode::HERO, owner.getBattle()->battleGetMyHero()))
{
owner.castThisSpell(id);
}
};
addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_0, [useSpellIfPossible](){ useSpellIfPossible(0); });
addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_1, [useSpellIfPossible](){ useSpellIfPossible(1); });
addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_2, [useSpellIfPossible](){ useSpellIfPossible(2); });
addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_3, [useSpellIfPossible](){ useSpellIfPossible(3); });
addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_4, [useSpellIfPossible](){ useSpellIfPossible(4); });
addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_5, [useSpellIfPossible](){ useSpellIfPossible(5); });
addShortcut(EShortcut::BATTLE_SPELL_SHORTCUT_6, [useSpellIfPossible](){ useSpellIfPossible(6); });
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::GLOBAL_OPTIONS, std::bind(&BattleWindow::bOptionsf, this));
addShortcut(EShortcut::BATTLE_SURRENDER, std::bind(&BattleWindow::bSurrenderf, this));
addShortcut(EShortcut::BATTLE_RETREAT, std::bind(&BattleWindow::bFleef, this));
@@ -102,24 +121,23 @@ BattleWindow::BattleWindow(BattleInterface & owner):
if(w)
{
auto hero = owner.getBattle()->battleGetMyHero();
auto battle = owner.getBattle();
if(GH.screenDimensions().x >= 1000 && hero && owner.getBattle()->battleCanCastSpell(hero, spells::Mode::HERO) != ESpellCastProblem::NO_SPELLBOOK && settings["general"]["enableUiEnhancements"].Bool())
{
auto createQuickSpellPanelWindow = [](std::shared_ptr<CButton> widget, std::shared_ptr<CPlayerBattleCallback> battle){
std::shared_ptr<QuickSpellPanel> window = std::make_shared<QuickSpellPanel>(widget, battle);
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, battle](bool on)
w->addHoverCallback([this, createQuickSpellPanelWindow, w](bool on)
{
if(on)
createQuickSpellPanelWindow(w, battle);
createQuickSpellPanelWindow(w, owner);
});
w->addPanningCallback([this, createQuickSpellPanelWindow, w, battle](const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
w->addPanningCallback([this, createQuickSpellPanelWindow, w](const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
{
if((currentPosition - initialPosition).y < -20)
createQuickSpellPanelWindow(w, battle);
createQuickSpellPanelWindow(w, owner);
});
}
}

View File

@@ -186,6 +186,16 @@ enum class EShortcut
BATTLE_TOGGLE_HEROES_STATS,
BATTLE_OPEN_ACTIVE_UNIT,
BATTLE_OPEN_HOVERED_UNIT,
BATTLE_SPELL_SHORTCUT_0,
BATTLE_SPELL_SHORTCUT_1,
BATTLE_SPELL_SHORTCUT_2,
BATTLE_SPELL_SHORTCUT_3,
BATTLE_SPELL_SHORTCUT_4,
BATTLE_SPELL_SHORTCUT_5,
BATTLE_SPELL_SHORTCUT_6,
BATTLE_SPELL_SHORTCUT_7,
BATTLE_SPELL_SHORTCUT_8,
BATTLE_SPELL_SHORTCUT_9,
MARKET_DEAL,
MARKET_MAX_AMOUNT,

View File

@@ -222,6 +222,16 @@ EShortcut ShortcutHandler::findShortcut(const std::string & identifier ) const
{"battleTacticsNext", EShortcut::BATTLE_TACTICS_NEXT },
{"battleTacticsEnd", EShortcut::BATTLE_TACTICS_END },
{"battleSelectAction", EShortcut::BATTLE_SELECT_ACTION },
{"battleSpellShortcut0", EShortcut::BATTLE_SPELL_SHORTCUT_0 },
{"battleSpellShortcut1", EShortcut::BATTLE_SPELL_SHORTCUT_1 },
{"battleSpellShortcut2", EShortcut::BATTLE_SPELL_SHORTCUT_2 },
{"battleSpellShortcut3", EShortcut::BATTLE_SPELL_SHORTCUT_3 },
{"battleSpellShortcut4", EShortcut::BATTLE_SPELL_SHORTCUT_4 },
{"battleSpellShortcut5", EShortcut::BATTLE_SPELL_SHORTCUT_5 },
{"battleSpellShortcut6", EShortcut::BATTLE_SPELL_SHORTCUT_6 },
{"battleSpellShortcut7", EShortcut::BATTLE_SPELL_SHORTCUT_7 },
{"battleSpellShortcut8", EShortcut::BATTLE_SPELL_SHORTCUT_8 },
{"battleSpellShortcut9", EShortcut::BATTLE_SPELL_SHORTCUT_9 },
{"spectateTrackHero", EShortcut::SPECTATE_TRACK_HERO },
{"spectateSkipBattle", EShortcut::SPECTATE_SKIP_BATTLE },
{"spectateSkipBattleResult", EShortcut::SPECTATE_SKIP_BATTLE_RESULT },

View File

@@ -64,6 +64,16 @@
"battleOpenHoveredUnit": "V",
"battleRetreat": "R",
"battleSelectAction": "S",
"battleSpellShortcut0": "0",
"battleSpellShortcut1": "1",
"battleSpellShortcut2": "2",
"battleSpellShortcut3": "3",
"battleSpellShortcut4": "4",
"battleSpellShortcut5": "5",
"battleSpellShortcut6": "6",
"battleSpellShortcut7": "7",
"battleSpellShortcut8": "8",
"battleSpellShortcut9": "9",
"battleSurrender": "S",
"battleTacticsEnd": [ "Return", "Keypad Enter"],
"battleTacticsNext": "Space",