Back to Home

ESO Lua File v101042

libraries/zo_progressbar/zo_multisegmentprogressbar.lua

[◄ back to folders ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
----------------------------------
-- ZO Multi Segment Progress Bar
----------------------------------
ZO_PROGRESS_BAR_GROWTH_DIRECTION_LEFT_TO_RIGHT = 1
ZO_PROGRESS_BAR_GROWTH_DIRECTION_RIGHT_TO_LEFT = 2
ZO_PROGRESS_BAR_GROWTH_DIRECTION_TOP_TO_BOTTOM = 3
ZO_PROGRESS_BAR_GROWTH_DIRECTION_BOTTOM_TO_TOP = 4
ZO_MultiSegmentProgressBar = ZO_InitializingObject:Subclass()
function ZO_MultiSegmentProgressBar:Initialize(control, templateName, setupFunction)
    self.control = control
    self.segmentTemplate = templateName
    self.textureControls = {}
    self.currentGrowthDirectionPosition = 0
    self.isUniformSegmentation = false
    self.maxNumSegments = 1
    self.progressBarGrowthDirection = ZO_PROGRESS_BAR_GROWTH_DIRECTION_LEFT_TO_RIGHT
    self.previousSegmentUnderneathOverlap = 0
    -- This ensures proper draw ordering using accumulators
    local function FactorySetup(segment)
        segment:SetAutoRectClipChildren(true)
    end
    self.segmentControlPool = ZO_ControlPool:New(self.segmentTemplate, self.control, "Segment")
    self.segmentControlPool:SetCustomFactoryBehavior(FactorySetup)
end
function ZO_MultiSegmentProgressBar:SetSegmentationUniformity(isUniform)
    self.isUniformSegmentation = isUniform
end
function ZO_MultiSegmentProgressBar:SetMaxSegments(numSegments)
    if numSegments > 0 then
        self.maxNumSegments = numSegments
    end
end
function ZO_MultiSegmentProgressBar:SetSegmentTemplate(templateName)
    self:Clear()
    self.segmentTemplate = templateName
    self.segmentControlPool.templateName = templateName
end
function ZO_MultiSegmentProgressBar:SetProgressBarGrowthDirection(growthDirection)
    self.progressBarGrowthDirection = growthDirection
end
function ZO_MultiSegmentProgressBar:SetPreviousSegmentUnderneathOverlap(overlapValue)
    self.previousSegmentUnderneathOverlap = overlapValue
end
function ZO_MultiSegmentProgressBar:AddSegment(data)
    if #self.textureControls < self.maxNumSegments then
        local segmentIndex = #self.textureControls + 1
        local previousSegmentUnderneathOverlap = segmentIndex > 1 and self.previousSegmentUnderneathOverlap or 0
        if self.progressBarGrowthDirection == ZO_PROGRESS_BAR_GROWTH_DIRECTION_LEFT_TO_RIGHT or self.progressBarGrowthDirection == ZO_PROGRESS_BAR_GROWTH_DIRECTION_RIGHT_TO_LEFT then
            local currentX = self.currentGrowthDirectionPosition + previousSegmentUnderneathOverlap
            local segmentWidth = data and data.width or 0
            if self.isUniformSegmentation then
                segmentWidth = self.control:GetWidth() / self.maxNumSegments
            end
            local segmentControl = self.segmentControlPool:AcquireObject()
            ApplyTemplateToControl(segmentControl, self.segmentTemplate)
            segmentControl:SetWidth(segmentWidth - previousSegmentUnderneathOverlap)
            segmentControl:SetDrawLevel(self.maxNumSegments + 2 - segmentIndex)
            local anchorPoint = self.progressBarGrowthDirection == ZO_PROGRESS_BAR_GROWTH_DIRECTION_LEFT_TO_RIGHT and LEFT or RIGHT
            segmentControl:ClearAnchors()
            segmentControl:SetAnchor(anchorPoint, self.control, anchorPoint, currentX, 0)
            table.insert(self.textureControls, segmentControl)
            if self.setupFunction then
                self.setupFunction(segmentControl, segmentIndex)
            end
            self.currentGrowthDirectionPosition = self.currentGrowthDirectionPosition + segmentWidth
        elseif self.progressBarGrowthDirection == ZO_PROGRESS_BAR_GROWTH_DIRECTION_TOP_TO_BOTTOM or self.progressBarGrowthDirection == ZO_PROGRESS_BAR_GROWTH_DIRECTION_BOTTOM_TO_TOP then
            local currentY = self.currentGrowthDirectionPosition + previousSegmentUnderneathOverlap
            local segmentHeight = data.height
            if self.isUniformSegmentation then
                segmentHeight = self.control:GetHeight() / self.maxNumSegments
            end
            local segmentControl = self.segmentControlPool:AcquireObject()
            ApplyTemplateToControl(segmentControl, self.segmentTemplate)
            segmentControl:SetHeight(segmentHeight - previousSegmentUnderneathOverlap)
            local anchorPoint = self.progressBarGrowthDirection == ZO_PROGRESS_BAR_GROWTH_DIRECTION_TOP_TO_BOTTOM and TOP or BOTTOM
            segmentControl:ClearAnchors()
            segmentControl:SetAnchor(anchorPoint, self.control, anchorPoint, 0, currentY)
            table.insert(self.textureControls, segmentControl)
            self.currentGrowthDirectionPosition = self.currentGrowthDirectionPosition + segmentHeight
        end
    end
end
function ZO_MultiSegmentProgressBar:Clear()
    self.currentGrowthDirectionPosition = 0
    self.segmentControlPool:ReleaseAllObjects()
    self.textureControls = {}
end