Skip to content

Commit

Permalink
Merge pull request #13 from adrianocastro189/release/version-1.3.0
Browse files Browse the repository at this point in the history
Release - v1.3.0
  • Loading branch information
adrianocastro189 authored Sep 11, 2024
2 parents 06a0105 + 6ab0079 commit 44134c9
Show file tree
Hide file tree
Showing 16 changed files with 1,434 additions and 413 deletions.
11 changes: 8 additions & 3 deletions CenterGossipFrame-Cata.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
## Interface: 40400
## Name: Center Gossip Frame
## Notes: A very simple addon to centralize the main gossip and quest frames.
## Title: Center Gossip Frame |cffffee771.2.0|r
## Version: 1.2.0
## Title: Center Gossip Frame |cffffee771.3.0|r
## Version: 1.3.0
## X-Curse-Project-ID: 1051711

lib\stormwind-library.lua

CenterGossipFrame.lua

src\Integrations\TradeSkillMasterIntegration.lua
src\Integrations\TradeSkillMasterIntegration.lua

src\Models\AbstractCoveredFrame.lua
src\Models\ClassTrainerCoveredFrame.lua
src\Models\GenericCoveredFrame.lua
src\Models\MerchantCoveredFrame.lua
11 changes: 8 additions & 3 deletions CenterGossipFrame-Classic.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
## Interface: 11503
## Name: Center Gossip Frame
## Notes: A very simple addon to centralize the main gossip and quest frames.
## Title: Center Gossip Frame |cffffee771.2.0|r
## Version: 1.2.0
## Title: Center Gossip Frame |cffffee771.3.0|r
## Version: 1.3.0
## X-Curse-Project-ID: 1051711

lib\stormwind-library.lua

CenterGossipFrame.lua

src\Integrations\TradeSkillMasterIntegration.lua
src\Integrations\TradeSkillMasterIntegration.lua

src\Models\AbstractCoveredFrame.lua
src\Models\ClassTrainerCoveredFrame.lua
src\Models\GenericCoveredFrame.lua
src\Models\MerchantCoveredFrame.lua
129 changes: 13 additions & 116 deletions CenterGossipFrame.lua
Original file line number Diff line number Diff line change
@@ -1,131 +1,28 @@
---@diagnostic disable: duplicate-set-field

CenterGossipFrame = StormwindLibrary_v1_12_1.new({
CenterGossipFrame = StormwindLibrary_v1_13_0.new({
colors = {
primary = 'ED5859'
},
name = 'Center Gossip Frame',
version = '1.2.0',
version = '1.3.0',
})

--[[
Apply a listener to a frame.
The listener will be responsible for detecting when the frame is updated and
centralizing it if necessary. When the frame is already centralized, no changes
will be made, so the listener will not be invoked repeatedly.
@param gameFrame The frame to be listened to
]]
function CenterGossipFrame:applyListener(gameFrame)
if not self:canBeCentralized(gameFrame) then return end

gameFrame:HookScript('OnUpdate', function()
CenterGossipFrame:maybeCentralizeFrame(gameFrame)
end)
end

--[[
Determines whether a frame can be centralized or not.
@param gameFrame The frame to be checked
]]
function CenterGossipFrame:canBeCentralized(gameFrame)
return
gameFrame ~= nil and
gameFrame.ClearAllPoints ~= nil and
gameFrame.SetPoint ~= nil
end

--[[
Positions a frame in the center of the screen.
This method was designed to be used with the GossipFrame and QuestFrame. It
will probably work with many other frames, but must be well tested if the
addon covers other frames in the future.
@param gameFrame The frame to be centralized
]]
function CenterGossipFrame:centralizeFrame(gameFrame)
gameFrame:ClearAllPoints()
gameFrame:SetPoint('CENTER', UIParent, 'CENTER', 0, 0)
end

--[[
Determines whether a frame is already centered or not.
@param gameFrame The frame to be checked
]]
function CenterGossipFrame:isFrameCentered(frame)
local point, relativeTo, relativePoint, offsetX, offsetY = frame:GetPoint()

return
point == 'CENTER' and
relativeTo == UIParent and
relativePoint == 'CENTER' and
offsetX == 0 and
offsetY == 0
end

--[[
May centralize a frame if it can be centralized.
@param frame The frame to be centralized
]]
function CenterGossipFrame:maybeCentralizeFrame(frame)
-- @TODO: Remove this condition when the frame class implementation is done <2024.08.21>
if not self:shouldCentralizeIfMerchantFrame(frame) then return end

if not self:isFrameCentered(frame) then
self:centralizeFrame(frame)
end
end

--[[
May register the ClassTrainerFrame listener.
During development, it was noticed that ClassTrainerFrame doesn't exist until
players interact with a class trainer. That said, it can't be registered when the
addon initializes like the other frames.
Still, it must be registered only once, and that's why this method manages a flag.
]]
function CenterGossipFrame:maybeRegisterClassTrainerFrame()
if CenterGossipFrame.classTrainerFrameRegistered then return end

CenterGossipFrame:applyListener(ClassTrainerFrame)

CenterGossipFrame.classTrainerFrameRegistered = true
end

--[[
Determines whether the GossipFrame should be centralized or not if it's
MerchantFrame.
@NOTE: This is a temporary solution that will be migrated in upcoming versions when
every frame will be encapsulated in a class, so these conditions will be
later refactored.
]]
function CenterGossipFrame:shouldCentralizeIfMerchantFrame(frame)
local isMerchantFrame = frame == MerchantFrame

local isTsmEnabledForMerchantFrame = isMerchantFrame and CenterGossipFrame.tsmIntegration:isMerchantFrameVisible()

return not isMerchantFrame or not isTsmEnabledForMerchantFrame
end

CenterGossipFrame:applyListener(GossipFrame)
CenterGossipFrame:applyListener(MerchantFrame)
CenterGossipFrame:applyListener(QuestFrame)
CenterGossipFrame:applyListener(TaxiFrame)

local events = CenterGossipFrame.events

events:listen(events.EVENT_NAME_PLAYER_LOGIN, function()
-- initializes the TSM integration
CenterGossipFrame.tsmIntegration = CenterGossipFrame:new('CenterGossipFrame/TradeSkillMasterIntegration')
end)

events:listenOriginal('TRAINER_UPDATE', function ()
CenterGossipFrame:maybeRegisterClassTrainerFrame()
local coveredFrames = {
CenterGossipFrame:new('CenterGossipFrame/GenericCoveredFrame', GossipFrame),
CenterGossipFrame:new('CenterGossipFrame/GenericCoveredFrame', QuestFrame),
CenterGossipFrame:new('CenterGossipFrame/GenericCoveredFrame', TaxiFrame),
CenterGossipFrame:new('CenterGossipFrame/MerchantCoveredFrame'),
CenterGossipFrame:new('CenterGossipFrame/ClassTrainerCoveredFrame'),
}

CenterGossipFrame.arr:each(coveredFrames, function(coveredFrame)
coveredFrame:register()
end)
end)
11 changes: 8 additions & 3 deletions CenterGossipFrame.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
## Interface: 110002
## Name: Center Gossip Frame
## Notes: A very simple addon to centralize the main gossip and quest frames.
## Title: Center Gossip Frame |cffffee771.2.0|r
## Version: 1.2.0
## Title: Center Gossip Frame |cffffee771.3.0|r
## Version: 1.3.0
## X-Curse-Project-ID: 1051711

lib\stormwind-library.lua

CenterGossipFrame.lua

src\Integrations\TradeSkillMasterIntegration.lua
src\Integrations\TradeSkillMasterIntegration.lua

src\Models\AbstractCoveredFrame.lua
src\Models\ClassTrainerCoveredFrame.lua
src\Models\GenericCoveredFrame.lua
src\Models\MerchantCoveredFrame.lua
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ For now, there are no commands available for this addon.

## Changelog

### 2024.09.11 - version 1.3.0

* Internal improvements to the centralization process
* Update Stormwind Library to version 1.13.0

### 2024.08.21 - version 1.2.0

* New frames covered: Trainer Frame for learning class skills (Classic only) and
Expand Down
Loading

0 comments on commit 44134c9

Please sign in to comment.