1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Added combat option Highlight Movement on Hover

This commit is contained in:
krs
2023-04-06 00:04:40 +03:00
parent 9012a25276
commit 1644cab938
7 changed files with 49 additions and 18 deletions

View File

@@ -81,6 +81,8 @@
"vcmi.battleOptions.animationsSpeed6.help": "Set animation speed to instantaneous", "vcmi.battleOptions.animationsSpeed6.help": "Set animation speed to instantaneous",
"vcmi.battleOptions.touchscreenMode.hover": "Touchscreen mode", "vcmi.battleOptions.touchscreenMode.hover": "Touchscreen mode",
"vcmi.battleOptions.touchscreenMode.help": "{Touchscreen mode}\n\nIf enabled, second click is required to confirm and execute action. This is more suitable for touchscreen devices.", "vcmi.battleOptions.touchscreenMode.help": "{Touchscreen mode}\n\nIf enabled, second click is required to confirm and execute action. This is more suitable for touchscreen devices.",
"vcmi.battleOptions.movementHighlightOnHover.hover": "Movement Highlight on Hover",
"vcmi.battleOptions.movementHighlightOnHover.help": "{Movement Highlight on Hover}\n\nHighlight unit's movement range when you hover over it.",
"vcmi.battleOptions.skipBattleIntroMusic.hover": "Skip Intro Music", "vcmi.battleOptions.skipBattleIntroMusic.hover": "Skip Intro Music",
"vcmi.battleOptions.skipBattleIntroMusic.help": "{Skip Intro Music}\n\nAllow actions during the intro music that plays at the beginning of each battle", "vcmi.battleOptions.skipBattleIntroMusic.help": "{Skip Intro Music}\n\nAllow actions during the intro music that plays at the beginning of each battle",
"vcmi.battleWindow.pressKeyToSkipIntro" : "Press any key to start battle immediately", "vcmi.battleWindow.pressKeyToSkipIntro" : "Press any key to start battle immediately",

View File

@@ -50,6 +50,7 @@
"description" : "Ключові файли необхідні для повноцінної роботи VCMI", "description" : "Ключові файли необхідні для повноцінної роботи VCMI",
"author" : "Команда VCMI", "author" : "Команда VCMI",
"skipValidation" : true,
"translations" : [ "translations" : [
"config/vcmi/ukrainian.json" "config/vcmi/ukrainian.json"
] ]

View File

@@ -174,7 +174,7 @@ void BattleFieldController::redrawBackgroundWithHexes()
const CStack *activeStack = owner.stacksController->getActiveStack(); const CStack *activeStack = owner.stacksController->getActiveStack();
std::vector<BattleHex> attackableHexes; std::vector<BattleHex> attackableHexes;
if(activeStack) if(activeStack)
occupyableHexes = owner.curInt->cb->battleGetAvailableHexes(activeStack, true, true, &attackableHexes); occupiableHexes = owner.curInt->cb->battleGetAvailableHexes(activeStack, true, true, &attackableHexes);
// prepare background graphic with hexes and shaded hexes // prepare background graphic with hexes and shaded hexes
backgroundWithHexes->draw(background, Point(0,0)); backgroundWithHexes->draw(background, Point(0,0));
@@ -182,14 +182,14 @@ void BattleFieldController::redrawBackgroundWithHexes()
if(owner.siegeController) if(owner.siegeController)
owner.siegeController->showAbsoluteObstacles(*backgroundWithHexes); owner.siegeController->showAbsoluteObstacles(*backgroundWithHexes);
// show shaded hexes for active's stackMovement valid movement and the hexes that it can attack // show shaded hexes for active's stack valid movement and the hexes that it can attack
if(settings["battle"]["stackRange"].Bool()) if(settings["battle"]["stackRange"].Bool())
{ {
std::vector<BattleHex> hexesToShade = occupyableHexes; std::vector<BattleHex> hexesToShade = occupiableHexes;
hexesToShade.insert(hexesToShade.end(), attackableHexes.begin(), attackableHexes.end()); hexesToShade.insert(hexesToShade.end(), attackableHexes.begin(), attackableHexes.end());
for(BattleHex hex : hexesToShade) for(BattleHex hex : hexesToShade)
{ {
backgroundWithHexes->draw(cellShade, hexPositionLocal(hex).topLeft()); showHighlightedHex(*backgroundWithHexes, cellShade, hex, false);
} }
} }
@@ -243,7 +243,7 @@ std::set<BattleHex> BattleFieldController::getMovementRangeForHoveredStack()
if (!owner.stacksController->getActiveStack()) if (!owner.stacksController->getActiveStack())
return result; return result;
if (!settings["battle"]["stackRange"].Bool()) if (!settings["battle"]["movementHighlightOnHover"].Bool())
return result; return result;
auto hoveredHex = getHoveredHex(); auto hoveredHex = getHoveredHex();
@@ -266,7 +266,7 @@ std::set<BattleHex> BattleFieldController::STUB_getMaxMovementRangeForHoveredSta
if (!owner.stacksController->getActiveStack()) if (!owner.stacksController->getActiveStack())
return result; return result;
if (!settings["battle"]["stackRange"].Bool()) if (!settings["battle"]["movementHighlightOnHover"].Bool())
return result; return result;
auto hoveredHex = getHoveredHex(); auto hoveredHex = getHoveredHex();
@@ -486,18 +486,18 @@ BattleHex::EDir BattleFieldController::selectAttackDirection(BattleHex myNumber,
// | - - | - - | - - | - o o | o o - | - - | - - | o o // | - - | - - | - - | - o o | o o - | - - | - - | o o
for (size_t i : { 1, 2, 3}) for (size_t i : { 1, 2, 3})
attackAvailability[i] = vstd::contains(occupyableHexes, neighbours[i]) && vstd::contains(occupyableHexes, neighbours[i].cloneInDirection(BattleHex::RIGHT, false)); attackAvailability[i] = vstd::contains(occupiableHexes, neighbours[i]) && vstd::contains(occupiableHexes, neighbours[i].cloneInDirection(BattleHex::RIGHT, false));
for (size_t i : { 4, 5, 0}) for (size_t i : { 4, 5, 0})
attackAvailability[i] = vstd::contains(occupyableHexes, neighbours[i]) && vstd::contains(occupyableHexes, neighbours[i].cloneInDirection(BattleHex::LEFT, false)); attackAvailability[i] = vstd::contains(occupiableHexes, neighbours[i]) && vstd::contains(occupiableHexes, neighbours[i].cloneInDirection(BattleHex::LEFT, false));
attackAvailability[6] = vstd::contains(occupyableHexes, neighbours[0]) && vstd::contains(occupyableHexes, neighbours[1]); attackAvailability[6] = vstd::contains(occupiableHexes, neighbours[0]) && vstd::contains(occupiableHexes, neighbours[1]);
attackAvailability[7] = vstd::contains(occupyableHexes, neighbours[3]) && vstd::contains(occupyableHexes, neighbours[4]); attackAvailability[7] = vstd::contains(occupiableHexes, neighbours[3]) && vstd::contains(occupiableHexes, neighbours[4]);
} }
else else
{ {
for (size_t i = 0; i < 6; ++i) for (size_t i = 0; i < 6; ++i)
attackAvailability[i] = vstd::contains(occupyableHexes, neighbours[i]); attackAvailability[i] = vstd::contains(occupiableHexes, neighbours[i]);
attackAvailability[6] = false; attackAvailability[6] = false;
attackAvailability[7] = false; attackAvailability[7] = false;
@@ -609,7 +609,7 @@ BattleHex BattleFieldController::fromWhichHexAttack(BattleHex attackTarget)
bool BattleFieldController::isTileAttackable(const BattleHex & number) const bool BattleFieldController::isTileAttackable(const BattleHex & number) const
{ {
for (auto & elem : occupyableHexes) for (auto & elem : occupiableHexes)
{ {
if (BattleHex::mutualPosition(elem, number) != -1 || elem == number) if (BattleHex::mutualPosition(elem, number) != -1 || elem == number)
return true; return true;

View File

@@ -43,7 +43,7 @@ class BattleFieldController : public CIntObject
BattleHex attackingHex; BattleHex attackingHex;
/// hexes to which currently active stack can move /// hexes to which currently active stack can move
std::vector<BattleHex> occupyableHexes; std::vector<BattleHex> occupiableHexes;
/// hexes that when in front of a unit cause it's amount box to move back /// hexes that when in front of a unit cause it's amount box to move back
std::array<bool, GameConstants::BFIELD_SIZE> stackCountOutsideHexes; std::array<bool, GameConstants::BFIELD_SIZE> stackCountOutsideHexes;

View File

@@ -34,6 +34,10 @@ BattleOptionsTab::BattleOptionsTab(BattleInterface * owner)
{ {
movementShadowChangedCallback(value, owner); movementShadowChangedCallback(value, owner);
}); });
addCallback("movementHighlightOnHoverChanged", [this, owner](bool value)
{
movementHighlightOnHoverChangedCallback(value, owner);
});
addCallback("mouseShadowChanged", [this](bool value) addCallback("mouseShadowChanged", [this](bool value)
{ {
mouseShadowChangedCallback(value); mouseShadowChangedCallback(value);
@@ -72,6 +76,9 @@ BattleOptionsTab::BattleOptionsTab(BattleInterface * owner)
std::shared_ptr<CToggleButton> movementShadowCheckbox = widget<CToggleButton>("movementShadowCheckbox"); std::shared_ptr<CToggleButton> movementShadowCheckbox = widget<CToggleButton>("movementShadowCheckbox");
movementShadowCheckbox->setSelected(settings["battle"]["stackRange"].Bool()); movementShadowCheckbox->setSelected(settings["battle"]["stackRange"].Bool());
std::shared_ptr<CToggleButton> movementHighlightOnHoverCheckbox = widget<CToggleButton>("movementHighlightOnHoverCheckbox");
movementHighlightOnHoverCheckbox->setSelected(settings["battle"]["movementHighlightOnHover"].Bool());
std::shared_ptr<CToggleButton> mouseShadowCheckbox = widget<CToggleButton>("mouseShadowCheckbox"); std::shared_ptr<CToggleButton> mouseShadowCheckbox = widget<CToggleButton>("mouseShadowCheckbox");
mouseShadowCheckbox->setSelected(settings["battle"]["mouseShadow"].Bool()); mouseShadowCheckbox->setSelected(settings["battle"]["mouseShadow"].Bool());
@@ -138,6 +145,14 @@ void BattleOptionsTab::movementShadowChangedCallback(bool value, BattleInterface
parentBattleInterface->redrawBattlefield(); parentBattleInterface->redrawBattlefield();
} }
void BattleOptionsTab::movementHighlightOnHoverChangedCallback(bool value, BattleInterface * parentBattleInterface)
{
Settings stackRange = settings.write["battle"]["movementHighlightOnHover"];
stackRange->Bool() = value;
if(parentBattleInterface)
parentBattleInterface->redrawBattlefield();
}
void BattleOptionsTab::mouseShadowChangedCallback(bool value) void BattleOptionsTab::mouseShadowChangedCallback(bool value)
{ {
Settings shadow = settings.write["battle"]["mouseShadow"]; Settings shadow = settings.write["battle"]["mouseShadow"];

View File

@@ -24,6 +24,7 @@ private:
std::string getQueueSizeStringFromId(int value) const; std::string getQueueSizeStringFromId(int value) const;
void viewGridChangedCallback(bool value, BattleInterface * parentBattleInterface); void viewGridChangedCallback(bool value, BattleInterface * parentBattleInterface);
void movementShadowChangedCallback(bool value, BattleInterface * parentBattleInterface); void movementShadowChangedCallback(bool value, BattleInterface * parentBattleInterface);
void movementHighlightOnHoverChangedCallback(bool value, BattleInterface * parentBattleInterface);
void mouseShadowChangedCallback(bool value); void mouseShadowChangedCallback(bool value);
void animationSpeedChangedCallback(int value); void animationSpeedChangedCallback(int value);
void showQueueChangedCallback(bool value, BattleInterface * parentBattleInterface); void showQueueChangedCallback(bool value, BattleInterface * parentBattleInterface);

View File

@@ -142,13 +142,17 @@
"position": {"x": 45, "y": 85} "position": {"x": 45, "y": 85}
}, },
{ {
"text": "core.genrltxt.406", "text": "vcmi.battleOptions.movementHighlightOnHover.hover",
"position": {"x": 45, "y": 115} "position": {"x": 45, "y": 115}
}, },
{ {
"text": "core.genrltxt.407", "text": "core.genrltxt.406",
"position": {"x": 45, "y": 145} "position": {"x": 45, "y": 145}
}, },
{
"text": "core.genrltxt.407",
"position": {"x": 45, "y": 175}
},
{ {
"text": "vcmi.battleOptions.skipBattleIntroMusic.hover", "text": "vcmi.battleOptions.skipBattleIntroMusic.hover",
"position": {"x": 45, "y": 175} "position": {"x": 45, "y": 175}
@@ -176,26 +180,34 @@
"position": {"x": 10, "y": 83}, "position": {"x": 10, "y": 83},
"callback": "movementShadowChanged" "callback": "movementShadowChanged"
}, },
{
"name": "movementHighlightOnHoverCheckbox",
"type": "toggleButton",
"image": "sysopchk.def",
"help": "vcmi.battleOptions.movementHighlightOnHover",
"position": {"x": 10, "y": 113},
"callback": "movementHighlightOnHoverChanged"
},
{ {
"name": "mouseShadowCheckbox", "name": "mouseShadowCheckbox",
"type": "toggleButton", "type": "toggleButton",
"image": "sysopchk.def", "image": "sysopchk.def",
"help": "core.help.429", "help": "core.help.429",
"position": {"x": 10, "y": 113}, "position": {"x": 10, "y": 143},
"callback": "mouseShadowChanged" "callback": "mouseShadowChanged"
}, },
{ {
"name": "battleFieldCasualtiesPlaceholder", "name": "battleFieldCasualtiesPlaceholder",
"type": "picture", "type": "picture",
"image": "settingsWindow/checkBoxEmpty", "image": "settingsWindow/checkBoxEmpty",
"position": {"x": 10, "y": 143}, "position": {"x": 10, "y": 173},
}, },
{ {
"name": "skipBattleIntroMusicCheckbox", "name": "skipBattleIntroMusicCheckbox",
"type": "toggleButton", "type": "toggleButton",
"image": "sysopchk.def", "image": "sysopchk.def",
"help": "vcmi.battleOptions.skipBattleIntroMusic", "help": "vcmi.battleOptions.skipBattleIntroMusic",
"position": {"x": 10, "y": 173}, "position": {"x": 10, "y": 203},
"callback": "skipBattleIntroMusicChanged" "callback": "skipBattleIntroMusicChanged"
}, },
{ {