Skip to content

Commit

Permalink
Feat: added mounted crosshair option, fixed invalid target bug (#90)
Browse files Browse the repository at this point in the history
* Fix: fixed Opie rings not relocking cursor upon closure (#82)

* Fix: added support for patch 10.2.5 (#84)

* Fix: fixed Opie rings not relocking cursor upon closure

* Fix: toc bump

* Fix: fixed crosshair animation issue; updated libs (#86)

* Fix: fixed Opie rings not relocking cursor upon closure

* Fix: toc bump

* Fix: fixed crosshair animation issue; updated libs

* 10.2.6 toc bump (#87)

* Fix: toc bump

* Feat: added mounted crosshair option, fixed invalid target bug (#89)

* Fix: fixed Opie rings not relocking cursor upon closure

* Fix: toc bump

* Fix: fixed crosshair animation issue; updated libs

* Fix: toc bump

* Development (#88)

* Fix: fixed Opie rings not relocking cursor upon closure (#82)

* Fix: added support for patch 10.2.5 (#84)

* Fix: fixed Opie rings not relocking cursor upon closure

* Fix: toc bump

* Fix: fixed crosshair animation issue; updated libs (#86)

* Fix: fixed Opie rings not relocking cursor upon closure

* Fix: toc bump

* Fix: fixed crosshair animation issue; updated libs

* 10.2.6 toc bump (#87)

* Fix: toc bump

* Feat: added mounted crosshair option, fixed invalid target bug
  • Loading branch information
sampconrad authored Apr 16, 2024
1 parent 73214fd commit 2aa24ba
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 24 deletions.
44 changes: 27 additions & 17 deletions CombatMode/CombatMode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,19 @@ local function IsDefaultMouseActionBeingUsed()
end

-- CROSSHAIR STATE HANDLING FUNCTIONS
local function HideWhileMounted()
return CM.DB.global.crosshairMounted and _G.IsMounted()
end

local function SetCrosshairAppearance(state)
local CrosshairAppearance = CM.DB.global.crosshairAppearance
local yOffset = CM.DB.global.crosshairY or 100

-- Sets new scale at the end of animation
CrosshairAnimation:SetScript("OnFinished", function()
if state == "hostile" or state == "friendly" then
CrosshairFrame:SetScale(endingScale)
CrosshairFrame:SetPoint("CENTER", 0, (CM.DB.global.crosshairY or 100) / endingScale)
CrosshairFrame:SetPoint("CENTER", 0, yOffset / endingScale)
end
end)

Expand All @@ -122,12 +127,15 @@ local function SetCrosshairAppearance(state)
CrosshairTexture:SetTexture(CrosshairAppearance.Active)
CrosshairTexture:SetVertexColor(0, 1, 0.3, .8)
CrosshairAnimation:Play()
elseif state == "mounted" then
CrosshairTexture:SetVertexColor(1, 1, 1, 0)
CrosshairAnimation:Play()
else -- "base" falls here
CrosshairTexture:SetTexture(CrosshairAppearance.Base)
CrosshairTexture:SetVertexColor(1, 1, 1, .5)
CrosshairAnimation:Play(true) -- reverse
CrosshairFrame:SetScale(startingScale)
CrosshairFrame:SetPoint("CENTER", 0, CM.DB.global.crosshairY or 100)
CrosshairFrame:SetPoint("CENTER", 0, yOffset)
end
end

Expand Down Expand Up @@ -173,15 +181,12 @@ end

local function HandleCrosshairReactionToTarget(target)
local isTargetVisible = _G.UnitIsVisible(target)
local isTargetHostile = _G.UnitReaction("player", target) and _G.UnitReaction("player", target) <= 4
local isTargetFriendly = _G.UnitReaction("player", target) and _G.UnitReaction("player", target) >= 5
local reaction = _G.UnitReaction("player", target)
local isTargetHostile = reaction and reaction <= 4
local isTargetFriendly = reaction and reaction >= 5

if isTargetVisible then
if isTargetHostile then
SetCrosshairAppearance("hostile")
elseif isTargetFriendly then
SetCrosshairAppearance("friendly")
end
SetCrosshairAppearance(isTargetHostile and "hostile" or isTargetFriendly and "friendly" or "base")
else
SetCrosshairAppearance("base")
end
Expand Down Expand Up @@ -428,15 +433,20 @@ function _G.CombatMode_OnEvent(event)
end

-- Events responsible for crosshair reaction
if event == "PLAYER_SOFT_ENEMY_CHANGED" then
HandleCrosshairReactionToTarget("softenemy")
elseif event == "PLAYER_SOFT_INTERACT_CHANGED" then
HandleCrosshairReactionToTarget("softinteract")
end
if event == "PLAYER_SOFT_ENEMY_CHANGED" or event == "PLAYER_SOFT_INTERACT_CHANGED" then
if not HideWhileMounted() then
HandleCrosshairReactionToTarget(event == "PLAYER_SOFT_ENEMY_CHANGED" and "softenemy" or "softinteract")
end

-- Reseting crosshair when leaving combat
if event == "PLAYER_REGEN_ENABLED" then
SetCrosshairAppearance("base")
-- Hiding crosshair while mounted
elseif event == "PLAYER_MOUNT_DISPLAY_CHANGED" then
SetCrosshairAppearance(HideWhileMounted() and "mounted" or "base")

-- Reseting crosshair when leaving combat
elseif event == "PLAYER_REGEN_ENABLED" then
if not HideWhileMounted() then
SetCrosshairAppearance("base")
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion CombatMode/CombatMode.toc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Interface: 100206
## Version: 2.0.11
## Version: 2.0.12

## Title: |A:::|a|TInterface\Addons\CombatMode\assets\cmtitle:22:95|t
## Author: justice7ca w/ contributions from sampconrad, ThomasDigio, DKulan.
Expand Down
5 changes: 3 additions & 2 deletions CombatMode/Constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ CM.Constants.BLIZZARD_EVENTS = {
"BARBER_SHOP_OPEN",
"PLAYER_SOFT_ENEMY_CHANGED",
"PLAYER_SOFT_INTERACT_CHANGED",
"PLAYER_REGEN_ENABLED"
"PLAYER_REGEN_ENABLED",
"PLAYER_MOUNT_DISPLAY_CHANGED"
}

local assetsFolderPath = "Interface\\AddOns\\CombatMode\\assets\\"
Expand Down Expand Up @@ -284,7 +285,7 @@ CM.Constants.CustomCVarValues = {
["SoftTargetIconInteract"] = 1,
["SoftTargetIconGameObject"] = 1,
-- friendly target
["SoftTargetFriend"] = 3,
["SoftTargetFriend"] = 0,
["SoftTargetFriendArc"] = 0,
["SoftTargetFriendRange"] = 15,
["SoftTargetIconFriend"] = 0,
Expand Down
16 changes: 12 additions & 4 deletions CombatMode/Options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ CM.Options.DatabaseDefaults = {
customCondition = "",
reticleTargeting = true,
crosshair = true,
crosshairMounted = true,
crosshairAppearance = CM.Constants.CrosshairTextureObj.Triangle,
crosshairSize = 64,
crosshairOpacity = 1.0,
Expand Down Expand Up @@ -784,11 +785,18 @@ CM.Options.ConfigOptions = {
return CM.DB.global.crosshair
end
},
crosshairSpacing = {
type = "description",
name = " ",
crosshairMounted = {
type = "toggle",
name = "Hide While Mounted",
desc = "Hides the crosshair while mounted.",
width = 1.4,
order = 2.1
order = 2.1,
set = function(_, value)
CM.DB.global.crosshairMounted = value
end,
get = function()
return CM.DB.global.crosshairMounted
end
},
crosshairAppearance = {
name = "Crosshair Appearance",
Expand Down

0 comments on commit 2aa24ba

Please sign in to comment.