Skip to content

Commit

Permalink
Made announcements in "custom" format movable on the screen
Browse files Browse the repository at this point in the history
  • Loading branch information
MysteryDragon committed Mar 25, 2021
1 parent 6b94715 commit 0e8822a
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 4 deletions.
1 change: 1 addition & 0 deletions RaidNotifier.lua
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ do ----------------------
self:InitializeStatusDisplay("StatusDisplay")
self:InitializeGlyphWindow("GlyphWindow", self.Vars.mawLorkhaj.zhaj_glyphs_invert)
self:InitializeArrowDisplay("ArrowDisplay")
self.AnnouncementUIManager:Initialize(RaidNotifierUICenterAnnounce)
RaidNotifier.NotificationsPool.GetInstance():SetScale(self.Vars.general.notifications_scale / 100);
RaidNotifier.NotificationsPool.GetInstance():SetPrecise(self.Vars.countdown.timerPrecise)

Expand Down
11 changes: 9 additions & 2 deletions RaidNotifier.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,17 @@
<TopLevelControl name="RaidNotifierUI" hidden="true" mouseEnabled="true">
<Anchor point="TOPLEFT" relativeTo="GuiRoot" relativePoint="TOPLEFT" />
<Controls>
<Control name="$(parent)CenterAnnounce" resizeToFitDescendents="false" mouseEnabled="false" movable="false" clampedToScreen="true" hidden="false">
<Control name="$(parent)CenterAnnounce" resizeToFitDescendents="false" mouseEnabled="true" movable="false" clampedToScreen="true" hidden="false">
<Anchor point="CENTER" relativeTo="GuiRoot" relativePoint="CENTER" offsetY="-120"/>
<Dimensions x="250" y="150" />
</Control>
<OnInitialized>
local anchor = {}
_, anchor.point, anchor.relativeTo, anchor.relativePoint, anchor.offsetX, anchor.offsetY = self:GetAnchor(0)
self.initialAnchor = anchor
self.category = "general"
self.key = "announcement_position"
</OnInitialized>
</Control>
<Control name="$(parent)UltimateWindow" movable="true" mouseEnabled="true" resizeToFitDescendents="true" hidden="true" clampedToScreen ="true">
<Dimensions x="250" y="200" />
<Anchor point="TOPLEFT" relativeTo="GuiRoot" offsetX="100" offsetY="600" />
Expand Down
10 changes: 10 additions & 0 deletions Settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ do ------------------
status_display = {100, 400, CENTER},
unlock_status_icon = false,
default_sound = SOUNDS.CHAMPION_POINTS_COMMITTED,
announcement_position = {0, -120, CENTER},
},
ultimate = {
enabled = false,
Expand Down Expand Up @@ -626,6 +627,15 @@ function RaidNotifier:CreateSettingsMenu()
type = "dropdown",
name = L.Settings_General_Center_Screen_Announce,
tooltip = L.Settings_General_Center_Screen_Announce_TT,
setFunc = function(value)
savedVars.general.use_center_screen_announce = value

if (value == 0) then
self.AnnouncementUIManager:SetupCustomState()
else
self.AnnouncementUIManager:SetupCSAState()
end
end,
choices = {
L.Settings_General_Choices_Small,
--L.Settings_General_Choices_Large,
Expand Down
56 changes: 54 additions & 2 deletions UI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ do
HUD_UI_SCENE:RemoveFragment(UI_FRAGMENT)
end

local function SetElementPosition(ctrl, position)
local initial = ctrl.initialAnchor or {}
ctrl:ClearAnchors()
ctrl:SetAnchor(position[3] or TOPLEFT, initial.relativeTo or RaidNotifierUI, position[4] or TOPLEFT, position[1], position[2])
end

local function SaveElementPosition(ctrl)
local settings = GetSettingForControl(ctrl)
if settings and settings.position then -- move this to GetSettingForControl?
Expand All @@ -44,6 +50,9 @@ do
else
local anchor = settings[3] or TOPLEFT
settings[1], settings[2] = CUSTOM_ANCHORS[anchor](ctrl)
-- After moving UI element it's "relative point" and "point" may also be recalculated
-- Getting position by GetCenter() or GetLeft() / GetTop() will mind "relative point" = TOPLEFT it seems
-- That's why settings[4] doesn't saved here, thus default TOPLEFT will be loaded instead
end
end

Expand All @@ -55,8 +64,7 @@ do
if not settings then
--df("Could not find saved position for '%s'", ctrl:GetName())
else
ctrl:ClearAnchors()
ctrl:SetAnchor(settings[3] or TOPLEFT, RaidNotifierUI, TOPLEFT, settings[1], settings[2])
SetElementPosition(ctrl, settings)
end
end

Expand All @@ -71,6 +79,20 @@ do
return ctrl
end

function RaidNotifier:ResetElement(ctrl)
if type(ctrl) == "string" then
ctrl = RaidNotifierUI:GetNamedChild(ctrl)
end
if ctrl.initialAnchor then
SetElementPosition(ctrl, {
ctrl.initialAnchor.offsetX,
ctrl.initialAnchor.offsetY,
ctrl.initialAnchor.relativePoint,
ctrl.initialAnchor.point
})
end
end

function RaidNotifier:SetElementHidden(category, key, hidden)
local ctrl = elements[key]
if ctrl then
Expand Down Expand Up @@ -607,3 +629,33 @@ do -----------------
end

end
-- ----------------------
-- -- ANNOUNCEMENT WINDOW
do ----------------------
local manager = {}
RaidNotifier.AnnouncementUIManager = manager

manager.control = nil

function manager:SetupCSAState()
if not self.control then return end

self.control:SetMovable(false)
RaidNotifier:ResetElement(self.control)
end

function manager:SetupCustomState()
if not self.control then return end

self.control:SetMovable(true)
RaidNotifier:RegisterElement(self.control)
end

function manager:Initialize(control)
self.control = control

if RaidNotifier.Vars.general.use_center_screen_announce == 0 then
self:SetupCustomState()
end
end
end

0 comments on commit 0e8822a

Please sign in to comment.