From e0dcb668da3d8a8443c7330e551b8e149e941beb Mon Sep 17 00:00:00 2001 From: dekvall Date: Mon, 5 Aug 2019 17:31:17 +0200 Subject: [PATCH] attack styles: fix hide styles on weapon change Hiding attack styles primarily relies on a subscription to onWidgetHiddenChanged but when swapping between bludgeon and bow this event fires before onVarbitChanged which means that when swapping quickly between the two, the longrange option will not be hidden. Since the plugin uses info about the weapon to determine in which skill xp will be gained and ultimately, which widgets should be hidden, we need an extra call to ProcessWidgets after a weapon switch to ensure expected behavior. --- .../attackstyles/AttackStylesPlugin.java | 55 +++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/attackstyles/AttackStylesPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/attackstyles/AttackStylesPlugin.java index dfe129f922..449e91d987 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/attackstyles/AttackStylesPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/attackstyles/AttackStylesPlugin.java @@ -105,11 +105,7 @@ public class AttackStylesPlugin extends Plugin private void start() { - updateWarnedSkills(config.warnForAttack(), Skill.ATTACK); - updateWarnedSkills(config.warnForStrength(), Skill.STRENGTH); - updateWarnedSkills(config.warnForDefence(), Skill.DEFENCE); - updateWarnedSkills(config.warnForRanged(), Skill.RANGED); - updateWarnedSkills(config.warnForMagic(), Skill.MAGIC); + resetWarnings(); attackStyleVarbit = client.getVar(VarPlayer.ATTACK_STYLE); equippedWeaponTypeVarbit = client.getVar(Varbits.EQUIPPED_WEAPON_TYPE); castingModeVarbit = client.getVar(Varbits.DEFENSIVE_CASTING_MODE); @@ -185,39 +181,33 @@ public class AttackStylesPlugin extends Plugin { if (event.getGameState() == GameState.LOGGED_IN) { - updateWarnedSkills(config.warnForAttack(), Skill.ATTACK); - updateWarnedSkills(config.warnForStrength(), Skill.STRENGTH); - updateWarnedSkills(config.warnForDefence(), Skill.DEFENCE); - updateWarnedSkills(config.warnForRanged(), Skill.RANGED); - updateWarnedSkills(config.warnForMagic(), Skill.MAGIC); + resetWarnings(); } } @Subscribe public void onVarbitChanged(VarbitChanged event) { - if (attackStyleVarbit == -1 || attackStyleVarbit != client.getVar(VarPlayer.ATTACK_STYLE)) - { - attackStyleVarbit = client.getVar(VarPlayer.ATTACK_STYLE); - updateAttackStyle(client.getVar(Varbits.EQUIPPED_WEAPON_TYPE), attackStyleVarbit, - client.getVar(Varbits.DEFENSIVE_CASTING_MODE)); - updateWarning(false); - } + int currentAttackStyleVarbit = client.getVar(VarPlayer.ATTACK_STYLE); + int currentEquippedWeaponTypeVarbit = client.getVar(Varbits.EQUIPPED_WEAPON_TYPE); + int currentCastingModeVarbit = client.getVar(Varbits.DEFENSIVE_CASTING_MODE); - if (equippedWeaponTypeVarbit == -1 || equippedWeaponTypeVarbit != client.getVar(Varbits.EQUIPPED_WEAPON_TYPE)) + if (attackStyleVarbit != currentAttackStyleVarbit || equippedWeaponTypeVarbit != currentEquippedWeaponTypeVarbit || castingModeVarbit != currentCastingModeVarbit) { - equippedWeaponTypeVarbit = client.getVar(Varbits.EQUIPPED_WEAPON_TYPE); - updateAttackStyle(equippedWeaponTypeVarbit, client.getVar(VarPlayer.ATTACK_STYLE), - client.getVar(Varbits.DEFENSIVE_CASTING_MODE)); - updateWarning(true); - } + boolean weaponSwitch = currentEquippedWeaponTypeVarbit != equippedWeaponTypeVarbit; - if (castingModeVarbit == -1 || castingModeVarbit != client.getVar(Varbits.DEFENSIVE_CASTING_MODE)) - { - castingModeVarbit = client.getVar(Varbits.DEFENSIVE_CASTING_MODE); - updateAttackStyle(client.getVar(Varbits.EQUIPPED_WEAPON_TYPE), client.getVar(VarPlayer.ATTACK_STYLE), + attackStyleVarbit = currentAttackStyleVarbit; + equippedWeaponTypeVarbit = currentEquippedWeaponTypeVarbit; + castingModeVarbit = currentCastingModeVarbit; + + updateAttackStyle(equippedWeaponTypeVarbit, attackStyleVarbit, castingModeVarbit); - updateWarning(false); + updateWarning(weaponSwitch); + + if (weaponSwitch) + { + processWidgets(); + } } } @@ -252,6 +242,15 @@ public class AttackStylesPlugin extends Plugin } } + private void resetWarnings() + { + updateWarnedSkills(config.warnForAttack(), Skill.ATTACK); + updateWarnedSkills(config.warnForStrength(), Skill.STRENGTH); + updateWarnedSkills(config.warnForDefence(), Skill.DEFENCE); + updateWarnedSkills(config.warnForRanged(), Skill.RANGED); + updateWarnedSkills(config.warnForMagic(), Skill.MAGIC); + } + private void updateAttackStyle(int equippedWeaponType, int attackStyleIndex, int castingMode) { AttackStyle[] attackStyles = WeaponType.getWeaponType(equippedWeaponType).getAttackStyles();