1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-27 21:49:10 +02:00

disable correctly

This commit is contained in:
Laserlicht 2024-05-19 22:31:35 +02:00
parent 1a8a14a56d
commit e4dfca9f3d
3 changed files with 34 additions and 15 deletions

View File

@ -417,8 +417,8 @@ BattleHero::BattleHero(const BattleInterface & owner, const CGHeroInstance * her
addUsedEvents(TIME);
}
QuickSpellPanel::QuickSpellPanel(std::shared_ptr<CButton> initWidget)
: CWindowObject(NEEDS_ANIMATED_BACKGROUND), initWidget(initWidget)
QuickSpellPanel::QuickSpellPanel(std::shared_ptr<CButton> initWidget, std::shared_ptr<CPlayerBattleCallback> battle)
: CWindowObject(NEEDS_ANIMATED_BACKGROUND), initWidget(initWidget), battle(battle)
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
@ -435,17 +435,29 @@ QuickSpellPanel::QuickSpellPanel(std::shared_ptr<CButton> initWidget)
void QuickSpellPanel::create()
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
labels.clear();
buttons.clear();
buttonsDisabled.clear();
auto hero = battle->battleGetMyHero();
if(!hero)
return;
for(int i = 0; i < 10; i++) {
SpellID id = 14;
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"; });
button->setOverlay(std::make_shared<CAnimImage>(AnimationPath::builtin("spellint"), i > 0 ? id.num : 0));
button->addPopupCallback([this](){
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(i > 3)
if(!id.hasValue() || !id.toSpell()->canBeCast(battle.get(), spells::Mode::HERO, hero))
{
button->block(true);
buttonsDisabled.push_back(std::make_shared<TransparentFilledRectangle>(Rect(2, 1 + 37 * i, 48, 36), ColorRGBA(0, 0, 0, 128)));
}
labels.push_back(std::make_shared<CLabel>(7, 4 + 37 * i, EFonts::FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, std::to_string(i)));
@ -525,10 +537,13 @@ QuickSpellPanelSelect::QuickSpellPanelSelect(QuickSpellPanel * Parent)
{
int y = i % 10;
int x = i / 10;
auto button = std::make_shared<CButton>(Point(2 + 50 * x, 1 + 37 * y), AnimationPath::builtin("spellint"), CButton::tooltip(), [this](){
ConstTransitivePtr<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);
GH.windows().totalRedraw();
wasEnabled = true;
Settings configID = persistentStorage.write["quickSpell"][std::to_string(spellSlot)];
configID->String() = spell->identifier;
parent->create();
});
button->setOverlay(std::make_shared<CAnimImage>(AnimationPath::builtin("spellint"), spellList[i]->getId().num + 1));

View File

@ -45,6 +45,7 @@ class CPlayerInterface;
class BattleRenderer;
class VideoWidget;
class QuickSpellPanel;
class CPlayerBattleCallback;
/// Class which shows the console at the bottom of the battle screen and manages the text of the console
class BattleConsole : public CIntObject, public IStatusBar
@ -158,6 +159,7 @@ private:
public:
QuickSpellPanelSelect(QuickSpellPanel * Parent);
bool wasEnabled; // was the panel opened? -> don't close window because mouse is not in area
int spellSlot;
};
class QuickSpellPanel : public CWindowObject
@ -177,8 +179,9 @@ private:
void mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance) override;
std::shared_ptr<CButton> initWidget;
std::shared_ptr<CPlayerBattleCallback> battle;
public:
QuickSpellPanel(std::shared_ptr<CButton> initWidget);
QuickSpellPanel(std::shared_ptr<CButton> initWidget, std::shared_ptr<CPlayerBattleCallback> battle);
void create();

View File

@ -102,23 +102,24 @@ 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<QuickSpellPanel> window = std::make_shared<QuickSpellPanel>(widget);
auto createQuickSpellPanelWindow = [](std::shared_ptr<CButton> widget, std::shared_ptr<CPlayerBattleCallback> battle){
std::shared_ptr<QuickSpellPanel> window = std::make_shared<QuickSpellPanel>(widget, battle);
window->moveTo(Point(widget->pos.x - 2, widget->pos.y - 378));
GH.windows().pushWindow(window);
};
w->addHoverCallback([this, createQuickSpellPanelWindow, w](bool on)
w->addHoverCallback([this, createQuickSpellPanelWindow, w, battle](bool on)
{
if(on)
createQuickSpellPanelWindow(w);
createQuickSpellPanelWindow(w, battle);
});
w->addPanningCallback([this, createQuickSpellPanelWindow, w](const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
w->addPanningCallback([this, createQuickSpellPanelWindow, w, battle](const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
{
if((currentPosition - initialPosition).y < -20)
createQuickSpellPanelWindow(w);
createQuickSpellPanelWindow(w, battle);
});
}
}